-
Notifications
You must be signed in to change notification settings - Fork 597
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(meta): add hummock version relevant tables to rw_catalog (#12309)
- Loading branch information
Showing
11 changed files
with
292 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_branched_objects.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2023 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use risingwave_common::catalog::RW_CATALOG_SCHEMA_NAME; | ||
use risingwave_common::error::Result; | ||
use risingwave_common::row::OwnedRow; | ||
use risingwave_common::types::{DataType, ScalarImpl}; | ||
|
||
use crate::catalog::system_catalog::{BuiltinTable, SysCatalogReaderImpl}; | ||
|
||
pub const RW_HUMMOCK_BRANCHED_OBJECTS: BuiltinTable = BuiltinTable { | ||
name: "rw_hummock_branched_objects", | ||
schema: RW_CATALOG_SCHEMA_NAME, | ||
columns: &[ | ||
(DataType::Int64, "object_id"), | ||
(DataType::Int64, "sst_id"), | ||
(DataType::Int64, "compaction_group_id"), | ||
], | ||
pk: &[], | ||
}; | ||
|
||
impl SysCatalogReaderImpl { | ||
pub async fn read_hummock_branched_objects(&self) -> Result<Vec<OwnedRow>> { | ||
let branched_objects = self.meta_client.list_branched_objects().await?; | ||
let rows = branched_objects | ||
.into_iter() | ||
.map(|o| { | ||
OwnedRow::new(vec![ | ||
Some(ScalarImpl::Int64(o.object_id as _)), | ||
Some(ScalarImpl::Int64(o.sst_id as _)), | ||
Some(ScalarImpl::Int64(o.compaction_group_id as _)), | ||
]) | ||
}) | ||
.collect(); | ||
Ok(rows) | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_version.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright 2023 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use risingwave_common::catalog::RW_CATALOG_SCHEMA_NAME; | ||
use risingwave_common::error::Result; | ||
use risingwave_common::row::OwnedRow; | ||
use risingwave_common::types::{DataType, ScalarImpl}; | ||
use risingwave_pb::hummock::HummockVersion; | ||
use serde_json::json; | ||
|
||
use crate::catalog::system_catalog::{BuiltinTable, SysCatalogReaderImpl}; | ||
|
||
pub const RW_HUMMOCK_CURRENT_VERSION: BuiltinTable = BuiltinTable { | ||
name: "rw_hummock_current_version", | ||
schema: RW_CATALOG_SCHEMA_NAME, | ||
columns: &[ | ||
(DataType::Int64, "version_id"), | ||
(DataType::Int64, "max_committed_epoch"), | ||
(DataType::Int64, "safe_epoch"), | ||
(DataType::Jsonb, "compaction_group"), | ||
], | ||
pk: &[], | ||
}; | ||
|
||
pub const RW_HUMMOCK_CHECKPOINT_VERSION: BuiltinTable = BuiltinTable { | ||
name: "rw_hummock_checkpoint_version", | ||
schema: RW_CATALOG_SCHEMA_NAME, | ||
columns: &[ | ||
(DataType::Int64, "version_id"), | ||
(DataType::Int64, "max_committed_epoch"), | ||
(DataType::Int64, "safe_epoch"), | ||
(DataType::Jsonb, "compaction_group"), | ||
], | ||
pk: &[], | ||
}; | ||
|
||
impl SysCatalogReaderImpl { | ||
pub async fn read_hummock_current_version(&self) -> Result<Vec<OwnedRow>> { | ||
let version = self.meta_client.get_hummock_current_version().await?; | ||
Ok(version_to_rows(&version)) | ||
} | ||
|
||
pub async fn read_hummock_checkpoint_version(&self) -> Result<Vec<OwnedRow>> { | ||
let version = self.meta_client.get_hummock_checkpoint_version().await?; | ||
Ok(version_to_rows(&version)) | ||
} | ||
} | ||
|
||
fn version_to_rows(version: &HummockVersion) -> Vec<OwnedRow> { | ||
version | ||
.levels | ||
.values() | ||
.map(|cg| { | ||
OwnedRow::new(vec![ | ||
Some(ScalarImpl::Int64(version.id as _)), | ||
Some(ScalarImpl::Int64(version.max_committed_epoch as _)), | ||
Some(ScalarImpl::Int64(version.safe_epoch as _)), | ||
// FIXME #8612: The byte array key_range is encoded to a string by serde_json. We need disable this behavior as it makes it harder to understand the key range. | ||
Some(ScalarImpl::Jsonb(json!(cg).into())), | ||
]) | ||
}) | ||
.collect() | ||
} |
57 changes: 57 additions & 0 deletions
57
src/frontend/src/catalog/system_catalog/rw_catalog/rw_hummock_version_deltas.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2023 RisingWave Labs | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use risingwave_common::catalog::RW_CATALOG_SCHEMA_NAME; | ||
use risingwave_common::error::Result; | ||
use risingwave_common::row::OwnedRow; | ||
use risingwave_common::types::{DataType, ScalarImpl}; | ||
use serde_json::json; | ||
|
||
use crate::catalog::system_catalog::{BuiltinTable, SysCatalogReaderImpl}; | ||
|
||
pub const RW_HUMMOCK_VERSION_DELTAS: BuiltinTable = BuiltinTable { | ||
name: "rw_hummock_version_deltas", | ||
schema: RW_CATALOG_SCHEMA_NAME, | ||
columns: &[ | ||
(DataType::Int64, "id"), | ||
(DataType::Int64, "prev_id"), | ||
(DataType::Int64, "max_committed_epoch"), | ||
(DataType::Int64, "safe_epoch"), | ||
(DataType::Boolean, "trivial_move"), | ||
(DataType::Jsonb, "gc_object_ids"), | ||
(DataType::Jsonb, "group_deltas"), | ||
], | ||
pk: &[0], | ||
}; | ||
|
||
impl SysCatalogReaderImpl { | ||
pub async fn read_hummock_version_deltas(&self) -> Result<Vec<OwnedRow>> { | ||
let deltas = self.meta_client.list_version_deltas().await?; | ||
let rows = deltas | ||
.into_iter() | ||
.map(|d| { | ||
OwnedRow::new(vec![ | ||
Some(ScalarImpl::Int64(d.id as _)), | ||
Some(ScalarImpl::Int64(d.prev_id as _)), | ||
Some(ScalarImpl::Int64(d.max_committed_epoch as _)), | ||
Some(ScalarImpl::Int64(d.safe_epoch as _)), | ||
Some(ScalarImpl::Bool(d.trivial_move)), | ||
Some(ScalarImpl::Jsonb(json!(d.gc_object_ids).into())), | ||
Some(ScalarImpl::Jsonb(json!(d.group_deltas).into())), | ||
]) | ||
}) | ||
.collect(); | ||
Ok(rows) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters