From 082b410a92631ec694dfaa5b8786193963268f72 Mon Sep 17 00:00:00 2001 From: Axlgrep Date: Tue, 18 Dec 2018 10:53:20 +0800 Subject: [PATCH] add protobuf submodule and pika_inner_message.proto (#429) --- .gitignore | 2 ++ .gitmodules | 3 ++ Makefile | 29 ++++++++++++++--- src/pika_inner_message.proto | 60 ++++++++++++++++++++++++++++++++++++ third/protobuf | 1 + 5 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 src/pika_inner_message.proto create mode 160000 third/protobuf diff --git a/.gitignore b/.gitignore index 52009d9d49..5d21ed9c5a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,8 @@ *.lo *.o *.obj +*pb.cc +*pb.h # Precompiled Headers *.gch diff --git a/.gitmodules b/.gitmodules index 392c363bf0..3a631bfd74 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "third/pink"] path = third/pink url = https://github.com/Qihoo360/pink.git +[submodule "third/protobuf"] + path = third/protobuf + url = https://github.com/google/protobuf.git diff --git a/Makefile b/Makefile index 6c4d7a3a40..c0a7550af2 100644 --- a/Makefile +++ b/Makefile @@ -81,6 +81,12 @@ BLACKWIDOW_PATH = $(THIRD_PATH)/blackwidow endif BLACKWIDOW = $(BLACKWIDOW_PATH)/lib/libblackwidow$(DEBUG_SUFFIX).a +ifndef PROTOBUF_PATH +PROTOBUF_PATH = $(THIRD_PATH)/protobuf +endif +PROTOBUF = $(PROTOBUF_PATH)/_install/lib/libprotobuf.a +PROTOC = $(PROTOBUF_PATH)/_install/bin/protoc + ifeq ($(360), 1) GLOG := $(GLOG_PATH)/.libs/libglog.a endif @@ -90,7 +96,8 @@ INCLUDE_PATH = -I. \ -I$(PINK_PATH) \ -I$(BLACKWIDOW_PATH)/include \ -I$(ROCKSDB_PATH) \ - -I$(ROCKSDB_PATH)/include + -I$(ROCKSDB_PATH)/include \ + -I$(PROTOBUF_PATH)/_install/include ifeq ($(360),1) INCLUDE_PATH += -I$(GLOG_PATH)/src @@ -100,7 +107,7 @@ LIB_PATH = -L./ \ -L$(SLASH_PATH)/slash/lib \ -L$(PINK_PATH)/pink/lib \ -L$(BLACKWIDOW_PATH)/lib \ - -L$(ROCKSDB_PATH) + -L$(ROCKSDB_PATH) \ ifeq ($(360),1) LIB_PATH += -L$(GLOG_PATH)/.libs @@ -111,7 +118,7 @@ LDFLAGS += $(LIB_PATH) \ -lslash$(DEBUG_SUFFIX) \ -lblackwidow$(DEBUG_SUFFIX) \ -lrocksdb$(DEBUG_SUFFIX) \ - -lglog + -lglog \ # ---------------End Dependences---------------- @@ -119,6 +126,9 @@ VERSION_CC=$(SRC_PATH)/build_version.cc LIB_SOURCES := $(VERSION_CC) \ $(filter-out $(VERSION_CC), $(wildcard $(SRC_PATH)/*.cc)) +PIKA_PROTO := $(wildcard $(SRC_PATH)/*.proto) +PIKA_PROTO_GENS:= $(PIKA_PROTO:%.proto=%.pb.cc) $(PIKA_PROTO:%.proto=%.pb.h) + #----------------------------------------------- @@ -182,6 +192,7 @@ $(SRC_PATH)/build_version.cc: FORCE FORCE: LIBOBJECTS = $(LIB_SOURCES:.cc=.o) +PROTOOBJECTS = $(PIKA_PROTO:.proto=.pb.o) # if user didn't config LIBNAME, set the default ifeq ($(BINNAME),) @@ -192,14 +203,19 @@ BINARY = ${BINNAME} .PHONY: distclean clean dbg all +%.pb.cc %.pb.h: %.proto $(PROTOC) + $(AM_V_CC)$(PROTOC) -I=$(SRC_PATH) --cpp_out=$(SRC_PATH) $< + %.o: %.cc $(AM_V_CC)$(CXX) $(CXXFLAGS) -c $< -o $@ +proto : $(PIKA_PROTO_GENS) + all: $(BINARY) dbg: $(BINARY) -$(BINARY): $(SLASH) $(PINK) $(ROCKSDB) $(BLACKWIDOW) $(GLOG) $(LIBOBJECTS) +$(BINARY): $(SLASH) $(PINK) $(ROCKSDB) $(BLACKWIDOW) $(GLOG) $(PROTOOBJECTS) $(PROTOBUF) $(LIBOBJECTS) $(AM_V_at)rm -f $@ $(AM_V_at)$(AM_LINK) $(AM_V_at)rm -rf $(OUTPUT) @@ -220,12 +236,16 @@ $(ROCKSDB): $(BLACKWIDOW): $(AM_V_at)make -C $(BLACKWIDOW_PATH) ROCKSDB_PATH=$(ROCKSDB_PATH) SLASH_PATH=$(SLASH_PATH) DEBUG_LEVEL=$(DEBUG_LEVEL) +$(PROTOBUF) $(PROTOC): + cd $(PROTOBUF_PATH); autoreconf -if; ./configure --prefix=$(PROTOBUF_PATH)/_install; make install + $(GLOG): cd $(THIRD_PATH)/glog; if [ ! -f ./Makefile ]; then ./configure --disable-shared; fi; make; echo '*' > $(CURDIR)/third/glog/.gitignore; clean: rm -rf $(OUTPUT) rm -rf $(CLEAN_FILES) + rm -rf $(PIKA_PROTO_GENS) find $(SRC_PATH) -name "*.[oda]*" -exec rm -f {} \; find $(SRC_PATH) -type f -regex ".*\.\(\(gcda\)\|\(gcno\)\)" -exec rm {} \; @@ -234,4 +254,5 @@ distclean: clean make -C $(SLASH_PATH)/slash/ clean make -C $(BLACKWIDOW_PATH)/ clean make -C $(ROCKSDB_PATH)/ clean + make -C $(PROTOBUF_PATH)/ clean # make -C $(GLOG_PATH)/ clean diff --git a/src/pika_inner_message.proto b/src/pika_inner_message.proto new file mode 100644 index 0000000000..6af8374649 --- /dev/null +++ b/src/pika_inner_message.proto @@ -0,0 +1,60 @@ +package InnerMessage; + +enum Type { + kSyncMeta = 1; + kTrySync = 2; +} + +enum StatusCode { + kOk = 1; + kWait = 2; + kError = 3; +} + +message SyncOffset { + required int32 filenum = 1; + required int64 offset = 2; + optional bool force = 3; +} + +message Node { + required string ip = 1; + required int32 port = 2; +} + +message Table { + required string table_name = 1; + required int32 partition_num = 2; +} + +message InnerRequst { + message SyncMeta { + required Node node = 1; + } + + message TrySync { + required Node node = 1; + required string table_name = 2; + required int32 partition_id = 3; + required SyncOffset sync_offset = 4; + } + + required Type type = 1; + optional SyncMeta sync_meta = 2; + optional TrySync try_sync = 3; +} + +message InnerResponse { + message SyncMeta { + repeated Table tables = 1; + } + + message TrySync { + required StatusCode code = 1; + optional string reply = 2; + } + + required Type type = 1; + optional SyncMeta sync_meta = 2; + optional TrySync try_sync = 3; +} diff --git a/third/protobuf b/third/protobuf new file mode 160000 index 0000000000..774d630bde --- /dev/null +++ b/third/protobuf @@ -0,0 +1 @@ +Subproject commit 774d630bde574f5fcbb6dae6eaa0f91f7bc12967