mito2/sst/
location.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use object_store::util;
16
17use crate::sst::file::FileId;
18
19/// Returns the path of the SST file in the object store:
20/// `{region_dir}/{sst_file_id}.parquet`
21pub fn sst_file_path(region_dir: &str, sst_file_id: FileId) -> String {
22    util::join_path(region_dir, &sst_file_id.as_parquet())
23}
24
25/// Returns the path of the index file in the object store:
26/// `{region_dir}/index/{sst_file_id}.puffin`
27pub fn index_file_path(region_dir: &str, sst_file_id: FileId) -> String {
28    let dir = util::join_dir(region_dir, "index");
29    util::join_path(&dir, &sst_file_id.as_puffin())
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn test_sst_file_path() {
38        let file_id = FileId::random();
39        assert_eq!(
40            sst_file_path("region_dir", file_id),
41            format!("region_dir/{file_id}.parquet")
42        );
43    }
44
45    #[test]
46    fn test_index_file_path() {
47        let file_id = FileId::random();
48        assert_eq!(
49            index_file_path("region_dir", file_id),
50            format!("region_dir/index/{file_id}.puffin")
51        );
52    }
53}