| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * add a list of changes to the underlying db. |
| | | * |
| | |
| | | try |
| | | { |
| | | dbCloseLock.readLock().lock(); |
| | | |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | for (UpdateMsg change : changes) |
| | | { |
| | | DatabaseEntry key = new ReplicationKey( |
| | |
| | | try |
| | | { |
| | | db.close(); |
| | | db = null; |
| | | } |
| | | finally |
| | | { |
| | |
| | | dbCloseLock.readLock().lock(); |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | DatabaseEntry key = new DatabaseEntry(); |
| | | DatabaseEntry data = new DatabaseEntry(); |
| | | |
| | |
| | | dbCloseLock.readLock().lock(); |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | DatabaseEntry key = new DatabaseEntry(); |
| | | DatabaseEntry data = new DatabaseEntry(); |
| | | |
| | |
| | | dbCloseLock.readLock().lock(); |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | cursor = db.openCursor(null, null); |
| | | if (cursor.getSearchKeyRange(key, data, LockMode.DEFAULT) |
| | | == OperationStatus.SUCCESS) |
| | |
| | | Cursor localCursor = null; |
| | | try |
| | | { |
| | | // If the DB has been closed then create empty cursor. |
| | | if (isDBClosed()) |
| | | { |
| | | isClosed = true; |
| | | cursor = null; |
| | | return; |
| | | } |
| | | |
| | | localCursor = db.openCursor(txn, null); |
| | | if (startingChangeNumber != null) |
| | | { |
| | |
| | | Cursor localCursor = null; |
| | | try |
| | | { |
| | | // If the DB has been closed then create empty cursor. |
| | | if (isDBClosed()) |
| | | { |
| | | isClosed = true; |
| | | txn = null; |
| | | cursor = null; |
| | | return; |
| | | } |
| | | |
| | | // Create the transaction that will protect whatever done with this |
| | | // write cursor. |
| | | localTxn = dbenv.beginTransaction(); |
| | |
| | | */ |
| | | public ChangeNumber nextChangeNumber() throws DatabaseException |
| | | { |
| | | if (isClosed) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | OperationStatus status = cursor.getNext(key, data, LockMode.DEFAULT); |
| | | |
| | | if (status != OperationStatus.SUCCESS) |
| | |
| | | */ |
| | | public UpdateMsg next() |
| | | { |
| | | if (isClosed) |
| | | { |
| | | return null; |
| | | } |
| | | |
| | | UpdateMsg currentChange = null; |
| | | while (currentChange == null) |
| | | { |
| | |
| | | */ |
| | | public void delete() throws DatabaseException |
| | | { |
| | | if (isClosed) |
| | | { |
| | | throw new IllegalStateException("ReplServerDBCursor already closed"); |
| | | } |
| | | |
| | | cursor.delete(); |
| | | } |
| | | } // ReplServerDBCursor |
| | |
| | | dbCloseLock.writeLock().lock(); |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | String dbName = db.getDatabaseName(); |
| | | |
| | | // Clears the reference to this serverID |
| | |
| | | |
| | | // Closing is requested by the Berkeley DB before truncate |
| | | db.close(); |
| | | db = null; // In case there's a failure between here and recreation. |
| | | |
| | | // Clears the changes |
| | | dbenv.clearDb(dbName); |
| | |
| | | * @param start The lower limit of the count. |
| | | * @param stop The higher limit of the count. |
| | | * @return The number of changes between provided start and stop changeNumber. |
| | | * Returns -1 when an error occurs. |
| | | * Returns 0 when an error occurs. |
| | | */ |
| | | public int count(ChangeNumber start, ChangeNumber stop) |
| | | { |
| | |
| | | int distBackToCounterRecord2 = 0; |
| | | int count=0; |
| | | OperationStatus status; |
| | | |
| | | try |
| | | { |
| | | dbCloseLock.readLock().lock(); |
| | | |
| | | Cursor cursor = null; |
| | | try |
| | | { |
| | | // If the DB has been closed then return immediately. |
| | | if (isDBClosed()) |
| | | { |
| | | return 0; |
| | | } |
| | | |
| | | ChangeNumber cn ; |
| | | |
| | | if ((start==null)&&(stop==null)) |
| | |
| | | } |
| | | finally |
| | | { |
| | | if (cursor != null) |
| | | { |
| | | cursor.close(); |
| | | } |
| | | closeLockedCursor(cursor); |
| | | } |
| | | } |
| | | catch (DatabaseException e) |
| | |
| | | this.counterWindowSize = size; |
| | | } |
| | | |
| | | |
| | | |
| | | // Returns {@code true} if the DB is closed. This method assumes that either |
| | | // the db read/write lock has been taken. |
| | | private boolean isDBClosed() |
| | | { |
| | | return db == null; |
| | | } |
| | | |
| | | } |