Java Code Examples for org.rocksdb.ColumnFamilyOptions#close()

The following examples show how to use org.rocksdb.ColumnFamilyOptions#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StorageOptionsFactory.java    From sofa-jraft with Apache License 2.0 6 votes vote down vote up
/**
 * Get a new default ColumnFamilyOptions or a copy of the exist
 * ColumnFamilyOptions.  Users should call ColumnFamilyOptions#close()
 * to release resources themselves.
 *
 * @param cls the key of ColumnFamilyOptions
 * @return new default ColumnFamilyOptions or a copy of the exist
 * ColumnFamilyOptions
 */
public static ColumnFamilyOptions getRocksDBColumnFamilyOptions(final Class<?> cls) {
    Requires.requireNonNull(cls, "cls");
    ColumnFamilyOptions opts = columnFamilyOptionsTable.get(cls.getName());
    if (opts == null) {
        final ColumnFamilyOptions newOpts = getDefaultRocksDBColumnFamilyOptions();
        opts = columnFamilyOptionsTable.putIfAbsent(cls.getName(), newOpts);
        if (opts == null) {
            opts = newOpts;
        } else {
            newOpts.close();
        }
    }
    // NOTE: This does a shallow copy, which means comparator, merge_operator,
    // compaction_filter, compaction_filter_factory and other pointers will be
    // cloned!
    return new ColumnFamilyOptions(checkInvalid(opts));
}
 
Example 2
Source File: RocksDBLogStorage.java    From sofa-jraft with Apache License 2.0 5 votes vote down vote up
@Override
public void shutdown() {
    this.writeLock.lock();
    try {
        // The shutdown order is matter.
        // 1. close column family handles
        closeDB();
        onShutdown();
        // 2. close column family options.
        for (final ColumnFamilyOptions opt : this.cfOptions) {
            opt.close();
        }
        // 3. close options
        this.dbOptions.close();
        if (this.statistics != null) {
            this.statistics.close();
        }
        this.writeOptions.close();
        this.totalOrderReadOptions.close();
        // 4. help gc.
        this.cfOptions.clear();
        this.dbOptions = null;
        this.statistics = null;
        this.writeOptions = null;
        this.totalOrderReadOptions = null;
        this.defaultHandle = null;
        this.confHandle = null;
        this.db = null;
        LOG.info("DB destroyed, the db path is: {}.", this.path);
    } finally {
        this.writeLock.unlock();
    }
}
 
Example 3
Source File: RocksDBStateBackendTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testCorrectMergeOperatorSet() throws Exception {
	prepareRocksDB();
	final ColumnFamilyOptions columnFamilyOptions = spy(new ColumnFamilyOptions());
	RocksDBKeyedStateBackend<Integer> test = null;

	try {
		test = RocksDBTestUtils.builderForTestDB(
			tempFolder.newFolder(),
			IntSerializer.INSTANCE,
			db,
			defaultCFHandle,
			columnFamilyOptions)
			.setEnableIncrementalCheckpointing(enableIncrementalCheckpointing)
			.build();

		ValueStateDescriptor<String> stubState1 =
			new ValueStateDescriptor<>("StubState-1", StringSerializer.INSTANCE);
		test.createInternalState(StringSerializer.INSTANCE, stubState1);
		ValueStateDescriptor<String> stubState2 =
			new ValueStateDescriptor<>("StubState-2", StringSerializer.INSTANCE);
		test.createInternalState(StringSerializer.INSTANCE, stubState2);

		// The default CF is pre-created so sum up to 2 times (once for each stub state)
		verify(columnFamilyOptions, Mockito.times(2))
			.setMergeOperatorName(RocksDBKeyedStateBackend.MERGE_OPERATOR_NAME);
	} finally {
		if (test != null) {
			IOUtils.closeQuietly(test);
			test.dispose();
		}
		columnFamilyOptions.close();
	}
}
 
