Search in sources :

Example 21 with RocksDBException

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);
}
Also used : RocksDBException(org.rocksdb.RocksDBException) ArrayList(java.util.ArrayList) TimeoutRetry(alluxio.retry.TimeoutRetry) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) Checkpoint(org.rocksdb.Checkpoint)

Example 22 with RocksDBException

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);
}
Also used : RocksDBException(org.rocksdb.RocksDBException) CheckpointOutputStream(alluxio.master.journal.checkpoint.CheckpointOutputStream) IOException(java.io.IOException)

Example 23 with RocksDBException

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());
            }
        }
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) Versioned(voldemort.versioning.Versioned) Version(voldemort.versioning.Version) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Example 24 with RocksDBException

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);
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) VoldemortException(voldemort.VoldemortException)

Example 25 with RocksDBException

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;
}
Also used : RocksDBException(org.rocksdb.RocksDBException) Versioned(voldemort.versioning.Versioned) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Aggregations

RocksDBException (org.rocksdb.RocksDBException)66 IOException (java.io.IOException)17 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)17 ProcessorStateException (org.apache.kafka.streams.errors.ProcessorStateException)11 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)11 ArrayList (java.util.ArrayList)10 WriteBatch (org.rocksdb.WriteBatch)10 HashMap (java.util.HashMap)8 Map (java.util.Map)8 MetricException (org.apache.storm.metricstore.MetricException)8 WriteOptions (org.rocksdb.WriteOptions)7 Options (org.rocksdb.Options)6 File (java.io.File)5 DBOptions (org.rocksdb.DBOptions)5 FlushOptions (org.rocksdb.FlushOptions)5 RocksDB (org.rocksdb.RocksDB)5 DataInputViewStreamWrapper (org.apache.flink.core.memory.DataInputViewStreamWrapper)4 ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)4 ReadOptions (org.rocksdb.ReadOptions)4 RocksIterator (org.rocksdb.RocksIterator)4