Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: shuffle segments during distributed pruning #8793

Merged
merged 3 commits into from
Nov 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/query/storages/fuse/fuse/src/operations/read_partitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
use std::hash::Hash;
use std::hash::Hasher;
use std::sync::Arc;
use std::time::Instant;

Expand Down Expand Up @@ -60,8 +63,30 @@ impl FuseTable {
if settings.get_enable_distributed_eval_index()? {
let mut segments = Vec::with_capacity(snapshot.segments.len());

for segment_location in &snapshot.segments {
segments.push(FuseLazyPartInfo::create(segment_location.clone()))
let mut segments_locations = snapshot.segments.clone();

// reorder the segment locations according to their hash of location,
// so that,
// - segments are kind of shuffled
// - with the assumption of stable query cluster membership
// the same segment will likely to be assigned to the same query
// node (by PlanFragment::redistribute_source_fragment), and cache will be
// utilized better.
let num_nodes = ctx.get_cluster().nodes.len() as u64;
let hash = |path: &str| -> u64 {
let mut s = DefaultHasher::new();
path.hash(&mut s);
s.finish() % num_nodes
};
segments_locations.sort_by(|a, b| {
let hl = hash(&a.0);
let hr = hash(&b.0);
hl.cmp(&hr)
});

// build the PartInfos
for segment_location in segments_locations {
segments.push(FuseLazyPartInfo::create(segment_location))
}

return Ok((
Expand Down