-
Notifications
You must be signed in to change notification settings - Fork 14
fix: associate each Session
with a Channel
#1346
Conversation
Factor the `SessionPool::ChannelInfo` struct out to a stand-alone object, so we can store a `shared_ptr` to it in each `Session`. This allows us to properly account for `Sessions` that are marked bad or disassociated from the pool. Previously, the per-Channel session count was not being decremented in those cases. Since the `Channel` also holds a `shared_ptr<Stub>`, we can eliminate the `Session::stub_` member. Fixes #1344
google/cloud/spanner/internal/channel.h, line 34 at r1 (raw file):
FWIW, I was debating disabling copy/move here because it's easy to make an inadvertent copy, and that causes some subtle bugs. Internally we tend to make things no copy/no move by default but don't really seem to do it in this project. |
Codecov Report
@@ Coverage Diff @@
## master #1346 +/- ##
==========================================
- Coverage 94.65% 94.65% -0.01%
==========================================
Files 171 173 +2
Lines 13637 13628 -9
==========================================
- Hits 12908 12899 -9
Misses 729 729
Continue to review full report at Codecov.
|
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.
Reviewable status: 0 of 7 files reviewed, 4 unresolved discussions (waiting on @coryan and @mr-salty)
google/cloud/spanner/internal/channel.h, line 34 at r1 (raw file):
Previously, mr-salty (Todd Derr) wrote…
FWIW, I was debating disabling copy/move here because it's easy to make an inadvertent copy, and that causes some subtle bugs. Internally we tend to make things no copy/no move by default but don't really seem to do it in this project.
FWIW, having stub
be const
already does:
Channel& Channel::operator=(Channel const&) = delete;
Channel& Channel::operator=(Channel&&) = delete;
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.
Reviewable status: 0 of 7 files reviewed, 4 unresolved discussions (waiting on @coryan and @devbww)
google/cloud/spanner/internal/channel.h, line 24 at r1 (raw file):
Previously, devbww (Bradley White) wrote…
#include "google/cloud/spanner/version.h"
Done.
google/cloud/spanner/internal/channel.h, line 31 at r1 (raw file):
Previously, devbww (Bradley White) wrote…
s/stub/stub_param/
Done.
google/cloud/spanner/internal/channel.h, line 34 at r1 (raw file):
Previously, devbww (Bradley White) wrote…
FWIW, having
stub
beconst
already does:Channel& Channel::operator=(Channel const&) = delete; Channel& Channel::operator=(Channel&&) = delete;
for assignment, but not construction... I definitely messed up trying to use it in one place.. so maybe I should just explicitly make it non-copy/move.
google/cloud/spanner/internal/session.h, line 19 at r1 (raw file):
Previously, devbww (Bradley White) wrote…
No longer needed?
Done.
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.
The copyright notice needs to be fixed, the other thing is up to you.
Reviewed 7 of 7 files at r1, 2 of 2 files at r2.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @devbww and @mr-salty)
google/cloud/spanner/internal/channel.h, line 1 at r1 (raw file):
// Copyright 2019 Google LLC
s/2019/2020/
google/cloud/spanner/internal/channel.h, line 34 at r1 (raw file):
Previously, mr-salty (Todd Derr) wrote…
for assignment, but not construction... I definitely messed up trying to use it in one place.. so maybe I should just explicitly make it non-copy/move.
If disabling copy/move is better: go for it, this is in internal
anyways. AFAIK we do not have a rule about making every type copyable. I have opinions about making user-facing code unnecessarily hard to use, but that is neither here nor there in this case.
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.
Reviewable status: 6 of 7 files reviewed, 4 unresolved discussions (waiting on @coryan and @devbww)
google/cloud/spanner/internal/channel.h, line 1 at r1 (raw file):
Previously, coryan (Carlos O'Ryan) wrote…
s/2019/2020/
Done.
google/cloud/spanner/internal/channel.h, line 34 at r1 (raw file):
Previously, coryan (Carlos O'Ryan) wrote…
If disabling copy/move is better: go for it, this is in
internal
anyways. AFAIK we do not have a rule about making every type copyable. I have opinions about making user-facing code unnecessarily hard to use, but that is neither here nor there in this case.
ok, I made it non-copyable (and non-moveable)
Channel(const Channel&) = delete; | ||
Channel& operator=(const Channel&) = delete; |
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.
East const.
explicit Channel(std::shared_ptr<SpannerStub> stub_param) | ||
: stub(std::move(stub_param)) {} | ||
|
||
// This class is not copyable or movable. |
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.
Channel(Channel&&) = delete;
Channel& operator=(Channel&&) = delete;
as well?
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.
once you address the questions from @devbww
Reviewed 1 of 1 files at r3.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @devbww and @mr-salty)
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.
Reviewable status: 6 of 7 files reviewed, 5 unresolved discussions (waiting on @coryan and @devbww)
google/cloud/spanner/internal/channel.h, line 36 at r3 (raw file):
Previously, devbww (Bradley White) wrote…
Channel(Channel&&) = delete; Channel& operator=(Channel&&) = delete;
as well?
not necessary: https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types
google/cloud/spanner/internal/channel.h, line 38 at r3 (raw file):
Previously, devbww (Bradley White) wrote…
East const.
%&&
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.
Reviewable status: 6 of 7 files reviewed, 5 unresolved discussions (waiting on @coryan, @devbww, and @mr-salty)
google/cloud/spanner/internal/channel.h, line 36 at r3 (raw file):
Previously, mr-salty (Todd Derr) wrote…
not necessary: https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types
Not necessary, but I believe we still choose to do it.
google/cloud/spanner/internal/channel.h, line 36 at r3 (raw file): Previously, devbww (Bradley White) wrote…
I see no documentation to support your assertion. https://github.com/googleapis/google-cloud-cpp-common/blob/master/doc/cpp-style-guide.md |
…ud-cpp-spanner#1346) * fix: associate each `Session` with a `Channel` Factor the `SessionPool::ChannelInfo` struct out to a stand-alone object, so we can store a `shared_ptr` to it in each `Session`. This allows us to properly account for `Sessions` that are marked bad or disassociated from the pool. Previously, the per-Channel session count was not being decremented in those cases. Since the `Channel` also holds a `shared_ptr<Stub>`, we can eliminate the `Session::stub_` member. Fixes googleapis/google-cloud-cpp-spanner#1344 * address review comments * address review comments * review comments
Factor the
SessionPool::ChannelInfo
struct out to a stand-aloneobject, so we can store a
shared_ptr
to it in eachSession
.This allows us to properly account for
Sessions
that are marked bad ordisassociated from the pool. Previously, the per-Channel session count
was not being decremented in those cases.
Since the
Channel
also holds ashared_ptr<Stub>
, we can eliminatethe
Session::stub_
member.Fixes #1344
This change is![Reviewable](https://camo.githubusercontent.com/1541c4039185914e83657d3683ec25920c672c6c5c7ab4240ee7bff601adec0b/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)