Skip to main content

mito2/sst/index/indexer/
abort.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 common_telemetry::warn;
16
17use crate::access_layer::TempFileCleaner;
18use crate::sst::file::{RegionFileId, RegionIndexId};
19use crate::sst::index::Indexer;
20
21impl Indexer {
22    /// Aborts builtin creators while retaining synchronous extension creators.
23    pub(crate) async fn abort_builtin_creators(&mut self) {
24        self.dense_pk_decoder = None;
25        let mut position = 0;
26        while position < self.creators.len() {
27            if self.creators[position].is_builtin() {
28                self.abort_creator(position).await;
29            } else {
30                position += 1;
31            }
32        }
33        self.flush_mem_metrics();
34    }
35
36    pub(crate) async fn abort_creator(&mut self, position: usize) {
37        let mut active = self.creators.remove(position);
38        if let Err(err) = active.creator.abort().await {
39            if active.is_builtin() && cfg!(any(test, feature = "test")) {
40                panic!("Failed to abort index: {err:?}");
41            }
42            warn!(err; "Failed to abort index, region_id: {}, file_id: {}, kinds: {:?}", self.region_id, self.file_id, active.kinds);
43        }
44    }
45
46    pub(crate) async fn do_abort(&mut self) {
47        self.dense_pk_decoder = None;
48        while !self.creators.is_empty() {
49            self.abort_creator(0).await;
50        }
51        self.do_prune_intm_sst_dir().await;
52        if self.write_cache_enabled {
53            self.do_abort_clean_fs_temp_dir().await;
54        }
55        self.puffin_manager = None;
56    }
57
58    async fn do_abort_clean_fs_temp_dir(&mut self) {
59        let Some(puffin_manager) = &self.puffin_manager else {
60            return;
61        };
62        let fs_accessor = puffin_manager.file_accessor();
63
64        let fs_handle = RegionIndexId::new(
65            RegionFileId::new(self.physical_region_id, self.file_id),
66            self.index_version,
67        )
68        .to_string();
69        TempFileCleaner::clean_atomic_dir_files(fs_accessor.store().store(), &[&fs_handle]).await;
70    }
71}