8000 Use different costs for primary and secondary assignments in suggester. · jchjava/rethinkdb@1920cf1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1920cf1

Browse files
author
Daniel Mewes
committed
Use different costs for primary and secondary assignments in suggester.
1 parent 54bab7f commit 1920cf1

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/clustering/suggester/suggester.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
#include "containers/priority_queue.hpp"
66
#include "clustering/generic/nonoverlapping_regions.hpp"
77

8+
// Because being primary for a shard usually comes with a higher cost than
9+
// being secondary, we want to consider that difference in the replica assignment.
10+
// The concrete value of these doesn't matter, only their ratio
11+
// (float)PRIMARY_USAGE_COST/(float)SECONDARY_USAGE_COST is important.
12+
// As long as PRIMARY_USAGE_COST > SECONDARY_USAGE_COST, this is a solution to
13+
// https://github.com/rethinkdb/rethinkdb/issues/344 (if the machine roles are
14+
// otherwise equal).
15+
#define PRIMARY_USAGE_COST 10
16+
#define SECONDARY_USAGE_COST 8
17+
818
namespace {
919

1020
struct priority_t {
@@ -222,7 +232,7 @@ std::map<machine_id_t, blueprint_role_t> suggest_blueprint_for_shard(
222232
sub_blueprint[primary] = blueprint_role_primary;
223233

224234
//Update primary_usage
225-
++(*usage)[primary];
235+
(*usage)[primary] += PRIMARY_USAGE_COST;
226236
}
227237

228238

@@ -243,7 +253,7 @@ std::map<machine_id_t, blueprint_role_t> suggest_blueprint_for_shard(
243253

244254
for (std::vector<machine_id_t>::iterator jt = secondaries.begin(); jt != secondaries.end(); jt++) {
245255
//Update secondary usage
246-
++(*usage)[*jt];
256+
(*usage)[*jt] += SECONDARY_USAGE_COST;
247257
sub_blueprint[*jt] = blueprint_role_secondary;
248258
unused_machines.erase(*jt);
249259
}
@@ -265,7 +275,7 @@ std::map<machine_id_t, blueprint_role_t> suggest_blueprint_for_shard(
265275
sub_blueprint[primary] = blueprint_role_primary;
266276

267277
//Update primary_usage
268-
++(*usage)[primary];
278+
(*usage)[primary] += PRIMARY_USAGE_COST;
269279
}
270280

271281
/* Finally pick the secondaries for the nil datacenter */
@@ -280,7 +290,7 @@ std::map<machine_id_t, blueprint_role_t> suggest_blueprint_for_shard(
280290

281291
for (std::vector<machine_id_t>::iterator jt = secondaries.begin(); jt != secondaries.end(); jt++) {
282292
//Update secondary usage
283-
++(*usage)[*jt];
293+
(*usage)[*jt] += SECONDARY_USAGE_COST;
284294
sub_blueprint[*jt] = blueprint_role_secondary;
285295
unused_machines.erase(*jt);
286296
}

0 commit comments

Comments
 (0)
0