Search in sources :

Example 1 with DiskFailurePolicy

use of org.apache.cassandra.config.Config.DiskFailurePolicy in project cassandra by apache.

the class OutOfSpaceTest method testFlushUnwriteableDie.

@Test
public void testFlushUnwriteableDie() throws Throwable {
    makeTable();
    KillerForTests killerForTests = new KillerForTests();
    JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);
    DiskFailurePolicy oldPolicy = DatabaseDescriptor.getDiskFailurePolicy();
    try (Closeable c = Util.markDirectoriesUnwriteable(getCurrentColumnFamilyStore())) {
        DatabaseDescriptor.setDiskFailurePolicy(DiskFailurePolicy.die);
        flushAndExpectError();
        Assert.assertTrue(killerForTests.wasKilled());
        //only killed quietly on startup failure
        Assert.assertFalse(killerForTests.wasKilledQuietly());
    } finally {
        DatabaseDescriptor.setDiskFailurePolicy(oldPolicy);
        JVMStabilityInspector.replaceKiller(originalKiller);
    }
}
Also used : JVMStabilityInspector(org.apache.cassandra.utils.JVMStabilityInspector) KillerForTests(org.apache.cassandra.utils.KillerForTests) DiskFailurePolicy(org.apache.cassandra.config.Config.DiskFailurePolicy) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 2 with DiskFailurePolicy

use of org.apache.cassandra.config.Config.DiskFailurePolicy in project cassandra by apache.

the class OutOfSpaceTest method testFlushUnwriteableStop.

@Test
public void testFlushUnwriteableStop() throws Throwable {
    makeTable();
    DiskFailurePolicy oldPolicy = DatabaseDescriptor.getDiskFailurePolicy();
    try (Closeable c = Util.markDirectoriesUnwriteable(getCurrentColumnFamilyStore())) {
        DatabaseDescriptor.setDiskFailurePolicy(DiskFailurePolicy.stop);
        flushAndExpectError();
        Assert.assertFalse(Gossiper.instance.isEnabled());
    } finally {
        DatabaseDescriptor.setDiskFailurePolicy(oldPolicy);
    }
}
Also used : DiskFailurePolicy(org.apache.cassandra.config.Config.DiskFailurePolicy) Closeable(java.io.Closeable) Test(org.junit.Test)

Example 3 with DiskFailurePolicy

use of org.apache.cassandra.config.Config.DiskFailurePolicy in project cassandra by apache.

the class DirectoriesTest method testDiskFailurePolicy_best_effort.

@Test
public void testDiskFailurePolicy_best_effort() {
    DiskFailurePolicy origPolicy = DatabaseDescriptor.getDiskFailurePolicy();
    try {
        DatabaseDescriptor.setDiskFailurePolicy(DiskFailurePolicy.best_effort);
        // Fake a Directory creation failure
        if (Directories.dataDirectories.length > 0) {
            String[] path = new String[] { KS, "bad" };
            File dir = new File(Directories.dataDirectories[0].location, StringUtils.join(path, File.separator));
            FileUtils.handleFSError(new FSWriteError(new IOException("Unable to create directory " + dir), dir));
        }
        for (DataDirectory dd : Directories.dataDirectories) {
            File file = new File(dd.location, new File(KS, "bad").getPath());
            assertTrue(BlacklistedDirectories.isUnwritable(file));
        }
    } finally {
        DatabaseDescriptor.setDiskFailurePolicy(origPolicy);
    }
}
Also used : DiskFailurePolicy(org.apache.cassandra.config.Config.DiskFailurePolicy) FSWriteError(org.apache.cassandra.io.FSWriteError) DataDirectory(org.apache.cassandra.db.Directories.DataDirectory) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test)

Example 4 with DiskFailurePolicy

use of org.apache.cassandra.config.Config.DiskFailurePolicy in project cassandra by apache.

the class CommitLogTest method testUnwriteableFlushRecovery.

public void testUnwriteableFlushRecovery() throws ExecutionException, InterruptedException, IOException {
    CommitLog.instance.resetUnsafe(true);
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(STANDARD1);
    DiskFailurePolicy oldPolicy = DatabaseDescriptor.getDiskFailurePolicy();
    try {
        DatabaseDescriptor.setDiskFailurePolicy(DiskFailurePolicy.ignore);
        for (int i = 0; i < 5; i++) {
            new RowUpdateBuilder(cfs.metadata(), 0, "k").clustering("c" + i).add("val", ByteBuffer.allocate(100)).build().apply();
            if (i == 2) {
                try (Closeable c = Util.markDirectoriesUnwriteable(cfs)) {
                    cfs.forceBlockingFlush();
                } catch (Throwable t) {
                    // expected. Cause (after some wrappings) should be a write error
                    while (!(t instanceof FSWriteError)) t = t.getCause();
                }
            } else
                cfs.forceBlockingFlush();
        }
    } finally {
        DatabaseDescriptor.setDiskFailurePolicy(oldPolicy);
    }
    CommitLog.instance.sync();
    System.setProperty("cassandra.replayList", KEYSPACE1 + "." + STANDARD1);
    // Currently we don't attempt to re-flush a memtable that failed, thus make sure data is replayed by commitlog.
    // If retries work subsequent flushes should clear up error and this should change to expect 0.
    Assert.assertEquals(1, CommitLog.instance.resetUnsafe(false));
}
Also used : DiskFailurePolicy(org.apache.cassandra.config.Config.DiskFailurePolicy) FSWriteError(org.apache.cassandra.io.FSWriteError)

Example 5 with DiskFailurePolicy

use of org.apache.cassandra.config.Config.DiskFailurePolicy in project cassandra by apache.

the class OutOfSpaceTest method testFlushUnwriteableIgnore.

@Test
public void testFlushUnwriteableIgnore() throws Throwable {
    makeTable();
    DiskFailurePolicy oldPolicy = DatabaseDescriptor.getDiskFailurePolicy();
    try (Closeable c = Util.markDirectoriesUnwriteable(getCurrentColumnFamilyStore())) {
        DatabaseDescriptor.setDiskFailurePolicy(DiskFailurePolicy.ignore);
        flushAndExpectError();
    } finally {
        DatabaseDescriptor.setDiskFailurePolicy(oldPolicy);
    }
    // Next flush should succeed.
    flush();
}
Also used : DiskFailurePolicy(org.apache.cassandra.config.Config.DiskFailurePolicy) Closeable(java.io.Closeable) Test(org.junit.Test)

Aggregations

DiskFailurePolicy (org.apache.cassandra.config.Config.DiskFailurePolicy)5 Test (org.junit.Test)4 Closeable (java.io.Closeable)3 FSWriteError (org.apache.cassandra.io.FSWriteError)2 File (java.io.File)1 IOException (java.io.IOException)1 DataDirectory (org.apache.cassandra.db.Directories.DataDirectory)1 JVMStabilityInspector (org.apache.cassandra.utils.JVMStabilityInspector)1 KillerForTests (org.apache.cassandra.utils.KillerForTests)1