Search in sources :

Example 6 with OperationStatus

use of com.sleepycat.je.OperationStatus in project voldemort by voldemort.

the class BdbConvertBaseToPidScan method transfer.

@Override
public void transfer() throws Exception {
    cursor = srcDB.openCursor(null, null);
    DatabaseEntry keyEntry = new DatabaseEntry();
    DatabaseEntry valueEntry = new DatabaseEntry();
    byte[] prevKey = null;
    List<Versioned<byte[]>> vals = new ArrayList<Versioned<byte[]>>();
    HashFunction hash = new FnvHashFunction();
    int totalPartitions = cluster.getNumberOfPartitions();
    long startTime = System.currentTimeMillis();
    int scanCount = 0;
    int keyCount = 0;
    while (cursor.getNext(keyEntry, valueEntry, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
        scanCount++;
        if (scanCount % 1000000 == 0)
            logger.info("Converted " + scanCount + " entries in " + (System.currentTimeMillis() - startTime) / 1000 + " secs");
        // read the value as a versioned Object
        VectorClock clock = new VectorClock(valueEntry.getData());
        byte[] bytes = ByteUtils.copy(valueEntry.getData(), clock.sizeInBytes(), valueEntry.getData().length);
        Versioned<byte[]> value = new Versioned<byte[]>(bytes, clock);
        byte[] key = keyEntry.getData();
        if (prevKey != null && (ByteUtils.compare(prevKey, key) != 0)) {
            // there is a new key; write out the buffered values and
            // previous key
            int partition = BdbConvertData.abs(hash.hash(prevKey)) % (Math.max(1, totalPartitions));
            OperationStatus putStatus = dstDB.put(null, new DatabaseEntry(StoreBinaryFormat.makePrefixedKey(prevKey, partition)), new DatabaseEntry(StoreBinaryFormat.toByteArray(vals)));
            if (OperationStatus.SUCCESS != putStatus) {
                String errorStr = "Put failed with " + putStatus + " for key" + BdbConvertData.writeAsciiString(prevKey);
                logger.error(errorStr);
                throw new Exception(errorStr);
            }
            vals = new ArrayList<Versioned<byte[]>>();
            keyCount++;
        }
        vals.add(value);
        prevKey = key;
    }
    if (vals.size() > 0) {
        int partition = BdbConvertData.abs(hash.hash(prevKey)) % (Math.max(1, totalPartitions));
        OperationStatus putStatus = dstDB.put(null, new DatabaseEntry(StoreBinaryFormat.makePrefixedKey(prevKey, partition)), new DatabaseEntry(StoreBinaryFormat.toByteArray(vals)));
        if (OperationStatus.SUCCESS != putStatus) {
            String errorStr = "Put failed with " + putStatus + " for key" + BdbConvertData.writeAsciiString(prevKey);
            logger.error(errorStr);
            throw new Exception(errorStr);
        }
        keyCount++;
    }
    logger.info("Completed " + scanCount + " entries and " + keyCount + " keys in " + (System.currentTimeMillis() - startTime) / 1000 + " secs");
}
Also used : Versioned(voldemort.versioning.Versioned) VectorClock(voldemort.versioning.VectorClock) ArrayList(java.util.ArrayList) DatabaseEntry(com.sleepycat.je.DatabaseEntry) FnvHashFunction(voldemort.utils.FnvHashFunction) HashFunction(voldemort.utils.HashFunction) FnvHashFunction(voldemort.utils.FnvHashFunction) OperationStatus(com.sleepycat.je.OperationStatus)

Example 7 with OperationStatus

use of com.sleepycat.je.OperationStatus in project voldemort by voldemort.

the class BdbRevertNewDupToBase method transfer.

@Override
public void transfer() throws Exception {
    cursor = srcDB.openCursor(null, null);
    DatabaseEntry keyEntry = new DatabaseEntry();
    DatabaseEntry valueEntry = new DatabaseEntry();
    VersionedSerializer<byte[]> versionedSerializer = new VersionedSerializer<byte[]>(new IdentitySerializer());
    List<Versioned<byte[]>> vals;
    long startTime = System.currentTimeMillis();
    int scanCount = 0;
    int keyCount = 0;
    while (cursor.getNext(keyEntry, valueEntry, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
        keyCount++;
        vals = StoreBinaryFormat.fromByteArray(valueEntry.getData());
        for (Versioned<byte[]> val : vals) {
            OperationStatus putStatus = dstDB.put(null, keyEntry, new DatabaseEntry(versionedSerializer.toBytes(val)));
            if (OperationStatus.SUCCESS != putStatus) {
                String errorStr = "Put failed with " + putStatus + " for key" + BdbConvertData.writeAsciiString(keyEntry.getData());
                logger.error(errorStr);
                throw new Exception(errorStr);
            }
            scanCount++;
        }
        if (scanCount % 1000000 == 0)
            logger.info("Reverted " + scanCount + " entries in " + (System.currentTimeMillis() - startTime) / 1000 + " secs");
    }
    logger.info("Reverted " + scanCount + " entries and " + keyCount + " keys in " + (System.currentTimeMillis() - startTime) / 1000 + " secs");
}
Also used : Versioned(voldemort.versioning.Versioned) OperationStatus(com.sleepycat.je.OperationStatus) IdentitySerializer(voldemort.serialization.IdentitySerializer) DatabaseEntry(com.sleepycat.je.DatabaseEntry) VersionedSerializer(voldemort.serialization.VersionedSerializer)

Example 8 with OperationStatus

use of com.sleepycat.je.OperationStatus in project voldemort by voldemort.

the class BdbRevertPidScanToBase method transfer.

@Override
public void transfer() throws Exception {
    cursor = srcDB.openCursor(null, null);
    DatabaseEntry keyEntry = new DatabaseEntry();
    DatabaseEntry valueEntry = new DatabaseEntry();
    VersionedSerializer<byte[]> versionedSerializer = new VersionedSerializer<byte[]>(new IdentitySerializer());
    List<Versioned<byte[]>> vals;
    long startTime = System.currentTimeMillis();
    int scanCount = 0;
    int keyCount = 0;
    while (cursor.getNext(keyEntry, valueEntry, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
        keyCount++;
        vals = StoreBinaryFormat.fromByteArray(valueEntry.getData());
        // pull out the real key
        byte[] stripedKey = StoreBinaryFormat.extractKey(keyEntry.getData());
        for (Versioned<byte[]> val : vals) {
            OperationStatus putStatus = dstDB.put(null, new DatabaseEntry(stripedKey), new DatabaseEntry(versionedSerializer.toBytes(val)));
            if (OperationStatus.SUCCESS != putStatus) {
                String errorStr = "Put failed with " + putStatus + " for key" + BdbConvertData.writeAsciiString(stripedKey);
                logger.error(errorStr);
                throw new Exception(errorStr);
            }
            scanCount++;
        }
        if (scanCount % 1000000 == 0)
            logger.info("Reverted " + scanCount + " entries in " + (System.currentTimeMillis() - startTime) / 1000 + " secs");
    }
    logger.info("Reverted " + scanCount + " entries and " + keyCount + " keys in " + (System.currentTimeMillis() - startTime) / 1000 + " secs");
}
Also used : Versioned(voldemort.versioning.Versioned) DatabaseEntry(com.sleepycat.je.DatabaseEntry) VersionedSerializer(voldemort.serialization.VersionedSerializer) OperationStatus(com.sleepycat.je.OperationStatus) IdentitySerializer(voldemort.serialization.IdentitySerializer)

Example 9 with OperationStatus

use of com.sleepycat.je.OperationStatus in project voldemort by voldemort.

the class BdbRevertPidScanToNewDup method transfer.

@Override
public void transfer() throws Exception {
    cursor = srcDB.openCursor(null, null);
    DatabaseEntry keyEntry = new DatabaseEntry();
    DatabaseEntry valueEntry = new DatabaseEntry();
    List<Versioned<byte[]>> vals;
    long startTime = System.currentTimeMillis();
    int scanCount = 0;
    int keyCount = 0;
    while (cursor.getNext(keyEntry, valueEntry, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
        keyCount++;
        vals = StoreBinaryFormat.fromByteArray(valueEntry.getData());
        scanCount += vals.size();
        // pull out the real key
        byte[] stripedKey = StoreBinaryFormat.extractKey(keyEntry.getData());
        OperationStatus putStatus = dstDB.put(null, new DatabaseEntry(stripedKey), valueEntry);
        if (OperationStatus.SUCCESS != putStatus) {
            String errorStr = "Put failed with " + putStatus + " for key" + BdbConvertData.writeAsciiString(keyEntry.getData());
            logger.error(errorStr);
            throw new Exception(errorStr);
        }
        if (scanCount % 1000000 == 0)
            logger.info("Reverted " + scanCount + " entries in " + (System.currentTimeMillis() - startTime) / 1000 + " secs");
    }
    logger.info("Reverted " + scanCount + " entries and " + keyCount + " keys in " + (System.currentTimeMillis() - startTime) / 1000 + " secs");
}
Also used : Versioned(voldemort.versioning.Versioned) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 10 with OperationStatus

use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.

the class BDBJEPointCache method get.

@Override
public CoordinateSequence get(List<Long> ids) {
    Preconditions.checkNotNull(ids, "ids is null");
    OSMCoordinateSequence cs = CSFAC.create(ids.size());
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry data = new DatabaseEntry();
    for (int index = 0; index < ids.size(); index++) {
        Long nodeID = ids.get(index);
        LongBinding.longToEntry(nodeID.longValue(), key);
        OperationStatus status = database.get(null, key, data, LockMode.DEFAULT);
        if (!OperationStatus.SUCCESS.equals(status)) {
            String msg = String.format("node id %s not found", nodeID);
            throw new IllegalArgumentException(msg);
        }
        int[] c = CoordinateBinding.entryToCoord(data);
        cs.setOrdinate(index, 0, c[0]);
        cs.setOrdinate(index, 1, c[1]);
    }
    return cs;
}
Also used : OSMCoordinateSequence(org.locationtech.geogig.osm.internal.OSMCoordinateSequence) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Aggregations

OperationStatus (com.sleepycat.je.OperationStatus)23 DatabaseEntry (com.sleepycat.je.DatabaseEntry)22 Transaction (com.sleepycat.je.Transaction)13 Versioned (voldemort.versioning.Versioned)9 DatabaseException (com.sleepycat.je.DatabaseException)6 Cursor (com.sleepycat.je.Cursor)5 AsyncOperationStatus (voldemort.server.protocol.admin.AsyncOperationStatus)5 PersistenceFailureException (voldemort.store.PersistenceFailureException)5 ArrayList (java.util.ArrayList)4 CursorConfig (com.sleepycat.je.CursorConfig)2 LockMode (com.sleepycat.je.LockMode)2 ObjectId (org.locationtech.geogig.api.ObjectId)2 IdentitySerializer (voldemort.serialization.IdentitySerializer)2 VersionedSerializer (voldemort.serialization.VersionedSerializer)2 FnvHashFunction (voldemort.utils.FnvHashFunction)2 HashFunction (voldemort.utils.HashFunction)2 VectorClock (voldemort.versioning.VectorClock)2 EnvironmentLockedException (com.sleepycat.je.EnvironmentLockedException)1 WebURL (edu.uci.ics.crawler4j.url.WebURL)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1