Skip to content

Commit 962d0ff

Browse files
generatedunixname1395027625275998meta-codesync[bot]
authored andcommitted
fbcode/mcrouter/routes/McRouteHandleProvider-inl.h
Reviewed By: MatzeB Differential Revision: D104066553 fbshipit-source-id: 0a37e97d59a1f7287ef32ab54a90afe0b1569239
1 parent 1aeaa44 commit 962d0ff

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

‎mcrouter/routes/McRouteHandleProvider-inl.h‎

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <folly/Conv.h>
1313
#include <folly/Range.h>
14+
#include <folly/container/Reserve.h>
1415

1516
#include "mcrouter/CarbonRouterInstanceBase.h"
1617
#include "mcrouter/McrouterLogFailure.h"
@@ -319,6 +320,7 @@ McRouteHandleProvider<RouterInfo>::makePool(
319320
jWeights = nullptr;
320321
}
321322
folly::dynamic jNewWeights = folly::dynamic::array;
323+
auto accessPointsIt = accessPoints_.end();
322324
for (size_t i = 0; i < jservers->size(); ++i) {
323325
const auto& server = jservers->at(i);
324326
checkLogic(
@@ -346,17 +348,21 @@ McRouteHandleProvider<RouterInfo>::makePool(
346348
proxy_.stats().increment(dest_with_no_failure_domain_count_stat);
347349
}
348350

351+
if (accessPointsIt == accessPoints_.end()) {
352+
auto expectedSize = jservers->size() * (1 + additionalFanout);
353+
auto [it, inserted] = accessPoints_.try_emplace(name, expectedSize);
354+
accessPointsIt = it;
355+
if (!inserted) {
356+
folly::grow_capacity_by(accessPointsIt->second, expectedSize);
357+
}
358+
}
359+
auto& accessPointsSet = accessPointsIt->second;
360+
folly::StringPiece nameSp = accessPointsIt->first;
361+
349362
for (uint32_t idx = 0; idx < (1 + additionalFanout); ++idx) {
350363
auto ap = createAccessPoint(
351364
server.stringPiece(), failureDomain, proxy_.router(), *apAttr);
352365

353-
auto it = accessPoints_.find(name);
354-
if (it == accessPoints_.end()) {
355-
folly::F14FastSet<std::shared_ptr<const AccessPoint>> accessPoints;
356-
it = accessPoints_.emplace(name, std::move(accessPoints)).first;
357-
}
358-
folly::StringPiece nameSp = it->first;
359-
360366
if (ap->getProtocol() == mc_thrift_protocol) {
361367
checkLogic(
362368
ap->getSecurityMech() == SecurityMech::NONE ||
@@ -381,7 +387,7 @@ McRouteHandleProvider<RouterInfo>::makePool(
381387
poolTkoTracker,
382388
keepRoutingPrefix,
383389
idx);
384-
it->second.insert(destResult.second);
390+
accessPointsSet.insert(destResult.second);
385391
addDestination(std::move(destResult.first));
386392
} else {
387393
using Transport = AsyncMcClient;
@@ -398,7 +404,7 @@ McRouteHandleProvider<RouterInfo>::makePool(
398404
poolTkoTracker,
399405
keepRoutingPrefix,
400406
idx);
401-
it->second.insert(destResult.second);
407+
accessPointsSet.insert(destResult.second);
402408
addDestination(std::move(destResult.first));
403409
}
404410
}

0 commit comments

Comments
 (0)