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

Possible memory leak when iterating over database with MergeOperator enabled #4313

Closed
vitalyisaev2 opened this issue Aug 24, 2018 · 7 comments
Assignees
Labels
waiting Waiting for a response from the issue creator.

Comments

@vitalyisaev2
Copy link
Contributor

vitalyisaev2 commented Aug 24, 2018

We faced with memory leak in one of our applications, which is written in Go and uses RocksDB 5.13 via cgo interface (https://github.com/tecbot/gorocksdb). The application periodically iterates over whole RocksDB nstance and reads data sequentially key by key. It turns out that the memory allocated after every iteration is never freed.

Please visit this repo for the further information: https://github.com/vitalyisaev2/gorocksdb_merge_operator_issue
I will appreciate if somebody could point out, what's wrong with our database instance (database dump provided) or the application code.

heap profile

@ajkr
Copy link
Contributor

ajkr commented Aug 25, 2018

Also reported tecbot/gorocksdb#144.

I'll probably wait on them to rule out a problem with your Go application or the Go bindings, unless you want to try providing a repro using RocksDB directly in C or C++.

@ajkr ajkr self-assigned this Aug 25, 2018
@ajkr ajkr added the waiting Waiting for a response from the issue creator. label Aug 25, 2018
@vitalyisaev2
Copy link
Contributor Author

vitalyisaev2 commented Aug 27, 2018

@ajkr I've added C++ example and as far as I can see there is no memory leak in it.

Though I'm not totally sure if my implementations of MergeOperator in Go and C++ are equivalent: in Go it concatenates []byte slices via built-in append function, while in C++ it uses string::append (which I believe also implies memory allocations and copying). Providing that these operations are really equal, we can conclude that problem is somewhere in Go runtime.

Also I would like to ask you if there are any tools/methods/techniques to check the integrity of database structure. The data within a problematic dump is not corrupted, it just causes strange behavior of Go application.

@vitalyisaev2
Copy link
Contributor Author

I still have no idea what has happened to the database, but if I trigger whole database compaction manually at the start of the application, the leak is no longer observed.

Like this:

db.CompactRange(gorocksdb.Range{})

I thinks that there is some non-obvious and strange relationship between state of the database and the behavior of the iterators accessed through the CGO wrappers.

@vitalyisaev2
Copy link
Contributor Author

Sorry, but it is still an issue. Even after manual compaction, after several hours, the linear memory growth comes back.

@ajkr
Copy link
Contributor

ajkr commented Sep 5, 2018

To check integrity: first use DB::Open(), which will process WALs and MANIFEST. It'll return non-OK status if there's any problem. Then, call DB::VerifyChecksum(), which will verify checksums in all blocks of all SSTs and will let you know about any corruptions.

@ajkr
Copy link
Contributor

ajkr commented Sep 5, 2018

For your primary issue: I'm not sure I can be much help if the equivalent program written in C++ doesn't repro the issue. Maybe chase down the go binding maintainers? :)

@vitalyisaev2
Copy link
Contributor Author

@ajkr thanks for the tips! Going to check database integrity first

facebook-github-bot pushed a commit that referenced this issue Sep 13, 2018
Summary:
Please consider this small PR providing access to the `MemoryUsage::GetApproximateMemoryUsageByType` function in plain C API. Actually I'm working on Go application and now trying to investigate the reasons of high memory consumption (#4313). Go [wrappers](https://github.com/tecbot/gorocksdb) are built on the top of Rocksdb C API. According to the #706, `MemoryUsage::GetApproximateMemoryUsageByType` is considered as the best option to get database internal memory usage stats, but it wasn't supported in C API yet.
Pull Request resolved: #4340

Differential Revision: D9655135

Pulled By: ajkr

fbshipit-source-id: a3d2f3f47c143ae75862fbcca2f571ea1b49e14a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting Waiting for a response from the issue creator.
Projects
None yet
Development

No branches or pull requests

2 participants