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

ian.packer
22.05.2016 61aad5b3ed8c70c8fa83494b0b2d3591eb420b81
OPENDJ-3237: Make read/writing offline.state files more robust

1) If an offline.state file becomes empty, ignore and log a warning rather than prevent the server starting.
2) When writing the file, don't ignore exceptions on closing, this should cause a failed write to surface earlier.
2 files modified
16 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/ReplicationEnvironment.java 9 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/replication/server/changelog/file/ReplicationEnvironmentTest.java 7 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/replication/server/changelog/file/ReplicationEnvironment.java
@@ -531,7 +531,7 @@
      {
        // Only the last sent offline CSN is kept
        writer.write(offlineCSN.toString());
        StaticUtils.close(writer);
        writer.close();
        changelogState.addOfflineReplica(domainDN, offlineCSN);
        commitFile(offlineFile);
      }
@@ -669,6 +669,8 @@
  {
    state.addServerIdToDomain(toServerId(serverIdPath.getName()), domainDN);
    try
    {
    final File offlineFile = new File(serverIdPath, REPLICA_OFFLINE_STATE_FILENAME);
    if (offlineFile.exists())
    {
@@ -676,6 +678,11 @@
      state.addOfflineReplica(domainDN, offlineCSN);
    }
  }
    catch(ChangelogException ce)
    {
      logger.warn(getExceptionMessage(ce));
    }
  }
  private CSN readOfflineStateFile(final File offlineFile, DN domainDN) throws ChangelogException
  {
opendj-server-legacy/src/test/java/org/opends/server/replication/server/changelog/file/ReplicationEnvironmentTest.java
@@ -172,7 +172,7 @@
    }
  }
  @Test(expectedExceptions=ChangelogException.class)
  @Test
  public void testReadChangelogStateWithReplicaOfflineStateFileCorrupted() throws Exception
  {
    Log<Long,ChangeNumberIndexRecord> cnDB = null;
@@ -188,7 +188,10 @@
      File offlineStateFile = new File(environment.getServerIdPath("1", 1), REPLICA_OFFLINE_STATE_FILENAME);
      offlineStateFile.createNewFile();
      environment.readOnDiskChangelogState();
      // If the offline state file is not readable, the best we can do is continue as if the file wasn't there at all
      final ChangelogState state = environment.readOnDiskChangelogState();
      assertThat(state.getOfflineReplicas()).isEmpty();
      assertThat(state.isEqualTo(environment.getChangelogState())).isTrue();
    }
    finally
    {