Skip to content

Commit

Permalink
Merge branch 'master' of github.com:baidu/tera into show_bug
Browse files Browse the repository at this point in the history
  • Loading branch information
caijieming committed May 8, 2017
2 parents 9360318 + 8bf0c4c commit 4d315ea
Show file tree
Hide file tree
Showing 122 changed files with 2,856 additions and 1,344 deletions.
8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
language: cpp
compiler: gcc
env:
global:
- secure: "EBGwhqHaPbERmOAPA7a1IprZZdFjEZqnuekgkNTBtzmGTaIYuh1BbSNGmVtnj3DuXuqAusiYN6olW2lMax15Fqw3Mwh++vh6DJFQ4wePImCzot7D4fTcopmNS2yoPl0IeyL/sLyQrxjflBfoTzw6DUZAXiU55gGB1faqCAfM5sQ="
- CC=gcc-4.8
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- gcc-4.8
- g++-4.8
- gdb
- apport
coverity_scan:
Expand Down
40 changes: 27 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ include depends.mk
OPT ?= -g2 -Wall -Werror # (B) Debug mode, w/ full line-level debugging symbols
# OPT ?= -O2 -g2 -DNDEBUG # (C) Profiling mode: opt, but w/debugging symbols

CC = cc
CXX = g++
ifndef CXX
CXX = g++
endif
ifndef CC
CC = gcc
endif

