Skip to content

Commit

Permalink
Merge branch 'master' into disksing/storage-tests
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/storage/mod.rs
#	tests/coprocessor/test_select.rs
  • Loading branch information
disksing committed Jul 27, 2016
2 parents 3c6f982 + 2630749 commit c3749e7
Show file tree
Hide file tree
Showing 36 changed files with 677 additions and 523 deletions.
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ENABLE_FEATURES ?= default

DEPS_PATH = $(CURDIR)/tmp
BIN_PATH = $(CURDIR)/bin
GOROOT ?= $(DEPS_PATH)/go

.PHONY: all

Expand Down Expand Up @@ -32,22 +33,25 @@ format:
@cargo fmt -- --write-mode diff | grep "Diff at line" > /dev/null && cargo fmt -- --write-mode overwrite | grep -v "found TODO" || exit 0
@rustfmt --write-mode diff tests/tests.rs benches/benches.rs | grep "Diff at line" > /dev/null && rustfmt --write-mode overwrite tests/tests.rs benches/benches.rs | grep -v "found TODO" || exit 0

check_req:
DEPS_PATH=$(DEPS_PATH) GOROOT=$(GOROOT) ./scripts/check_req.sh

rocksdb:
DEPS_PATH=$(DEPS_PATH) ./scripts/build_rocksdb.sh

$(BIN_PATH)/pd-server:
@DEPS_PATH=$(DEPS_PATH) BIN_PATH=$(BIN_PATH) ./scripts/build_pd.sh
@DEPS_PATH=$(DEPS_PATH) BIN_PATH=$(BIN_PATH) PATH=$(PATH):$(GOROOT)/bin GOROOT=$(GOROOT) ./scripts/build_pd.sh

pd: $(BIN_PATH)/pd-server

$(BIN_PATH)/tidb-server:
@DEPS_PATH=$(DEPS_PATH) BIN_PATH=$(BIN_PATH) ./scripts/build_tidb.sh
@DEPS_PATH=$(DEPS_PATH) BIN_PATH=$(BIN_PATH) PATH=$(PATH):$(GOROOT)/bin GOROOT=$(GOROOT) ./scripts/build_tidb.sh

tidb: $(BIN_PATH)/tidb-server

deps: rocksdb pd tidb

install: deps release
install: check_req deps release
@cp -f ./target/release/tikv-server $(BIN_PATH)

clean_pd:
Expand Down
10 changes: 4 additions & 6 deletions etc/config-template.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ notify-capacity = 40960
# maximum number of messages can be processed in one tick.
messages-per-tick = 4096
# socket send/recv buffer size.
send-buffer-size = 131072
recv-buffer-size = 131072
send-buffer-size = "128KB"
recv-buffer-size = "128KB"

# set store capacity, if no set, use unlimited or disk size later.
# capacity = 0 # 0 is unlimited.
Expand Down Expand Up @@ -59,11 +59,9 @@ region-split-check-diff = "8MB"
# set cluster id, must greater than 0.
cluster-id = 1

[etcd]
# etcd endpoints
[pd]
# pd endpoints
endpoints = ""
# pd root path in etcd
pd-root = "/pd"

# For detailed explanation please refer to https://github.com/facebook/rocksdb/blob/master/include/rocksdb/options.h
[rocksdb]
Expand Down
140 changes: 140 additions & 0 deletions scripts/check_req.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/bin/bash

set -e

echo "Checking requirements..."
mkdir -p ${DEPS_PATH}
cd $DEPS_PATH

export PATH=$PATH:$GOROOT/bin

SUDO=
if which sudo &>/dev/null; then
SUDO=sudo
fi

function get_linux_platform {
if [ -f /etc/redhat-release ]; then
# For CentOS or redhat, we treat all as CentOS.
echo "CentOS"
elif [ -f /etc/lsb-release ]; then
DIST=`cat /etc/lsb-release | grep '^DISTRIB_ID' | awk -F= '{ print $2 }'`
echo "$DIST"
else
echo "Unknown"
fi
}

