5
5
#include " containers/priority_queue.hpp"
6
6
#include " clustering/generic/nonoverlapping_regions.hpp"
7
7
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
+
8
18
namespace {
9
19
10
20
struct priority_t {
@@ -222,7 +232,7 @@ std::map<machine_id_t, blueprint_role_t> suggest_blueprint_for_shard(
222
232
sub_blueprint[primary] = blueprint_role_primary;
223
233
224
234
// Update primary_usage
225
- ++ (*usage)[primary];
235
+ (*usage)[primary] += PRIMARY_USAGE_COST ;
226
236
}
227
237
228
238
@@ -243,7 +253,7 @@ std::map<machine_id_t, blueprint_role_t> suggest_blueprint_for_shard(
243
253
244
254
for (std::vector<machine_id_t >::iterator jt = secondaries.begin (); jt != secondaries.end (); jt++) {
245
255
// Update secondary usage
246
- ++ (*usage)[*jt];
256
+ (*usage)[*jt] += SECONDARY_USAGE_COST ;
247
257
sub_blueprint[*jt] = blueprint_role_secondary;
248
258
unused_machines.erase (*jt);
249
259
}
@@ -265,7 +275,7 @@ std::map<machine_id_t, blueprint_role_t> suggest_blueprint_for_shard(
265
275
sub_blueprint[primary] = blueprint_role_primary;
266
276
267
277
// Update primary_usage
268
- ++ (*usage)[primary];
278
+ (*usage)[primary] += PRIMARY_USAGE_COST ;
269
279
}
270
280
271
281
/* Finally pick the secondaries for the nil datacenter */
@@ -280,7 +290,7 @@ std::map<machine_id_t, blueprint_role_t> suggest_blueprint_for_shard(
280
290
281
291
for (std::vector<machine_id_t >::iterator jt = secondaries.begin (); jt != secondaries.end (); jt++) {
282
292
// Update secondary usage
283
- ++ (*usage)[*jt];
293
+ (*usage)[*jt] += SECONDARY_USAGE_COST ;
284
294
sub_blueprint[*jt] = blueprint_role_secondary;
285
295
unused_machines.erase (*jt);
286
296
}
0 commit comments