Search in sources :

Example 6 with DataRow

use of org.apache.ignite.internal.storage.DataRow in project ignite-3 by apache.

the class VersionedRowStore method get.

/**
 * Gets a row.
 *
 * @param row The search row.
 * @param ts The timestamp.
 * @return The result row.
 */
public BinaryRow get(@NotNull BinaryRow row, Timestamp ts) {
    assert row != null;
    var key = new BinarySearchRow(row);
    DataRow readValue = storage.read(key);
    return versionedRow(readValue, ts).getFirst();
}
Also used : BinarySearchRow(org.apache.ignite.internal.storage.basic.BinarySearchRow) DataRow(org.apache.ignite.internal.storage.DataRow) DelegatingDataRow(org.apache.ignite.internal.storage.basic.DelegatingDataRow)

Example 7 with DataRow

use of org.apache.ignite.internal.storage.DataRow in project ignite-3 by apache.

the class ConcurrentHashMapPartitionStorage method removeAllExact.

/**
 * {@inheritDoc}
 */
@Override
public Collection<DataRow> removeAllExact(List<? extends DataRow> keyValues) {
    var skippedRows = new ArrayList<DataRow>(keyValues.size());
    for (DataRow row : keyValues) {
        var key = new ByteArray(row.keyBytes());
        byte[] existingValueBytes = map.get(key);
        if (Arrays.equals(existingValueBytes, row.valueBytes())) {
            map.remove(key);
        } else {
            skippedRows.add(row);
        }
    }
    return skippedRows;
}
Also used : ArrayList(java.util.ArrayList) ByteArray(org.apache.ignite.lang.ByteArray) DataRow(org.apache.ignite.internal.storage.DataRow)

Example 8 with DataRow

use of org.apache.ignite.internal.storage.DataRow in project ignite-3 by apache.

the class ConcurrentHashMapPartitionStorage method invoke.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public <T> T invoke(SearchRow key, InvokeClosure<T> clo) throws StorageException {
    byte[] keyBytes = key.keyBytes();
    ByteArray mapKey = new ByteArray(keyBytes);
    byte[] existingDataBytes = map.get(mapKey);
    clo.call(existingDataBytes == null ? null : new SimpleDataRow(keyBytes, existingDataBytes));
    switch(clo.operationType()) {
        case WRITE:
            DataRow newRow = clo.newRow();
            assert newRow != null;
            map.put(mapKey, newRow.valueBytes());
            break;
        case REMOVE:
            map.remove(mapKey);
            break;
        case NOOP:
            break;
        default:
            throw new UnsupportedOperationException(String.valueOf(clo.operationType()));
    }
    return clo.result();
}
Also used : ByteArray(org.apache.ignite.lang.ByteArray) DataRow(org.apache.ignite.internal.storage.DataRow) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with DataRow

use of org.apache.ignite.internal.storage.DataRow in project ignite-3 by apache.

the class RocksDbPartitionStorage method readAll.

/**
 * {@inheritDoc}
 */
@Override
public Collection<DataRow> readAll(List<? extends SearchRow> keys) throws StorageException {
    int resultSize = keys.size();
    List<byte[]> values;
    try {
        values = db.multiGetAsList(nCopies(resultSize, data.handle()), getKeys(keys));
    } catch (RocksDBException e) {
        throw new StorageException("Failed to read data from the storage", e);
    }
    assert resultSize == values.size();
    List<DataRow> res = new ArrayList<>(resultSize);
    for (int i = 0; i < resultSize; i++) {
        byte[] value = values.get(i);
        if (value != null) {
            res.add(new DelegatingDataRow(keys.get(i), value));
        }
    }
    return res;
}
Also used : RocksDBException(org.rocksdb.RocksDBException) ArrayList(java.util.ArrayList) StorageException(org.apache.ignite.internal.storage.StorageException) DelegatingDataRow(org.apache.ignite.internal.storage.basic.DelegatingDataRow) DataRow(org.apache.ignite.internal.storage.DataRow) SimpleDataRow(org.apache.ignite.internal.storage.basic.SimpleDataRow) DelegatingDataRow(org.apache.ignite.internal.storage.basic.DelegatingDataRow)

Example 10 with DataRow

use of org.apache.ignite.internal.storage.DataRow in project ignite-3 by apache.

the class RocksDbPartitionStorage method removeAllExact.

/**
 * {@inheritDoc}
 */
@Override
public Collection<DataRow> removeAllExact(List<? extends DataRow> keyValues) {
    List<DataRow> skippedRows = new ArrayList<>();
    try (WriteBatch batch = new WriteBatch();
        WriteOptions opts = new WriteOptions()) {
        List<byte[]> keys = getKeys(keyValues);
        List<byte[]> values = db.multiGetAsList(nCopies(keys.size(), data.handle()), keys);
        assert values.size() == keys.size();
        for (int i = 0; i < keys.size(); i++) {
            byte[] key = keys.get(i);
            byte[] expectedValue = keyValues.get(i).valueBytes();
            byte[] value = values.get(i);
            if (Arrays.equals(value, expectedValue)) {
                data.delete(batch, key);
            } else {
                skippedRows.add(keyValues.get(i));
            }
        }
        db.write(opts, batch);
    } catch (RocksDBException e) {
        throw new StorageException("Failed to remove data from the storage", e);
    }
    return skippedRows;
}
Also used : WriteOptions(org.rocksdb.WriteOptions) RocksDBException(org.rocksdb.RocksDBException) ArrayList(java.util.ArrayList) DelegatingDataRow(org.apache.ignite.internal.storage.basic.DelegatingDataRow) DataRow(org.apache.ignite.internal.storage.DataRow) SimpleDataRow(org.apache.ignite.internal.storage.basic.SimpleDataRow) WriteBatch(org.rocksdb.WriteBatch) StorageException(org.apache.ignite.internal.storage.StorageException)

Aggregations

DataRow (org.apache.ignite.internal.storage.DataRow)10 DelegatingDataRow (org.apache.ignite.internal.storage.basic.DelegatingDataRow)7 SimpleDataRow (org.apache.ignite.internal.storage.basic.SimpleDataRow)6 StorageException (org.apache.ignite.internal.storage.StorageException)5 RocksDBException (org.rocksdb.RocksDBException)5 ArrayList (java.util.ArrayList)4 Nullable (org.jetbrains.annotations.Nullable)3 WriteBatch (org.rocksdb.WriteBatch)3 WriteOptions (org.rocksdb.WriteOptions)3 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)2 ByteArray (org.apache.ignite.lang.ByteArray)2 UUID (java.util.UUID)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 RaftServerImpl (org.apache.ignite.internal.raft.server.impl.RaftServerImpl)1 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)1 PartitionStorage (org.apache.ignite.internal.storage.PartitionStorage)1 BinarySearchRow (org.apache.ignite.internal.storage.basic.BinarySearchRow)1 PartitionListener (org.apache.ignite.internal.table.distributed.raft.PartitionListener)1 InternalTableImpl (org.apache.ignite.internal.table.distributed.storage.InternalTableImpl)1 VersionedRowStore (org.apache.ignite.internal.table.distributed.storage.VersionedRowStore)1