Search in sources :

Example 1 with RocksDbSortedIndexStorage

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

use of org.apache.ignite.internal.storage.rocksdb.index.RocksDbSortedIndexStorage 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)

Aggregations

ColumnFamily (org.apache.ignite.internal.rocksdb.ColumnFamily)2 SortedIndexDescriptor (org.apache.ignite.internal.storage.index.SortedIndexDescriptor)2 RocksDbSortedIndexStorage (org.apache.ignite.internal.storage.rocksdb.index.RocksDbSortedIndexStorage)2 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 StorageException (org.apache.ignite.internal.storage.StorageException)1 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)1 DBOptions (org.rocksdb.DBOptions)1 RocksDBException (org.rocksdb.RocksDBException)1