Search in sources :

Example 51 with IgniteInternalException

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();
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) WriteBatch(org.rocksdb.WriteBatch) NotNull(org.jetbrains.annotations.NotNull)

Example 52 with IgniteInternalException

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);
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) Nullable(org.jetbrains.annotations.Nullable)

Example 53 with IgniteInternalException

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();
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) WriteBatch(org.rocksdb.WriteBatch)

Example 54 with IgniteInternalException

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);
    }
}
Also used : IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ExecutionException(java.util.concurrent.ExecutionException) OperationTimeoutException(org.apache.ignite.internal.metastorage.client.OperationTimeoutException) CompactedException(org.apache.ignite.internal.metastorage.client.CompactedException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IgniteException(org.apache.ignite.lang.IgniteException) NoSuchElementException(java.util.NoSuchElementException) NodeStoppingException(org.apache.ignite.lang.NodeStoppingException) ExecutionException(java.util.concurrent.ExecutionException)

Example 55 with IgniteInternalException

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);
        }
    });
}
Also used : Path(java.nio.file.Path) Snapshot(org.rocksdb.Snapshot) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

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