Search in sources :

Example 16 with IgniteInternalException

use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.

the class CommandUtils method rowsToBytes.

/**
 * Writes a list of rows to byte array.
 *
 * @param rows     Collection of rows.
 * @return         Rows data.
 */
public static byte[] rowsToBytes(Collection<BinaryRow> rows) {
    if (rows == null || rows.isEmpty()) {
        return null;
    }
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        for (BinaryRow row : rows) {
            if (row == null) {
                baos.write(intToBytes(0));
            } else {
                byte[] bytes = rowToBytes(row);
                baos.write(intToBytes(bytes.length));
                baos.write(bytes);
            }
        }
        baos.flush();
        return baos.toByteArray();
    } catch (IOException e) {
        LOG.error("Could not write rows to stream [rows=" + rows.size() + ']', e);
        throw new IgniteInternalException(e);
    }
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) IOException(java.io.IOException)

Example 17 with IgniteInternalException

use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.

the class PartitionListener method handleScanCloseCommand.

/**
 * Handler for the {@link ScanCloseCommand}.
 *
 * @param clo Command closure.
 * @param cmd Command.
 */
private void handleScanCloseCommand(CommandClosure<ScanCloseCommand> clo, ScanCloseCommand cmd) {
    CursorMeta cursorDesc = cursors.remove(cmd.scanId());
    if (cursorDesc == null) {
        clo.result(null);
        return;
    }
    try {
        cursorDesc.cursor().close();
    } catch (Exception e) {
        throw new IgniteInternalException(e);
    }
    clo.result(null);
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) StorageException(org.apache.ignite.internal.storage.StorageException) TransactionException(org.apache.ignite.tx.TransactionException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) NoSuchElementException(java.util.NoSuchElementException)

Example 18 with IgniteInternalException

use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.

the class RocksDbKeyValueStorage method invoke.

/**
 * {@inheritDoc}
 */
@Override
public boolean invoke(Condition condition, Collection<Operation> success, Collection<Operation> failure) {
    rwLock.writeLock().lock();
    try {
        Entry[] entries = getAll(Arrays.asList(condition.keys())).toArray(new Entry[] {});
        boolean branch = condition.test(entries);
        Collection<Operation> ops = branch ? success : failure;
        applyOperations(ops);
        return branch;
    } catch (RocksDBException e) {
        throw new IgniteInternalException(e);
    } finally {
        rwLock.writeLock().unlock();
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) Entry(org.apache.ignite.internal.metastorage.server.Entry) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) Operation(org.apache.ignite.internal.metastorage.server.Operation)

Example 19 with IgniteInternalException

use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.

the class RocksDbKeyValueStorage method invoke.

@Override
public StatementResult invoke(If iif) {
    rwLock.writeLock().lock();
    try {
        If currIf = iif;
        byte maximumNumOfNestedBranch = 100;
        while (true) {
            if (maximumNumOfNestedBranch-- <= 0) {
                throw new IgniteInternalException("Too many nested (" + maximumNumOfNestedBranch + ") statements in multi-invoke command.");
            }
            Entry[] entries = getAll(Arrays.asList(currIf.cond().keys())).toArray(new Entry[] {});
            Statement branch = (currIf.cond().test(entries)) ? currIf.andThen() : currIf.orElse();
            if (branch.isTerminal()) {
                Update update = branch.update();
                applyOperations(update.operations());
                return update.result();
            } else {
                currIf = branch.iif();
            }
        }
    } catch (RocksDBException e) {
        throw new IgniteInternalException(e);
    } finally {
        rwLock.writeLock().unlock();
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) Entry(org.apache.ignite.internal.metastorage.server.Entry) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) Statement(org.apache.ignite.internal.metastorage.server.Statement) Update(org.apache.ignite.internal.metastorage.server.Update) If(org.apache.ignite.internal.metastorage.server.If)

Example 20 with IgniteInternalException

use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.

the class RocksDbKeyValueStorage method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() {
    options = new DBOptions().setCreateMissingColumnFamilies(true).setCreateIfMissing(true);
    Options dataOptions = new Options().setCreateIfMissing(true).useFixedLengthPrefixExtractor(Long.BYTES);
    ColumnFamilyOptions dataFamilyOptions = new ColumnFamilyOptions(dataOptions);
    Options indexOptions = new Options().setCreateIfMissing(true);
    ColumnFamilyOptions indexFamilyOptions = new ColumnFamilyOptions(indexOptions);
    List<ColumnFamilyDescriptor> descriptors = Arrays.asList(new ColumnFamilyDescriptor(DATA.nameAsBytes(), dataFamilyOptions), new ColumnFamilyDescriptor(INDEX.nameAsBytes(), indexFamilyOptions));
    var handles = new ArrayList<ColumnFamilyHandle>();
    try {
        // Delete existing data, relying on the raft's snapshot and log playback
        destroyRocksDb();
        this.db = RocksDB.open(options, dbPath.toAbsolutePath().toString(), descriptors, handles);
    } catch (RocksDBException e) {
        throw new IgniteInternalException("Failed to start the storage", e);
    }
    data = new ColumnFamily(db, handles.get(0), DATA.name(), dataFamilyOptions, dataOptions);
    index = new ColumnFamily(db, handles.get(1), INDEX.name(), indexFamilyOptions, indexOptions);
}
Also used : ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) ReadOptions(org.rocksdb.ReadOptions) IngestExternalFileOptions(org.rocksdb.IngestExternalFileOptions) WriteOptions(org.rocksdb.WriteOptions) Options(org.rocksdb.Options) DBOptions(org.rocksdb.DBOptions) RocksDBException(org.rocksdb.RocksDBException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ArrayList(java.util.ArrayList) DBOptions(org.rocksdb.DBOptions) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ColumnFamily(org.apache.ignite.internal.rocksdb.ColumnFamily)

Aggregations

IgniteInternalException (org.apache.ignite.lang.IgniteInternalException)58 RocksDBException (org.rocksdb.RocksDBException)19 IOException (java.io.IOException)11 Path (java.nio.file.Path)10 ArrayList (java.util.ArrayList)10 NotNull (org.jetbrains.annotations.NotNull)10 WriteBatch (org.rocksdb.WriteBatch)9 List (java.util.List)7 Entry (org.apache.ignite.internal.metastorage.server.Entry)7 NoSuchElementException (java.util.NoSuchElementException)6 NetworkAddress (org.apache.ignite.network.NetworkAddress)6 Test (org.junit.jupiter.api.Test)6 RaftGroupService (org.apache.ignite.raft.client.service.RaftGroupService)5 Nullable (org.jetbrains.annotations.Nullable)5 UUID (java.util.UUID)4 TimeoutException (java.util.concurrent.TimeoutException)4 NodeStoppingException (org.apache.ignite.lang.NodeStoppingException)4 ReadOptions (org.rocksdb.ReadOptions)4 RocksIterator (org.rocksdb.RocksIterator)4 CompletableFuture (java.util.concurrent.CompletableFuture)3