Search in sources :

Example 11 with PersistenceFailureException

use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.

the class MysqlStorageEngine method tableExists.

private boolean tableExists() {
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    String select = "show tables like '" + getName() + "'";
    try {
        conn = this.datasource.getConnection();
        stmt = conn.prepareStatement(select);
        rs = stmt.executeQuery();
        return rs.next();
    } catch (SQLException e) {
        throw new PersistenceFailureException("SQLException while checking for table existence!", e);
    } finally {
        tryClose(rs);
        tryClose(stmt);
        tryClose(conn);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Example 12 with PersistenceFailureException

use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.

the class AdminServiceRequestHandler method handleDisableStoreVersion.

private Message handleDisableStoreVersion(VAdminProto.DisableStoreVersionRequest disableStoreVersion) {
    String storeName = disableStoreVersion.getStoreName();
    Long version = disableStoreVersion.getPushVersion();
    Properties properties = new Properties();
    try {
        properties.load(new StringReader(disableStoreVersion.getInfo()));
    } catch (IOException e) {
        logger.error("Got IOException while trying to decipher a DisableStoreVersionRequest's info.", e);
    }
    logger.info("Received DisableStoreVersionRequest:\n" + "\tstore_name: " + storeName + "\n" + "\tpush_version: " + version + "\n" + "\tinfo: " + properties.toString());
    VAdminProto.DisableStoreVersionResponse.Builder response = VAdminProto.DisableStoreVersionResponse.newBuilder();
    response.setNodeId(server.getMetadataStore().getNodeId());
    final String logMessagePrefix = "handleDisableStoreVersion returning response: ";
    try {
        StorageEngine storeToDisable = storeRepository.getStorageEngine(storeName);
        if (storeToDisable == null) {
            response.setDisableSuccess(false).setInfo("The store '" + storeName + "' does not exist!");
        } else {
            StoreVersionManager storeVersionManager = (StoreVersionManager) storeToDisable.getCapability(StoreCapabilityType.DISABLE_STORE_VERSION);
            storeVersionManager.disableStoreVersion(version);
            response.setDisableSuccess(true).setDisablePersistenceSuccess(true).setInfo("The store '" + storeName + "' version " + version + " was successfully disabled.");
        }
        logger.info(logMessagePrefix + response.getInfo());
    } catch (PersistenceFailureException e) {
        String message = "The store '" + storeName + "' version " + version + " was disabled" + " but the change could not be persisted and will thus remain in effect only" + " until the next server restart. This is likely caused by the IO subsystem" + " becoming read-only.";
        logger.error(logMessagePrefix + message, e);
        response.setDisableSuccess(true).setDisablePersistenceSuccess(false).setInfo(message);
    } catch (NoSuchCapabilityException e) {
        String message = "The store '" + storeName + "' does not support disabling versions!";
        logger.error(logMessagePrefix + message, e);
        response.setDisableSuccess(false).setInfo(message);
    } catch (Exception e) {
        String message = "The store '" + storeName + "' version " + version + " was not disabled because of an unexpected exception.";
        logger.error(logMessagePrefix + message, e);
        response.setDisableSuccess(false).setInfo(message);
    }
    if (response.getDisableSuccess()) {
        // Then we also want to put the server in offline mode
        VAdminProto.SetOfflineStateRequest offlineStateRequest = VAdminProto.SetOfflineStateRequest.newBuilder().setOfflineMode(true).build();
        handleSetOfflineState(offlineStateRequest);
    }
    return response.build();
}
Also used : StoreVersionManager(voldemort.store.readonly.StoreVersionManager) NoSuchCapabilityException(voldemort.store.NoSuchCapabilityException) IOException(java.io.IOException) Properties(java.util.Properties) MysqlStorageEngine(voldemort.store.mysql.MysqlStorageEngine) StorageEngine(voldemort.store.StorageEngine) SlopStorageEngine(voldemort.store.slop.SlopStorageEngine) ReadOnlyStorageEngine(voldemort.store.readonly.ReadOnlyStorageEngine) PersistenceFailureException(voldemort.store.PersistenceFailureException) NoSuchCapabilityException(voldemort.store.NoSuchCapabilityException) ConfigurationException(voldemort.utils.ConfigurationException) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) StoreOperationFailureException(voldemort.store.StoreOperationFailureException) VoldemortException(voldemort.VoldemortException) IOException(java.io.IOException) PersistenceFailureException(voldemort.store.PersistenceFailureException) StoreNotFoundException(voldemort.store.StoreNotFoundException) StringReader(java.io.StringReader) VAdminProto(voldemort.client.protocol.pb.VAdminProto)

Example 13 with PersistenceFailureException

use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.

the class BdbStorageEngineTest method testPutAndLock.

@Test(timeout = 30000)
public void testPutAndLock() throws Exception {
    final ByteArray key = new ByteArray("putAndLock".getBytes());
    final byte[] valueBytes = "Lion".getBytes();
    store.put(key, new Versioned<byte[]>(valueBytes), null);
    // begin the read-modify-write cycle
    KeyLockHandle<byte[]> handle = store.getAndLock(key);
    // put will block and timeout
    try {
        store.put(key, new Versioned<byte[]>("Mountain Lion".getBytes()), null);
        fail("put(..) should have blocked and timedout");
    } catch (PersistenceFailureException pfe) {
        // expected
        assertTrue("Should have had a LockTimeoutException", pfe.getCause() instanceof LockTimeoutException);
    }
    // end the read-modify-write cycle
    handle.setValues(Lists.newArrayList(new Versioned<byte[]>("Mavericks".getBytes())));
    store.putAndUnlock(key, handle);
    // get should not block, and read out Mavericks
    List<Versioned<byte[]>> vals = store.get(key, null);
    assertEquals("Exactly one version", 1, vals.size());
    assertEquals("Should read back the version written by putAndUnlock", "Mavericks", new String(vals.get(0).getValue()));
}
Also used : Versioned(voldemort.versioning.Versioned) ByteArray(voldemort.utils.ByteArray) PersistenceFailureException(voldemort.store.PersistenceFailureException) LockTimeoutException(com.sleepycat.je.LockTimeoutException) AbstractStorageEngineTest(voldemort.store.AbstractStorageEngineTest) Test(org.junit.Test)

Example 14 with PersistenceFailureException

use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.

the class MysqlStorageEngine method delete.

@Override
public boolean delete(ByteArray key, Version maxVersion) throws PersistenceFailureException {
    StoreUtils.assertValidKey(key);
    Connection conn = null;
    PreparedStatement selectStmt = null;
    ResultSet rs = null;
    String select = "select version_ from " + getName() + " where key_ = ? for update";
    try {
        conn = datasource.getConnection();
        selectStmt = conn.prepareStatement(select);
        selectStmt.setBytes(1, key.get());
        rs = selectStmt.executeQuery();
        boolean deletedSomething = false;
        while (rs.next()) {
            byte[] version = rs.getBytes("version_");
            if ((maxVersion == null) || (new VectorClock(version).compare(maxVersion) == Occurred.BEFORE)) {
                delete(conn, key.get(), version);
                deletedSomething = true;
            }
        }
        return deletedSomething;
    } catch (SQLException e) {
        throw new PersistenceFailureException("Fix me!", e);
    } finally {
        tryClose(rs);
        tryClose(selectStmt);
        tryClose(conn);
    }
}
Also used : SQLException(java.sql.SQLException) VectorClock(voldemort.versioning.VectorClock) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Example 15 with PersistenceFailureException

use of voldemort.store.PersistenceFailureException in project voldemort by voldemort.

the class MysqlStorageEngine method execute.

public void execute(String query) {
    Connection conn = null;
    PreparedStatement stmt = null;
    try {
        conn = datasource.getConnection();
        stmt = conn.prepareStatement(query);
        stmt.executeUpdate();
    } catch (SQLException e) {
        throw new PersistenceFailureException("SQLException while performing operation.", e);
    } finally {
        tryClose(stmt);
        tryClose(conn);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Aggregations

PersistenceFailureException (voldemort.store.PersistenceFailureException)26 Versioned (voldemort.versioning.Versioned)13 ByteArray (voldemort.utils.ByteArray)9 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 SQLException (java.sql.SQLException)6 DatabaseEntry (com.sleepycat.je.DatabaseEntry)5 DatabaseException (com.sleepycat.je.DatabaseException)5 OperationStatus (com.sleepycat.je.OperationStatus)5 ResultSet (java.sql.ResultSet)5 Test (org.junit.Test)5 AsyncOperationStatus (voldemort.server.protocol.admin.AsyncOperationStatus)5 Transaction (com.sleepycat.je.Transaction)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 RocksDBException (org.rocksdb.RocksDBException)4 ObsoleteVersionException (voldemort.versioning.ObsoleteVersionException)4 VectorClock (voldemort.versioning.VectorClock)4 Occurred (voldemort.versioning.Occurred)3 LockTimeoutException (com.sleepycat.je.LockTimeoutException)2