mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-26 01:23:13 +01:00
refactor(channelserver): replace global stagesLock with sync.Map-backed StageMap
The global stagesLock sync.RWMutex protected map[string]*Stage, causing all stage operations to contend on a single lock even for unrelated stages. Any stage creation or deletion blocked all reads server-wide. Replace with a typed StageMap wrapper around sync.Map which provides lock-free reads and allows concurrent writes to disjoint keys. Per-stage sync.RWMutex remains unchanged for protecting individual stage state. StageMap exposes Get, GetOrCreate, StoreIfAbsent, Store, Delete, and Range methods. Updated ~50 call sites across 6 production files and 9 test files.
This commit is contained in:
@@ -192,22 +192,16 @@ func TestChannelIsolation_IndependentStages(t *testing.T) {
|
||||
stageName := "sl1Qs999p0a0u42"
|
||||
|
||||
// Add stage only to channel 1.
|
||||
channels[0].stagesLock.Lock()
|
||||
channels[0].stages[stageName] = NewStage(stageName)
|
||||
channels[0].stagesLock.Unlock()
|
||||
channels[0].stages.Store(stageName, NewStage(stageName))
|
||||
|
||||
// Channel 1 should have the stage.
|
||||
channels[0].stagesLock.RLock()
|
||||
_, ok1 := channels[0].stages[stageName]
|
||||
channels[0].stagesLock.RUnlock()
|
||||
_, ok1 := channels[0].stages.Get(stageName)
|
||||
if !ok1 {
|
||||
t.Error("channel 1 should have the stage")
|
||||
}
|
||||
|
||||
// Channel 2 should NOT have the stage.
|
||||
channels[1].stagesLock.RLock()
|
||||
_, ok2 := channels[1].stages[stageName]
|
||||
channels[1].stagesLock.RUnlock()
|
||||
_, ok2 := channels[1].stages.Get(stageName)
|
||||
if ok2 {
|
||||
t.Error("channel 2 should not have channel 1's stage")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user