-
Notifications
You must be signed in to change notification settings - Fork 171
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
Turn titan into read-only on error during gc and version_change #42
Conversation
JiayuZzz
commented
Jul 14, 2019
- Set background error if encountered a critical error. Now it's set for two cases
- BackgroundGC() error
- LogAndApply() error after generate new blob file
- If background error is set, all following foreground write operations will be refused and return background error status
Codecov Report
@@ Coverage Diff @@
## master #42 +/- ##
=========================================
+ Coverage 84.12% 84.33% +0.2%
=========================================
Files 43 43
Lines 2577 2617 +40
=========================================
+ Hits 2168 2207 +39
- Misses 409 410 +1 |
src/db_impl_gc.cc
Outdated
Status bg_err = s; | ||
if (!db_options_.listeners.empty()) { | ||
// TODO(@jiayu) : check if mutex_ is freeable for futrue use case | ||
mutex_.Unlock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why we could unlock here. Listener iterator needs syncing, and callback will mutate bg_err
too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bg_err is a local variable, won't be accessed concurrently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if listeners would be modified, it seems no API to do that unless reopen db
src/titan_db_test.cc
Outdated
@@ -748,6 +814,9 @@ TEST_F(TitanDBTest, FallbackModeEncounterMissingBlobFile) { | |||
VerifyDB({{"bar", "v1"}}); | |||
} | |||
|
|||
TEST_F(TitanDBTest, BackgroundErrorHandling) { BackgroundErrorHandling(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we unfold the function here? Not general enough to be a test class method i think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
src/db_impl.h
Outdated
@@ -171,6 +221,9 @@ class TitanDBImpl : public TitanDB { | |||
EnvOptions env_options_; | |||
DBImpl* db_impl_; | |||
TitanDBOptions db_options_; | |||
// Turn DB into read-only if background happened |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
src/db_impl_gc.cc
Outdated
mutex_.AssertHeld(); | ||
Status bg_err = s; | ||
if (!db_options_.listeners.empty()) { | ||
// TODO(@jiayu) : check if mutex_ is freeable for futrue use case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
@@ -155,6 +196,15 @@ class TitanDBImpl : public TitanDB { | |||
return oldest_snapshot; | |||
} | |||
|
|||
Status SetBGError(const Status& s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add mutex held hint. btw, google code style says we should write accessor as set_bg_error()
and bg_error()
, not sure if we follows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the rocksdb convention is do SetBgError
for non-trivial assessor and set_bg_error
for trivial ones. And this one is non-trivial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! The patch is nice and clean!
@@ -43,6 +43,47 @@ class TitanDBImpl : public TitanDB { | |||
|
|||
Status CloseImpl(); | |||
|
|||
using TitanDB::Put; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the following changes to db_impl.cc?
@@ -155,6 +196,15 @@ class TitanDBImpl : public TitanDB { | |||
return oldest_snapshot; | |||
} | |||
|
|||
Status SetBGError(const Status& s); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the rocksdb convention is do SetBgError
for non-trivial assessor and set_bg_error
for trivial ones. And this one is non-trivial.
// BG error is restored by listener for first time | ||
ASSERT_OK(db_->Put(WriteOptions(), key, val)); | ||
SetBGError(Status::IOError("")); | ||
ASSERT_OK(db_->Get(ReadOptions(), key, &val)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put a non-empty value and verify the value return from Get
?
@tabokie thanks for reviewing btw :) |
@yiwu-arbug @tabokie All modified, thanks for reviewing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Turn titan into read-only on error during gc and version_change (tikv#42)