Skip to content

liveness: lazily calculate the node connectivity inside NodeVitality #144272

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

Merged
merged 1 commit into from
May 2, 2025

Conversation

iskettaneh
Copy link
Contributor

@iskettaneh iskettaneh commented Apr 11, 2025

Before this commit, always calculate if we are connected to the node as part of the NodeVitality creation. However, most uses of node vitality don't need that calculation to be made. This commit addresses this performance issue by lazily calculating the connected field only when requested.

Fixes: #143144

Release note: None

Copy link

blathers-crl bot commented Apr 11, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@iskettaneh iskettaneh force-pushed the gossip3 branch 2 times, most recently from 214d487 to c7b1f4d Compare April 15, 2025 02:16
@iskettaneh iskettaneh changed the title liveness stop calculating connected liveness: lazily calculate the node connectivity inside NodeVitality Apr 22, 2025
@iskettaneh iskettaneh marked this pull request as ready for review April 30, 2025 00:06
@iskettaneh iskettaneh requested a review from a team as a code owner April 30, 2025 00:06
@iskettaneh iskettaneh requested a review from kvoli April 30, 2025 00:06
Copy link
Contributor

@kvoli kvoli left a comment

Choose a reason for hiding this comment

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

Reviewed 6 of 6 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @iskettaneh)


pkg/kv/kvserver/liveness/livenesspb/liveness.go line 16 at r1 (raw file):

	"github.com/cockroachdb/cockroach/pkg/roachpb"
	"github.com/cockroachdb/cockroach/pkg/rpc"
	"github.com/cockroachdb/cockroach/pkg/rpc/nodedialer"

Would it be possible to stub out the interfaces required here to avoid the dependence on the rpc and nodedialer pkgs? Usually in pb files, we avoid larger deps.


pkg/kv/kvserver/liveness/livenesspb/liveness.go line 200 at r1 (raw file):

func (ncs *NodeConnectionStatus) IsConnected() bool {
	if !ncs.calculatedConnected.Load() {
		// If we need to calculate the connection status, we need to take upgrade

nit: upgrade our read lock.

@iskettaneh iskettaneh force-pushed the gossip3 branch 2 times, most recently from 7cd91ca to 2da4a60 Compare May 1, 2025 18:36
Copy link
Contributor Author

@iskettaneh iskettaneh left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @kvoli)


pkg/kv/kvserver/liveness/livenesspb/liveness.go line 16 at r1 (raw file):

Previously, kvoli (Austen) wrote…

Would it be possible to stub out the interfaces required here to avoid the dependence on the rpc and nodedialer pkgs? Usually in pb files, we avoid larger deps.

I added a thin interface to remove the dependency on the rpc/nodedialer. Also, while I am at it, I added a test that asserts the caching behaviour (introduced a light mock to do that).


pkg/kv/kvserver/liveness/livenesspb/liveness.go line 200 at r1 (raw file):

Previously, kvoli (Austen) wrote…

nit: upgrade our read lock.

I changed the whole paragraph. I realized that the comment is stale (came in my first iteration of doing this work, where I was using read/write locks).

@iskettaneh iskettaneh requested a review from kvoli May 1, 2025 18:38
Before this commit, always calculate if we are connected to the node as
part of the NodeVitality creation. However, most uses of node vitality
don't need that calculation to be made. This commit addresses this
performance issue by lazily calculating the connected field only when
requested.

Fixes: cockroachdb#143144

Release note: None
Copy link
Contributor

@kvoli kvoli left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @iskettaneh)

@iskettaneh
Copy link
Contributor Author

TFTR!

bors r+

@craig
Copy link
Contributor

craig bot commented May 2, 2025

@craig craig bot merged commit d9b15fd into cockroachdb:master May 2, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

liveness: don't compute connection health when unnecessary
3 participants