MCPcopy Create free account
hub / github.com/apple/foundationdb / ClusterConnectionString

Method ClusterConnectionString

fdbclient/MonitorLeader.actor.cpp:88–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88ClusterConnectionString::ClusterConnectionString(const std::string& connectionString) {
89 auto trimmed = trim(connectionString);
90 // Split on '@' into key@addrs
91 int pAt = trimmed.find_first_of('@');
92 if (pAt == trimmed.npos) {
93 throw connection_string_invalid();
94 }
95 std::string key = trimmed.substr(0, pAt);
96 std::string addrs = trimmed.substr(pAt + 1);
97
98 parseKey(key);
99 std::set<Hostname> hostnameSet;
100 std::set<NetworkAddress> addressSet;
101 std::string curAddr;
102 for (int p = 0; p <= addrs.size();) {
103 int pComma = addrs.find_first_of(',', p);
104 if (pComma == addrs.npos)
105 pComma = addrs.size();
106 curAddr = addrs.substr(p, pComma - p);
107 if (Hostname::isHostname(curAddr)) {
108 Hostname h = Hostname::parse(curAddr);
109 // Check that there are no duplicate hostnames
110 if (hostnameSet.find(h) != hostnameSet.end()) {
111 throw connection_string_invalid();
112 }
113 hostnames.push_back(Hostname::parse(curAddr));
114 hostnameSet.insert(h);
115 } else {
116 NetworkAddress n = NetworkAddress::parse(curAddr);
117 // Check that there are no duplicate addresses
118 if (addressSet.find(n) != addressSet.end()) {
119 throw connection_string_invalid();
120 }
121 coords.push_back(n);
122 addressSet.insert(n);
123 }
124 p = pComma + 1;
125 }
126 ASSERT((coords.size() + hostnames.size()) > 0);
127}
128
129TEST_CASE("/fdbclient/MonitorLeader/parseConnectionString/addresses") {
130 state std::string input;

Callers

nothing calls this directly

Calls 11

trimFunction · 0.85
parseKeyFunction · 0.85
substrMethod · 0.80
parseFunction · 0.70
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
insertMethod · 0.45
beginMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected