-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
server: always create a liveness record before starting up #53805
Closed
irfansharif
wants to merge
2
commits into
cockroachdb:master
from
irfansharif:200901.heartbeat-early
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1402,11 +1402,9 @@ func (s *Server) Start(ctx context.Context) error { | |
// one, make sure it's the clusterID we already know (and are guaranteed to | ||
// know) at this point. If it's not the same, explode. | ||
// | ||
// TODO(tbg): remove this when we have changed ServeAndWait() to join an | ||
// existing cluster via a one-off RPC, at which point we can create gossip | ||
// (and thus the RPC layer) only after the clusterID is already known. We | ||
// can then rely on the RPC layer's protection against cross-cluster | ||
// communication. | ||
// TODO(irfansharif): The above is no longer applicable; in 21.1 we can | ||
// always assume that the RPC layer will always get set up after having | ||
// found out what the cluster ID is. The checks below can be removed then. | ||
{ | ||
// We populated this above, so it should still be set. This is just to | ||
// demonstrate that we're not doing anything functional here (and to | ||
|
@@ -1538,6 +1536,32 @@ func (s *Server) Start(ctx context.Context) error { | |
} | ||
}) | ||
|
||
// Begin the node liveness heartbeat. Add a callback which records the | ||
// local store "last up" timestamp for every store whenever the liveness | ||
// record is updated. We're sure to do this before we open RPC | ||
// floodgates. | ||
var livenessOnce sync.Once | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: don't leak livenessRecordCreated := make(chan struct{}, 1)
{
// all the other stuff
}
if initialStart { ... } |
||
livenessRecordCreated := make(chan struct{}, 1) | ||
s.nodeLiveness.StartHeartbeat(ctx, s.stopper, s.engines, func(ctx context.Context) { | ||
now := s.clock.Now() | ||
if err := s.node.stores.VisitStores(func(s *kvserver.Store) error { | ||
return s.WriteLastUpTimestamp(ctx, now) | ||
}); err != nil { | ||
log.Warningf(ctx, "writing last up timestamp: %v", err) | ||
} | ||
livenessOnce.Do(func() { | ||
livenessRecordCreated <- struct{}{} | ||
}) | ||
}) | ||
|
||
if initialStart { | ||
// If we're a new node being added, we're going to wait for the | ||
// liveness record to be created before allowing all RPCs below. | ||
<-livenessRecordCreated | ||
} | ||
|
||
// Allow all RPCs, this server can now be considered to be fully | ||
// initialized. | ||
s.grpc.setMode(modeOperational) | ||
|
||
log.Infof(ctx, "starting %s server at %s (use: %s)", | ||
|
@@ -1552,18 +1576,6 @@ func (s *Server) Start(ctx context.Context) error { | |
|
||
log.Event(ctx, "accepting connections") | ||
|
||
// Begin the node liveness heartbeat. Add a callback which records the local | ||
// store "last up" timestamp for every store whenever the liveness record is | ||
// updated. | ||
s.nodeLiveness.StartHeartbeat(ctx, s.stopper, s.engines, func(ctx context.Context) { | ||
now := s.clock.Now() | ||
if err := s.node.stores.VisitStores(func(s *kvserver.Store) error { | ||
return s.WriteLastUpTimestamp(ctx, now) | ||
}); err != nil { | ||
log.Warningf(ctx, "writing last up timestamp: %v", err) | ||
} | ||
}) | ||
|
||
// Begin recording status summaries. | ||
s.node.startWriteNodeStatus(base.DefaultMetricsSampleInterval) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not guaranteed since it's async, so add that it's best effort