Skip to content

Commit b8d4e8b

Browse files
authored
Merge pull request #333 from WrenSecurity/backport/pr-332-sustaining/15.x
Fix persistent search restart with affinity-based load balancing (backport)
2 parents b783169 + be6faa7 commit b8d4e8b

1 file changed

Lines changed: 18 additions & 30 deletions

File tree

openam-core/src/main/java/com/iplanet/services/ldap/event/LDAPv3PersistentSearch.java

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,18 @@
1717

1818
package com.iplanet.services.ldap.event;
1919

20-
import static org.forgerock.openam.ldap.LDAPConstants.*;
21-
import static org.forgerock.openam.utils.Time.*;
20+
import static org.forgerock.openam.ldap.LDAPConstants.AD_IS_DELETED_ATTR;
21+
import static org.forgerock.openam.ldap.LDAPConstants.AD_NOTIFICATION_OID;
22+
import static org.forgerock.openam.ldap.LDAPConstants.AD_WHEN_CHANGED_ATTR;
23+
import static org.forgerock.openam.ldap.LDAPConstants.AD_WHEN_CREATED_ATTR;
24+
import static org.forgerock.openam.ldap.LDAPConstants.DN_ATTR;
25+
import static org.forgerock.openam.utils.Time.currentTimeMillis;
2226

27+
import com.sun.identity.common.GeneralTaskRunnable;
28+
import com.sun.identity.common.SystemTimerPool;
29+
import com.sun.identity.idm.IdRepoListener;
30+
import com.sun.identity.idm.IdType;
31+
import com.sun.identity.shared.debug.Debug;
2332
import java.util.ArrayList;
2433
import java.util.Arrays;
2534
import java.util.Collection;
@@ -29,14 +38,12 @@
2938
import java.util.List;
3039
import java.util.Map;
3140
import java.util.concurrent.ConcurrentHashMap;
32-
3341
import org.forgerock.openam.ldap.LDAPRequests;
3442
import org.forgerock.openam.sm.datalayer.api.ConnectionFactory;
3543
import org.forgerock.openam.sm.datalayer.api.DataLayerException;
3644
import org.forgerock.openam.utils.IOUtils;
3745
import org.forgerock.opendj.ldap.Attribute;
3846
import org.forgerock.opendj.ldap.Connection;
39-
import org.forgerock.opendj.ldap.ConnectionEventListener;
4047
import org.forgerock.opendj.ldap.DN;
4148
import org.forgerock.opendj.ldap.DecodeException;
4249
import org.forgerock.opendj.ldap.DecodeOptions;
@@ -52,18 +59,11 @@
5259
import org.forgerock.opendj.ldap.controls.PersistentSearchChangeType;
5360
import org.forgerock.opendj.ldap.controls.PersistentSearchRequestControl;
5461
import org.forgerock.opendj.ldap.requests.SearchRequest;
55-
import org.forgerock.opendj.ldap.responses.ExtendedResult;
5662
import org.forgerock.opendj.ldap.responses.Result;
5763
import org.forgerock.opendj.ldap.responses.SearchResultEntry;
5864
import org.forgerock.opendj.ldap.responses.SearchResultReference;
5965
import org.forgerock.util.annotations.VisibleForTesting;
6066

61-
import com.sun.identity.common.GeneralTaskRunnable;
62-
import com.sun.identity.common.SystemTimerPool;
63-
import com.sun.identity.idm.IdRepoListener;
64-
import com.sun.identity.idm.IdType;
65-
import com.sun.identity.shared.debug.Debug;
66-
6767
/**
6868
* An abstract implementation of LDAPv3 persistent searches.
6969
*
@@ -188,7 +188,6 @@ private void logError(Throwable t) {
188188
}
189189

190190
private void startSearch(Connection conn) throws LdapException {
191-
conn.addConnectionEventListener(new ConnectionRestartListener());
192191
if (mode == null) {
193192
detectPersistentSearchMode(conn);
194193
}
@@ -227,7 +226,13 @@ private void startSearch(Connection conn) throws LdapException {
227226
//since psearch wasn't running until now, let's clear the caches to make sure that if something got into the
228227
//cache, while PS was stopped, those gets cleared out and we start with a clean cache.
229228
clearCaches();
230-
futureResult = conn.searchAsync(searchRequest, null, new PersistentSearchResultHandler());
229+
futureResult = conn.searchAsync(searchRequest, null, new PersistentSearchResultHandler())
230+
.thenOnException(e -> {
231+
if (!shutdown) {
232+
DEBUG.error("Persistent search against base DN {} has failed: {}", searchBaseDN, e.getMessage());
233+
restartSearch();
234+
}
235+
});
231236
}
232237

233238
/**
@@ -407,23 +412,6 @@ public void run() {
407412
}
408413
}
409414

410-
private class ConnectionRestartListener implements ConnectionEventListener {
411-
412-
@Override
413-
public void handleConnectionClosed() {
414-
}
415-
416-
@Override
417-
public void handleConnectionError(boolean isDisconnectNotification, LdapException e) {
418-
DEBUG.error("An error occurred while executing persistent search against base DN: {}", searchBaseDN, e);
419-
restartSearch();
420-
}
421-
422-
@Override
423-
public void handleUnsolicitedNotification(ExtendedResult notification) {
424-
}
425-
}
426-
427415
@VisibleForTesting
428416
protected boolean isShutdown() {
429417
return shutdown;

0 commit comments

Comments
 (0)