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

Add a DB Session ID #6959

Closed
wants to merge 1 commit into from
Closed

Add a DB Session ID #6959

wants to merge 1 commit into from

Conversation

gg814
Copy link
Contributor

@gg814 gg814 commented Jun 9, 2020

Summary:
Added DB::GetDbSessionId by using the same format and machinery as DB::GetDbIdentity.
The DB Session ID is generated (and therefore, updated) each time a DB object is opened. It is written to the LOG file right after the line of “DB SUMMARY”.
A test for the uniqueness, for different openings and during the same opening, is also added.

Test plan:
Passed make check

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@gg814 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@zhichao-cao
Copy link
Contributor

Thanks for working on this! I'm thinking it is a little misleading using 'Session', the first impression is like a session in a transaction or something similar. How about DBObjectID? @pdillinger what do you think?

@pdillinger
Copy link
Contributor

I'm thinking it is a little misleading using 'Session', the first impression is like a session in a transaction or something similar. How about DBObjectID?

Roughly quoting Andrew from internal group chat: that requires the user to know that Open() is only offered as a static function (otherwise, someone could reopen the DB using the same object).

So I think we decided to keep the name used here.

@zhichao-cao
Copy link
Contributor

I'm thinking it is a little misleading using 'Session', the first impression is like a session in a transaction or something similar. How about DBObjectID?

Roughly quoting Andrew from internal group chat: that requires the user to know that Open() is only offered as a static function (otherwise, someone could reopen the DB using the same object).

So I think we decided to keep the name used here.

Yeah. Agree, keep DbSessionID will be better (post is just one minutes ahead of the discussion>_<)


#ifndef ROCKSDB_LITE
Close();
ASSERT_OK(ReadOnlyReopen(options));
Copy link
Contributor

Choose a reason for hiding this comment

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

How about add a test to compare the id between regular reopen and ReadonlyReopen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! :)

@@ -1538,6 +1538,9 @@ class DB {
// Returns Status::OK if identity could be set properly
virtual Status GetDbIdentity(std::string& identity) const = 0;

// Return a unique identifier for each DB object that is opened
virtual Status GetDbSessionId(std::string& session_id) const = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you add new interfaces to include/rocksdb/*, please also change HISTORY.md and add the comments to Public API changes

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should say how unique the value is. (Unique only among currently open DBs on the host?) Perhaps add this:

This DB session ID should be unique among all open DB instances on all hosts, and should be unique among re-openings of the same or other DBs. (Two open DBs have the same identity from other function GetDbIdentity when one is physically copied from the other.)

@@ -980,6 +982,7 @@ class DBImpl : public DB {
protected:
const std::string dbname_;
std::string db_id_;
std::string db_session_id_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comment to the new variable being added.

@@ -1161,6 +1164,8 @@ class DBImpl : public DB {
// bump up the version set's next_file_number_ to be 1 + largest_file_number.
Status FinishBestEffortsRecovery();

void SetDbSessionId() { db_session_id_ = env_->GenerateUniqueId(); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, a comment here to explain why we use GenerateUniqueId() as the ID and also when SetDbSessionId() should be called.

@facebook-github-bot
Copy link
Contributor

@gg814 has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@gg814 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

HISTORY.md Outdated
@@ -23,6 +23,7 @@
* ldb now uses options.force_consistency_checks = true by default and "--disable_consistency_checks" is added to disable it.
* DB::OpenForReadOnly no longer creates files or directories if the named DB does not exist, unless create_if_missing is set to true.
* The consistency checks that validate LSM state changes (table file additions/deletions during flushes and compactions) are now stricter, more efficient, and no longer optional, i.e. they are performed even if `force_consistency_checks` is `false`.
* `DB::GetDbSessionId(std::string& session_id)` is added. `session_id` stores a unique identifier that gets updated every the DB is opened. This identifier is recorded in the `LOG` file on the line starting with `DB Session ID:`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say, "that gets reset every time the DB is opened." ("updated" can mean new value depends on old value.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe follow what Peter stated before "This DB session ID should be unique among all open DB instances on all hosts, and should be unique among re-openings of the same or other DBs." to explain session_id

@@ -1538,6 +1538,9 @@ class DB {
// Returns Status::OK if identity could be set properly
virtual Status GetDbIdentity(std::string& identity) const = 0;

// Return a unique identifier for each DB object that is opened
virtual Status GetDbSessionId(std::string& session_id) const = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should say how unique the value is. (Unique only among currently open DBs on the host?) Perhaps add this:

This DB session ID should be unique among all open DB instances on all hosts, and should be unique among re-openings of the same or other DBs. (Two open DBs have the same identity from other function GetDbIdentity when one is physically copied from the other.)

@gg814
Copy link
Contributor Author

gg814 commented Jun 12, 2020

@pdillinger Thanks for the review! Will update correspondingly.

@facebook-github-bot
Copy link
Contributor

@gg814 has updated the pull request. Re-import the pull request

@facebook-github-bot
Copy link
Contributor

@gg814 has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@gg814 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Summary:
Added DB::GetDbSessionId by using the same format and machinery as DB::GetDbIdentity.
The DB Session ID is generated (and therefore, updated) each time a DB object is opened. It is written to the LOG file right after the line of “DB SUMMARY”.
A test for the uniqueness, for different openings and during the same opening, is also added.

Test plan:
Passed make check
@facebook-github-bot
Copy link
Contributor

@gg814 has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@gg814 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@zhichao-cao zhichao-cao left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for working on this!

@facebook-github-bot
Copy link
Contributor

@gg814 merged this pull request in 88db97b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants