ellutionist commented on PR #1418:
URL:
https://github.com/apache/incubator-kvrocks/pull/1418#issuecomment-1536378582
> @ellutionist Thanks for your explanation.
>
> I have not dived into these changes deeply, but if you just want to make
lifetime of SyncMigrateContext as long as the command object, you can store an
instance of SyncMigrateContext in CommandClusterX directly (`class
CommandClusterX { SyncMigrateContext ctx_; ... }`), and pass some non-owning
pointer (like raw pointer, no ownership) to the migrator.
@PragmaTwice @xiaobiaozhao Thank you for the advice. This is another
reasonable solution. However, there are two things to note here:
1. The `CommandClusterX` does not always have a `SyncMigrateContext` (only
when migrating with a "sync" flag). Making the context a non-pointer member of
the `CommandClusterX` object may not make good sense here. If we decide to do
this, I suggest to adopt `std::optional<SyncMigrateContext>`.
2. Due to the concern of memory safety, I am not a fan of raw pointers. Of
course, in this PR we could use it, but we may set up some potential risk for
the future. Because not every maintainer could get to know that
"the`CommandClusterX` object must live long enough to complete the migration".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]