11//
22// DISCLAIMER
33//
4- // Copyright 2016-2023 ArangoDB GmbH, Cologne, Germany
4+ // Copyright 2016-2025 ArangoDB GmbH, Cologne, Germany
55//
66// Licensed under the Apache License, Version 2.0 (the "License");
77// you may not use this file except in compliance with the License.
@@ -65,6 +65,24 @@ type Supervision struct {
6565 Maintenance Timestamp `json:"Maintenance,omitempty"`
6666}
6767
68+ type ShardCountDetails struct {
69+ Leader , Follower int
70+ }
71+
72+ func (s ShardCountDetails ) Count () int {
73+ return s .Leader + s .Follower
74+ }
75+
76+ func (s ShardCountDetails ) Add (leader bool ) ShardCountDetails {
77+ if leader {
78+ s .Leader += 1
79+ } else {
80+ s .Follower += 1
81+ }
82+
83+ return s
84+ }
85+
6886func (s State ) CountShards () int {
6987 count := 0
7088
@@ -76,14 +94,14 @@ func (s State) CountShards() int {
7694}
7795
7896// ShardsByDBServers returns a map of DBServers and the amount of shards they have
79- func (s State ) ShardsByDBServers () map [Server ]int {
80- result := make (map [Server ]int )
97+ func (s State ) ShardsByDBServers () map [Server ]ShardCountDetails {
98+ result := make (map [Server ]ShardCountDetails )
8199
82100 for _ , collections := range s .Current .Collections {
83101 for _ , shards := range collections {
84102 for _ , shard := range shards {
85- for _ , server := range shard .Servers {
86- result [server ]++
103+ for id , server := range shard .Servers {
104+ result [server ] = result [ server ]. Add ( id == 0 )
87105 }
88106 }
89107 }
@@ -101,10 +119,10 @@ func (s State) GetDBServerWithLowestShards() Server {
101119 // init first server as result
102120 if resultServer == "" {
103121 resultServer = server
104- resultShards = shards
105- } else if shards < resultShards {
122+ resultShards = shards . Count ()
123+ } else if shards . Count () < resultShards {
106124 resultServer = server
107- resultShards = shards
125+ resultShards = shards . Count ()
108126 }
109127 }
110128 return resultServer
@@ -238,6 +256,24 @@ func (s State) PlanLeaderServers() Servers {
238256 return r
239257}
240258
259+ // PlanServerUsage returns number of the shards and replicas by a server
260+ func (s State ) PlanServerUsage (id Server ) ShardCountDetails {
261+ var z ShardCountDetails
262+ for _ , db := range s .Plan .Collections {
263+ for _ , col := range db {
264+ for _ , shards := range col .Shards {
265+ for i , shard := range shards {
266+ if shard == id {
267+ z = z .Add (i == 0 )
268+ }
269+ }
270+ }
271+ }
272+ }
273+
274+ return z
275+ }
276+
241277// PlanLeaderServersWithFailOver returns all servers which are part of the plan as a leader and can fail over
242278func (s State ) PlanLeaderServersWithFailOver () Servers {
243279 q := map [Server ]bool {}
0 commit comments