Adar Dembo has posted comments on this change. Change subject: consensus: consolidate Raft thread pools ......................................................................
Patch Set 7: (1 comment) http://gerrit.cloudera.org:8080/#/c/6946/7/src/kudu/consensus/consensus_peers.cc File src/kudu/consensus/consensus_peers.cc: PS7, Line 133: shared_ptr<SequenceToken> locked_token = raft_pool_token_.lock(); : if (!locked_token) { : return Status::ServiceUnavailable("raft thread pool has been shutdown"); : } > I have mixed opinions on this. We discussed this further over Slack. I'll try to summarize the main points: 1. It's true that, as far as the Kudu codebase is concerned, shared_ptr connotes shared ownership. Meaning, even if there was only one use of shared_ptr and the rest were weak_ptr, it wouldn't be obvious that this is an attempt at "single ownership + dependent sharing". 2. There is one clear-cut advantage to shared_ptr+weak_ptr: you can have more control if there's a bug in the lifecycle. For example, a dependent can CHECK() that lock() succeeded and reliably crash if not (if the dependent were using a raw pointer, dereferencing it could yield one of several outcomes). Without weak_ptr you have to rely instead on ASAN coverage of the affected code. 3. The use of shared_ptr+weak_ptr can hide real lifecycle issues. For example, suppose there was no synchronization between deleting and accessing the pointee. If using a raw pointer, TSAN will flag the access as a data race. If using a weak_ptr, the access is safe, TSAN doesn't flag anything, and the underlying lifecycle issue is never surfaced. Given all this, I'm going to revert this back to unique_ptr for the owner (RaftConsensus) and raw pointers for dependents (Peers). -- To view, visit http://gerrit.cloudera.org:8080/6946 To unsubscribe, visit http://gerrit.cloudera.org:8080/settings Gerrit-MessageType: comment Gerrit-Change-Id: I8958c607d11ac2e94908670c985059bef0ff5f54 Gerrit-PatchSet: 7 Gerrit-Project: kudu Gerrit-Branch: master Gerrit-Owner: Adar Dembo <[email protected]> Gerrit-Reviewer: Adar Dembo <[email protected]> Gerrit-Reviewer: Dan Burkert <[email protected]> Gerrit-Reviewer: David Ribeiro Alves <[email protected]> Gerrit-Reviewer: Kudu Jenkins Gerrit-Reviewer: Tidy Bot Gerrit-Reviewer: Todd Lipcon <[email protected]> Gerrit-HasComments: Yes
