Search in sources :

Example 46 with IgniteInternalException

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

Example 47 with IgniteInternalException

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

Example 48 with IgniteInternalException

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

Example 49 with IgniteInternalException

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

Example 50 with IgniteInternalException

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();
    }
}
Also used : Path(java.nio.file.Path) RocksDBException(org.rocksdb.RocksDBException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IngestExternalFileOptions(org.rocksdb.IngestExternalFileOptions) ColumnFamily(org.apache.ignite.internal.rocksdb.ColumnFamily)

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