mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
Remove pkv from acl project because it has been a independent project now.
This commit is contained in:
parent
a8f80c1e48
commit
599e6dae0f
@ -46,6 +46,7 @@ Architecture diagram:
|
||||
* [5.3. Who are using acl?](#53-who-are-using-acl)
|
||||
* [5.4. License](#54-license)
|
||||
* [5.5. Reference](#55-reference)
|
||||
* [5.6. Thanks](#56-thanks)
|
||||
|
||||
<hr>
|
||||
|
||||
@ -436,3 +437,7 @@ If you have some questions when using Acl, please see [FAQ.md](FAQ.md).
|
||||
- Gitee: https://gitee.com/acl-dev/acl
|
||||
- Weibo: http://weibo.com/zsxxsz
|
||||
- QQ Group: 705290654
|
||||
|
||||
## 5.6. Thanks
|
||||
|
||||
Thanks <a href=https://jb.gg/OpenSourceSupport target=_blank><img widith=100 height=50 src=res/logo/clion_icon.png /> </a> for the supporting of Acl development.
|
@ -1,141 +0,0 @@
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(pkv)
|
||||
|
||||
if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
message(FATAL_ERROR "Please into another dir to build!")
|
||||
endif()
|
||||
|
||||
if (${CMAKE_BINARY_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
message(FATAL_ERROR "Please into another dir to build!")
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "RELEASE")
|
||||
message(STATUS "build pkv for release version")
|
||||
elseif (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
|
||||
message(STATUS "build pkv for debug version")
|
||||
else()
|
||||
message(STATUS "build pkv for default version")
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||
add_definitions("-Wno-invalid-source-encoding")
|
||||
include_directories("/usr/local/include")
|
||||
SET(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> Scr <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
SET(CMAKE_CXX_ARCHIVE_FINISH "<CMAKE_RANLIB> -no_warning_for_no_symbols -c <TARGET>")
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
else()
|
||||
message(FATAL_ERROR "unknown CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")
|
||||
endif()
|
||||
|
||||
##############################################################################
|
||||
|
||||
set(home_path ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
||||
set(acl_path ${home_path}/lib_acl)
|
||||
set(acl_cpp_path ${home_path}/lib_acl_cpp)
|
||||
set(fiber_path ${home_path}/lib_fiber/c)
|
||||
set(fiber_cpp_path ${home_path}/lib_fiber/cpp)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${acl_path}/include
|
||||
${acl_cpp_path}/include
|
||||
${fiber_path}/include
|
||||
${fiber_cpp_path}/include
|
||||
)
|
||||
|
||||
set(base_path ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(src_paths
|
||||
${base_path}
|
||||
${base_path}/test
|
||||
${base_path}/coder
|
||||
${base_path}/action
|
||||
${base_path}/dao
|
||||
${base_path}/db
|
||||
${base_path}/db/rocksdb
|
||||
${base_path}/db/wt
|
||||
)
|
||||
|
||||
foreach(iter ${src_paths})
|
||||
aux_source_directory(${iter} src_files)
|
||||
endforeach()
|
||||
|
||||
##############################################################################
|
||||
|
||||
#SET(CMAKE_VERBOSE_MAKEFILE on)
|
||||
|
||||
add_definitions(
|
||||
"-g"
|
||||
"-W"
|
||||
"-O3"
|
||||
"-Wall"
|
||||
"-Werror"
|
||||
"-Wshadow"
|
||||
"-Wformat"
|
||||
"-Wpointer-arith"
|
||||
"-D_REENTRANT"
|
||||
"-Wno-long-long"
|
||||
"-Wuninitialized"
|
||||
"-D_POSIX_PTHREAD_SEMANTICS"
|
||||
"-fexceptions"
|
||||
"-Wno-unused-parameter"
|
||||
"-Wno-error=deprecated-declarations"
|
||||
"-Wno-deprecated-declarations"
|
||||
"-fPIC"
|
||||
)
|
||||
|
||||
if (${BUILD_WITH_C11} MATCHES "YES")
|
||||
add_definitions("-std=c++11")
|
||||
else()
|
||||
add_definitions("-std=c++17")
|
||||
endif()
|
||||
|
||||
#find_library(acl_lib acl_all PATHS /usr/lib /usr/local/lib)
|
||||
#find_library(fiber_cpp_lib fiber_cpp PATHS /usr/lib /usr/local/lib)
|
||||
#find_library(fiber_lib fiber PATHS /usr/lib /usr/local/lib)
|
||||
|
||||
set(acl_all ${home_path}/lib_fiber/lib/libfiber_cpp.a ${home_path}/libacl_all.a)
|
||||
set(fiber ${home_path}/lib_fiber/lib/libfiber.a)
|
||||
|
||||
find_library(yyjson NAMES yyjson PATHS /usr/lib /usr/local/lib)
|
||||
set(lib_all ${acl_all} ${yyjson})
|
||||
|
||||
if(${HAS_ROCKSDB} MATCHES "YES")
|
||||
find_library(rocksdb NAMES rocksdb PATHS /usr/lib /usr/local/lib)
|
||||
add_definitions("-DHAS_ROCKSDB")
|
||||
set(lib_all ${lib_all} ${rocksdb})
|
||||
endif()
|
||||
|
||||
if(${HAS_WT} MATCHES "YES")
|
||||
find_library(wiredtiger NAMES wiredtiger PATHS /usr/lib /usr/local/lib)
|
||||
add_definitions("-DHAS_WT")
|
||||
set(lib_all ${lib_all} ${wiredtiger})
|
||||
endif()
|
||||
|
||||
if(${HAS_JEMALLOC} MATCHES "YES")
|
||||
find_library(jemalloc NAMES jemalloc PATHS /usr/lib /usr/local/lib)
|
||||
add_definitions("-DHAS_JEAMALLOC")
|
||||
set(lib_all ${lib_all} ${jemalloc})
|
||||
endif()
|
||||
|
||||
#set(wt -lwiredtiger)
|
||||
#set(uring -luring-ffi)
|
||||
#set(iconv -liconv)
|
||||
|
||||
set(lib_all ${lib_all} ${fiber})
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
|
||||
set(lib_all ${lib_all} -liconv)
|
||||
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux")
|
||||
set(lib_all ${lib_all} ${uring} ${iconv} ${jemalloc})
|
||||
endif()
|
||||
|
||||
set(lib_all ${lib_all} -lz -lpthread -ldl)
|
||||
|
||||
set(output_path ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_path})
|
||||
link_directories(${output_path})
|
||||
|
||||
add_executable(pkv ${src_files} test/test_coder.cpp test/test_coder.h test/test_db.cpp test/test_db.h)
|
||||
target_link_libraries(pkv ${lib_all})
|
||||
|
||||
###############################################################################
|
@ -1,23 +0,0 @@
|
||||
|
||||
# make BUILD_WITH_C11=YES; or make
|
||||
#
|
||||
ifeq ($(BUILD_WITH_C11), YES)
|
||||
BUILD_ARGS = -DBUILD_WITH_C11=YES
|
||||
else
|
||||
BUILD_ARGS = -DBUILD_WITH_C11=NO
|
||||
endif
|
||||
|
||||
#BUILD_ARGS += -DCMAKE_VERBOSE_MAKEFILE=ON
|
||||
BUILD_ARGS += -DHAS_ROCKSDB=YES
|
||||
BUILD_ARGS += -DHAS_WT=YES
|
||||
BUILD_ARGS += -DHAS_JEMALLOC=YES
|
||||
|
||||
all:
|
||||
@(mkdir -p build; cd build; cmake ${BUILD_ARGS} ..; make -j 4)
|
||||
|
||||
clean cl:
|
||||
@(rm -rf build pkv)
|
||||
|
||||
help h:
|
||||
@echo "\"make BUILD_WITH_C11=YES\"" to build with c++11 or to build with c++17.
|
||||
rebuild rb: cl all
|
@ -1,189 +0,0 @@
|
||||
CC = g++
|
||||
|
||||
CFLAGS = -c -g -W \
|
||||
-Wall \
|
||||
-Wcast-qual \
|
||||
-Wcast-align \
|
||||
-Wno-long-long \
|
||||
-Wpointer-arith \
|
||||
-Werror \
|
||||
-Wshadow \
|
||||
-O3 \
|
||||
-D_REENTRANT \
|
||||
-D_POSIX_PTHREAD_SEMANTICS \
|
||||
-D_USE_FAST_MACRO
|
||||
CFLAGS += --std=c++17
|
||||
|
||||
###########################################################
|
||||
#Check system:
|
||||
# Linux, SunOS, Solaris, BSD variants, AIX, HP-UX
|
||||
SYSLIB = -lpthread -lz -ldl
|
||||
CHECKSYSRES = @echo "Unknow system type!";exit 1
|
||||
UNIXNAME = $(shell uname -s)
|
||||
OSTYPE = $(shell uname -m)
|
||||
RPATH = linux64
|
||||
|
||||
OS_ENV=$(shell uname -a)
|
||||
ifeq ($(findstring WSL, $(OS_ENV)), WSL)
|
||||
SYSLIB += -liconv
|
||||
endif
|
||||
|
||||
ifeq ($(findstring ubuntu, $(OS_ENV)), ubuntu)
|
||||
SYSLIB += -liconv
|
||||
endif
|
||||
|
||||
ifeq ($(CC),)
|
||||
CC = gcc
|
||||
endif
|
||||
|
||||
ifeq ($(findstring Alpine, $(shell uname -a)), Alpine)
|
||||
SYSLIB += -lucontext
|
||||
endif
|
||||
|
||||
ifeq ($(findstring g++, $(CC)), g++)
|
||||
GCC_VERSION=$(shell g++ --version | grep ^g++ | sed 's/^.* //g')
|
||||
GCC_MAJOR:=$(shell echo "$(GCC_VERSION)" | cut -d'.' -f1)
|
||||
GCC_MINOR:=$(shell echo "$(GCC_VERSION)" | cut -d'.' -f2)
|
||||
GCC_SUB:=$(shell echo "$(GCC_VERSION)" | cut -d'.' -f3)
|
||||
GCC_VER:=$(shell [ $(GCC_MAJOR) -gt 4 -o \( $(GCC_MAJOR) -eq 4 -a $(GCC_MINOR) -gt 7 \) ] && echo true)
|
||||
endif
|
||||
|
||||
# For FreeBSD
|
||||
ifeq ($(findstring FreeBSD, $(UNIXNAME)), FreeBSD)
|
||||
ifeq ($(findstring gcc, $(CC)), gcc)
|
||||
CFLAGS += -Wstrict-prototypes
|
||||
endif
|
||||
CFLAGS += -DFREEBSD -D_REENTRANT
|
||||
SYSLIB = -lcrypt -lpthread -lz
|
||||
RPATH = freebsd
|
||||
endif
|
||||
|
||||
# For Darwin
|
||||
ifeq ($(findstring Darwin, $(UNIXNAME)), Darwin)
|
||||
# CC += -arch x86_64 -arch arm64
|
||||
CFLAGS += -DMACOSX -Wno-invalid-source-encoding \
|
||||
-Wno-invalid-offsetof \
|
||||
-DHAS_ROCKSDB
|
||||
UNIXTYPE = MACOSX
|
||||
SYSLIB += -liconv -rdynamic -lz
|
||||
RPATH = macos
|
||||
endif
|
||||
|
||||
#Path for Linux
|
||||
ifeq ($(findstring Linux, $(UNIXNAME)), Linux)
|
||||
ifeq ($CC, "gcc")
|
||||
CFLAGS += -Wstrict-prototypes
|
||||
endif
|
||||
ifeq ($(findstring i686, $(OSTYPE)), i686)
|
||||
RPATH = linux32
|
||||
endif
|
||||
ifeq ($(findstring x86_64, $(OSTYPE)), x86_64)
|
||||
RPATH = linux64
|
||||
endif
|
||||
has_io_uring=$(HAS_IO_URING)
|
||||
ifeq ($(has_io_uring), yes)
|
||||
SYSLIB += -luring-ffi
|
||||
endif
|
||||
|
||||
CFLAGS += -DLINUX2 -D_REENTRANT -DHAS_ROCKSDB
|
||||
SYSLIB += -lcrypt -lz -lunwind -lunwind-generic
|
||||
endif
|
||||
|
||||
# For CYGWIN
|
||||
ifeq ($(findstring CYGWIN, $(UNIXNAME)), CYGWIN)
|
||||
SYSLIB = -lpthread -liconv -lz
|
||||
CFLAGS += -DLINUX2 -DMINGW
|
||||
UNIXTYPE = LINUX
|
||||
endif
|
||||
|
||||
# For MINGW
|
||||
ifeq ($(findstring MINGW, $(UNIXNAME)), MINGW)
|
||||
SYSLIB = -lpthread -liconv -lz
|
||||
CFLAGS += -DLINUX2 -DMINGW
|
||||
UNIXTYPE = LINUX
|
||||
endif
|
||||
|
||||
# For MSYS
|
||||
ifeq ($(findstring MSYS, $(UNIXNAME)), MSYS)
|
||||
SYSLIB = -lpthread -liconv -lz
|
||||
CFLAGS += -DLINUX2 -DMINGW
|
||||
UNIXTYPE = LINUX
|
||||
endif
|
||||
|
||||
#Path for SunOS
|
||||
ifeq ($(findstring SunOS, $(UNIXNAME)), SunOS)
|
||||
ifeq ($(findstring 86, $(UNIXNAME)), 86)
|
||||
SYSLIB += -lsocket -lnsl -lrt
|
||||
endif
|
||||
ifeq ($(findstring sun4u, $(UNIXNAME)), sun4u)
|
||||
SYSLIB += -lsocket -lnsl -lrt
|
||||
endif
|
||||
ifeq ($CC, "gcc")
|
||||
CFLAGS += -Wstrict-prototypes
|
||||
endif
|
||||
CFLAGS += -DSUNOS5 -D_REENTRANT
|
||||
RPATH = sunos_x86
|
||||
endif
|
||||
|
||||
#Path for HP-UX
|
||||
ifeq ($(findstring HP-UX, $(UNIXNAME)), HP-UX)
|
||||
ifeq ($CC, "gcc")
|
||||
CFLAGS += -Wstrict-prototypes
|
||||
endif
|
||||
CFLAGS += -DHP_UX -DHPUX11
|
||||
PLAT_NAME=hp-ux
|
||||
endif
|
||||
|
||||
#Find system type.
|
||||
ifneq ($(SYSPATH),)
|
||||
CHECKSYSRES = @echo "System is $(shell uname -sm)"
|
||||
endif
|
||||
###########################################################
|
||||
|
||||
ACL_PATH = ../../..
|
||||
CFLAGS += -I. -I$(ACL_PATH)/lib_acl/include \
|
||||
-I$(ACL_PATH)/lib_protocol/include \
|
||||
-I$(ACL_PATH)/lib_acl_cpp/include \
|
||||
-I$(ACL_PATH)/lib_fiber/c/include \
|
||||
-I$(ACL_PATH)/lib_fiber/cpp/include
|
||||
EXTLIBS =
|
||||
LDFLAGS = -L$(ACL_PATH)/lib_fiber/lib -lfiber_cpp \
|
||||
-L$(ACL_PATH)/lib_acl_cpp/lib -lacl_cpp \
|
||||
-L$(ACL_PATH)/lib_protocol/lib -lprotocol \
|
||||
-L$(ACL_PATH)/lib_acl/lib -lacl -lfiber \
|
||||
-lrocksdb -Wl,-rpath,/usr/local/lib \
|
||||
$(EXTLIBS) $(SYSLIB)
|
||||
|
||||
COMPILE = $(CC) $(CFLAGS)
|
||||
LINK = $(CC) $(OBJ) $(LDFLAGS)
|
||||
###########################################################
|
||||
OBJ_PATH = ./debug
|
||||
|
||||
$(shell mkdir -p ${OBJ_PATH})
|
||||
|
||||
#Project's objs
|
||||
SRC = $(wildcard *.cpp) $(wildcard db/*.cpp) \
|
||||
$(wildcard db/rocksdb/*.cpp) $(wildcard db/wt/*.cpp)
|
||||
OBJ = $(patsubst %.cpp, $(OBJ_PATH)/%.o, $(notdir $(SRC)))
|
||||
|
||||
$(OBJ_PATH)/%.o: %.cpp
|
||||
$(COMPILE) $< -o $@
|
||||
$(OBJ_PATH)/%.o: db/%.cpp
|
||||
$(COMPILE) $< -o $@
|
||||
$(OBJ_PATH)/%.o: db/rocksdb/%.cpp
|
||||
$(COMPILE) $< -o $@
|
||||
$(OBJ_PATH)/%.o: db/wt/%.cpp
|
||||
$(COMPILE) $< -o $@
|
||||
|
||||
.PHONY = all clean
|
||||
all: RM $(OBJ)
|
||||
$(LINK) -o $(PROG)
|
||||
@echo ""
|
||||
@echo "All ok! Output:$(PROG)"
|
||||
@echo ""
|
||||
RM:
|
||||
rm -f $(PROG)
|
||||
clean:
|
||||
rm -f $(PROG)
|
||||
rm -f $(OBJ)
|
||||
###########################################################
|
@ -1,152 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/8/1.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "proto/redis_coder.h"
|
||||
#include "proto/redis_object.h"
|
||||
|
||||
#include "redis_handler.h"
|
||||
#include "redis_hash.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
redis_hash::redis_hash(redis_handler &handler, const redis_object &obj)
|
||||
: redis_command(handler, obj)
|
||||
{}
|
||||
|
||||
bool redis_hash::hset(redis_coder &result) {
|
||||
auto& objs = obj_.get_objects();
|
||||
if (objs.size() < 4) {
|
||||
logger_error("invalid HSET command's size=%zd < 4", objs.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto key = objs[1]->get_str();
|
||||
if (key == nullptr || *key == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto name = objs[2]->get_str();
|
||||
if (name == nullptr || *name == 0) {
|
||||
logger_error("name null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto value = objs[3]->get_str();
|
||||
if (value == nullptr || *value == 0) {
|
||||
logger_error("value null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& coder = handler_.get_coder();
|
||||
coder.clear();
|
||||
|
||||
coder.create_object()
|
||||
.create_child().set_string(name, true)
|
||||
.create_child().set_string(value, true);
|
||||
|
||||
std::string buff;
|
||||
if (!coder.to_string(buff)) {
|
||||
logger_error("build data error");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!handler_.get_db()->set(key, buff)) {
|
||||
logger_error("set key=%s, value=%s error", key, buff.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
//printf(">set key=%s, value=%s ok\n", key, buff.c_str());
|
||||
result.create_object().set_number(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool redis_hash::hget(redis_coder &result) {
|
||||
auto& objs = obj_.get_objects();
|
||||
if (objs.size() < 3) {
|
||||
logger_error("invalid HGET command's size=%zd < 3", objs.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto key = objs[1]->get_str();
|
||||
if (key == nullptr || *key == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto name = objs[2]->get_str();
|
||||
if (name == nullptr || *name == 0) {
|
||||
logger_error("name null");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string buff;
|
||||
if (!handler_.get_db()->get(key, buff) || buff.empty()) {
|
||||
logger_error("db get key=%s error", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
//printf(">>hget: [%s]\r\n", buff.c_str());
|
||||
|
||||
auto& coder = handler_.get_coder();
|
||||
coder.clear();
|
||||
|
||||
size_t len = buff.size();
|
||||
(void) coder.update(buff.c_str(), len);
|
||||
if (len > 0) {
|
||||
logger_error("invalid buff in db for key=%s", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& objs2 = coder.get_objects();
|
||||
if (objs2.size() != 1) {
|
||||
logger_error("invalid object in db, key=%s, objs=%zd", key, objs2.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto array = objs2[0];
|
||||
if (array->get_type() != REDIS_OBJ_ARRAY) {
|
||||
logger_error("invalid array object, key=%s", key);
|
||||
return false;
|
||||
}
|
||||
auto& objs3 = array->get_objects();
|
||||
if (objs3.empty() || objs3.size() % 2 != 0) {
|
||||
logger_error("invalid array objects' size=%zd, key=%s", objs3.size(), key);
|
||||
return false;
|
||||
}
|
||||
for (size_t i = 0; i < objs3.size();) {
|
||||
auto n = objs3[i++]->get_str();
|
||||
auto v = objs3[i++]->get_str();
|
||||
if (n == nullptr || *n == 0 || v == nullptr || *v == 0) {
|
||||
logger_error("no value set in db, key=%s", key);
|
||||
return false;
|
||||
}
|
||||
if (strcmp(name, n) == 0) {
|
||||
result.create_object().set_string(v);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
logger_error("Not found, key=%s, name=%s", key, name);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool redis_hash::hdel(redis_coder &result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool redis_hash::hmset(redis_coder &result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool redis_hash::hmget(redis_coder &result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool redis_hash::hgetall(redis_coder &result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,25 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/8/1.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "redis_command.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class redis_coder;
|
||||
|
||||
class redis_hash : public redis_command {
|
||||
public:
|
||||
redis_hash(redis_handler& handler, const redis_object& obj);
|
||||
~redis_hash() override = default;
|
||||
|
||||
bool hset(redis_coder& result);
|
||||
bool hget(redis_coder& result);
|
||||
bool hdel(redis_coder& result);
|
||||
bool hmset(redis_coder& result);
|
||||
bool hmget(redis_coder& result);
|
||||
bool hgetall(redis_coder& result);
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,13 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/8/1.
|
||||
//
|
||||
|
||||
#include "redis_command.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
redis_command::redis_command(redis_handler& handler, const redis_object& obj)
|
||||
: handler_(handler), obj_(obj)
|
||||
{}
|
||||
|
||||
} // namespace pkv
|
@ -1,22 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/8/1.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class redis_handler;
|
||||
class redis_object;
|
||||
|
||||
class redis_command {
|
||||
public:
|
||||
redis_command(redis_handler& handler, const redis_object& obj);
|
||||
virtual ~redis_command() = default;
|
||||
|
||||
protected:
|
||||
redis_handler& handler_;
|
||||
const redis_object &obj_;
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,117 +0,0 @@
|
||||
//
|
||||
// Created by zsx on 2023/7/23.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "coder/redis_object.h"
|
||||
#include "coder/redis_coder.h"
|
||||
#include "redis_key.h"
|
||||
#include "redis_string.h"
|
||||
#include "redis_hash.h"
|
||||
#include "redis_server.h"
|
||||
#include "redis_handler.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
#define EQ !strcasecmp
|
||||
|
||||
redis_handler::redis_handler(shared_db& db, redis_coder& parser,
|
||||
acl::socket_stream& conn)
|
||||
: db_(db)
|
||||
, parser_(parser)
|
||||
, conn_(conn)
|
||||
, builder_(parser.get_cache())
|
||||
, coder_(parser.get_cache())
|
||||
{
|
||||
}
|
||||
|
||||
bool redis_handler::handle() {
|
||||
auto objs = parser_.get_objects();
|
||||
if (objs.empty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
{
|
||||
std::string tmp;
|
||||
for (size_t i = 0; i < objs.size(); i++) {
|
||||
tmp += "+OK\r\n";
|
||||
}
|
||||
return conn_.write(tmp.c_str(), tmp.size()) == (int) tmp.size();
|
||||
}
|
||||
#endif
|
||||
|
||||
//if (objs.size() >= 20) { printf(">>>objs=%zd\r\n", objs.size()); }
|
||||
|
||||
for (const auto& obj : objs) {
|
||||
if (!handle_one(*obj)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string buf;
|
||||
if (!builder_.to_string(buf)) {
|
||||
builder_.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
builder_.clear();
|
||||
|
||||
//if (objs.size() >= 20) { printf("reply len=%zd\r\n", buf.size()); }
|
||||
|
||||
//printf(">>>buf=[%s]\r\n", buf.c_str());
|
||||
return conn_.write(buf.c_str(), buf.size()) != -1;
|
||||
}
|
||||
|
||||
bool redis_handler::handle_one(const redis_object &obj) {
|
||||
auto cmd = obj.get_cmd();
|
||||
if (cmd == nullptr || *cmd == '\0') {
|
||||
logger_error("redis command null");
|
||||
return false;
|
||||
}
|
||||
|
||||
//printf(">>>%s(%d): cmd=%s\r\n", __func__, __LINE__, cmd);
|
||||
|
||||
if (EQ(cmd, "SET")) {
|
||||
redis_string redis(*this, obj);
|
||||
return redis.set(builder_);
|
||||
} else if (EQ(cmd, "GET")) {
|
||||
redis_string redis(*this, obj);
|
||||
return redis.get(builder_);
|
||||
} else if (EQ(cmd, "DEL")) {
|
||||
redis_key redis(*this, obj);
|
||||
return redis.del(builder_);
|
||||
} else if (EQ(cmd, "TYPE")) {
|
||||
redis_key redis(*this, obj);
|
||||
return redis.type(builder_);
|
||||
} else if (EQ(cmd, "HSET")) {
|
||||
redis_hash redis(*this, obj);
|
||||
return redis.hset(builder_);
|
||||
} else if (EQ(cmd, "HGET")) {
|
||||
redis_hash redis(*this, obj);
|
||||
return redis.hget(builder_);
|
||||
} else if (EQ(cmd, "HDEL")) {
|
||||
redis_hash redis(*this, obj);
|
||||
return redis.hdel(builder_);
|
||||
} else if (EQ(cmd, "HMSET")) {
|
||||
redis_hash redis(*this, obj);
|
||||
return redis.hmset(builder_);
|
||||
} else if (EQ(cmd, "HMGET")) {
|
||||
redis_hash redis(*this, obj);
|
||||
return redis.hmget(builder_);
|
||||
} else if (EQ(cmd, "HGETALL")) {
|
||||
redis_hash redis(*this, obj);
|
||||
return redis.hgetall(builder_);
|
||||
} else if (EQ(cmd, "CONFIG")) {
|
||||
redis_server redis(*this, obj);
|
||||
return redis.config(builder_);
|
||||
}
|
||||
|
||||
std::string err;
|
||||
err.append(cmd).append("not support yet");
|
||||
logger_error("cmd=%s not support!", cmd);
|
||||
builder_.create_object().set_error(err);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,53 +0,0 @@
|
||||
//
|
||||
// Created by zsx on 2023/7/23.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "coder/redis_coder.h"
|
||||
#include "db/db.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class redis_object;
|
||||
class redis_ocache;
|
||||
|
||||
class redis_handler {
|
||||
public:
|
||||
explicit redis_handler(shared_db& db, redis_coder& parser,
|
||||
acl::socket_stream& conn);
|
||||
~redis_handler() = default;
|
||||
|
||||
bool handle();
|
||||
|
||||
NODISCARD redis_ocache& get_cache() const {
|
||||
return parser_.get_cache();
|
||||
}
|
||||
|
||||
NODISCARD redis_coder& get_coder() {
|
||||
return coder_;
|
||||
}
|
||||
|
||||
NODISCARD shared_db& get_db() {
|
||||
return db_;
|
||||
}
|
||||
|
||||
private:
|
||||
shared_db& db_;
|
||||
redis_coder& parser_;
|
||||
acl::socket_stream& conn_;
|
||||
redis_coder builder_;
|
||||
redis_coder coder_;
|
||||
|
||||
bool handle_one(const redis_object& obj);
|
||||
|
||||
bool hset(const redis_object& obj);
|
||||
bool hget(const redis_object& obj);
|
||||
bool hdel(const redis_object& obj);
|
||||
bool hmset(const redis_object& obj);
|
||||
bool hmget(const redis_object& obj);
|
||||
bool hgetall(const redis_object& obj);
|
||||
};
|
||||
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/8/1.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "coder/redis_coder.h"
|
||||
#include "coder/redis_object.h"
|
||||
#include "dao/hash.h"
|
||||
|
||||
#include "redis_handler.h"
|
||||
#include "redis_hash.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
redis_hash::redis_hash(redis_handler &handler, const redis_object &obj)
|
||||
: redis_command(handler, obj)
|
||||
{}
|
||||
|
||||
bool redis_hash::hset(redis_coder &result) {
|
||||
if (obj_.size() < 4) {
|
||||
logger_error("invalid HSET command's size=%zd < 4", obj_.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto key = obj_[1];
|
||||
if (key == nullptr || *key == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto name = obj_[2];
|
||||
if (name == nullptr || *name == 0) {
|
||||
logger_error("name null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto value = obj_[3];
|
||||
if (value == nullptr || *value == 0) {
|
||||
logger_error("value null");
|
||||
return false;
|
||||
}
|
||||
|
||||
dao::hash dao;
|
||||
if (!dao.hset(handler_.get_db(), key, name, value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
result.create_object().set_number(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool redis_hash::hget(redis_coder &result) {
|
||||
if (obj_.size() < 3) {
|
||||
logger_error("invalid HGET command's size=%zd < 3", obj_.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto key = obj_[1];
|
||||
if (key == nullptr || *key == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto name = obj_[2];
|
||||
if (name == nullptr || *name == 0) {
|
||||
logger_error("name null");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string buff;
|
||||
dao::hash dao;
|
||||
if (!dao.hget(handler_.get_db(), key, name, buff)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//printf(">>hget: [%s]\r\n", buff.c_str());
|
||||
result.create_object().set_string(buff);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool redis_hash::hdel(redis_coder &result) {
|
||||
if (obj_.size() < 3) {
|
||||
logger_error("invalid HDEL params' size=%zd < 3", obj_.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto key = obj_[1];
|
||||
if (key == nullptr || *key == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto name = obj_[2];
|
||||
if (name == nullptr || *name == 0) {
|
||||
logger_error("name null");
|
||||
return false;
|
||||
}
|
||||
|
||||
dao::hash dao;
|
||||
int ret = dao.hdel(handler_.get_db(), key, name);
|
||||
result.create_object().set_number(ret);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool redis_hash::hmset(redis_coder &result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool redis_hash::hmget(redis_coder &result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool redis_hash::hgetall(redis_coder &result) {
|
||||
if (obj_.size() < 2) {
|
||||
logger_error("invalid HGETALL command's size=%zd < 2", obj_.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto key = obj_[1];
|
||||
if (key == nullptr || *key == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
dao::hash dao;
|
||||
if (!dao.hgetall(handler_.get_db(), key)) {
|
||||
logger_error("dao.hgetall error, key=%s", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& fields = dao.get_fields();
|
||||
auto& obj = result.create_object();
|
||||
for (const auto& it : fields) {
|
||||
obj.create_child().set_string(it.first, true)
|
||||
.create_child().set_string(it.second);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,25 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/8/1.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "redis_command.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class redis_coder;
|
||||
|
||||
class redis_hash : public redis_command {
|
||||
public:
|
||||
redis_hash(redis_handler& handler, const redis_object& obj);
|
||||
~redis_hash() override = default;
|
||||
|
||||
bool hset(redis_coder& result);
|
||||
bool hget(redis_coder& result);
|
||||
bool hdel(redis_coder& result);
|
||||
bool hmset(redis_coder& result);
|
||||
bool hmget(redis_coder& result);
|
||||
bool hgetall(redis_coder& result);
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,63 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/31.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "coder/redis_coder.h"
|
||||
#include "dao/key.h"
|
||||
|
||||
#include "redis_handler.h"
|
||||
#include "redis_key.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
redis_key::redis_key(redis_handler& handler, const redis_object& obj)
|
||||
: redis_command(handler, obj)
|
||||
{
|
||||
}
|
||||
|
||||
bool redis_key::del(redis_coder& result) {
|
||||
if (obj_.size() < 2) {
|
||||
logger_error("invalid SET params' size=%zd", obj_.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto key = obj_[1];
|
||||
if (key == nullptr || *key == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
dao::key dao;
|
||||
if (!dao.del(handler_.get_db(), key)) {
|
||||
logger_error("db del error, key=%s", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
result.create_object().set_number(1);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool redis_key::type(redis_coder& result) {
|
||||
if (obj_.size() < 2) {
|
||||
logger_error("invalid TYPE params' size=%zd", obj_.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto key = obj_[1];
|
||||
if (key == nullptr || *key == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string buff;
|
||||
dao::key dao;
|
||||
if (!dao.type(handler_.get_db(), key, buff)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
result.create_object().set_status(buff);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,23 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/31.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "redis_command.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class redis_handler;
|
||||
class redis_object;
|
||||
class redis_coder;
|
||||
|
||||
class redis_key : public redis_command {
|
||||
public:
|
||||
redis_key(redis_handler& handler, const redis_object& obj);
|
||||
~redis_key() override = default;
|
||||
|
||||
bool del(redis_coder& result);
|
||||
bool type(redis_coder& result);
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,68 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/8/2.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "coder/redis_coder.h"
|
||||
#include "coder/redis_object.h"
|
||||
|
||||
#include "redis_handler.h"
|
||||
#include "redis_server.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
#define EQ !strcasecmp
|
||||
|
||||
redis_server::redis_server(redis_handler &handler, const redis_object &obj)
|
||||
: redis_command(handler, obj)
|
||||
{}
|
||||
|
||||
bool redis_server::config(redis_coder &result) {
|
||||
if (obj_.size() < 3) {
|
||||
logger_error("invalid CONFIG command's size=%zd < 3", obj_.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto oper = obj_[1];
|
||||
if (oper == nullptr || *oper == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto name = obj_[2];
|
||||
if (name == nullptr || *name == 0) {
|
||||
logger_error("name null");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EQ(oper, "GET")) {
|
||||
return config_get(name, result);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool redis_server::config_get(const char *name, redis_coder &result) {
|
||||
if (EQ(name, "save")) {
|
||||
return config_get_save(result);
|
||||
} else if (EQ(name, "appendonly")) {
|
||||
return config_get_appendonly(result);
|
||||
}
|
||||
|
||||
result.create_object().set_error("unkown config entry");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool redis_server::config_get_save(redis_coder &result) {
|
||||
result.create_object().create_child().set_string("save", true)
|
||||
.create_child().set_string("3600 1 300 100 60 10000");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool redis_server::config_get_appendonly(redis_coder &result) {
|
||||
result.create_object().create_child().set_string("appendonly", true)
|
||||
.create_child().set_string("no");
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,25 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/8/2.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "redis_command.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class redis_coder;
|
||||
|
||||
class redis_server : public redis_command {
|
||||
public:
|
||||
redis_server(redis_handler &handler, const redis_object &obj);
|
||||
~redis_server() override = default;
|
||||
|
||||
bool config(redis_coder &result);
|
||||
|
||||
private:
|
||||
static bool config_get(const char *name, redis_coder &result);
|
||||
static bool config_get_save(redis_coder &result);
|
||||
static bool config_get_appendonly(redis_coder &result);
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,133 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/31.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "coder/redis_coder.h"
|
||||
#include "coder/redis_object.h"
|
||||
#include "dao/string.h"
|
||||
|
||||
#include "redis_handler.h"
|
||||
#include "redis_string.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
redis_string::redis_string(redis_handler& handler, const redis_object &obj)
|
||||
: redis_command(handler, obj)
|
||||
{}
|
||||
|
||||
bool redis_string::set(redis_coder& result) {
|
||||
if (obj_.size() < 3) {
|
||||
logger_error("invalid SET params' size=%zd", obj_.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto key = obj_[1];
|
||||
if (key == nullptr || *key == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto value = obj_[2];
|
||||
if (value == nullptr || *value == 0) {
|
||||
logger_error("value null");
|
||||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (!var_cfg_disable_serialize) {
|
||||
std::string buff;
|
||||
auto& coder = handler_.get_coder();
|
||||
coder.clear();
|
||||
|
||||
coder.create_object().create_child().set_string("string", true) // type
|
||||
.create_child().set_number(-1); // expire time
|
||||
coder.create_object().set_string(value);
|
||||
coder.to_string(buff);
|
||||
|
||||
//printf("buf=[%s]\n", buff.c_str());
|
||||
|
||||
if (!var_cfg_disable_save) {
|
||||
if (!handler_.get_db()->set(key, buff.c_str())) {
|
||||
logger_error("db set error, key=%s", key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (!var_cfg_disable_save) {
|
||||
dao::string dao;
|
||||
|
||||
if (!dao.set(handler_.get_db(), key, value)) {
|
||||
logger_error("db set error, key=%s", key);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
result.create_object().set_status("OK");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool redis_string::get(redis_coder& result) {
|
||||
if (obj_.size() < 2) {
|
||||
logger_error("invalid GET params' size=%zd", obj_.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto key = obj_[1];
|
||||
if (key == nullptr || *key == 0) {
|
||||
logger_error("key null");
|
||||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
std::string buff;
|
||||
if (!handler_.get_db()->get(key, buff) || buff.empty()) {
|
||||
logger_error("db get error, key=%s", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
//printf(">>>get key=%s, val=[%s]\n", key, buff.c_str());
|
||||
|
||||
auto& coder = handler_.get_coder();
|
||||
coder.clear();
|
||||
|
||||
size_t len = buff.size();
|
||||
(void) coder.update(buff.c_str(), len);
|
||||
if (len > 0) {
|
||||
logger_error("invalid buff in db, key=%s", key);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& objs2 = coder.get_objects();
|
||||
if (objs2.size() != 2) {
|
||||
logger_error("invalid object in db, key=%s, size=%zd", key, objs2.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto o = objs2[1];
|
||||
if (o->get_type() != REDIS_OBJ_STRING) {
|
||||
logger_error("invalid object type=%d, key=%s", (int) o->get_type(), key);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto v = o->get_str();
|
||||
if (v == nullptr || *v == 0) {
|
||||
logger_error("value null, key=%s", key);
|
||||
return false;
|
||||
}
|
||||
result.create_object().set_string(v);
|
||||
#else
|
||||
std::string buff;
|
||||
dao::string dao;
|
||||
if (!dao.get(handler_.get_db(), key, buff)) {
|
||||
return false;
|
||||
}
|
||||
result.create_object().set_string(buff);
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,22 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/31.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "redis_command.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class redis_coder;
|
||||
|
||||
class redis_string : public redis_command {
|
||||
public:
|
||||
redis_string(redis_handler& handler, const redis_object& obj);
|
||||
~redis_string() override = default;
|
||||
|
||||
bool set(redis_coder& result);
|
||||
bool get(redis_coder& result);
|
||||
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,11 +0,0 @@
|
||||
//
|
||||
// Created by shuxin zheng on 2023/7/27
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus >= 201703L
|
||||
# define NODISCARD [[nodiscard]]
|
||||
#else
|
||||
# define NODISCARD
|
||||
#endif
|
@ -1,75 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/19.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "redis_ocache.h"
|
||||
#include "redis_coder.h"
|
||||
#include "dao/string.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
#if 1
|
||||
#define EMPTY(x) ((x).size() == 0)
|
||||
#else
|
||||
#define EMPTY(x) ((x).empty())
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
#define LIKELY(x) (x)
|
||||
#define UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
redis_coder::redis_coder(redis_ocache& cache)
|
||||
: cache_(cache)
|
||||
{
|
||||
curr_ = cache_.get();
|
||||
}
|
||||
|
||||
redis_coder::~redis_coder() {
|
||||
clear();
|
||||
cache_.put(curr_);
|
||||
}
|
||||
|
||||
void redis_coder::clear() {
|
||||
for (auto obj : objs_) {
|
||||
cache_.put(obj);
|
||||
}
|
||||
objs_.clear();
|
||||
}
|
||||
|
||||
const char* redis_coder::update(const char* data, size_t& len) {
|
||||
while (len > 0) {
|
||||
data = curr_->update(data, len);
|
||||
if (curr_->finish()) {
|
||||
objs_.push_back(curr_);
|
||||
curr_ = cache_.get();
|
||||
} else if (curr_->failed()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
redis_object& redis_coder::create_object() {
|
||||
redis_object* obj = cache_.get();
|
||||
assert(obj);
|
||||
objs_.push_back(obj);
|
||||
return *obj;
|
||||
}
|
||||
|
||||
bool redis_coder::to_string(std::string& out) const {
|
||||
for (const auto& obj : objs_) {
|
||||
if (!obj->to_string(out)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,55 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "c++_patch.h"
|
||||
#include "redis_object.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class redis_ocache;
|
||||
|
||||
class redis_coder {
|
||||
public:
|
||||
explicit redis_coder(redis_ocache& cache);
|
||||
~redis_coder();
|
||||
|
||||
const char* update(const char* data, size_t& len);
|
||||
|
||||
NODISCARD const std::vector<redis_object*>& get_objects() const {
|
||||
return objs_;
|
||||
}
|
||||
|
||||
NODISCARD redis_object* get_curr() const {
|
||||
return curr_;
|
||||
}
|
||||
|
||||
void clear();
|
||||
|
||||
NODISCARD redis_ocache& get_cache() const {
|
||||
return cache_;
|
||||
}
|
||||
|
||||
public:
|
||||
NODISCARD redis_object& create_object();
|
||||
|
||||
bool to_string(std::string& out) const;
|
||||
|
||||
private:
|
||||
redis_ocache& cache_;
|
||||
std::vector<redis_object*> objs_;
|
||||
redis_object* curr_;
|
||||
};
|
||||
|
||||
bool test_redis_parse(const char* filepath);
|
||||
bool test_redis_parse_once(const char* filepath);
|
||||
bool test_redis_parse_stream(const char* filepath);
|
||||
|
||||
bool test_redis_build();
|
||||
size_t redis_build_bench(size_t max);
|
||||
size_t redis_parse_bench(const char* filepath, size_t max);
|
||||
|
||||
} // namespace pkv
|
@ -1,531 +0,0 @@
|
||||
//
|
||||
// Created by shuxin zheng on 2023/7/19.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "redis_ocache.h"
|
||||
#include "redis_object.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
#if 1
|
||||
#define EMPTY(x) ((x).size() == 0)
|
||||
#else
|
||||
#define EMPTY(x) ((x).empty())
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
#define LIKELY(x) (x)
|
||||
#define UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
#define CHECK(x) { if ((x) == nullptr) (x) = new std::vector<redis_object*>; }
|
||||
|
||||
redis_object::redis_object(redis_ocache& cache)
|
||||
: parent_(this)
|
||||
, cache_(cache)
|
||||
, objs_(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
redis_object::~redis_object() {
|
||||
reset();
|
||||
delete objs_;
|
||||
}
|
||||
|
||||
void redis_object::destroy() {
|
||||
delete this;
|
||||
}
|
||||
|
||||
void redis_object::set_parent(redis_object* parent) {
|
||||
if (parent) {
|
||||
parent_ = parent;
|
||||
}
|
||||
}
|
||||
|
||||
void redis_object::reset() {
|
||||
if (objs_) {
|
||||
for (auto obj : *objs_) {
|
||||
cache_.put(obj);
|
||||
}
|
||||
objs_->clear();
|
||||
}
|
||||
|
||||
status_ = redis_s_begin;
|
||||
type_ = REDIS_OBJ_UNKOWN;
|
||||
parent_ = this;
|
||||
obj_ = nullptr;
|
||||
cnt_ = 0;
|
||||
|
||||
buf_.clear();
|
||||
}
|
||||
|
||||
const char* redis_object::get_cmd() const {
|
||||
if (type_ == REDIS_OBJ_STRING) {
|
||||
return buf_.c_str();
|
||||
}
|
||||
|
||||
if (objs_ == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (UNLIKELY(EMPTY(*objs_) || type_ != REDIS_OBJ_ARRAY)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return (*objs_)[0]->get_cmd();
|
||||
}
|
||||
|
||||
const char* redis_object::get_str() const {
|
||||
if (type_ == REDIS_OBJ_STRING) {
|
||||
return buf_.c_str();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const char* redis_object::operator[](size_t i) const {
|
||||
if (objs_ == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (i >= objs_->size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return (*objs_)[i]->get_str();
|
||||
}
|
||||
|
||||
struct status_machine {
|
||||
/* 状态码 */
|
||||
int status;
|
||||
|
||||
/* 状态机处理函数 */
|
||||
const char* (redis_object::*func) (const char*, size_t&);
|
||||
};
|
||||
|
||||
static struct status_machine status_tab[] = {
|
||||
{ redis_s_begin, &redis_object::parse_begin },
|
||||
{ redis_s_status, &redis_object::parse_status },
|
||||
{ redis_s_error, &redis_object::parse_error },
|
||||
{ redis_s_number, &redis_object::parse_number },
|
||||
{ redis_s_strlen, &redis_object::parse_strlen },
|
||||
{ redis_s_string, &redis_object::parse_string },
|
||||
{ redis_s_strend, &redis_object::parse_strend },
|
||||
{ redis_s_arlen, &redis_object::parse_arlen },
|
||||
{ redis_s_array, &redis_object::parse_array },
|
||||
};
|
||||
|
||||
const char* redis_object::update(const char *data, size_t& len) {
|
||||
if (failed() || finish()) {
|
||||
return data;
|
||||
}
|
||||
|
||||
if (obj_) {
|
||||
return parse_object(data, len);
|
||||
}
|
||||
|
||||
while (len > 0) {
|
||||
//printf(">>>parse one: %s<<<\n", data);
|
||||
//printf(">>parse one<<<\n");
|
||||
data = (this->*(status_tab[status_].func))(data, len);
|
||||
if (status_ == redis_s_null || status_ == redis_s_finish) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
const char* redis_object::parse_object(const char* data, size_t& len) {
|
||||
assert(cnt_ > 0);
|
||||
assert(obj_);
|
||||
|
||||
data = obj_->update(data, len);
|
||||
if (obj_->failed()) {
|
||||
status_ = redis_s_null;
|
||||
return data;
|
||||
}
|
||||
|
||||
if (!obj_->finish()) {
|
||||
return data;
|
||||
}
|
||||
|
||||
CHECK(objs_);
|
||||
|
||||
objs_->push_back(obj_);
|
||||
|
||||
if (objs_->size() == (size_t) cnt_) {
|
||||
obj_ = nullptr;
|
||||
cnt_ = 0;
|
||||
status_ = redis_s_finish;
|
||||
return data;
|
||||
} else {
|
||||
obj_ = cache_.get();
|
||||
obj_->set_parent(this);
|
||||
return parse_object(data, len);
|
||||
}
|
||||
}
|
||||
|
||||
const char* redis_object::parse_begin(const char* data, size_t& len) {
|
||||
if (len == 0) {
|
||||
return data;
|
||||
}
|
||||
|
||||
switch (*data) {
|
||||
case ':': // INTEGER
|
||||
status_ = redis_s_number;
|
||||
break;
|
||||
case '+': // STATUS
|
||||
status_ = redis_s_status;
|
||||
break;
|
||||
case '-': // ERROR
|
||||
status_ = redis_s_error;
|
||||
break;
|
||||
case '$': // STRING
|
||||
status_ = redis_s_strlen;
|
||||
break;
|
||||
case '*': // ARRAY
|
||||
status_ = redis_s_arlen;
|
||||
break;
|
||||
default: // INVALID
|
||||
status_ = redis_s_null;
|
||||
break;
|
||||
}
|
||||
|
||||
len--;
|
||||
data++;
|
||||
return data;
|
||||
}
|
||||
|
||||
const char* redis_object::parse_status(const char* data, size_t& len) {
|
||||
bool found = false;
|
||||
data = get_line(data, len, buf_, found);
|
||||
if (!found) {
|
||||
assert(len == 0);
|
||||
return data;
|
||||
}
|
||||
|
||||
if (UNLIKELY(EMPTY(buf_))) {
|
||||
status_ = redis_s_null;
|
||||
return data;
|
||||
}
|
||||
|
||||
type_ = REDIS_OBJ_STATUS;
|
||||
status_ = redis_s_finish;
|
||||
return data;
|
||||
}
|
||||
|
||||
const char* redis_object::parse_error(const char* data, size_t& len) {
|
||||
bool found = false;
|
||||
data = get_line(data, len, buf_, found);
|
||||
if (!found) {
|
||||
assert(len == 0);
|
||||
return data;
|
||||
}
|
||||
|
||||
if (UNLIKELY(EMPTY(buf_))) {
|
||||
status_ = redis_s_null;
|
||||
return data;
|
||||
}
|
||||
|
||||
type_ = REDIS_OBJ_ERROR;
|
||||
status_ = redis_s_finish;
|
||||
return data;
|
||||
}
|
||||
|
||||
const char* redis_object::parse_number(const char* data, size_t& len) {
|
||||
bool found = false;
|
||||
data = get_line(data, len, buf_, found);
|
||||
if (!found) {
|
||||
assert(len == 0);
|
||||
return data;
|
||||
}
|
||||
|
||||
if (UNLIKELY(EMPTY(buf_))) {
|
||||
status_ = redis_s_null;
|
||||
return data;
|
||||
}
|
||||
|
||||
type_ = REDIS_OBJ_INTEGER;
|
||||
status_ = redis_s_finish;
|
||||
return data;
|
||||
}
|
||||
|
||||
const char* redis_object::parse_strlen(const char* data, size_t& len) {
|
||||
bool found = false;
|
||||
cnt_ = 0;
|
||||
data = get_length(data, len, cnt_, found);
|
||||
if (status_ == redis_s_null || !found) {
|
||||
return data;
|
||||
}
|
||||
|
||||
if (cnt_ <= 0) {
|
||||
status_ = redis_s_finish;
|
||||
return data;
|
||||
}
|
||||
|
||||
type_ = REDIS_OBJ_STRING;
|
||||
status_ = redis_s_string;
|
||||
|
||||
return parse_string(data, len);
|
||||
}
|
||||
|
||||
const char* redis_object::parse_string(const char* data, size_t& len) {
|
||||
buf_.reserve((size_t) cnt_);
|
||||
data = get_data(data, len, (size_t) cnt_);
|
||||
if (buf_.size() == (size_t) cnt_) {
|
||||
status_ = redis_s_strend;
|
||||
return parse_strend(data, len);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
const char* redis_object::parse_strend(const char* data, size_t& len) {
|
||||
bool found = false;
|
||||
std::string buf;
|
||||
data = get_line(data, len, buf, found);
|
||||
|
||||
// If the buf_ not empty, some data other '\r\n' got.
|
||||
if (UNLIKELY(!EMPTY(buf))) {
|
||||
status_ = redis_s_null;
|
||||
return data;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
assert(len == 0);
|
||||
return data;
|
||||
}
|
||||
|
||||
status_ = redis_s_finish;
|
||||
return data;
|
||||
}
|
||||
|
||||
const char* redis_object::parse_arlen(const char* data, size_t& len) {
|
||||
bool found = false;
|
||||
cnt_ = 0;
|
||||
data = get_length(data, len, cnt_, found);
|
||||
if (status_ == redis_s_null || !found) {
|
||||
return data;
|
||||
}
|
||||
|
||||
if (cnt_ <= 0) {
|
||||
status_ = redis_s_finish;
|
||||
return data;
|
||||
}
|
||||
|
||||
type_ = REDIS_OBJ_ARRAY;
|
||||
status_ = redis_s_array;
|
||||
|
||||
obj_ = cache_.get();
|
||||
obj_->set_parent(this);
|
||||
|
||||
return parse_array(data, len);
|
||||
}
|
||||
|
||||
const char* redis_object::parse_array(const char* data, size_t& len) {
|
||||
assert(obj_ != nullptr);
|
||||
|
||||
return parse_object(data, len);
|
||||
}
|
||||
|
||||
const char* redis_object::get_data(const char* data, size_t& len, size_t want) {
|
||||
size_t n = buf_.size();
|
||||
assert(n < want);
|
||||
|
||||
want -= n;
|
||||
|
||||
#if 1
|
||||
if (want > len) {
|
||||
want = len;
|
||||
len = 0;
|
||||
} else {
|
||||
len -= want;
|
||||
}
|
||||
|
||||
buf_.append(data, want);
|
||||
data += want;
|
||||
#else
|
||||
for (size_t i = 0; i < want && len > 0; i++) {
|
||||
buf_.push_back(*data++);
|
||||
len--;
|
||||
}
|
||||
#endif
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
const char* redis_object::get_length(const char* data, size_t& len,
|
||||
int& res, bool& found) {
|
||||
data = get_line(data, len, buf_, found);
|
||||
if (!found) {
|
||||
assert(len == 0);
|
||||
return data;
|
||||
}
|
||||
|
||||
if (UNLIKELY(EMPTY(buf_))) {
|
||||
status_ = redis_s_null;
|
||||
return data;
|
||||
}
|
||||
|
||||
// buf_.push_back('\0'); // The c++11 promise the last char is null.
|
||||
char* endptr;
|
||||
res = (int) strtol(buf_.c_str(), &endptr, 10);
|
||||
buf_.clear();
|
||||
|
||||
if (endptr == buf_.c_str() || *endptr != '\0') {
|
||||
status_ = redis_s_null;
|
||||
return data;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
const char* redis_object::get_line(const char* data, size_t& len,
|
||||
std::string& buf, bool& found) {
|
||||
while (len > 0) {
|
||||
switch (*data) {
|
||||
case '\r':
|
||||
data++;
|
||||
len--;
|
||||
break;
|
||||
case '\n':
|
||||
data++;
|
||||
len--;
|
||||
found = true;
|
||||
return data;
|
||||
default:
|
||||
buf.push_back(*data++);
|
||||
len--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
bool redis_object::to_string(std::string& out) const {
|
||||
//#define USE_UNIX_CRLF
|
||||
#ifdef USE_UNIX_CRLF
|
||||
#define CRLF "\n"
|
||||
#else
|
||||
#define CRLF "\r\n"
|
||||
#endif
|
||||
|
||||
#define USE_APPEND
|
||||
|
||||
if (objs_ && !EMPTY(*objs_)) {
|
||||
#ifdef USE_APPEND
|
||||
out.append("*").append(std::to_string(objs_->size())).append(CRLF);
|
||||
#else
|
||||
out += "*";
|
||||
out += std::to_string(objs_->size());
|
||||
out += CRLF;
|
||||
#endif
|
||||
|
||||
for (const auto& obj : *objs_) {
|
||||
if (!obj->to_string(out)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//assert(UNLIKELY(!EMPTY(buf_)));
|
||||
|
||||
switch (type_) {
|
||||
case REDIS_OBJ_STATUS:
|
||||
#ifdef USE_APPEND
|
||||
out.append("+").append(buf_.c_str(), buf_.size()).append(CRLF);
|
||||
#else
|
||||
out += "+";
|
||||
out.append(buf_.c_str(), buf_.size());
|
||||
out += CRLF;
|
||||
#endif
|
||||
break;
|
||||
case REDIS_OBJ_ERROR:
|
||||
#ifdef USE_APPEND
|
||||
out.append("-").append(buf_.c_str(), buf_.size()).append(CRLF);
|
||||
#else
|
||||
out += "-";
|
||||
out.append(buf_.c_str(), buf_.size());
|
||||
out += CRLF;
|
||||
#endif
|
||||
break;
|
||||
case REDIS_OBJ_INTEGER:
|
||||
#ifdef USE_APPEND
|
||||
out.append(":").append(buf_.c_str(), buf_.size()).append(CRLF);
|
||||
#else
|
||||
out += ":";
|
||||
out.append(buf_.c_str(), buf_.size());
|
||||
out += CRLF;
|
||||
#endif
|
||||
break;
|
||||
case REDIS_OBJ_STRING:
|
||||
#ifdef USE_APPEND
|
||||
out.append("$").append(std::to_string(buf_.size())).append(CRLF)
|
||||
.append(buf_.c_str(), buf_.size()).append(CRLF);
|
||||
#else
|
||||
out += "$";
|
||||
out += std::to_string(buf_.size());
|
||||
out += CRLF;
|
||||
out.append(buf_.c_str(), buf_.size());
|
||||
out += CRLF;
|
||||
#endif
|
||||
break;
|
||||
//case acl::REDIS_RESULT_ARRAY:
|
||||
// break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
redis_object& redis_object::set_status(const std::string& data,
|
||||
bool return_parent) {
|
||||
type_ = REDIS_OBJ_STATUS;
|
||||
buf_ = data;
|
||||
return return_parent ? *parent_ : *this;
|
||||
}
|
||||
|
||||
redis_object& redis_object::set_error(const std::string& data,
|
||||
bool return_parent) {
|
||||
type_ = REDIS_OBJ_ERROR;
|
||||
buf_ = data;
|
||||
return return_parent ? *parent_ : *this;
|
||||
}
|
||||
|
||||
redis_object& redis_object::set_number(long long n, bool return_parent) {
|
||||
type_ = REDIS_OBJ_INTEGER;
|
||||
buf_ = std::to_string(n);
|
||||
return return_parent ? *parent_ : *this;
|
||||
}
|
||||
|
||||
redis_object& redis_object::set_string(const std::string &data,
|
||||
bool return_parent) {
|
||||
type_ = REDIS_OBJ_STRING;
|
||||
if (UNLIKELY(!EMPTY(data))) {
|
||||
buf_ = data;
|
||||
}
|
||||
return return_parent ? *parent_ : *this;
|
||||
}
|
||||
|
||||
redis_object& redis_object::create_child() {
|
||||
redis_object* obj = cache_.get();
|
||||
obj->set_parent(this);
|
||||
|
||||
CHECK(objs_);
|
||||
objs_->push_back(obj);
|
||||
|
||||
if (obj_ == nullptr) {
|
||||
// The last one is NULL.
|
||||
type_ = REDIS_OBJ_ARRAY;
|
||||
}
|
||||
|
||||
cnt_ = objs_->size();
|
||||
return *obj;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,110 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "c++_patch.h"
|
||||
#include "redis_type.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
typedef enum {
|
||||
REDIS_OBJ_UNKOWN,
|
||||
REDIS_OBJ_ERROR,
|
||||
REDIS_OBJ_STATUS,
|
||||
REDIS_OBJ_INTEGER,
|
||||
REDIS_OBJ_STRING,
|
||||
REDIS_OBJ_ARRAY,
|
||||
} redis_obj_t;
|
||||
|
||||
class redis_ocache;
|
||||
|
||||
class redis_object {
|
||||
public:
|
||||
explicit redis_object(redis_ocache& cache);
|
||||
|
||||
void destroy();
|
||||
|
||||
redis_object(const redis_object&) = delete;
|
||||
void operator=(const redis_object&) = delete;
|
||||
|
||||
void set_parent(redis_object* parent);
|
||||
void reset();
|
||||
|
||||
//private:
|
||||
~redis_object();
|
||||
|
||||
public:
|
||||
const char* update(const char* data, size_t& len);
|
||||
|
||||
NODISCARD bool finish() const {
|
||||
return status_ == redis_s_finish;
|
||||
}
|
||||
|
||||
NODISCARD bool failed() const {
|
||||
return status_ == redis_s_null;
|
||||
}
|
||||
|
||||
NODISCARD int get_status() const {
|
||||
return status_;
|
||||
}
|
||||
|
||||
NODISCARD redis_obj_t get_type() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
NODISCARD const char* get_cmd() const;
|
||||
|
||||
NODISCARD const char* get_str() const;
|
||||
|
||||
NODISCARD size_t size() const {
|
||||
return objs_ ? objs_->size() : 0;
|
||||
}
|
||||
|
||||
NODISCARD const char* operator[](size_t i) const;
|
||||
|
||||
public:
|
||||
redis_object& set_status(const std::string& data, bool return_parent = false);
|
||||
redis_object& set_error(const std::string& data, bool return_parent = false);
|
||||
redis_object& set_number(long long n, bool return_parent = false);
|
||||
redis_object& set_string(const std::string& data, bool return_parent = false);
|
||||
redis_object& create_child();
|
||||
|
||||
bool to_string(std::string& out) const;
|
||||
|
||||
private:
|
||||
int status_ = redis_s_begin;
|
||||
redis_obj_t type_ = REDIS_OBJ_UNKOWN;
|
||||
|
||||
redis_object* parent_ = nullptr;
|
||||
redis_object* obj_ = nullptr;
|
||||
|
||||
std::string buf_;
|
||||
int cnt_ = 0;
|
||||
|
||||
redis_ocache& cache_;
|
||||
std::vector<redis_object*>* objs_;
|
||||
|
||||
private:
|
||||
static const char* get_line(const char*, size_t&, std::string&, bool&);
|
||||
const char* get_length(const char*, size_t&, int&, bool&);
|
||||
const char* get_data(const char*, size_t&, size_t);
|
||||
|
||||
const char* parse_object(const char*, size_t&);
|
||||
|
||||
public:
|
||||
const char* parse_begin(const char* data, size_t& len);
|
||||
const char* parse_status(const char* data, size_t& len);
|
||||
const char* parse_error(const char* data, size_t& len);
|
||||
const char* parse_number(const char* data, size_t& len);
|
||||
const char* parse_strlen(const char* data, size_t& len);
|
||||
const char* parse_string(const char* data, size_t& len);
|
||||
const char* parse_strend(const char* data, size_t& len);
|
||||
const char* parse_arlen(const char* data, size_t& len);
|
||||
const char* parse_array(const char* data, size_t& len);
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,85 +0,0 @@
|
||||
//
|
||||
// Created by zsx on 2023/8/3.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "redis_object.h"
|
||||
#include "redis_ocache.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
#if 1
|
||||
#define EMPTY(x) ((x).size() == 0)
|
||||
#else
|
||||
#define EMPTY(x) ((x).empty())
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define LIKELY(x) __builtin_expect(!!(x), 1)
|
||||
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
#define LIKELY(x) (x)
|
||||
#define UNLIKELY(x) (x)
|
||||
#endif
|
||||
|
||||
redis_ocache::redis_ocache(size_t max) : max_(max) {
|
||||
#ifndef USE_VECTOR
|
||||
cache_ = new redis_object* [max];
|
||||
for (size_t i = 0; i < max; i++) {
|
||||
cache_[i] = NULL;
|
||||
}
|
||||
pos_ = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
redis_ocache::~redis_ocache() {
|
||||
#ifdef USE_VECTOR
|
||||
for (auto o : cache_) {
|
||||
o->destroy();
|
||||
}
|
||||
#else
|
||||
for (size_t i = 0; i < pos_; i++) {
|
||||
cache_[i]->destroy();
|
||||
}
|
||||
delete [] cache_;
|
||||
#endif
|
||||
}
|
||||
|
||||
redis_object *redis_ocache::get() {
|
||||
#ifdef USE_VECTOR
|
||||
if (UNLIKELY(EMPTY(cache_))) {
|
||||
return new redis_object(*this);
|
||||
} else {
|
||||
auto obj = cache_.back();
|
||||
cache_.pop_back();
|
||||
return obj;
|
||||
}
|
||||
#else
|
||||
if (LIKELY(pos_ > 0)) {
|
||||
return cache_[--pos_];
|
||||
} else {
|
||||
return new redis_object(*this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void redis_ocache::put(redis_object* obj) {
|
||||
#ifdef USE_VECTOR
|
||||
if (cache_.size() < max_) {
|
||||
cache_.push_back(obj);
|
||||
obj->reset();
|
||||
} else {
|
||||
obj->destroy();
|
||||
}
|
||||
#else
|
||||
if (LIKELY(pos_ < max_)) {
|
||||
assert(obj);
|
||||
cache_[pos_++] = obj;
|
||||
obj->reset();
|
||||
} else {
|
||||
obj->destroy();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,30 +0,0 @@
|
||||
//
|
||||
// Created by zsx on 2023/8/3.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class redis_object;
|
||||
|
||||
class redis_ocache {
|
||||
public:
|
||||
redis_ocache(size_t max = 100);
|
||||
~redis_ocache();
|
||||
|
||||
redis_object* get();
|
||||
void put(redis_object* obj);
|
||||
|
||||
private:
|
||||
size_t max_;
|
||||
#ifdef USE_VECTOR
|
||||
std::vector<redis_object*> cache_;
|
||||
#else
|
||||
redis_object** cache_;
|
||||
size_t pos_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,23 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace pkv {
|
||||
|
||||
enum {
|
||||
redis_s_begin,
|
||||
redis_s_status,
|
||||
redis_s_error,
|
||||
redis_s_number,
|
||||
redis_s_strlen,
|
||||
redis_s_string,
|
||||
redis_s_strend,
|
||||
redis_s_arlen,
|
||||
redis_s_array,
|
||||
redis_s_null,
|
||||
redis_s_finish,
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,74 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "dao_base.h"
|
||||
|
||||
namespace pkv {
|
||||
namespace dao {
|
||||
|
||||
dao_base::dao_base()
|
||||
: finished_(false)
|
||||
, result_(nullptr)
|
||||
, w_doc_(nullptr)
|
||||
, w_root_(nullptr)
|
||||
, r_doc_(nullptr)
|
||||
, r_root_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
dao_base::~dao_base() {
|
||||
if (result_) {
|
||||
free(result_);
|
||||
}
|
||||
|
||||
if (w_doc_) {
|
||||
yyjson_mut_doc_free(w_doc_);
|
||||
}
|
||||
|
||||
if (r_doc_) {
|
||||
yyjson_doc_free(r_doc_);
|
||||
}
|
||||
}
|
||||
|
||||
void dao_base::create_writer() {
|
||||
if (w_doc_ == nullptr) {
|
||||
w_doc_ = yyjson_mut_doc_new(NULL);
|
||||
w_root_ = yyjson_mut_obj(w_doc_);
|
||||
yyjson_mut_doc_set_root(w_doc_, w_root_);
|
||||
}
|
||||
}
|
||||
|
||||
yyjson_val* dao_base::read(shared_db& db, const std::string& key) {
|
||||
std::string buff;
|
||||
if (!db->get(key, buff)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
r_doc_ = yyjson_read(buff.c_str(), buff.size(), 0);
|
||||
|
||||
if (r_doc_ == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
r_root_ = yyjson_doc_get_root(r_doc_);
|
||||
yyjson_val* val = yyjson_obj_get(r_root_, "type");
|
||||
if (val == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto type = yyjson_get_str(val);
|
||||
auto len = yyjson_get_len(val);
|
||||
if (type && len > 0) {
|
||||
type_ = type;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return yyjson_obj_get(r_root_, "data");
|
||||
}
|
||||
|
||||
bool dao_base::save(shared_db& db, const std::string& key,
|
||||
const std::string& data) {
|
||||
return db->set(key, data);
|
||||
}
|
||||
|
||||
} // namespace dao
|
||||
} // namespace pkv
|
@ -1,38 +0,0 @@
|
||||
#pragma once
|
||||
#include <yyjson.h>
|
||||
#include "db/db.h"
|
||||
|
||||
namespace pkv {
|
||||
namespace dao {
|
||||
|
||||
class dao_base {
|
||||
public:
|
||||
dao_base();
|
||||
virtual ~dao_base();
|
||||
|
||||
public:
|
||||
bool save(shared_db& db, const std::string& key, const std::string& data);
|
||||
yyjson_val* read(shared_db& db, const std::string& key);
|
||||
|
||||
protected:
|
||||
bool finished_;
|
||||
std::string type_;
|
||||
char* result_;
|
||||
yyjson_mut_doc* w_doc_;
|
||||
yyjson_mut_val* w_root_;
|
||||
yyjson_doc* r_doc_;
|
||||
yyjson_val* r_root_;
|
||||
|
||||
void create_writer();
|
||||
|
||||
yyjson_doc* get_reader_doc() const {
|
||||
return r_doc_;
|
||||
}
|
||||
|
||||
yyjson_val* get_reader_root() const {
|
||||
return r_root_;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace dao
|
||||
} // namespace pkv
|
@ -1,138 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "dao/hash.h"
|
||||
|
||||
namespace pkv {
|
||||
namespace dao {
|
||||
|
||||
hash::hash() {}
|
||||
|
||||
bool hash::to_string(std::string& out) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const char* hash::build() {
|
||||
if (this->finished_) {
|
||||
return this->result_;
|
||||
}
|
||||
|
||||
this->create_writer();
|
||||
|
||||
yyjson_mut_obj_add_str(this->w_doc_, this->w_root_, "type", "hash");
|
||||
yyjson_mut_obj_add_int(this->w_doc_, this->w_root_, "expire", -1);
|
||||
|
||||
auto data = yyjson_mut_obj(this->w_doc_);
|
||||
yyjson_mut_obj_add_val(this->w_doc_, this->w_root_, "data", data);
|
||||
|
||||
for (const auto& cit : fields_) {
|
||||
yyjson_mut_obj_add_str(this->w_doc_, data, cit.first.c_str(),
|
||||
cit.second.c_str());
|
||||
}
|
||||
|
||||
this->result_ = yyjson_mut_write(this->w_doc_, 0, NULL);
|
||||
|
||||
this->finished_ = true;
|
||||
return result_;
|
||||
}
|
||||
|
||||
bool hash::hset(shared_db& db, const std::string& key, const std::string& name,
|
||||
const std::string& value) {
|
||||
|
||||
(void) hgetall(db, key);
|
||||
fields_[name] = value;
|
||||
|
||||
if (build() == nullptr) {
|
||||
logger_error("build for hset error, key=%s, name=%s, value=%s",
|
||||
key.c_str(), name.c_str(), value.c_str());
|
||||
return false;
|
||||
}
|
||||
//printf(">>>%s<<<\r\n", this->result_);
|
||||
return this->save(db, key, this->result_);
|
||||
}
|
||||
|
||||
int hash::hdel(shared_db& db, const std::string& key, const std::string& name) {
|
||||
if (!hgetall(db, key)) {
|
||||
return -1;
|
||||
}
|
||||
auto it = fields_.find(name);
|
||||
if (it == fields_.end()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
fields_.erase(it);
|
||||
|
||||
if (fields_.empty()) {
|
||||
db->del(key);
|
||||
} else if (build() == nullptr) {
|
||||
logger_error("build for hset error, key=%s, name=%s",
|
||||
key.c_str(), name.c_str());
|
||||
return -1;
|
||||
} else if (!this->save(db, key, this->result_)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// { "type": "hash", "expire": -1, "data": { "name1": "value1", "name2": "value2" }}
|
||||
|
||||
bool hash::hget(shared_db& db, const std::string& key, const std::string& name,
|
||||
std::string& value) {
|
||||
auto data = this->read(db, key);
|
||||
if (data == nullptr) {
|
||||
logger_error("db read error, key=%s", key.c_str());
|
||||
return false;
|
||||
}
|
||||
if (strcasecmp(type_.c_str(), "hash") != 0) {
|
||||
logger_error("nvalid type=%s, key=%s", type_.c_str(), key.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
yyjson_obj_iter iter;
|
||||
yyjson_obj_iter_init(data, &iter);
|
||||
|
||||
yyjson_val* vkey, *vval;
|
||||
while ((vkey = yyjson_obj_iter_next(&iter))) {
|
||||
vval = yyjson_obj_iter_get_val(vkey);
|
||||
if (yyjson_equals_str(vkey, name.c_str())) {
|
||||
auto v = yyjson_get_str(vval);
|
||||
if (v) {
|
||||
value = v;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool hash::hgetall(shared_db& db, const std::string& key) {
|
||||
fields_.clear();
|
||||
|
||||
auto data = this->read(db, key);
|
||||
if (data == nullptr) {
|
||||
logger_error("db read error, key=%s", key.c_str());
|
||||
return false;
|
||||
}
|
||||
if (strcasecmp(type_.c_str(), "hash") != 0) {
|
||||
logger_error("nvalid type=%s, key=%s", type_.c_str(), key.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
yyjson_obj_iter iter;
|
||||
yyjson_obj_iter_init(data, &iter);
|
||||
|
||||
yyjson_val* vkey, *vval;
|
||||
while ((vkey = yyjson_obj_iter_next(&iter))) {
|
||||
vval = yyjson_obj_iter_get_val(vkey);
|
||||
auto n = yyjson_get_str(vkey);
|
||||
auto v = yyjson_get_str(vval);
|
||||
if (n && v) {
|
||||
fields_[n] = v;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace dao
|
||||
} // namespace pkv
|
@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
#include "db/db.h"
|
||||
#include "dao_base.h"
|
||||
|
||||
namespace pkv {
|
||||
namespace dao {
|
||||
|
||||
class hash : public dao_base {
|
||||
public:
|
||||
hash();
|
||||
~hash() override = default;
|
||||
|
||||
int hdel(shared_db& db, const std::string& key, const std::string& name);
|
||||
|
||||
bool hset(shared_db& db, const std::string& key, const std::string& name,
|
||||
const std::string& value);
|
||||
|
||||
bool hget(shared_db& db, const std::string& key, const std::string& name,
|
||||
std::string& value);
|
||||
|
||||
bool hgetall(shared_db& db, const std::string& key);
|
||||
|
||||
const std::map<std::string, std::string>& get_fields() {
|
||||
return fields_;
|
||||
}
|
||||
|
||||
public:
|
||||
bool to_string(std::string& out);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::string> fields_;
|
||||
|
||||
const char* build();
|
||||
};
|
||||
|
||||
} // namespace dao
|
||||
} // namespace pkv
|
@ -1,27 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "key.h"
|
||||
|
||||
namespace pkv {
|
||||
namespace dao {
|
||||
|
||||
key::key() {}
|
||||
|
||||
bool key::to_string(std::string& out) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool key::del(shared_db& db, const std::string& keyname) {
|
||||
return db->del(keyname);
|
||||
}
|
||||
|
||||
bool key::type(shared_db& db, const std::string& keyname, std::string& out) {
|
||||
auto data = this->read(db, keyname);
|
||||
if (data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
out = this->type_;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace dao
|
||||
} // namespace pkv
|
@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
#include "db/db.h"
|
||||
#include "dao_base.h"
|
||||
|
||||
namespace pkv {
|
||||
namespace dao {
|
||||
|
||||
class key : public dao_base {
|
||||
public:
|
||||
key();
|
||||
~key() override = default;
|
||||
|
||||
bool del(shared_db& db, const std::string& key);
|
||||
bool type(shared_db& db, const std::string& key, std::string& out);
|
||||
|
||||
public:
|
||||
bool to_string(std::string& out);
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace dao
|
||||
} // namespace pkv
|
@ -1,73 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "string.h"
|
||||
|
||||
namespace pkv {
|
||||
namespace dao {
|
||||
|
||||
string::string() : data_(nullptr) {}
|
||||
|
||||
bool string::to_string(std::string& out) {
|
||||
auto res = build();
|
||||
if (res && *res) {
|
||||
out = res;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void string::set_string(const char* data) {
|
||||
data_ = data;
|
||||
}
|
||||
|
||||
const char* string::build() {
|
||||
if (this->finished_) {
|
||||
return this->result_;
|
||||
}
|
||||
|
||||
this->create_writer();
|
||||
|
||||
yyjson_mut_obj_add_str(this->w_doc_, this->w_root_, "type", "string");
|
||||
yyjson_mut_obj_add_int(this->w_doc_, this->w_root_, "expire", -1);
|
||||
yyjson_mut_obj_add_str(this->w_doc_, this->w_root_, "data", data_);
|
||||
this->result_ = yyjson_mut_write(this->w_doc_, 0, NULL);
|
||||
|
||||
finished_ = true;
|
||||
return result_;
|
||||
}
|
||||
|
||||
bool string::set(shared_db& db, const std::string& key, const char* data) {
|
||||
data_ = data;
|
||||
if (build() == nullptr) {
|
||||
return false;
|
||||
}
|
||||
return this->save(db, key, this->result_);
|
||||
}
|
||||
|
||||
bool string::get(shared_db& db, const std::string& key, std::string& out) {
|
||||
auto data = this->read(db, key);
|
||||
if (data == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (strcasecmp(this->type_.c_str(), "string") != 0) {
|
||||
logger_error("invalid type=%s, key=%s", type_.c_str(), key.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
auto type = yyjson_get_type(data);
|
||||
if (type != YYJSON_TYPE_STR) {
|
||||
logger_error("invalid json_node type=%d", (int) type);
|
||||
return false;
|
||||
}
|
||||
|
||||
auto v = yyjson_get_str(data);
|
||||
auto n = yyjson_get_len(data);
|
||||
if (v && n > 0) {
|
||||
out.append(v, n);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace dao
|
||||
} // namespace pkv
|
@ -1,28 +0,0 @@
|
||||
#pragma once
|
||||
#include "db/db.h"
|
||||
#include "dao_base.h"
|
||||
|
||||
namespace pkv {
|
||||
namespace dao {
|
||||
|
||||
class string : public dao_base {
|
||||
public:
|
||||
string();
|
||||
~string() override = default;
|
||||
|
||||
bool set(shared_db& db, const std::string& key, const char* data);
|
||||
bool get(shared_db& db, const std::string& key, std::string& out);
|
||||
|
||||
public:
|
||||
void set_string(const char* data);
|
||||
bool to_string(std::string& out);
|
||||
|
||||
protected:
|
||||
const char* build();
|
||||
|
||||
private:
|
||||
const char* data_;
|
||||
};
|
||||
|
||||
} // namespace dao
|
||||
} // namespace pkv
|
@ -1,53 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef HAS_ROCKSDB
|
||||
#include "rocksdb/rdb.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAS_WT
|
||||
#include "wt/wdb.h"
|
||||
#endif
|
||||
|
||||
#include "db.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class dummy_db : public db {
|
||||
public:
|
||||
dummy_db() = default;
|
||||
~dummy_db() override = default;
|
||||
|
||||
bool open(const char*) override {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool set(const std::string&, const std::string&) override {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool get(const std::string&, std::string&) override {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool del(const std::string&) override {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
shared_db db::create_rdb() {
|
||||
#ifdef HAS_ROCKSDB
|
||||
return std::make_shared<rdb>();
|
||||
#else
|
||||
return std::make_shared<dummy_db>();
|
||||
#endif
|
||||
}
|
||||
|
||||
shared_db db::create_wdb() {
|
||||
#ifdef HAS_WT
|
||||
return std::make_shared<wdb>();
|
||||
#else
|
||||
return std::make_shared<dummy_db>();
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class db;
|
||||
using shared_db = std::shared_ptr<db>;
|
||||
|
||||
class db {
|
||||
public:
|
||||
db() = default;
|
||||
virtual ~db() = default;
|
||||
|
||||
virtual bool open(const char* path) = 0;
|
||||
virtual bool set(const std::string& key, const std::string& value) = 0;
|
||||
virtual bool get(const std::string& key, std::string& value) = 0;
|
||||
virtual bool del(const std::string& key) = 0;
|
||||
|
||||
public:
|
||||
virtual const char* get_dbtype() const = 0;
|
||||
|
||||
static shared_db create_rdb();
|
||||
static shared_db create_wdb();
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,78 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef HAS_ROCKSDB
|
||||
|
||||
#include "rocksdb/db.h"
|
||||
#include "rocksdb/slice.h"
|
||||
#include "rocksdb/options.h"
|
||||
|
||||
#include "rdb.h"
|
||||
|
||||
using namespace rocksdb;
|
||||
|
||||
namespace pkv {
|
||||
|
||||
rdb::rdb() : db_(nullptr) {}
|
||||
|
||||
rdb::~rdb() {
|
||||
delete db_;
|
||||
logger("rdb in %s closed", path_.c_str());
|
||||
}
|
||||
|
||||
bool rdb::open(const char* path) {
|
||||
path_ = path;
|
||||
path_ += "/rdb";
|
||||
|
||||
if (acl_make_dirs(path_.c_str(), 0755) == -1) {
|
||||
logger_error("create %s error=%s", path_.c_str(), acl::last_serror());
|
||||
return -1;
|
||||
}
|
||||
|
||||
Options options;
|
||||
options.IncreaseParallelism();
|
||||
// options.OptimizeLevelStyleCompaction();
|
||||
options.create_if_missing = true;
|
||||
Status s = DB::Open(options, path_.c_str(), &db_);
|
||||
if (!s.ok()) {
|
||||
logger_error("open %s db error: %s", path_.c_str(), s.getState());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rdb::set(const std::string& key, const std::string& value) {
|
||||
Status s = db_->Put(WriteOptions(), key, value);
|
||||
if (!s.ok()) {
|
||||
logger_error("put to %s error: %s, key=%s",
|
||||
path_.c_str(), s.getState(), key.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rdb::get(const std::string& key, std::string& value) {
|
||||
Status s = db_->Get(ReadOptions(), key, &value);
|
||||
if (!s.ok()) {
|
||||
logger_error("get from %s error: %s, key=%s, data=%zd",
|
||||
path_.c_str(), s.getState(), key.c_str(), value.size());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rdb::del(const std::string& key) {
|
||||
Status s = db_->Delete(WriteOptions(), key);
|
||||
if (!s.ok()) {
|
||||
logger_error("del from %s error: %s", path_.c_str(), s.getState());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
||||
|
||||
#endif // HAS_ROCKSDB
|
@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "../db.h"
|
||||
|
||||
#ifdef HAS_ROCKSDB
|
||||
|
||||
namespace rocksdb {
|
||||
class DB;
|
||||
}
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class rdb : public db {
|
||||
public:
|
||||
rdb();
|
||||
~rdb() override;
|
||||
|
||||
protected:
|
||||
// @override
|
||||
bool open(const char* path) override;
|
||||
|
||||
// @override
|
||||
bool set(const std::string& key, const std::string& value) override;
|
||||
|
||||
// @override
|
||||
bool get(const std::string& key, std::string& value) override;
|
||||
|
||||
// @override
|
||||
bool del(const std::string& key) override;
|
||||
|
||||
public:
|
||||
// @override
|
||||
const char* get_dbtype() const override {
|
||||
return "rdb";
|
||||
}
|
||||
|
||||
private:
|
||||
std::string path_;
|
||||
rocksdb::DB* db_;
|
||||
};
|
||||
|
||||
} // namespace pkv
|
||||
|
||||
#endif // HAS_ROCKSDB
|
@ -1,125 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/27.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#ifdef HAS_WT
|
||||
|
||||
#include <wiredtiger.h>
|
||||
#include "wt_sess.h"
|
||||
#include "wdb.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
size_t __cache_max = 10000;
|
||||
static __thread std::vector<wt_sess*>* __sessions = nullptr;
|
||||
|
||||
static acl_pthread_once_t once_control = ACL_PTHREAD_ONCE_INIT;
|
||||
|
||||
static void thread_on_exit(void*) {
|
||||
for (std::vector<wt_sess*>::iterator it = __sessions->begin();
|
||||
it != __sessions->end(); ++it) {
|
||||
delete *it;
|
||||
}
|
||||
|
||||
delete __sessions;
|
||||
}
|
||||
|
||||
static acl_pthread_key_t __free_sess_key;
|
||||
|
||||
static void thread_init_once() {
|
||||
acl_pthread_key_create(&__free_sess_key, thread_on_exit);
|
||||
}
|
||||
|
||||
static wt_sess *get_session(wdb& db) {
|
||||
if (__sessions == nullptr) {
|
||||
__sessions = new std::vector<wt_sess*>;
|
||||
acl_pthread_once(&once_control, thread_init_once);
|
||||
} else if (!__sessions->empty()) {
|
||||
auto sess = __sessions->back();
|
||||
__sessions->pop_back();
|
||||
return sess;
|
||||
}
|
||||
|
||||
auto sess = new wt_sess(db);
|
||||
if (sess->open()) {
|
||||
return sess;
|
||||
}
|
||||
|
||||
delete sess;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static void put_session(wt_sess* sess) {
|
||||
if (__sessions->size() < __cache_max) {
|
||||
__sessions->emplace_back(sess);
|
||||
} else {
|
||||
delete sess;
|
||||
}
|
||||
}
|
||||
|
||||
wdb::wdb(size_t cache_max) : db_(nullptr) {
|
||||
__cache_max = cache_max;
|
||||
}
|
||||
|
||||
wdb::~wdb() {
|
||||
if (db_) {
|
||||
db_->close(db_, nullptr);
|
||||
logger("wdb in %s closed", path_.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
bool wdb::open(const char *path) {
|
||||
path_ = path;
|
||||
path_ += "/wdb";
|
||||
if (acl_make_dirs(path_.c_str(), 0755) == -1) {
|
||||
logger_error("create dir=%s error=%s", path_.c_str(), acl::last_serror());
|
||||
return false;
|
||||
}
|
||||
|
||||
int ret = wiredtiger_open(path_.c_str(), nullptr, "create", &db_);
|
||||
if (ret != 0) {
|
||||
logger_error("open %s error=%d", path_.c_str(), ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wdb::set(const std::string &key, const std::string &value) {
|
||||
auto sess = get_session(*this);
|
||||
if (sess == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = sess->add(key, value);
|
||||
put_session(sess);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool wdb::get(const std::string &key, std::string &value) {
|
||||
auto sess = get_session(*this);
|
||||
if (sess == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = sess->get(key, value);
|
||||
put_session(sess);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool wdb::del(const std::string &key) {
|
||||
auto sess = get_session(*this);
|
||||
if (sess == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ret = sess->del(key);
|
||||
put_session(sess);
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
||||
|
||||
#endif // HAS_WT
|
@ -1,53 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/27.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../db.h"
|
||||
|
||||
#ifdef HAS_WT
|
||||
|
||||
typedef struct __wt_connection WT_CONNECTION;
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class wt_sess;
|
||||
|
||||
class wdb : public db {
|
||||
public:
|
||||
explicit wdb(size_t cache_max = 10000);
|
||||
~wdb() override;
|
||||
|
||||
protected:
|
||||
// @override
|
||||
bool open(const char* path) override;
|
||||
|
||||
// @override
|
||||
bool set(const std::string& key, const std::string& value) override;
|
||||
|
||||
// @override
|
||||
bool get(const std::string& key, std::string& value) override;
|
||||
|
||||
// @override
|
||||
bool del(const std::string& key) override;
|
||||
|
||||
public:
|
||||
// @override
|
||||
const char* get_dbtype() const override {
|
||||
return "wdb";
|
||||
}
|
||||
|
||||
public:
|
||||
WT_CONNECTION* get_db() const {
|
||||
return db_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string path_;
|
||||
WT_CONNECTION *db_;
|
||||
};
|
||||
|
||||
} // namespace pkv
|
||||
|
||||
#endif // HAS_WT
|
@ -1,92 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/27.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "wdb.h"
|
||||
#include "wt_sess.h"
|
||||
|
||||
#ifdef HAS_WT
|
||||
|
||||
namespace pkv {
|
||||
|
||||
wt_sess::wt_sess(wdb &db) : db_(db), sess_(nullptr), curs_(nullptr) {}
|
||||
|
||||
wt_sess::~wt_sess() = default;
|
||||
|
||||
bool wt_sess::open() {
|
||||
int ret = db_.get_db()->open_session(db_.get_db(), nullptr, nullptr, &sess_);
|
||||
if (ret != 0) {
|
||||
logger_error("open session error %d", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = sess_->create(sess_, "table:access", "key_format=S, value_format=S");
|
||||
if (ret != 0) {
|
||||
logger_error("create session error %d", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = sess_->open_cursor(sess_, "table:access", nullptr, nullptr, &curs_);
|
||||
if (ret != 0) {
|
||||
logger_error("open cursor error %d", ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wt_sess::add(const std::string &key, const std::string &value) {
|
||||
assert(curs_);
|
||||
curs_->set_key(curs_, key.c_str());
|
||||
curs_->set_value(curs_, value.c_str());
|
||||
int ret = curs_->insert(curs_);
|
||||
if (ret != 0) {
|
||||
logger_error("insert %s %s error=%d", key.c_str(), value.c_str(), ret);
|
||||
curs_->reset(curs_);
|
||||
return false;
|
||||
}
|
||||
curs_->reset(curs_);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wt_sess::get(const std::string &key, std::string &value) {
|
||||
assert(curs_);
|
||||
curs_->set_key(curs_, key.c_str());
|
||||
int ret = curs_->search(curs_);
|
||||
if (ret != 0) {
|
||||
logger("search key=%s error=%d", key.c_str(), ret);
|
||||
curs_->reset(curs_);
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* v;
|
||||
ret = curs_->get_value(curs_, &v);
|
||||
if (ret != 0) {
|
||||
logger_error("get_value key=%s errort=%d", key.c_str(), ret);
|
||||
curs_->reset(curs_);
|
||||
return false;
|
||||
}
|
||||
|
||||
value = v;
|
||||
curs_->reset(curs_);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wt_sess::del(const std::string &key) {
|
||||
assert(curs_);
|
||||
curs_->set_key(curs_, key.c_str());
|
||||
int ret = curs_->remove(curs_);
|
||||
if (ret != 0 && ret != WT_NOTFOUND) {
|
||||
logger_error("remove key=%s error=%d", key.c_str(), ret);
|
||||
curs_->reset(curs_);
|
||||
return false;
|
||||
}
|
||||
|
||||
curs_->reset(curs_);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
||||
|
||||
#endif // HAS_WT
|
@ -1,37 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/27.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HAS_WT
|
||||
|
||||
#include <wiredtiger.h>
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class wdb;
|
||||
|
||||
class wt_sess {
|
||||
public:
|
||||
explicit wt_sess(wdb& db);
|
||||
~wt_sess();
|
||||
|
||||
bool open();
|
||||
|
||||
bool add(const std::string& key, const std::string& value);
|
||||
|
||||
bool get(const std::string& key, std::string& value);
|
||||
|
||||
bool del(const std::string& key);
|
||||
|
||||
private:
|
||||
wdb& db_;
|
||||
|
||||
WT_SESSION *sess_;
|
||||
WT_CURSOR *curs_;
|
||||
};
|
||||
|
||||
} // namespace pkv
|
||||
|
||||
#endif // HAS_WT
|
@ -1,17 +0,0 @@
|
||||
*8
|
||||
$5
|
||||
HMSET
|
||||
$8
|
||||
hash-key
|
||||
$6
|
||||
field1
|
||||
$6
|
||||
vaule1
|
||||
$6
|
||||
field2
|
||||
$6
|
||||
vaule2
|
||||
$6
|
||||
field3
|
||||
$6
|
||||
vaule3
|
@ -1,109 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include <signal.h>
|
||||
#include "test/test_coder.h"
|
||||
#include "test/test_db.h"
|
||||
#include "master_service.h"
|
||||
|
||||
static void on_sigint(int) {
|
||||
master_service& ms = acl::singleton2<master_service>::get_instance();
|
||||
logger("---Begin to close db---");
|
||||
ms.close_db();
|
||||
logger("---Close db ok---");
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
static bool test_redis_coder(const char* file, size_t max) {
|
||||
#if 1
|
||||
printf(">>>>>>>>Begin to test redis parsing<<<<<<<<<\r\n");
|
||||
if (!pkv::test_redis_parse(file)) {
|
||||
printf(">>>>>>>Test redis parsing Error<<<<<<<\r\n");
|
||||
return false;
|
||||
}
|
||||
printf(">>>>>>>Test redis parsing successfully<<<<<<<<<\r\n");
|
||||
|
||||
printf("\r\n");
|
||||
|
||||
printf(">>>>>>>>>Begin to test redis building<<<<<<<<\r\n");
|
||||
if (!pkv::test_redis_build()) {
|
||||
printf(">>>>>Test redis building Error<<<<<<<<\r\n");
|
||||
return false;
|
||||
}
|
||||
printf(">>>>>>>Test redis building successfully<<<<<<<\r\n");
|
||||
|
||||
#endif
|
||||
|
||||
struct timeval begin, end;
|
||||
|
||||
printf(">>>Begin to build benchmark\r\n");
|
||||
gettimeofday(&begin, NULL);
|
||||
size_t n = pkv::redis_build_bench(max);
|
||||
gettimeofday(&end, NULL);
|
||||
double cost = acl::stamp_sub(end, begin);
|
||||
double speed = (n * 1000) / (cost > 0 ? cost : 0.00001);
|
||||
printf(">>>Build ok, count=%zd, cost=%.2f, speed=%.2f\r\n", n, cost, speed);
|
||||
|
||||
printf(">>>Begin to parse benchmark\r\n");
|
||||
gettimeofday(&begin, NULL);
|
||||
n = pkv::redis_parse_bench(file, max);
|
||||
gettimeofday(&end, NULL);
|
||||
cost = acl::stamp_sub(end, begin);
|
||||
speed = (n * 1000) / (cost > 0 ? cost : 0.00001);
|
||||
printf(">>>Parse ok, count=%zd, cost=%.2f, speed=%.2f\r\n", n, cost, speed);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void test_db(const char* dbpath, size_t max) {
|
||||
pkv::test_db::bench(dbpath, max);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
acl::acl_cpp_init();
|
||||
|
||||
if (argc >= 2 && strcasecmp(argv[1], "test") == 0) {
|
||||
const char* file = "hash.txt";
|
||||
size_t max = 2000000;
|
||||
|
||||
if (argc >= 3) {
|
||||
file = argv[2];
|
||||
}
|
||||
if (argc >= 4) {
|
||||
max = std::atoi(argv[3]);
|
||||
}
|
||||
test_redis_coder(file, max);
|
||||
test_db("./data/test", max);
|
||||
return 0;
|
||||
}
|
||||
|
||||
master_service& ms = acl::singleton2<master_service>::get_instance();
|
||||
|
||||
// 设置配置参数表
|
||||
ms.set_cfg_int(var_conf_int_tab);
|
||||
ms.set_cfg_int64(var_conf_int64_tab);
|
||||
ms.set_cfg_str(var_conf_str_tab);
|
||||
ms.set_cfg_bool(var_conf_bool_tab);
|
||||
|
||||
if (argc == 1 || (argc >= 2 && strcasecmp(argv[1], "alone") == 0)) {
|
||||
signal(SIGINT, on_sigint);
|
||||
|
||||
// 日志输出至标准输出
|
||||
acl::log::stdout_open(true);
|
||||
// 禁止生成 acl_master.log 日志
|
||||
acl::master_log_enable(false);
|
||||
|
||||
const char* addr = nullptr;
|
||||
//printf("listen: %s\r\n", addr);
|
||||
ms.run_alone(addr, argc >= 3 ? argv[2] : nullptr);
|
||||
} else {
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
const char* addr = "|8887";
|
||||
|
||||
acl::log::stdout_open(true);
|
||||
printf("listen on: %s\r\n", addrs);
|
||||
ms.run_alone(addr, argc >= 3 ? argv[2] : NULL);
|
||||
#else
|
||||
ms.run_daemon(argc, argv);
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,140 +0,0 @@
|
||||
#include "stdafx.h"
|
||||
#include "coder/redis_ocache.h"
|
||||
#include "coder/redis_coder.h"
|
||||
#include "action/redis_handler.h"
|
||||
#include "master_service.h"
|
||||
|
||||
static char *var_cfg_dbpath;
|
||||
static char *var_cfg_dbtype;
|
||||
|
||||
acl::master_str_tbl var_conf_str_tab[] = {
|
||||
{ "dbpath", "./dbpath", &var_cfg_dbpath },
|
||||
{ "dbtype", "rdb", &var_cfg_dbtype },
|
||||
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
int var_cfg_disable_serialize;
|
||||
int var_cfg_disable_save;
|
||||
|
||||
acl::master_bool_tbl var_conf_bool_tab[] = {
|
||||
{ "disable_serialize", 0, &var_cfg_disable_serialize },
|
||||
{ "disable_save", 0, &var_cfg_disable_save },
|
||||
|
||||
{ 0, 0, 0 }
|
||||
};
|
||||
|
||||
static int var_cfg_io_timeout;
|
||||
static int var_cfg_buf_size;
|
||||
|
||||
acl::master_int_tbl var_conf_int_tab[] = {
|
||||
{ "io_timeout", 120, &var_cfg_io_timeout, 0, 0 },
|
||||
{ "buf_size", 8192, &var_cfg_buf_size, 0, 0 },
|
||||
|
||||
{ 0, 0 , 0 , 0, 0 }
|
||||
};
|
||||
|
||||
acl::master_int64_tbl var_conf_int64_tab[] = {
|
||||
{ 0, 0 , 0 , 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using namespace pkv;
|
||||
|
||||
void master_service::on_accept(acl::socket_stream& conn) {
|
||||
//conn.set_rw_timeout(var_cfg_io_timeout);
|
||||
//logger(">>>accept connection: %d", conn.sock_handle());
|
||||
|
||||
run(conn, var_cfg_buf_size);
|
||||
|
||||
//logger("Disconnect from peer, fd=%d", conn.sock_handle());
|
||||
}
|
||||
|
||||
static __thread redis_ocache* __cache = NULL;
|
||||
|
||||
void master_service::run(acl::socket_stream& conn, size_t size) {
|
||||
if (__cache == NULL) {
|
||||
__cache = new redis_ocache;
|
||||
for (size_t i = 0; i < 100000; i++) {
|
||||
pkv::redis_object* o = new pkv::redis_object(*__cache);
|
||||
__cache->put(o);
|
||||
}
|
||||
}
|
||||
|
||||
pkv::redis_coder parser(*__cache);
|
||||
pkv::redis_handler handler(db_, parser, conn);
|
||||
char buf[size];
|
||||
|
||||
while(true) {
|
||||
int ret = conn.read(buf, sizeof(buf) - 1, false);
|
||||
if (ret <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
buf[ret] = 0;
|
||||
//printf("%s", buf); fflush(stdout);
|
||||
|
||||
size_t len = (size_t) ret;
|
||||
const char* data = parser.update(buf, len);
|
||||
auto obj = parser.get_curr();
|
||||
assert(obj);
|
||||
if (obj->failed()) {
|
||||
break;
|
||||
}
|
||||
|
||||
assert(*data == '\0' && len == 0);
|
||||
|
||||
if (!handler.handle()) {
|
||||
break;
|
||||
}
|
||||
|
||||
parser.clear();
|
||||
}
|
||||
}
|
||||
|
||||
void master_service::proc_pre_jail() {
|
||||
logger(">>>proc_pre_jail<<<");
|
||||
}
|
||||
|
||||
void master_service::proc_on_listen(acl::server_socket& ss) {
|
||||
logger(">>>listen %s ok<<<", ss.get_addr());
|
||||
}
|
||||
|
||||
void master_service::proc_on_init() {
|
||||
logger(">>>proc_on_init<<<");
|
||||
if (strcasecmp(var_cfg_dbtype, "rdb") == 0) {
|
||||
db_ = db::create_rdb();
|
||||
if (!db_->open(var_cfg_dbpath)) {
|
||||
logger_error("open db(%s) error %s", var_cfg_dbpath,
|
||||
acl::last_serror());
|
||||
exit(1);
|
||||
}
|
||||
} else if (strcasecmp(var_cfg_dbtype, "wdb") == 0) {
|
||||
db_ = db::create_wdb();
|
||||
if (!db_->open(var_cfg_dbpath)) {
|
||||
logger_error("open db(%s) error", var_cfg_dbpath);
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
logger_error("unknown dbtype=%s", var_cfg_dbtype);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void master_service::close_db() {
|
||||
if (db_) {
|
||||
db_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void master_service::proc_on_exit() {
|
||||
logger(">>>proc_on_exit<<<");
|
||||
close_db();
|
||||
}
|
||||
|
||||
bool master_service::proc_on_sighup(acl::string&) {
|
||||
logger(">>>proc_on_sighup<<<");
|
||||
return true;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "db/db.h"
|
||||
|
||||
class master_service : public acl::master_fiber {
|
||||
public:
|
||||
master_service() = default;
|
||||
~master_service() override = default;
|
||||
|
||||
void close_db();
|
||||
|
||||
protected:
|
||||
// @override
|
||||
void on_accept(acl::socket_stream& conn) override;
|
||||
|
||||
// @override
|
||||
void proc_on_listen(acl::server_socket& ss) override;
|
||||
|
||||
// @override
|
||||
void proc_pre_jail() override;
|
||||
|
||||
// @override
|
||||
void proc_on_init() override;
|
||||
|
||||
// @override
|
||||
void proc_on_exit() override;
|
||||
|
||||
// @override
|
||||
bool proc_on_sighup(acl::string&) override;
|
||||
|
||||
private:
|
||||
pkv::shared_db db_ = nullptr;
|
||||
|
||||
void run(acl::socket_stream& conn, size_t size);
|
||||
};
|
@ -1,131 +0,0 @@
|
||||
|
||||
service pkv
|
||||
{
|
||||
# 进程是否禁止运行
|
||||
master_disable = no
|
||||
# 服务地址及端口号
|
||||
# for master_type = inet
|
||||
# master_service = 127.0.0.1|5001
|
||||
# for master_type = unix
|
||||
# master_service = echo.sock
|
||||
# for master_type = sock
|
||||
master_service = 127.0.0.1|19001
|
||||
|
||||
# 服务监听为域套接口
|
||||
# master_service = aio_echo.sock
|
||||
# 服务类型
|
||||
# master_type = inet
|
||||
# master_type = unix
|
||||
master_type = sock
|
||||
|
||||
# 停止子进程时是否采用强行停止的方式(即给子进程发送 SIGTERM 信号)
|
||||
master_stop_kill = false
|
||||
# 当 master_stop_kill 为 true 时,该配置决定是否要等待子进程退出
|
||||
master_stop_wait = false
|
||||
|
||||
# 当系统支持 SO_REUSEPORT 时,是否启用该功能
|
||||
master_reuseport = yes
|
||||
# 当启用 SO_REUSEPORT 时(即 master_reuseport=yes 时), 是否需要 acl_master
|
||||
# 也监听该地址, 对于使用旧版 acl(< 3.5.3-17) 编写的服务, 必须将此项设为
|
||||
# yes, 即: master_reuseport_listen = yes; 对于使用 acl 版本 >= 3.5.3-17
|
||||
# 编写的服务需设置为 no; 当 master_reuseport=no时,该项设置将被忽略; 当未
|
||||
# 设置此项时内部缺省值为 yes. 以便使 acl_master 保持对于旧版服务的兼容性.
|
||||
master_reuseport_listen = no
|
||||
# 是否针对监听套接口设定为非阻塞方式
|
||||
master_nonblock = yes
|
||||
# 当系统支持 TCP_FASTOPEN 时,是否启用该功能
|
||||
master_fastopen = no
|
||||
|
||||
# 当子进程异常退出时,如果该值非空,则将子进程异常退出的消息通知该服务
|
||||
# master_notify_addr = 127.0.0.1:5801
|
||||
# 邮件通知接收者
|
||||
# master_notify_recipients = zhengshuxin@hotmail.com
|
||||
|
||||
# 是否允许延迟接受客户端连接,如果为0则表示关闭该功能,如果大于0则表示打开此功能
|
||||
# 并且此值代表延迟接受连接的超时值,超过此值时如果客户端依然没有发来数据,则操作
|
||||
# 系统会在系统层直接关闭该连接
|
||||
# master_defer_accept = 0
|
||||
# 是否只允许私有访问, 如果为 y, 则域套接口创建在 {install_path}/var/log/private/ 目录下,
|
||||
# 如果为 n, 则域套接口创建在 {install_path}/var/log/public/ 目录下,
|
||||
master_private = n
|
||||
master_unpriv = n
|
||||
# 是否需要 chroot: n -- no, y -- yes
|
||||
master_chroot = n
|
||||
# 每隔多长时间触发一次,单位为秒(仅对 trigger 模式有效)
|
||||
master_wakeup = -
|
||||
# 最大进程数
|
||||
master_maxproc = 1
|
||||
# 预启动进程数,该值不得大于 master_maxproc
|
||||
master_prefork = 1
|
||||
# 进程程序名
|
||||
master_command = {install_path}/sbin/pkv
|
||||
# 进程日志记录文件
|
||||
master_log = {install_path}/var/log/pkv.log
|
||||
# 调试日志方式,格式:tag:level; tag:level; tab:level, 如:all:1; 101:2
|
||||
# master_debug =
|
||||
# 进程启动参数,只能为: -u [是否允许以某普通用户的身份运行]
|
||||
# master_args =
|
||||
# 传递给服务子进程的环境变量, 可以通过 getenv("SERVICE_ENV") 获得此值
|
||||
# master_env = mempool_limit:512000000
|
||||
# 当启动多个子进程实例时,该开关控制多个子进程在接收连接时是否向 acl_master 发送消息报告自己的状态
|
||||
# master_status_notify = 1
|
||||
# 程序标准输出重定向至指定文件中
|
||||
# master_stdout = {install_path}/var/log/stdout.log
|
||||
# 程序错误输出重定向至指定文件中
|
||||
# master_stderr = {install_path}/var/log/stderr.log
|
||||
|
||||
# 事件引擎: kernel, poll, select, io_uring
|
||||
fiber_schedule_event = kernel
|
||||
# fiber_schedule_event = io_uring
|
||||
# 是否允许产生 core 文件
|
||||
# fiber_enable_core = 1
|
||||
# core 文件大小限制,-1 表示不限制 core 文件大小,0 表示禁止产生 core,> 0 表示 core 文件最大大小
|
||||
# fiber_core_limit = -1
|
||||
# 进程退出时是否禁止产生 core 文件
|
||||
# fiber_disable_core_onexit = 1
|
||||
# 每个进程实例处理连接数的最大次数,超过此值后进程实例主动退出
|
||||
fiber_use_limit = 0
|
||||
# 每个进程实例的空闲超时时间,超过此值后进程实例主动退出
|
||||
fiber_idle_limit = 0
|
||||
# 每个进程启动的线程数
|
||||
fiber_threads = 4
|
||||
# 进程运行时所在的路径
|
||||
fiber_queue_dir = {install_path}/var
|
||||
# 读写超时时间, 单位为秒
|
||||
fiber_rw_timeout = 120
|
||||
# 读缓冲区的缓冲区大小
|
||||
fiber_buf_size = 8192
|
||||
# 进程运行时的用户身份
|
||||
fiber_owner = root
|
||||
|
||||
# 当启用 master_dispatch 连接分开服务后,该配置指定 master_dispatch 所监听的
|
||||
# 域套接口的全路径,这样本子进程就可以从 master_dispatch 获得客户端连接
|
||||
# fiber_dispatch_addr = {install_path}/var/private/dispatch.sock
|
||||
# 当 fiber_dispatch_addr 开启后,下面参数控制本服务进程发给前端 master_dispatch 的服务标识信息
|
||||
# fiber_dispatch_type = default
|
||||
|
||||
# 线程的堆栈空间大小,单位为字节
|
||||
fiber_stack_size = 256000
|
||||
# 允许访问 udserver 的客户端IP地址范围
|
||||
# fiber_access_allow = 127.0.0.1:255.255.255.255, 127.0.0.1:127.0.0.1
|
||||
fiber_access_allow = all
|
||||
|
||||
# 当 acl_master 退出时,如果该值置1则该程序不等所有连接处理完毕便立即退出
|
||||
fiber_quick_abort = 1
|
||||
|
||||
# 是否启用协程共享栈模式
|
||||
fiber_share_stack = 0
|
||||
|
||||
# 当 fiber_quick_abort 为 0 且本配置项大于 0 时,该配置项才有效,指定了
|
||||
# 本进程在所有连接退出前的最大等待时间(秒)
|
||||
fiber_wait_limit = 0
|
||||
|
||||
############################################################################
|
||||
# 应用自己的配置选项
|
||||
|
||||
disable_serialize = 1
|
||||
disable_save = 1
|
||||
buf_size = 81920
|
||||
dbpath = ./data
|
||||
dbtype = wdb
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
|
||||
service pkv
|
||||
{
|
||||
# 进程是否禁止运行
|
||||
master_disable = no
|
||||
# 服务地址及端口号
|
||||
# for master_type = inet
|
||||
# master_service = 127.0.0.1|5001
|
||||
# for master_type = unix
|
||||
# master_service = echo.sock
|
||||
# for master_type = sock
|
||||
master_service = 127.0.0.1|19001
|
||||
|
||||
# 服务监听为域套接口
|
||||
# master_service = aio_echo.sock
|
||||
# 服务类型
|
||||
# master_type = inet
|
||||
# master_type = unix
|
||||
master_type = sock
|
||||
|
||||
# 停止子进程时是否采用强行停止的方式(即给子进程发送 SIGTERM 信号)
|
||||
master_stop_kill = false
|
||||
# 当 master_stop_kill 为 true 时,该配置决定是否要等待子进程退出
|
||||
master_stop_wait = false
|
||||
|
||||
# 当系统支持 SO_REUSEPORT 时,是否启用该功能
|
||||
master_reuseport = yes
|
||||
# 当启用 SO_REUSEPORT 时(即 master_reuseport=yes 时), 是否需要 acl_master
|
||||
# 也监听该地址, 对于使用旧版 acl(< 3.5.3-17) 编写的服务, 必须将此项设为
|
||||
# yes, 即: master_reuseport_listen = yes; 对于使用 acl 版本 >= 3.5.3-17
|
||||
# 编写的服务需设置为 no; 当 master_reuseport=no时,该项设置将被忽略; 当未
|
||||
# 设置此项时内部缺省值为 yes. 以便使 acl_master 保持对于旧版服务的兼容性.
|
||||
master_reuseport_listen = no
|
||||
# 是否针对监听套接口设定为非阻塞方式
|
||||
master_nonblock = yes
|
||||
# 当系统支持 TCP_FASTOPEN 时,是否启用该功能
|
||||
master_fastopen = no
|
||||
|
||||
# 当子进程异常退出时,如果该值非空,则将子进程异常退出的消息通知该服务
|
||||
# master_notify_addr = 127.0.0.1:5801
|
||||
# 邮件通知接收者
|
||||
# master_notify_recipients = zhengshuxin@hotmail.com
|
||||
|
||||
# 是否允许延迟接受客户端连接,如果为0则表示关闭该功能,如果大于0则表示打开此功能
|
||||
# 并且此值代表延迟接受连接的超时值,超过此值时如果客户端依然没有发来数据,则操作
|
||||
# 系统会在系统层直接关闭该连接
|
||||
# master_defer_accept = 0
|
||||
# 是否只允许私有访问, 如果为 y, 则域套接口创建在 {install_path}/var/log/private/ 目录下,
|
||||
# 如果为 n, 则域套接口创建在 {install_path}/var/log/public/ 目录下,
|
||||
master_private = n
|
||||
master_unpriv = n
|
||||
# 是否需要 chroot: n -- no, y -- yes
|
||||
master_chroot = n
|
||||
# 每隔多长时间触发一次,单位为秒(仅对 trigger 模式有效)
|
||||
master_wakeup = -
|
||||
# 最大进程数
|
||||
master_maxproc = 1
|
||||
# 预启动进程数,该值不得大于 master_maxproc
|
||||
master_prefork = 1
|
||||
# 进程程序名
|
||||
master_command = {install_path}/sbin/pkv
|
||||
# 进程日志记录文件
|
||||
master_log = {install_path}/var/log/pkv.log
|
||||
# 调试日志方式,格式:tag:level; tag:level; tab:level, 如:all:1; 101:2
|
||||
# master_debug =
|
||||
# 进程启动参数,只能为: -u [是否允许以某普通用户的身份运行]
|
||||
# master_args =
|
||||
# 传递给服务子进程的环境变量, 可以通过 getenv("SERVICE_ENV") 获得此值
|
||||
# master_env = mempool_limit:512000000
|
||||
# 当启动多个子进程实例时,该开关控制多个子进程在接收连接时是否向 acl_master 发送消息报告自己的状态
|
||||
# master_status_notify = 1
|
||||
# 程序标准输出重定向至指定文件中
|
||||
# master_stdout = {install_path}/var/log/stdout.log
|
||||
# 程序错误输出重定向至指定文件中
|
||||
# master_stderr = {install_path}/var/log/stderr.log
|
||||
|
||||
# 事件引擎: kernel, poll, select, io_uring
|
||||
fiber_schedule_event = kernel
|
||||
# fiber_schedule_event = io_uring
|
||||
# 是否允许产生 core 文件
|
||||
# fiber_enable_core = 1
|
||||
# core 文件大小限制,-1 表示不限制 core 文件大小,0 表示禁止产生 core,> 0 表示 core 文件最大大小
|
||||
# fiber_core_limit = -1
|
||||
# 进程退出时是否禁止产生 core 文件
|
||||
# fiber_disable_core_onexit = 1
|
||||
# 每个进程实例处理连接数的最大次数,超过此值后进程实例主动退出
|
||||
fiber_use_limit = 0
|
||||
# 每个进程实例的空闲超时时间,超过此值后进程实例主动退出
|
||||
fiber_idle_limit = 0
|
||||
# 每个进程启动的线程数
|
||||
fiber_threads = 1
|
||||
# 进程运行时所在的路径
|
||||
fiber_queue_dir = {install_path}/var
|
||||
# 读写超时时间, 单位为秒
|
||||
fiber_rw_timeout = 120
|
||||
# 读缓冲区的缓冲区大小
|
||||
fiber_buf_size = 8192
|
||||
# 进程运行时的用户身份
|
||||
fiber_owner = root
|
||||
|
||||
# 当启用 master_dispatch 连接分开服务后,该配置指定 master_dispatch 所监听的
|
||||
# 域套接口的全路径,这样本子进程就可以从 master_dispatch 获得客户端连接
|
||||
# fiber_dispatch_addr = {install_path}/var/private/dispatch.sock
|
||||
# 当 fiber_dispatch_addr 开启后,下面参数控制本服务进程发给前端 master_dispatch 的服务标识信息
|
||||
# fiber_dispatch_type = default
|
||||
|
||||
# 线程的堆栈空间大小,单位为字节
|
||||
fiber_stack_size = 256000
|
||||
# 允许访问 udserver 的客户端IP地址范围
|
||||
# fiber_access_allow = 127.0.0.1:255.255.255.255, 127.0.0.1:127.0.0.1
|
||||
fiber_access_allow = all
|
||||
|
||||
# 当 acl_master 退出时,如果该值置1则该程序不等所有连接处理完毕便立即退出
|
||||
fiber_quick_abort = 1
|
||||
|
||||
# 是否启用协程共享栈模式
|
||||
fiber_share_stack = 0
|
||||
|
||||
# 当 fiber_quick_abort 为 0 且本配置项大于 0 时,该配置项才有效,指定了
|
||||
# 本进程在所有连接退出前的最大等待时间(秒)
|
||||
fiber_wait_limit = 0
|
||||
|
||||
############################################################################
|
||||
# 应用自己的配置选项
|
||||
|
||||
buf_size = 8192
|
||||
dbpath = ./data
|
||||
dbtype = wdb
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pkv", "pkv.vcproj", "{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
Debug = Debug
|
||||
DebugDll = DebugDll
|
||||
Release = Release
|
||||
ReleaseDll = ReleaseDll
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfiguration) = postSolution
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Debug.ActiveCfg = Debug|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Debug.Build.0 = Debug|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.DebugDll.ActiveCfg = DebugDll|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.DebugDll.Build.0 = DebugDll|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Release.ActiveCfg = Release|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Release.Build.0 = Release|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.ReleaseDll.ActiveCfg = ReleaseDll|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.ReleaseDll.Build.0 = ReleaseDll|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||
EndGlobalSection
|
||||
EndGlobal
|
@ -1,37 +0,0 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 14.00
|
||||
# Visual Studio 2019
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pkv", "pkv_vc2019.vcxproj", "{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
DebugDll|Win32 = DebugDll|Win32
|
||||
DebugDll|x64 = DebugDll|x64
|
||||
Release|Win32 = Release|Win32
|
||||
Release|x64 = Release|x64
|
||||
ReleaseDll|Win32 = ReleaseDll|Win32
|
||||
ReleaseDll|x64 = ReleaseDll|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Debug|x64.Build.0 = Debug|x64
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.DebugDll|Win32.ActiveCfg = DebugDll|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.DebugDll|Win32.Build.0 = DebugDll|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.DebugDll|x64.ActiveCfg = DebugDll|x64
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.DebugDll|x64.Build.0 = DebugDll|x64
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Release|Win32.Build.0 = Release|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Release|x64.ActiveCfg = Release|x64
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.Release|x64.Build.0 = Release|x64
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.ReleaseDll|Win32.ActiveCfg = ReleaseDll|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.ReleaseDll|Win32.Build.0 = ReleaseDll|Win32
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.ReleaseDll|x64.ActiveCfg = ReleaseDll|x64
|
||||
{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}.ReleaseDll|x64.Build.0 = ReleaseDll|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
@ -1,356 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="DebugDll|Win32">
|
||||
<Configuration>DebugDll</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="DebugDll|x64">
|
||||
<Configuration>DebugDll</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="ReleaseDll|Win32">
|
||||
<Configuration>ReleaseDll</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="ReleaseDll|x64">
|
||||
<Configuration>ReleaseDll</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{58FE3581-C997-4BD5-9AC6-AEEB54A43D2C}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectName>pkv</ProjectName>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>11.0.50727.1</_ProjectFileVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>.\</OutDir>
|
||||
<IntDir>Debug\</IntDir>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>.\</OutDir>
|
||||
<IntDir>Debug\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>Release\</OutDir>
|
||||
<IntDir>Release\</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>.\</OutDir>
|
||||
<IntDir>Release\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">
|
||||
<OutDir>.\</OutDir>
|
||||
<IntDir>ReleaseDll\</IntDir>
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<OutDir>.\</OutDir>
|
||||
<IntDir>ReleaseDll\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">
|
||||
<OutDir>.\</OutDir>
|
||||
<IntDir>DebugDll\</IntDir>
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<OutDir>.\</OutDir>
|
||||
<IntDir>DebugDll\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>lib_acl_cpp.lib;lib_acl.lib;lib_protocol.lib;libfiber.lib;libfiber_cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)pkv.exe</OutputFile>
|
||||
<AdditionalLibraryDirectories>..\..\..\dist\lib\win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(OutDir)pkv.pdb</ProgramDatabaseFile>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>lib_acl_cpp.lib;lib_acl.lib;lib_protocol.lib;libfiber.lib;libfiber_cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)pkv.exe</OutputFile>
|
||||
<AdditionalLibraryDirectories>..\..\..\dist\lib\win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(OutDir)pkv.pdb</ProgramDatabaseFile>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
|
||||
<StackReserveSize>20240000</StackReserveSize>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>lib_acl_cpp.lib;lib_acl.lib;lib_protocol.lib;libfiber.lib;libfiber_cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)pkv.exe</OutputFile>
|
||||
<AdditionalLibraryDirectories>..\..\..\dist\lib\win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>lib_acl_cpp.lib;lib_acl.lib;lib_protocol.lib;libfiber.lib;libfiber_cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)pkv.exe</OutputFile>
|
||||
<AdditionalLibraryDirectories>..\..\..\dist\lib\win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;ACL_CPP_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>lib_acl_cpp.lib;lib_acl.lib;lib_protocol.lib;libfiber.lib;libfiber_cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)pkv.exe</OutputFile>
|
||||
<AdditionalLibraryDirectories>..\..\..\dist\lib\win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>copy $(OutDir)\..\..\..\$(Configuration)\lib_acl.dll $(OutDir) /Y copy $(OutDir)\..\..\..\$(Configuration)\lib_acl_cpp.dll $(OutDir) /Y copy $(OutDir)\..\..\..\$(Configuration)\lib_protocol.dll $(OutDir) /Y</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|x64'">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN64;NDEBUG;_CONSOLE;ACL_CPP_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>lib_acl_cpp.lib;lib_acl.lib;lib_protocol.lib;libfiber.lib;libfiber_cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)pkv.exe</OutputFile>
|
||||
<AdditionalLibraryDirectories>..\..\..\dist\lib\win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>copy $(OutDir)\..\..\..\$(Configuration)\lib_acl.dll $(OutDir) /Y copy $(OutDir)\..\..\..\$(Configuration)\lib_acl_cpp.dll $(OutDir) /Y copy $(OutDir)\..\..\..\$(Configuration)\lib_protocol.dll $(OutDir) /Y</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;ACL_CPP_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>false</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>lib_acl_cpp.lib;lib_acl.lib;lib_protocol.lib;libfiber.lib;libfiber_cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)pkv.exe</OutputFile>
|
||||
<AdditionalLibraryDirectories>..\..\..\dist\lib\win32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(OutDir)pkv.pdb</ProgramDatabaseFile>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>copy $(OutDir)\..\..\..\$(Configuration)\lib_acl.dll $(OutDir) /Y copy $(OutDir)\..\..\..\$(Configuration)\lib_acl_cpp.dll $(OutDir) /Y copy $(OutDir)\..\..\..\$(Configuration)\lib_protocol.dll $(OutDir) /Y</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='DebugDll|x64'">
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<AdditionalIncludeDirectories>..\..\..\lib_acl_cpp\include;..\..\..\lib_acl\include;..\..\..\lib_fiber\c\include;..\..\..\lib_fiber\cpp\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN64;_DEBUG;_CONSOLE;ACL_CPP_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>lib_acl_cpp.lib;lib_acl.lib;lib_protocol.lib;libfiber.lib;libfiber_cpp.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>$(OutDir)pkv.exe</OutputFile>
|
||||
<AdditionalLibraryDirectories>..\..\..\dist\lib\win64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>$(OutDir)pkv.pdb</ProgramDatabaseFile>
|
||||
<SubSystem>Console</SubSystem>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>copy $(OutDir)\..\..\..\$(Configuration)\lib_acl.dll $(OutDir) /Y copy $(OutDir)\..\..\..\$(Configuration)\lib_acl_cpp.dll $(OutDir) /Y copy $(OutDir)\..\..\..\$(Configuration)\lib_protocol.dll $(OutDir) /Y</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="master_service.cpp" />
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='DebugDll|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='DebugDll|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='ReleaseDll|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="master_service.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -1,39 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="master_service.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="master_service.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="stdafx.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="ReadMe.txt" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -1,129 +0,0 @@
|
||||
|
||||
service pkv
|
||||
{
|
||||
# 进程是否禁止运行
|
||||
master_disable = no
|
||||
# 服务地址及端口号
|
||||
# for master_type = inet
|
||||
# master_service = 127.0.0.1|5001
|
||||
# for master_type = unix
|
||||
# master_service = echo.sock
|
||||
# for master_type = sock
|
||||
master_service = 127.0.0.1|19001
|
||||
|
||||
# 服务监听为域套接口
|
||||
# master_service = aio_echo.sock
|
||||
# 服务类型
|
||||
# master_type = inet
|
||||
# master_type = unix
|
||||
master_type = sock
|
||||
|
||||
# 停止子进程时是否采用强行停止的方式(即给子进程发送 SIGTERM 信号)
|
||||
master_stop_kill = false
|
||||
# 当 master_stop_kill 为 true 时,该配置决定是否要等待子进程退出
|
||||
master_stop_wait = false
|
||||
|
||||
# 当系统支持 SO_REUSEPORT 时,是否启用该功能
|
||||
master_reuseport = yes
|
||||
# 当启用 SO_REUSEPORT 时(即 master_reuseport=yes 时), 是否需要 acl_master
|
||||
# 也监听该地址, 对于使用旧版 acl(< 3.5.3-17) 编写的服务, 必须将此项设为
|
||||
# yes, 即: master_reuseport_listen = yes; 对于使用 acl 版本 >= 3.5.3-17
|
||||
# 编写的服务需设置为 no; 当 master_reuseport=no时,该项设置将被忽略; 当未
|
||||
# 设置此项时内部缺省值为 yes. 以便使 acl_master 保持对于旧版服务的兼容性.
|
||||
master_reuseport_listen = no
|
||||
# 是否针对监听套接口设定为非阻塞方式
|
||||
master_nonblock = yes
|
||||
# 当系统支持 TCP_FASTOPEN 时,是否启用该功能
|
||||
master_fastopen = no
|
||||
|
||||
# 当子进程异常退出时,如果该值非空,则将子进程异常退出的消息通知该服务
|
||||
# master_notify_addr = 127.0.0.1:5801
|
||||
# 邮件通知接收者
|
||||
# master_notify_recipients = zhengshuxin@hotmail.com
|
||||
|
||||
# 是否允许延迟接受客户端连接,如果为0则表示关闭该功能,如果大于0则表示打开此功能
|
||||
# 并且此值代表延迟接受连接的超时值,超过此值时如果客户端依然没有发来数据,则操作
|
||||
# 系统会在系统层直接关闭该连接
|
||||
# master_defer_accept = 0
|
||||
# 是否只允许私有访问, 如果为 y, 则域套接口创建在 {install_path}/var/log/private/ 目录下,
|
||||
# 如果为 n, 则域套接口创建在 {install_path}/var/log/public/ 目录下,
|
||||
master_private = n
|
||||
master_unpriv = n
|
||||
# 是否需要 chroot: n -- no, y -- yes
|
||||
master_chroot = n
|
||||
# 每隔多长时间触发一次,单位为秒(仅对 trigger 模式有效)
|
||||
master_wakeup = -
|
||||
# 最大进程数
|
||||
master_maxproc = 1
|
||||
# 预启动进程数,该值不得大于 master_maxproc
|
||||
master_prefork = 1
|
||||
# 进程程序名
|
||||
master_command = {install_path}/sbin/pkv
|
||||
# 进程日志记录文件
|
||||
master_log = {install_path}/var/log/pkv.log
|
||||
# 调试日志方式,格式:tag:level; tag:level; tab:level, 如:all:1; 101:2
|
||||
# master_debug =
|
||||
# 进程启动参数,只能为: -u [是否允许以某普通用户的身份运行]
|
||||
# master_args =
|
||||
# 传递给服务子进程的环境变量, 可以通过 getenv("SERVICE_ENV") 获得此值
|
||||
# master_env = mempool_limit:512000000
|
||||
# 当启动多个子进程实例时,该开关控制多个子进程在接收连接时是否向 acl_master 发送消息报告自己的状态
|
||||
# master_status_notify = 1
|
||||
# 程序标准输出重定向至指定文件中
|
||||
# master_stdout = {install_path}/var/log/stdout.log
|
||||
# 程序错误输出重定向至指定文件中
|
||||
# master_stderr = {install_path}/var/log/stderr.log
|
||||
|
||||
# 事件引擎: kernel, poll, select, io_uring
|
||||
fiber_schedule_event = kernel
|
||||
# fiber_schedule_event = io_uring
|
||||
# 是否允许产生 core 文件
|
||||
# fiber_enable_core = 1
|
||||
# core 文件大小限制,-1 表示不限制 core 文件大小,0 表示禁止产生 core,> 0 表示 core 文件最大大小
|
||||
# fiber_core_limit = -1
|
||||
# 进程退出时是否禁止产生 core 文件
|
||||
# fiber_disable_core_onexit = 1
|
||||
# 每个进程实例处理连接数的最大次数,超过此值后进程实例主动退出
|
||||
fiber_use_limit = 0
|
||||
# 每个进程实例的空闲超时时间,超过此值后进程实例主动退出
|
||||
fiber_idle_limit = 0
|
||||
# 每个进程启动的线程数
|
||||
fiber_threads = 4
|
||||
# 进程运行时所在的路径
|
||||
fiber_queue_dir = {install_path}/var
|
||||
# 读写超时时间, 单位为秒
|
||||
fiber_rw_timeout = 120
|
||||
# 读缓冲区的缓冲区大小
|
||||
fiber_buf_size = 8192
|
||||
# 进程运行时的用户身份
|
||||
fiber_owner = root
|
||||
|
||||
# 当启用 master_dispatch 连接分开服务后,该配置指定 master_dispatch 所监听的
|
||||
# 域套接口的全路径,这样本子进程就可以从 master_dispatch 获得客户端连接
|
||||
# fiber_dispatch_addr = {install_path}/var/private/dispatch.sock
|
||||
# 当 fiber_dispatch_addr 开启后,下面参数控制本服务进程发给前端 master_dispatch 的服务标识信息
|
||||
# fiber_dispatch_type = default
|
||||
|
||||
# 线程的堆栈空间大小,单位为字节
|
||||
fiber_stack_size = 256000
|
||||
# 允许访问 udserver 的客户端IP地址范围
|
||||
# fiber_access_allow = 127.0.0.1:255.255.255.255, 127.0.0.1:127.0.0.1
|
||||
fiber_access_allow = all
|
||||
|
||||
# 当 acl_master 退出时,如果该值置1则该程序不等所有连接处理完毕便立即退出
|
||||
fiber_quick_abort = 1
|
||||
|
||||
# 是否启用协程共享栈模式
|
||||
fiber_share_stack = 0
|
||||
|
||||
# 当 fiber_quick_abort 为 0 且本配置项大于 0 时,该配置项才有效,指定了
|
||||
# 本进程在所有连接退出前的最大等待时间(秒)
|
||||
fiber_wait_limit = 0
|
||||
|
||||
############################################################################
|
||||
# 应用自己的配置选项
|
||||
|
||||
buf_size = 8192
|
||||
dbpath = ./data
|
||||
dbtype = rdb
|
||||
}
|
@ -1,197 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
###############################################################################
|
||||
PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc
|
||||
tempdir="/tmp"
|
||||
|
||||
umask 022
|
||||
|
||||
function censored_ls() {
|
||||
ls "$@" | egrep -v '^\.|/\.|CVS|RCS|SCCS|linux\.d|solaris\.d|hp_ux\.d|example'
|
||||
}
|
||||
|
||||
function compare_or_replace() {
|
||||
(cmp $2 $3 >/dev/null 2>&1 && echo Skipping $3...) || {
|
||||
echo Updating $3...
|
||||
rm -f $tempdir/junk || exit 1
|
||||
cp $2 $tempdir/junk || exit 1
|
||||
chmod $1 $tempdir/junk || exit 1
|
||||
mv -f $tempdir/junk $3 || exit 1
|
||||
chmod $1 $3 || exit 1
|
||||
}
|
||||
}
|
||||
###############################################################################
|
||||
RPATH=
|
||||
function guess_os() {
|
||||
os_name=`uname -s`
|
||||
os_type=`uname -p`
|
||||
case $os_name in
|
||||
Linux)
|
||||
case $os_type in
|
||||
x86_64)
|
||||
RPATH="linux64"
|
||||
;;
|
||||
i686)
|
||||
RPATH="linux32"
|
||||
;;
|
||||
aarch64)
|
||||
RPATH="aarch64"
|
||||
;;
|
||||
*)
|
||||
echo "unknown OS - $os_name $os_type"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
SunOS)
|
||||
case $os_type in
|
||||
i386)
|
||||
RPATH="sunos_x86"
|
||||
;;
|
||||
*)
|
||||
echo "unknown OS - $os_name $os_type"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
FreeBSD)
|
||||
RPATH="freebsd"
|
||||
;;
|
||||
Darwin)
|
||||
RPATH="macos"
|
||||
;;
|
||||
*)
|
||||
echo "unknown OS - $os_name $os_type"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function create_path() {
|
||||
test -d $1 || mkdir -p $1 || {
|
||||
echo "can't mkdir $1"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
function copy_file() {
|
||||
test -f $2 && {
|
||||
compare_or_replace $1 $2 $3 || {
|
||||
echo "copy file: $2 error"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function install_file() {
|
||||
rm -f $tempdir/junk2 || {
|
||||
echo "can't remove file: $tempdir/junk2"
|
||||
exit 1
|
||||
}
|
||||
test -f $2 && {
|
||||
cat $2 | sed -e 's;{install_path};'$INSTALL_PATH';;' >$tempdir/junk2 || {
|
||||
echo "can't create file: $tempdir/junk2"
|
||||
exit 1
|
||||
}
|
||||
compare_or_replace $1 $tempdir/junk2 $3 || {
|
||||
echo "can't move to file: $3"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
rm -f $tempdir/junk2 || {
|
||||
echo "can't remove file: $tempdir/junk2"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
INSTALL_PATH=
|
||||
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
# echo "parameter not enougth($#)"
|
||||
echo "usage:$0 install_path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $# -eq 2 ]
|
||||
then
|
||||
PREFIX_PATH=$1
|
||||
INSTALL_PATH=$2
|
||||
else
|
||||
INSTALL_PATH=$1
|
||||
PREFIX_PATH=
|
||||
fi
|
||||
|
||||
case $INSTALL_PATH in
|
||||
/*) ;;
|
||||
no) ;;
|
||||
*) echo Error: $INSTALL_PATH should be an absolute path name. 1>&2; exit 1;;
|
||||
esac
|
||||
|
||||
echo Installing to $INSTALL_PATH...
|
||||
|
||||
BIN_PATH=$PREFIX_PATH$INSTALL_PATH/bin
|
||||
SBIN_PATH=$PREFIX_PATH$INSTALL_PATH/sbin
|
||||
CONF_PATH=$PREFIX_PATH$INSTALL_PATH/conf
|
||||
SH_PATH=$PREFIX_PATH$INSTALL_PATH/sh
|
||||
VAR_PATH=$PREFIX_PATH$INSTALL_PATH/var
|
||||
|
||||
SERVICE_NAME=pkv
|
||||
SERVICE_BIN=$SBIN_PATH/$SERVICE_NAME
|
||||
SERVICE_CONF=$CONF_PATH/$SERVICE_NAME.cf
|
||||
###############################################################################
|
||||
|
||||
function create_all_path() {
|
||||
create_path $INSTALL_PATH
|
||||
create_path $BIN_PATH
|
||||
create_path $SBIN_PATH
|
||||
create_path $SH_PATH
|
||||
create_path $CONF_PATH
|
||||
create_path $VAR_PATH
|
||||
create_path $VAR_PATH/log
|
||||
create_path $VAR_PATH/pid
|
||||
chmod 1777 $VAR_PATH/log
|
||||
}
|
||||
|
||||
function copy_all_file() {
|
||||
copy_file a+x,go+rx $SERVICE_NAME $SERVICE_BIN
|
||||
install_file a+x,go-wrx $SERVICE_NAME.cf $SERVICE_CONF
|
||||
}
|
||||
|
||||
MASTER_PATH=/opt/soft/acl-master
|
||||
MASTER_CONF=$MASTER_PATH/conf
|
||||
MASTER_SERVICES=$MASTER_CONF/services.cf
|
||||
MASTER_CTL=$MASTER_PATH/bin/master_ctl
|
||||
|
||||
function add_master_service() {
|
||||
echo ""
|
||||
|
||||
if [ ! -d $MASTER_CONF ]; then
|
||||
echo "$MASTER_CONF not exist!"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -f $MASTER_SERVICES ]; then
|
||||
has=`cat $MASTER_SERVICES | grep $SERVICE_CONF | wc -l`
|
||||
if [ $has != 0 ]; then
|
||||
echo "Service for $SERVICE_CONF already in $MASTER_SERVICES!"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$SERVICE_CONF" >> $MASTER_SERVICES
|
||||
echo "Service added for $SERVICE_CONF"
|
||||
|
||||
if [ -f $MASTER_CTL ]; then
|
||||
echo "Start your service by running:"
|
||||
echo "$MASTER_CTL -f $SERVICE_CONF -a start"
|
||||
fi
|
||||
}
|
||||
|
||||
guess_os
|
||||
create_all_path
|
||||
copy_all_file
|
||||
add_master_service
|
||||
|
||||
###############################################################################
|
@ -1,8 +0,0 @@
|
||||
// stdafx.cpp : 只包括标准包含文件的源文件
|
||||
// master_threads.pch 将成为预编译头
|
||||
// stdafx.obj 将包含预编译类型信息
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: 在 STDAFX.H 中
|
||||
//引用任何所需的附加头文件,而不是在此文件中引用
|
@ -1,71 +0,0 @@
|
||||
// stdafx.h : 标准系统包含文件的包含文件,
|
||||
// 或是常用但不常更改的项目特定的包含文件
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
//#include <iostream>
|
||||
//#include <tchar.h>
|
||||
#include <memory>
|
||||
|
||||
// TODO: 在此处引用程序要求的附加头文件
|
||||
|
||||
#include "lib_acl.h"
|
||||
#include "acl_cpp/lib_acl.hpp"
|
||||
#include "fiber/lib_fiber.h"
|
||||
#include "fiber/lib_fiber.hpp"
|
||||
|
||||
#ifdef WIN32
|
||||
#define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#undef logger
|
||||
#undef logger_warn
|
||||
#undef logger_error
|
||||
#undef logger_fatal
|
||||
#undef logger_debug
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
# if _MSC_VER >= 1500
|
||||
# define logger(fmt, ...) \
|
||||
acl::log::msg4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
|
||||
# define logger_warn(fmt, ...) \
|
||||
acl::log::warn4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
|
||||
# define logger_error(fmt, ...) \
|
||||
acl::log::error4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
|
||||
# define logger_fatal(fmt, ...) \
|
||||
acl::log::fatal4(__FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
|
||||
# define logger_debug(section, level, fmt, ...) \
|
||||
acl::log::msg6(section, level, __FILE__, __LINE__, __FUNCTION__, fmt, __VA_ARGS__)
|
||||
# else
|
||||
# define logger acl::log::msg1
|
||||
# define logger_warn acl::log::warn1
|
||||
# define logger_error acl::log::error1
|
||||
# define logger_fatal acl::log::fatal1
|
||||
# define logger_debug acl::log::msg3
|
||||
# endif
|
||||
#else
|
||||
# define logger(fmt, args...) \
|
||||
acl::log::msg4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
|
||||
# define logger_warn(fmt, args...) \
|
||||
acl::log::warn4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
|
||||
# define logger_error(fmt, args...) \
|
||||
acl::log::error4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
|
||||
# define logger_fatal(fmt, args...) \
|
||||
acl::log::fatal4(__FILE__, __LINE__, __FUNCTION__, fmt, ##args)
|
||||
# define logger_debug(section, level, fmt, args...) \
|
||||
acl::log::msg6(section, level, __FILE__, __LINE__, __FUNCTION__, fmt, ##args)
|
||||
#endif // !_WIN32 && !_WIN64
|
||||
|
||||
extern acl::master_str_tbl var_conf_str_tab[];
|
||||
|
||||
extern int var_cfg_disable_serialize;
|
||||
extern int var_cfg_disable_save;
|
||||
extern acl::master_bool_tbl var_conf_bool_tab[];
|
||||
|
||||
extern acl::master_int_tbl var_conf_int_tab[];
|
||||
extern acl::master_int64_tbl var_conf_int64_tab[];
|
||||
|
||||
//#define HAS_VECTOR
|
@ -1,7 +0,0 @@
|
||||
*3
|
||||
$3
|
||||
SET
|
||||
$3
|
||||
key
|
||||
$5
|
||||
value
|
@ -1,237 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/19.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "coder/redis_ocache.h"
|
||||
#include "coder/redis_coder.h"
|
||||
|
||||
#include "test_coder.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
bool test_redis_parse(const char* filepath) {
|
||||
if (!test_redis_parse_once(filepath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("\r\n");
|
||||
|
||||
if (!test_redis_parse_stream(filepath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_redis_parse_once(const char* filepath) {
|
||||
acl::string buf;
|
||||
if (!acl::ifstream::load(filepath, buf)) {
|
||||
printf("load %s error %s\r\n", filepath, acl::last_serror());
|
||||
return false;
|
||||
}
|
||||
|
||||
redis_ocache cache;
|
||||
redis_coder parser(cache);
|
||||
const char* data = buf.c_str();
|
||||
size_t len = buf.size();
|
||||
const char* left = parser.update(data, len);
|
||||
|
||||
if (len > 0) {
|
||||
printf(">>>%s: parse failed<<<\r\n", __func__);
|
||||
printf("%s\r\n", left);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf(">>>%s: parse success<<<\r\n", __func__);
|
||||
|
||||
std::string out;
|
||||
|
||||
if (!parser.to_string(out)) {
|
||||
printf(">>>%s: build failed<<<\r\n", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (out != std::string(buf.c_str())) {
|
||||
printf(">>>%s: build failed<<<\r\n", __func__);
|
||||
printf("output:\r\n|%s|\r\n", out.c_str());
|
||||
printf("input:\r\n|%s|\r\n", buf.c_str());
|
||||
|
||||
acl::string filetmp(filepath);
|
||||
filetmp += ".tmp";
|
||||
acl::ofstream fp;
|
||||
if (fp.open_trunc(filetmp)) {
|
||||
fp.write(out.c_str(), out.size());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s\r\n", out.c_str());
|
||||
printf(">>>%s: build successfully<<<\r\n", __func__);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_redis_parse_stream(const char* filepath) {
|
||||
acl::string buf;
|
||||
|
||||
if (!acl::ifstream::load(filepath, buf)) {
|
||||
printf("load %s error %s\r\n", filepath, acl::last_serror());
|
||||
return false;
|
||||
}
|
||||
|
||||
redis_ocache cache;
|
||||
redis_coder parser(cache);
|
||||
const char* data = buf.c_str();
|
||||
size_t len = buf.size();
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
char ch = *data++;
|
||||
size_t n = 1;
|
||||
//putchar(ch);
|
||||
const char* left = parser.update(&ch, n);
|
||||
if (n > 0) {
|
||||
printf(">>>%s(%d): parse failed, left=%s<<<\r\n", __func__, __LINE__, left);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
printf(">>%s(%d): parse successfully<<<\r\n", __func__, __LINE__);
|
||||
|
||||
std::string out;
|
||||
|
||||
if (!parser.to_string(out)) {
|
||||
printf(">>%s(%d): build failed<<\r\n", __func__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (out != std::string(buf.c_str())) {
|
||||
printf("%s\r\n", out.c_str());
|
||||
printf(">>%s(%d): build failed<<\r\n", __func__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
printf("%s\r\n", out.c_str());
|
||||
const char* cmd = parser.get_objects()[0]->get_cmd();
|
||||
printf(">>%s(%d): build successfully, cmd=%s<<\r\n",
|
||||
__func__, __LINE__, cmd ? cmd : "unknown");
|
||||
return true;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool test_redis_build() {
|
||||
redis_ocache cache;
|
||||
redis_coder builder(cache);
|
||||
|
||||
auto& obj = builder.create_object();
|
||||
|
||||
#if 0
|
||||
obj.create_child().set_string("HMSET");
|
||||
obj.create_child().set_string("hash-key");
|
||||
obj.create_child().set_string("field1");
|
||||
obj.create_child().set_string("vaule1");
|
||||
obj.create_child().set_string("field2");
|
||||
obj.create_child().set_string("value2");
|
||||
obj.create_child().set_string("field3");
|
||||
obj.create_child().set_string("value3");
|
||||
#else
|
||||
obj.create_child().set_string("HMSET", true)
|
||||
.create_child().set_string("hash-key", true)
|
||||
.create_child().set_string("field1", true)
|
||||
.create_child().set_string("value1", true)
|
||||
.create_child().set_string("field2", true)
|
||||
.create_child().set_string("value2", true)
|
||||
.create_child().set_string("field3", true)
|
||||
.create_child().set_string("value3", true);
|
||||
#endif
|
||||
|
||||
std::string buf;
|
||||
if (builder.to_string(buf)) {
|
||||
const char* cmd = obj.get_cmd();
|
||||
printf("%s(%d): build redis successfully, cmd=%s\r\n",
|
||||
__func__, __LINE__, cmd ? cmd : "unknown");
|
||||
printf("[%s]\r\n", buf.c_str());
|
||||
} else {
|
||||
printf("%s(%d): build redis failed\r\n", __func__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t redis_build_bench(size_t max) {
|
||||
#if 0
|
||||
redis_ocache cache;
|
||||
size_t i = 0;
|
||||
|
||||
for (; i < max; i++) {
|
||||
redis_object obj(cache);
|
||||
|
||||
obj.set_number(-1);
|
||||
}
|
||||
#elif 1
|
||||
redis_ocache cache;
|
||||
redis_coder builder(cache);
|
||||
size_t i = 0;
|
||||
|
||||
for (; i < max; i++) {
|
||||
std::string buff;
|
||||
|
||||
// builder.create_object()
|
||||
// .create_child().set_string("string", true)
|
||||
// .create_child().set_number(-1);
|
||||
//builder.create_object().set_status("hello world!");
|
||||
//builder.create_object().set_status("hello world!");
|
||||
//builder.create_object().set_number(-1);
|
||||
builder.create_object().set_number(-1);
|
||||
builder.to_string(buff);
|
||||
builder.clear();
|
||||
}
|
||||
#else
|
||||
size_t i = 0;
|
||||
|
||||
for (; i < max; i++) {
|
||||
std::string buff;
|
||||
dao::string dao;
|
||||
dao.set_string("hello world");
|
||||
if (!dao.to_string(buff)) {
|
||||
printf("to_string error\r\n");
|
||||
break;
|
||||
}
|
||||
if (i == 0) {
|
||||
printf("%s\r\n", buff.c_str());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return i;
|
||||
}
|
||||
|
||||
size_t redis_parse_bench(const char* filepath, size_t max) {
|
||||
acl::string buff;
|
||||
if (!acl::ifstream::load(filepath, buff)) {
|
||||
printf("Load from %s error %s\r\n", filepath, acl::last_serror());
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("Load ok:\r\n%s\r\n", buff.c_str());
|
||||
|
||||
redis_ocache cache;
|
||||
redis_coder parser(cache);
|
||||
|
||||
size_t i = 0;
|
||||
|
||||
for (; i < max; i++) {
|
||||
const char* data = buff.c_str();
|
||||
size_t len = buff.size();
|
||||
|
||||
(void) parser.update(data, len);
|
||||
if (len > 0) {
|
||||
printf("parse error, left=%zd\r\n", len);
|
||||
break;
|
||||
}
|
||||
parser.clear();
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,17 +0,0 @@
|
||||
//
|
||||
// Created by shuxin ¡¡¡¡zheng on 2023/7/19.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace pkv {
|
||||
|
||||
bool test_redis_parse(const char* filepath);
|
||||
bool test_redis_parse_once(const char* filepath);
|
||||
bool test_redis_parse_stream(const char* filepath);
|
||||
|
||||
bool test_redis_build();
|
||||
size_t redis_build_bench(size_t max);
|
||||
size_t redis_parse_bench(const char* filepath, size_t max);
|
||||
|
||||
} // namespace pkv
|
@ -1,101 +0,0 @@
|
||||
//
|
||||
// Created by zsx on 2023/8/13.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "test_db.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
test_db::test_db() {}
|
||||
|
||||
test_db::~test_db() {}
|
||||
|
||||
void test_db::bench(const std::string &path, size_t max) {
|
||||
rdb_bench(path, max);
|
||||
wdb_bench(path, max);
|
||||
}
|
||||
|
||||
void test_db::rdb_bench(const std::string &path, size_t max) {
|
||||
auto db = db::create_rdb();
|
||||
if (!db->open(path.c_str())) {
|
||||
printf("%s: open %s db error %s\r\n",
|
||||
__func__, path.c_str(), acl::last_serror());
|
||||
} else {
|
||||
bench(db, max);
|
||||
// Close the db
|
||||
db = nullptr;
|
||||
}
|
||||
}
|
||||
void test_db::wdb_bench(const std::string &path, size_t max) {
|
||||
auto db = db::create_wdb();
|
||||
if (!db->open(path.c_str())) {
|
||||
printf("%s: open %s db error %s\r\n",
|
||||
__func__, path.c_str(), acl::last_serror());
|
||||
} else {
|
||||
bench(db, max);
|
||||
// Close the db
|
||||
db = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void test_db::bench(shared_db &db, size_t max) {
|
||||
printf("Begin test %s, count=%zd\r\n", db->get_dbtype(), max);
|
||||
|
||||
struct timeval begin;
|
||||
gettimeofday(&begin, nullptr);
|
||||
|
||||
size_t n = bench_set(db, max);
|
||||
|
||||
struct timeval end;
|
||||
gettimeofday(&end, nullptr);
|
||||
double cost = acl::stamp_sub(end, begin);
|
||||
double speed = (n * 1000) / (cost > 0 ? cost : 0.0001);
|
||||
printf("%s: count=%zd, cost=%.2f ms, set speed=%.2f\r\n",
|
||||
db->get_dbtype(), n, cost, speed);
|
||||
|
||||
gettimeofday(&begin, nullptr);
|
||||
n = bench_get(db, max);
|
||||
gettimeofday(&end, nullptr);
|
||||
|
||||
cost = acl::stamp_sub(end, begin);
|
||||
speed = (n * 1000) / (cost > 0 ? cost : 0.0001);
|
||||
printf("%s: count=%zd, cost=%.2f ms, get speed=%.2f\r\n",
|
||||
db->get_dbtype(), n, cost, speed);
|
||||
}
|
||||
|
||||
size_t test_db::bench_set(pkv::shared_db &db, size_t max) {
|
||||
size_t i;
|
||||
for (i = 0; i < max; i++) {
|
||||
std::string key("key-");
|
||||
key += std::to_string(i);
|
||||
|
||||
std::string val("val-");
|
||||
val += std::to_string(i);
|
||||
if (!db->set(key, val)) {
|
||||
printf("%s: dbtype=%s, set error, key=%s, val=%s\r\n",
|
||||
__func__, db->get_dbtype(), key.c_str(), val.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
size_t test_db::bench_get(pkv::shared_db &db, size_t max) {
|
||||
size_t i;
|
||||
for (i = 0; i < max; i++) {
|
||||
std::string key("key-");
|
||||
key += std::to_string(i);
|
||||
|
||||
std::string val;
|
||||
if (!db->get(key, val)) {
|
||||
printf("%s: dbtype=%s, set error, key=%s\r\n",
|
||||
__func__, db->get_dbtype(), key.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
} // namespace pkv
|
@ -1,23 +0,0 @@
|
||||
//
|
||||
// Created by zsx on 2023/8/13.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include "db/db.h"
|
||||
|
||||
namespace pkv {
|
||||
|
||||
class test_db {
|
||||
public:
|
||||
test_db();
|
||||
~test_db();
|
||||
|
||||
static void bench(const std::string& path, size_t max);
|
||||
static void bench(shared_db& db, size_t max);
|
||||
static size_t bench_set(shared_db& db, size_t max);
|
||||
static size_t bench_get(shared_db& db, size_t max);
|
||||
static void rdb_bench(const std::string& path, size_t max);
|
||||
static void wdb_bench(const std::string& path, size_t max);
|
||||
};
|
||||
|
||||
} // namespace pkv
|
@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
valgrind --tool=memcheck --leak-check=yes -v ./pkv alone pkv.cf
|
@ -1,129 +0,0 @@
|
||||
|
||||
service pkv
|
||||
{
|
||||
# 进程是否禁止运行
|
||||
master_disable = no
|
||||
# 服务地址及端口号
|
||||
# for master_type = inet
|
||||
# master_service = 127.0.0.1|5001
|
||||
# for master_type = unix
|
||||
# master_service = echo.sock
|
||||
# for master_type = sock
|
||||
master_service = 127.0.0.1|19001
|
||||
|
||||
# 服务监听为域套接口
|
||||
# master_service = aio_echo.sock
|
||||
# 服务类型
|
||||
# master_type = inet
|
||||
# master_type = unix
|
||||
master_type = sock
|
||||
|
||||
# 停止子进程时是否采用强行停止的方式(即给子进程发送 SIGTERM 信号)
|
||||
master_stop_kill = false
|
||||
# 当 master_stop_kill 为 true 时,该配置决定是否要等待子进程退出
|
||||
master_stop_wait = false
|
||||
|
||||
# 当系统支持 SO_REUSEPORT 时,是否启用该功能
|
||||
master_reuseport = yes
|
||||
# 当启用 SO_REUSEPORT 时(即 master_reuseport=yes 时), 是否需要 acl_master
|
||||
# 也监听该地址, 对于使用旧版 acl(< 3.5.3-17) 编写的服务, 必须将此项设为
|
||||
# yes, 即: master_reuseport_listen = yes; 对于使用 acl 版本 >= 3.5.3-17
|
||||
# 编写的服务需设置为 no; 当 master_reuseport=no时,该项设置将被忽略; 当未
|
||||
# 设置此项时内部缺省值为 yes. 以便使 acl_master 保持对于旧版服务的兼容性.
|
||||
master_reuseport_listen = no
|
||||
# 是否针对监听套接口设定为非阻塞方式
|
||||
master_nonblock = yes
|
||||
# 当系统支持 TCP_FASTOPEN 时,是否启用该功能
|
||||
master_fastopen = no
|
||||
|
||||
# 当子进程异常退出时,如果该值非空,则将子进程异常退出的消息通知该服务
|
||||
# master_notify_addr = 127.0.0.1:5801
|
||||
# 邮件通知接收者
|
||||
# master_notify_recipients = zhengshuxin@hotmail.com
|
||||
|
||||
# 是否允许延迟接受客户端连接,如果为0则表示关闭该功能,如果大于0则表示打开此功能
|
||||
# 并且此值代表延迟接受连接的超时值,超过此值时如果客户端依然没有发来数据,则操作
|
||||
# 系统会在系统层直接关闭该连接
|
||||
# master_defer_accept = 0
|
||||
# 是否只允许私有访问, 如果为 y, 则域套接口创建在 {install_path}/var/log/private/ 目录下,
|
||||
# 如果为 n, 则域套接口创建在 {install_path}/var/log/public/ 目录下,
|
||||
master_private = n
|
||||
master_unpriv = n
|
||||
# 是否需要 chroot: n -- no, y -- yes
|
||||
master_chroot = n
|
||||
# 每隔多长时间触发一次,单位为秒(仅对 trigger 模式有效)
|
||||
master_wakeup = -
|
||||
# 最大进程数
|
||||
master_maxproc = 1
|
||||
# 预启动进程数,该值不得大于 master_maxproc
|
||||
master_prefork = 1
|
||||
# 进程程序名
|
||||
master_command = {install_path}/sbin/pkv
|
||||
# 进程日志记录文件
|
||||
master_log = {install_path}/var/log/pkv.log
|
||||
# 调试日志方式,格式:tag:level; tag:level; tab:level, 如:all:1; 101:2
|
||||
# master_debug =
|
||||
# 进程启动参数,只能为: -u [是否允许以某普通用户的身份运行]
|
||||
# master_args =
|
||||
# 传递给服务子进程的环境变量, 可以通过 getenv("SERVICE_ENV") 获得此值
|
||||
# master_env = mempool_limit:512000000
|
||||
# 当启动多个子进程实例时,该开关控制多个子进程在接收连接时是否向 acl_master 发送消息报告自己的状态
|
||||
# master_status_notify = 1
|
||||
# 程序标准输出重定向至指定文件中
|
||||
# master_stdout = {install_path}/var/log/stdout.log
|
||||
# 程序错误输出重定向至指定文件中
|
||||
# master_stderr = {install_path}/var/log/stderr.log
|
||||
|
||||
# 事件引擎: kernel, poll, select, io_uring
|
||||
fiber_schedule_event = kernel
|
||||
# fiber_schedule_event = io_uring
|
||||
# 是否允许产生 core 文件
|
||||
# fiber_enable_core = 1
|
||||
# core 文件大小限制,-1 表示不限制 core 文件大小,0 表示禁止产生 core,> 0 表示 core 文件最大大小
|
||||
# fiber_core_limit = -1
|
||||
# 进程退出时是否禁止产生 core 文件
|
||||
# fiber_disable_core_onexit = 1
|
||||
# 每个进程实例处理连接数的最大次数,超过此值后进程实例主动退出
|
||||
fiber_use_limit = 0
|
||||
# 每个进程实例的空闲超时时间,超过此值后进程实例主动退出
|
||||
fiber_idle_limit = 0
|
||||
# 每个进程启动的线程数
|
||||
fiber_threads = 1
|
||||
# 进程运行时所在的路径
|
||||
fiber_queue_dir = {install_path}/var
|
||||
# 读写超时时间, 单位为秒
|
||||
fiber_rw_timeout = 120
|
||||
# 读缓冲区的缓冲区大小
|
||||
fiber_buf_size = 8192
|
||||
# 进程运行时的用户身份
|
||||
fiber_owner = root
|
||||
|
||||
# 当启用 master_dispatch 连接分开服务后,该配置指定 master_dispatch 所监听的
|
||||
# 域套接口的全路径,这样本子进程就可以从 master_dispatch 获得客户端连接
|
||||
# fiber_dispatch_addr = {install_path}/var/private/dispatch.sock
|
||||
# 当 fiber_dispatch_addr 开启后,下面参数控制本服务进程发给前端 master_dispatch 的服务标识信息
|
||||
# fiber_dispatch_type = default
|
||||
|
||||
# 线程的堆栈空间大小,单位为字节
|
||||
fiber_stack_size = 256000
|
||||
# 允许访问 udserver 的客户端IP地址范围
|
||||
# fiber_access_allow = 127.0.0.1:255.255.255.255, 127.0.0.1:127.0.0.1
|
||||
fiber_access_allow = all
|
||||
|
||||
# 当 acl_master 退出时,如果该值置1则该程序不等所有连接处理完毕便立即退出
|
||||
fiber_quick_abort = 1
|
||||
|
||||
# 是否启用协程共享栈模式
|
||||
fiber_share_stack = 0
|
||||
|
||||
# 当 fiber_quick_abort 为 0 且本配置项大于 0 时,该配置项才有效,指定了
|
||||
# 本进程在所有连接退出前的最大等待时间(秒)
|
||||
fiber_wait_limit = 0
|
||||
|
||||
############################################################################
|
||||
# 应用自己的配置选项
|
||||
|
||||
buf_size = 8192
|
||||
dbpath = ./data
|
||||
dbtype = wdb
|
||||
}
|
Loading…
Reference in New Issue
Block a user