Skip to content

Commit 98b475f

Browse files
committed
asim: print store info to * _setup.txt
This commit outputs store capacity and store attributes t.o the setup file.
1 parent 5abaa70 commit 98b475f

File tree

5 files changed

+49
-30
lines changed

5 files changed

+49
-30
lines changed

pkg/kv/kvserver/asim/event/mutation_event.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func (sce SetCapacityOverrideEvent) Func() EventFunc {
169169
}
170170

171171
func (sce SetCapacityOverrideEvent) String() string {
172-
return fmt.Sprintf("set capacity override event with storeID=%d, capacity_override=%v", sce.StoreID, sce.CapacityOverride)
172+
return fmt.Sprintf("override s%d capacity to %v", sce.StoreID, sce.CapacityOverride)
173173
}
174174

175175
func (sne SetNodeLocalityEvent) Func() EventFunc {

pkg/kv/kvserver/asim/gen/printer.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ func generateClusterVisualization(
8383
return
8484
}
8585
_, _ = fmt.Fprintf(buf, "Cluster Set Up\n")
86-
for _, n := range s.Nodes() {
87-
_, _ = fmt.Fprintf(buf, "%v", n)
88-
_, _ = fmt.Fprintf(buf, "\n")
89-
}
86+
_, _ = fmt.Fprintf(buf, "%v", s.NodesString())
9087
_, _ = fmt.Fprintf(buf, "Key Space\n%s", rangeStateStr)
9188
_, _ = fmt.Fprintf(buf, "Event\n%s", eventGen.String())
9289
_, _ = fmt.Fprintf(buf, "Workload Set Up\n%s", loadGen.String())

pkg/kv/kvserver/asim/state/impl.go

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,44 @@ func (s *state) SetSimulationSettings(Key string, Value interface{}) {
14251425
}
14261426
}
14271427

1428+
func (s *state) NodesString() string {
1429+
var buf strings.Builder
1430+
1431+
nodes := make([]*node, 0, len(s.nodes))
1432+
for _, node := range s.nodes {
1433+
nodes = append(nodes, node)
1434+
}
1435+
slices.SortFunc(nodes, func(a, b *node) int {
1436+
return cmp.Compare(a.nodeID, b.nodeID)
1437+
})
1438+
1439+
for _, n := range nodes {
1440+
_, _ = fmt.Fprintf(&buf, "\tn%d(", n.nodeID)
1441+
for _, locality := range n.desc.Locality.Tiers {
1442+
_, _ = fmt.Fprintf(&buf, "%s,", locality.Value)
1443+
}
1444+
_, _ = fmt.Fprintf(&buf, "%dvcpu): {",
1445+
n.cpuRateCapacity/time.Second.Nanoseconds())
1446+
for i, store := range n.Stores() {
1447+
s, ok := s.Store(store)
1448+
if ok {
1449+
attrStr := ""
1450+
if attrs := s.Descriptor().Attrs; attrs.Size() != 0 {
1451+
attrStr = fmt.Sprintf("%v,", attrs)
1452+
}
1453+
_, _ = fmt.Fprintf(&buf, "s%d:(%s%vGiB)", store, attrStr, s.Descriptor().Capacity.Capacity>>30)
1454+
} else {
1455+
_, _ = fmt.Fprintf(&buf, "s%d:notfound", store)
1456+
}
1457+
if i < len(n.Stores())-1 {
1458+
_, _ = fmt.Fprintf(&buf, ",")
1459+
}
1460+
}
1461+
_, _ = fmt.Fprintf(&buf, "}\n")
1462+
}
1463+
return buf.String()
1464+
}
1465+
14281466
// node is an implementation of the Node interface.
14291467
type node struct {
14301468
nodeID NodeID
@@ -1437,24 +1475,6 @@ type node struct {
14371475
as *mmaintegration.AllocatorSync
14381476
}
14391477

1440-
func (n *node) String() string {
1441-
var buf strings.Builder
1442-
_, _ = fmt.Fprintf(&buf, "\tn%d(", n.nodeID)
1443-
for _, locality := range n.desc.Locality.Tiers {
1444-
_, _ = fmt.Fprintf(&buf, "%s,", locality.Value)
1445-
}
1446-
_, _ = fmt.Fprintf(&buf, "%dvcpu): {",
1447-
n.cpuRateCapacity/time.Second.Nanoseconds())
1448-
for i, s := range n.Stores() {
1449-
_, _ = fmt.Fprintf(&buf, "s%d", s)
1450-
if i < len(n.Stores())-1 {
1451-
_, _ = fmt.Fprintf(&buf, ",")
1452-
}
1453-
}
1454-
_, _ = fmt.Fprintf(&buf, "}")
1455-
return buf.String()
1456-
}
1457-
14581478
// NodeID returns the ID of this node.
14591479
func (n *node) NodeID() NodeID {
14601480
return n.nodeID

pkg/kv/kvserver/asim/state/state.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ type State interface {
6363
Node(NodeID) Node
6464
// Nodes returns all nodes that exist in this state.
6565
Nodes() []Node
66+
// NodesString returns a string representation of all nodes.
67+
NodesString() string
6668
// RangeFor returns the range containing Key in [StartKey, EndKey). This
6769
// cannot fail.
6870
RangeFor(Key) Range

pkg/kv/kvserver/asim/tests/testdata/generated/example_rebalancing/example_rebalancing_setup.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Cluster Set Up
2-
n1(AU_EAST,AU_EAST_1,8vcpu): {s1}
3-
n2(AU_EAST,AU_EAST_1,8vcpu): {s2}
4-
n3(AU_EAST,AU_EAST_1,8vcpu): {s3}
5-
n4(AU_EAST,AU_EAST_1,8vcpu): {s4}
6-
n5(AU_EAST,AU_EAST_1,8vcpu): {s5}
7-
n6(AU_EAST,AU_EAST_1,8vcpu): {s6}
8-
n7(AU_EAST,AU_EAST_1,8vcpu): {s7}
2+
n1(AU_EAST,AU_EAST_1,8vcpu): {s1:(256GiB)}
3+
n2(AU_EAST,AU_EAST_1,8vcpu): {s2:(256GiB)}
4+
n3(AU_EAST,AU_EAST_1,8vcpu): {s3:(256GiB)}
5+
n4(AU_EAST,AU_EAST_1,8vcpu): {s4:(256GiB)}
6+
n5(AU_EAST,AU_EAST_1,8vcpu): {s5:(256GiB)}
7+
n6(AU_EAST,AU_EAST_1,8vcpu): {s6:(256GiB)}
8+
n7(AU_EAST,AU_EAST_1,8vcpu): {s7:(256GiB)}
99
Key Space
1010
[0,10000): 7(rf=3), 0MiB, [s1:(10,3*),s2:(5,1*),s3:(2,0*),s4:(1,0*),s5:(0,0*),s6:(0,0*),s7:(0,0*)]
1111
Event

0 commit comments

Comments
 (0)