rocksdb icon indicating copy to clipboard operation
rocksdb copied to clipboard

Many empty memtables are created during MyRocks create index

Open rockeet opened this issue 2 years ago • 11 comments

Expected behavior

New MemTable should not be created if there are empty memtables.

Actual behavior

Many new (empty) MemTables are created during MyRocks create index. This is a benign bug, these empty MemTables are deleted on create index finishes.

Steps to reproduce the behavior

In MyRocks, create many indexes in parallel on existing large table while heavily writing to another table.

It seems these MemTables are created in IngestExternalFiles -> FlushMemTable -> SwitchMemtable.


We found this bug by our webview inspector for DB, gray are empty MemTables:

image

These empty MemTables get deleted:

image

rockeet avatar Dec 24 '23 08:12 rockeet

@rockeet would like to get started in contributing to rocksdb. Shall I assign this to myself?

pranavshenoy avatar Jan 03 '24 02:01 pranavshenoy

@rockeet would like to get started in contributing to rocksdb. Shall I assign this to myself?

Sure, thanks for your contribution!

rockeet avatar Jan 03 '24 14:01 rockeet

@rockeet, I was going through the code. One thing I noticed was, isEmpty() check is absent before calling SwitchMemtable() in FlushMemTable() while rest all invocations of SwitchMemtable() has the check .(https://github.com/facebook/rocksdb/blob/1de69409805e196dae4daad4975f6f83080f8a7c/db/db_impl/db_impl_compaction_flush.cc#L2344)

Let me know if I am going in the right direction. Thanks!

pranavshenoy avatar Jan 07 '24 00:01 pranavshenoy

@rockeet Can you tell me how can I reproduce this issue?

pranavshenoy avatar Jan 11 '24 02:01 pranavshenoy

@rockeet Can you tell me how can I reproduce this issue?

In MyRocks, create many indexes in parallel on existing large table while heavily writing to another table.

rockeet avatar Jan 11 '24 08:01 rockeet

PR #12230 did not fix the issue, we applied the PR to our branch, the issue still exists: image

The gray text is empty MemTable.

rockeet avatar Jan 29 '24 02:01 rockeet

PR #12230 did not fix the issue, we applied the PR to our branch, the issue still exists: image

The gray text is empty MemTable.

Are they still created in SwitchMemtable?

cbi42 avatar Jan 29 '24 19:01 cbi42

@rockeet I am trying to repro within RocksDB by writing a simple program. My intention is to check if Ingestion + write load is calling IngestExternalFiles -> FlushMemTable -> SwitchMemtable and also verify if at any time the memtable size is 0. I am having a hard time trying to reproing the issue. Am I missing something from trying to repro in RocksDB?

I am not familiar with the MyRocks setup and functionalities. It would be great if you could share me your setup or the steps that you followed. Thanks!

pranavshenoy avatar Jan 30 '24 04:01 pranavshenoy

@rockeet I am trying to repro within RocksDB by writing a simple program. My intention is to check if Ingestion + write load is calling IngestExternalFiles -> FlushMemTable -> SwitchMemtable and also verify if at any time the memtable size is 0. I am having a hard time trying to reproing the issue. Am I missing something from trying to repro in RocksDB?

I am not familiar with the MyRocks setup and functionalities. It would be great if you could share me your setup or the steps that you followed. Thanks!

Your setup missed long lived iterators scanning the db while writting db.

rockeet avatar Jan 30 '24 04:01 rockeet

Got it. missed this part. let me try adding it.

pranavshenoy avatar Mar 01 '24 01:03 pranavshenoy

@rockeet From my understanding, I thought SwitchMemtable is the only place where new Memtables are created. Since the issue is reproducible even with IsEmpty() check inside SwitchMemtable(), are there other places where Memtable can be created?

I added live iterators as well but couldn't get it to reproduce. The way I am checking is verifying if Memtable size is 0 in SwitchMemtable().. (ingesting multiple files with 1000+ keys and 10k concurrent writes and 1 iterator trying to read).

This is the sample test that I am writing. Would you recommend any changes to the test or the way I am verifying if there are empty memtables? https://github.com/pranavshenoy/speedb/commit/002c48c8931bf10144cb9dd47327ccc884d8c188

PR #12230 did not fix the issue, we applied the PR to our branch, the issue still exists: image

The gray text is empty MemTable.

pranavshenoy avatar Mar 02 '24 23:03 pranavshenoy