Search in sources :

Example 1 with ColumnFamily

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

the class RocksDbTableStorage method getOrCreateSortedIndex.

@Override
public SortedIndexStorage getOrCreateSortedIndex(String indexName) {
    assert !stopped : "Storage has been stopped";
    return sortedIndices.computeIfAbsent(indexName, name -> {
        var indexDescriptor = new SortedIndexDescriptor(name, tableCfg.value());
        ColumnFamilyDescriptor cfDescriptor = sortedIndexCfDescriptor(indexDescriptor);
        ColumnFamily cf = createColumnFamily(sortedIndexCfName(name), cfDescriptor);
        return new RocksDbSortedIndexStorage(cf, indexDescriptor);
    });
}
Also used : RocksDbSortedIndexStorage(org.apache.ignite.internal.storage.rocksdb.index.RocksDbSortedIndexStorage) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) SortedIndexDescriptor(org.apache.ignite.internal.storage.index.SortedIndexDescriptor) ColumnFamily(org.apache.ignite.internal.rocksdb.ColumnFamily)

Example 2 with ColumnFamily

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

the class RocksDbTableStorage method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws StorageException {
    try {
        Files.createDirectories(tablePath);
    } catch (IOException e) {
        throw new StorageException("Failed to create a directory for the table storage", e);
    }
    List<ColumnFamilyDescriptor> cfDescriptors = getExistingCfDescriptors();
    List<ColumnFamilyHandle> cfHandles = new ArrayList<>(cfDescriptors.size());
    DBOptions dbOptions = new DBOptions().setCreateIfMissing(true).setWriteBufferManager(dataRegion.writeBufferManager());
    try {
        db = RocksDB.open(dbOptions, tablePath.toAbsolutePath().toString(), cfDescriptors, cfHandles);
    } catch (RocksDBException e) {
        throw new StorageException("Failed to initialize RocksDB instance", e);
    }
    addToCloseableResources(db::closeE);
    // read all existing Column Families from the db and parse them according to type: meta, partition data or index.
    for (int i = 0; i < cfHandles.size(); i++) {
        ColumnFamilyHandle cfHandle = cfHandles.get(i);
        ColumnFamilyDescriptor cfDescriptor = cfDescriptors.get(i);
        String handleName = cfHandleName(cfHandle);
        ColumnFamily cf = new ColumnFamily(db, cfHandle, handleName, cfDescriptor.getOptions(), null);
        switch(columnFamilyType(handleName)) {
            case META:
                meta = addToCloseableResources(new RocksDbMetaStorage(cf));
                break;
            case PARTITION:
                partitionCf = addToCloseableResources(cf);
                break;
            case SORTED_INDEX:
                String indexName = sortedIndexName(handleName);
                var indexDescriptor = new SortedIndexDescriptor(indexName, tableCfg.value());
                sortedIndices.put(indexName, new RocksDbSortedIndexStorage(cf, indexDescriptor));
                break;
            default:
                throw new StorageException("Unidentified column family [name=" + handleName + ", table=" + tableCfg.name() + ']');
        }
    }
    if (partitionCf == null) {
        partitionCf = addToCloseableResources(createColumnFamily(PARTITION_CF_NAME, partitionCfDescriptor()));
    }
    partitions = new AtomicReferenceArray<>(tableCfg.value().partitions());
    for (int partId : meta.getPartitionIds()) {
        partitions.set(partId, new RocksDbPartitionStorage(threadPool, partId, db, partitionCf));
    }
}
Also used : RocksDBException(org.rocksdb.RocksDBException) ArrayList(java.util.ArrayList) RocksDbSortedIndexStorage(org.apache.ignite.internal.storage.rocksdb.index.RocksDbSortedIndexStorage) IOException(java.io.IOException) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) SortedIndexDescriptor(org.apache.ignite.internal.storage.index.SortedIndexDescriptor) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) ColumnFamily(org.apache.ignite.internal.rocksdb.ColumnFamily) DBOptions(org.rocksdb.DBOptions) StorageException(org.apache.ignite.internal.storage.StorageException)

Example 3 with ColumnFamily

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

the class RocksDbKeyValueStorage method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() {
    options = new DBOptions().setCreateMissingColumnFamilies(true).setCreateIfMissing(true);
    Options dataOptions = new Options().setCreateIfMissing(true).useFixedLengthPrefixExtractor(Long.BYTES);
    ColumnFamilyOptions dataFamilyOptions = new ColumnFamilyOptions(dataOptions);
    Options indexOptions = new Options().setCreateIfMissing(true);
    ColumnFamilyOptions indexFamilyOptions = new ColumnFamilyOptions(indexOptions);
    List<ColumnFamilyDescriptor> descriptors = Arrays.asList(new ColumnFamilyDescriptor(DATA.nameAsBytes(), dataFamilyOptions), new ColumnFamilyDescriptor(INDEX.nameAsBytes(), indexFamilyOptions));
    var handles = new ArrayList<ColumnFamilyHandle>();
    try {
        // Delete existing data, relying on the raft's snapshot and log playback
        destroyRocksDb();
        this.db = RocksDB.open(options, dbPath.toAbsolutePath().toString(), descriptors, handles);
    } catch (RocksDBException e) {
        throw new IgniteInternalException("Failed to start the storage", e);
    }
    data = new ColumnFamily(db, handles.get(0), DATA.name(), dataFamilyOptions, dataOptions);
    index = new ColumnFamily(db, handles.get(1), INDEX.name(), indexFamilyOptions, indexOptions);
}
Also used : ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) ColumnFamilyOptions(org.rocksdb.ColumnFamilyOptions) ReadOptions(org.rocksdb.ReadOptions) IngestExternalFileOptions(org.rocksdb.IngestExternalFileOptions) WriteOptions(org.rocksdb.WriteOptions) Options(org.rocksdb.Options) DBOptions(org.rocksdb.DBOptions) RocksDBException(org.rocksdb.RocksDBException) IgniteInternalException(org.apache.ignite.lang.IgniteInternalException) ArrayList(java.util.ArrayList) DBOptions(org.rocksdb.DBOptions) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ColumnFamily(org.apache.ignite.internal.rocksdb.ColumnFamily)

Example 4 with ColumnFamily

use of org.apache.ignite.internal.rocksdb.ColumnFamily 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

ColumnFamily (org.apache.ignite.internal.rocksdb.ColumnFamily)4 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)3 RocksDBException (org.rocksdb.RocksDBException)3 ArrayList (java.util.ArrayList)2 SortedIndexDescriptor (org.apache.ignite.internal.storage.index.SortedIndexDescriptor)2 RocksDbSortedIndexStorage (org.apache.ignite.internal.storage.rocksdb.index.RocksDbSortedIndexStorage)2 IgniteInternalException (org.apache.ignite.lang.IgniteInternalException)2 DBOptions (org.rocksdb.DBOptions)2 IngestExternalFileOptions (org.rocksdb.IngestExternalFileOptions)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 StorageException (org.apache.ignite.internal.storage.StorageException)1 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)1 ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)1 Options (org.rocksdb.Options)1 ReadOptions (org.rocksdb.ReadOptions)1 WriteOptions (org.rocksdb.WriteOptions)1