fix: read committed holder identity without waiting for authority writes

This commit is contained in:
pingqiu committed 2026-11-22 00:58:47 -08:00
1 parent d2525156cc
commit 58839e5c2d
3 files changed
+23 -2

No files matched your search

@@ -157,6 +157,18 @@ type PublishedLine struct {
IssuedHost string
}
// PublishedAuthorityLine reads one committed line under leaf leaseMu. Identity
// checks on renewal must not wait for p.mu, which spans authority store I/O.
func (p *Publisher) PublishedAuthorityLine(volume string) (PublishedLine, bool) {
p.leaseMu.Lock()
defer p.leaseMu.Unlock()
lv := p.leaseViews[volume]
if lv == nil || !lv.d.bound {
return PublishedLine{}, false
}
return PublishedLine{ReplicaID: lv.d.replica, Epoch: lv.d.epoch, IssuedHost: lv.d.issuedHost}, true
}
// PublishedAuthorityLines returns the committed authority line of every
// volume that has one. It reads the lease views under the leaf leaseMu only:
// it never waits on p.mu, which writers hold across store writes, and it
@@ -76,6 +76,11 @@ func (h *Host) workspaceSourceHost(volume, replica string, epoch uint64) string
}
}
}
return h.placementSourceHost(volume, replica)
}
// placementSourceHost uses explicit membership, never endpoint inference.
func (h *Host) placementSourceHost(volume, replica string) string {
if h.lifecycle != nil {
if p, ok := h.lifecycle.Placements.GetPlacement(volume); ok {
for _, slot := range p.Slots {
@@ -91,8 +91,12 @@ func (s *services) RenewWorkspaceLease(ctx context.Context, q *control.Workspace
return nil, err
}
// r2.34 AUTHORITY: a replica id can move between servers.
line, ok := s.host.Publisher().VolumeAuthorityLine(q.GetVolumeId())
if !ok || line.ReplicaID != q.GetReplicaId() || line.Epoch != q.GetEpoch() || q.GetServerId() == "" || q.GetServerId() != s.host.workspaceSourceHost(q.GetVolumeId(), line.ReplicaID, line.Epoch) {
line, ok := s.host.Publisher().PublishedAuthorityLine(q.GetVolumeId())
server := line.IssuedHost
if server == "" {
server = s.host.placementSourceHost(q.GetVolumeId(), line.ReplicaID)
}
if !ok || line.ReplicaID != q.GetReplicaId() || line.Epoch != q.GetEpoch() || q.GetServerId() == "" || q.GetServerId() != server {
return nil, status.Error(codes.FailedPrecondition, "workspace lease: server identity does not match the current holder")
}
l, err := s.host.Publisher().RenewWorkspaceLease(ctx, q.GetVolumeId(), q.GetReplicaId(), q.GetEpoch())