@@ -185,13 +185,10 @@ class DDTeamCollectionImpl {
185185
186186 // Find the team with the exact storage servers as req.src.
187187 static void getTeamByServers (DDTeamCollection* self, GetTeamRequest req) {
188- const std::string servers = TCTeamInfo::serversToString (req.src );
189188 Optional<Reference<IDataDistributionTeam>> res;
190- for (const auto & team : self->teams ) {
191- if (team->getServerIDsStr () == servers) {
192- res = team;
193- break ;
194- }
189+ auto it = self->teamsByServerIDs .find (TCTeamInfo::serversToString (req.src ));
190+ if (it != self->teamsByServerIDs .end ()) {
191+ res = it->second ;
195192 }
196193 req.reply .send (std::make_pair (res, false ));
197194 }
@@ -3076,6 +3073,7 @@ class DDTeamCollectionImpl {
30763073 ACTOR static Future<Void> serverGetTeamRequests (DDTeamCollection* self, TeamCollectionInterface tci) {
30773074 loop {
30783075 GetTeamRequest req = waitNext (tci.getTeam .getFuture ());
3076+ wait (yield ());
30793077 if (req.findTeamByServers ) {
30803078 getTeamByServers (self, req);
30813079 } else {
@@ -4763,6 +4761,7 @@ void DDTeamCollection::addTeam(const std::vector<Reference<TCServerInfo>>& newTe
47634761
47644762 // For a good team, we add it to teams and create machine team for it when necessary
47654763 teams.push_back (teamInfo);
4764+ teamsByServerIDs[teamInfo->getServerIDsStr ()] = teamInfo;
47664765 for (auto & server : newTeamServers) {
47674766 server->addTeam (teamInfo);
47684767 }
@@ -5688,6 +5687,7 @@ void DDTeamCollection::addServer(StorageServerInterface newServer,
56885687
56895688bool DDTeamCollection::removeTeam (Reference<TCTeamInfo> team) {
56905689 TraceEvent (" RemovedServerTeam" , distributorId).detail (" Team" , team->getDesc ());
5690+ teamsByServerIDs.erase (team->getServerIDsStr ());
56915691 bool found = false ;
56925692 for (int t = 0 ; t < teams.size (); t++) {
56935693 if (teams[t] == team) {
0 commit comments