-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgroup_snapshot.go
More file actions
172 lines (136 loc) · 6.2 KB
/
group_snapshot.go
File metadata and controls
172 lines (136 loc) · 6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
Copyright 2026 The ARCORIS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package bufferpool
// PoolGroupSnapshot is a diagnostic group snapshot.
//
// The snapshot is caller-owned and copy-safe. It is read-only inspection state:
// it does not run coordinator ticks, tick partitions, publish policy or
// budgets, apply pressure, execute Pool trim, or start/stop/retime schedulers.
// Group-level consistency is observational across partition snapshots, not a
// distributed transaction.
type PoolGroupSnapshot struct {
// Name is diagnostic group metadata.
Name string
// Lifecycle is the observed group lifecycle state.
Lifecycle LifecycleState
// Generation is the observed group state/event generation.
Generation Generation
// PolicyGeneration is the observed group runtime-policy generation.
PolicyGeneration Generation
// Config is a defensive copy of normalized construction config.
Config PoolGroupConfig
// Policy is the observed group runtime policy.
Policy PoolGroupPolicy
// PressureSignal is the immutable pressure signal currently published into
// the group runtime snapshot.
PressureSignal PressureSignal
// Pressure is the effective pressure interpretation for aggregate group
// state.
Pressure PoolGroupPressureSnapshot
// Budget is the aggregate group budget projection.
Budget PoolGroupBudgetSnapshot
// CoordinatorStatus is the retained lightweight outcome of the last group
// coordinator cycle.
CoordinatorStatus PoolGroupControllerStatus
// Scheduler describes the group-local coordinator scheduler runtime.
Scheduler ControllerSchedulerSnapshot
// Partitions contains diagnostic snapshots for group-owned partitions.
Partitions []PoolGroupPartitionSnapshot
// Metrics is an aggregate projection derived from one group sample.
Metrics PoolGroupMetrics
}
// PoolGroupPartitionSnapshot is one named partition diagnostic snapshot.
type PoolGroupPartitionSnapshot struct {
// Name is the group-local partition name.
Name string
// Lifecycle is the observed partition lifecycle state.
Lifecycle LifecycleState
// Generation is the observed partition state/event generation.
Generation Generation
// PolicyGeneration is the observed partition runtime-policy generation.
PolicyGeneration Generation
// PressureSignal is the partition runtime pressure signal.
PressureSignal PressureSignal
// Pressure is the partition effective pressure projection.
Pressure PartitionPressureSnapshot
// Budget is the partition budget projection.
Budget PartitionBudgetSnapshot
// ControllerStatus is the partition retained controller status.
ControllerStatus PoolPartitionControllerStatus
// Scheduler describes the partition-local scheduler runtime. Group snapshot
// only observes this child state; it does not manage partition schedulers.
Scheduler ControllerSchedulerSnapshot
// PoolCount is the number of Pools represented by the partition snapshot.
PoolCount int
// ActivePoolCount is the number of active Pool markers in the partition.
ActivePoolCount int
// DirtyPoolCount is the number of dirty Pool markers in the partition.
DirtyPoolCount int
// Partition is the partition diagnostic snapshot.
Partition PoolPartitionSnapshot
}
// Snapshot returns a diagnostic group snapshot.
//
// The snapshot is observational across partitions, not a global transaction.
// Metrics are derived from one group sample, while partition snapshots may
// reflect nearby different instants under concurrent activity. Snapshot is not
// controller input; coordinator code should use Sample or SampleInto. Snapshot
// is diagnostic and remains available after group close.
func (g *PoolGroup) Snapshot() PoolGroupSnapshot {
g.mustBeInitialized()
runtime := g.currentRuntimeSnapshot()
var sample PoolGroupSample
g.sampleWithRuntimeAndGeneration(&sample, runtime, g.generation.Load())
partitions := make([]PoolGroupPartitionSnapshot, 0, g.registry.len())
for _, entry := range g.registry.entries {
partitionSnapshot := entry.partition.Snapshot()
partitions = append(partitions, newPoolGroupPartitionSnapshot(entry.name, partitionSnapshot))
}
pressure := PoolGroupPressureSnapshot(newEffectivePartitionPressureSnapshot(runtime.Policy.Pressure, runtime.Pressure, sample.Aggregate))
return PoolGroupSnapshot{
Name: g.name,
Lifecycle: g.lifecycle.Load(),
Generation: sample.Generation,
PolicyGeneration: runtime.Generation,
Config: g.Config(),
Policy: runtime.Policy,
PressureSignal: runtime.Pressure,
Pressure: pressure,
Budget: newGroupBudgetSnapshot(runtime.Policy.Budget, sample),
CoordinatorStatus: g.ControllerStatus(),
Scheduler: g.coordinatorSchedulerSnapshot(runtime),
Partitions: partitions,
Metrics: newPoolGroupMetrics(g.name, sample),
}
}
func newPoolGroupPartitionSnapshot(name string, snapshot PoolPartitionSnapshot) PoolGroupPartitionSnapshot {
return PoolGroupPartitionSnapshot{
Name: name,
Lifecycle: snapshot.Lifecycle,
Generation: snapshot.Generation,
PolicyGeneration: snapshot.PolicyGeneration,
PressureSignal: snapshot.PressureSignal,
Pressure: snapshot.Pressure,
Budget: snapshot.Budget,
ControllerStatus: snapshot.ControllerStatus,
Scheduler: snapshot.Scheduler,
PoolCount: snapshot.PoolCount(),
ActivePoolCount: snapshot.ActivePoolCount,
DirtyPoolCount: snapshot.DirtyPoolCount,
Partition: snapshot,
}
}
// PartitionCount returns the number of partition snapshots.
func (s PoolGroupSnapshot) PartitionCount() int { return len(s.Partitions) }
// IsEmpty reports whether snapshot contains no owned memory and no observed activity.
func (s PoolGroupSnapshot) IsEmpty() bool { return s.Metrics.IsZero() }