Search in sources :

Example 16 with Directories

use of org.apache.cassandra.db.Directories in project cassandra by apache.

the class LogTransactionTest method testGetTemporaryFilesMultipleFolders.

@Test
public void testGetTemporaryFilesMultipleFolders() throws IOException {
    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) };
    // they should all have the same number of files since they are created in the same way
    int numSStableFiles = sstables[0].getAllFilePaths().size();
    LogTransaction log = new LogTransaction(OperationType.COMPACTION);
    assertNotNull(log);
    for (File dataFolder : new File[] { dataFolder1, dataFolder2 }) {
        Set<File> tmpFiles = getTemporaryFiles(dataFolder);
        assertNotNull(tmpFiles);
        assertEquals(0, tmpFiles.size());
    }
    LogTransaction.SSTableTidier[] tidiers = { log.obsoleted(sstables[0]), log.obsoleted(sstables[2]) };
    log.trackNew(sstables[1]);
    log.trackNew(sstables[3]);
    for (File dataFolder : new File[] { dataFolder1, dataFolder2 }) {
        Set<File> tmpFiles = getTemporaryFiles(dataFolder);
        assertNotNull(tmpFiles);
        assertEquals(numSStableFiles, tmpFiles.size());
    }
    log.finish();
    for (File dataFolder : new File[] { dataFolder1, dataFolder2 }) {
        Set<File> tmpFiles = getTemporaryFiles(dataFolder);
        assertNotNull(tmpFiles);
        assertEquals(numSStableFiles, tmpFiles.size());
    }
    sstables[0].markObsolete(tidiers[0]);
    sstables[2].markObsolete(tidiers[1]);
    Arrays.stream(sstables).forEach(s -> s.selfRef().release());
    LogTransaction.waitForDeletions();
    for (File dataFolder : new File[] { dataFolder1, dataFolder2 }) {
        Set<File> tmpFiles = getTemporaryFiles(dataFolder);
        assertNotNull(tmpFiles);
        assertEquals(0, tmpFiles.size());
    }
}
Also used : Directories(org.apache.cassandra.db.Directories) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test) AbstractTransactionalTest(org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)

Example 17 with Directories

use of org.apache.cassandra.db.Directories in project cassandra by apache.

the class LogTransactionTest method testAbortMultipleFolders.

@Test
public void testAbortMultipleFolders() 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]);
    Arrays.stream(tidiers).forEach(LogTransaction.SSTableTidier::abort);
    log.abort();
    Arrays.stream(sstables).forEach(s -> s.selfRef().release());
    LogTransaction.waitForDeletions();
    assertFiles(dataFolder1.getPath(), new HashSet<>(sstables[0].getAllFilePaths()));
    assertFiles(dataFolder2.getPath(), new HashSet<>(sstables[2].getAllFilePaths()));
}
Also used : Directories(org.apache.cassandra.db.Directories) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test) AbstractTransactionalTest(org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)

Example 18 with Directories

use of org.apache.cassandra.db.Directories in project cassandra by apache.

the class LogTransactionTest method testCommitSameDesc.

@Test
public void testCommitSameDesc() throws Throwable {
    ColumnFamilyStore cfs = MockSchema.newCFS(KEYSPACE);
    File dataFolder = new Directories(cfs.metadata()).getDirectoryForNewSSTables();
    SSTableReader sstableOld1 = sstable(dataFolder, cfs, 0, 128);
    SSTableReader sstableOld2 = sstable(dataFolder, cfs, 0, 256);
    SSTableReader sstableNew = sstable(dataFolder, cfs, 1, 128);
    LogTransaction log = new LogTransaction(OperationType.COMPACTION);
    assertNotNull(log);
    log.trackNew(sstableNew);
    sstableOld1.setReplaced();
    LogTransaction.SSTableTidier tidier = log.obsoleted(sstableOld2);
    assertNotNull(tidier);
    log.finish();
    sstableOld2.markObsolete(tidier);
    sstableOld1.selfRef().release();
    sstableOld2.selfRef().release();
    assertFiles(dataFolder.getPath(), new HashSet<>(sstableNew.getAllFilePaths()));
    sstableNew.selfRef().release();
}
Also used : Directories(org.apache.cassandra.db.Directories) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test) AbstractTransactionalTest(org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)

Example 19 with Directories

use of org.apache.cassandra.db.Directories in project cassandra by apache.

the class LogTransactionTest method testUntrack.

@Test
public void testUntrack() throws Throwable {
    ColumnFamilyStore cfs = MockSchema.newCFS(KEYSPACE);
    File dataFolder = new Directories(cfs.metadata()).getDirectoryForNewSSTables();
    SSTableReader sstableNew = sstable(dataFolder, cfs, 1, 128);
    // complete a transaction without keep the new files since they were untracked
    LogTransaction log = new LogTransaction(OperationType.COMPACTION);
    assertNotNull(log);
    log.trackNew(sstableNew);
    log.untrackNew(sstableNew);
    log.finish();
    sstableNew.selfRef().release();
    Thread.sleep(1);
    LogTransaction.waitForDeletions();
    assertFiles(dataFolder.getPath(), Collections.<String>emptySet());
}
Also used : Directories(org.apache.cassandra.db.Directories) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test) AbstractTransactionalTest(org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)

Aggregations

File (java.io.File)19 RandomAccessFile (java.io.RandomAccessFile)19 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)19 Directories (org.apache.cassandra.db.Directories)19 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)19 AbstractTransactionalTest (org.apache.cassandra.utils.concurrent.AbstractTransactionalTest)17 Test (org.junit.Test)17 ImmutableSet (com.google.common.collect.ImmutableSet)4 Iterables (com.google.common.collect.Iterables)1 Sets (com.google.common.collect.Sets)1 IOError (java.io.IOError)1 IOException (java.io.IOException)1 Files (java.nio.file.Files)1 java.util (java.util)1 BiConsumer (java.util.function.BiConsumer)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Assert (junit.framework.Assert)1 Assert.assertNotNull (junit.framework.Assert.assertNotNull)1 Assert.assertNull (junit.framework.Assert.assertNull)1