OPENDJ-1116 Introduce abstraction for the changelog DB
Changes after review from Matthew Swift.
Hid ChangeNumberIndexDB.nextChangeNumber() from client code.
ChangeNumberIndexDB.java, JEChangeNumberIndexDB.java:
Removed nextChangeNumber().
Changed addRecord() to return the assigned changeNumber.
ECLServerHandler.java, CNIndexRecord.java:
Consequence of the change above.
| | |
| | | private void assignNewChangeNumberAndStore(ECLUpdateMsg change) |
| | | throws ChangelogException |
| | | { |
| | | ChangeNumberIndexDB cnIndexDB = replicationServer.getChangeNumberIndexDB(); |
| | | |
| | | change.setChangeNumber(cnIndexDB.nextChangeNumber()); |
| | | |
| | | final CNIndexRecord record = new CNIndexRecord(previousCookie.toString(), |
| | | change.getBaseDN(), change.getUpdateMsg().getCSN()); |
| | | // store in CNIndexDB the pair |
| | | // (change number of the current change, state before this change) |
| | | cnIndexDB.addRecord(new CNIndexRecord( |
| | | change.getChangeNumber(), |
| | | previousCookie.toString(), |
| | | change.getBaseDN(), |
| | | change.getUpdateMsg().getCSN())); |
| | | change.setChangeNumber( |
| | | replicationServer.getChangeNumberIndexDB().addRecord(record)); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | |
| | | /** This is the key used to store the rest of the . */ |
| | | private long changeNumber; |
| | | private String previousCookie; |
| | | private DN baseDN; |
| | | private CSN csn; |
| | | private final long changeNumber; |
| | | private final String previousCookie; |
| | | private final DN baseDN; |
| | | private final CSN csn; |
| | | |
| | | /** |
| | | * Builds an instance of this class. |
| | |
| | | } |
| | | |
| | | /** |
| | | * Builds an instance of this class, with changeNumber equal to 0. |
| | | * |
| | | * @param previousCookie |
| | | * the previous cookie |
| | | * @param baseDN |
| | | * the baseDN |
| | | * @param csn |
| | | * the replication CSN field |
| | | * @see #CNIndexRecord(long, String, DN, CSN) |
| | | */ |
| | | public CNIndexRecord(String previousCookie, DN baseDN, CSN csn) |
| | | { |
| | | this(0, previousCookie, baseDN, csn); |
| | | } |
| | | |
| | | /** |
| | | * Getter for the baseDN field. |
| | | * |
| | | * @return the baseDN |
| | |
| | | */ |
| | | public interface ChangeNumberIndexDB |
| | | { |
| | | /** |
| | | * Generates the next change number. |
| | | * |
| | | * @return The newly generated change number |
| | | */ |
| | | long nextChangeNumber(); |
| | | |
| | | /** |
| | | * Returns the last generated change number. |
| | |
| | | * |
| | | * @param record |
| | | * The {@link CNIndexRecord} to add to this DB. |
| | | * @return the change number associated to this record on adding to this DB |
| | | * @throws ChangelogException |
| | | * if a database problem occurs. |
| | | */ |
| | | void addRecord(CNIndexRecord record) throws ChangelogException; |
| | | long addRecord(CNIndexRecord record) throws ChangelogException; |
| | | |
| | | /** |
| | | * Generate a new {@link ChangeNumberIndexDBCursor} that allows to browse the |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void addRecord(CNIndexRecord record) throws ChangelogException |
| | | public long addRecord(CNIndexRecord record) throws ChangelogException |
| | | { |
| | | db.addRecord(record); |
| | | long changeNumber = nextChangeNumber(); |
| | | final CNIndexRecord newRecord = |
| | | new CNIndexRecord(changeNumber, record.getPreviousCookie(), record |
| | | .getBaseDN(), record.getCSN()); |
| | | db.addRecord(newRecord); |
| | | |
| | | if (debugEnabled()) |
| | | TRACER.debugInfo("In JEChangeNumberIndexDB.add, added: " + record); |
| | | TRACER.debugInfo("In JEChangeNumberIndexDB.add, added: " + newRecord); |
| | | return changeNumber; |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | return db.readLastRecord(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public long nextChangeNumber() |
| | | private long nextChangeNumber() |
| | | { |
| | | return lastGeneratedChangeNumber.incrementAndGet(); |
| | | } |