void assertInProgress() throws Exception { assertFiles( dataFolder.getPath(), Sets.newHashSet( Iterables.concat( sstableNew.getAllFilePaths(), sstableOld.getAllFilePaths(), txnLogs.logFilePaths()))); }
private static void testCorruptRecord( BiConsumer<LogTransaction, SSTableReader> modifier, boolean isRecoverable) throws IOException { ColumnFamilyStore cfs = MockSchema.newCFS(KEYSPACE); File dataFolder = new Directories(cfs.metadata).getDirectoryForNewSSTables(); SSTableReader sstableOld = sstable(dataFolder, cfs, 0, 128); SSTableReader sstableNew = sstable(dataFolder, cfs, 1, 128); // simulate tracking sstables with a committed transaction except the checksum will be wrong LogTransaction log = new LogTransaction(OperationType.COMPACTION); assertNotNull(log); log.trackNew(sstableNew); log.obsoleted(sstableOld); // Modify the transaction log or disk state for sstableOld modifier.accept(log, sstableOld); assertNull(log.complete(null)); sstableOld.selfRef().release(); sstableNew.selfRef().release(); // The files on disk, for old files make sure to exclude the files that were deleted by the // modifier Set<String> newFiles = sstableNew.getAllFilePaths().stream().collect(Collectors.toSet()); Set<String> oldFiles = sstableOld .getAllFilePaths() .stream() .filter(p -> new File(p).exists()) .collect(Collectors.toSet()); // This should filter as in progress since the last record is corrupt assertFiles(newFiles, getTemporaryFiles(dataFolder)); assertFiles(oldFiles, getFinalFiles(dataFolder)); if (isRecoverable) { // the corruption is recoverable but the commit record is unreadable so the // transaction is still in progress // This should remove new files LogTransaction.removeUnfinishedLeftovers(cfs.metadata); // make sure to exclude the old files that were deleted by the modifier assertFiles(dataFolder.getPath(), oldFiles); } else { // if an intermediate line was also modified, it should ignore the tx log file // This should not remove any files LogTransaction.removeUnfinishedLeftovers(cfs.metadata); assertFiles( dataFolder.getPath(), Sets.newHashSet(Iterables.concat(newFiles, oldFiles, log.logFilePaths()))); } }
private static void testObsoletedFilesChanged(Consumer<SSTableReader> modifier) throws IOException { ColumnFamilyStore cfs = MockSchema.newCFS(KEYSPACE); File dataFolder = new Directories(cfs.metadata).getDirectoryForNewSSTables(); SSTableReader sstableOld = sstable(dataFolder, cfs, 0, 128); SSTableReader sstableNew = sstable(dataFolder, cfs, 1, 128); // simulate tracking sstables with a committed transaction except the checksum will be wrong LogTransaction log = new LogTransaction(OperationType.COMPACTION); assertNotNull(log); log.trackNew(sstableNew); /*TransactionLog.SSTableTidier tidier =*/ log.obsoleted(sstableOld); // modify the old sstable files modifier.accept(sstableOld); // Fake a commit log.txnFile().commit(); // This should not remove the old files LogTransaction.removeUnfinishedLeftovers(cfs.metadata); assertFiles( dataFolder.getPath(), Sets.newHashSet( Iterables.concat( sstableNew.getAllFilePaths(), sstableOld.getAllFilePaths(), log.logFilePaths()))); sstableOld.selfRef().release(); sstableNew.selfRef().release(); // complete the transaction to avoid LEAK errors assertNull(log.complete(null)); assertFiles( dataFolder.getPath(), Sets.newHashSet( Iterables.concat( sstableNew.getAllFilePaths(), sstableOld.getAllFilePaths(), log.logFilePaths()))); }
private static void testRemoveUnfinishedLeftovers_multipleFolders_errorConditions( Consumer<LogTransaction> modifier, boolean shouldCommit) throws Throwable { ColumnFamilyStore cfs = MockSchema.newCFS(KEYSPACE); File origiFolder = new Directories(cfs.metadata).getDirectoryForNewSSTables(); File dataFolder1 = new File(origiFolder, "1"); File dataFolder2 = new File(origiFolder, "2"); Files.createDirectories(dataFolder1.toPath()); Files.createDirectories(dataFolder2.toPath()); SSTableReader[] sstables = { sstable(dataFolder1, cfs, 0, 128), sstable(dataFolder1, cfs, 1, 128), sstable(dataFolder2, cfs, 2, 128), sstable(dataFolder2, cfs, 3, 128) }; LogTransaction log = new LogTransaction(OperationType.COMPACTION); assertNotNull(log); LogTransaction.SSTableTidier[] tidiers = { log.obsoleted(sstables[0]), log.obsoleted(sstables[2]) }; log.trackNew(sstables[1]); log.trackNew(sstables[3]); // fake some error condition on the txn logs modifier.accept(log); Arrays.stream(sstables).forEach(s -> s.selfRef().release()); LogTransaction.removeUnfinishedLeftovers(Arrays.asList(dataFolder1, dataFolder2)); LogTransaction.waitForDeletions(); if (shouldCommit) { // only new sstables should still be there assertFiles(dataFolder1.getPath(), new HashSet<>(sstables[1].getAllFilePaths())); assertFiles(dataFolder2.getPath(), new HashSet<>(sstables[3].getAllFilePaths())); } else { // all files should still be there assertFiles( dataFolder1.getPath(), Sets.newHashSet( Iterables.concat( sstables[0].getAllFilePaths(), sstables[1].getAllFilePaths(), Collections.singleton(log.logFilePaths().get(0))))); assertFiles( dataFolder2.getPath(), Sets.newHashSet( Iterables.concat( sstables[2].getAllFilePaths(), sstables[3].getAllFilePaths(), Collections.singleton(log.logFilePaths().get(1))))); } // complete the transaction to avoid LEAK errors Arrays.stream(tidiers).forEach(LogTransaction.SSTableTidier::run); log.txnFile().commit(); // just anything to make sure transaction tidier will finish assertNull(log.complete(null)); }