// availableShardsByIndex returns a bitmap of all shards by indexes.
514279
func (h *Holder) availableShardsByIndex() map[string]*roaring.Bitmap {
	m := make(map[string]*roaring.Bitmap)
	for _, index := range h.Indexes() {
		m[index.Name()] = index.AvailableShards()
	}
	return m
}
294716
func (c *threadSafeMap) ByIndex(indexName, indexKey string) ([]interface{}, error) {
	c.lock.RLock()
	defer c.lock.RUnlock()

	indexFunc := c.indexers[indexName]
	if indexFunc == nil {
		return nil, fmt.Errorf("Index with name %s does not exist", indexName)
	}

	index := c.indices[indexName]

	set := index[indexKey]
	list := make([]interface{}, 0, set.Len())
	for _, key := range set.List() {
		list = append(list, c.items[key])
	}

	return list, nil
}
1064009
func (i *InverseBloomFilter) index(data []byte) uint32 {
	hash := i.hashPool.Get().(hash.Hash32)
	hash.Write(data)
	index := hash.Sum32() % uint32(i.capacity)
	hash.Reset()
	i.hashPool.Put(hash)
	return index
}
872008
func (h *Handler) handleDeleteRemoteAvailableShard(w http.ResponseWriter, r *http.Request) {
	if !validHeaderAcceptJSON(r.Header) {
		http.Error(w, "JSON only acceptable response", http.StatusNotAcceptable)
		return
	}

	indexName := mux.Vars(r)["index"]
	fieldName := mux.Vars(r)["field"]
	shardID, _ := strconv.ParseUint(mux.Vars(r)["shardID"], 10, 64)

	resp := successResponse{h: h}
	err := h.api.DeleteAvailableShard(r.Context(), indexName, fieldName, shardID)
	resp.write(w, err)
}
1316532
func availableAddresses(allAddrs []net.IP) (v4 []net.IP, v6 []net.IP) {
	for _, addr := range allAddrs {
		if addr.To4() != nil {
			v4 = append(v4, addr)
		} else {
			v6 = append(v6, addr)
		}
	}
	return
}
328339
func (c Config) maximumShardSize() int {
	maxShardSize := 0

	if c.HardMaxCacheSize > 0 {
		maxShardSize = convertMBToBytes(c.HardMaxCacheSize) / c.Shards
	}

	return maxShardSize
}
930518
func fetchShardSizes(c context.Context, baseQ *datastore.Query, shards []*shard) error {
	c, cancel := clock.WithTimeout(c, 10*time.Minute)
	defer cancel()

	err := parallel.WorkPool(32, func(tasks chan<- func() error) {
		for _, sh := range shards {
			sh := sh
			tasks <- func() error {
				n, err := datastore.CountBatch(c, 1024, sh.Range.Apply(baseQ))
				if err == nil {
					sh.ExpectedCount = n
				}
				return errors.Annotate(err, "for shard #%d", sh.Index).Err()
			}
		}
	})

	return transient.Tag.Apply(err)
}
592562
func (conn *VTGateConn) ExecuteShards(ctx context.Context, query string, keyspace string, shards []string, bindVars map[string]*querypb.BindVariable, tabletType topodatapb.TabletType, options *querypb.ExecuteOptions) (*sqltypes.Result, error) {
	_, res, err := conn.impl.ExecuteShards(ctx, query, keyspace, shards, bindVars, tabletType, nil, options)
	return res, err
}
1021985
func (s *ClusterHealthService) WaitForActiveShards(waitForActiveShards int) *ClusterHealthService {
	s.waitForActiveShards = &waitForActiveShards
	return s
}
1022105
func (tc *TabletStatsCache) GetHealthyTabletStats(keyspace, shard string, tabletType topodatapb.TabletType) []TabletStats {
	e := tc.getEntry(keyspace, shard, tabletType)
	if e == nil {
		return nil
	}

	e.mu.RLock()
	defer e.mu.RUnlock()
	result := make([]TabletStats, len(e.healthy))
	for i, ts := range e.healthy {
		result[i] = *ts
	}
	return result
}
10072
func (c *cluster) fragCombos(idx string, availableShards *roaring.Bitmap, fieldViews viewsByField) fragsByHost {
	t := make(fragsByHost)
	availableShards.ForEach(func(i uint64) {
		nodes := c.shardNodes(idx, i)
		for _, n := range nodes {
			// for each field/view combination:
			for field, views := range fieldViews {
				for _, view := range views {
					t[n.ID] = append(t[n.ID], frag{field, view, i})
				}
			}
		}
	})
	return t
}
825426
func (e *executor) shardsByNode(nodes []*Node, index string, shards []uint64) (map[*Node][]uint64, error) {
	m := make(map[*Node][]uint64)

loop:
	for _, shard := range shards {
		for _, node := range e.Cluster.ShardNodes(index, shard) {
			if Nodes(nodes).Contains(node) {
				m[node] = append(m[node], shard)
				continue loop
			}
		}
		return nil, errShardUnavailable
	}
	return m, nil
}
1333846
func QbsWrapIndex(indexer QbsRestIndex, s *QbsStore) RestIndex {
	return &qbsWrapped{index: indexer, store: s}
}
1068037
func (ix *Index) indexReadyBlobs(ctx context.Context) {
	defer ix.reindexWg.Done()
	ix.RLock()
	// For tests
	if ix.oooDisabled {
		ix.RUnlock()
		return
	}
	ix.RUnlock()
	failed := make(map[blob.Ref]bool)
	for {
		ix.Lock()
		if len(ix.readyReindex) == 0 {
			ix.Unlock()
			return
		}
		var br blob.Ref
		for br = range ix.readyReindex {
			break
		}
		delete(ix.readyReindex, br)
		ix.Unlock()
		if err := ix.indexBlob(ctx, br); err != nil {
			log.Printf("out-of-order indexBlob(%v) = %v", br, err)
			failed[br] = true
		}
	}
	ix.Lock()
	defer ix.Unlock()
	for br := range failed {
		ix.readyReindex[br] = true
	}
}
626856
func (i *Index) AvailableShards() *roaring.Bitmap {
	if i == nil {
		return roaring.NewBitmap()
	}

	i.mu.RLock()
	defer i.mu.RUnlock()

	b := roaring.NewBitmap()
	for _, f := range i.fields {
		b = b.Union(f.AvailableShards())
	}

	i.Stats.Gauge("maxShard", float64(b.Max()), 1.0)
	return b
}
460739
func (h *Client) DimensionIndex(dimensionIndex string) *Client {
	h.dimensionIndex = dimensionIndex
	h.dimensionIndexSet = true
	return h
}
858233
func (api *Client) GetAvailableNumbers(numberType AvailableNumberType, query *GetAvailableNumberQuery) ([]*AvailableNumber, error) {
	result, _, err := api.makeRequest(http.MethodGet, fmt.Sprintf("%s/%s", availableNumbersPath, numberType), &[]*AvailableNumber{}, query)
	if err != nil {
		return nil, err
	}
	return *(result.(*[]*AvailableNumber)), nil
}