use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class ItInternalTableScanTest method invalidRequestNtest.
/**
* Checks whether {@link IllegalArgumentException} is thrown and inner storage cursor is closes in case of invalid requested amount of
* items.
*
* @param reqAmount Amount of rows to request at a time.
* @throws Exception If Any.
*/
private void invalidRequestNtest(int reqAmount) throws InterruptedException {
// The latch that allows to await Subscriber.onComplete() before asserting test invariants
// and avoids the race between closing the cursor and stopping the node.
CountDownLatch subscriberFinishedLatch = new CountDownLatch(2);
when(mockStorage.scan(any())).thenAnswer(invocation -> {
var cursor = mock(Cursor.class);
doAnswer(invocationClose -> {
subscriberFinishedLatch.countDown();
return null;
}).when(cursor).close();
when(cursor.hasNext()).thenAnswer(hnInvocation -> {
throw new StorageException("test");
});
return cursor;
});
AtomicReference<Throwable> gotException = new AtomicReference<>();
internalTbl.scan(0, null).subscribe(new Subscriber<>() {
@Override
public void onSubscribe(Subscription subscription) {
subscription.request(reqAmount);
}
@Override
public void onNext(BinaryRow item) {
fail("Should never get here.");
}
@Override
public void onError(Throwable throwable) {
gotException.set(throwable);
subscriberFinishedLatch.countDown();
}
@Override
public void onComplete() {
fail("Should never get here.");
}
});
subscriberFinishedLatch.await();
assertThrows(IllegalArgumentException.class, () -> {
throw gotException.get();
});
}
use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class RocksDbPartitionStorage method invoke.
/**
* {@inheritDoc}
*/
@Nullable
@Override
public <T> T invoke(SearchRow key, InvokeClosure<T> clo) throws StorageException {
try {
byte[] partitionKey = partitionKey(key);
byte[] existingDataBytes = data.get(partitionKey);
clo.call(existingDataBytes == null ? null : new DelegatingDataRow(key, existingDataBytes));
switch(clo.operationType()) {
case WRITE:
DataRow newRow = clo.newRow();
assert newRow != null;
byte[] value = newRow.valueBytes();
assert value != null;
data.put(partitionKey, value);
break;
case REMOVE:
data.delete(partitionKey);
break;
case NOOP:
break;
default:
throw new UnsupportedOperationException(String.valueOf(clo.operationType()));
}
return clo.result();
} catch (RocksDBException e) {
throw new StorageException("Failed to access data in the storage", e);
}
}
use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class RocksDbPartitionStorage method insertAll.
/**
* {@inheritDoc}
*/
@Override
public Collection<DataRow> insertAll(List<? extends DataRow> rows) throws StorageException {
List<DataRow> cantInsert = new ArrayList<>();
try (var batch = new WriteBatch();
var opts = new WriteOptions()) {
for (DataRow row : rows) {
byte[] partitionKey = partitionKey(row);
if (data.get(partitionKey) == null) {
byte[] value = row.valueBytes();
assert value != null;
data.put(batch, partitionKey, value);
} else {
cantInsert.add(row);
}
}
db.write(opts, batch);
} catch (RocksDBException e) {
throw new StorageException("Filed to write data to the storage", e);
}
return cantInsert;
}
use of org.apache.ignite.internal.storage.StorageException in project ignite-3 by apache.
the class RocksDbPartitionStorage method writeAll.
/**
* {@inheritDoc}
*/
@Override
public void writeAll(List<? extends DataRow> rows) throws StorageException {
try (WriteBatch batch = new WriteBatch();
WriteOptions opts = new WriteOptions()) {
for (DataRow row : rows) {
byte[] value = row.valueBytes();
assert value != null;
data.put(batch, partitionKey(row), value);
}
db.write(opts, batch);
} 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 RocksDbTableStorage method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws StorageException {
try {
Files.createDirectories(tablePath);
} catch (IOException e) {
throw new StorageException("Failed to create a directory for the table storage", e);
}
List<ColumnFamilyDescriptor> cfDescriptors = getExistingCfDescriptors();
List<ColumnFamilyHandle> cfHandles = new ArrayList<>(cfDescriptors.size());
DBOptions dbOptions = new DBOptions().setCreateIfMissing(true).setWriteBufferManager(dataRegion.writeBufferManager());
try {
db = RocksDB.open(dbOptions, tablePath.toAbsolutePath().toString(), cfDescriptors, cfHandles);
} catch (RocksDBException e) {
throw new StorageException("Failed to initialize RocksDB instance", e);
}
addToCloseableResources(db::closeE);
// read all existing Column Families from the db and parse them according to type: meta, partition data or index.
for (int i = 0; i < cfHandles.size(); i++) {
ColumnFamilyHandle cfHandle = cfHandles.get(i);
ColumnFamilyDescriptor cfDescriptor = cfDescriptors.get(i);
String handleName = cfHandleName(cfHandle);
ColumnFamily cf = new ColumnFamily(db, cfHandle, handleName, cfDescriptor.getOptions(), null);
switch(columnFamilyType(handleName)) {
case META:
meta = addToCloseableResources(new RocksDbMetaStorage(cf));
break;
case PARTITION:
partitionCf = addToCloseableResources(cf);
break;
case SORTED_INDEX:
String indexName = sortedIndexName(handleName);
var indexDescriptor = new SortedIndexDescriptor(indexName, tableCfg.value());
sortedIndices.put(indexName, new RocksDbSortedIndexStorage(cf, indexDescriptor));
break;
default:
throw new StorageException("Unidentified column family [name=" + handleName + ", table=" + tableCfg.name() + ']');
}
}
if (partitionCf == null) {
partitionCf = addToCloseableResources(createColumnFamily(PARTITION_CF_NAME, partitionCfDescriptor()));
}
partitions = new AtomicReferenceArray<>(tableCfg.value().partitions());
for (int partId : meta.getPartitionIds()) {
partitions.set(partId, new RocksDbPartitionStorage(threadPool, partId, db, partitionCf));
}
}
Aggregations