OPENDJ-1116 Introduce abstraction for the changelog DB
Slayered walking dead code.
Walking dead code is code that looks it is alive, tastes just like if it was alive, but there is funny smell about it, and actually... it turns out this code is dead.
ReplicationServerDomain.getEligibleState() is walking dead code because:
- JEChangelogDB.getCSNAfter() always returns null: the API of ReplicaDBCursor mandates to call call next() before calling getChange(), however getCSNAfter() fails to do so, hence getChange() always returns null, which means getCSNAfter() always returns null.
- the "result" local variable is a duplicate of "latestState", which means it starts of with the exact same state. The code iterates through "latestState" to get its CSNs, calling update() on "result" with these CSNs. But... since "result" duplicates "latestState", it has the exact same CSNs, which means calling update() will have no effect on "result", leaving it on the same state as it was before the iterations.
ECLServerHandler.java, ReplicationServer.java:
Replaced ReplicationServerDomain.getEligibleState() with ReplicationServerDomain.getLatestServerState().duplicate() where applicable.
ReplicationServerDomain.java:
Removed getEligibleState() which does literally nothing, but in a very inneficient way.
ReplicationDomainDB.java, JEChangelogDB.java:
Removed getCSNAfter(), now become unused.
| | |
| | | // Assign the start state for the domain |
| | | if (isPersistent == PERSISTENT_CHANGES_ONLY) |
| | | { |
| | | newDomainCtxt.startState = rsd.getEligibleState(eligibleCSN); |
| | | newDomainCtxt.startState = rsd.getLatestServerState().duplicate(); |
| | | startStatesFromProvidedCookie.remove(rsd.getBaseDN()); |
| | | } |
| | | else |
| | |
| | | } |
| | | } |
| | | |
| | | // Set the stop state for the domain from the eligibleCSN |
| | | newDomainCtxt.stopState = rsd.getEligibleState(eligibleCSN); |
| | | newDomainCtxt.stopState = rsd.getLatestServerState().duplicate(); |
| | | } |
| | | newDomainCtxt.currentState = new ServerState(); |
| | | |
| | |
| | | MultiDomainServerState result = new MultiDomainServerState(); |
| | | for (ReplicationServerDomain rsd : getReplicationServerDomains()) |
| | | { |
| | | final ServerState latestDBServerState = rsd.getLatestServerState(); |
| | | if (contains(excludedBaseDNs, rsd.getBaseDN().toNormalizedString()) |
| | | || rsd.getLatestServerState().isEmpty()) |
| | | || latestDBServerState.isEmpty()) |
| | | continue; |
| | | |
| | | final CSN eligibleCSN = getEligibleCSN(excludedBaseDNs); |
| | | result.update(rsd.getBaseDN(), rsd.getEligibleState(eligibleCSN)); |
| | | result.update(rsd.getBaseDN(), latestDBServerState); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * Computes the eligible server state for the domain. |
| | | * |
| | | * <pre> |
| | | * s1 s2 s3 |
| | | * -- -- -- |
| | | * csn31 |
| | | * csn15 |
| | | * |
| | | * ----------------------------------------- eligibleCSN |
| | | * csn14 |
| | | * csn26 |
| | | * csn13 |
| | | * </pre> |
| | | * |
| | | * The eligibleState is : s1;csn14 / s2;csn26 / s3;csn31 |
| | | * |
| | | * @param eligibleCSN |
| | | * The provided eligible CSN. |
| | | * @return The computed eligible server state. |
| | | */ |
| | | public ServerState getEligibleState(CSN eligibleCSN) |
| | | { |
| | | ServerState latestState = getLatestServerState(); |
| | | |
| | | // The result is initialized from the dbState. |
| | | // From it, we don't want to keep the changes newer than eligibleCSN. |
| | | ServerState result = latestState.duplicate(); |
| | | |
| | | if (eligibleCSN != null) |
| | | { |
| | | for (CSN mostRecentDbCSN : latestState) |
| | | { |
| | | try { |
| | | // Is the most recent change in the Db newer than eligible CSN ? |
| | | // if yes (like csn15 in the example above, then we have to go back |
| | | // to the Db and look for the change older than eligible CSN (csn14) |
| | | if (eligibleCSN.olderOrEqual(mostRecentDbCSN)) |
| | | { |
| | | // let's try to seek the first change <= eligibleCSN |
| | | CSN newCSN = domainDB.getCSNAfter(baseDN, |
| | | mostRecentDbCSN.getServerId(), eligibleCSN); |
| | | result.update(newCSN); |
| | | } |
| | | else |
| | | { |
| | | // for this serverId, all changes in the ChangelogDb are holder |
| | | // than eligibleCSN, the most recent in the db is our guy. |
| | | result.update(mostRecentDbCSN); |
| | | } |
| | | } catch (Exception e) { |
| | | logError(ERR_WRITER_UNEXPECTED_EXCEPTION |
| | | .get(stackTraceToSingleLineString(e))); |
| | | TRACER.debugCaught(DebugLogLevel.ERROR, e); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (debugEnabled()) |
| | | { |
| | | debug("getEligibleState() result is " + result); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * Returns the start state of the domain, made of the oldest CSN stored for |
| | | * each serverId. |
| | | * <p> |
| | |
| | | long getCount(DN baseDN, int serverId, CSN from, CSN to); |
| | | |
| | | /** |
| | | * Returns the {@link CSN} situated immediately after the specified |
| | | * {@link CSN} for the specified serverId and replication domain according to |
| | | * the order specified by {@link CSN#compareTo(CSN)}. If an Exception occurs |
| | | * in this method, then it returns the oldest possible CSN for the provided |
| | | * serverId. |
| | | * |
| | | * @param baseDN |
| | | * the replication domain baseDN |
| | | * @param serverId |
| | | * the serverId for which we want the information |
| | | * @param startAfterCSN |
| | | * The position where the iterator must start |
| | | * @return the CSN immediately after startAfterCSN, or null if no CSN exist |
| | | * after startAfterCSN |
| | | */ |
| | | CSN getCSNAfter(DN baseDN, int serverId, CSN startAfterCSN); |
| | | |
| | | /** |
| | | * Generates a {@link ReplicaDBCursor} for the specified serverId and |
| | | * replication domain starting after the provided CSN. |
| | | * <p> |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public CSN getCSNAfter(DN baseDN, int serverId, CSN startAfterCSN) |
| | | { |
| | | final JEReplicaDB replicaDB = getReplicaDB(baseDN, serverId); |
| | | |
| | | ReplicaDBCursor cursor = null; |
| | | try |
| | | { |
| | | cursor = replicaDB.generateCursorFrom(startAfterCSN); |
| | | if (cursor != null && cursor.getChange() != null) |
| | | { |
| | | return cursor.getChange().getCSN(); |
| | | } |
| | | return null; |
| | | } |
| | | catch (ChangelogException e) |
| | | { |
| | | // there's no change older than startAfterCSN |
| | | return new CSN(0, 0, serverId); |
| | | } |
| | | finally |
| | | { |
| | | close(cursor); |
| | | } |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public ChangeNumberIndexDB getChangeNumberIndexDB() |
| | | { |
| | | synchronized (cnIndexDBLock) |