Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: support online change rocksdb config #6377

Merged
merged 10 commits into from Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion cmd/src/server.rs
Expand Up @@ -32,7 +32,7 @@ use std::{
use tikv::config::ConfigHandler;
use tikv::raftstore::router::ServerRaftStoreRouter;
use tikv::{
config::{ConfigController, TiKvConfig},
config::{ConfigController, DBConfigManger, DBType, TiKvConfig},
coprocessor,
import::{ImportSSTService, SSTImporter},
raftstore::{
Expand Down Expand Up @@ -321,6 +321,16 @@ impl TiKVServer {
LocalReader::new(engines.kv.clone(), store_meta.clone(), self.router.clone());
let raft_router = ServerRaftStoreRouter::new(self.router.clone(), local_reader);

let cfg_controller = self.cfg_controller.as_mut().unwrap();
cfg_controller.register(
"rocksdb",
Box::new(DBConfigManger::new(engines.kv.clone(), DBType::Kv)),
);
cfg_controller.register(
"raftdb",
Box::new(DBConfigManger::new(engines.raft.clone(), DBType::Raft)),
);

let engine = RaftKv::new(raft_router.clone());

self.engines = Some(Engines {
Expand Down
23 changes: 21 additions & 2 deletions components/configuration/src/lib.rs
@@ -1,21 +1,27 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use std::collections::HashMap;
use std::fmt::{self, Display, Formatter};
use std::fmt::{self, Debug, Display, Formatter};

pub use configuration_derive::*;

pub type ConfigChange = HashMap<String, ConfigValue>;

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, PartialEq)]
pub enum ConfigValue {
Duration(u64),
Size(u64),
U64(u64),
F64(f64),
I32(i32),
U32(u32),
Usize(usize),
Bool(bool),
String(String),
// `String` represent config field that has type `String`,
// `Other` represent config field with type that can be
// coverted to `String` as temporary representation i.e enum type.
Other(String),
Module(ConfigChange),
}

Expand All @@ -26,14 +32,23 @@ impl Display for ConfigValue {
ConfigValue::Size(v) => write!(f, "{}b", v),
ConfigValue::U64(v) => write!(f, "{}", v),
ConfigValue::F64(v) => write!(f, "{}", v),
ConfigValue::I32(v) => write!(f, "{}", v),
ConfigValue::U32(v) => write!(f, "{}", v),
ConfigValue::Usize(v) => write!(f, "{}", v),
ConfigValue::Bool(v) => write!(f, "{}", v),
ConfigValue::String(v) => write!(f, "{}", v),
ConfigValue::Other(v) => write!(f, "{}", v),
ConfigValue::Module(v) => write!(f, "{:?}", v),
}
}
}

impl Debug for ConfigValue {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self)
}
}

macro_rules! impl_from {
($from: ty, $to: tt) => {
impl From<$from> for ConfigValue {
Expand All @@ -45,6 +60,8 @@ macro_rules! impl_from {
}
impl_from!(u64, U64);
impl_from!(f64, F64);
impl_from!(i32, I32);
impl_from!(u32, U32);
impl_from!(usize, Usize);
impl_from!(bool, Bool);
impl_from!(String, String);
Expand All @@ -69,6 +86,8 @@ macro_rules! impl_into {
}
impl_into!(u64, U64);
impl_into!(f64, F64);
impl_into!(i32, I32);
impl_into!(u32, U32);
impl_into!(usize, Usize);
impl_into!(bool, Bool);
impl_into!(String, String);
Expand Down
1 change: 1 addition & 0 deletions components/engine/Cargo.toml
Expand Up @@ -13,6 +13,7 @@ prost-codec = ["kvproto/prost-codec", "prost"]
protobuf-codec = ["kvproto/protobuf-codec"]

[dependencies]
configuration = { path = "../configuration" }
engine_traits = { path = "../engine_traits" }
hex = "0.3"
kvproto = { git = "https://github.com/pingcap/kvproto.git", default-features = false }
Expand Down
22 changes: 22 additions & 0 deletions components/engine/src/rocks/util/config.rs
@@ -1,6 +1,7 @@
// Copyright 2019 TiKV Project Authors. Licensed under Apache-2.0.

use crate::rocks::{DBCompressionType, DBTitanDBBlobRunMode};
use configuration::ConfigValue;

#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -124,6 +125,27 @@ pub enum BlobRunMode {
Fallback,
}

impl From<BlobRunMode> for ConfigValue {
fn from(mode: BlobRunMode) -> ConfigValue {
ConfigValue::Other(format!("k{:?}", mode))
}
}

impl Into<BlobRunMode> for ConfigValue {
fn into(self) -> BlobRunMode {
if let ConfigValue::Other(s) = self {
match s.as_str() {
"kNormal" => BlobRunMode::Normal,
"kReadOnly" => BlobRunMode::ReadOnly,
"kFallback" => BlobRunMode::Fallback,
m => panic!("expect: kNormal, kReadOnly or kFallback, got: {:?}", m),
}
} else {
panic!("expect: ConfigValue::Other, got: {:?}", self);
}
}
}

impl Into<DBTitanDBBlobRunMode> for BlobRunMode {
fn into(self) -> DBTitanDBBlobRunMode {
match self {
Expand Down