Skip to content

Commit cdaeae3

Browse files
author
Dan Lambright
committed
Optimize for _count=3
1 parent dd846d7 commit cdaeae3

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

fdbrpc/ReplicationPolicy.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ bool PolicyAcross::validate(std::vector<LocalityEntry> const& solutionSet,
177177
// Choose new servers from "least utilized" alsoServers and append the new servers to results
178178
// fromserverse are the servers that have already been chosen and
179179
// that should be excluded from being selected as replicas.
180-
// fromServers are the servers that must have;
181180
// alsoServers are the servers you can choose.
182181
bool PolicyAcross::selectReplicas(Reference<LocalitySet>& fromServers,
183182
std::vector<LocalityEntry> const& alsoServers,
@@ -189,14 +188,14 @@ bool PolicyAcross::selectReplicas(Reference<LocalitySet>& fromServers,
189188
int resultsInit = results.size();
190189

191190
// Clear the member variables
191+
AttribValue firstUsedValue, secondUsedValue;
192192
_usedValues.clear();
193193
_newResults.clear();
194194
_addedResults.resize(_arena, 0);
195-
196195
for (auto& alsoServer : alsoServers) {
197196
auto value = fromServers->getValueViaGroupKey(alsoServer, groupIndexKey);
198197
if (value.present()) {
199-
if (!_usedValues.contains(value.get())) {
198+
if (firstUsedValue != value.get() && secondUsedValue != value.get() && !_usedValues.contains(value.get())) {
200199
//_selected is a set of processes that have the same indexKey and indexValue (value)
201200
_selected = fromServers->restrict(indexKey, value.get());
202201
if (_selected->size()) {
@@ -211,7 +210,13 @@ bool PolicyAcross::selectReplicas(Reference<LocalitySet>& fromServers,
211210
}
212211
if (count >= _count)
213212
break;
214-
_usedValues.insert(value.get());
213+
if (firstUsedValue._id == -1) {
214+
firstUsedValue = AttribValue(value.get());
215+
} else if (secondUsedValue._id == -1) {
216+
secondUsedValue = AttribValue(value.get());
217+
} else {
218+
_usedValues.insert(value.get());
219+
}
215220
}
216221
}
217222
}
@@ -256,14 +261,20 @@ bool PolicyAcross::selectReplicas(Reference<LocalitySet>& fromServers,
256261
auto& entry = mutableArray[recordIndex];
257262
auto value = fromServers->getValueViaGroupKey(entry, groupIndexKey);
258263
if (value.present()) {
259-
if (!_usedValues.contains(value.get())) {
264+
if (firstUsedValue != value.get() && secondUsedValue != value.get() && !_usedValues.contains(value.get())) {
260265
_selected = fromServers->restrict(indexKey, value.get());
261266
if (_selected->size()) {
262267
if (_policy->selectReplicas(_selected, emptyEntryArray, results)) {
263268
count++;
264269
if (count >= _count)
265270
break;
266-
_usedValues.insert(value.get());
271+
if (firstUsedValue._id == -1) {
272+
firstUsedValue = AttribValue(value.get());
273+
} else if (secondUsedValue._id == -1) {
274+
secondUsedValue = AttribValue(value.get());
275+
} else {
276+
_usedValues.insert(value.get());
277+
}
267278
}
268279
}
269280
}

fdbrpc/include/fdbrpc/ReplicationTypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ struct AttribValue {
5757
namespace std {
5858
template <>
5959
struct hash<AttribValue> {
60-
std::size_t operator()(const AttribValue& v) const noexcept { return std::hash<int>{}(v._id); }
60+
std::size_t operator()(const AttribValue& v) const noexcept { return static_cast<std::size_t>(v._id); }
61+
// return std::hash<int>{}(v._id);
6162
};
6263
} // namespace std
6364
struct LocalityEntry {

0 commit comments

Comments
 (0)