Search in sources :

Example 1 with INDEX

use of org.apache.ignite.internal.metastorage.server.persistence.StorageColumnFamilyType.INDEX 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);
        }
    });
}
Also used : Path(java.nio.file.Path) Value(org.apache.ignite.internal.metastorage.server.Value) Arrays(java.util.Arrays) StatementResult(org.apache.ignite.internal.metastorage.server.StatementResult) Statement(org.apache.ignite.internal.metastorage.server.Statement) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) RocksStorageUtils.longToBytes(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.longToBytes) ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) Entry(org.apache.ignite.internal.metastorage.server.Entry) Map(java.util.Map) RocksDBException(org.rocksdb.RocksDBException) Path(java.nio.file.Path) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReadOptions(org.rocksdb.ReadOptions) Operation(org.apache.ignite.internal.metastorage.server.Operation) KeyValueStorage(org.apache.ignite.internal.metastorage.server.KeyValueStorage) IngestExternalFileOptions(org.rocksdb.IngestExternalFileOptions) Collection(java.util.Collection) Cursor(org.apache.ignite.internal.util.Cursor) WriteOptions(org.rocksdb.WriteOptions) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) WatchEvent(org.apache.ignite.internal.metastorage.server.WatchEvent) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) Options(org.rocksdb.Options) ColumnFamily(org.apache.ignite.internal.rocksdb.ColumnFamily) NotNull(org.jetbrains.annotations.NotNull) RocksStorageUtils.getAsLongs(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.getAsLongs) RocksStorageUtils.bytesToValue(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.bytesToValue) RocksStorageUtils.bytesToLong(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.bytesToLong) DATA(org.apache.ignite.internal.metastorage.server.persistence.StorageColumnFamilyType.DATA) WriteBatch(org.rocksdb.WriteBatch) CompletableFuture(java.util.concurrent.CompletableFuture) RocksUtils.forEach(org.apache.ignite.internal.rocksdb.RocksUtils.forEach) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) RocksUtils.createSstFile(org.apache.ignite.internal.rocksdb.RocksUtils.createSstFile) TreeSet(java.util.TreeSet) RocksIterator(org.rocksdb.RocksIterator) ArrayList(java.util.ArrayList) Condition(org.apache.ignite.internal.metastorage.server.Condition) TOMBSTONE(org.apache.ignite.internal.metastorage.server.Value.TOMBSTONE) RocksDB(org.rocksdb.RocksDB) LONG_EMPTY_ARRAY(org.apache.ignite.internal.util.ArrayUtils.LONG_EMPTY_ARRAY) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) RocksBiPredicate(org.apache.ignite.internal.rocksdb.RocksBiPredicate) RocksUtils.find(org.apache.ignite.internal.rocksdb.RocksUtils.find) ExecutorService(java.util.concurrent.ExecutorService) Files(java.nio.file.Files) DBOptions(org.rocksdb.DBOptions) INDEX(org.apache.ignite.internal.metastorage.server.persistence.StorageColumnFamilyType.INDEX) If(org.apache.ignite.internal.metastorage.server.If) IOException(java.io.IOException) RocksStorageUtils.appendLong(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.appendLong) TimeUnit(java.util.concurrent.TimeUnit) TestOnly(org.jetbrains.annotations.TestOnly) Paths(java.nio.file.Paths) Snapshot(org.rocksdb.Snapshot) Comparator(java.util.Comparator) RocksStorageUtils.keyToRocksKey(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.keyToRocksKey) Collections(java.util.Collections) Update(org.apache.ignite.internal.metastorage.server.Update) RocksStorageUtils.valueToBytes(org.apache.ignite.internal.metastorage.server.persistence.RocksStorageUtils.valueToBytes) Snapshot(org.rocksdb.Snapshot) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

IOException (java.io.IOException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutorService (java.util.concurrent.ExecutorService)1 Executors (java.util.concurrent.Executors)1 TimeUnit (java.util.concurrent.TimeUnit)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Condition (org.apache.ignite.internal.metastorage.server.Condition)1