INCPATH += -I./src -I./include -I./src/leveldb/include -I./src/leveldb \
-I./src/sdk/java/native-src $(DEPS_INCPATH)
CFLAGS += $(OPT) $(INCPATH) -fPIC -fvisibility=hidden # hide internal symbol of tera
CXXFLAGS += $(CFLAGS)
CXXFLAGS += -std=gnu++11 $(CFLAGS)
LDFLAGS += -rdynamic $(DEPS_LDPATH) $(DEPS_LDFLAGS) -lpthread -lrt -lz -ldl \
-lreadline -lncurses
SO_LDFLAGS += -rdynamic $(DEPS_LDPATH) $(SO_DEPS_LDFLAGS) -lpthread -lrt -lz -ldl \
Expand All @@ -32,7 +36,8 @@ OTHER_SRC := $(wildcard src/zk/*.cc) $(wildcard src/utils/*.cc) $(VERSION_SRC) \
src/tera_flags.cc
COMMON_SRC := $(wildcard src/common/base/*.cc) $(wildcard src/common/net/*.cc) \
$(wildcard src/common/file/*.cc) $(wildcard src/common/file/recordio/*.cc) \
$(wildcard src/common/console/*.cc)
$(wildcard src/common/console/*.cc)
SERVER_WRAPPER_SRC := src/tera_main_wrapper.cc
SERVER_SRC := src/tera_main.cc src/tera_entry.cc
CLIENT_SRC := src/teracli_main.cc
TEST_CLIENT_SRC := src/tera_test_main.cc
Expand All @@ -41,7 +46,7 @@ MONITOR_SRC := src/monitor/teramo_main.cc
MARK_SRC := src/benchmark/mark.cc src/benchmark/mark_main.cc
TEST_SRC := src/utils/test/prop_tree_test.cc src/utils/test/tprinter_test.cc \
src/io/test/tablet_io_test.cc src/io/test/tablet_scanner_test.cc \
src/master/test/master_impl_test.cc src/io/test/load_test.cc
src/master/test/master_impl_test.cc src/io/test/load_test.cc

TEST_OUTPUT := test_output
UNITTEST_OUTPUT := $(TEST_OUTPUT)/unittest
Expand All @@ -54,6 +59,7 @@ PROTO_OBJ := $(PROTO_SRC:.cc=.o)
JNI_TERA_OBJ := $(JNI_TERA_SRC:.cc=.o)
OTHER_OBJ := $(OTHER_SRC:.cc=.o)
COMMON_OBJ := $(COMMON_SRC:.cc=.o)
SERVER_WRAPPER_OBJ := $(SERVER_WRAPPER_SRC:.cc=.o)
SERVER_OBJ := $(SERVER_SRC:.cc=.o)
CLIENT_OBJ := $(CLIENT_SRC:.cc=.o)
TEST_CLIENT_OBJ := $(TEST_CLIENT_SRC:.cc=.o)
Expand All @@ -64,11 +70,12 @@ HTTP_OBJ := $(HTTP_SRC:.cc=.o)
TEST_OBJ := $(TEST_SRC:.cc=.o)
ALL_OBJ := $(MASTER_OBJ) $(TABLETNODE_OBJ) $(IO_OBJ) $(SDK_OBJ) $(PROTO_OBJ) \
$(JNI_TERA_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(SERVER_OBJ) $(CLIENT_OBJ) \
$(TEST_CLIENT_OBJ) $(TERA_C_OBJ) $(MONITOR_OBJ) $(MARK_OBJ) $(TEST_OBJ)
$(TEST_CLIENT_OBJ) $(TERA_C_OBJ) $(MONITOR_OBJ) $(MARK_OBJ) $(TEST_OBJ) \
$(SERVER_WRAPPER_OBJ)
LEVELDB_LIB := src/leveldb/libleveldb.a
LEVELDB_UTIL := src/leveldb/util/histogram.o
LEVELDB_UTIL := src/leveldb/util/histogram.o src/leveldb/port/port_posix.o

PROGRAM = tera_main teracli teramo tera_test
PROGRAM = tera_main tera_master tabletserver teracli teramo tera_test
LIBRARY = libtera.a
SOLIBRARY = libtera.so
TERA_C_SO = libtera_c.so
Expand Down Expand Up @@ -110,8 +117,15 @@ cleanall:
$(MAKE) clean
rm -rf build

tera_main: $(SERVER_OBJ) $(MASTER_OBJ) $(TABLETNODE_OBJ) $(IO_OBJ) $(SDK_OBJ) \
$(PROTO_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(LEVELDB_LIB)
tera_main: src/tera_main_wrapper.o src/version.o src/tera_flags.o
$(CXX) -o $@ $^ $(LDFLAGS)

tera_master: $(SERVER_OBJ) $(MASTER_OBJ) $(IO_OBJ) $(SDK_OBJ) \
$(PROTO_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(LEVELDB_LIB)
$(CXX) -o $@ $^ $(LDFLAGS)

tabletserver: $(SERVER_OBJ) $(TABLETNODE_OBJ) $(IO_OBJ) $(SDK_OBJ) \
$(PROTO_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(LEVELDB_LIB)
$(CXX) -o $@ $^ $(LDFLAGS)

libtera.a: $(SDK_OBJ) $(PROTO_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(LEVELDB_UTIL)
Expand Down Expand Up @@ -142,7 +156,7 @@ libjni_tera.so: $(JNI_TERA_OBJ) $(LIBRARY)
$(CXX) -o $@ $^ $(SO_LDFLAGS)

src/leveldb/libleveldb.a: FORCE
$(MAKE) -C src/leveldb
CC=$(CC) CXX=$(CXX) $(MAKE) -C src/leveldb

tera_bench:

Expand Down Expand Up @@ -174,8 +188,8 @@ tablet_scanner_test: src/io/test/tablet_scanner_test.o src/tabletnode/tabletnode
$(IO_OBJ) $(PROTO_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(LEVELDB_LIB)
$(CXX) -o $@ $^ $(LDFLAGS)

master_impl_test: src/master/test/master_impl_test.o src/tera_entry.o $(MASTER_OBJ) $(TABLETNODE_OBJ) $(IO_OBJ) $(SDK_OBJ) \
$(PROTO_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(LEVELDB_LIB)
master_impl_test: src/master/test/master_impl_test.o src/tera_entry.cc $(MASTER_OBJ) $(IO_OBJ) $(SDK_OBJ) \
$(PROTO_OBJ) $(OTHER_OBJ) $(COMMON_OBJ) $(LEVELDB_LIB)
$(CXX) -o $@ $^ $(LDFLAGS)

$(ALL_OBJ): %.o: %.cc $(PROTO_OUT_H)
Expand Down
4 changes: 2 additions & 2 deletions build.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ MIRROR=$1
BOOST_VERSION=1_58_0
PROTOBUF_VERSION=2.6.1
SNAPPY_VERSION=1.1.3
SOFA_PBRPC_VERSION=1.1.1
SOFA_PBRPC_VERSION=1.1.3
ZOOKEEPER_VERSION=3.4.9
GFLAGS_VERSION=2.1.2
GLOG_VERSION=0.3.3
Expand All @@ -28,7 +28,7 @@ if [ $MIRROR == "china" ]; then
GFLAGS_URL=https://github.com/schuhschuh/gflags/archive/v${GFLAGS_VERSION}.tar.gz
GLOG_URL=https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz
GTEST_URL=https://github.com/google/googletest/archive/release-${GTEST_VERSION}.tar.gz
LIBUNWIND_URL=http://mirrors.163.com/gentoo/distfiles/libunwind-${LIBUNWIND_VERSION}.tar.gz
LIBUNWIND_URL=http://repository.timesys.com/buildsources/l/libunwind/libunwind-${LIBUNWIND_VERSION}/libunwind-${LIBUNWIND_VERSION}.tar.gz
GPERFTOOLS_URL=https://github.com/00k/gperftools/raw/master/gperftools-${GPERFTOOLS_VERSION}.tar.gz
INS_URL=https://github.com/baidu/ins/archive/${INS_VERSION}.tar.gz
NOSE_URL=http://mirrors.163.com/gentoo/distfiles/nose-${NOSE_VERSION}.tar.gz
Expand Down
6 changes: 3 additions & 3 deletions doc/cn/cluster_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ Tera集群搭建
* 在master节点上,执行以下命令
```
cd ${tera_prefix}/bin
nohup ./tera_main --flagfile=../conf/tera.flag --tera_role=master &> ../log/master.stderr &
nohup ./tera_master --flagfile=../conf/tera.flag &> ../log/master.stderr &
```
* 在TabletServer节点上,执行以下命令
```
cd ${tera_prefix}/bin
nohup ./tera_main --flagfile=../conf/tera.flag --tera_role=tabletnode &> ../log/tabletserver.stderr &
nohup ./tabletserver --flagfile=../conf/tera.flag &> ../log/tabletserver.stderr &
```
5. 停止tera
* 用kill命令杀掉tera_main对应的进程即可
* 用kill命令杀掉tera_master和tabletserver对应的进程即可
2 changes: 1 addition & 1 deletion doc/cn/onebox.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

## 准备工作
1. 完成Tera的编译,请参考:https://github.com/baidu/tera/wiki/Build-Manual
2. 将编译生成的tera_main, teracli两个二进制文件放入example/onebox/bin
2. 将编译生成的tera_master, tabletserver, teracli三个二进制文件放入example/onebox/bin
3. 如有需要,通过修改example/onebox/bin/config中的选项配置tabletnode个数
4. 进入example/onebox/bin/目录

Expand Down
2 changes: 1 addition & 1 deletion doc/en/onebox.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Your can run Tera in pseudo-distributed mode which means that Tera runs on a sin
1. git clone https://github.com/baidu/tera.git
1. cd tera
1. ./build.sh
1. cp {tera_main,teracli} example/onebox/bin
1. cp {tera_master,tabletserver,teracli} example/onebox/bin
1. cd example/onebox/bin


Expand Down
11 changes: 7 additions & 4 deletions doc/ubuntu_install_onebox_and_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ ubuntu安装tera(单机和集群)
4). 提示错误:fatal error: readline/history.h:
sudo apt-get install libreadline-dev

5). 提示缺少ncurses包:
5). 提示缺少ncurses包:
sudo apt-get install libncurses5-dev

6). 提示 "cmake: command not found":
sudo apt-get install cmake

3. 等待编译结束 & 单机体验

将编译生成的tera_main和teracli文件copy到example/onebox/bin目录下,进入目录执行:sh launch_tera.sh。然后执行./teracli进终端交互。Have fun!
将编译生成的tera_master,tabletserver和teracli文件copy到example/onebox/bin目录下,进入目录执行:sh launch_tera.sh。然后执行./teracli进终端交互。Have fun!
详见:https://github.com/baidu/tera/blob/master/doc/onebox-cn.md


Expand Down Expand Up @@ -259,10 +262,10 @@ ubuntu安装tera(单机和集群)
> 在zookeeper目录中执行:./bin/zkServer.sh status,找到leader那台机器,即master
> 进入tera_root的bin目录,
在master上执行:
nohup ./tera_main --flagfile=../conf/tera.flag --tera_role=master &> ../log/master.stderr &
nohup ./tera_master --flagfile=../conf/tera.flag &> ../log/master.stderr &
在其他两台slave机器上执行:
nohup ./tera_main --flagfile=../conf/tera.flag --tera_role=tabletnode &> ../log/tabletserver.stderr &
nohup ./tabletserver --flagfile=../conf/tera.flag &> ../log/tabletserver.stderr &
> 在任意一台机器上的tera_root/bin目录中执行:./teracli
Have Fun!
Expand Down
2 changes: 1 addition & 1 deletion example/docker/master
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/jre/lib/amd64/:/home/ubuntu/leiliyuan/hadoop-1.2.1/lib:$(hadoop classpath)
cd /opt/tera/bin

nohup ./tera_main --flagfile=../conf/tera.flag --tera_local_addr $1 --tera_role=master &> ../../share/log/master.stderr &
nohup ./tera_master --flagfile=../conf/tera.flag --tera_local_addr $1 &> ../../share/log/master.stderr &
2 changes: 1 addition & 1 deletion example/docker/tabletnode
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/jre/lib/amd64/:/home/ubuntu/leiliyuan/hadoop-1.2.1/lib:$(hadoop classpath)
cd /opt/tera/bin
nohup ./tera_main --flagfile=../conf/tera.flag --tera_local_addr $1 --tera_role=tabletnode &> ../../share/log/tabletserver.stderr &
nohup ./tabletserver --flagfile=../conf/tera.flag --tera_local_addr $1 &> ../../share/log/tabletserver.stderr &
9 changes: 7 additions & 2 deletions example/onebox/bin/kill_tera.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#!/bin/bash
source ./config

for ((i=0; i<=${TABLETNODE_NUM}; i++)); do
PID=`ps x | grep tera_main | grep $((PORT+i)) | awk '{print $1}'`;
PID=`ps x | grep tera_master | grep $PORT | awk '{print $1}'`;
if [ ${PID}"x" != "x" ]; then
kill -9 $PID;
fi

for ((i=1; i<=${TABLETNODE_NUM}; i++)); do
PID=`ps x | grep tabletserver | grep $((PORT+i)) | awk '{print $1}'`;
if [ ${PID}"x" != "x" ]; then
kill -9 $PID;
fi
Expand Down
6 changes: 2 additions & 4 deletions example/onebox/bin/launch_tera.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ for ((i=1; i<=$TABLETNODE_NUM; i++)); do
if [ ! -x $CACHE_PATH ];then
mkdir -p $CACHE_PATH
fi
${CURRENT_DIR}/tera_main \
${CURRENT_DIR}/tabletserver \
--flagfile=${CURRENT_DIR}/../conf/tera.flag \
--tera_role=tabletnode \
--tera_tabletnode_port=$((PORT+i)) \
--tera_leveldb_log_path=${LEVELDB_LOG_FILE} \
--tera_tabletnode_cache_paths=${CACHE_PATH} \
Expand All @@ -53,9 +52,8 @@ MASTER_LOG_FILE=${CURRENT_DIR}/../log/master.stderr
if [ -f ${MASTER_LOG_FILE} ];then
mv ${MASTER_LOG_FILE} ${MASTER_LOG_FILE}.${TIME}
fi
${CURRENT_DIR}/tera_main \
${CURRENT_DIR}/tera_master \
--flagfile=${CURRENT_DIR}/../conf/tera.flag \
--tera_role=master \
--tera_master_port=${PORT} \
--tera_fake_zk_path_prefix=${FAKE_ZK_PATH_PREFIX} \
--tera_log_prefix=master &> ${MASTER_LOG_FILE} </dev/null &
3 changes: 2 additions & 1 deletion ft_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ if ! $run_without_fetch; then
cp example/onebox/conf/tera.flag $test_dir/conf

cp build/bin/teracli $test_dir/bin
cp build/bin/tera_main $test_dir/bin
cp build/bin/tera_master $test_dir/bin
cp build/bin/tabletserver $test_dir/bin
cp build/bin/tera_test $test_dir/bin
cp build/benchmark/tera_bench $test_dir/bin
cp build/benchmark/tera_mark $test_dir/bin
Expand Down
8 changes: 6 additions & 2 deletions include/tera_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ void tera_table_apply_reader_batch(tera_table_t* table, tera_row_reader_t** read
tera_row_mutation_t* tera_row_mutation(tera_table_t* table, const char* row_key, uint64_t keylen);
void tera_table_apply_mutation(tera_table_t* table, tera_row_mutation_t* mutation);
void tera_table_apply_mutation_batch(tera_table_t* table, tera_row_mutation_t** mutation_batch, int64_t num);
void tera_row_mutation_put_kv(tera_row_mutation_t* mu,
const char* val, uint64_t vallen, int32_t ttl);
void tera_row_mutation_put_kv(tera_row_mutation_t* mu,
const char* val, uint64_t vallen, int32_t ttl);
void tera_row_mutation_put(tera_row_mutation_t* mu, const char* cf,
const char* qu, uint64_t qulen,
const char* val, uint64_t vallen);
void tera_row_mutation_put_with_timestamp(tera_row_mutation_t* mu, const char* cf,
const char* qu, uint64_t qulen,
int64_t timestamp,
const char* val, uint64_t vallen);
void tera_row_mutation_put_int64(tera_row_mutation_t* mu, const char* cf,
const char* qu, uint64_t qulen, int64_t val);
void tera_row_mutation_delete_column(tera_row_mutation_t* mu, const char* cf,
Expand Down
2 changes: 1 addition & 1 deletion readme-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ map<RowKey, map<ColummnFamily:Qualifier, map<Timestamp, Value> > >

#系统架构
系统主要由Tabletserver、Master和ClientSDK三部分构成。其中Tabletserver是核心服务器,承载着所有的数据管理与访问;Master是系统的仲裁者,负责表格的创建、schema更新与负载均衡;ClientSDK包含供管理员使用的命令行工具teracli和给用户使用的SDK。
表格被按RowKey全局排序,并横向切分成多个Tablet,每个Tablet负责服务RowKey的一个区间,表格又被纵向且分为多个LocalityGroup,一个Tablet的多个Localitygroup在物理上单独存储,可以选择不同的存储介质,以优化访问效率。
表格被按RowKey全局排序,并横向切分成多个Tablet,每个Tablet负责服务RowKey的一个区间,表格又被纵向切分为多个LocalityGroup,一个Tablet的多个Localitygroup在物理上单独存储,可以选择不同的存储介质,以优化访问效率。

![架构图](resources/images/arch.png)

Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/mark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void Adapter::Write(const std::string& row,
if (FLAGS_verify) {
add_checksum(row, family, qualifier, &value);
}
row_mu->Put(family, qualifier, timestamp, value);
row_mu->Put(family, qualifier, value, (int64_t)timestamp);
if (FLAGS_verify) {
remove_checksum(&value);
}
Expand Down
2 changes: 2 additions & 0 deletions src/benchmark/mark_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ void print_summary(Statistic* marker, double duration) {

print_opt(marker);
std::streamsize precision = std::cout.precision();
std::ios::fmtflags flag(std::cout.flags());
std::cout.precision(3);
std::cout << " Summary: " << std::fixed << duration << " s\n"
<< " total: " << finish_size << " bytes "
Expand All @@ -434,6 +435,7 @@ void print_summary(Statistic* marker, double duration) {
<< (double)success_size / 1048576 / duration << " MB/s"
<< std::endl;
std::cout.precision(precision);
std::cout.flags(flag);
}

void print_summary_proc(Adapter* adapter, double duration) {
Expand Down
7 changes: 3 additions & 4 deletions src/common/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
#ifndef TERA_COMMON_THREAD_H_
#define TERA_COMMON_THREAD_H_

#include <functional>
#include <pthread.h>

#include <boost/function.hpp>

namespace common {

class Thread {
public:
Thread() : tid_(0) {}
bool Start(boost::function<void()> thread_proc) {
bool Start(std::function<void()> thread_proc) {
user_proc_ = thread_proc;
int ret = pthread_create(&tid_, NULL, ProcWrapper, this);
return (ret == 0);
Expand All @@ -33,7 +32,7 @@ class Thread {
}

private:
boost::function<void()> user_proc_;
std::function<void()> user_proc_;
pthread_t tid_;
};

Expand Down
2 changes: 1 addition & 1 deletion src/common/thread_attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ThreadAttributes {
}

bool SetCpuMask(int32_t cpu_id) {
if (cpu_id < 0 || cpu_id > cpu_num_) {
if (cpu_id < 0 || cpu_id >= cpu_num_) {
return false;
}

Expand Down
8 changes: 5 additions & 3 deletions src/common/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
#define TERA_COMMON_THREAD_POOL_H_

#include <deque>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <boost/function.hpp>

#include "mutex.h"
#include "timer.h"

Expand Down Expand Up @@ -60,7 +61,8 @@ class ThreadPool {
bool Stop(bool wait) {
if (wait) {
while (pending_num_ > 0) {
usleep(10000);
struct timespec ts = {0, 10000000};
nanosleep(&ts, NULL);
}
}

Expand All @@ -77,7 +79,7 @@ class ThreadPool {
}

// Task definition.
typedef boost::function<void (int64_t)> Task;
typedef std::function<void (int64_t)> Task;

// Add a task to the thread pool.
void AddTask(const Task& task) {
Expand Down
Loading

0 comments on commit 4d315ea

Please sign in to comment.