use of org.rocksdb.RocksDBException in project alluxio by Alluxio.
the class RocksStore method createDb.
private void createDb() throws RocksDBException {
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();
cfDescriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
cfDescriptors.addAll(mColumnFamilyDescriptors);
// a list which will hold the handles for the column families once the db is opened
List<ColumnFamilyHandle> columns = new ArrayList<>();
final TimeoutRetry retryPolicy = new TimeoutRetry(ROCKS_OPEN_RETRY_TIMEOUT, 100);
RocksDBException lastException = null;
while (retryPolicy.attempt()) {
try {
mDb = RocksDB.open(mDbOpts, mDbPath, cfDescriptors, columns);
break;
} catch (RocksDBException e) {
// sometimes the previous terminated process's lock may not have been fully cleared yet
// retry until timeout to make sure that isn't the case
lastException = e;
}
}
if (mDb == null && lastException != null) {
throw lastException;
}
mCheckpoint = Checkpoint.create(mDb);
for (int i = 0; i < columns.size() - 1; i++) {
// Skip the default column.
mColumnHandles.get(i).set(columns.get(i + 1));
}
LOG.info("Opened rocks database under path {}", mDbPath);
}
use of org.rocksdb.RocksDBException in project alluxio by Alluxio.
the class RocksStore method writeToCheckpoint.
/**
* Writes a checkpoint of the database's content to the given output stream.
*
* @param output the stream to write to
*/
public synchronized void writeToCheckpoint(OutputStream output) throws IOException, InterruptedException {
LOG.info("Creating rocksdb checkpoint at {}", mDbCheckpointPath);
long startNano = System.nanoTime();
CheckpointOutputStream out = new CheckpointOutputStream(output, CheckpointType.ROCKS);
try {
// createCheckpoint requires that the directory not already exist.
FileUtils.deletePathRecursively(mDbCheckpointPath);
mCheckpoint.createCheckpoint(mDbCheckpointPath);
} catch (RocksDBException e) {
throw new IOException(e);
}
LOG.info("Checkpoint complete, creating tarball");
TarUtils.writeTarGz(Paths.get(mDbCheckpointPath), out);
LOG.info("Completed rocksdb checkpoint in {}ms", (System.nanoTime() - startNano) / 1_000_000);
// Checkpoint is no longer needed, delete to save space.
FileUtils.deletePathRecursively(mDbCheckpointPath);
}
use of org.rocksdb.RocksDBException in project voldemort by voldemort.
the class RocksDbStorageEngine method delete.
@Override
public boolean delete(ByteArray key, Version version) throws PersistenceFailureException {
StoreUtils.assertValidKey(key);
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
synchronized (this.locks.lockFor(key.get())) {
try {
byte[] value = getRocksDB().get(storeHandle, key.get());
if (value == null) {
return false;
}
if (version == null) {
// unversioned delete. Just blow away the whole thing
getRocksDB().remove(storeHandle, key.get());
return true;
} else {
// versioned deletes; need to determine what to delete
List<Versioned<byte[]>> vals = StoreBinaryFormat.fromByteArray(value);
Iterator<Versioned<byte[]>> iter = vals.iterator();
int numVersions = vals.size();
int numDeletedVersions = 0;
// supplied version
while (iter.hasNext()) {
Versioned<byte[]> curr = iter.next();
Version currentVersion = curr.getVersion();
if (currentVersion.compare(version) == Occurred.BEFORE) {
iter.remove();
numDeletedVersions++;
}
}
if (numDeletedVersions < numVersions) {
// we still have some valid versions
value = StoreBinaryFormat.toByteArray(vals);
getRocksDB().put(storeHandle, key.get(), value);
} else {
// we have deleted all the versions; so get rid of the
// entry
// in the database
getRocksDB().remove(storeHandle, key.get());
}
return numDeletedVersions > 0;
}
} catch (RocksDBException e) {
logger.error(e);
throw new PersistenceFailureException(e);
} finally {
if (logger.isTraceEnabled()) {
logger.trace("Completed DELETE (" + getName() + ") of key " + ByteUtils.toHexString(key.get()) + " (keyRef: " + System.identityHashCode(key) + ") in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
}
}
}
}
use of org.rocksdb.RocksDBException in project voldemort by voldemort.
the class RocksDbStorageEngine method truncate.
@Override
public void truncate() {
try {
rocksDB.dropColumnFamily(storeHandle);
storeHandle.dispose();
storeHandle = rocksDB.createColumnFamily(new ColumnFamilyDescriptor(getName().getBytes(), storeOptions));
} catch (RocksDBException e) {
throw new VoldemortException("Failed to truncate DB", e);
}
}
use of org.rocksdb.RocksDBException in project voldemort by voldemort.
the class RocksDbStorageEngine method multiVersionPut.
@Override
public List<Versioned<byte[]>> multiVersionPut(ByteArray key, List<Versioned<byte[]>> values) {
// TODO Implement getandLock() and putAndUnlock() and then remove this
// method
StoreUtils.assertValidKey(key);
long startTimeNs = -1;
if (logger.isTraceEnabled())
startTimeNs = System.nanoTime();
List<Versioned<byte[]>> currentValues = null;
List<Versioned<byte[]>> obsoleteVals = null;
synchronized (this.locks.lockFor(key.get())) {
/*
* Get the existing values. Make sure to "get" from the underlying
* storage instead of using the get method described in this class.
* Invoking the get method from this class will unnecessarily double
* prefix the key in case of PartitionPrefixedRocksdbStorageEngine
* and can cause unpredictable results.
*/
try {
byte[] result = getRocksDB().get(storeHandle, key.get());
if (result != null) {
currentValues = StoreBinaryFormat.fromByteArray(result);
} else {
currentValues = new ArrayList<Versioned<byte[]>>();
}
} catch (RocksDBException e) {
logger.error(e);
throw new PersistenceFailureException(e);
}
obsoleteVals = resolveAndConstructVersionsToPersist(currentValues, values);
try {
getRocksDB().put(storeHandle, key.get(), StoreBinaryFormat.toByteArray(currentValues));
} catch (RocksDBException e) {
logger.error(e);
throw new PersistenceFailureException(e);
} finally {
if (logger.isTraceEnabled()) {
String valueStr = "";
for (Versioned<byte[]> val : currentValues) {
valueStr += val + ",";
}
logger.trace("Completed PUT (" + getName() + ") to key " + key + " (keyRef: " + System.identityHashCode(key) + " values " + valueStr + " in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
}
}
}
return obsoleteVals;
}
Aggregations