| | |
| | | /** |
| | | * This class implements the interface between the underlying database |
| | | * and the JEReplicaDB class. |
| | | * <p> |
| | | * This is the only class that should have code using the BDB interfaces. |
| | | */ |
| | | public class ReplicationDB |
| | |
| | | replicationServer.getReplicationServerDomain(baseDN, true); |
| | | db = dbenv.getOrAddDb(serverId, baseDN, domain.getGenerationId()); |
| | | |
| | | |
| | | intializeCounters(); |
| | | } |
| | | |
| | |
| | | return new CSN(decodeUTF8(data)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * add a list of changes to the underlying db. |
| | | * |
| | |
| | | |
| | | for (UpdateMsg change : changes) |
| | | { |
| | | final DatabaseEntry key = |
| | | createReplicationKey(change.getCSN()); |
| | | final DatabaseEntry key = createReplicationKey(change.getCSN()); |
| | | final DatabaseEntry data = new ReplicationData(change); |
| | | |
| | | insertCounterRecordIfNeeded(change.getCSN()); |
| | |
| | | return new ReplServerDBCursor(); |
| | | } |
| | | |
| | | |
| | | |
| | | private void closeAndReleaseReadLock(Cursor cursor) |
| | | { |
| | | try |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Read the newest CSN present in the database. |
| | | * |
| | |
| | | } |
| | | catch (DatabaseException e) |
| | | { |
| | | StaticUtils.close(localCursor); |
| | | throw new ChangelogException(e); |
| | | } |
| | | finally |
| | | { |
| | | if (!cursorHeld) |
| | | { |
| | | dbCloseLock.readLock().unlock(); |
| | | closeAndReleaseReadLock(localCursor); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | catch (ChangelogException e) |
| | | { |
| | | StaticUtils.close(localCursor); |
| | | abort(localTxn); |
| | | throw e; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | StaticUtils.close(localCursor); |
| | | abort(localTxn); |
| | | throw new ChangelogException(e); |
| | | } |
| | |
| | | { |
| | | if (!cursorHeld) |
| | | { |
| | | dbCloseLock.readLock().unlock(); |
| | | closeAndReleaseReadLock(localCursor); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | return null; |
| | | } |
| | | } catch (DatabaseException e) |
| | | } |
| | | catch (DatabaseException e) |
| | | { |
| | | return null; |
| | | } |
| | |
| | | // RE-create the db |
| | | db = dbenv.getOrAddDb(serverId, baseDN, -1); |
| | | } |
| | | catch(Exception e) |
| | | catch (Exception e) |
| | | { |
| | | MessageBuilder mb = new MessageBuilder(); |
| | | mb.append(ERR_ERROR_CLEARING_DB.get(toString(), |
| | | e.getMessage() + " " + |
| | | stackTraceToSingleLineString(e))); |
| | | e.getMessage() + " " + stackTraceToSingleLineString(e))); |
| | | logError(mb.toMessage()); |
| | | } |
| | | finally |
| | |
| | | dbCloseLock.writeLock().unlock(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Count the number of changes between 2 changes numbers (inclusive). |
| | | * @param start The lower limit of the count. |
| | |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | private void findFirstCounterRecordAfterStartPoint(CSN start, |
| | | CSN stop, int[] counterValues, int[] distanceToCounterRecords) |
| | | private void findFirstCounterRecordAfterStartPoint(CSN start, CSN stop, |
| | | int[] counterValues, int[] distanceToCounterRecords) |
| | | throws DatabaseException |
| | | { |
| | | Cursor cursor = db.openCursor(null, null); |
| | |
| | | } |
| | | } |
| | | |
| | | private boolean findFirstCounterRecordBeforeStopPoint(CSN start, |
| | | CSN stop, int[] counterValues, int[] distanceToCounterRecords) |
| | | private boolean findFirstCounterRecordBeforeStopPoint(CSN start, CSN stop, |
| | | int[] counterValues, int[] distanceToCounterRecords) |
| | | throws DatabaseException |
| | | { |
| | | Cursor cursor = db.openCursor(null, null); |