Search in sources :

Example 1 with SortedIndexDescriptor

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

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

use of org.apache.ignite.internal.storage.index.SortedIndexDescriptor in project ignite-3 by apache.

the class BinaryRowComparator method rowComparator.

/**
 * Creates a comparator that compares two {@link Row}s by comparing individual columns.
 */
private static Comparator<Row> rowComparator(SortedIndexDescriptor descriptor) {
    return descriptor.indexRowColumns().stream().map(columnDescriptor -> {
        Column column = columnDescriptor.column();
        Comparator<Row> columnComparator = columnComparator(column);
        if (columnDescriptor.nullable()) {
            columnComparator = comparingNull(row -> row.hasNullValue(column.schemaIndex(), column.type().spec()) ? null : row, columnComparator);
        }
        return columnDescriptor.asc() ? columnComparator : columnComparator.reversed();
    }).reduce(Comparator::thenComparing).orElseThrow();
}
Also used : ComparatorUtils.comparingNull(org.apache.ignite.internal.storage.rocksdb.index.ComparatorUtils.comparingNull) Comparator.comparingInt(java.util.Comparator.comparingInt) Arrays(java.util.Arrays) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) SortedIndexDescriptor(org.apache.ignite.internal.storage.index.SortedIndexDescriptor) Comparator.comparingDouble(java.util.Comparator.comparingDouble) NativeTypeSpec(org.apache.ignite.internal.schema.NativeTypeSpec) AbstractComparator(org.rocksdb.AbstractComparator) ByteBuffer(java.nio.ByteBuffer) ByteOrder(java.nio.ByteOrder) ComparatorOptions(org.rocksdb.ComparatorOptions) Comparator.comparingLong(java.util.Comparator.comparingLong) Row(org.apache.ignite.internal.schema.row.Row) Column(org.apache.ignite.internal.schema.Column) Comparator.comparing(java.util.Comparator.comparing) Comparator(java.util.Comparator) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow) Column(org.apache.ignite.internal.schema.Column) BinaryRow(org.apache.ignite.internal.schema.BinaryRow) Row(org.apache.ignite.internal.schema.row.Row) ByteBufferRow(org.apache.ignite.internal.schema.ByteBufferRow)

Aggregations

SortedIndexDescriptor (org.apache.ignite.internal.storage.index.SortedIndexDescriptor)3 ColumnFamily (org.apache.ignite.internal.rocksdb.ColumnFamily)2 RocksDbSortedIndexStorage (org.apache.ignite.internal.storage.rocksdb.index.RocksDbSortedIndexStorage)2 ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ByteOrder (java.nio.ByteOrder)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 Comparator.comparing (java.util.Comparator.comparing)1 Comparator.comparingDouble (java.util.Comparator.comparingDouble)1 Comparator.comparingInt (java.util.Comparator.comparingInt)1 Comparator.comparingLong (java.util.Comparator.comparingLong)1 BinaryRow (org.apache.ignite.internal.schema.BinaryRow)1 ByteBufferRow (org.apache.ignite.internal.schema.ByteBufferRow)1 Column (org.apache.ignite.internal.schema.Column)1 NativeTypeSpec (org.apache.ignite.internal.schema.NativeTypeSpec)1 Row (org.apache.ignite.internal.schema.row.Row)1 StorageException (org.apache.ignite.internal.storage.StorageException)1