use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class RocksDbKeyValueStorage method doGetValue.
/**
* Gets the value by a key and a revision.
*
* @param key Target key.
* @param revision Target revision.
* @return Entry.
*/
@NotNull
Entry doGetValue(byte[] key, long revision) {
if (revision == 0) {
return Entry.empty(key);
}
byte[] valueBytes;
try {
valueBytes = data.get(keyToRocksKey(revision, key));
} catch (RocksDBException e) {
throw new IgniteInternalException(e);
}
if (valueBytes == null || valueBytes.length == 0) {
return Entry.empty(key);
}
Value lastVal = bytesToValue(valueBytes);
if (lastVal.tombstone()) {
return Entry.tombstone(key, revision, lastVal.updateCounter());
}
return new Entry(key, lastVal.bytes(), revision, lastVal.updateCounter());
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class RocksDbKeyValueStorage method putAll.
/**
* {@inheritDoc}
*/
@Override
public void putAll(List<byte[]> keys, List<byte[]> values) {
rwLock.writeLock().lock();
try (WriteBatch batch = new WriteBatch()) {
long curRev = rev + 1;
long counter = addAllToBatch(batch, keys, values, curRev);
for (byte[] key : keys) {
updateKeysIndex(batch, key, curRev);
}
fillAndWriteBatch(batch, curRev, counter);
} 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 getAndPutAll.
/**
* {@inheritDoc}
*/
@NotNull
@Override
public Collection<Entry> getAndPutAll(List<byte[]> keys, List<byte[]> values) {
Collection<Entry> res;
rwLock.writeLock().lock();
try (WriteBatch batch = new WriteBatch()) {
long curRev = rev + 1;
res = doGetAll(keys, curRev);
long counter = addAllToBatch(batch, keys, values, curRev);
for (byte[] key : keys) {
updateKeysIndex(batch, key, curRev);
}
fillAndWriteBatch(batch, curRev, counter);
} catch (RocksDBException e) {
throw new IgniteInternalException(e);
} finally {
rwLock.writeLock().unlock();
}
return res;
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class RocksDbKeyValueStorage method higherOrCeiling.
/**
* Gets an entry from the keys index with the least key greater than or equal to the specified key, depending on the strictlyHigher
* parameter.
*
* @param key Key.
* @param strictlyHigher {@code true} for a strictly higher entry, {@code false} for a ceiling one.
* @return Entry for the least key greater than or equal to the specified key. If no such entry exists returns {@code null}.
*/
@Nullable
private IgniteBiTuple<byte[], long[]> higherOrCeiling(byte[] key, boolean strictlyHigher) {
try (RocksIterator iterator = index.newIterator()) {
iterator.seek(key);
RocksBiPredicate predicate = strictlyHigher ? (k, v) -> CMP.compare(k, key) > 0 : (k, v) -> CMP.compare(k, key) >= 0;
boolean found = find(iterator, predicate);
if (!found) {
return null;
}
return new IgniteBiTuple<>(iterator.key(), getAsLongs(iterator.value()));
} catch (RocksDBException e) {
throw new IgniteInternalException(e);
}
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class RocksDbKeyValueStorage method snapshot.
/**
* {@inheritDoc}
*/
@NotNull
@Override
public CompletableFuture<Void> snapshot(Path snapshotPath) {
Path tempPath = Paths.get(snapshotPath.toString() + TMP_SUFFIX);
// Create a RocksDB point-in-time snapshot
Snapshot snapshot = db.getSnapshot();
return CompletableFuture.runAsync(() -> {
// (Re)create the temporary directory
IgniteUtils.deleteIfExists(tempPath);
try {
Files.createDirectories(tempPath);
} catch (IOException e) {
throw new IgniteInternalException("Failed to create directory: " + tempPath, e);
}
}, snapshotExecutor).thenCompose(argVoid -> CompletableFuture.allOf(CompletableFuture.runAsync(() -> createSstFile(data, snapshot, tempPath), snapshotExecutor), CompletableFuture.runAsync(() -> createSstFile(index, snapshot, tempPath), snapshotExecutor))).whenComplete((argVoid, throwable) -> {
// Release a snapshot
db.releaseSnapshot(snapshot);
// Snapshot is not actually closed here, because a Snapshot instance doesn't own a pointer, the
// database does. Calling close to maintain the AutoCloseable semantics
snapshot.close();
if (throwable != null) {
return;
}
// Delete snapshot directory if it already exists
IgniteUtils.deleteIfExists(snapshotPath);
try {
// Rename the temporary directory
IgniteUtils.atomicMoveFile(tempPath, snapshotPath, null);
} catch (IOException e) {
throw new IgniteInternalException("Failed to rename: " + tempPath + " to " + snapshotPath, e);
}
});
}
Aggregations