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

Implemented a file logger that uses WritableFileWriter #5491

Closed
wants to merge 10 commits into from

Conversation

ggaurav28
Copy link
Contributor

@ggaurav28 ggaurav28 commented Jun 19, 2019

Summary:
Current PosixLogger performs IO operations using posix calls. Thus the
current implementation will not work for non-posix env. Created a new
logger class EnvLogger that uses env specific WritableFileWriter for IO operations.

Test Plan:
make check

@ggaurav28 ggaurav28 marked this pull request as ready for review June 19, 2019 21:58
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.

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

Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

Are we ready to replace the existing PosixLogger, or shall we keep both in the beginning?

@ggaurav28
Copy link
Contributor Author

Are we ready to replace the existing PosixLogger, or shall we keep both in the beginning?

It may be safer to add a gflag to control whether to use a posix logger or a generic logger. We can enable new logger in debug build (by default) and later when we have confidence we can enable the new logger in release build as well.
Thoughts?

@siying
Copy link
Contributor

siying commented Jun 20, 2019

@ggaurav28 RocksDB (except tools) doesn't rely on gflag, and we don't require users to use gflag at all. I suggest we leave default as PosixLogger for now, and users can directly create EnvLogger for now if they want. Gradually, we can talk about replacement.

@ggaurav28
Copy link
Contributor Author

users can directly create E

Sounds good. I will make the changes and update the PR.

@facebook-github-bot
Copy link
Contributor

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

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

Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

We need to expose a factory function under include/rocksdb for users to be able to create such a logger.

Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

And how about make it the default logger for Env::NewLogger()?

Copy link
Contributor

@siying siying left a comment

Choose a reason for hiding this comment

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

I'm a little bit worried that we are adding some code with 0 unit test coverage. Can we add a unit test and does some simple verification?

logging/env_logger.h Outdated Show resolved Hide resolved
logging/env_logger.h Outdated Show resolved Hide resolved
logging/env_logger.h Outdated Show resolved Hide resolved
logging/env_logger.h Show resolved Hide resolved
void Logv(const char* format, va_list ap) override {
IOSTATS_TIMER_GUARD(logger_nanos);

const uint64_t thread_id = (*gettid_)();
Copy link
Contributor

Choose a reason for hiding this comment

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

We had a discussion about changing it to a more modern way of getting ID. Does STL thread ID works?

Copy link
Contributor Author

@ggaurav28 ggaurav28 Jun 21, 2019

Choose a reason for hiding this comment

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

env.cc has this function. Leverage it in the EnvLogger class.

uint64_t Env::GetThreadID() const {
  std::hash<std::thread::id> hasher;
  return hasher(std::this_thread::get_id());
}

private:
std::unique_ptr<WritableFileWriter> file_;
uint64_t (*gettid_)(); // Return the thread id for the current thread
mutable port::Mutex mutex_; // Mutex to protect the shared variables below.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does mutex_ need to be tagged as mutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case mutex does not need to be mutable as there are no const method acquiring the mutex.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mutex now needs to be mutable as it is being acquired in const member method GetLogFileSize().

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

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

logging/env_logger.h Outdated Show resolved Hide resolved
logging/env_logger.h Outdated Show resolved Hide resolved
@facebook-github-bot
Copy link
Contributor

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

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

env/env.cc Show resolved Hide resolved
if (now_micros - last_flush_micros_ >= flush_every_seconds_ * 1000000) {
FlushLocked();
}
mutex_.WriteUnlock();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use a scoped lock instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we use scoped lock, then lock will be held while delete is called at line#145
i.e.,
if (base != buffer) { delete[] base; }
Is it acceptable to hold the lock while memory is being freed?

logging/env_logger.h Outdated Show resolved Hide resolved
*result = std::make_shared<EnvLogger>(std::move(writable_file), fname,
options, this);
return Status::OK();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I missed something but I don't see this function is covered in unit test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function can not be directly used in the test as this is a virtual method. PosixEnv which is being used in the test has overridden this method.

As you suggested, i have created a new public helper method NewEnvLogger(). This method is now being called from test.

env/env.cc Outdated Show resolved Hide resolved
@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

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

// EnvLogger) for storing informational messages. This method is public for
// testing purposes.
Status NewEnvLogger(const std::string& fname,
std::shared_ptr<Logger>* result);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move it to a standalone function, rather than a function of Env?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Made this as a static method in EnvLogger class.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused here. It is still Env::NewEnvLogger(). Did I miss anything?

@facebook-github-bot
Copy link
Contributor

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

}

