mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Fabio Pistolesi
02.09.2015 24d7644bb126bc3d798b49208d74a22e86d13f49
opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/BlockLogReader.java
@@ -620,4 +620,23 @@
   }
 }
Record<K, V> getNewestRecord() throws ChangelogException
 {
   try {
     final long lastBlockStart = getClosestBlockStartBeforeOrAtPosition(getFileLength());
     positionToRecordFromBlockStart(lastBlockStart);
     ByteString candidate = readNextRecord();
     ByteString record = candidate;
     while (candidate != null)
     {
       record = candidate;
       candidate = readNextRecord();
     }
     return record == null ? null : parser.decodeRecord(record);
   }
   catch (IOException e)
   {
     throw new ChangelogException(ERR_CHANGELOG_CANNOT_READ_NEWEST_RECORD.get(file.getPath()), e);
   }
 }
}
opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/LogFile.java
@@ -80,6 +80,8 @@
  /** Indicates if log is enabled for write. */
  private final boolean isWriteEnabled;
  private Record<K, V> newestRecord;
  /**
   * Creates a new log file.
   *
@@ -243,6 +245,7 @@
  {
    checkLogIsEnabledForWrite();
    writer.write(record);
    newestRecord = record;
  }
  /**
@@ -366,22 +369,11 @@
   */
  Record<K, V> getNewestRecord() throws ChangelogException
  {
    // TODO : need a more efficient way to retrieve it
    DBCursor<Record<K, V>> cursor = null;
    try
    if (newestRecord == null)
    {
      cursor = getCursor();
      Record<K, V> record = null;
      while (cursor.next())
      {
        record = cursor.getRecord();
      }
      return record;
      newestRecord = getReader().getNewestRecord();
    }
    finally
    {
      StaticUtils.close(cursor);
    }
    return newestRecord;
  }
  /**
opendj-server-legacy/src/messages/org/opends/messages/replication.properties
@@ -629,4 +629,6 @@
ERR_CHANGELOG_UNABLE_TO_DELETE_LAST_LOG_ROTATION_TIME_FILE_289=Could not delete \
 file '%s' that stored the previous last log rotation time
ERR_CHANGELOG_CURSOR_ABORTED_290=Cursor on log '%s' has been aborted after \
 a purge or a clear
 a purge or a clear
ERR_CHANGELOG_CANNOT_READ_NEWEST_RECORD_291=Could not position and read newest record from log file '%s'
opendj-server-legacy/src/test/java/org/opends/server/replication/server/changelog/file/LogFileTest.java
@@ -270,12 +270,11 @@
    }
  }
  /** Test that changes are visible immediately to a reader after a write. */
  /** Test that changes are properly ordered. */
  @Test
  public void testWriteAndReadOnSameLogFile() throws Exception
  public void testAppendingChangesAreOrdered() throws Exception
  {
    try (LogFile<String, String> writeLog = getLogFile(RECORD_PARSER);
        LogFile<String, String> readLog = getLogFile(RECORD_PARSER))
    try (LogFile<String, String> writeLog = getLogFile(RECORD_PARSER))
    {
      for (int i = 1; i <= 100; i++)
      {
@@ -283,8 +282,6 @@
        writeLog.append(record);
        assertThat(writeLog.getNewestRecord()).as("write changelog " + i).isEqualTo(record);
        assertThat(writeLog.getOldestRecord()).as("write changelog " + i).isEqualTo(Record.from("key01", "value1"));
        assertThat(readLog.getNewestRecord()).as("read changelog " + i).isEqualTo(record);
        assertThat(readLog.getOldestRecord()).as("read changelog " + i).isEqualTo(Record.from("key01", "value1"));
      }
    }
  }