Search in sources :

Example 1 with IngestExternalFileOptions

use of org.rocksdb.IngestExternalFileOptions in project sofa-jraft by sofastack.

the class RocksRawKVStore method ingestSstFiles.

void ingestSstFiles(final EnumMap<SstColumnFamily, File> sstFileTable) {
    final Timer.Context timeCtx = getTimeContext("INGEST_SST_FILE");
    final Lock readLock = this.readWriteLock.readLock();
    readLock.lock();
    try {
        for (final Map.Entry<SstColumnFamily, File> entry : sstFileTable.entrySet()) {
            final SstColumnFamily sstColumnFamily = entry.getKey();
            final File sstFile = entry.getValue();
            final ColumnFamilyHandle columnFamilyHandle = findColumnFamilyHandle(sstColumnFamily);
            try (final IngestExternalFileOptions ingestOptions = new IngestExternalFileOptions()) {
                if (FileUtils.sizeOf(sstFile) == 0L) {
                    return;
                }
                final String filePath = sstFile.getAbsolutePath();
                LOG.info("Start ingest sst file {}.", filePath);
                this.db.ingestExternalFile(columnFamilyHandle, Collections.singletonList(filePath), ingestOptions);
            } catch (final RocksDBException e) {
                throw new StorageException("Fail to ingest sst file at path: " + sstFile, e);
            }
        }
    } finally {
        readLock.unlock();
        timeCtx.stop();
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) Timer(com.codahale.metrics.Timer) Map(java.util.Map) EnumMap(java.util.EnumMap) File(java.io.File) StorageException(com.alipay.sofa.jraft.rhea.errors.StorageException) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) IngestExternalFileOptions(org.rocksdb.IngestExternalFileOptions) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) DistributedLock(com.alipay.sofa.jraft.rhea.util.concurrent.DistributedLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Example 2 with IngestExternalFileOptions

use of org.rocksdb.IngestExternalFileOptions 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)

Example 3 with IngestExternalFileOptions

use of org.rocksdb.IngestExternalFileOptions in project ignite-3 by apache.

the class RocksDbPartitionStorage method restoreSnapshot.

/**
 * {@inheritDoc}
 */
@Override
public void restoreSnapshot(Path path) {
    try (IngestExternalFileOptions ingestOptions = new IngestExternalFileOptions()) {
        Path snapshotPath = path.resolve(data.name());
        if (!Files.exists(snapshotPath)) {
            throw new IgniteInternalException("Snapshot not found: " + snapshotPath);
        }
        data.ingestExternalFile(Collections.singletonList(snapshotPath.toString()), ingestOptions);
    } catch (RocksDBException e) {
        throw new IgniteInternalException("Fail to ingest sst file at path: " + path, e);
    }
}
Also used : Path(java.nio.file.Path) RocksDBException(org.rocksdb.RocksDBException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) IngestExternalFileOptions(org.rocksdb.IngestExternalFileOptions)

Example 4 with IngestExternalFileOptions

use of org.rocksdb.IngestExternalFileOptions in project dingo by dingodb.

the class RocksRawKVStore method ingestSstFiles.

void ingestSstFiles(final EnumMap<SstColumnFamily, File> sstFileTable) {
    final Timer.Context timeCtx = getTimeContext("INGEST_SST_FILE");
    final Lock readLock = this.readWriteLock.readLock();
    readLock.lock();
    try {
        for (final Map.Entry<SstColumnFamily, File> entry : sstFileTable.entrySet()) {
            final SstColumnFamily sstColumnFamily = entry.getKey();
            final File sstFile = entry.getValue();
            final ColumnFamilyHandle columnFamilyHandle = findColumnFamilyHandle(sstColumnFamily);
            try (final IngestExternalFileOptions ingestOptions = new IngestExternalFileOptions()) {
                if (FileUtils.sizeOf(sstFile) == 0L) {
                    return;
                }
                final String filePath = sstFile.getAbsolutePath();
                LOG.info("Start ingest sst file {}.", filePath);
                this.db.ingestExternalFile(columnFamilyHandle, Collections.singletonList(filePath), ingestOptions);
            } catch (final RocksDBException e) {
                throw new StorageException("Fail to ingest sst file at path: " + sstFile, e);
            }
        }
    } finally {
        readLock.unlock();
        timeCtx.stop();
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) Timer(com.codahale.metrics.Timer) Map(java.util.Map) EnumMap(java.util.EnumMap) File(java.io.File) StorageException(io.dingodb.store.row.errors.StorageException) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) IngestExternalFileOptions(org.rocksdb.IngestExternalFileOptions) DistributedLock(io.dingodb.store.row.util.concurrent.DistributedLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock)

Aggregations

IngestExternalFileOptions (org.rocksdb.IngestExternalFileOptions)4 RocksDBException (org.rocksdb.RocksDBException)4 Timer (com.codahale.metrics.Timer)2 File (java.io.File)2 Path (java.nio.file.Path)2 EnumMap (java.util.EnumMap)2 Map (java.util.Map)2 Lock (java.util.concurrent.locks.Lock)2 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)2 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)2 IgniteInternalException (org.apache.ignite.lang.IgniteInternalException)2 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)2 StorageException (com.alipay.sofa.jraft.rhea.errors.StorageException)1 DistributedLock (com.alipay.sofa.jraft.rhea.util.concurrent.DistributedLock)1 StorageException (io.dingodb.store.row.errors.StorageException)1 DistributedLock (io.dingodb.store.row.util.concurrent.DistributedLock)1 ColumnFamily (org.apache.ignite.internal.rocksdb.ColumnFamily)1