| | |
| | | * @param baseDN The baseDN of the replication domain. |
| | | * @param replicationServer The ReplicationServer that needs to be shutdown. |
| | | * @param dbenv The Db environment to use to create the db. |
| | | * @throws ChangelogException If a database problem happened. |
| | | * @throws ChangelogException If a database problem happened |
| | | */ |
| | | public ReplicationDB(int serverId, DN baseDN, |
| | | ReplicationServer replicationServer, ReplicationDbEnv dbenv) |
| | |
| | | /** |
| | | * add a list of changes to the underlying db. |
| | | * |
| | | * @param changes The list of changes to add to the underlying db. |
| | | * @param changes |
| | | * The list of changes to add to the underlying db. |
| | | * @throws ChangelogException |
| | | * If a database problem happened |
| | | */ |
| | | public void addEntries(List<UpdateMsg> changes) |
| | | public void addEntries(List<UpdateMsg> changes) throws ChangelogException |
| | | { |
| | | dbCloseLock.readLock().lock(); |
| | | try |
| | |
| | | } |
| | | catch (DatabaseException e) |
| | | { |
| | | dbenv.shutdownOnException(e); |
| | | throw new ChangelogException(e); |
| | | } |
| | | finally |
| | | { |
| | |
| | | * @param startCSN |
| | | * The CSN from which the cursor must start.If null, start from the |
| | | * oldest CSN |
| | | * @throws ChangelogException |
| | | * When a problem occurs or the startCSN does not exist. |
| | | * @return The ReplServerDBCursor. |
| | | * @throws ChangelogException |
| | | * If a database problem happened |
| | | */ |
| | | public ReplServerDBCursor openReadCursor(CSN startCSN) |
| | | throws ChangelogException |
| | |
| | | * Read the oldest CSN present in the database. |
| | | * |
| | | * @return the oldest CSN in the DB, null if the DB is empty or closed |
| | | * @throws ChangelogException |
| | | * If a database problem happened |
| | | */ |
| | | public CSN readOldestCSN() |
| | | public CSN readOldestCSN() throws ChangelogException |
| | | { |
| | | dbCloseLock.readLock().lock(); |
| | | |
| | |
| | | } |
| | | catch (DatabaseException e) |
| | | { |
| | | dbenv.shutdownOnException(e); |
| | | return null; |
| | | throw new ChangelogException(e); |
| | | } |
| | | finally |
| | | { |
| | |
| | | * Read the newest CSN present in the database. |
| | | * |
| | | * @return the newest CSN in the DB, null if the DB is empty or closed |
| | | * @throws ChangelogException |
| | | * If a database problem happened |
| | | */ |
| | | public CSN readNewestCSN() |
| | | public CSN readNewestCSN() throws ChangelogException |
| | | { |
| | | dbCloseLock.readLock().lock(); |
| | | |
| | |
| | | } |
| | | catch (DatabaseException e) |
| | | { |
| | | dbenv.shutdownOnException(e); |
| | | return null; |
| | | throw new ChangelogException(e); |
| | | } |
| | | finally |
| | | { |
| | |
| | | * The CSN from which we start searching. |
| | | * @return the CSN right before the one passed as a parameter. Can return null |
| | | * if there is none. |
| | | * @throws ChangelogException |
| | | * If a database problem happened |
| | | */ |
| | | public CSN getPreviousCSN(CSN csn) |
| | | public CSN getPreviousCSN(CSN csn) throws ChangelogException |
| | | { |
| | | if (csn == null) |
| | | { |
| | |
| | | } |
| | | catch (DatabaseException e) |
| | | { |
| | | dbenv.shutdownOnException(e); |
| | | throw new ChangelogException(e); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | catch (ChangelogException e) |
| | | { |
| | | abort(localTxn); |
| | | JEUtils.abort(localTxn); |
| | | throw e; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | abort(localTxn); |
| | | JEUtils.abort(localTxn); |
| | | throw new ChangelogException(e); |
| | | } |
| | | finally |
| | |
| | | } |
| | | } |
| | | |
| | | private void abort(Transaction localTxn) |
| | | { |
| | | if (localTxn != null) |
| | | { |
| | | try |
| | | { |
| | | localTxn.abort(); |
| | | } |
| | | catch (DatabaseException ignore) |
| | | { |
| | | // Ignore. |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Close the ReplicationServer Cursor. |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Abort the Cursor after a Deadlock Exception. |
| | | * This method catch and ignore the DeadlockException because |
| | | * this must be done when aborting a cursor after a DeadlockException |
| | | * Abort the cursor after an Exception. |
| | | * This method catch and ignore the DatabaseException because |
| | | * this must be done when aborting a cursor after a DatabaseException |
| | | * (per the Cursor documentation). |
| | | * This should not be used in any other case. |
| | | */ |
| | |
| | | } |
| | | |
| | | closeAndReleaseReadLock(cursor); |
| | | |
| | | if (txn != null) |
| | | { |
| | | try |
| | | { |
| | | txn.abort(); |
| | | } |
| | | catch (DatabaseException e) |
| | | { |
| | | dbenv.shutdownOnException(e); |
| | | } |
| | | } |
| | | JEUtils.abort(txn); |
| | | } |
| | | |
| | | /** |