Skip to content

Commit

Permalink
Clean code.
Browse files Browse the repository at this point in the history
Signed-off-by: vegetableysm <[email protected]>
  • Loading branch information
vegetableysm committed Feb 28, 2024
1 parent 7bdffc6 commit 5c12567
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 94 deletions.
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ option(BUILD_VINEYARD_MALLOC_OVERRIDE "Using the client-side malloc to override
option(BUILD_VINEYARD_FUSE "Enable vineyard's fuse support" OFF)
option(BUILD_VINEYARD_FUSE_PARQUET "Enable vineyard's fuse parquet support" OFF)
option(BUILD_VINEYARD_HOSSEINMOEIN_DATAFRAME "Enable hosseinmoein dataframe support" OFF)
option(BUILD_VINEYARD_KV_STATE_CACHE "Enable kv-state cache support" ON)
option(BUILD_VINEYARD_LLM_CACHE "Enable kv-state cache support" ON)

option(BUILD_VINEYARD_TESTS "Generate make targets for vineyard tests" ON)
option(BUILD_VINEYARD_TESTS_ALL "Include make targets for vineyard tests to ALL" OFF)
Expand Down Expand Up @@ -933,9 +933,9 @@ if(BUILD_VINEYARD_HOSSEINMOEIN_DATAFRAME)
list(APPEND VINEYARD_INSTALL_LIBS vineyard_hosseinmoein_dataframe)
endif()

if(BUILD_VINEYARD_KV_STATE_CACHE)
add_subdirectory(modules/kv-state-cache)
list(APPEND VINEYARD_INSTALL_LIBS vineyard_kv_state_cache)
if(BUILD_VINEYARD_LLM_CACHE)
add_subdirectory(modules/llm-cache)
list(APPEND VINEYARD_INSTALL_LIBS vineyard_llm_cache)
endif()

if(BUILD_VINEYARD_TESTS)
Expand Down Expand Up @@ -981,7 +981,7 @@ endfunction()

file_glob_recurse(FILES_NEED_FORMAT DIRECTORIES "src" "modules" "python" "test" "benchmark"
PATTERNS ".*\\.(cc|cpp|h|hpp|vineyard-mod)$"
EXCLUDE_PATTERNS "(.*\\.vineyard.h$)|(.*modules/kv-state-cache/radix-tree/radix\.(cc|h)$)"
EXCLUDE_PATTERNS "(.*\\.vineyard.h$)|(.*modules/llm-cache/radix-tree/radix\.(cc|h)$)"
)

# the `memcpy.h` is borrowed from external project
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ SOFTWARE.

-------------------------------------------------------------------------------

The files modules/kv-state-cache/radix-tree/{radix.cc, radix.h, rax_malloc} is referred from project antirez/rax,
The files modules/llm-cache/radix-tree/{radix.cc, radix.h, rax_malloc} is referred from project antirez/rax,
which has the following license:

Copyright (c) 2017, Salvatore Sanfilippo <[email protected]>
Expand Down
18 changes: 0 additions & 18 deletions modules/kv-state-cache/CMakeLists.txt

This file was deleted.

16 changes: 16 additions & 0 deletions modules/llm-cache/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
file(GLOB VINEYARD_LLM_CACHE_SRCS "${CMAKE_CURRENT_SOURCE_DIR}"
"ds/*.cc"
"ds/*.h"
"radix-tree/*.cc"
"radix-tree/*.h"
"utils/*.cc"
"utils/*.h"
)

add_library(vineyard_llm_cache ${VINEYARD_LLM_CACHE_SRCS})
target_link_libraries(vineyard_llm_cache PUBLIC vineyard_client vineyard_basic)

install_export_vineyard_target(vineyard_llm_cache)
install_vineyard_headers("${CMAKE_CURRENT_SOURCE_DIR}/utils/")
install_vineyard_headers("${CMAKE_CURRENT_SOURCE_DIR}/ds/")
install_vineyard_headers("${CMAKE_CURRENT_SOURCE_DIR}/radix-tree/")
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ limitations under the License.
#include "common/util/base64.h"
#include "common/util/logging.h"
#include "common/util/status.h"
#include "kv-state-cache/ds/kv_state_cache.h"
#include "kv-state-cache/radix-tree/radix-tree.h"
#include "kv-state-cache/radix-tree/radix.h"
#include "llm-cache/ds/kv_state_cache.h"
#include "llm-cache/radix-tree/radix-tree.h"
#include "llm-cache/radix-tree/radix.h"

namespace vineyard {

Expand Down Expand Up @@ -63,9 +63,7 @@ void KVStateCache::Resolve() {
<< " layer:" << this->layer;
}

KVStateCache::~KVStateCache() {
// TBD
}
KVStateCache::~KVStateCache() {}

KVStateCacheBuilder::KVStateCacheBuilder(Client& client, int dimension,
int cacheCapacity, int layer,
Expand Down Expand Up @@ -200,8 +198,6 @@ void KVStateCacheBuilder::Update(Client& client,
<< " bitmap:" << kvStateCacheBlockBuilder->GetBitmapStr();
}

static std::shared_ptr<NodeData> node;

KV_STATE_WITH_LAYER KVStateCacheBuilder::Query(
Client& client, const std::vector<int>& tokenList, int token) {
std::vector<int> tokenListCopy = tokenList;
Expand Down Expand Up @@ -285,10 +281,7 @@ void KVStateCacheBuilder::Merge(Client& client,
return;
}

Status KVStateCacheBuilder::Build(Client& client) {
// TBD
return Status::OK();
}
Status KVStateCacheBuilder::Build(Client& client) { return Status::OK(); }

std::shared_ptr<Object> KVStateCacheBuilder::_Seal(Client& client) {
this->Build(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ limitations under the License.
#include "client/client.h"
#include "common/util/logging.h"
#include "common/util/status.h"
#include "kv-state-cache/ds/kv_state_cache_block.h"
#include "kv-state-cache/radix-tree/radix-tree.h"
#include "llm-cache/ds/kv_state_cache_block.h"
#include "llm-cache/radix-tree/radix-tree.h"

#ifndef MODULES_KV_STATE_CACHE_DS_KV_STATE_CACHE_H_
#define MODULES_KV_STATE_CACHE_DS_KV_STATE_CACHE_H_
#ifndef MODULES_LLM_CACHE_DS_KV_STATE_CACHE_H_
#define MODULES_LLM_CACHE_DS_KV_STATE_CACHE_H_

namespace vineyard {

Expand Down Expand Up @@ -120,4 +120,4 @@ class KVStateCacheBuilder : public vineyard::ObjectBuilder {

} // namespace vineyard

#endif // MODULES_KV_STATE_CACHE_DS_KV_STATE_CACHE_H_
#endif // MODULES_LLM_CACHE_DS_KV_STATE_CACHE_H_
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ limitations under the License.

#include "client/client.h"
#include "common/util/logging.h"
#include "kv-state-cache/ds/kv_state_cache_block.h"
#include "llm-cache/ds/kv_state_cache_block.h"

namespace vineyard {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef MODULES_KV_STATE_CACHE_DS_KV_STATE_CACHE_BLOCK_H_
#define MODULES_KV_STATE_CACHE_DS_KV_STATE_CACHE_BLOCK_H_
#ifndef MODULES_LLM_CACHE_DS_KV_STATE_CACHE_BLOCK_H_
#define MODULES_LLM_CACHE_DS_KV_STATE_CACHE_BLOCK_H_

#include <array>
#include <iostream>
Expand All @@ -27,17 +27,16 @@ limitations under the License.
#include "basic/ds/tensor.h"
#include "client/ds/blob.h"
#include "client/ds/i_object.h"
#include "kv-state-cache/radix-tree/radix-tree.h"

typedef std::map<int, std::pair<std::vector<double>, std::vector<double>>>
KV_STATE_WITH_LAYER;
typedef std::vector<
std::map<int, std::pair<std::vector<double>, std::vector<double>>>>
LIST_KV_STATE_WITH_LAYER;
typedef std::vector<std::pair<std::vector<double>, std::vector<double>>>
KV_STATE;
typedef std::vector<std::pair<std::vector<double>, std::vector<double>>>
LIST_KV_STATE;
#include "llm-cache/radix-tree/radix-tree.h"

using KV_STATE_WITH_LAYER =
std::map<int, std::pair<std::vector<double>, std::vector<double>>>;
using LIST_KV_STATE_WITH_LAYER = std::vector<
std::map<int, std::pair<std::vector<double>, std::vector<double>>>>;
using KV_STATE =
std::vector<std::pair<std::vector<double>, std::vector<double>>>;
using LIST_KV_STATE =
std::vector<std::pair<std::vector<double>, std::vector<double>>>;

// Set the bit to 1, which means the resource is not being used
#define FREE_BIT_RESOURCE(value, bit) ((value) |= (((uint64_t) 1) << (bit)))
Expand Down Expand Up @@ -203,4 +202,4 @@ class KVStateCacheBlockBuilder : public ObjectBuilder {

} // namespace vineyard

#endif // MODULES_KV_STATE_CACHE_DS_KV_STATE_CACHE_BLOCK_H_
#endif // MODULES_LLM_CACHE_DS_KV_STATE_CACHE_BLOCK_H_
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#include "kv-state-cache/radix-tree/radix-tree.h"
#include "llm-cache/radix-tree/radix-tree.h"

#include "common/util/base64.h"
#include "common/util/logging.h"
Expand Down Expand Up @@ -319,7 +319,7 @@ std::shared_ptr<RadixTree> RadixTree::Deserialize(std::string data) {
data.erase(0, sizeof(int));
int rootNumNodes = *reinterpret_cast<uint32_t*>(data.data());
data.erase(0, sizeof(uint32_t));
unsigned long long ds = ZSTD_getFrameContentSize(data.c_str(), data.size());
uint64_t ds = ZSTD_getFrameContentSize(data.c_str(), data.size());
if (ds == ZSTD_CONTENTSIZE_ERROR) {
LOG(ERROR) << "Error: not a valid compressed frame";
} else if (ds == ZSTD_CONTENTSIZE_UNKNOWN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef MODULES_KV_STATE_CACHE_RADIX_TREE_RADIX_TREE_H_
#define MODULES_KV_STATE_CACHE_RADIX_TREE_RADIX_TREE_H_
#ifndef MODULES_LLM_CACHE_RADIX_TREE_RADIX_TREE_H_
#define MODULES_LLM_CACHE_RADIX_TREE_RADIX_TREE_H_

#include "kv-state-cache/radix-tree/radix.h"
#include "llm-cache/radix-tree/radix.h"

#include <iomanip>
#include <map>
Expand Down Expand Up @@ -118,4 +118,4 @@ class RadixTree : public std::enable_shared_from_this<RadixTree> {
std::set<void*> GetAllNodeData();
};

#endif // MODULES_KV_STATE_CACHE_RADIX_TREE_RADIX_TREE_H_"
#endif // MODULES_LLM_CACHE_RADIX_TREE_RADIX_TREE_H_
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
* the include of your alternate allocator if needed (not needed in order
* to use the default libc allocator). */

#ifndef MODULES_KV_STATE_CACHE_RADIX_TREE_RAX_MALLOC_H_
#define MODULES_KV_STATE_CACHE_RADIX_TREE_RAX_MALLOC_H_
#ifndef MODULES_LLM_CACHE_RADIX_TREE_RAX_MALLOC_H_
#define MODULES_LLM_CACHE_RADIX_TREE_RAX_MALLOC_H_
#define rax_malloc malloc
#define rax_realloc realloc
#define rax_free free

#endif // MODULES_KV_STATE_CACHE_RADIX_TREE_RAX_MALLOC_H_
#endif // MODULES_LLM_CACHE_RADIX_TREE_RAX_MALLOC_H_
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ limitations under the License.

#include "client/client.h"
#include "common/util/logging.h"
#include "kv-state-cache/ds/kv_state_cache.h"
#include "kv-state-cache/utils/kv_state_cache_utils.h"
#include "llm-cache/ds/kv_state_cache.h"
#include "llm-cache/utils/kv_state_cache_utils.h"

namespace vineyard {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ limitations under the License.
#include <string>
#include <vector>

#include "kv-state-cache/ds/kv_state_cache.h"
#include "llm-cache/ds/kv_state_cache.h"

#ifndef MODULES_KV_STATE_CACHE_UTILS_KV_STATE_CACHE_UTILS_H_
#define MODULES_KV_STATE_CACHE_UTILS_KV_STATE_CACHE_UTILS_H_
#ifndef MODULES_LLM_CACHE_UTILS_KV_STATE_CACHE_UTILS_H_
#define MODULES_LLM_CACHE_UTILS_KV_STATE_CACHE_UTILS_H_

namespace vineyard {

Expand All @@ -44,4 +44,4 @@ void CloseKVStateCache();

} // namespace vineyard

#endif // MODULES_KV_STATE_CACHE_UTILS_KV_STATE_CACHE_UTILS_H_
#endif // MODULES_LLM_CACHE_UTILS_KV_STATE_CACHE_UTILS_H_
7 changes: 1 addition & 6 deletions src/server/services/etcd_meta_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,17 @@ void EtcdMetaService::Stop() {

void EtcdMetaService::TryAcquireLock(
std::string key, callback_t<bool, std::string> callback_after_try_lock) {
LOG(INFO) << "TryAcquireLock, key:" << key;
auto self(shared_from_base());

etcd_->lock(prefix_ + key)
.then([self, callback_after_try_lock](
pplx::task<etcd::Response> const& resp_task) {
auto const& resp = resp_task.get();
if (resp.is_ok()) {
LOG(INFO) << "lock success! key is :" + resp.lock_key();
self->server_ptr_->GetMetaContext().post(
boost::bind(callback_after_try_lock, Status::OK(), true,
resp.lock_key().substr(self->prefix_.size())));
} else {
LOG(INFO) << "lock failed!";
self->server_ptr_->GetMetaContext().post(
boost::bind(callback_after_try_lock, Status::OK(), false, ""));
}
Expand All @@ -182,13 +179,11 @@ void EtcdMetaService::TryReleaseLock(
pplx::task<etcd::Response> const& resp_task) {
auto const& resp = resp_task.get();
if (resp.is_ok()) {
LOG(INFO) << "unlock success!";
self->server_ptr_->GetMetaContext().post(
boost::bind(callback_after_try_unlock, Status::OK(), true));
} else {
LOG(INFO) << "unlock failed!";
self->server_ptr_->GetMetaContext().post(
boost::bind(callback_after_try_unlock, Status::OK(), true));
boost::bind(callback_after_try_unlock, Status::OK(), false));
}
});
}
Expand Down
12 changes: 6 additions & 6 deletions src/server/services/local_meta_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class LocalMetaService : public IMetaService {
~LocalMetaService() override {}

void TryAcquireLock(std::string key,
callback_t<bool, std::string> callback_after_try_locked) {
// TBD
assert(false);
callback_t<bool, std::string> callback_after_try_lock) {
server_ptr_->GetMetaContext().post(boost::bind(
callback_after_try_lock, Status::NotImplemented(), false, ""));
}

void TryReleaseLock(std::string key,
callback_t<bool> callback_after_try_unlocked) {
// TBD
assert(false);
callback_t<bool> callback_after_try_unlock) {
server_ptr_->GetMetaContext().post(boost::bind(
callback_after_try_unlock, Status::NotImplemented(), false));
}

protected:
Expand Down
12 changes: 6 additions & 6 deletions src/server/services/redis_meta_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,15 @@ class RedisMetaService : public IMetaService {
~RedisMetaService() override {}

void TryAcquireLock(std::string key,
callback_t<bool, std::string> callback_after_try_locked) {
// TBD
assert(false);
callback_t<bool, std::string> callback_after_try_lock) {
server_ptr_->GetMetaContext().post(boost::bind(
callback_after_try_lock, Status::NotImplemented, false, ""));
}

void TryReleaseLock(std::string key,
callback_t<bool> callback_after_try_unlocked) {
// TBD
assert(false);
callback_t<bool> callback_after_try_unlock) {
server_ptr_->GetMetaContext().post(
boost::bind(callback_after_try_unlock, Status::NotImplemented, false));
}

protected:
Expand Down
2 changes: 1 addition & 1 deletion test/kv_state_cache_benchmark_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ limitations under the License.
#include "client/ds/object_meta.h"
#include "common/util/logging.h"

#include "kv-state-cache/utils/kv_state_cache_utils.h"
#include "llm-cache/utils/kv_state_cache_utils.h"

using namespace vineyard; // NOLINT(build/namespaces)

Expand Down
4 changes: 2 additions & 2 deletions test/kv_state_cache_radix_tree_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ limitations under the License.
#include <iostream>
#include <random>
#include <vector>
#include "kv-state-cache/radix-tree/radix.h"
#include "llm-cache/radix-tree/radix.h"

#include "common/util/logging.h"
#include "kv-state-cache/utils/kv_state_cache_utils.h"
#include "llm-cache/utils/kv_state_cache_utils.h"

using namespace vineyard; // NOLINT(build/namespaces)

Expand Down
4 changes: 2 additions & 2 deletions test/kv_state_cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ limitations under the License.
#include <iostream>
#include <random>
#include <vector>
#include "kv-state-cache/radix-tree/radix.h"
#include "llm-cache/radix-tree/radix.h"

#include "common/util/logging.h"
#include "kv-state-cache/utils/kv_state_cache_utils.h"
#include "llm-cache/utils/kv_state_cache_utils.h"

using namespace vineyard; // NOLINT(build/namespaces)

Expand Down

0 comments on commit 5c12567

Please sign in to comment.