Skip to content

Commit

Permalink
Add comments about the choice of memory size for sort managers
Browse files Browse the repository at this point in the history
  • Loading branch information
rostislav authored and hoffmang9 committed Mar 27, 2021
1 parent ee238ab commit 618a2af
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/phase2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ Phase2Results RunPhase2(
// * update (pos, offset) to remain valid after table_index-1 has been
// compacted.
// * sort by pos
//
// As we have to sort two adjacent tables at the same time in phase 3,
// we can use only a half of memory_size for SortManager. However,
// table 1 is already sorted, so we can use all memory for sorting
// table 2.

auto sort_manager = std::make_unique<SortManager>(
table_index == 2 ? memory_size : memory_size / 2,
Expand Down
10 changes: 8 additions & 2 deletions src/phase3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ Phase3Results RunPhase3(
L_sort_manager->FreeMemory();
}

// We read only from this SortManager during the second pass, so all
// memory is available
R_sort_manager = std::make_unique<SortManager>(
memory_size,
num_buckets,
Expand Down Expand Up @@ -363,8 +365,12 @@ Phase3Results RunPhase3(
L_sort_manager.reset();
}

// L sort manager will be used for the writer, and R sort manager will be used for the
// reader
// In the second pass we read from R sort manager and write to L sort
// manager, and they both handle table (table_index + 1)'s data.
// For tables below 6 we can only use a half of memory_size since it
// will be sorted in the first pass of the next iteration together with
// the next table, which will use the other half of memory_size.
// Tables 6 and 7 will be sorted alone, so we use all memory for them.
R_sort_manager->FreeMemory();
L_sort_manager = std::make_unique<SortManager>(
(table_index >= 5) ? memory_size : (memory_size / 2),
Expand Down

0 comments on commit 618a2af

Please sign in to comment.