Skip to content

Commit

Permalink
test pkv.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengshuxin committed Aug 13, 2023
1 parent 1faee05 commit d75199b
Show file tree
Hide file tree
Showing 19 changed files with 113 additions and 87 deletions.
5 changes: 3 additions & 2 deletions app/wizard_demo/pkv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ include_directories(
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
${base_path}/proto
)

foreach(iter ${src_paths})
Expand Down Expand Up @@ -134,7 +135,7 @@ set(output_path ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_path})
link_directories(${output_path})

add_executable(pkv ${src_files})
add_executable(pkv ${src_files} test/test_coder.cpp test/test_coder.h)
target_link_libraries(pkv ${lib_all})

###############################################################################
4 changes: 2 additions & 2 deletions app/wizard_demo/pkv/action/redis_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//

#include "stdafx.h"
#include "proto/redis_object.h"
#include "proto/redis_coder.h"
#include "coder/redis_object.h"
#include "coder/redis_coder.h"
#include "redis_key.h"
#include "redis_string.h"
#include "redis_hash.h"
Expand Down
2 changes: 1 addition & 1 deletion app/wizard_demo/pkv/action/redis_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#pragma once

#include <vector>
#include "proto/redis_coder.h"
#include "coder/redis_coder.h"
#include "db/db.h"

namespace pkv {
Expand Down
4 changes: 2 additions & 2 deletions app/wizard_demo/pkv/action/redis_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//

#include "stdafx.h"
#include "proto/redis_coder.h"
#include "proto/redis_object.h"
#include "coder/redis_coder.h"
#include "coder/redis_object.h"
#include "dao/hash.h"

#include "redis_handler.h"
Expand Down
2 changes: 1 addition & 1 deletion app/wizard_demo/pkv/action/redis_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//

#include "stdafx.h"
#include "proto/redis_coder.h"
#include "coder/redis_coder.h"
#include "dao/key.h"

#include "redis_handler.h"
Expand Down
4 changes: 2 additions & 2 deletions app/wizard_demo/pkv/action/redis_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//

#include "stdafx.h"
#include "proto/redis_coder.h"
#include "proto/redis_object.h"
#include "coder/redis_coder.h"
#include "coder/redis_object.h"

#include "redis_handler.h"
#include "redis_server.h"
Expand Down
4 changes: 2 additions & 2 deletions app/wizard_demo/pkv/action/redis_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
//

#include "stdafx.h"
#include "proto/redis_coder.h"
#include "proto/redis_object.h"
#include "coder/redis_coder.h"
#include "coder/redis_object.h"
#include "dao/string.h"

#include "redis_handler.h"
Expand Down
75 changes: 75 additions & 0 deletions app/wizard_demo/pkv/coder/redis_coder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion app/wizard_demo/pkv/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "stdafx.h"
#include <signal.h>
#include "proto/redis_coder.h"
#include "test/test_coder.h"
#include "master_service.h"

static void on_sigint(int) {
Expand Down
4 changes: 2 additions & 2 deletions app/wizard_demo/pkv/master_service.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "stdafx.h"
#include "proto/redis_ocache.h"
#include "proto/redis_coder.h"
#include "coder/redis_ocache.h"
#include "coder/redis_coder.h"
#include "action/redis_handler.h"
#include "master_service.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,77 +3,12 @@
//

#include "stdafx.h"
#include "redis_ocache.h"
#include "redis_coder.h"
#include "dao/string.h"
#include "coder/redis_ocache.h"
#include "coder/redis_coder.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_);
}
#include "test_coder.h"

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 {

bool test_redis_parse(const char* filepath) {
if (!test_redis_parse_once(filepath)) {
Expand Down Expand Up @@ -299,6 +234,4 @@ size_t redis_parse_bench(const char* filepath, size_t max) {
return i;
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
} // namespace pkv
17 changes: 17 additions & 0 deletions app/wizard_demo/pkv/test/test_coder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// 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
2 changes: 1 addition & 1 deletion app/wizard_demo/pkv/wdb.cf
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ service pkv
# 每个进程实例的空闲超时时间,超过此值后进程实例主动退出
fiber_idle_limit = 0
# 每个进程启动的线程数
fiber_threads = 4
fiber_threads = 1
# 进程运行时所在的路径
fiber_queue_dir = {install_path}/var
# 读写超时时间, 单位为秒
Expand Down

0 comments on commit d75199b

Please sign in to comment.