-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add cache layer #440
Merged
chejinge
merged 19 commits into
OpenAtomFoundation:unstable
from
hahahashen:feat/addCacheLayer
Oct 25, 2024
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f15e0cf
add dependency
hahahashen fe6d27a
add class rediscache and string rediscache api
hahahashen 144c234
add Class PCache and add dependency correctly
hahahashen 68884bf
read cache config and add cache when processing cmd
hahahashen 7968fd2
add part kv cmd with cache
hahahashen df1ac35
add all kv command with cache
hahahashen 513c996
modify list cmd with cache
hahahashen 7360ca0
delete useless code
hahahashen 2343a78
modify hash cmd with cache
hahahashen a70e4fc
modify set cmd with cache
hahahashen 0263cd3
modify zset command with cache
hahahashen 33cd365
modify zset part cmd with cache and fix count_ bug
hahahashen 67d66c3
comment some tcl cases
hahahashen 0c9c0ce
fix build ci error
hahahashen 2e13ab5
tcl cases
hahahashen f33d48a
fix rename and String2int error
hahahashen 10e5ad9
fix ttl definition
hahahashen f83bc90
clang18 format code
hahahashen 7552978
check clang format version
hahahashen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright (c) 2024-present, Qihoo, Inc. All rights reserved. | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. An additional grant | ||
# of patent rights can be found in the PATENTS file in the same directory. | ||
|
||
SET(REDISCACHE_SOURCES_DIR "${LIB_INSTALL_PREFIX}" CACHE PATH "rediscache source directory." FORCE) | ||
SET(REDISCACHE_INSTALL_DIR "${LIB_INSTALL_PREFIX}" CACHE PATH "rediscache install directory." FORCE) | ||
SET(REDISCACHE_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "rediscache include directory." FORCE) | ||
SET(REDISCACHE_LIBRARIES "${LIB_INSTALL_DIR}/librediscache.a" CACHE FILEPATH "rediscache library." FORCE) | ||
|
||
ExternalProject_Add( | ||
extern_rediscache | ||
${EXTERNAL_PROJECT_LOG_ARGS} | ||
#URL https://github.com/pikiwidb/rediscache/archive/refs/tags/v1.0.7.tar.gz | ||
#URL_HASH MD5=02c8aadc018dd8d4d3803cc420d1d75b | ||
#temp used | ||
GIT_REPOSITORY https://github.com/hahahashen/rediscache.git | ||
GIT_TAG feat/removeUseTcMallocMacroDefinition | ||
CMAKE_ARGS | ||
-DCMAKE_BUILD_TYPE=Debug | ||
-DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX} | ||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON | ||
-DPROJECT_BINARY_DIR=${LIB_INSTALL_PREFIX} | ||
-DCMAKE_FIND_LIBRARY_SUFFIXES=${LIB_INSTALL_PREFIX} | ||
-DSNAPPY_BUILD_TESTS=OFF | ||
-DCMAKE_INSTALL_INCLUDEDIR=${REDISCACHE_INCLUDE_DIR} | ||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON | ||
BUILD_COMMAND make -j${CPU_CORE} | ||
) | ||
|
||
ADD_LIBRARY(rediscache STATIC IMPORTED GLOBAL) | ||
SET_PROPERTY(TARGET rediscache PROPERTY IMPORTED_LOCATION ${REDISCACHE_LIBRARIES}) | ||
ADD_DEPENDENCIES(rediscache extern_rediscache) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (c) 2024-present, Qihoo, Inc. All rights reserved. | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. An additional grant | ||
# of patent rights can be found in the PATENTS file in the same directory. | ||
|
||
FILE(GLOB PCACHE_SRC | ||
"${CMAKE_CURRENT_SOURCE_DIR}/*.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/*.cc" | ||
) | ||
SET(LIBRARY_OUTPUT_PATH ${PLIB_INSTALL_DIR}) | ||
|
||
ADD_LIBRARY(pcache ${PCACHE_SRC}) | ||
|
||
TARGET_INCLUDE_DIRECTORIES(pcache | ||
PRIVATE ${PROJECT_SOURCE_DIR}/src | ||
PRIVATE ${rocksdb_SOURCE_DIR}/include | ||
PRIVATE ${REDISCACHE_INCLUDE_DIR} | ||
PRIVATE ${PROJECT_SOURCE_DIR}/src/pstd | ||
PRIVATE ${PROJECT_SOURCE_DIR}/src/storage/include | ||
) | ||
|
||
ADD_DEPENDENCIES(pcache rediscache storage ) | ||
|
||
TARGET_LINK_LIBRARIES(pcache pstd rediscache gflags rocksdb storage) | ||
|
||
SET_TARGET_PROPERTIES(pcache PROPERTIES LINKER_LANGUAGE CXX) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright (c) 2024-present, Qihoo, Inc. All rights reserved. | ||
// This source code is licensed under the BSD-style license found in the | ||
// LICENSE file in the root directory of this source tree. An additional grant | ||
// of patent rights can be found in the PATENTS file in the same directory. | ||
|
||
#pragma once | ||
|
||
#include <cstdint> | ||
|
||
#include "rediscache/commondef.h" | ||
|
||
namespace cache { | ||
|
||
/* Redis maxmemory strategies */ | ||
enum RedisMaxmemoryPolicy { | ||
CACHE_VOLATILE_LRU = 0, | ||
CACHE_ALLKEYS_LRU = 1, | ||
CACHE_VOLATILE_LFU = 2, | ||
CACHE_ALLKEYS_LFU = 3, | ||
CACHE_VOLATILE_RANDOM = 4, | ||
CACHE_ALLKEYS_RANDOM = 5, | ||
CACHE_VOLATILE_TTL = 6, | ||
CACHE_NO_EVICTION = 7 | ||
}; | ||
|
||
#define CACHE_DEFAULT_MAXMEMORY CONFIG_DEFAULT_MAXMEMORY // 10G | ||
#define CACHE_DEFAULT_MAXMEMORY_SAMPLES CONFIG_DEFAULT_MAXMEMORY_SAMPLES | ||
#define CACHE_DEFAULT_LFU_DECAY_TIME CONFIG_DEFAULT_LFU_DECAY_TIME | ||
|
||
/* | ||
* cache start pos | ||
*/ | ||
constexpr int CACHE_START_FROM_BEGIN = 0; | ||
constexpr int CACHE_START_FROM_END = -1; | ||
/* | ||
* cache items per key | ||
*/ | ||
#define DEFAULT_CACHE_ITEMS_PER_KEY 512 | ||
|
||
struct CacheConfig { | ||
uint64_t maxmemory; /* Can used max memory */ | ||
int32_t maxmemory_policy; /* Policy for key eviction */ | ||
int32_t maxmemory_samples; /* Precision of random sampling */ | ||
int32_t lfu_decay_time; /* LFU counter decay factor. */ | ||
int32_t zset_cache_start_direction; | ||
int32_t zset_cache_field_num_per_key; | ||
|
||
CacheConfig() | ||
: maxmemory(CACHE_DEFAULT_MAXMEMORY), | ||
maxmemory_policy(CACHE_NO_EVICTION), | ||
maxmemory_samples(CACHE_DEFAULT_MAXMEMORY_SAMPLES), | ||
lfu_decay_time(CACHE_DEFAULT_LFU_DECAY_TIME), | ||
zset_cache_start_direction(CACHE_START_FROM_BEGIN), | ||
zset_cache_field_num_per_key(DEFAULT_CACHE_ITEMS_PER_KEY) {} | ||
|
||
CacheConfig& operator=(const CacheConfig& obj) { | ||
maxmemory = obj.maxmemory; | ||
maxmemory_policy = obj.maxmemory_policy; | ||
maxmemory_samples = obj.maxmemory_samples; | ||
lfu_decay_time = obj.lfu_decay_time; | ||
zset_cache_start_direction = obj.zset_cache_start_direction; | ||
zset_cache_field_num_per_key = obj.zset_cache_field_num_per_key; | ||
return *this; | ||
} | ||
}; | ||
} // namespace cache |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里没有命中缓存为什么还需要在写一次DB
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个是,对于读命令来说,如果读命令没有命中cache就执行DB操作,读命令对应DB操作是读DB。这样处理的原因是,一个key在cache中不存在不代表在DB中不存在