| | |
| | | // Read the CNIndexDB to see whether it contains startChangeNumber |
| | | DBCursor<ChangeNumberIndexRecord> cursor = |
| | | cnIndexDB.getCursorFrom(startChangeNumber); |
| | | final ChangeNumberIndexRecord startRecord = cursor.getRecord(); |
| | | if (startRecord != null) |
| | | if (cursor.next()) |
| | | { |
| | | // found the provided startChangeNumber, let's return it |
| | | cnIndexDBCursor = cursor; |
| | | return startRecord.getPreviousCookie(); |
| | | return cursor.getRecord().getPreviousCookie(); |
| | | } |
| | | close(cursor); |
| | | |
| | |
| | | if (startChangeNumber < oldestChangeNumber) |
| | | { |
| | | cursor = cnIndexDB.getCursorFrom(oldestChangeNumber); |
| | | final ChangeNumberIndexRecord oldestRecord = cursor.getRecord(); |
| | | if (oldestRecord == null) |
| | | if (!cursor.next()) |
| | | { |
| | | // This should not happen |
| | | close(cursor); |
| | |
| | | } |
| | | |
| | | cnIndexDBCursor = cursor; |
| | | return oldestRecord.getPreviousCookie(); |
| | | return cursor.getRecord().getPreviousCookie(); |
| | | } |
| | | else if (startChangeNumber <= newestChangeNumber) |
| | | { |
| | |
| | | { |
| | | DBCursor<ChangeNumberIndexRecord> cursor = |
| | | cnIndexDB.getCursorFrom(startChangeNumber); |
| | | cursor.next(); |
| | | if (cursor.getRecord() == null) |
| | | { |
| | | close(cursor); |
| | |
| | | * |
| | | * @param startChangeNumber |
| | | * The position where the iterator must start. |
| | | * @return a new ReplicationIterator that allows to browse this DB managed by |
| | | * @return a new DBCursor that allows to browse this DB managed by |
| | | * this object and starting at the position defined by a given |
| | | * changeNumber. |
| | | * @throws ChangelogException |
| | |
| | | |
| | | /** |
| | | * A cursor on ChangeNumberIndexDB. |
| | | * <p> |
| | | * The cursor initially points to a record, that is {@code cursor.getRecord()} |
| | | * is equals to the first record available from the cursor before any call to |
| | | * {@code cursor.next()} method. |
| | | */ |
| | | class FileChangeNumberIndexDBCursor implements DBCursor<ChangeNumberIndexRecord> |
| | | { |
| | |
| | | throws ChangelogException |
| | | { |
| | | this.cursor = cursor; |
| | | // cursor is positioned to first record at start |
| | | next(); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | { |
| | | private static final DebugTracer TRACER = getTracer(); |
| | | |
| | | // TODO : to replace by configurable value |
| | | private static final long MAX_LOG_FILE_SIZE_IN_BYTES = 10*1024; |
| | | private static final long MAX_LOG_FILE_SIZE_IN_BYTES = 10*1024*1024; |
| | | |
| | | private static final int NO_GENERATION_ID = -1; |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2013 ForgeRock AS |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | */ |
| | | package org.opends.server.replication.server.changelog.je; |
| | | |
| | |
| | | private DraftCNDBCursor draftCNDbCursor; |
| | | |
| | | /** |
| | | * Creates a new ReplicationIterator. All created iterator must be released by |
| | | * As underlying cursor is already pointing to a record at start, this |
| | | * indicator allow to shift the pointed record at initialization time. |
| | | */ |
| | | private boolean isInitialized = false; |
| | | |
| | | /** |
| | | * Creates a new DB Cursor. All created iterator must be released by |
| | | * the caller using the {@link #close()} method. |
| | | * |
| | | * @param db |
| | |
| | | { |
| | | try |
| | | { |
| | | return this.draftCNDbCursor.currentRecord(); |
| | | return isInitialized ? draftCNDbCursor.currentRecord() : null; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | |
| | | { |
| | | if (draftCNDbCursor != null) |
| | | { |
| | | return draftCNDbCursor.next(); |
| | | if (!isInitialized) |
| | | { |
| | | isInitialized = true; |
| | | return draftCNDbCursor.currentRecord() != null; |
| | | } |
| | | else |
| | | { |
| | | return draftCNDbCursor.next(); |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | |
| | | DBCursor<ChangeNumberIndexRecord> cursor = cnIndexDB.getCursorFrom(oldestCN); |
| | | try |
| | | { |
| | | assertTrue(cursor.next()); |
| | | assertEqualTo(cursor.getRecord(), csns[0], baseDN1, cookies.get(0)); |
| | | assertTrue(cursor.next()); |
| | | assertEqualTo(cursor.getRecord(), csns[1], baseDN2, cookies.get(1)); |
| | |
| | | DBCursor<ChangeNumberIndexRecord> cursor = cnIndexDB.getCursorFrom(changeNumber); |
| | | try |
| | | { |
| | | cursor.next(); |
| | | return cursor.getRecord().getPreviousCookie(); |
| | | } |
| | | finally |
| | |
| | | { |
| | | for (int i = 0; i < cns.length; i++) |
| | | { |
| | | assertTrue(cursor.next()); |
| | | assertEquals(cursor.getRecord().getChangeNumber(), cns[i]); |
| | | final boolean isNotLast = i + 1 < cns.length; |
| | | assertEquals(cursor.next(), isNotLast); |
| | | } |
| | | assertFalse(cursor.next()); |
| | | } |
| | | finally |
| | | { |
| | |
| | | DBCursor<ChangeNumberIndexRecord> cursor = cnIndexDB.getCursorFrom(oldestCN); |
| | | try |
| | | { |
| | | assertTrue(cursor.next()); |
| | | assertEqualTo(cursor.getRecord(), csns[0], baseDN1, cookies.get(0)); |
| | | assertTrue(cursor.next()); |
| | | assertEqualTo(cursor.getRecord(), csns[1], baseDN2, cookies.get(1)); |
| | |
| | | DBCursor<ChangeNumberIndexRecord> cursor = cnIndexDB.getCursorFrom(changeNumber); |
| | | try |
| | | { |
| | | cursor.next(); |
| | | return cursor.getRecord().getPreviousCookie(); |
| | | } |
| | | finally |
| | |
| | | { |
| | | for (int i = 0; i < cns.length; i++) |
| | | { |
| | | assertTrue(cursor.next()); |
| | | assertEquals(cursor.getRecord().getChangeNumber(), cns[i]); |
| | | final boolean isNotLast = i + 1 < cns.length; |
| | | assertEquals(cursor.next(), isNotLast); |
| | | } |
| | | assertFalse(cursor.next()); |
| | | } |
| | | finally |
| | | { |