-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[core] [6/N] Fix shared pointer usage for gcs server #48990
[core] [6/N] Fix shared pointer usage for gcs server #48990
Conversation
Signed-off-by: hjiang <[email protected]>
80ca126
to
ec79f58
Compare
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.
LGTM. though I think if we move forward this way we need to do proper lifetime annotations, e.g.
- GcsServer outlives everyone.
- GcsTableStorage, all GcsManagers share a lifetime, that starts from a GcsServer
DoStart
toStop
and so on.
Could you please tell me what should I add? C++ attributes? Or documentations? |
/// Grpc based pubsub's periodical runner. | ||
PeriodicalRunner pubsub_periodical_runner_; | ||
/// The runner to run function periodically. | ||
PeriodicalRunner periodical_runner_; | ||
/// The gcs table storage. | ||
std::shared_ptr<gcs::GcsTableStorage> gcs_table_storage_; | ||
std::unique_ptr<gcs::GcsTableStorage> gcs_table_storage_; |
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 should the decision process be behind keeping things as unique ptr vs. just the obj and deleted copy constructors for the 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 prefer to use unique pointer for all dependent class, which potentially involves IO operations.
I think the best strategy is to have
- a base class, which defines the interface
- an implementation class, which is the real production code
- and a mock class/fake class for unit test purpose
In GCS, most of the data members have their own logic, should be wrapped in unique pointer.
Signed-off-by: hjiang <[email protected]>
Signed-off-by: hjiang <[email protected]>
Signed-off-by: hjiang <[email protected]>
Signed-off-by: hjiang <[email protected]>
Signed-off-by: hjiang <[email protected]>
Discussed offline, comments added, PTAL. |
Merge confclit. |
Signed-off-by: hjiang <[email protected]>
@jjyao Yeah this PR has been on hold for a while... conflict should be resolved now. |
@@ -89,7 +89,7 @@ class GcsInitData { | |||
|
|||
protected: | |||
/// The gcs table storage. | |||
std::shared_ptr<gcs::GcsTableStorage> gcs_table_storage_; | |||
gcs::GcsTableStorage &gcs_table_storage_; |
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 see reference and pointer are both used. What's the rule you are following?
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.
- Prefer to use reference as data member, since it guarantee non-null;
- Have to use pointer in some places due to our testing implementation.
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 our test case, quite a few places are implemented as
Class(/*member1=*/nullptr, /*member2=*/nullptr)
meanwhile mem1 and mem2 have their own dependency which I don't want to touch, so using nullptr in some places, but the ownership should be clear.
Signed-off-by: hjiang <[email protected]> Signed-off-by: ujjawal-khare <[email protected]>
Cleanup shared pointer and use unique pointer for clear memory ownership and less error prune.
Previous PRs: