use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class RocksDbKeyValueStorage method doGet.
/**
* Gets the value by key and revision.
*
* @param key Target key.
* @param rev Target revision.
* @param exactRev {@code true} if searching for exact revision, {@code false} if rev is an upper bound (inclusive).
* @return Value.
*/
@NotNull
Entry doGet(byte[] key, long rev, boolean exactRev) {
assert rev == LATEST_REV && !exactRev || rev > LATEST_REV : "Invalid arguments: [rev=" + rev + ", exactRev=" + exactRev + ']';
long[] revs;
try {
revs = getRevisions(key);
} catch (RocksDBException e) {
throw new IgniteInternalException(e);
}
if (revs == null || revs.length == 0) {
return Entry.empty(key);
}
long lastRev;
if (rev == LATEST_REV) {
lastRev = lastRevision(revs);
} else {
lastRev = exactRev ? rev : maxRevision(revs, rev);
}
// lastRev can be -1 if maxRevision return -1.
if (lastRev == -1) {
return Entry.empty(key);
}
return doGetValue(key, lastRev);
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class RocksDbKeyValueStorage method put.
/**
* {@inheritDoc}
*/
@Override
public void put(byte[] key, byte[] value) {
rwLock.writeLock().lock();
try (WriteBatch batch = new WriteBatch()) {
long curRev = rev + 1;
long cntr = updCntr + 1;
addDataToBatch(batch, key, value, curRev, cntr);
updateKeysIndex(batch, key, curRev);
fillAndWriteBatch(batch, curRev, cntr);
} 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 compact.
/**
* {@inheritDoc}
*/
@Override
public void compact() {
rwLock.writeLock().lock();
try (WriteBatch batch = new WriteBatch()) {
try (RocksIterator iterator = index.newIterator()) {
iterator.seekToFirst();
forEach(iterator, (key, value) -> compactForKey(batch, key, getAsLongs(value)));
}
fillAndWriteBatch(batch, rev, updCntr);
} 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 removeAll.
/**
* {@inheritDoc}
*/
@Override
public void removeAll(List<byte[]> keys) {
rwLock.writeLock().lock();
try (WriteBatch batch = new WriteBatch()) {
long curRev = rev + 1;
List<byte[]> existingKeys = new ArrayList<>(keys.size());
long counter = updCntr;
for (byte[] key : keys) {
if (addToBatchForRemoval(batch, key, curRev, counter + 1)) {
existingKeys.add(key);
counter++;
}
}
for (byte[] key : existingKeys) {
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 restoreSnapshot.
/**
* {@inheritDoc}
*/
@Override
public void restoreSnapshot(Path path) {
rwLock.writeLock().lock();
try (IngestExternalFileOptions ingestOptions = new IngestExternalFileOptions()) {
for (ColumnFamily family : Arrays.asList(data, index)) {
Path snapshotPath = path.resolve(family.name());
if (!Files.exists(snapshotPath)) {
throw new IgniteInternalException("Snapshot not found: " + snapshotPath);
}
family.ingestExternalFile(Collections.singletonList(snapshotPath.toString()), ingestOptions);
}
rev = bytesToLong(data.get(REVISION_KEY));
updCntr = bytesToLong(data.get(UPDATE_COUNTER_KEY));
} catch (RocksDBException e) {
throw new IgniteInternalException("Fail to ingest sst file at path: " + path, e);
} finally {
rwLock.writeLock().unlock();
}
}
Aggregations