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