Skip to content

Commit

Permalink
Adding allocation in builder for best read nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeniawhite committed Apr 27, 2016
1 parent bad8c3c commit dbacd3d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/server/mapper/block_allocator.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function refresh_pool_alloc(pool) {
* @param avoid_nodes array of node ids to avoid
*
*/
function allocate_node(pools, avoid_nodes) {
function allocate_node(pools, avoid_nodes, params) {
let pool_set = _.map(pools, pool => pool._id.toString()).sort().join(',');
let alloc_group =
alloc_group_by_pool_set[pool_set] =
Expand All @@ -105,6 +105,14 @@ function allocate_node(pools, avoid_nodes) {
return group && group.nodes;
})))
};

// Used in map_builder, for content tiering
if (params && params.special_replica) {
alloc_group.nodes = _.sortBy(alloc_group.nodes, node =>
_.sum(node.latency_of_disk_read) / node.latency_of_disk_read.length
);
}

let num_nodes = alloc_group ? alloc_group.nodes.length : 0;
dbg.log1('allocate_node: pool_set', pool_set,
'num_nodes', num_nodes,
Expand Down Expand Up @@ -133,4 +141,4 @@ function get_round_robin(nodes) {
var rr = (nodes.rr || 0) % nodes.length;
nodes.rr = rr + 1;
return nodes[rr];
}
}
4 changes: 3 additions & 1 deletion src/server/mapper/map_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ class MapBuilder {
'digest_type',
'digest_b64');
block._id = md_store.make_md_id();
let node = block_allocator.allocate_node(alloc.pools, avoid_nodes);
let node = block_allocator.allocate_node(alloc.pools, avoid_nodes, {
special_replica: true
});
if (!node) {
dbg.error('MapBuilder: no nodes for allocation');
chunk.had_errors = true;
Expand Down
3 changes: 2 additions & 1 deletion src/server/stores/nodes_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const NODE_FIELDS_FOR_MAP = Object.freeze({
heartbeat: 1,
rpc_address: 1,
storage: 1,
latency_of_disk_read: 1,
});

module.exports = {
Expand Down Expand Up @@ -175,7 +176,7 @@ function aggregate_nodes_by_pool(query) {
}
))
.then(res => {
var bins = {};
var bins = {};
_.each(res, r => {
var t = bins[r._id[0]] = bins[r._id[0]] || {};
t[r._id[1]] = r.value;
Expand Down

0 comments on commit dbacd3d

Please sign in to comment.