function install_go {
echo "Intall go ..."
case "$OSTYPE" in
linux*)
if [ ! -d $GOROOT ]; then
curl -L https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz -o golang.tar.gz
tar -C ${DEPS_PATH}/ -xzf golang.tar.gz
fi
# `go get` needs git and hg.
dist=$(get_linux_platform)
case $dist in
Ubuntu)
${SUDO} apt-get install -y mercurial git
;;
CentOS)
${SUDO} yum install -y hg git
;;
*)
echo "unsupported platform $dist, you may install Go manually"
exit 1
;;
esac
;;

darwin*)
brew update
brew install go
brew install git
brew install mercurial
echo 'export GOVERSION=$(brew list go | head -n 1 | cut -d '/' -f 6)' >> ${HOME}/.bashrc
echo 'export GOROOT=$(brew --prefix)/Cellar/go/${GOVERSION}/libexec' >> ${HOME}/.bashrc
echo 'export PATH=$PATH:$GOROOT/bin' >> ${HOME}/.bashrc
;;

*)
echo "unsupported $OSTYPE"
exit 1
;;
esac
}

function install_gpp {
echo "Install g++ ..."
case "$OSTYPE" in
linux*)
dist=$(get_linux_platform)
case $dist in
Ubuntu)
${SUDO} apt-get install -y g++
;;
CentOS)
${SUDO} yum install -y gcc-c++
;;
*)
echo "unsupported platform $dist, you may install g++ manually"
exit 1
;;
esac
;;

darwin*)
# refer to https://github.com/facebook/rocksdb/blob/master/INSTALL.md
xcode-select --install
brew update
brew tap homebrew/versions
brew install gcc48 --use-llvm
;;

*)
echo "unsupported $OSTYPE"
exit 1
;;
esac
}

# Check rust
if which cargo &>/dev/null; then
if ! cargo --version | grep nightly &>/dev/null; then
echo "Please upgrade Rust to nightly."
exit 1
fi
else
echo "Install Rust ..."
${SUDO} curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly
fi

# Check go
if which go &>/dev/null; then
# requires go >= 1.5
GO_VER_1=`go version | awk 'match($0, /([0-9])+(\.[0-9])+/) { ver = substr($0, RSTART, RLENGTH); split(ver, n, "."); print n[1];}'`
GO_VER_2=`go version | awk 'match($0, /([0-9])+(\.[0-9])+/) { ver = substr($0, RSTART, RLENGTH); split(ver, n, "."); print n[2];}'`
if [[ (($GO_VER_1 -eq 1 && $GO_VER_2 -lt 5)) || (($GO_VER_1 -lt 1)) ]]; then
echo "Please upgrade Go to 1.5 or later."
exit 1
fi
else
install_go
fi

# Check g++
if which g++ &>/dev/null; then
# Check g++ version, RocksDB requires >= 4.7
G_VER_1=`g++ -dumpversion | awk '{split($0, n, "."); print n[1];}'`
G_VER_2=`g++ -dumpversion | awk '{split($0, n, "."); print n[2];}'`
if [[ (($G_VER_1 -eq 4 && $G_VER_2 -lt 7)) || (($G_VER_1 -lt 4)) ]]; then
echo "Please upgrade g++ to 4.7 or later."
exit 1
fi
else
install_gpp
fi

