1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2021 Alibaba Cloud. All rights reserved.
//
// SPDX-License-Identifier: Apache-2.0
use anyhow::Result;
use crate::core::node::{Node, Overlay};
use crate::core::prefetch::Prefetch;
#[derive(Clone)]
pub struct BlobLayout {}
impl BlobLayout {
pub fn layout_blob_simple(prefetch: &Prefetch, nodes: &[Node]) -> Result<(Vec<usize>, usize)> {
let mut inodes = Vec::with_capacity(nodes.len());
// Put all prefetch inodes at the head
// NOTE: Don't try to sort readahead files by their sizes, thus to keep files
// belonging to the same directory arranged in adjacent in blob file. Together with
// BFS style collecting descendants inodes, it will have a higher merging possibility.
// Later, we might write chunks of data one by one according to inode number order.
let prefetches = prefetch.get_file_indexes();
for index in prefetches {
let index = index as usize - 1;
let node = &nodes[index];
if Self::should_dump_node(node) {
inodes.push(index);
}
}
let prefetch_entries = inodes.len();
// Put all other non-prefetch inode at the tail
for (index, node) in nodes.iter().enumerate() {
// Ignore lower layer node when dump blob
if !prefetch.contains(node) && Self::should_dump_node(node) {
inodes.push(index);
}
}
Ok((inodes, prefetch_entries))
}
#[inline]
fn should_dump_node(node: &Node) -> bool {
node.overlay == Overlay::UpperAddition || node.overlay == Overlay::UpperModification
}
}