diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000000000000000000000000000000000000..7e3fc038d13704080b41ae6a7b6f95e782354b9b
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,49 @@
+# Build matrix / environment variables are explained on:
+# http://about.travis-ci.org/docs/user/build-configuration/
+# This file can be validated on: http://lint.travis-ci.org/
+
+language: cpp
+sudo: required
+
+compiler:
+- gcc
+- g++
+os:
+- linux
+addons:
+ apt:
+ packages:
+ - g++-4.9
+env:
+- DTC_EVAL="CC=gcc-4.9 && CXX=g++-4.9"
+
+befor_install:
+- eval "${DTC_EVAL}"
+
+install:
+- echo ${CC}
+- ${CC} --version
+- echo ${CXX}
+- ${CXX} --version
+- cmake --version
+- sudo apt-get install snappy libsnappy-dev zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev
+
+script:
+- cd src/
+- mkdir build/
+- cd build/
+- cmake ../
+- make
+
+after_success:
+- cd ../../
+- cp conf/* dockerfiles/server/
+- cp src/core/dtcd dockerfiles/server/
+- cp src/devel/cpp/libdtc.2.so dockerfiles/sdk-cpp/
+- cd dockerfiles/server/
+- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
+- docker build -t $DOCKER_USERNAME/server:latest .
+- docker push $DOCKER_USERNAME/server:latest
+- cd ../sdk-cpp/
+- docker build -t $DOCKER_USERNAME/sdk-cpp:latest .
+- docker push $DOCKER_USERNAME/sdk-cpp:latest
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..4ec79ec0efea5ecf0fb2c9cc97c13936769ec189
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,7 @@
+CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
+PROJECT(dtc)
+
+ADD_SUBDIRECTORY(./src)
+
+#if you want to uninstall libraries, you should enter "build" folder, and use this command
+# cat install_manifest.txt | sudo xargs rm
\ No newline at end of file
diff --git a/README.md b/README.md
index 21f9ce809c588964f378dc7381c3f7435b24c236..e9473565d9db7c4911bccc45e4043215076e4e8e 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,9 @@

# DTC - Distributed Table Cache 分布式表缓存
+[](https://app.travis-ci.com/github/DTC8/DTC)
## 概述
-DTC是一个分布式表级缓存系统。
+DTC是一个分布式表级缓存系统,可为数据库提供热点数据缓存支持,减少数据库的访问压力。
DTC系统由以下组件组成:
* **Agent** - 提供Key路由、命令请求的服务。
@@ -10,30 +11,36 @@ DTC系统由以下组件组成:
* **Connector** - 此组件为缓存与持久化存储数据库(例如:MySql)之间提供连接和数据传输功能。
## 特征
+* 为数据库提供保护机制:
+ - 保护空节点,防止缓存穿透。
+ - 提供永不过期的缓存数据,防止缓存击穿。
+ - 数据源线程柔性可用,保护数据库有限的连接数。
+ - 预估超时机制,减少无效数据库请求。
+* 保障缓存和数据库的数据一致性:
+ - write-through机制,保证缓存和数据库数据一致。
+ - 栅栏机制,防止高并发情景下更新请求丢失。
+ - 支持分库分表。
+* 缓存高性能:
+ - 集成内存分配机制,避免频繁系统调用。
+ - I/O多路复用机制,承接大并发请求量。
+ - 多种数据结构模型,提高内存读写速度。
## 性能
- 单核CPU,单DTC实例情况下,可支持60,000 QPS的查询;
+ 单核CPU,单DTC实例情况下,可支持90,000 QPS的查询;
在真实的分布式场景中,DTC可支持超过3,000,000 QPS的查询服务,且命中率在99.9%以上。
## 构建
-* gcc/g++ 4.8
-* cmake >= 3.6.2
-* 安装gflags:
- gflags是google开源的一套命令行参数解析工具,支持从环境变量和配置文件读取参数
- `git clone https://github.com/gflags/gflags.git`
- `cd gflags`
- `git checkout -b 2.2 v2.2.2`
- `cmake3 -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G "Unix Makefiles" .`
- `make && sudo make install`
- `sudo ldconfig `
- `sudo ln -s /usr/local/lib/libgflags.so.2.2 /lib64`
- ### CentOS
- - 执行以下命令安装依赖:
- `sudo yum install -y snappy snappy-devel zlib zlib-devel bzip2 bzip2-devel lz4-devel libasan openssl-devel cmake3 mysql-devel mxml-devel`
- ### Ubuntu
- - 执行以下命令安装依赖:
- `sudo apt-get install snappy libsnappy-dev zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev`
-* src目录下,执行make即可编译。
+ 项目提供docker镜像,可快速启动和运行示例:
+ - 启动server镜像:
+ `docker pull dtc/server:latest`
+ `docker run -i -t -p 127.0.0.1:20015:20015 dtc/server:latest /bin/bash`
+ - 启动SDK镜像:
+ - C++:
+ `docker pull dtc/sdk-cpp:latest`
+ `docker run -i -t dtc/sdk-cpp:latest /bin/bash`
+ - 后续计划SDK支持更多语言版本。
+
+ 更多编译详情,请移步[buiding](docs/buiding.md).
## 第三方依赖
* [cJson](https://github.com/DaveGamble/cJSON)
@@ -45,6 +52,16 @@ DTC系统由以下组件组成:
* [mxml](https://www.msweet.org/mxml/)
* [twemproxy](https://github.com/twitter/twemproxy)
+## 项目成员
+- 付学宝(项目发起者、导师、总设计师)
+- [林金明](https://gitee.com/shrewdlin)(项目开发)
+- [杨爽](https://gitee.com/kfysck)(项目开发)
+- [仇路](https://gitee.com/qiuluAbel)(项目开发)
+- [吴昕臻](https://gitee.com/wuxinzhen_1997)(项目开发)
+- [曹沛](https://gitee.com/warm-byte)(项目开发)
+- [陈雨杰](https://gitee.com/chenyujie28)(项目开发)
+- [朱林](https://gitee.com/leol3)(项目开发)
+
## 许可证
京东集团 版权所有 © Copyright 2021 [JD.com](https://www.jd.com), Inc.
diff --git a/conf/cache.yaml b/conf/cache.yaml
new file mode 100755
index 0000000000000000000000000000000000000000..5deaca60e46f46861b88a1f16d26b2961030da95
--- /dev/null
+++ b/conf/cache.yaml
@@ -0,0 +1,27 @@
+cache:
+ LogLevel: debug
+ BindAddr: '*:20015/tcp'
+ IdleTimeout: 30
+ HelperTimeout: 30
+ CacheShmKey: 20015
+ CacheMemorySize: 100
+ CacheAverageDataSize: 50
+ MaxFlushSpeed: 1
+ MinDirtyNode: 40
+ MaxDirtyNode: 60
+ MinDirtyTime: 3600
+ MaxDirtyTime: 43200
+ DelayUpdate: 0
+ DisableDataSource: 1
+ OpenningFDAttrID: 41784
+ EnableCoreDump: 1
+ RemoteLogAddr: 172.28.133.131
+ RemoteLogPort: 9876
+ UseSingleThread: 1
+ DisableLRUUpdate: 2
+ MaxIncomingPollers@inc0: 10000
+ MaxFdCount: 10240
+ MaxBarrierCount: 100000
+ # DisableWatchDog: 1
+ MaxKeyCount: 10000
+ FaultLoggerMode: disable
diff --git a/conf/log4cplus.conf b/conf/log4cplus.conf
new file mode 100644
index 0000000000000000000000000000000000000000..ad10cd18b17bbdb5f1e11921935baa4560889091
--- /dev/null
+++ b/conf/log4cplus.conf
@@ -0,0 +1,17 @@
+log4cplus.rootLogger=TRACE, STDOUT, apdPlatform
+
+log4cplus.appender.STDOUT=log4cplus::ConsoleAppender
+log4cplus.appender.STDOUT.Encoding=utf-8
+log4cplus.appender.STDOUT.layout=log4cplus::PatternLayout
+log4cplus.appender.STDOUT.layout.ConversionPattern=[%T] %D{%Y-%m-%d %H:%M:%S} %-5p - %m %n
+
+## synchronous log properties.
+log4cplus.appender.apdPlatform=log4cplus::TimeBasedRollingFileAppender
+log4cplus.appender.apdPlatform.FilenamePattern==/var/log/dtc/%d{yyyy-MM-dd}.log
+log4cplus.appender.apdPlatform.Append=true
+log4cplus.appender.apdPlatform.MaxHistory=999
+log4cplus.appender.apdPlatform.ImmediateFlush=false
+log4cplus.appender.apdPlatform.RollOnClose=false
+log4cplus.appender.apdPlatform.CreateDirs=true
+log4cplus.appender.apdPlatform.layout=log4cplus::PatternLayout
+log4cplus.appender.apdPlatform.layout.ConversionPattern=[%T] %D{%Y-%m-%d %H:%M:%S} %-5p - -%m %n
\ No newline at end of file
diff --git a/conf/table.yaml b/conf/table.yaml
new file mode 100755
index 0000000000000000000000000000000000000000..38be91fb0ed50f5f5ccc1ec5c3366e31b9a5fdf6
--- /dev/null
+++ b/conf/table.yaml
@@ -0,0 +1,55 @@
+DB_DEFINE:
+ DbName: dtc_opensource
+ DbNum: (1,1)
+ dbMax: 1
+ MachineNum: 1
+ Deploy: 0
+ EnableKeyHash: 0
+ KeyHashSo: ../lib/key-hash.so
+ KeyHashFunction: StringHash(1,128)
+
+MACHINE1:
+ Procs: 10
+ WriteProcs: 10
+ CommitProcs: 10
+ DbIdx: 0
+ DbAddr: 127.0.0.1:3306
+ DbUser: username
+ DbPass: password
+
+TABLE_DEFINE:
+ TableName: Table_Test
+ FieldCount: 5
+ eyFieldCount: 1
+ TableNum: (1,100)
+
+# None=0, Signed=1, Unsigned=2, Float=3, String=4, Binary=5
+FIELD1:
+ FieldName: uid
+ FieldType: 1
+ FieldSize: 4
+ UniqField: 0
+
+FIELD2:
+ FieldName: name
+ FieldType: 5
+ FieldSize: 50
+ UniqField: 0
+
+FIELD3:
+ FieldName: city
+ FieldType: 4
+ FieldSize: 50
+ UniqField: 0
+
+FIELD4:
+ FieldName: sex
+ FieldType: 1
+ FieldSize: 4
+ UniqField: 0
+
+FIELD5:
+ FieldName: age
+ FieldType: 1
+ FieldSize: 4
+ UniqField: 0
diff --git a/dockerfiles/sdk-cpp/dockerfile b/dockerfiles/sdk-cpp/dockerfile
new file mode 100644
index 0000000000000000000000000000000000000000..a9b0d6a06c220fb66141990a701c8d2e5644572a
--- /dev/null
+++ b/dockerfiles/sdk-cpp/dockerfile
@@ -0,0 +1,18 @@
+FROM centos:centos8
+
+COPY start.sh /root/start.sh
+
+ARG sofile=libdtc.2.so
+COPY $sofile /usr/lib/$sofile
+RUN ln -sf /usr/lib/$sofile /usr/lib/libdtc.so.1 && \
+ ln -sf /usr/lib/libdtc.so.1 /usr/lib/libdtc.so && \
+ echo "/usr/lib" >> /etc/ld.so.conf && \
+ /sbin/ldconfig -v
+
+#cpp test
+RUN mkdir -p /usr/local/sdk-cpp
+COPY ../../tests/get.cc /usr/local/sdk-cpp/get.cc
+COPY ../../tests/insert.cc /usr/local/sdk-cpp/insert.cc
+COPY ../../tests/build.sh /usr/local/sdk-cpp/build.sh
+
+CMD ["/bin/bash", "/root/start.sh"]
\ No newline at end of file
diff --git a/dockerfiles/sdk-cpp/start.sh b/dockerfiles/sdk-cpp/start.sh
new file mode 100644
index 0000000000000000000000000000000000000000..cfc4bed64f0524faaa39aea8f65d3ef770b3025f
--- /dev/null
+++ b/dockerfiles/sdk-cpp/start.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+INIT(){
+ cd /usr/local/sdk-cpp/
+ chmod +x build.sh
+ echo "=============BUILD==================="
+ ./build.sh
+ echo "=============INSERT=================="
+ ./insert
+ echo "=============GET====================="
+ ./get
+ echo "=============END====================="
+}
+
+PROCESS_DAEMON(){
+ while :
+ do
+ sleep 60
+ done
+}
+
+INIT
+#PROCESS_DAEMON
\ No newline at end of file
diff --git a/dockerfiles/server/dockerfile b/dockerfiles/server/dockerfile
new file mode 100644
index 0000000000000000000000000000000000000000..317d177a7deb62348e7b8eab513763086027a522
--- /dev/null
+++ b/dockerfiles/server/dockerfile
@@ -0,0 +1,19 @@
+FROM centos:centos8
+
+ARG basepath=/usr/local/dtc
+ARG confpath=/etc/dtc
+ARG logpath=/var/log/dtc
+
+RUN mkdir -p $basepath/bin
+RUN mkdir -p $basepath/data
+RUN mkdir -p $basepath/stat
+RUN mkdir -p $confpath
+RUN mkdir -p $logpath
+
+COPY start.sh /root/start.sh
+COPY dtcd $basepath/bin/dtcd
+COPY table.yaml $confpath/table.yaml
+COPY cache.yaml $confpath/cache.yaml
+COPY log4cplus.conf $confpath/log4cplus.conf
+
+CMD ["/usr/local/dtc/bin/dtcd", "-d"]
\ No newline at end of file
diff --git a/docs/buiding.md b/docs/buiding.md
new file mode 100644
index 0000000000000000000000000000000000000000..f4ba6e7d5996b52ec1f3f59e0c6f8824f4e46cc9
--- /dev/null
+++ b/docs/buiding.md
@@ -0,0 +1,18 @@
+* gcc/g++ 4.8
+* cmake >= 3.6.2
+* 安装gflags:
+ gflags是google开源的一套命令行参数解析工具,支持从环境变量和配置文件读取参数
+ `git clone https://github.com/gflags/gflags.git`
+ `cd gflags`
+ `git checkout -b 2.2 v2.2.2`
+ `cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G "Unix Makefiles" .`
+ `make && sudo make install`
+ `sudo ldconfig `
+ `sudo ln -s /usr/local/lib/libgflags.so.2.2 /lib64`
+ ### CentOS
+ - 执行以下命令安装依赖:
+ `sudo yum install -y make snappy snappy-devel zlib zlib-devel bzip2 bzip2-devel lz4-devel libasan openssl-devel cmake3 mysql-devel mxml-devel`
+ ### Ubuntu
+ - 执行以下命令安装依赖:
+ `sudo apt-get install make snappy libsnappy-dev zlib1g zlib1g-dev bzip2 liblz4-dev libasan0 openssl libmxml-dev`
+* src目录下,执行make即可编译。
\ No newline at end of file
diff --git a/script/dtcd.sh b/script/dtcd.sh
new file mode 100644
index 0000000000000000000000000000000000000000..e97d4a09b7e1799ccea42315d9561590c7a73fdb
--- /dev/null
+++ b/script/dtcd.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+ulimit -c unlimited
+
+DTC_BIN="dtcd_docker"
+rm -f "$DTC_BIN"
+ln -s dtcd "$DTC_BIN"
+
+if [ "$1" = "stop" ] ; then
+ killall -9 $DTC_BIN
+elif [ "$1" = "restart" ]; then
+ killall -9 $DTC_BIN
+ sleep 2
+ ./$DTC_BIN >> /dev/null 2>&1
+elif [ "$1" = "start" ]; then
+ ./$DTC_BIN >> /dev/null 2>&1
+ sleep 1
+else
+ echo "usage: $0 stop | start |restart"
+fi
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..e078a0bd007124dabb7815a520e938634accfb5d
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,7 @@
+ADD_SUBDIRECTORY(./agent)
+ADD_SUBDIRECTORY(./configcenter)
+ADD_SUBDIRECTORY(./libs)
+ADD_SUBDIRECTORY(./devel)
+ADD_SUBDIRECTORY(./daemons)
+ADD_SUBDIRECTORY(./core)
+#ADD_SUBDIRECTORY(./connector)
diff --git a/src/agent/CMakeLists.txt b/src/agent/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..3b26ecabf4e8eebc6cac317b2f3a6927c5e202a3
--- /dev/null
+++ b/src/agent/CMakeLists.txt
@@ -0,0 +1,45 @@
+#设置库文件输出路径
+SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/agent)
+
+IF("${GPROF}" EQUAL 1)
+ ADD_COMPILE_OPTIONS(-pg)
+ENDIF()
+IF("${USE_REGPARM}" EQUAL 1)
+ ADD_COMPILE_OPTIONS(-DCONFIG_REGPARM=3)
+ENDIF()
+IF("${HAVE_STATS}" EQUAL 1)
+ ADD_COMPILE_OPTIONS(-DHAVE_STATS=1)
+ENDIF()
+IF("${USE_COMPATIBLE_MODE}" EQUAL 1)
+ ADD_COMPILE_OPTIONS(-DUSE_COMPATIBLE_MODE=1)
+ENDIF()
+IF("${HAVE_ASSERT_LOG}" EQUAL 1)
+ ADD_COMPILE_OPTIONS(-DHAVE_ASSERT_LOG=1)
+ENDIF()
+
+#把当前目录下的源文件列表存放到变量SRC_LIST1里
+FILE(GLOB SRC_LIST1 ./*.c)
+FILE(GLOB SRC_LIST2 ./common/*.c)
+FILE(GLOB SRC_LIST3 ./event/*.c)
+FILE(GLOB SRC_LIST4 ./hashkit/*.c)
+FILE(GLOB SRC_LIST5 ./proto/*.c)
+
+#添加头文件搜索路径,相当于gcc -I
+INCLUDE_DIRECTORIES(
+ .
+ ./common
+ ./event
+ ./hashkit
+ ./proto)
+
+#链接目标库
+LINK_LIBRARIES(rt)
+LINK_LIBRARIES(mxml)
+LINK_LIBRARIES(pthread)
+
+#编译参数
+ADD_DEFINITIONS ("-D_GNU_SOURCE")
+
+#编译为.so/.a
+ADD_EXECUTABLE(dtcagent ${SRC_LIST1} ${SRC_LIST2} ${SRC_LIST3} ${SRC_LIST4} ${SRC_LIST5})
+
diff --git a/src/agent/da_log.c b/src/agent/da_log.c
index 76936b33ca5991f898ce73239653e26f941f22de..ed70a503a7570d5f374aeb91241665e57d42d3cd 100644
--- a/src/agent/da_log.c
+++ b/src/agent/da_log.c
@@ -24,7 +24,7 @@
#define MSGSIZE 4096
#define REMOTELOG_ERR_TYPE 14
#define AGENT_CLIENT_TYPE 1
-
+#define O_LARGEFILE __O_LARGEFILE
int __log_level__ = 6;
int __log_switch__ = 1;
int __business_id__ = 0;
diff --git a/src/agent/da_msg.c b/src/agent/da_msg.c
index c86f78925764750dac3d81c753276bb5f67894a7..2d1256a8a7320a225832890a6acb699d1fae080a 100644
--- a/src/agent/da_msg.c
+++ b/src/agent/da_msg.c
@@ -27,6 +27,10 @@
#include "da_conn.h"
#include "da_stats.h"
+
+#define __IOV_MAX 1024
+# define IOV_MAX __IOV_MAX
+
#if (IOV_MAX > 128)
#define NC_IOV_MAX 128
#else
diff --git a/src/configcenter/CMakeLists.txt b/src/configcenter/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..11a33363326a07176628371a9c27e8601e7e2a0b
--- /dev/null
+++ b/src/configcenter/CMakeLists.txt
@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(./ca_api)
\ No newline at end of file
diff --git a/src/configcenter/ca_api/CMakeLists.txt b/src/configcenter/ca_api/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..cc7d6cb5782a3c7e8f346f81b45e82d86b8ddec1
--- /dev/null
+++ b/src/configcenter/ca_api/CMakeLists.txt
@@ -0,0 +1,15 @@
+SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/configcenter/ca_api)
+#添加头文件搜索路径,相当于gcc -I
+INCLUDE_DIRECTORIES(.)
+
+#把当前目录下的源文件列表存放到变量SRC_LIST1里
+AUX_SOURCE_DIRECTORY(. SRC_LIST1)
+
+#编译参数
+ADD_DEFINITIONS("-g -Wall -fPIC")
+
+#编译为.so/.a
+ADD_EXECUTABLE(client-tool ${SRC_LIST1})
+ADD_LIBRARY(app-client ${SRC_LIST1})
+
+
diff --git a/src/connector/CMakeLists.txt b/src/connector/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..b7d6a129802a21776fcb58565b787cb8779ea865
--- /dev/null
+++ b/src/connector/CMakeLists.txt
@@ -0,0 +1,63 @@
+#设置库文件输出路径
+SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/connector)
+
+IF(CMAKE_COMPILER_IS_GNUCXX)
+ ADD_COMPILE_OPTIONS(-std=gnu++11)
+ENDIF(CMAKE_COMPILER_IS_GNUCXX)
+
+#把当前目录下的源文件列表存放到变量SRC_LIST里
+FILE(GLOB_RECURSE SRC_LIST ./*.cc)
+
+#添加头文件搜索路径,相当于gcc -I
+INCLUDE_DIRECTORIES (
+ .
+ ../daemons
+ ../libs/stat
+ ../libs/common
+ ../libs/common/log
+ ../libs/common/config
+ ../libs/common/daemon
+ ../libs/common/socket
+ ../libs/common/listener
+ ../libs/common/task
+ ../core
+ ../libs/rocksdb/include
+ ../libs/rocksdb/logging
+ ../libs/log4cplus/include/
+ ../libs/zlib/include64
+ ../libs/yaml-cpp/include/)
+
+#添加.so/.a文件搜索路径,相当于gcc -L
+LINK_DIRECTORIES (
+ ${PROJECT_SOURCE_DIR}/libs/rocksdb/lib
+ ${PROJECT_SOURCE_DIR}/libs/common
+ ${PROJECT_SOURCE_DIR}/core
+ ${PROJECT_SOURCE_DIR}/libs/zlib/lib/libz64.a
+ ${PROJECT_SOURCE_DIR}/libs/log4cplus/libs
+ ${PROJECT_SOURCE_DIR}/libs/yaml-cpp/libs
+ ${PROJECT_SOURCE_DIR}/daemons
+ ${PROJECT_SOURCE_DIR}/libs/stat
+)
+
+#添加链接库,相当于gcc -l
+LINK_LIBRARIES(liblog4cplus.a)
+LINK_LIBRARIES(libyaml-cpp.a)
+LINK_LIBRARIES(libz64.a)
+LINK_LIBRARIES(pthread)
+LINK_LIBRARIES(nsl)
+LINK_LIBRARIES(stdc++)
+LINK_LIBRARIES(dl)
+LINK_LIBRARIES(z)
+LINK_LIBRARIES(rocksdb)
+LINK_LIBRARIES(libdtcd.a)
+LINK_LIBRARIES(libcommon.a)
+LINK_LIBRARIES(libdaemons.a)
+LINK_LIBRARIES(libstat.a)
+
+#编译参数
+ADD_DEFINITIONS ("-g -fPIC -fpermissive -DROCKSDB_COMPILER=1 -DOMN_PLATFORM_UNIX -Wl,--no-undefined -Xlinker -zmuldefs")
+#编译为.so/.a
+ADD_LIBRARY (rocksdb_connector ${SRC_LIST})
+
+#将目标文件与库文件链接
+TARGET_LINK_LIBRARIES(rocksdb_connector liblog4cplus.a libyaml-cpp.a libz64.a lbdtcd.a libcommon.a libdaemons.a libstat.a)
\ No newline at end of file
diff --git a/src/connector/comm_main.cc b/src/connector/comm_main.cc
index a3b3c1060c87596a8aae29d737fd1f4930ec3f75..d754d65d32b28d405e03019f065111fd2e2d5bc7 100644
--- a/src/connector/comm_main.cc
+++ b/src/connector/comm_main.cc
@@ -38,6 +38,7 @@
#include
#include
#include
+#include
const char service_file[] = "./helper-service.so";
const char create_handle_name[] = "create_process";
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..2da6c9f44f4e7b0e546a3171d09c92559cc016d0
--- /dev/null
+++ b/src/core/CMakeLists.txt
@@ -0,0 +1,65 @@
+#设置库文件输出路径
+SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/core)
+#设置可执行文件输出路径
+SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/core)
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ add_compile_options(-std=gnu++11)
+endif(CMAKE_COMPILER_IS_GNUCXX)
+
+
+#把当前目录下的源文件列表存放到变量SRC_LIST里
+FILE(GLOB_RECURSE SRC_LIST ./*.cc ./*.c)
+
+#添加头文件搜索路径,相当于gcc -I
+INCLUDE_DIRECTORIES(
+ . ./algorithm ./buffer ./chain
+ ./data ./hotbk ./log ./mem
+ ./misc ./node ./nodegroup ./raw
+ ./task ./time ./tree
+ ../libs/common
+ ../devel/cpp
+ ../daemons
+ ../libs/stat
+ ../connector
+ ../libs/log4cplus/include
+ ../libs/zlib/include64
+ ../libs/yaml-cpp/include)
+
+#添加.so/.a文件搜索路径,相当于gcc -L
+LINK_DIRECTORIES(
+ ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/libs
+ ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/libs
+ ${PROJECT_SOURCE_DIR}/src/libs/zlib/lib/
+ ${PROJECT_SOURCE_DIR}/src/libs/common
+ ${PROJECT_SOURCE_DIR}/src/libs/stat
+ ${PROJECT_SOURCE_DIR}/src/daemons)
+
+#添加链接库,相当于gcc -l
+LINK_LIBRARIES(liblog4cplus.a)
+LINK_LIBRARIES(libcommon.a)
+LINK_LIBRARIES(libyaml-cpp.a)
+LINK_LIBRARIES(libstat.a)
+LINK_LIBRARIES(libdaemons.a)
+LINK_LIBRARIES(libz64.a)
+LINK_LIBRARIES(pthread)
+LINK_LIBRARIES(dl)
+
+#编译参数
+ADD_DEFINITIONS(" -g -rdynamic -fPIC -fpermissive -D_GLIBCXX_USE_CXX11_ABI=0 -export-dynamic -Wl,--version-script,dtcd.export.lst")
+
+#编译为.so/.a
+ADD_EXECUTABLE(dtcd ${SRC_LIST})
+ADD_LIBRARY(dtcd_static ${SRC_LIST})
+
+#将目标文件与库文件链接
+TARGET_LINK_LIBRARIES(dtcd libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a)
+TARGET_LINK_LIBRARIES(dtcd_static libdaemons.a libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a libz64.a)
+
+SET_TARGET_PROPERTIES (dtcd_static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
+SET_TARGET_PROPERTIES (dtcd PROPERTIES CLEAN_DIRECT_OUTPUT 1)
+SET_TARGET_PROPERTIES(dtcd_static PROPERTIES OUTPUT_NAME "dtcd")
+
+#设置make install 安装路径
+INSTALL(TARGETS dtcd RUNTIME DESTINATION /usr/local/dtc/bin)
+
diff --git a/src/core/buffer/buffer_reader.cc b/src/core/buffer/buffer_reader.cc
deleted file mode 100644
index d262432a443e931c776760fa38eeb1712c0ebbf0..0000000000000000000000000000000000000000
--- a/src/core/buffer/buffer_reader.cc
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
-* Copyright [2021] JD.com, Inc.
-*
-* 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.
-*/
-
-#include
-#include
-#include
-
-#include "task/task_pkey.h"
-#include "buffer_reader.h"
-#include "log/log.h"
-#include "sys_malloc.h"
-
-BufferReader::BufferReader(void) : BufferPond(NULL)
-{
- pstItem = NULL;
- pstDataProcess = NULL;
- iInDirtyLRU = 1;
- notFetch = 1;
-}
-
-BufferReader::~BufferReader(void)
-{
- if (pstItem != NULL)
- delete pstItem;
- pstItem = NULL;
-}
-
-int BufferReader::cache_open(int shmKey, int keySize,
- DTCTableDefinition *p_table_definition_)
-{
- int iRet;
-
- BlockProperties stInfo;
- memset(&stInfo, 0, sizeof(stInfo));
- stInfo.ipcMemKey = shmKey;
- stInfo.keySize = keySize;
- stInfo.readOnly = 1;
-
- iRet = BufferPond::cache_open(&stInfo);
- if (iRet != E_OK)
- return -1;
-
- pstItem = new RawData(&g_stSysMalloc, 1);
- if (pstItem == NULL) {
- snprintf(error_message, sizeof(error_message),
- "new RawData error: %m");
- return -1;
- }
-
- UpdateMode stUpdateMod;
- stUpdateMod.m_iAsyncServer = MODE_SYNC;
- stUpdateMod.m_iUpdateMode = MODE_SYNC;
- stUpdateMod.m_iInsertMode = MODE_SYNC;
- stUpdateMod.m_uchInsertOrder = 0;
-
- if (p_table_definition_->index_fields() > 0) {
-#if HAS_TREE_DATA
- pstDataProcess = new TreeDataProcess(PtMalloc::instance(),
- p_table_definition_, this,
- &stUpdateMod);
-#else
- log4cplus_error("tree index not supported, index field num[%d]",
- p_table_definition_->index_fields());
- return -1;
-#endif
- } else
- pstDataProcess = new RawDataProcess(PtMalloc::instance(),
- p_table_definition_, this,
- &stUpdateMod);
- if (pstDataProcess == NULL) {
- log4cplus_error("create %s error: %m",
- p_table_definition_->index_fields() > 0 ?
- "TreeDataProcess" :
- "RawDataProcess");
- return -1;
- }
-
- return 0;
-}
-
-int BufferReader::begin_read()
-{
- stDirtyHead = dirty_lru_head();
- stClrHead = clean_lru_head();
- if (!dirty_lru_empty()) {
- iInDirtyLRU = 1;
- stCurNode = stDirtyHead;
- } else {
- iInDirtyLRU = 0;
- stCurNode = stClrHead;
- }
- return 0;
-}
-
-int BufferReader::fetch_node()
-{
- pstItem->destory();
- if (!stCurNode) {
- snprintf(error_message, sizeof(error_message),
- "begin read first!");
- return -1;
- }
- if (end()) {
- snprintf(error_message, sizeof(error_message),
- "reach end of cache");
- return -2;
- }
- notFetch = 0;
-
- curRowIdx = 0;
- if (iInDirtyLRU) {
- while (stCurNode != stDirtyHead && is_time_marker(stCurNode))
- stCurNode = stCurNode.Next();
- if (stCurNode != stDirtyHead && !is_time_marker(stCurNode)) {
- if (pstDataProcess->get_node_all_rows_count(
- &stCurNode, pstItem) != 0) {
- snprintf(error_message, sizeof(error_message),
- "get node's data error");
- return -3;
- }
- return (0);
- }
-
- iInDirtyLRU = 0;
- stCurNode = stClrHead.Next();
- }
-
- stCurNode = stCurNode.Next();
- if (stCurNode != stClrHead) {
- if (pstDataProcess->get_node_all_rows_count(&stCurNode,
- pstItem) != 0) {
- snprintf(error_message, sizeof(error_message),
- "get node's data error");
- return -3;
- }
- } else {
- snprintf(error_message, sizeof(error_message),
- "reach end of cache");
- return -2;
- }
-
- return (0);
-}
-
-int BufferReader::num_rows()
-{
- if (pstItem == NULL)
- return (-1);
-
- return pstItem->total_rows();
-}
-
-int BufferReader::read_row(RowValue &row)
-{
- while (notFetch || curRowIdx >= (int)pstItem->total_rows()) {
- if (fetch_node() != 0)
- return -1;
- }
-
- TaskPackedKey::unpack_key(row.table_definition(), pstItem->key(),
- row.field_value(0));
-
- if (pstItem->decode_row(row, uchRowFlags, 0) != 0)
- return -2;
-
- curRowIdx++;
-
- return 0;
-}
diff --git a/src/core/buffer/buffer_reader.h b/src/core/buffer/buffer_reader.h
deleted file mode 100644
index 90979835b662d3aed996473ef772c04028cb6d44..0000000000000000000000000000000000000000
--- a/src/core/buffer/buffer_reader.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
-* Copyright [2021] JD.com, Inc.
-*
-* 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.
-*/
-
-#ifndef __CACHE_READER_H
-#define __CACHE_READER_H
-
-#include "reader_interface.h"
-#include "buffer_pond.h"
-#include "table/table_def.h"
-#include "raw_data_process.h"
-
-class BufferReader : public ReaderInterface, public BufferPond {
- private:
- Node stClrHead;
- Node stDirtyHead;
- int iInDirtyLRU;
- Node stCurNode;
- unsigned char uchRowFlags;
- RawData *pstItem;
- DataProcess *pstDataProcess;
- int notFetch;
- int curRowIdx;
- char error_message[200];
-
- public:
- BufferReader(void);
- ~BufferReader(void);
-
- int cache_open(int shmKey, int keySize,
- DTCTableDefinition *p_table_definition_);
-
- const char *err_msg()
- {
- return error_message;
- }
- int begin_read();
- int read_row(RowValue &row);
- int end();
- int key_flags(void) const
- {
- return stCurNode.is_dirty();
- }
- int key_flag_dirty(void) const
- {
- return stCurNode.is_dirty();
- }
- int row_flags(void) const
- {
- return uchRowFlags;
- }
- int row_flag_dirty(void) const
- {
- return uchRowFlags & OPER_DIRTY;
- }
- int fetch_node();
- int num_rows();
-};
-
-inline int BufferReader::end()
-{
- return (iInDirtyLRU == 0) && (notFetch == 0) &&
- (stCurNode == stClrHead);
-}
-
-#endif
diff --git a/src/core/buffer/buffer_writer.cc b/src/core/buffer/buffer_writer.cc
deleted file mode 100644
index ec7dc857e6e8ccdf553f107c4b5c37f04ca7b119..0000000000000000000000000000000000000000
--- a/src/core/buffer/buffer_writer.cc
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
-* Copyright [2021] JD.com, Inc.
-*
-* 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.
-*/
-
-#include
-#include
-#include
-
-#include "task/task_pkey.h"
-#include "buffer_writer.h"
-#include "pt_malloc.h"
-#include "sys_malloc.h"
-#include "log/log.h"
-
-BufferWriter::BufferWriter(void) : BufferPond(NULL)
-{
- pstItem = NULL;
- iRowIdx = 0;
- iIsFull = 0;
- memset(achPackKey, 0, sizeof(achPackKey));
-}
-
-BufferWriter::~BufferWriter(void)
-{
- if (pstItem != NULL)
- delete pstItem;
- pstItem = NULL;
-}
-
-int BufferWriter::cache_open(BlockProperties *pstInfo,
- DTCTableDefinition *p_table_definition_)
-{
- int iRet;
-
- iRet = BufferPond::cache_open(pstInfo);
- if (iRet != E_OK) {
- log4cplus_error("cache open error: %d, %s", iRet, Error());
- return -1;
- }
-
- pstItem = new RawData(&g_stSysMalloc, 1);
- if (pstItem == NULL) {
- snprintf(szErrMsg, sizeof(szErrMsg), "new RawData error: %m");
- return -2;
- }
-
- UpdateMode stUpdateMod;
- stUpdateMod.m_iAsyncServer =
- pstInfo->syncUpdate ? MODE_SYNC : MODE_ASYNC;
- stUpdateMod.m_iUpdateMode =
- pstInfo->syncUpdate ? MODE_SYNC : MODE_ASYNC;
- stUpdateMod.m_iInsertMode =
- pstInfo->syncUpdate ? MODE_SYNC : MODE_ASYNC;
- stUpdateMod.m_uchInsertOrder = 0;
-
- if (p_table_definition_->index_fields() > 0) {
-#if HAS_TREE_DATA
- pstDataProcess = new TreeDataProcess(PtMalloc::instance(),
- p_table_definition_, this,
- &stUpdateMod);
-#else
- log4cplus_error("tree index not supported, index field num[%d]",
- p_table_definition_->index_fields());
- return -1;
-#endif
- } else
- pstDataProcess = new RawDataProcess(PtMalloc::instance(),
- p_table_definition_, this,
- &stUpdateMod);
- if (pstDataProcess == NULL) {
- log4cplus_error("create %s error: %m",
- p_table_definition_->index_fields() > 0 ?
- "TreeDataProcess" :
- "RawDataProcess");
- return -3;
- }
-
- return 0;
-}
-
-int BufferWriter::begin_write()
-{
- iRowIdx = 0;
-
- return 0;
-}
-
-int BufferWriter::full()
-{
- return (iIsFull);
-}
-
-int BufferWriter::AllocNode(const RowValue &row)
-{
- int iRet;
-
- iRet = TaskPackedKey::build_packed_key(row.table_definition(),
- row.field_value(0),
- sizeof(achPackKey), achPackKey);
- if (iRet != 0) {
- snprintf(szErrMsg, sizeof(szErrMsg),
- "build packed key error: %d", iRet);
- return -1;
- }
-
- stCurNode = cache_allocation(achPackKey);
- if (!stCurNode) {
- snprintf(szErrMsg, sizeof(szErrMsg), "cache alloc node error");
- iIsFull = 1;
- return -2;
- }
-
- iRet = pstItem->init(row.table_definition()->key_fields() - 1,
- row.table_definition()->key_format(), achPackKey,
- 0);
- if (iRet != 0) {
- snprintf(szErrMsg, sizeof(szErrMsg), "raw data init error: %s",
- pstItem->get_err_msg());
- cache_purge(achPackKey);
- return -3;
- }
-
- return 0;
-}
-
-int BufferWriter::write_row(const RowValue &row)
-{
- int iRet;
-
- if (iRowIdx == 0) {
- if (AllocNode(row) != 0)
- return -1;
- }
-
- iRet = pstItem->insert_row(row, false, false);
- if (iRet != 0) {
- snprintf(szErrMsg, sizeof(szErrMsg), "insert row error: %s",
- pstItem->get_err_msg());
- cache_purge(achPackKey);
- return -2;
- }
-
- iRowIdx++;
- return 0;
-}
-
-int BufferWriter::commit_node()
-{
- int iRet;
-
- if (iRowIdx < 1)
- return 0;
-
- const MemHead *pstHead = PtMalloc::instance()->get_head_info();
- if (pstHead->m_hTop + pstItem->data_size() + MINSIZE >=
- pstHead->m_tSize) {
- iIsFull = 1;
- cache_purge(achPackKey);
- return -1;
- }
-
- iRet = pstDataProcess->do_replace_all(&stCurNode, pstItem);
- if (iRet != 0) {
- snprintf(szErrMsg, sizeof(szErrMsg),
- "write data into cache error");
- cache_purge(achPackKey);
- return -2;
- }
-
- iRowIdx = 0;
- memset(achPackKey, 0, sizeof(achPackKey));
- pstItem->destory();
- return 0;
-}
-
-int BufferWriter::rollback_node()
-{
- pstItem->destory();
- cache_purge(achPackKey);
- memset(achPackKey, 0, sizeof(achPackKey));
-
- return 0;
-}
diff --git a/src/core/buffer/buffer_writer.h b/src/core/buffer/buffer_writer.h
deleted file mode 100644
index 09a9d98748258b06b4f7664ef2994b0f76eedde0..0000000000000000000000000000000000000000
--- a/src/core/buffer/buffer_writer.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
-* Copyright [2021] JD.com, Inc.
-*
-* 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.
-*/
-
-#ifndef __CACHE_WRITER_H
-#define __CACHE_WRITER_H
-
-#include "buffer_pond.h"
-#include "table/table_def.h"
-#include "writer_interface.h"
-#include "raw_data_process.h"
-
-class BufferWriter : public WriterInterface, public BufferPond {
- private:
- RawData *pstItem;
- DataProcess *pstDataProcess;
- int iIsFull;
- int iRowIdx;
- Node stCurNode;
- char achPackKey[MAX_KEY_LEN + 1];
- char szErrMsg[200];
-
- protected:
- int AllocNode(const RowValue &row);
-
- public:
- BufferWriter(void);
- ~BufferWriter(void);
-
- int cache_open(BlockProperties *pstInfo,
- DTCTableDefinition *p_table_definition_);
-
- const char *err_msg()
- {
- return szErrMsg;
- }
- int begin_write();
- int full();
- int write_row(const RowValue &row);
- int commit_node();
- int rollback_node();
-};
-
-#endif
diff --git a/src/core/misc/main_supply.cc b/src/core/misc/main_supply.cc
index c212711f3c95bcaa753bb453533e6df3a0333002..32d5a010647f04161582091be18df19dc69ad498 100644
--- a/src/core/misc/main_supply.cc
+++ b/src/core/misc/main_supply.cc
@@ -593,8 +593,8 @@ int init_data_connector_ask_chain(PollerBase *thread)
//获取、配置基础信息
int init_config_info()
{
- mkdir("../stat", 0777);
- mkdir("../data", 0777);
+ // mkdir("/usr/local/dtc/stat", 0777);
+ // mkdir("/usr/local/dtc/data", 0777);
g_hash_changing = g_dtc_config->get_int_val("cache", "HashChanging", 0);
g_target_new_hash =
diff --git a/src/daemons/CMakeLists.txt b/src/daemons/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..b0caf017c3983b067ec696d067e2d29a0f7eeda4
--- /dev/null
+++ b/src/daemons/CMakeLists.txt
@@ -0,0 +1,44 @@
+SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/daemons)
+SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/daemons)
+
+if(CMAKE_COMPILER_IS_GNUCXX)
+ add_compile_options(-std=gnu++11)
+endif(CMAKE_COMPILER_IS_GNUCXX)
+
+#添加头文件搜索路径,相当于gcc -I
+INCLUDE_DIRECTORIES(
+ ${PROJECT_SOURCE_DIR}/src/daemons
+ ${PROJECT_SOURCE_DIR}/src/libs/common
+ ${PROJECT_SOURCE_DIR}/src/libs/stat
+ ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/include
+ ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/include)
+
+#添加.so/.a文件搜索路径,相当于gcc -L
+LINK_DIRECTORIES(
+ ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/libs
+ ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/libs
+ ${PROJECT_SOURCE_DIR}/src/libs/common
+ ${PROJECT_SOURCE_DIR}/src/libs/stat)
+
+#把当前目录下的源文件列表存放到变量SRC_LIST1里
+FILE(GLOB_RECURSE SRC_LIST1 ./*.cc ./*.c)
+#aux_source_directory(${PROJECT_SOURCE_DIR}/libs/stat/stat_alarm_reporter SRC_LIST2)
+
+#链接目标库
+LINK_LIBRARIES(liblog4cplus.a)
+LINK_LIBRARIES(libcommon.a)
+LINK_LIBRARIES(libyaml-cpp.a)
+LINK_LIBRARIES(libstat.a)
+LINK_LIBRARIES(pthread)
+LINK_LIBRARIES(dl)
+
+#编译参数
+ADD_DEFINITIONS("-g -fPIC -fpermissive")
+
+#编译为.so/.a
+ADD_EXECUTABLE(faultlogger ${SRC_LIST1})
+ADD_LIBRARY(daemons ${SRC_LIST1})
+
+#把目标文件与库文件进行链接
+TARGET_LINK_LIBRARIES(faultlogger libstat.a libcommon.a libyaml-cpp.a liblog4cplus.a)
+TARGET_LINK_LIBRARIES(daemons libstat.a liblog4cplus.a libyaml-cpp.a libcommon.a)
diff --git a/src/devel/CMakeLists.txt b/src/devel/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..61126a2c0579e4cfb8894e47c6d3c66ed29b9dc0
--- /dev/null
+++ b/src/devel/CMakeLists.txt
@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(./cpp)
\ No newline at end of file
diff --git a/src/devel/cpp/CMakeLists.txt b/src/devel/cpp/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..402d4f37b81e962729f1ba1fe8aa08822a5152b9
--- /dev/null
+++ b/src/devel/cpp/CMakeLists.txt
@@ -0,0 +1,60 @@
+
+#设置库文件输出路径
+SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/devel/cpp)
+
+#把当前目录下的源文件列表存放到变量SRC_LIST1里
+FILE(GLOB SRC_LIST1 ./*.c)
+SET(${SRC_LIST2} ../../libs/common/value.c
+ ../../libs/common/poll/poller.cc
+ ../../libs/common/timer/timer_lsit.cc
+ ../../libs/common/table/table_def.cc
+ ../../libs/common/mem_check.cc
+ ../../libs/common/algorithm/md5.cc
+ ../../libs/common/section.cc
+ ../../libs/common/decode/decode.cc
+ ../../libs/common/encode.cc
+ ../../libs/common/field/field_api.cc
+ ../../libs/common/packet/packet_base.cc
+ ../../libs/common/packet/packet_client.cc
+ ../../libs/common/task/task_base.cc
+ ../../libs/common/task/task_const.cc
+ ../../libs/common/algorithm/compress.cc
+ ../../libs/common/buffer.cc
+ ../../libs/common/thread/thread.cc)
+
+#添加头文件搜索路径,相当于gcc -I
+INCLUDE_DIRECTORIES(
+ .
+ ../../libs/common
+ ../../configcenter/ca_api
+ ../../libs/log4cplus/include/
+ ../../libs/zlib/include64
+ ../../libs/yaml-cpp/include/)
+
+#添加.so/.a文件搜索路径,相当于gcc -L
+LINK_DIRECTORIES(
+ ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/libs
+ ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/libs
+ ${PROJECT_SOURCE_DIR}/src/libs/zlib/lib/
+ ${PROJECT_SOURCE_DIR}/src/libs/common
+ ${PROJECT_SOURCE_DIR}/src/configcenter/ca_api/)
+
+#链接目标库
+LINK_LIBRARIES(dl)
+LINK_LIBRARIES(pthread)
+LINK_LIBRARIES(liblog4cplus.a)
+LINK_LIBRARIES(libyaml-cpp.a)
+LINK_LIBRARIES(libz64.a)
+LINK_LIBRARIES(libapp-client.a)
+LINK_LIBRARIES(libcommon.a)
+
+#编译参数
+ADD_DEFINITIONS ("-g -rdynamic -fPIC -fpermissive -DCLIENTAPI -D_GLIBCXX_USE_CXX11_ABI=0 -std=gnu++11 ")
+
+#编译为.so/.a
+ADD_LIBRARY(dtc.2 SHARED ${SRC_LIST1} ${SRC_LIST2})
+ADD_LIBRARY(dtc STATIC ${SRC_LIST1} ${SRC_LIST2})
+ADD_LIBRARY(dtc.pic SHARED ${SRC_LIST1} ${SRC_LIST2})
+
+#设置make install 安装路径
+INSTALL(TARGETS dtc.2 LIBRARY DESTINATION /usr/lib/)
diff --git a/src/libs/CMakeLists.txt b/src/libs/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..5d7bf522d86d27a1c6d7a0fad7cf2e66a92111e9
--- /dev/null
+++ b/src/libs/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory (./common)
+add_subdirectory (./stat)
\ No newline at end of file
diff --git a/src/libs/common/CMakeLists.txt b/src/libs/common/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..b7b24131ed6f4515b25964701891b327548e1bde
--- /dev/null
+++ b/src/libs/common/CMakeLists.txt
@@ -0,0 +1,40 @@
+#设置库文件输出路径
+SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/src/libs/common)
+
+IF(CMAKE_COMPILER_IS_GNUCXX)
+ ADD_COMPILE_OPTIONS(-std=gnu++11)
+ENDIF(CMAKE_COMPILER_IS_GNUCXX)
+
+#把当前目录下的源文件列表存放到变量SRC_LIST里
+FILE(GLOB_RECURSE SRC_LIST ./*.cc ./*.c)
+
+#添加头文件搜索路径,相当于gcc -I
+INCLUDE_DIRECTORIES (
+ .
+ ../../devel/cpp
+ ../../daemons
+ ../stat
+ ../log4cplus/include/
+ ../zlib/include64
+ ../yaml-cpp/include/)
+
+#添加.so/.a文件搜索路径,相当于gcc -L
+LINK_DIRECTORIES (
+ ${PROJECT_SOURCE_DIR}/src/libs/zlib/lib/libz64.a
+ ${PROJECT_SOURCE_DIR}/src/libs/log4cplus/libs
+ ${PROJECT_SOURCE_DIR}/src/libs/yaml-cpp/libs
+)
+
+#添加链接库,相当于gcc -l
+LINK_LIBRARIES(liblog4cplus.a)
+LINK_LIBRARIES(libyaml-cpp.a)
+LINK_LIBRARIES(libz64.a)
+LINK_LIBRARIES(pthread)
+
+#编译参数
+ADD_DEFINITIONS ("-g -fPIC -fpermissive")
+#编译为.so/.a
+ADD_LIBRARY (common ${SRC_LIST})
+
+#将目标文件与库文件链接
+TARGET_LINK_LIBRARIES(common liblog4cplus.a libyaml-cpp.a libz64.a)
\ No newline at end of file
diff --git a/src/libs/common/config/config.cc b/src/libs/common/config/config.cc
index d26aefee7ba3b500548749522f874ffd3d4efae2..3cbe253eeea6e2963912d52cd6f9f90dc89e189c 100644
--- a/src/libs/common/config/config.cc
+++ b/src/libs/common/config/config.cc
@@ -125,7 +125,7 @@ int DTCConfig::parse_config(const char *fn, const char *defsec, bool bakconfig)
if (bakconfig) {
char bak_config[1024];
int err = 0;
- snprintf(bak_config, sizeof(bak_config), "cp %s ../stat/", fn);
+ snprintf(bak_config, sizeof(bak_config), "cp %s /usr/local/dtc/stat/", fn);
if (err == 0)
err = system(bak_config);
}
diff --git a/src/libs/common/config/parse_cluster_config.cc b/src/libs/common/config/parse_cluster_config.cc
index 5943e27299e92324e0046f425f527b56f5a897c9..845385da3c7d370253bc314da2265a2fa8dcc235 100644
--- a/src/libs/common/config/parse_cluster_config.cc
+++ b/src/libs/common/config/parse_cluster_config.cc
@@ -35,27 +35,38 @@ bool parse_cluster_config(std::string &strSelfName,
std::vector *result, const char *buf,
int len)
{
+
log4cplus_debug("%.*s", len, buf);
//配置中不允许有相同servername的节点出现,本set用于检查重复servername
+
std::set filter;
+
pair::iterator, bool> ret;
string xmldoc(buf, len);
+
MarkupSTL xml;
+
if (!xml.set_doc(xmldoc.c_str())) {
+
log4cplus_error("parse config file error");
+
return false;
}
+
xml.reset_main_pos();
if (!xml.find_elem("serverlist")) {
log4cplus_error("no serverlist info");
return -1;
}
+
strSelfName = xml.get_attrib("selfname");
+
log4cplus_debug("strSelfName is %s", strSelfName.c_str());
while (xml.find_child_elem("server")) {
+
if (xml.into_elem()) {
struct ClusterNode node;
node.name = xml.get_attrib("name");
@@ -83,7 +94,9 @@ bool parse_cluster_config(std::string &strSelfName,
result->push_back(node);
xml.out_of_elem();
}
+ log4cplus_debug("*********No.11************");
}
+ log4cplus_debug("*********No.12************");
if (result->empty())
log4cplus_info(
"ClusterConfig is empty,dtc runing in normal mode");
diff --git a/src/libs/common/config/parse_cluster_config.h b/src/libs/common/config/parse_cluster_config.h
index e7306d80da4f81f1d9fc2238d51a818bdaef269a..d2332945a0b618c9ee5d50d5e92aba660273fada 100644
--- a/src/libs/common/config/parse_cluster_config.h
+++ b/src/libs/common/config/parse_cluster_config.h
@@ -21,8 +21,8 @@
#include