Search in sources :

Example 6 with BatchOperation

use of io.nuls.db.service.BatchOperation in project nuls by nuls-io.

the class LocalUtxoStorageServiceImpl method batchSaveAndDeleteUTXO.

@Override
public Result batchSaveAndDeleteUTXO(List<Entry<byte[], byte[]>> utxosToSave, List<byte[]> utxosToDelete) {
    BatchOperation batch = dbService.createWriteBatch(AccountLedgerStorageConstant.DB_NAME_ACCOUNT_LEDGER_COINDATA);
    for (byte[] key : utxosToDelete) {
        batch.delete(key);
    }
    for (Entry<byte[], byte[]> entry : utxosToSave) {
        batch.put(entry.getKey(), entry.getValue());
    }
    Result batchResult = batch.executeBatch();
    if (batchResult.isFailed()) {
        return batchResult;
    }
    Result result = Result.getSuccess().setData(new Integer(utxosToSave.size() + utxosToDelete.size()));
    if (result.isSuccess() && cacheMap != null) {
        for (Entry<byte[], byte[]> entry : utxosToSave) {
            cacheMap.put(new String(entry.getKey()), entry);
        }
        for (byte[] key : utxosToDelete) {
            cacheMap.remove(new String(key));
        }
    }
    return result;
}
Also used : BatchOperation(io.nuls.db.service.BatchOperation) Result(io.nuls.kernel.model.Result)

Example 7 with BatchOperation

use of io.nuls.db.service.BatchOperation in project nuls by nuls-io.

the class LevelDbDataSource method updateBatchInternal.

private void updateBatchInternal(Map<byte[], byte[]> rows) {
    BatchOperation batchOperation = dbService.createWriteBatch(AREA);
    for (Map.Entry<byte[], byte[]> entry : rows.entrySet()) {
        if (entry.getValue() == null) {
            batchOperation.delete(entry.getKey());
        } else {
            batchOperation.put(entry.getKey(), entry.getValue());
        }
    }
    batchOperation.executeBatch();
}
Also used : BatchOperation(io.nuls.db.service.BatchOperation) Map(java.util.Map)

Aggregations

BatchOperation (io.nuls.db.service.BatchOperation)7 Result (io.nuls.kernel.model.Result)4 Entry (io.nuls.db.model.Entry)2 VarInt (io.nuls.kernel.utils.VarInt)2 ValidateResult (io.nuls.kernel.validate.ValidateResult)2 IOException (java.io.IOException)2 NulsByteBuffer (io.nuls.kernel.utils.NulsByteBuffer)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1