Search in sources :

Example 11 with StorageException

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

Example 12 with StorageException

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;
}
Also used : RocksDBException(org.rocksdb.RocksDBException) ArrayList(java.util.ArrayList) StorageException(org.apache.ignite.internal.storage.StorageException) DelegatingDataRow(org.apache.ignite.internal.storage.basic.DelegatingDataRow) DataRow(org.apache.ignite.internal.storage.DataRow) SimpleDataRow(org.apache.ignite.internal.storage.basic.SimpleDataRow) DelegatingDataRow(org.apache.ignite.internal.storage.basic.DelegatingDataRow)

Example 13 with StorageException

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;
}
Also used : WriteOptions(org.rocksdb.WriteOptions) RocksDBException(org.rocksdb.RocksDBException) ArrayList(java.util.ArrayList) DelegatingDataRow(org.apache.ignite.internal.storage.basic.DelegatingDataRow) DataRow(org.apache.ignite.internal.storage.DataRow) SimpleDataRow(org.apache.ignite.internal.storage.basic.SimpleDataRow) WriteBatch(org.rocksdb.WriteBatch) StorageException(org.apache.ignite.internal.storage.StorageException)

Example 14 with StorageException

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

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