From a35451eaa4fd0d08094035233bfd526ffe281f5a Mon Sep 17 00:00:00 2001 From: maoyouxiang Date: Thu, 31 May 2018 11:00:23 -0700 Subject: [PATCH] fix deadlock with enable_pipelined_write=true and max_successive_merges > 0 Summary: fix this https://github.com/facebook/rocksdb/issues/3916 Closes https://github.com/facebook/rocksdb/pull/3923 Differential Revision: D8215192 Pulled By: yiwu-arbug fbshipit-source-id: a4c2f839a91d92dc70906d2b7c6de0fe014a2422 --- HISTORY.md | 3 +++ db/db_impl_write.cc | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index f9c381a95..f2db631bb 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -7,6 +7,9 @@ ### New Features * Changes the format of index blocks by storing the key in their raw form rather than converting them to InternalKey. This saves 8 bytes per index key. The feature is backward compatbile but not forward compatible. It is disabled by default unless format_version 3 or above is used. +### Bug Fixes +* fix deadlock with enable_pipelined_write=true and max_successive_merges > 0 + ## 5.14.0 (5/16/2018) ### Public API Change * Add a BlockBasedTableOption to align uncompressed data blocks on the smaller of block size or page size boundary, to reduce flash reads by avoiding reads spanning 4K pages. diff --git a/db/db_impl_write.cc b/db/db_impl_write.cc index fce910c70..e05023ba5 100644 --- a/db/db_impl_write.cc +++ b/db/db_impl_write.cc @@ -1281,7 +1281,11 @@ Status DBImpl::SwitchMemtable(ColumnFamilyData* cfd, WriteContext* context, // In case of pipelined write is enabled, wait for all pending memtable // writers. if (immutable_db_options_.enable_pipelined_write) { + // Memtable writers may call DB::Get in case max_successive_merges > 0, + // which may lock mutex. Unlocking mutex here to avoid deadlock. + mutex_.Unlock(); write_thread_.WaitForMemTableWriters(); + mutex_.Lock(); } // Attempt to switch to a new memtable and trigger flush of old. -- GitLab