-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Conversation
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.
@ggaurav28 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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.
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. |
@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. |
Sounds good. I will make the changes and update the PR. |
8b57163
to
adeebd7
Compare
@ggaurav28 has updated the pull request. Re-import the pull request |
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.
@ggaurav28 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
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.
We need to expose a factory function under include/rocksdb for users to be able to create such a logger.
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.
And how about make it the default logger for Env::NewLogger()?
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 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
void Logv(const char* format, va_list ap) override { | ||
IOSTATS_TIMER_GUARD(logger_nanos); | ||
|
||
const uint64_t thread_id = (*gettid_)(); |
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.
We had a discussion about changing it to a more modern way of getting ID. Does STL thread ID works?
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.
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. |
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.
Why does mutex_
need to be tagged as mutable
?
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.
In this case mutex does not need to be mutable as there are no const method acquiring the mutex.
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.
Mutex now needs to be mutable as it is being acquired in const member method GetLogFileSize().
@ggaurav28 has updated the pull request. Re-import the pull request |
c9f2e8f
to
74af120
Compare
@ggaurav28 has updated the pull request. Re-import the pull request |
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.
@ggaurav28 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@ggaurav28 has updated the pull request. Re-import the pull request |
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.
@ggaurav28 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
logging/env_logger.h
Outdated
if (now_micros - last_flush_micros_ >= flush_every_seconds_ * 1000000) { | ||
FlushLocked(); | ||
} | ||
mutex_.WriteUnlock(); |
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.
Can we use a scoped lock instead?
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.
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?
*result = std::make_shared<EnvLogger>(std::move(writable_file), fname, | ||
options, this); | ||
return Status::OK(); | ||
} |
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.
Maybe I missed something but I don't see this function is covered in unit test.
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.
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.
@ggaurav28 has updated the pull request. Re-import the pull request |
c6892e9
to
682c8ab
Compare
@ggaurav28 has updated the pull request. Re-import the pull request |
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.
@ggaurav28 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
include/rocksdb/env.h
Outdated
// EnvLogger) for storing informational messages. This method is public for | ||
// testing purposes. | ||
Status NewEnvLogger(const std::string& fname, | ||
std::shared_ptr<Logger>* result); |
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.
Can we move it to a standalone function, rather than a function of Env?
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.
Made this as a static method in EnvLogger class.
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 confused here. It is still Env::NewEnvLogger()
. Did I miss anything?
@ggaurav28 has updated the pull request. Re-import the pull request |
logging/env_logger.h
Outdated
} | ||
|
||
static Status NewEnvLogger(const std::string& fname, Env* env, | ||
std::shared_ptr<Logger>* result) { |
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 hope the function is made public under include/rocksdb/. Now users cannot call this function, and they cannot easily call Env::NewLogger() either.
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.
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.
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.
For now, maybe env.h?
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. Moved it back to env.h. Please review it again.
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.
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.
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 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.
@ggaurav28 has updated the pull request. Re-import the pull request |
f9faf68
to
be43291
Compare
@ggaurav28 has updated the pull request. Re-import the pull request |
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.
@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.
be43291
to
1991af9
Compare
@ggaurav28 has updated the pull request. Re-import the pull request |
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.
@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 |
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 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.
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 i update the comment to say "This is a factory method to create a generic logger that uses env specific methods for logging operations"?
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 will push the code. We can make the changes in the comment later in a separate PR.
@ggaurav28 has updated the pull request. Re-import the pull request |
@ggaurav28 has updated the pull request. Re-import the pull request |
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.
@ggaurav28 is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@ggaurav28 merged this pull request in 60d8b19. |
@ggaurav28 merged this pull request in 60d8b19. |
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
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>
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>
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