static Status NewEnvLogger(const std::string& fname, Env* env,
std::shared_ptr<Logger>* result) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope the function is made public under include/rocksdb/. Now users cannot call this function, and they cannot easily call Env::NewLogger() either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Siying, Can you please let me know the file under the include/rocksdb where i should put this method? I will make the change accordingly.

Copy link
Contributor

Choose a reason for hiding this comment

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

For now, maybe env.h?

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. Moved it back to env.h. Please review it again.

Copy link
Contributor

Choose a reason for hiding this comment

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

What I see now is that it is back to a function of Env. The problem is that users have to create a Env class to use it, but it takes an Env as a parameter. To me it is confusing.

What I suggested is that, we need to keep the function publically available, which means under include/rocksdb, this is what users can see after we release the code. Also, it should not be a function of Env. So a workable solution is to create a standalone function in include/rocksdb/env.h.

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 misunderstood your earlier comment. Made it a standalone function in env.h.
I have implemented it in env.cc as EnvLogger does not have a cc file. If you prefer, i can create a env_logger.cc file to hold the implementation of NewEnvLogger.

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

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

…perations

Summary:
Current PosixLogger performs IO operations using posix calls. Thus the
current implementation will not work for non-posix env. Created a new
logger class EnvLogger that uses WritableFileWriter for IO operations.

Test Plan:
make check

Reviewers:

Subscribers:

Tasks:T45934141

Tags:
Summary:
PosixLogger will be replaced with EnvLogger later.

Test Plan:
make check -j32
Function NewEnvLogger is now a static method of EnvLogger class.
@facebook-github-bot
Copy link
Contributor

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

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

@@ -1563,4 +1565,10 @@ Status NewHdfsEnv(Env** hdfs_env, const std::string& fsname);
// This is a factory method for TimedEnv defined in utilities/env_timed.cc.
Env* NewTimedEnv(Env* base_env);

// Returns an instance of logger that can be used for storing informational
// messages.
// This is a factory method for EnvLogger declared in logging/env_logging.h
Copy link
Contributor

Choose a reason for hiding this comment

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

I know we did it in the function above but it's not a good idea to mention files outside include/rocksdb here, because they may not be available to users when it is released.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should i update the comment to say "This is a factory method to create a generic logger that uses env specific methods for logging operations"?

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 will push the code. We can make the changes in the comment later in a separate PR.

@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

@ggaurav28 is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@ggaurav28 merged this pull request in 60d8b19.

@facebook-github-bot
Copy link
Contributor

@ggaurav28 merged this pull request in 60d8b19.

merryChris pushed a commit to merryChris/rocksdb that referenced this pull request Nov 18, 2019
Summary:
Current PosixLogger performs IO operations using posix calls. Thus the
current implementation will not work for non-posix env. Created a new
logger class EnvLogger that uses env specific WritableFileWriter for IO operations.
Pull Request resolved: facebook#5491

Test Plan: make check

Differential Revision: D15909002

Pulled By: ggaurav28

fbshipit-source-id: 13a8105176e8e42db0c59798d48cb6a0dbccc965
levichen94 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 18, 2021
Summary:
Current PosixLogger performs IO operations using posix calls. Thus the
current implementation will not work for non-posix env. Created a new
logger class EnvLogger that uses env specific WritableFileWriter for IO operations.
Pull Request resolved: facebook/rocksdb#5491

Test Plan: make check

Differential Revision: D15909002

Pulled By: ggaurav28

fbshipit-source-id: 13a8105176e8e42db0c59798d48cb6a0dbccc965
Signed-off-by: Changlong Chen <levisonchen@live.cn>
mm304321141 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 23, 2021
Summary:
Current PosixLogger performs IO operations using posix calls. Thus the
current implementation will not work for non-posix env. Created a new
logger class EnvLogger that uses env specific WritableFileWriter for IO operations.
Pull Request resolved: facebook/rocksdb#5491

Test Plan: make check

Differential Revision: D15909002

Pulled By: ggaurav28

fbshipit-source-id: 13a8105176e8e42db0c59798d48cb6a0dbccc965
Signed-off-by: Changlong Chen <levisonchen@live.cn>
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

3 participants