use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class RocksDbMetaStorage method getPartitionIds.
/**
* Returns a list of partition IDs that exist in the associated storage.
*
* @return list of partition IDs
*/
int[] getPartitionIds() {
Stream.Builder<byte[]> data = Stream.builder();
try (var upperBound = new Slice(PARTITION_ID_PREFIX_END);
var options = new ReadOptions().setIterateUpperBound(upperBound);
RocksIterator it = metaCf.newIterator(options)) {
it.seek(PARTITION_ID_PREFIX);
RocksUtils.forEach(it, (key, value) -> data.add(value));
} catch (RocksDBException e) {
throw new StorageException("Error when reading a list of partition IDs from the meta Column Family", e);
}
return data.build().mapToInt(RocksDbMetaStorage::bytesToUnsignedShort).toArray();
}
use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class RocksDbPartitionStorage method write.
/**
* {@inheritDoc}
*/
@Override
public void write(DataRow row) throws StorageException {
try {
byte[] value = row.valueBytes();
assert value != null;
data.put(partitionKey(row), value);
} catch (RocksDBException e) {
throw new StorageException("Filed to write data to the storage", e);
}
}
use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class PartitionListener method handleScanInitCommand.
/**
* Handler for the {@link ScanInitCommand}.
*
* @param clo Command closure.
* @param cmd Command.
*/
private void handleScanInitCommand(CommandClosure<ScanInitCommand> clo, ScanInitCommand cmd) {
IgniteUuid cursorId = cmd.scanId();
try {
Cursor<BinaryRow> cursor = storage.scan(key -> true);
cursors.put(cursorId, new CursorMeta(cursor, cmd.requesterNodeId(), new AtomicInteger(0)));
} catch (StorageException e) {
clo.result(e);
}
clo.result(null);
}
use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class ItInternalTableScanTest method testExceptionRowScan.
/**
* Checks that exception from storage cursor creation properly propagates to subscriber.
*/
@Test
public void testExceptionRowScan() throws Exception {
// The latch that allows to await Subscriber.onError() before asserting test invariants.
CountDownLatch gotExceptionLatch = new CountDownLatch(1);
AtomicReference<Throwable> gotException = new AtomicReference<>();
when(mockStorage.scan(any())).thenThrow(new StorageException("Some storage exception"));
internalTbl.scan(0, null).subscribe(new Subscriber<>() {
@Override
public void onSubscribe(Subscription subscription) {
subscription.request(1);
}
@Override
public void onNext(BinaryRow item) {
fail("Should never get here.");
}
@Override
public void onError(Throwable throwable) {
gotException.set(throwable);
gotExceptionLatch.countDown();
}
@Override
public void onComplete() {
fail("Should never get here.");
}
});
gotExceptionLatch.await();
assertEquals(gotException.get().getCause().getClass(), StorageException.class);
}
use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class RocksDbMetaStorage method putPartitionId.
/**
* Saves the given partition ID into the meta Column Family.
*
* @param partitionId partition ID
*/
void putPartitionId(int partitionId) {
byte[] partitionIdKey = partitionIdKey(partitionId);
byte[] partitionIdBytes = Arrays.copyOfRange(partitionIdKey, PARTITION_ID_PREFIX.length, partitionIdKey.length);
try {
metaCf.put(partitionIdKey, partitionIdBytes);
} catch (RocksDBException e) {
throw new StorageException("Unable to save partition " + partitionId + " in the meta Column Family", e);
}
}
Aggregations