-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ctl): support list key-value pairs
Signed-off-by: Alex Chi <[email protected]>
- Loading branch information
Showing
8 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
mod list_version; | ||
pub use list_version::*; | ||
mod list_kv; | ||
pub use list_kv::*; |
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,16 @@ | ||
use risingwave_storage::StateStore; | ||
|
||
use crate::common::HummockServiceOpts; | ||
|
||
pub async fn list_kv() -> anyhow::Result<()> { | ||
let hummock_opts = HummockServiceOpts::from_env()?; | ||
let hummock = hummock_opts.create_hummock_store().await?; | ||
// TODO: support speficy epoch | ||
tracing::info!("using u64::MAX as epoch"); | ||
|
||
for (k, v) in hummock.scan::<_, Vec<u8>>(.., None, u64::MAX).await? { | ||
println!("{:?} => {:?}", k, v); | ||
} | ||
|
||
Ok(()) | ||
} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
mod meta_service; | ||
pub use meta_service::*; | ||
mod hummock_service; | ||
pub use hummock_service::*; |
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,61 @@ | ||
use std::env; | ||
use std::sync::Arc; | ||
|
||
use anyhow::{anyhow, Result}; | ||
use risingwave_common::config::StorageConfig; | ||
use risingwave_storage::hummock::HummockStateStore; | ||
use risingwave_storage::monitor::{MonitoredStateStore, StateStoreStats}; | ||
use risingwave_storage::StateStoreImpl; | ||
|
||
use super::MetaServiceOpts; | ||
|
||
pub struct HummockServiceOpts { | ||
pub meta_opts: MetaServiceOpts, | ||
pub hummock_url: String, | ||
} | ||
|
||
impl HummockServiceOpts { | ||
/// Recover hummock service options from env variable | ||
/// | ||
/// Currently, we will read these variables for meta: | ||
/// | ||
/// * `RW_HUMMOCK_URL`: meta service address | ||
pub fn from_env() -> Result<Self> { | ||
let meta_opts = MetaServiceOpts::from_env()?; | ||
let hummock_url = env::var("RW_HUMMOCK_URL").unwrap_or_else(|_| { | ||
const DEFAULT_ADDR: &str = "hummock+minio://hummock:[email protected]:9301/hummock001"; | ||
tracing::warn!( | ||
"`RW_HUMMOCK_URL` not found, using default hummock URL {}", | ||
DEFAULT_ADDR | ||
); | ||
DEFAULT_ADDR.to_string() | ||
}); | ||
Ok(Self { | ||
meta_opts, | ||
hummock_url, | ||
}) | ||
} | ||
|
||
pub async fn create_hummock_store(&self) -> Result<MonitoredStateStore<HummockStateStore>> { | ||
let meta_client = self.meta_opts.create_meta_client().await?; | ||
|
||
// FIXME: allow specify custom config | ||
let config = StorageConfig::default(); | ||
|
||
tracing::info!("using Hummock config: {:#?}", config); | ||
|
||
let state_store_impl = StateStoreImpl::new( | ||
&self.hummock_url, | ||
Arc::new(config), | ||
meta_client, | ||
Arc::new(StateStoreStats::unused()), | ||
) | ||
.await?; | ||
|
||
if let StateStoreImpl::HummockStateStore(hummock_state_store) = state_store_impl { | ||
Ok(hummock_state_store) | ||
} else { | ||
Err(anyhow!("only Hummock state store is supported in risectl")) | ||
} | ||
} | ||
} |
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