Consider available shards

This commit is contained in:
Alan Bernstein 2020-10-14 18:45:53 -05:00
parent ab502a0f8d
commit 94e82aea86
3 changed files with 8 additions and 18 deletions

9
api.go
View file

@ -1599,18 +1599,13 @@ func importExistenceColumns(qcx *Qcx, index *Index, columnIDs []uint64) error {
// ShardDistribution returns an object representing the distribution of shards
// across nodes for each index, distinguishing between primary and replica.
// The structure of this information is [indexName][nodeID][primaryOrReplica]uint64.
// The structure of this information is [indexName][nodeID][primaryOrReplica][]uint64.
// This function supports a view in the UI.
func (api *API) ShardDistribution(ctx context.Context) map[string]interface{} {
distByIndex := make(map[string]interface{})
maxShards := api.MaxShards(ctx)
for idx := range api.holder.indexes {
calculatedMaxShard := uint64(0)
if mx, ok := maxShards[idx]; ok {
calculatedMaxShard = mx
}
dist := api.cluster.shardDistributionByIndex(idx, calculatedMaxShard)
dist := api.cluster.shardDistributionByIndex(idx)
distByIndex[idx] = dist
}

View file

@ -980,7 +980,7 @@ func (c *cluster) translationNodes(to *cluster) (map[string][]*translationResize
// shardDistributionByIndex returns a map of [nodeID][primaryOrReplica][]uint64,
// where the int slices are lists of shards.
func (c *cluster) shardDistributionByIndex(index string, maxShard uint64) map[string]map[string][]uint64 {
func (c *cluster) shardDistributionByIndex(indexName string) map[string]map[string][]uint64 {
dist := make(map[string]map[string][]uint64)
for _, node := range c.nodes {
@ -990,11 +990,14 @@ func (c *cluster) shardDistributionByIndex(index string, maxShard uint64) map[st
dist[node.ID] = nodeDist
}
index := c.holder.Index(indexName)
available := index.AvailableShards(includeRemote).Slice()
c.mu.RLock()
defer c.mu.RUnlock()
for shard := uint64(0); shard <= maxShard; shard++ {
p := c.shardToShardPartition(index, shard)
for _, shard := range available {
p := c.shardToShardPartition(indexName, shard)
nodes := c.partitionNodes(p)
dist[nodes[0].ID]["primary-shards"] = append(dist[nodes[0].ID]["primary-shards"], shard)
for k := 1; k < len(nodes); k++ {

View file

@ -685,14 +685,6 @@ func (h *Handler) handleGetUsage(w http.ResponseWriter, r *http.Request) {
}
}
type getUsageResponse struct {
Disk diskUsage `json:"bytesOnDisk"`
}
type diskUsage struct {
Total int64 `json:"total"`
Indexes map[string]int64 `json:"indexes"`
}
// handleGetUsage handles GET /ui/shard-distribution requests.
func (h *Handler) handleGetShardDistribution(w http.ResponseWriter, r *http.Request) {
dist := h.api.ShardDistribution(r.Context())