use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class RocksDbPartitionStorage method removeAll.
/**
* {@inheritDoc}
*/
@Override
public Collection<SearchRow> removeAll(List<? extends SearchRow> keys) {
List<SearchRow> skippedRows = new ArrayList<>();
try (var batch = new WriteBatch();
var opts = new WriteOptions()) {
for (SearchRow key : keys) {
byte[] partitionKey = partitionKey(key);
byte[] value = data.get(partitionKey);
if (value != null) {
data.delete(batch, partitionKey);
} else {
skippedRows.add(key);
}
}
db.write(opts, batch);
} catch (RocksDBException e) {
throw new StorageException("Failed to remove data from the storage", e);
}
return skippedRows;
}
use of org.apache.ignite.internal.storage.StorageException 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.StorageException 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;
}
use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class RocksDbTableStorage method stop.
/**
* {@inheritDoc}
*/
@Override
public void stop() throws StorageException {
stopped = true;
List<AutoCloseable> resources = new ArrayList<>();
resources.addAll(autoCloseables);
resources.addAll(sortedIndices.values());
for (int i = 0; i < partitions.length(); i++) {
PartitionStorage partition = partitions.get(i);
if (partition != null) {
resources.add(partition);
}
}
Collections.reverse(resources);
try {
IgniteUtils.closeAll(resources);
} catch (Exception e) {
throw new StorageException("Failed to stop RocksDB table storage.", e);
}
}
Aggregations