zookeeper-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [zookeeper] anmolnar commented on a change in pull request #1079: ZOOKEEPER-3231:Purge task may lost data when the recent snapshots are all invalid
Date Wed, 18 Sep 2019 14:59:23 GMT
anmolnar commented on a change in pull request #1079: ZOOKEEPER-3231:Purge task may lost data
when the recent snapshots are all invalid
URL: https://github.com/apache/zookeeper/pull/1079#discussion_r325727027
 
 

 ##########
 File path: zookeeper-server/src/test/java/org/apache/zookeeper/server/PurgeTxnTest.java
 ##########
 @@ -484,6 +494,48 @@ public void testPurgeDoesNotDeleteOverlappingLogFile() throws Exception
{
         zks.shutdown();
     }
 
+    @Test
+    public void testPurgeTxnLogWhenRecentSnapshotsAreAllInvalid() throws Exception {
+        tmpDir = ClientBase.createTmpDir();
+        File dataDir = new File(tmpDir, "dataDir");
+        File dataLogDir = new File(tmpDir, "dataLogDir");
+
+        File dataDirVersion2 = new File(dataDir, "version-2");
+        dataDirVersion2.mkdirs();
+        File dataLogDirVersion2 = new File(dataLogDir, "version-2");
+        dataLogDirVersion2.mkdirs();
+
+        // create dummy log and transaction file
+        int totalFiles = 10;
+        int numberOfSnapFilesToKeep = 3;
+
+        // create transaction and snapshot files in different-different
+        // directories
+        for (int i = 0; i < totalFiles; i++) {
+            // simulate log file
+            File logFile = new File(dataLogDirVersion2, "log." + Long.toHexString(i));
+            logFile.createNewFile();
+            // simulate snapshot file
+            File snapFile = new File(dataDirVersion2, "snapshot." + Long.toHexString(i));
+            snapFile.createNewFile();
+            if (i < (totalFiles - numberOfSnapFilesToKeep)) {
+                makeValidSnapshot(snapFile);
+            } else {
+                makeInvalidSnapshot(snapFile);
+            }
+        }
+
+        // scenario where four parameter are passed
+        String[] args = new String[]{dataLogDir.getAbsolutePath(), dataDir.getAbsolutePath(),
"-n", Integer.toString(numberOfSnapFilesToKeep)};
+        PurgeTxnLog.main(args);
+        //Since the recent 3 snapshots are all invalid,when purging, we can assert that 6
snapshot files are retained(3 invalid snapshots and 3 retained valid snapshots)
+        assertEquals(numberOfSnapFilesToKeep + numberOfSnapFilesToKeep, dataDirVersion2.listFiles().length);
+        // Since for each snapshot we have a log file with same zxid, expect same # logs
as snaps to be kept
+        assertEquals(numberOfSnapFilesToKeep + numberOfSnapFilesToKeep, dataLogDirVersion2.listFiles().length);
+        ClientBase.recursiveDelete(tmpDir);
 
 Review comment:
   Also this should be in `tearDown()`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message