diff --git a/dump/src/util/dump/Dump.java b/dump/src/util/dump/Dump.java index 579abd3..e35cf91 100644 --- a/dump/src/util/dump/Dump.java +++ b/dump/src/util/dump/Dump.java @@ -272,10 +272,9 @@ public Dump( Class beanClass, ObjectStreamProvider streamProvider, readDeletions(); initMeta(); + checkVersion(); if ( !isReadonly() ) { - checkVersion(); - if ( shouldBePruned() ) { StopWatch t = new StopWatch(); _log.info("need to prune {} deleted entries from {}", _deletedPositions.size(), _dumpFile); @@ -1108,27 +1107,44 @@ private void checkVersion() throws IOException { int dumpVersion = getVersionFromDump(); if ( dumpVersion != codeVersion ) { if ( _dumpFile.exists() ) { - switch ( getOnIncompatibleVersion() ) { - case RenameDump: { - _log.warn("externalizationVersion in dump {} does not match current version {}, will rename old dump files", dumpVersion, codeVersion); - renameFile(_dumpFile, new File(_dumpFile.getAbsolutePath() + ".version" + dumpVersion)); - renameFile(_deletionsFile, new File(_deletionsFile.getAbsolutePath() + ".version" + dumpVersion)); - resetMeta(); - break; - } - case DeleteDump: { - _log.warn("externalizationVersion in dump {} does not match current version {}, will delete old dump files", dumpVersion, codeVersion); - deleteFile(_dumpFile); - deleteFile(_deletionsFile); - resetMeta(); - break; - } - case RewriteDump: { - StopWatch t = new StopWatch(); - _log.warn("externalizationVersion in dump {} does not match current version {}, will rewrite dump files", dumpVersion, codeVersion); - prune(); // has its own way of meta invalidation - _log.info("...rewrote dump {} in {}", _dumpFile, t); - } + final String msg = "externalizationVersion in dump {} does not match current version {}, {}"; + + if ( isReadonly() ) { + _log.warn(msg, dumpVersion, codeVersion, "not doing anything due to read-only mode"); + switch ( getOnIncompatibleVersion() ) { + case RenameDump: { + throw new AccessControlException("Renaming Dump is not allowed in read-only mode."); + } + case DeleteDump: { + throw new AccessControlException("Deleting Dump is not allowed in read-only mode."); + } + case RewriteDump: { + // do nothing, allowing potential readers to write the contents to some other dump in proper externalization version + } + } + } else { + switch ( getOnIncompatibleVersion() ) { + case RenameDump: { + _log.warn(msg, dumpVersion, codeVersion, "will rename old dump files"); + renameFile(_dumpFile, new File(_dumpFile.getAbsolutePath() + ".version" + dumpVersion)); + renameFile(_deletionsFile, new File(_deletionsFile.getAbsolutePath() + ".version" + dumpVersion)); + resetMeta(); + break; + } + case DeleteDump: { + _log.warn(msg, dumpVersion, codeVersion, "will delete old dump files"); + deleteFile(_dumpFile); + deleteFile(_deletionsFile); + resetMeta(); + break; + } + case RewriteDump: { + StopWatch t = new StopWatch(); + _log.warn(msg, dumpVersion, codeVersion, "will rewrite dump files"); + prune(); // has its own way of meta invalidation + _log.info("...rewrote dump {} in {}", _dumpFile, t); + } + } } } }