Skip to content

Conversation

@SpecterCipher
Copy link

Description

Before modification, when the mooncake master started, it would issue a warning: "Logging before InitGoogleLogging() is written to STDERR". After modification, logs are printed in the glog format, defaulting to the /tmp directory with filenames starting with mooncake_master. Custom log configuration can be achieved by setting the corresponding glog flags during startup.

Type of Change

  • Types
    • [√ ] Bug fix
    • New feature
      • Transfer Engine
      • Mooncake Store
      • Mooncake EP
      • Integration
      • P2P Store
      • Python Wheel
    • Breaking change
    • CI/CD
    • Documentation update
    • Other

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @SpecterCipher, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a bug in the mooncake master process where logging occurred before the proper initialization of Google Logging (glog). The changes ensure that glog is correctly set up and shut down, eliminating a startup warning and enabling all logs to be written in the intended glog format, with options for custom configuration via glog flags.

Highlights

  • Glog Initialization: The mooncake master process now correctly initializes Google Logging (glog) at startup, resolving the "Logging before InitGoogleLogging() is written to STDERR" warning.
  • Logging Format: Logs are now output in the glog format, defaulting to files in /tmp with names starting mooncake_master.
  • Custom Configuration: Users can now configure glog behavior by setting appropriate glog flags during the master's startup.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to integrate glog for logging in the master service. The changes correctly include the necessary headers and add initialization and shutdown calls for glog. However, there are two issues with the implementation. First, glog::InitGoogleLogging() is called after gflags::ParseCommandLineFlags(), which does not fix the original issue of logging before initialization, as gflags validators may use glog. Second, the google::ShutdownGoogleLogging() call is unreachable, meaning glog resources won't be cleaned up properly on exit. My review includes comments with high and critical severity to address these points and suggests corrections.

mooncake::RegisterRpcService(server, wrapped_master_service);
return server.start();
}
google::ShutdownGoogleLogging();
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

This call to google::ShutdownGoogleLogging() is unreachable. The if-else block starting at line 461 has return statements in both branches (return supervisor.Start(); at line 464 and return server.start(); at line 481), so the program will exit before this line is ever reached. This means glog resources will not be properly shut down, which can lead to logs not being flushed correctly.

To fix this, you should ensure google::ShutdownGoogleLogging() is called before all normal exit points of the main function. A common and robust pattern for this is to use an RAII object for initialization and cleanup at the top of main.

Comment on lines 363 to 366
gflags::ParseCommandLineFlags(&argc, &argv, true);

glog::InitGoogleLogging(argv[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

To fix the warning "Logging before InitGoogleLogging() is written to STDERR", glog::InitGoogleLogging should be called before gflags::ParseCommandLineFlags. Gflags validators, like the one defined on line 56 which uses LOG(FATAL), are executed during parsing. If a validator uses LOG(), glog must be initialized to avoid the warning and ensure logs are written to the configured files instead of STDERR. While glog uses gflags for its own configuration, InitGoogleLogging can be called before parsing, and glog will pick up the flag values after they are parsed.

Suggested change
gflags::ParseCommandLineFlags(&argc, &argv, true);
glog::InitGoogleLogging(argv[0]);
glog::InitGoogleLogging(argv[0]);
// Initialize gflags
gflags::ParseCommandLineFlags(&argc, &argv, true);

// Initialize gflags
gflags::ParseCommandLineFlags(&argc, &argv, true);

GlogRAII glogRAII(argv[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using a simple if...else statement to enable glog.

@stmatengss
Copy link
Collaborator

Use clang-format -i FILENAME before submiting PR.

@stmatengss
Copy link
Collaborator

Why use RAII for glog? @SpecterCipher

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.

2 participants