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);
}
}
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);
}
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();
}
}
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();
}
}
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);
}
Aggregations