Skip to content

Commit 69caea2

Browse files
authored
Add last replica ID to GetRangeDebugInfo (#11168)
1 parent d6f2830 commit 69caea2

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

enterprise/server/raft/store/store.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,13 @@ func (s *Store) queryForMetarange(ctx context.Context) {
582582
}
583583
func (s *Store) GetRangeDebugInfo(ctx context.Context, req *rfpb.GetRangeDebugInfoRequest) (*rfpb.GetRangeDebugInfoResponse, error) {
584584
leaderID, term, valid, _ := s.nodeHost.GetLeaderID(req.GetRangeId())
585+
lastReplicaIDKey := keys.MakeKey(constants.LastReplicaIDKeyPrefix, []byte(fmt.Sprintf("%d", req.GetRangeId())))
586+
lastReplicaIDBytes, err := s.sender.DirectRead(ctx, lastReplicaIDKey)
587+
if err != nil {
588+
return nil, status.WrapErrorf(err, "failed to read last replica ID for range %d with key %q", req.GetRangeId(), lastReplicaIDKey)
589+
} else if len(lastReplicaIDBytes) != 8 {
590+
return nil, status.InternalErrorf("failed to read last replica ID for range %d with key %q: expected 8 bytes, got %d", req.GetRangeId(), lastReplicaIDKey, len(lastReplicaIDBytes))
591+
}
585592
rsp := &rfpb.GetRangeDebugInfoResponse{
586593
Nhid: s.NHID(),
587594
RangeDescriptor: s.lookupRange(req.GetRangeId()),
@@ -591,6 +598,7 @@ func (s *Store) GetRangeDebugInfo(ctx context.Context, req *rfpb.GetRangeDebugIn
591598
Term: term,
592599
Valid: valid,
593600
},
601+
LastReplicaId: bytesToUint64(lastReplicaIDBytes),
594602
}
595603
// Fetch the range descriptor from meta range to make sure it's the most-up-to-date.
596604
ranges, err := s.sender.LookupRangeDescriptorsByIDs(ctx, []uint64{req.GetRangeId()})

proto/raft.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ message GetRangeDebugInfoResponse {
712712
RaftLeaderInfo leader = 3;
713713
bool has_lease = 4;
714714
RaftMembership membership = 5;
715+
uint64 last_replica_id = 7;
715716
}
716717

717718
message RangeDescriptorChange {

0 commit comments

Comments
 (0)