Java Code Examples for org.apache.cassandra.config.DatabaseDescriptor#getDiskFailurePolicy()

The following examples show how to use org.apache.cassandra.config.DatabaseDescriptor#getDiskFailurePolicy() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JVMStabilityInspector.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Certain Throwables and Exceptions represent "Die" conditions for the server.
 * @param t
 *      The Throwable to check for server-stop conditions
 */
public static void inspectThrowable(Throwable t)
{
    boolean isUnstable = false;
    if (t instanceof OutOfMemoryError)
        isUnstable = true;

    if (DatabaseDescriptor.getDiskFailurePolicy() == Config.DiskFailurePolicy.die)
        if (t instanceof FSError || t instanceof CorruptSSTableException)
        isUnstable = true;

    // Check for file handle exhaustion
    if (t instanceof FileNotFoundException || t instanceof SocketException)
        if (t.getMessage().contains("Too many open files"))
            isUnstable = true;

    if (isUnstable)
        killer.killCurrentJVM(t);
}
 
Example 2
Source File: FileUtils.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static void handleFSError(FSError e)
{
    JVMStabilityInspector.inspectThrowable(e);
    switch (DatabaseDescriptor.getDiskFailurePolicy())
    {
        case stop_paranoid:
        case stop:
            StorageService.instance.stopTransports();
            break;
        case best_effort:
            // for both read and write errors mark the path as unwritable.
            BlacklistedDirectories.maybeMarkUnwritable(e.path);
            if (e instanceof FSReadError)
            {
                File directory = BlacklistedDirectories.maybeMarkUnreadable(e.path);
                if (directory != null)
                    Keyspace.removeUnreadableSSTables(directory);
            }
            break;
        case ignore:
            // already logged, so left nothing to do
            break;
        default:
            throw new IllegalStateException();
    }
}
 
Example 3
Source File: FileUtils.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public static void handleCorruptSSTable(CorruptSSTableException e)
{
    JVMStabilityInspector.inspectThrowable(e);
    switch (DatabaseDescriptor.getDiskFailurePolicy())
    {
        case stop_paranoid:
            StorageService.instance.stopTransports();
            break;
    }
}
 
Example 4
Source File: JVMStabilityInspectorTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testKill() throws Exception
{
    KillerForTests killerForTests = new KillerForTests();
    JVMStabilityInspector.Killer originalKiller = JVMStabilityInspector.replaceKiller(killerForTests);

    Config.DiskFailurePolicy oldPolicy = DatabaseDescriptor.getDiskFailurePolicy();
    Config.CommitFailurePolicy oldCommitPolicy = DatabaseDescriptor.getCommitFailurePolicy();
    try
    {
        killerForTests.reset();
        JVMStabilityInspector.inspectThrowable(new IOException());
        assertFalse(killerForTests.wasKilled());

        killerForTests.reset();
        JVMStabilityInspector.inspectThrowable(new OutOfMemoryError());
        assertTrue(killerForTests.wasKilled());

        DatabaseDescriptor.setDiskFailurePolicy(Config.DiskFailurePolicy.die);
        killerForTests.reset();
        JVMStabilityInspector.inspectThrowable(new FSReadError(new IOException(), "blah"));
        assertTrue(killerForTests.wasKilled());

        DatabaseDescriptor.setCommitFailurePolicy(Config.CommitFailurePolicy.die);
        killerForTests.reset();
        JVMStabilityInspector.inspectCommitLogThrowable(new Throwable());
        assertTrue(killerForTests.wasKilled());
    }
    finally
    {
        JVMStabilityInspector.replaceKiller(originalKiller);
        DatabaseDescriptor.setDiskFailurePolicy(oldPolicy);
        DatabaseDescriptor.setCommitFailurePolicy(oldCommitPolicy);
    }
}
 
Example 5
Source File: DirectoriesTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@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);
    }
}