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);
});
}
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));
}
}
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();
}
Aggregations