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();
}
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;
}
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();
}
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;
}
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;
}
Aggregations