Repository navigation
Conversation
|
@hx235 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
ajkr
left a comment
There was a problem hiding this comment.
Sorry this doesn't leave us with a more understandable/maintainable test compared to before. Why do we need to disable DumpStats() and loosen some refcount checks? The description sounds like we gave up on repro - did the hypothesis not lead to any progress?
Replied in the internal |
|
Discussed offline that we are going to either loosen the assertion without disabling the dump stat or verifying it's actually the dump stat reference and remove the dump stat. Not both the same time in this PR for clarity in testing. |
beb9dbb to
cdc5995
Compare
|
@hx235 has updated the pull request. You must reimport the pull request before landing. |
|
Update:
|
|
@hx235 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
cdc5995 to
29b8fd3
Compare
|
@hx235 has updated the pull request. You must reimport the pull request before landing. |
|
@hx235 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
As mentioned offline I think these ASSERT_GE(2, ...s can be reverted. Extra references to ColumnFamilyData (e.g., from DumpStats()) do not increase the number of calls to RegisterDbPaths()
There was a problem hiding this comment.
For clarification, I was trying to assert there are at least two ref, one for each cf handle
Just to make sure I understand, are you suggesting to (a) revert this particular ASSERT_GE(2,..) to exact assertion, OR (b) all the ASSERT_GE(2, ...) to exact assertion OR (c) completely removing ASSERT_GE(2, ...) from all places?
There was a problem hiding this comment.
For (a), are we sure there won't be any extra reference to the cf other than the 2 references from the handles?
- I am not quite sure about this especially after we see some in the following places without reproducing it.
For (b), we will probably need to keep the ASSERT_GE(2, ...) at least for the place where we've seen the violation.
F(c - current PR), I think at least we need to assert the minimum of the column ref (even though that might be a false positive due to "extra reference" being a lot.
For "(d)", we just do ASSERT_GE(0, ...) for all places other than deletion. But that will prevent us from testing the case for "Delete one handle will not drop CF's entry from cache because another handle is still referencing cf_path_0_."
- Well.. one could also say even when we try to test it like (c), there might still be false positive.
There was a problem hiding this comment.
For clarification, I was trying to assert there are at least two ref, one for each cf handle
The calls to RegisterDbPaths() and UnregisterDbPaths() are in the ColumnFamilyData constructor/destructor, not ColumnFamilyHandle.
Just to make sure I understand, are you suggesting to (a) revert this particular ASSERT_GE(2,..) to exact assertion, OR (b) all the ASSERT_GE(2, ...) to exact assertion OR (c) completely removing ASSERT_GE(2, ...)?
(b)
There was a problem hiding this comment.
For clarification, I was trying to assert there are at least two ref, one for each cf handle
The calls to RegisterDbPaths() and UnregisterDbPaths() are in the ColumnFamilyData constructor/destructor, not ColumnFamilyHandle.
To clarify further, I realize you did not say that ColumnFamilyHandle references/unreferences the cache entry. I just have no idea how there could ever be more than two references here or the other place that says ASSERT_GE(2, ....
There was a problem hiding this comment.
(loosening assertions because there might be something we haven't thought of).
Well that's just my thought I'd like to share so that I can clearly get to where we disagree. I also wouldn't mind reverting those ASSERT_GE() to be honest. All I said above was just trying to make my point of view clear and again get to where we disagree, not necessarily asking for agreement :) Will update the PR.
I also welcome any efforts into reproducing it as this deserves more time than I have spent on it so far.
There was a problem hiding this comment.
Edit: I guess the underlying understanding I have from the test being flaky is that there can be extra refcount to cf_path_0 other than the ones from cf handles in the creation. I don't know what those ref count are/when they start to appear. Me not knowing it might be a result of not investigating the code enough (e.g, pinning down exactly where in the code places can ref cf_path_0)
The only code path I can find that references cf_path_0 is ColumnFamilyData constructor -> RegisterDbPaths() -> RefAndCacheLogicalBlockSize(). I believe only the two ColumnFamilyDatas (the one for "cf1" and the one for "cf2") register cf_path_0. So I do not see where more than two cf_path_0 references could ever come from, and IMO there needs to be a plausible explanation if we're going to embed that expectation in the test.
On the other hand, ColumnFamilyData could be referenced in more places, like for background work. Extra references to ColumnFamilyData extend its lifetime beyond when it is dropped and the user's CF handle is released. The effect is just it takes longer than the test expects to release a reference to cf_path_0 via ColumnFamilyData destructor -> UnregisterDbPaths() -> UnrefAndTryRemoveCachedLogicalBlockSize().
There was a problem hiding this comment.
I also welcome any efforts into reproducing it as this deserves more time than I have spent on it so far.
I think we should still reconsider who should be the PR author as it is taking more of my time to review than it deserves. We shouldn't be doing reviewer-driven development. It is quite inefficient and took many rounds of back and forth for me to even realize that the ASSERT_GE(2, ... changes were based on not investigating it yet.
There was a problem hiding this comment.
Here's how to repro the timing conditions in any case:
diff --git a/db/db_impl/db_impl.cc b/db/db_impl/db_impl.cc
index fd4d8a0c9..2aea4d6e9 100644
--- a/db/db_impl/db_impl.cc
+++ b/db/db_impl/db_impl.cc
@@ -949,6 +949,7 @@ void DBImpl::DumpStats() {
TEST_SYNC_POINT("DBImpl::DumpStats:StartRunning");
{
+ usleep(100000);
InstrumentedMutexLock l(&mutex_);
for (auto cfd : *versions_->GetColumnFamilySet()) {
if (cfd->initialized()) {
@@ -959,6 +960,9 @@ void DBImpl::DumpStats() {
cfd->Ref();
{
InstrumentedMutexUnlock u(&mutex_);
+ if (cfd->GetName() == "cf1") {
+ sleep(3);
+ }
cfd->internal_stats()->CollectCacheEntryStats(/*foreground=*/false);
}
cfd->UnrefAndTryDelete();
diff --git a/db/db_logical_block_size_cache_test.cc b/db/db_logical_block_size_cache_test.cc
index 1057871c9..728e14541 100644
--- a/db/db_logical_block_size_cache_test.cc
+++ b/db/db_logical_block_size_cache_test.cc
@@ -202,6 +202,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, CreateColumnFamilies) {
// Delete one handle will not drop cache because another handle is still
// referencing cf_path_0_.
+ usleep(150000);
ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[0]));
ASSERT_EQ(2, cache_->Size());
ASSERT_TRUE(cache_->Contains(dbname_));
Failure I get is
$ ./db_logical_block_size_cache_test --gtest_filter=DBLogicalBlockSizeCacheTest.CreateColumnFamilies
Note: Google Test filter = DBLogicalBlockSizeCacheTest.CreateColumnFamilies
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from DBLogicalBlockSizeCacheTest
[ RUN ] DBLogicalBlockSizeCacheTest.CreateColumnFamilies
db/db_logical_block_size_cache_test.cc:211: Failure
Expected equality of these values:
1
cache_->GetRefCount(cf_path_0_)
Which is: 2
[ FAILED ] DBLogicalBlockSizeCacheTest.CreateColumnFamilies (334 ms)
[----------] 1 test from DBLogicalBlockSizeCacheTest (334 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (334 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] DBLogicalBlockSizeCacheTest.CreateColumnFamilies
1 FAILED TEST
Segmentation fault (core dumped)
There was a problem hiding this comment.
Thanks for the repro! For other comments you left, I will reply through internal chat but no pressure in checking it before you return :)
|
@hx235 has updated the pull request. You must reimport the pull request before landing. |
|
@hx235 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
Update:
|
0aff572 to
d5d8f30
Compare
|
@hx235 has updated the pull request. You must reimport the pull request before landing. |
|
Update:
|
|
@hx235 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
…eta#9516) Summary: **Context:** `DBLogicalBlockSizeCacheTest.CreateColumnFamilies` is flaky on a rare occurrence of assertion failure below ``` db/db_logical_block_size_cache_test.cc:210 Expected equality of these values: 1 cache_->GetRefCount(cf_path_0_) Which is: 2 ``` Root-cause: `ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[0]));` in the test may not successfully decrease the ref count of `cf_path_0_` since the decreasing only happens in the clean-up of `ColumnFamilyData` when `ColumnFamilyData` has no referencing to it, which may not be true when `db->DestroyColumnFamilyHandle(cfs[0])` is called since background work such as `DumpStats()` can hold reference to that `ColumnFamilyData` (suggested and repro-d by ajkr ). Similar case `ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[1]));`. See following for a deterministic repro: ``` diff --git a/db/db_impl/db_impl.cc b/db/db_impl/db_impl.cc index 196b428..4e7a834c4 100644 --- a/db/db_impl/db_impl.cc +++ b/db/db_impl/db_impl.cc @@ -956,10 +956,16 @@ void DBImpl::DumpStats() { // near-atomically. // Get a ref before unlocking cfd->Ref(); + if (cfd->GetName() == "cf1" || cfd->GetName() == "cf2") { + TEST_SYNC_POINT("DBImpl::DumpStats:PostCFDRef"); + } { InstrumentedMutexUnlock u(&mutex_); cfd->internal_stats()->CollectCacheEntryStats(/*foreground=*/false); } + if (cfd->GetName() == "cf1" || cfd->GetName() == "cf2") { + TEST_SYNC_POINT("DBImpl::DumpStats::PreCFDUnrefAndTryDelete"); + } cfd->UnrefAndTryDelete(); } } diff --git a/db/db_logical_block_size_cache_test.cc b/db/db_logical_block_size_cache_test.cc index 1057871..c3872c036 100644 --- a/db/db_logical_block_size_cache_test.cc +++ b/db/db_logical_block_size_cache_test.cc @@ -9,6 +9,7 @@ #include "env/io_posix.h" #include "rocksdb/db.h" #include "rocksdb/env.h" +#include "test_util/sync_point.h" namespace ROCKSDB_NAMESPACE { class EnvWithCustomLogicalBlockSizeCache : public EnvWrapper { @@ -183,6 +184,15 @@ TEST_F(DBLogicalBlockSizeCacheTest, CreateColumnFamilies) { ASSERT_EQ(1, cache_->GetRefCount(dbname_)); std::vector<ColumnFamilyHandle*> cfs; + ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing(); + ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->LoadDependency( + {{"DBLogicalBlockSizeCacheTest::CreateColumnFamilies::PostSetupTwoCFH", + "DBImpl::DumpStats:StartRunning"}, + {"DBImpl::DumpStats:PostCFDRef", + "DBLogicalBlockSizeCacheTest::CreateColumnFamilies::PreDeleteTwoCFH"}, + {"DBLogicalBlockSizeCacheTest::CreateColumnFamilies::" + "PostFinishCheckingRef", + "DBImpl::DumpStats::PreCFDUnrefAndTryDelete"}}); ASSERT_OK(db->CreateColumnFamilies(cf_options, {"cf1", "cf2"}, &cfs)); ASSERT_EQ(2, cache_->Size()); ASSERT_TRUE(cache_->Contains(dbname_)); @@ -190,7 +200,7 @@ TEST_F(DBLogicalBlockSizeCacheTest, CreateColumnFamilies) { ASSERT_TRUE(cache_->Contains(cf_path_0_)); ASSERT_EQ(2, cache_->GetRefCount(cf_path_0_)); } // Delete one handle will not drop cache because another handle is still // referencing cf_path_0_. + TEST_SYNC_POINT( + "DBLogicalBlockSizeCacheTest::CreateColumnFamilies::PostSetupTwoCFH"); + TEST_SYNC_POINT( + "DBLogicalBlockSizeCacheTest::CreateColumnFamilies::PreDeleteTwoCFH"); ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[0])); ASSERT_EQ(2, cache_->Size()); ASSERT_TRUE(cache_->Contains(dbname_)); @@ -209,16 +221,20 @@ TEST_F(DBLogicalBlockSizeCacheTest, CreateColumnFamilies) { ASSERT_TRUE(cache_->Contains(cf_path_0_)); // Will fail ASSERT_EQ(1, cache_->GetRefCount(cf_path_0_)); // Delete the last handle will drop cache. ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[1])); ASSERT_EQ(1, cache_->Size()); ASSERT_TRUE(cache_->Contains(dbname_)); // Will fail ASSERT_EQ(1, cache_->GetRefCount(dbname_)); + TEST_SYNC_POINT( + "DBLogicalBlockSizeCacheTest::CreateColumnFamilies::" + "PostFinishCheckingRef"); delete db; ASSERT_EQ(0, cache_->Size()); ASSERT_OK(DestroyDB(dbname_, options, {{"cf1", cf_options}, {"cf2", cf_options}})); + ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing(); } ``` **Summary** - Removed the flaky assertion - Clarified the comments for the test Pull Request resolved: meta#9516 Test Plan: - CI - Monitor for future flakiness Reviewed By: ajkr Differential Revision: D34055232 Pulled By: hx235 fbshipit-source-id: 9bf83ae5fa88bf6fc829876494d4692082e4c357
Context:
DBLogicalBlockSizeCacheTest.CreateColumnFamiliesis flaky on a rare occurrence of assertion failure belowRoot-cause:
ASSERT_OK(db->DestroyColumnFamilyHandle(cfs[0]));in the test may not successfully decrease the ref count ofcf_path_0_since the decreasing only happens in the clean-up ofColumnFamilyDatawhenColumnFamilyDatahas no referencing to it, which may not be true whendb->DestroyColumnFamilyHandle(cfs[0])is called since background work such asDumpStats()can hold reference to thatColumnFamilyData(suggested and repro-d by @ajkr ). Similar caseASSERT_OK(db->DestroyColumnFamilyHandle(cfs[1]));.See following for a deterministic repro:
Summary
Test