Github user anmolnar commented on a diff in the pull request: https://github.com/apache/zookeeper/pull/450#discussion_r162929390 --- Diff: src/java/main/org/apache/zookeeper/server/persistence/FileTxnSnapLog.java --- @@ -136,13 +136,51 @@ public FileTxnSnapLog(File dataDir, File snapDir) throws IOException { throw new DatadirException("Cannot write to snap directory " + this.snapDir); } + // check content of transaction log and snapshot dirs if they are two different directories + if(!this.dataDir.getPath().equals(this.snapDir.getPath())){ + checkLogDir(); + checkSnapDir(); + } + txnLog = new FileTxnLog(this.dataDir); snapLog = new FileSnap(this.snapDir); autoCreateDB = Boolean.parseBoolean(System.getProperty(ZOOKEEPER_DB_AUTOCREATE, ZOOKEEPER_DB_AUTOCREATE_DEFAULT)); } + private void checkLogDir() throws LogdirContentCheckException { + File[] files = this.dataDir.listFiles(); + if(files != null) { + boolean hasSnapshotFiles = false; + for (File file : files) { + if(Util.isSnapshotFile(file)){ + hasSnapshotFiles = true; + break; + } + } + if (hasSnapshotFiles) { + throw new LogdirContentCheckException("Log directory has snapshot files. Check if dataLogDir and dataDir configuration is correct."); + } + } + } + + private void checkSnapDir() throws SnapdirContentCheckException { + File[] files = this.snapDir.listFiles(); --- End diff -- Same here. Get files with fileNameFilter and if it returns non-empty array, throw exception.
---