Search in sources :

Example 26 with ColumnFamilyDescriptor

use of org.rocksdb.ColumnFamilyDescriptor in project flink by apache.

the class RocksDBWriteBatchWrapperTest method testWriteBatchWrapperFlushAfterCountExceed.

/**
 * Tests that {@link RocksDBWriteBatchWrapper} flushes after the kv count exceeds the
 * preconfigured value.
 */
@Test
public void testWriteBatchWrapperFlushAfterCountExceed() throws Exception {
    try (RocksDB db = RocksDB.open(folder.newFolder().getAbsolutePath());
        WriteOptions options = new WriteOptions().setDisableWAL(true);
        ColumnFamilyHandle handle = db.createColumnFamily(new ColumnFamilyDescriptor("test".getBytes()));
        RocksDBWriteBatchWrapper writeBatchWrapper = new RocksDBWriteBatchWrapper(db, options, 100, 50000)) {
        long initBatchSize = writeBatchWrapper.getDataSize();
        byte[] dummy = new byte[2];
        ThreadLocalRandom.current().nextBytes(dummy);
        for (int i = 1; i < 100; ++i) {
            writeBatchWrapper.put(handle, dummy, dummy);
            // each kv consumes 8 bytes
            assertEquals(initBatchSize + 8 * i, writeBatchWrapper.getDataSize());
        }
        writeBatchWrapper.put(handle, dummy, dummy);
        assertEquals(initBatchSize, writeBatchWrapper.getDataSize());
    }
}
Also used : WriteOptions(org.rocksdb.WriteOptions) RocksDB(org.rocksdb.RocksDB) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) Test(org.junit.Test)

Example 27 with ColumnFamilyDescriptor

use of org.rocksdb.ColumnFamilyDescriptor in project flink by apache.

the class RocksDBIncrementalCheckpointUtilsTest method testClipDBWithKeyGroupRangeHelper.

private void testClipDBWithKeyGroupRangeHelper(KeyGroupRange targetGroupRange, KeyGroupRange currentGroupRange, int keyGroupPrefixBytes) throws RocksDBException, IOException {
    try (RocksDB rocksDB = RocksDB.open(tmp.newFolder().getAbsolutePath());
        ColumnFamilyHandle columnFamilyHandle = rocksDB.createColumnFamily(new ColumnFamilyDescriptor("test".getBytes()))) {
        int currentGroupRangeStart = currentGroupRange.getStartKeyGroup();
        int currentGroupRangeEnd = currentGroupRange.getEndKeyGroup();
        DataOutputSerializer outputView = new DataOutputSerializer(32);
        for (int i = currentGroupRangeStart; i <= currentGroupRangeEnd; ++i) {
            for (int j = 0; j < 100; ++j) {
                outputView.clear();
                CompositeKeySerializationUtils.writeKeyGroup(i, keyGroupPrefixBytes, outputView);
                CompositeKeySerializationUtils.writeKey(j, IntSerializer.INSTANCE, outputView, false);
                rocksDB.put(columnFamilyHandle, outputView.getCopyOfBuffer(), String.valueOf(j).getBytes());
            }
        }
        for (int i = currentGroupRangeStart; i <= currentGroupRangeEnd; ++i) {
            for (int j = 0; j < 100; ++j) {
                outputView.clear();
                CompositeKeySerializationUtils.writeKeyGroup(i, keyGroupPrefixBytes, outputView);
                CompositeKeySerializationUtils.writeKey(j, IntSerializer.INSTANCE, outputView, false);
                byte[] value = rocksDB.get(columnFamilyHandle, outputView.getCopyOfBuffer());
                Assert.assertEquals(String.valueOf(j), new String(value));
            }
        }
        RocksDBIncrementalCheckpointUtils.clipDBWithKeyGroupRange(rocksDB, Collections.singletonList(columnFamilyHandle), targetGroupRange, currentGroupRange, keyGroupPrefixBytes, RocksDBConfigurableOptions.WRITE_BATCH_SIZE.defaultValue().getBytes());
        for (int i = currentGroupRangeStart; i <= currentGroupRangeEnd; ++i) {
            for (int j = 0; j < 100; ++j) {
                outputView.clear();
                CompositeKeySerializationUtils.writeKeyGroup(i, keyGroupPrefixBytes, outputView);
                CompositeKeySerializationUtils.writeKey(j, IntSerializer.INSTANCE, outputView, false);
                byte[] value = rocksDB.get(columnFamilyHandle, outputView.getCopyOfBuffer());
                if (targetGroupRange.contains(i)) {
                    Assert.assertEquals(String.valueOf(j), new String(value));
                } else {
                    Assert.assertNull(value);
                }
            }
        }
    }
}
Also used : RocksDB(org.rocksdb.RocksDB) DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle)