echo OK
73 changes: 17 additions & 56 deletions src/bin/tikv-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ use cadence::{StatsdClient, NopMetricSink};
use tikv::storage::{Storage, TEMP_DIR, DEFAULT_CFS};
use tikv::util::{self, logger, panic_hook, rocksdb as rocksdb_util};
use tikv::util::metric::{self, BufferedUdpMetricSink};
use tikv::server::{DEFAULT_LISTENING_ADDR, SendCh, Server, Node, Config, bind, create_event_loop,
create_raft_storage};
use tikv::util::transport::SendCh;
use tikv::server::{DEFAULT_LISTENING_ADDR, Server, Node, Config, bind, create_event_loop,
create_raft_storage, Msg};
use tikv::server::{ServerTransport, ServerRaftStoreRouter, MockRaftStoreRouter};
use tikv::server::{MockStoreAddrResolver, PdStoreAddrResolver};
use tikv::raftstore::store::{self, SnapManager};
Expand Down Expand Up @@ -130,13 +131,13 @@ fn initial_log(matches: &Matches, config: &toml::Value) {
}

fn initial_metric(matches: &Matches, config: &toml::Value, node_id: Option<u64>) {
let host = get_string_value("metric-addr",
let host = get_string_value("",
"metric.addr",
matches,
config,
Some("".to_owned()),
|v| v.as_str().map(|s| s.to_owned()));
let mut prefix = get_string_value("metric-prefix",
let mut prefix = get_string_value("",
"metric.prefix",
matches,
config,
Expand Down Expand Up @@ -306,14 +307,14 @@ fn build_cfg(matches: &Matches, config: &toml::Value, cluster_id: u64, addr: &st
Some(addr.to_owned()),
|v| v.as_str().map(|s| s.to_owned()));
cfg.send_buffer_size =
get_integer_value("send-buffer-size",
get_integer_value("",
"server.send-buffer-size",
matches,
config,
Some(128 * 1024),
|v| v.as_integer()) as usize;
cfg.recv_buffer_size =
get_integer_value("recv-buffer-size",
get_integer_value("",
"server.recv-buffer-size",
matches,
config,
Expand All @@ -335,37 +336,37 @@ fn build_cfg(matches: &Matches, config: &toml::Value, cluster_id: u64, addr: &st
Some(4096),
|v| v.as_integer()) as usize;
cfg.raft_store.region_split_size =
get_integer_value("region-split-size",
get_integer_value("",
"raftstore.region-split-size",
matches,
config,
Some(64 * 1024 * 1024),
|v| v.as_integer()) as u64;
cfg.raft_store.region_max_size =
get_integer_value("region-max-size",
get_integer_value("",
"raftstore.region-max-size",
matches,
config,
Some(80 * 1024 * 1024),
|v| v.as_integer()) as u64;
cfg.raft_store.region_check_size_diff =
get_integer_value("region-split-check-diff",
get_integer_value("",
"raftstore.region-split-check-diff",
matches,
config,
Some(8 * 1024 * 1024),
|v| v.as_integer()) as u64;

cfg.raft_store.pd_heartbeat_tick_interval =
get_integer_value("pd-heartbeat-tick-interval",
get_integer_value("",
"raftstore.pd-heartbeat-tick-interval",
matches,
config,
Some(5000),
|v| v.as_integer()) as u64;

cfg.raft_store.pd_store_heartbeat_tick_interval =
get_integer_value("pd-store-heartbeat-tick-interval",
get_integer_value("",
"raftstore.pd-store-heartbeat-tick-interval",
matches,
config,
Expand Down Expand Up @@ -397,7 +398,7 @@ fn build_cfg(matches: &Matches, config: &toml::Value, cluster_id: u64, addr: &st

fn build_raftkv(matches: &Matches,
config: &toml::Value,
ch: SendCh,
ch: SendCh<Msg>,
pd_client: Arc<RpcClient>,
cfg: &Config)
-> (Storage, Arc<RwLock<ServerRaftStoreRouter>>, u64, SnapManager) {
Expand Down Expand Up @@ -471,20 +472,13 @@ fn run_local_server(listener: TcpListener, config: &Config) {
fn run_raft_server(listener: TcpListener, matches: &Matches, config: &toml::Value, cfg: &Config) {
let mut event_loop = create_event_loop(cfg).unwrap();
let ch = SendCh::new(event_loop.channel());
let etcd_endpoints = get_string_value("etcd",
"etcd.endpoints",
let etcd_endpoints = get_string_value("pd",
"pd.endpoints",
matches,
config,
None,
|v| v.as_str().map(|s| s.to_owned()));
let etcd_pd_root = get_string_value("pd-root",
"etcd.pd-root",
matches,
config,
Some("/pd".to_owned()),
|v| v.as_str().map(|s| s.to_owned()));
let pd_client = Arc::new(new_rpc_client(&etcd_endpoints, &etcd_pd_root, cfg.cluster_id)
.unwrap());
let pd_client = Arc::new(new_rpc_client(&etcd_endpoints, cfg.cluster_id).unwrap());
let resolver = PdStoreAddrResolver::new(pd_client.clone()).unwrap();

let store_path = get_store_path(matches, config);
Expand Down Expand Up @@ -548,44 +542,11 @@ fn main() {
"set which dsn to use, warning: default is rocksdb without persistent",
"dsn: rocksdb, raftkv");
opts.optopt("I", "cluster-id", "set cluster id", "must greater than 0.");
opts.optopt("", "metric-addr", "set statsd server address", "host:port");
opts.optopt("",
"metric-prefix",
"set metric prefix",
"metric prefix: tikv");
opts.optopt("",
"region-split-size",
"set region split size",
"default: 64 MB");
opts.optopt("",
"region-max-size",
"set region max size",
"default: 80 MB");
opts.optopt("",
"region-split-check-diff",
"set region split check diff",
"default: 8 MB");
opts.optopt("",
"etcd",
"etcd endpoints",
"127.0.0.1:2379,127.0.0.1:3379");
opts.optopt("", "pd-root", "pd root path in etcd", "/pd");
opts.optopt("",
"pd-heartbeat-tick-interval",
"set region heartbeat tick interval",
"default 5000 (ms)");
opts.optopt("",
"pd-store-heartbeat-tick-interval",
"set region store heartbeat tick interval",
"default 5000 (ms)");
opts.optopt("",
"send-buffer-size",
"server socket send buffer size",
"default 128 KB");
opts.optopt("",
"recv-buffer-size",
"server socket recv buffer size",
"default 128 KB");
opts.optopt("", "pd", "pd endpoints", "127.0.0.1:2379,127.0.0.1:3379");

let matches = opts.parse(&args[1..]).expect("opts parse failed");
if matches.opt_present("h") {
Expand Down
7 changes: 5 additions & 2 deletions src/pd/etcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,9 @@ impl<H: Transport> Handler<H> for EtcdHandler {
}
}

// Default root path used in pd.
const PD_ROOT_PATH: &'static str = "/pd";

#[derive(Debug)]
pub struct EtcdPdClient {
root_path: String,
Expand All @@ -230,7 +233,7 @@ pub struct EtcdPdClient {
impl EtcdPdClient {
// endpoints is etcd endpoints, format is 127.0.0.1:2379,127.0.0.1:3379.
// pd_root is pd root in etcd, like /pd.
pub fn new(endpoints: &str, pd_root: &str, cluster_id: u64) -> Result<EtcdPdClient> {
pub fn new(endpoints: &str, cluster_id: u64) -> Result<EtcdPdClient> {
// only 1 thread is enough for pd now.
// TODO: detect HTTP or HTTPs with SSL config.
let endpoints: Vec<_> = endpoints.split(',').map(|v| format!("http://{}", v)).collect();
Expand All @@ -242,7 +245,7 @@ impl EtcdPdClient {
.build());

Ok(EtcdPdClient {
root_path: format!("{}/{}", pd_root, cluster_id),
root_path: format!("{}/{}", PD_ROOT_PATH, cluster_id),
endpoints: endpoints,
next_index: 0,
client: Some(client),
Expand Down
Loading

0 comments on commit c3749e7

Please sign in to comment.