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.
| | |
| | | { |
| | | // Only the last sent offline CSN is kept |
| | | writer.write(offlineCSN.toString()); |
| | | StaticUtils.close(writer); |
| | | writer.close(); |
| | | changelogState.addOfflineReplica(domainDN, offlineCSN); |
| | | commitFile(offlineFile); |
| | | } |
| | |
| | | { |
| | | state.addServerIdToDomain(toServerId(serverIdPath.getName()), domainDN); |
| | | |
| | | try |
| | | { |
| | | final File offlineFile = new File(serverIdPath, REPLICA_OFFLINE_STATE_FILENAME); |
| | | if (offlineFile.exists()) |
| | | { |
| | |
| | | state.addOfflineReplica(domainDN, offlineCSN); |
| | | } |
| | | } |
| | | catch(ChangelogException ce) |
| | | { |
| | | logger.warn(getExceptionMessage(ce)); |
| | | } |
| | | } |
| | | |
| | | private CSN readOfflineStateFile(final File offlineFile, DN domainDN) throws ChangelogException |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | @Test(expectedExceptions=ChangelogException.class) |
| | | @Test |
| | | public void testReadChangelogStateWithReplicaOfflineStateFileCorrupted() throws Exception |
| | | { |
| | | Log<Long,ChangeNumberIndexRecord> cnDB = null; |
| | |
| | | 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 |
| | | { |