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);
}
}
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();
}
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()));
}
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);
}
}
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);
}
}
Aggregations