Search in sources :

Example 6 with StorageException

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();
}
Also used : RocksDBException(org.rocksdb.RocksDBException) ReadOptions(org.rocksdb.ReadOptions) Slice(org.rocksdb.Slice) Stream(java.util.stream.Stream) RocksIterator(org.rocksdb.RocksIterator) StorageException(org.apache.ignite.internal.storage.StorageException)

Example 7 with StorageException

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);
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) StorageException(org.apache.ignite.internal.storage.StorageException)

Example 8 with StorageException

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);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteUuid(org.apache.ignite.lang.IgniteUuid) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) StorageException(org.apache.ignite.internal.storage.StorageException)

Example 9 with StorageException

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);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(java.util.concurrent.Flow.Subscription) StorageException(org.apache.ignite.internal.storage.StorageException) Test(org.junit.jupiter.api.Test)

Example 10 with StorageException

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);
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) StorageException(org.apache.ignite.internal.storage.StorageException)

Aggregations

StorageException (org.apache.ignite.internal.storage.StorageException)14 RocksDBException (org.rocksdb.RocksDBException)11 ArrayList (java.util.ArrayList)6 DataRow (org.apache.ignite.internal.storage.DataRow)5 DelegatingDataRow (org.apache.ignite.internal.storage.basic.DelegatingDataRow)5 SimpleDataRow (org.apache.ignite.internal.storage.basic.SimpleDataRow)5 WriteBatch (org.rocksdb.WriteBatch)4 WriteOptions (org.rocksdb.WriteOptions)4 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)3 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Subscription (java.util.concurrent.Flow.Subscription)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Stream (java.util.stream.Stream)1 ColumnFamily (org.apache.ignite.internal.rocksdb.ColumnFamily)1 PartitionStorage (org.apache.ignite.internal.storage.PartitionStorage)1 SearchRow (org.apache.ignite.internal.storage.SearchRow)1 SortedIndexDescriptor (org.apache.ignite.internal.storage.index.SortedIndexDescriptor)1 RocksDbSortedIndexStorage (org.apache.ignite.internal.storage.rocksdb.index.RocksDbSortedIndexStorage)1