Skip to content

Commit

Permalink
feat: transform kv and hash command using blackwidow without cache (O…
Browse files Browse the repository at this point in the history
…penAtomFoundation#101)

* migrate bw interface for hset hget hmset hmget hgetall hkeys hlen

* fix: adjust the implementation of string cmd on blackwidow without cache

---------

Co-authored-by: panlei-coder <[email protected]>
  • Loading branch information
Centurybbx and panlei-coder authored Jan 3, 2024
1 parent 9c531c3 commit eb77974
Show file tree
Hide file tree
Showing 11 changed files with 335 additions and 608 deletions.
1 change: 1 addition & 0 deletions cmake/rocksdb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ FetchContent_MakeAvailableWithArgs(rocksdb
WITH_ZLIB=OFF
WITH_ZSTD=OFF
WITH_GFLAGS=OFF
USE_RTTI=ON
)
7 changes: 5 additions & 2 deletions pikiwidb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ port 9221
# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0

# Directory to store the data of PikiwiDB.
db-path ./db

# Specify the server verbosity level.
# This can be one of:
# debug (a lot of information, useful for development/testing)
Expand Down Expand Up @@ -331,8 +334,8 @@ hz 10
# is very limited. Try use leveldb for real storage, pikiwidb as cache. The cache algorithm
# is like linux page cache, please google or read your favorite linux book
# 0 is default, no backend
# 1 is leveldb, currently only support leveldb
backend 0
# 1 is RocksDB, currently only support RocksDB
backend 1
backendpath dump
# the frequency of dump to backend per second
backendhz 10
15 changes: 10 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@

AUX_SOURCE_DIRECTORY(. PIKIWIDB_SRC)

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/pstd)
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src/net)

ADD_EXECUTABLE(pikiwidb ${PIKIWIDB_SRC})
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

TARGET_INCLUDE_DIRECTORIES(pikiwidb PRIVATE ${rocksdb_SOURCE_DIR}/include)
TARGET_LINK_LIBRARIES(pikiwidb net; dl; leveldb; fmt; pikiwidb-folly; rocksdb)
TARGET_INCLUDE_DIRECTORIES(pikiwidb PRIVATE
${PROJECT_SOURCE_DIR}/src
${PROJECT_SOURCE_DIR}/src/pstd
${PROJECT_SOURCE_DIR}/src/net
${PROJECT_SOURCE_DIR}/src/storage/include
${rocksdb_SOURCE_DIR}/
${rocksdb_SOURCE_DIR}/include
)

TARGET_LINK_LIBRARIES(pikiwidb net; dl; leveldb; fmt; pikiwidb-folly; storage; rocksdb)
SET_TARGET_PROPERTIES(pikiwidb PROPERTIES LINKER_LANGUAGE CXX)
12 changes: 12 additions & 0 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "common.h"
#include "proto_parser.h"
#include "replication.h"
#include "storage/storage.h"
#include "tcp_connection.h"

namespace pikiwidb {
Expand Down Expand Up @@ -64,14 +65,19 @@ class CmdRes {

// Inline functions for Create Redis protocol
inline void AppendStringLen(int64_t ori) { RedisAppendLen(message_, ori, "$"); }
inline void AppendStringLenUint64(uint64_t ori) { RedisAppendLenUint64(message_, ori, "$"); }
inline void AppendArrayLen(int64_t ori) { RedisAppendLen(message_, ori, "*"); }
inline void AppendArrayLenUint64(uint64_t ori) { RedisAppendLenUint64(message_, ori, "*"); }
inline void AppendInteger(int64_t ori) { RedisAppendLen(message_, ori, ":"); }
inline void AppendContent(const std::string& value) { RedisAppendContent(message_, value); }
inline void AppendStringRaw(const std::string& value) { message_.append(value); }
inline void SetLineString(const std::string& value) { message_ = value + CRLF; }

void AppendString(const std::string& value);
void AppendStringVector(const std::vector<std::string>& strArray);
void RedisAppendLenUint64(std::string& str, uint64_t ori, const std::string& prefix) {
RedisAppendLen(str, static_cast<int64_t>(ori), prefix);
}

void SetRes(CmdRet _ret, const std::string& content = "");

Expand Down Expand Up @@ -170,6 +176,10 @@ class PClient : public std::enable_shared_from_this<PClient>, public CmdRes {
void SetKey(std::vector<std::string>& names);
const std::string& Key() const { return keys_.at(0); }
const std::vector<std::string>& Keys() const { return keys_; }
std::vector<storage::FieldValue>& Fvs() { return fvs_; }
void ClearFvs() { fvs_.clear(); }
std::vector<std::string>& Fields() { return fields_; }
void ClearFields() { fields_.clear(); }

void SetSlaveInfo();
PSlaveInfo* GetSlaveInfo() const { return slave_info_.get(); }
Expand Down Expand Up @@ -221,6 +231,8 @@ class PClient : public std::enable_shared_from_this<PClient>, public CmdRes {
std::string subCmdName_; // suchAs config set|get|rewrite
std::string cmdName_; // suchAs config
std::vector<std::string> keys_;
std::vector<storage::FieldValue> fvs_;
std::vector<std::string> fields_;

// All parameters of this command (including the command itself)
// e.g:["set","key","value"]
Expand Down
Loading

0 comments on commit eb77974

Please sign in to comment.