Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) rocksdb-compression-on-windows #22

Merged
merged 20 commits into from
Mar 11, 2019

Conversation

fengjiachun
Copy link
Contributor

Seems like the rocksdb jni for Windows doesn't come linked with any of the compression type


if (Platform.isWindows()) {
// Seems like the rocksdb jni for Windows doesn't come linked with any of the compression type
options.setCompressionType(CompressionType.NO_COMPRESSION);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有没有默认压缩可以选,是否可以不设置?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以不设置

.setLevel0FileNumCompactionTrigger(LEVEL0_FILE_NUM_COMPACTION_TRIGGER) //
.setLevel0SlowdownWritesTrigger(LEVEL0_SLOWDOWN_WRITES_TRIGGER) //
.setLevel0StopWritesTrigger(LEVEL0_STOP_WRITES_TRIGGER) //
.setMaxBytesForLevelBase(MAX_BYTES_FOR_LEVEL_BASE) //
.setTargetFileSizeBase(TARGET_FILE_SIZE_BASE) //
.setMergeOperator(mergeOperator) //
.setMemtablePrefixBloomSizeRatio(0.125);
if (Platform.isWindows()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

似乎重复的代码?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先不要 merge 吧,我把 export rocksdb options 一块改掉

@fengjiachun
Copy link
Contributor Author

@killme2008 再看下是否有其他意见?

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
for (final DBOptions opts : rocksDBOptionsTable.values()) {
if (opts != null) {
opts.close();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果用户已经释放了,这里会 core dump 的。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我记得这些选项会在 Storage 这些服务里 close,所以无论是用户,还是这些 shutdown hook,都没有必要去 close,选项统一交给使用的服务关闭。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

理论上只要允许用户传入 options,都阻止不了用户提前释放 options 产生的 core dump, 这个比较头疼;
StorageOptionsFactory 中其实是存储了一份 options 模板,getXXX 方法会返回一个 copy 副本,这些副本都是有使用者统一释放的;
shutdown hook 释放的是那一份模板 options

我做了以下改进:

  1. 增加 checkInvalid (opts) 方法,在 copy 之前先检查 opts 是否被释放, 如果已被用户释放则抛出异常,避免直接 copy 产生的 core dump,但先检查再拷贝不是原子操作,无法完全避免用户提前释放导致 core dump
  2. 去掉 shutdown hook, 增加 releaseAllOptions() , 用户可以在程序退出时选择主动调用该方法来释放所有模板options,但其实也可以不调用,因为 rocksdb 的options在进程退出时都会自动释放

@fengjiachun fengjiachun merged commit ca0805c into develop Mar 11, 2019
@fengjiachun fengjiachun deleted the fix/rocksdb-compression-on-windows branch March 11, 2019 08:54
This was referenced Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants