telemetry: drop the stats worker re-key path (#4918)
Reverts #4816. Since livekit/cloud#4747 a room re-key closes every participant's stats worker under the old room id and opens a new one under the new id (LeaveSession/JoinSession, #4917), so RoomIDChanged and reKeyRoom have nothing left to move, and with them go the sealed stats batches, SetRoom, ForceClose and the reference hand-over that only the re-key collision case needed. The worker map goes back to a flat (room, participant) key. The guard fixes that landed after #4816 (#4817, #4856, #4860) are kept. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
dc138b2bf0
commit
9a6c187afd
@@ -21,50 +21,6 @@ func TestStatsWorker(t *testing.T) {
|
||||
require.True(t, w.Closed(&g1))
|
||||
})
|
||||
|
||||
// a ReferenceGuard records that it activated some worker, not which one, so a
|
||||
// superseded worker has to hand its references to the one reachable in its place
|
||||
t.Run("force close hands references to the successor", func(t *testing.T) {
|
||||
t.Run("a guard shared by both workers", func(t *testing.T) {
|
||||
// the second worker never got a reference, the guard was already activated
|
||||
var g ReferenceGuard
|
||||
superseded := newStatsWorker(t.Context(), nil, "", "", "", "", &g)
|
||||
survivor := newStatsWorker(t.Context(), nil, "", "", "", "", &g)
|
||||
require.Equal(t, 1, superseded.refCount.count)
|
||||
require.Equal(t, 0, survivor.refCount.count)
|
||||
|
||||
require.True(t, superseded.ForceClose(survivor))
|
||||
require.Equal(t, 0, superseded.refCount.count)
|
||||
require.Equal(t, 1, survivor.refCount.count)
|
||||
|
||||
// without the hand over this would leave the survivor at -1 and never closed
|
||||
require.True(t, survivor.Close(&g))
|
||||
require.True(t, survivor.Closed(&g))
|
||||
})
|
||||
|
||||
t.Run("a guard per worker", func(t *testing.T) {
|
||||
var gSuperseded, gSurvivor ReferenceGuard
|
||||
superseded := newStatsWorker(t.Context(), nil, "", "", "", "", &gSuperseded)
|
||||
survivor := newStatsWorker(t.Context(), nil, "", "", "", "", &gSurvivor)
|
||||
|
||||
require.True(t, superseded.ForceClose(survivor))
|
||||
require.Equal(t, 2, survivor.refCount.count)
|
||||
|
||||
// the superseded worker's owner departs, it must not close the survivor early
|
||||
require.False(t, survivor.Close(&gSuperseded))
|
||||
require.True(t, survivor.Close(&gSurvivor))
|
||||
})
|
||||
|
||||
t.Run("closing an already closed worker holds on to its references", func(t *testing.T) {
|
||||
var g ReferenceGuard
|
||||
superseded := newStatsWorker(t.Context(), nil, "", "", "", "", &g)
|
||||
survivor := newStatsWorker(t.Context(), nil, "", "", "", "", nil)
|
||||
|
||||
require.True(t, superseded.ForceClose(nil))
|
||||
require.False(t, superseded.ForceClose(survivor))
|
||||
require.Equal(t, 0, survivor.refCount.count)
|
||||
})
|
||||
})
|
||||
|
||||
t.Run("logging a nil worker does not panic", func(t *testing.T) {
|
||||
var w *StatsWorker
|
||||
require.NoError(t, w.MarshalLogObject(zapcore.NewMapObjectEncoder()))
|
||||
@@ -75,7 +31,7 @@ func TestGetOrCreateWorkerReleasedGuard(t *testing.T) {
|
||||
// ParticipantActive overtaken by the participant's close arrives with a guard that
|
||||
// ParticipantLeft already released. It must not replace the closed worker with one
|
||||
// nothing can release.
|
||||
ts := &telemetryService{workers: make(map[livekit.RoomID]map[livekit.ParticipantID]*StatsWorker)}
|
||||
ts := &telemetryService{workers: make(map[statsWorkerKey]*StatsWorker)}
|
||||
roomID, pID := livekit.RoomID("room"), livekit.ParticipantID("participant")
|
||||
|
||||
var g ReferenceGuard
|
||||
@@ -87,16 +43,16 @@ func TestGetOrCreateWorkerReleasedGuard(t *testing.T) {
|
||||
late, found := ts.getOrCreateWorker(context.Background(), roomID, "", pID, "", &g)
|
||||
require.True(t, found)
|
||||
require.Same(t, w, late)
|
||||
require.Same(t, w, ts.workers[roomID][pID])
|
||||
require.Same(t, w, ts.workers[statsWorkerKey{roomID, pID}])
|
||||
})
|
||||
|
||||
t.Run("closed worker already reaped", func(t *testing.T) {
|
||||
delete(ts.workers[roomID], pID)
|
||||
delete(ts.workers, statsWorkerKey{roomID, pID})
|
||||
|
||||
late, found := ts.getOrCreateWorker(context.Background(), roomID, "", pID, "", &g)
|
||||
require.True(t, found)
|
||||
require.Nil(t, late)
|
||||
require.Empty(t, ts.workers[roomID])
|
||||
require.Empty(t, ts.workers)
|
||||
late.SetConnected()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user