Search in sources :

Example 1 with PersistenceFailureException

use of voldemort.store.PersistenceFailureException 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 2 with PersistenceFailureException

use of voldemort.store.PersistenceFailureException 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)

Example 3 with PersistenceFailureException

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

the class RocksDbStorageEngine method getValueForKey.

private List<Versioned<byte[]>> getValueForKey(ByteArray key, byte[] transforms) throws PersistenceFailureException {
    long startTimeNs = -1;
    if (logger.isTraceEnabled())
        startTimeNs = System.nanoTime();
    List<Versioned<byte[]>> value = null;
    try {
        byte[] result = getRocksDB().get(storeHandle, key.get());
        if (result != null) {
            value = StoreBinaryFormat.fromByteArray(result);
        } else {
            return Collections.emptyList();
        }
    } catch (RocksDBException e) {
        logger.error(e);
        throw new PersistenceFailureException(e);
    } finally {
        if (logger.isTraceEnabled()) {
            logger.trace("Completed GET (" + getName() + ") from key " + key + " (keyRef: " + System.identityHashCode(key) + ") in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
        }
    }
    return value;
}
Also used : RocksDBException(org.rocksdb.RocksDBException) Versioned(voldemort.versioning.Versioned) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Example 4 with PersistenceFailureException

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

the class RocksDbStorageEngine method getAll.

@Override
public Map<ByteArray, List<Versioned<byte[]>>> getAll(Iterable<ByteArray> keys, Map<ByteArray, byte[]> transforms) throws VoldemortException {
    // TODO Does RocksDB multiget supports atomicity ?
    StoreUtils.assertValidKeys(keys);
    long startTimeNs = -1;
    if (logger.isTraceEnabled())
        startTimeNs = System.nanoTime();
    Map<ByteArray, List<Versioned<byte[]>>> results = null;
    try {
        results = StoreUtils.getAll(this, keys, transforms);
    } catch (PersistenceFailureException e) {
        logger.error(e);
        throw new PersistenceFailureException(e);
    } finally {
        if (logger.isTraceEnabled()) {
            String keyStr = "";
            for (ByteArray key : keys) keyStr += key + " ";
            logger.trace("Completed GETALL (" + getName() + ") from keys " + keyStr + " in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
        }
    }
    return results;
}
Also used : ByteArray(voldemort.utils.ByteArray) ArrayList(java.util.ArrayList) List(java.util.List) PersistenceFailureException(voldemort.store.PersistenceFailureException)

Example 5 with PersistenceFailureException

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

the class RocksDbStorageEngine method put.

@Override
public void put(ByteArray key, Versioned<byte[]> value, byte[] transforms) throws PersistenceFailureException {
    StoreUtils.assertValidKey(key);
    long startTimeNs = -1;
    if (logger.isTraceEnabled())
        startTimeNs = System.nanoTime();
    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.
             */
        List<Versioned<byte[]>> currentValues;
        try {
            byte[] result = getRocksDB().get(storeHandle, key.get());
            if (result != null) {
                currentValues = StoreBinaryFormat.fromByteArray(result);
            } else {
                currentValues = Collections.emptyList();
            }
        } catch (RocksDBException e) {
            logger.error(e);
            throw new PersistenceFailureException(e);
        }
        if (currentValues.size() > 0) {
            // compare vector clocks and throw out old ones, for updates
            Iterator<Versioned<byte[]>> iter = currentValues.iterator();
            while (iter.hasNext()) {
                Versioned<byte[]> curr = iter.next();
                Occurred occurred = value.getVersion().compare(curr.getVersion());
                if (occurred == Occurred.BEFORE) {
                    throw new ObsoleteVersionException("Key " + new String(hexCodec.encode(key.get())) + " " + value.getVersion().toString() + " is obsolete, it is no greater than the current version of " + curr.getVersion().toString() + ".");
                } else if (occurred == Occurred.AFTER) {
                    iter.remove();
                }
            }
        } else {
            // if value does not exist add the value from put request to
            // existing values
            currentValues = new ArrayList<Versioned<byte[]>>(1);
        }
        currentValues.add(value);
        try {
            getRocksDB().put(storeHandle, key.get(), StoreBinaryFormat.toByteArray(currentValues));
        } catch (RocksDBException e) {
            logger.error(e);
            throw new PersistenceFailureException(e);
        } finally {
            if (logger.isTraceEnabled()) {
                logger.trace("Completed PUT (" + getName() + ") to key " + key + " (keyRef: " + System.identityHashCode(key) + " value " + value + " in " + (System.nanoTime() - startTimeNs) + " ns at " + System.currentTimeMillis());
            }
        }
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) ObsoleteVersionException(voldemort.versioning.ObsoleteVersionException) Versioned(voldemort.versioning.Versioned) PersistenceFailureException(voldemort.store.PersistenceFailureException) Occurred(voldemort.versioning.Occurred)

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