// GossipStore broadcasts the store on the gossip network. func (s *Store) gossipStore(rangeCount int) error { desc := s.getDesc(rangeCount) // Unique gossip key per store. gossipKey := gossip.MakeStoreKey(desc.StoreID) // Gossip store descriptor. return s.gossip.AddInfoProto(gossipKey, &desc, 0) }
// GossipStores queues up a list of stores to gossip and blocks until each one // is gossiped before returning. func (sg *StoreGossiper) GossipStores(storeDescs []*roachpb.StoreDescriptor, t *testing.T) { storeIDs := make([]roachpb.StoreID, len(storeDescs)) for i, store := range storeDescs { storeIDs[i] = store.StoreID } sg.GossipWithFunction(storeIDs, func() { for i, storeDesc := range storeDescs { if err := sg.g.AddInfoProto(gossip.MakeStoreKey(storeIDs[i]), storeDesc, 0); err != nil { t.Fatal(err) } } }) }
// GossipWithFunction calls gossipFn and blocks until gossip callbacks have // fired on each of the stores specified by storeIDs. func (sg *StoreGossiper) GossipWithFunction(storeIDs []roachpb.StoreID, gossipFn func()) { sg.mu.Lock() defer sg.mu.Unlock() sg.storeKeyMap = make(map[string]struct{}) for _, storeID := range storeIDs { storeKey := gossip.MakeStoreKey(storeID) sg.storeKeyMap[storeKey] = struct{}{} } gossipFn() // Wait for gossip callbacks to be invoked on all the stores. for len(sg.storeKeyMap) > 0 { sg.cond.Wait() } }