Skip to content

Commit 07f7c4c

Browse files
committed
return blocks in descending heartbeat order
1 parent 36ef365 commit 07f7c4c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/server/object_mapper.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,8 @@ function bad_block_in_part(obj, start, end, fragment, block_id, is_write) {
291291
function get_part_info(part, chunk, blocks, set_obj) {
292292
var fragments = [];
293293
_.each(_.groupBy(blocks, 'fragment'), function(fragment_blocks, fragment) {
294-
fragments[fragment] = _.map(fragment_blocks, get_block_info);
294+
var sorted_blocks = _.sortBy(fragment_blocks, block_heartbeat_sort);
295+
fragments[fragment] = _.map(sorted_blocks, get_block_info);
295296
});
296297
var p = _.pick(part, 'start', 'end', 'chunk_offset');
297298
p.fragments = fragments;
@@ -338,3 +339,10 @@ function sanitize_object_range(obj, start, end) {
338339
end: end,
339340
};
340341
}
342+
343+
/**
344+
* sorting function for sorting blocks with most recent heartbeat first
345+
*/
346+
function block_heartbeat_sort(block) {
347+
return -block.node.heartbeat.getTime();
348+
}

0 commit comments

Comments
 (0)