Example 4
Source File: RocksDBStateBackendTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testCorrectMergeOperatorSet() throws Exception {
	prepareRocksDB();
	final ColumnFamilyOptions columnFamilyOptions = spy(new ColumnFamilyOptions());
	RocksDBKeyedStateBackend<Integer> test = null;
	try (DBOptions options = new DBOptions().setCreateIfMissing(true)) {
		ExecutionConfig executionConfig = new ExecutionConfig();
		test = new RocksDBKeyedStateBackendBuilder<>(
			"test",
			Thread.currentThread().getContextClassLoader(),
			tempFolder.newFolder(),
			options,
			stateName -> columnFamilyOptions,
			mock(TaskKvStateRegistry.class),
			IntSerializer.INSTANCE,
			1,
			new KeyGroupRange(0, 0),
			executionConfig,
			mock(LocalRecoveryConfig.class),
			RocksDBStateBackend.PriorityQueueStateType.HEAP,
			TtlTimeProvider.DEFAULT,
			new UnregisteredMetricsGroup(),
			Collections.emptyList(),
			AbstractStateBackend.getCompressionDecorator(executionConfig),
			db,
			defaultCFHandle,
			new CloseableRegistry())
			.setEnableIncrementalCheckpointing(enableIncrementalCheckpointing)
			.build();
		ValueStateDescriptor<String> stubState1 =
			new ValueStateDescriptor<>("StubState-1", StringSerializer.INSTANCE);
		test.createInternalState(StringSerializer.INSTANCE, stubState1);
		ValueStateDescriptor<String> stubState2 =
			new ValueStateDescriptor<>("StubState-2", StringSerializer.INSTANCE);
		test.createInternalState(StringSerializer.INSTANCE, stubState2);

		// The default CF is pre-created so sum up to 2 times (once for each stub state)
		verify(columnFamilyOptions, Mockito.times(2))
			.setMergeOperatorName(RocksDBKeyedStateBackend.MERGE_OPERATOR_NAME);
	} finally {
		if (test != null) {
			IOUtils.closeQuietly(test);
			test.dispose();
		}
		columnFamilyOptions.close();
	}
}
 
Example 5
Source File: RocksRawKVStore.java    From sofa-jraft with Apache License 2.0 4 votes vote down vote up
@Override
public void shutdown() {
    final Lock writeLock = this.readWriteLock.writeLock();
    writeLock.lock();
    try {
        if (this.db == null) {
            return;
        }
        this.shutdownLock.setMaxPermits(0);
        closeRocksDB();
        if (this.defaultHandle != null) {
            this.defaultHandle.close();
            this.defaultHandle = null;
        }
        if (this.sequenceHandle != null) {
            this.sequenceHandle.close();
            this.sequenceHandle = null;
        }
        if (this.lockingHandle != null) {
            this.lockingHandle.close();
            this.lockingHandle = null;
        }
        if (this.fencingHandle != null) {
            this.fencingHandle.close();
            this.fencingHandle = null;
        }
        for (final ColumnFamilyOptions cfOptions : this.cfOptionsList) {
            cfOptions.close();
        }
        this.cfOptionsList.clear();
        this.cfDescriptors.clear();
        if (this.options != null) {
            this.options.close();
            this.options = null;
        }
        if (this.statisticsCollector != null) {
            try {
                this.statisticsCollector.shutdown(3000);
            } catch (final Throwable ignored) {
                // ignored
            }
        }
        if (this.statistics != null) {
            this.statistics.close();
            this.statistics = null;
        }
        if (this.writeOptions != null) {
            this.writeOptions.close();
            this.writeOptions = null;
        }
    } finally {
        writeLock.unlock();
        LOG.info("[RocksRawKVStore] shutdown successfully.");
    }
}
 
Example 6
Source File: RocksDBStateBackendTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testCorrectMergeOperatorSet() throws Exception {
	prepareRocksDB();
	final ColumnFamilyOptions columnFamilyOptions = spy(new ColumnFamilyOptions());
	RocksDBKeyedStateBackend<Integer> test = null;
	try (DBOptions options = new DBOptions().setCreateIfMissing(true)) {
		ExecutionConfig executionConfig = new ExecutionConfig();
		test = new RocksDBKeyedStateBackendBuilder<>(
			"test",
			Thread.currentThread().getContextClassLoader(),
			tempFolder.newFolder(),
			options,
			stateName -> columnFamilyOptions,
			mock(TaskKvStateRegistry.class),
			IntSerializer.INSTANCE,
			1,
			new KeyGroupRange(0, 0),
			executionConfig,
			mock(LocalRecoveryConfig.class),
			RocksDBStateBackend.PriorityQueueStateType.HEAP,
			TtlTimeProvider.DEFAULT,
			new UnregisteredMetricsGroup(),
			Collections.emptyList(),
			AbstractStateBackend.getCompressionDecorator(executionConfig),
			db,
			defaultCFHandle,
			new CloseableRegistry())
			.setEnableIncrementalCheckpointing(enableIncrementalCheckpointing)
			.build();
		ValueStateDescriptor<String> stubState1 =
			new ValueStateDescriptor<>("StubState-1", StringSerializer.INSTANCE);
		test.createInternalState(StringSerializer.INSTANCE, stubState1);
		ValueStateDescriptor<String> stubState2 =
			new ValueStateDescriptor<>("StubState-2", StringSerializer.INSTANCE);
		test.createInternalState(StringSerializer.INSTANCE, stubState2);

		// The default CF is pre-created so sum up to 2 times (once for each stub state)
		verify(columnFamilyOptions, Mockito.times(2))
			.setMergeOperatorName(RocksDBKeyedStateBackend.MERGE_OPERATOR_NAME);
	} finally {
		if (test != null) {
			IOUtils.closeQuietly(test);
			test.dispose();
		}
		columnFamilyOptions.close();
	}
}