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

Turn titan into read-only on error during gc and version_change #42

Merged
merged 6 commits into from
Jul 18, 2019

Conversation

JiayuZzz
Copy link
Contributor

  • 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-io
Copy link

codecov-io commented Jul 14, 2019

Codecov Report

Merging #42 into master will increase coverage by 0.2%.
The diff coverage is 92.85%.

@@            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

@JiayuZzz JiayuZzz requested a review from yiwu-arbug July 15, 2019 02:20
Status bg_err = s;
if (!db_options_.listeners.empty()) {
// TODO(@jiayu) : check if mutex_ is freeable for futrue use case
mutex_.Unlock();
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

@@ -748,6 +814,9 @@ TEST_F(TitanDBTest, FallbackModeEncounterMissingBlobFile) {
VerifyDB({{"bar", "v1"}});
}

TEST_F(TitanDBTest, BackgroundErrorHandling) { BackgroundErrorHandling(); }
Copy link
Member

@tabokie tabokie Jul 15, 2019

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.

Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

mutex_.AssertHeld();
Status bg_err = s;
if (!db_options_.listeners.empty()) {
// TODO(@jiayu) : check if mutex_ is freeable for futrue use case
Copy link
Member

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);
Copy link
Member

@tabokie tabokie Jul 15, 2019

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.

Copy link
Collaborator

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.

@tabokie tabokie changed the title Turn titan into read-only if encountere error during gc and version_change Turn titan into read-only on error during gc and version_change Jul 15, 2019
Copy link
Collaborator

@yiwu-arbug yiwu-arbug left a 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;
Copy link
Collaborator

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);
Copy link
Collaborator

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));
Copy link
Collaborator

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?

@yiwu-arbug
Copy link
Collaborator

@tabokie thanks for reviewing btw :)

@JiayuZzz
Copy link
Contributor Author

JiayuZzz commented Jul 17, 2019

@yiwu-arbug @tabokie All modified, thanks for reviewing.

Copy link
Collaborator

@yiwu-arbug yiwu-arbug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yiwu-arbug yiwu-arbug merged commit 8ee2e79 into tikv:master Jul 18, 2019
GlitterIsMe added a commit to GlitterIsMe/titan that referenced this pull request Jul 20, 2019
Turn titan into read-only on error during gc and version_change (tikv#42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants