|
| 1 | +// Copyright 2023 RisingWave Labs |
| 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 | + |
| 15 | +use risingwave_hummock_sdk::compaction_group::hummock_version_ext::HummockVersionUpdateExt; |
| 16 | +use risingwave_hummock_sdk::HummockEpoch; |
| 17 | + |
| 18 | +use crate::CtlContext; |
| 19 | + |
| 20 | +pub async fn disable_commit_epoch(context: &CtlContext) -> anyhow::Result<()> { |
| 21 | + let meta_client = context.meta_client().await?; |
| 22 | + let version = meta_client.disable_commit_epoch().await?; |
| 23 | + println!( |
| 24 | + "Disabled.\ |
| 25 | + Current version: id {}, max_committed_epoch {}", |
| 26 | + version.id, version.max_committed_epoch |
| 27 | + ); |
| 28 | + Ok(()) |
| 29 | +} |
| 30 | + |
| 31 | +pub async fn pause_version_checkpoint(context: &CtlContext) -> anyhow::Result<()> { |
| 32 | + let meta_client = context.meta_client().await?; |
| 33 | + meta_client |
| 34 | + .risectl_pause_hummock_version_checkpoint() |
| 35 | + .await?; |
| 36 | + println!("Hummock version checkpoint is paused"); |
| 37 | + Ok(()) |
| 38 | +} |
| 39 | + |
| 40 | +pub async fn resume_version_checkpoint(context: &CtlContext) -> anyhow::Result<()> { |
| 41 | + let meta_client = context.meta_client().await?; |
| 42 | + meta_client |
| 43 | + .risectl_resume_hummock_version_checkpoint() |
| 44 | + .await?; |
| 45 | + println!("Hummock version checkpoint is resumed"); |
| 46 | + Ok(()) |
| 47 | +} |
| 48 | + |
| 49 | +/// For now this function itself doesn't provide useful info. |
| 50 | +/// We can extend it to reveal interested info, e.g. at which hummock version is a user key |
| 51 | +/// added/removed for what reason (row deletion/compaction/etc.). |
| 52 | +pub async fn replay_version(context: &CtlContext) -> anyhow::Result<()> { |
| 53 | + let meta_client = context.meta_client().await?; |
| 54 | + let mut base_version = meta_client |
| 55 | + .risectl_get_checkpoint_hummock_version() |
| 56 | + .await? |
| 57 | + .checkpoint_version |
| 58 | + .unwrap(); |
| 59 | + println!("replay starts"); |
| 60 | + println!("base version {}", base_version.id); |
| 61 | + let delta_fetch_size = 100; |
| 62 | + let mut current_delta_id = base_version.id + 1; |
| 63 | + loop { |
| 64 | + let deltas = meta_client |
| 65 | + .list_version_deltas(current_delta_id, delta_fetch_size, HummockEpoch::MAX) |
| 66 | + .await |
| 67 | + .unwrap(); |
| 68 | + if deltas.version_deltas.is_empty() { |
| 69 | + break; |
| 70 | + } |
| 71 | + for delta in deltas.version_deltas { |
| 72 | + if delta.prev_id != base_version.id { |
| 73 | + eprintln!("missing delta log for version {}", base_version.id); |
| 74 | + break; |
| 75 | + } |
| 76 | + base_version.apply_version_delta(&delta); |
| 77 | + println!("replayed version {}", base_version.id); |
| 78 | + } |
| 79 | + current_delta_id = base_version.id + 1; |
| 80 | + } |
| 81 | + println!("replay ends"); |
| 82 | + Ok(()) |
| 83 | +} |
0 commit comments