use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class RocksDbKeyValueStorage method getAndPut.
/**
* {@inheritDoc}
*/
@NotNull
@Override
public Entry getAndPut(byte[] key, byte[] value) {
rwLock.writeLock().lock();
try (WriteBatch batch = new WriteBatch()) {
long curRev = rev + 1;
long cntr = updCntr + 1;
long[] revs = getRevisions(key);
final long lastRev = revs.length == 0 ? 0 : lastRevision(revs);
addDataToBatch(batch, key, value, curRev, cntr);
updateKeysIndex(batch, key, curRev);
fillAndWriteBatch(batch, curRev, cntr);
// Return previous value.
return doGetValue(key, lastRev);
} 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 updateKeysIndex.
/**
* Adds a revision to the keys index.
*
* @param batch Write batch.
* @param key Key.
* @param curRev New revision for key.
*/
private void updateKeysIndex(WriteBatch batch, byte[] key, long curRev) {
try {
// Get the revisions current value
byte @Nullable [] array = index.get(key);
// Store the new value
index.put(batch, key, appendLong(array, curRev));
} catch (RocksDBException e) {
throw new IgniteInternalException(e);
}
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class RocksDbKeyValueStorage method remove.
/**
* {@inheritDoc}
*/
@Override
public void remove(byte[] key) {
rwLock.writeLock().lock();
try (WriteBatch batch = new WriteBatch()) {
long curRev = rev + 1;
long counter = updCntr + 1;
if (addToBatchForRemoval(batch, key, curRev, counter)) {
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 MetaStorageManager method stop.
/**
* {@inheritDoc}
*/
@Override
public void stop() {
if (!stopGuard.compareAndSet(false, true)) {
return;
}
busyLock.block();
Optional<IgniteUuid> watchId;
try {
// TODO: add busy lock for init method https://issues.apache.org/jira/browse/IGNITE-15114
if (deployFut.isDone()) {
watchId = deployFut.get();
try {
if (watchId.isPresent()) {
metaStorageSvcFut.get().stopWatch(watchId.get());
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Failed to get meta storage service.");
throw new IgniteInternalException(e);
}
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Failed to get watch.");
throw new IgniteInternalException(e);
}
try {
if (raftGroupServiceFut != null) {
raftGroupServiceFut.get().shutdown();
raftMgr.stopRaftGroup(METASTORAGE_RAFT_GROUP_NAME);
}
} catch (InterruptedException | ExecutionException e) {
LOG.error("Failed to get meta storage raft group service.");
throw new IgniteInternalException(e);
} catch (NodeStoppingException e) {
throw new AssertionError("Loza was stopped before Meta Storage manager", e);
}
try {
storage.close();
} catch (Exception e) {
throw new IgniteInternalException("Exception when stopping the storage", e);
}
}
use of org.apache.ignite.lang.IgniteInternalException in project ignite-3 by apache.
the class RocksDbPartitionStorage method snapshot.
/**
* {@inheritDoc}
*/
@Override
@NotNull
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);
}
}, threadPool).thenRunAsync(() -> createSstFile(data, snapshot, tempPath), threadPool).whenComplete((nothing, 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
Files.move(tempPath, snapshotPath);
} catch (IOException e) {
throw new IgniteInternalException("Failed to rename: " + tempPath + " to " + snapshotPath, e);
}
});
}
Aggregations