Example 28 with ColumnFamilyDescriptor

use of org.rocksdb.ColumnFamilyDescriptor in project flink by apache.

the class RocksDBResource method createNewColumnFamily.

/**
 * Creates and returns a new column family with the given name.
 */
public ColumnFamilyHandle createNewColumnFamily(String name) {
    try {
        final ColumnFamilyHandle columnFamily = rocksDB.createColumnFamily(new ColumnFamilyDescriptor(name.getBytes(), columnFamilyOptions));
        columnFamilyHandles.add(columnFamily);
        return columnFamily;
    } catch (Exception ex) {
        throw new FlinkRuntimeException("Could not create column family.", ex);
    }
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException)

Example 29 with ColumnFamilyDescriptor

use of org.rocksdb.ColumnFamilyDescriptor in project flink by apache.

the class RocksDBIncrementalRestoreOperation method restoreDBInstanceFromStateHandle.

private RestoredDBInstance restoreDBInstanceFromStateHandle(IncrementalRemoteKeyedStateHandle restoreStateHandle, Path temporaryRestoreInstancePath) throws Exception {
    try (RocksDBStateDownloader rocksDBStateDownloader = new RocksDBStateDownloader(numberOfTransferringThreads)) {
        rocksDBStateDownloader.transferAllStateDataToDirectory(restoreStateHandle, temporaryRestoreInstancePath, cancelStreamRegistry);
    }
    KeyedBackendSerializationProxy<K> serializationProxy = readMetaData(restoreStateHandle.getMetaStateHandle());
    // read meta data
    List<StateMetaInfoSnapshot> stateMetaInfoSnapshots = serializationProxy.getStateMetaInfoSnapshots();
    List<ColumnFamilyDescriptor> columnFamilyDescriptors = createColumnFamilyDescriptors(stateMetaInfoSnapshots, false);
    List<ColumnFamilyHandle> columnFamilyHandles = new ArrayList<>(stateMetaInfoSnapshots.size() + 1);
    RocksDB restoreDb = RocksDBOperationUtils.openDB(temporaryRestoreInstancePath.toString(), columnFamilyDescriptors, columnFamilyHandles, RocksDBOperationUtils.createColumnFamilyOptions(this.rocksHandle.getColumnFamilyOptionsFactory(), "default"), this.rocksHandle.getDbOptions());
    return new RestoredDBInstance(restoreDb, columnFamilyHandles, columnFamilyDescriptors, stateMetaInfoSnapshots);
}
Also used : RocksDB(org.rocksdb.RocksDB) ArrayList(java.util.ArrayList) StateMetaInfoSnapshot(org.apache.flink.runtime.state.metainfo.StateMetaInfoSnapshot) RocksDBStateDownloader(org.apache.flink.contrib.streaming.state.RocksDBStateDownloader) ColumnFamilyDescriptor(org.rocksdb.ColumnFamilyDescriptor) ColumnFamilyHandle(org.rocksdb.ColumnFamilyHandle)

Aggregations

ColumnFamilyDescriptor (org.rocksdb.ColumnFamilyDescriptor)29 ColumnFamilyHandle (org.rocksdb.ColumnFamilyHandle)25 ArrayList (java.util.ArrayList)16 RocksDB (org.rocksdb.RocksDB)13 RocksDBException (org.rocksdb.RocksDBException)11 DBOptions (org.rocksdb.DBOptions)10 ColumnFamilyOptions (org.rocksdb.ColumnFamilyOptions)9 File (java.io.File)7 WriteOptions (org.rocksdb.WriteOptions)5 IOException (java.io.IOException)3 Map (java.util.Map)3 Tuple2 (org.apache.flink.api.java.tuple.Tuple2)3 Test (org.junit.Test)3 ReadOptions (org.rocksdb.ReadOptions)3 DataOutputStream (java.io.DataOutputStream)2 ByteBuffer (java.nio.ByteBuffer)2 Path (java.nio.file.Path)2 Random (java.util.Random)2 ByteArrayOutputStreamWithPos (org.apache.flink.core.memory.ByteArrayOutputStreamWithPos)2 RegisteredStateMetaInfoBase (org.apache.flink.runtime.state.RegisteredStateMetaInfoBase)2