Compare commits

..
Author SHA1 Message Date
Malavan Sotheeswaran 033de9ac9c stat64 is deprecated on mac 2023-11-09 00:17:41 -08:00
24 changed files with 250 additions and 139 deletions

No files matched your search

-1
View File
@@ -1 +0,0 @@
.gitea/CODEOWNERS linguist-detectable=false
-3
View File
@@ -1,3 +0,0 @@
# Pull requests request review from the eligible staff team(s).
# One approval from either an Admin or Developer satisfies branch protection.
* @trueog/Admins @trueog/Developers
+3 -1
View File
@@ -49,6 +49,8 @@ Join us on [Slack](https://docs.keydb.dev/slack/)
Learn more using KeyDB's extensive [documentation](https://docs.keydb.dev)
Post to our [Community Forum](https://community.keydb.dev)
See the [KeyDB Roadmap](https://docs.keydb.dev/docs/coming-soon) to see what's in store
@@ -78,7 +80,7 @@ The minimum number of clients on a thread before KeyDB assigns new connections t
```
replica-weighting-factor 2
```
KeyDB will attempt to balance clients across threads evenly; However, replica clients are usually much more expensive than a normal client, and so KeyDB will try to assign fewer clients to threads with a replica. The weighting factor below is intended to help tune this behavior. A replica weighting factor of 2 means we treat a replica as the equivalent of two normal clients. Adjusting this value may improve performance when replication is used. The best weighting is workload specific - e.g. read heavy workloads should set this to 1. Very write heavy workloads may benefit from higher numbers.
KeyDB will attempt to balance clients across threads evenly; However, replica clients are usually much more expensive than a normal client, and so KeyDB will try to assign fewer clients to threads with a replica. The weighting factor below is intented to help tune this behavior. A replica weighting factor of 2 means we treat a replica as the equivalent of two normal clients. Adjusting this value may improve performance when replication is used. The best weighting is workload specific - e.g. read heavy workloads should set this to 1. Very write heavy workloads may benefit from higher numbers.
```
active-client-balancing yes
-6
View File
@@ -34,17 +34,11 @@ ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'),
endif
distclean:
ifneq ($(USE_SYSTEM_HIREDIS),yes)
-(cd hiredis && $(MAKE) clean) > /dev/null || true
endif
-(cd linenoise && $(MAKE) clean) > /dev/null || true
-(cd lua && $(MAKE) clean) > /dev/null || true
ifneq ($(USE_SYSTEM_JEMALLOC),yes)
-(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true
endif
ifneq ($(USE_SYSTEM_ROCKSDB),yes)
-(cd rocksdb && $(MAKE) clean) > /dev/null || true
endif
-(cd hdr_histogram && $(MAKE) clean) > /dev/null || true
-(rm -f .make-*)
-4
View File
@@ -42,8 +42,6 @@
#ifndef HIREDIS_SDS_COMPAT
#define HIREDIS_SDS_COMPAT
#ifndef USE_SYSTEM_HIREDIS
#define sds hisds
#define sdslen hi_sdslen
@@ -93,6 +91,4 @@
#define sdsull2str hi_sdsull2str
#define sdsupdatelen hi_sdsupdatelen
#endif /* !USE_SYSTEM_HIREDIS */
#endif /* HIREDIS_SDS_COMPAT */
+1 -1
@@ -0,0 +1,84 @@
From: Chris Lamb <lamby@debian.org>
Date: Wed, 3 Oct 2018 19:24:16 +0100
Subject: Add support for a USE_SYSTEM_HIREDIS flag.
---
deps/Makefile | 2 ++
src/Makefile | 19 ++++++++++++++-----
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/deps/Makefile b/deps/Makefile
index 2ed7736..d6b8e3e 100644
--- a/deps/Makefile
+++ b/deps/Makefile
@@ -33,7 +33,9 @@ ifneq ($(shell sh -c '[ -f .make-ldflags ] && cat .make-ldflags || echo none'),
endif
distclean:
+ifneq ($(USE_SYSTEM_HIREDIS),yes)
-(cd hiredis && $(MAKE) clean) > /dev/null || true
+endif
-(cd linenoise && $(MAKE) clean) > /dev/null || true
ifneq ($(USE_SYSTEM_LUA),yes)
-(cd lua && $(MAKE) clean) > /dev/null || true
diff --git a/src/Makefile b/src/Makefile
index 49085f2..9e7e6f1 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -16,7 +16,7 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh')
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
OPTIMIZATION?=-O2
-DEPENDENCY_TARGETS=hiredis linenoise
+DEPENDENCY_TARGETS=linenoise
NODEPS:=clean distclean
# Default settings
@@ -107,7 +107,7 @@ endif
endif
endif
# Include paths to dependencies
-FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise
+FINAL_CFLAGS+= -I../deps/linenoise
ifeq ($(MALLOC),tcmalloc)
FINAL_CFLAGS+= -DUSE_TCMALLOC
@@ -139,6 +139,15 @@ else
FINAL_LIBS := ../deps/lua/src/liblua.a $(FINAL_LIBS)
endif
+ifeq ($(USE_SYSTEM_HIREDIS),yes)
+ FINAL_LIBS+= -lhiredis
+ FINAL_CFLAGS+= -I/usr/include/hiredis
+else
+ DEPENDENCY_TARGETS += hiredis
+ FINAL_LIBS+= ../deps/hiredis/libhiredis.a
+ FINAL_CFLAGS+= -I../deps/hiredis
+endif
+
REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS) $(CPPFLAGS)
REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
REDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL)
@@ -210,7 +219,7 @@ endif
# redis-server
$(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ)
- $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
+ $(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
# redis-sentinel
$(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)
@@ -226,11 +235,11 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_SERVER_NAME)
# redis-cli
$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
- $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
+ $(REDIS_LD) -o $@ $^ ../deps/linenoise/linenoise.o $(FINAL_LIBS)
# redis-benchmark
$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
- $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
+ $(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
dict-benchmark: dict.c zmalloc.c sds.c siphash.c
$(REDIS_CC) $(FINAL_CFLAGS) $^ -D DICT_BENCHMARK_MAIN -o $@ $(FINAL_LIBS)
@@ -0,0 +1,107 @@
From: Chris Lamb <lamby@debian.org>
Date: Sat, 25 Aug 2018 17:52:13 +0200
Subject: Add support for USE_SYSTEM_JEMALLOC flag.
https://github.com/antirez/redis/pull/5279
---
deps/Makefile | 2 ++
src/Makefile | 5 +++++
src/object.c | 5 +++++
src/zmalloc.c | 10 ++++++++++
src/zmalloc.h | 4 ++++
5 files changed, 26 insertions(+)
diff --git a/deps/Makefile b/deps/Makefile
index eb35c1e..1342fac 100644
--- a/deps/Makefile
+++ b/deps/Makefile
@@ -36,7 +36,9 @@ distclean:
-(cd hiredis && $(MAKE) clean) > /dev/null || true
-(cd linenoise && $(MAKE) clean) > /dev/null || true
-(cd lua && $(MAKE) clean) > /dev/null || true
+ifneq ($(USE_SYSTEM_JEMALLOC),yes)
-(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true
+endif
-(rm -f .make-*)
.PHONY: distclean
diff --git a/src/Makefile b/src/Makefile
index 0ff6e8b..51363fe 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -120,10 +120,15 @@ ifeq ($(MALLOC),tcmalloc_minimal)
endif
ifeq ($(MALLOC),jemalloc)
+ifeq ($(USE_SYSTEM_JEMALLOC),yes)
+ FINAL_CFLAGS+= -DUSE_JEMALLOC -I/usr/include/jemalloc/include
+ FINAL_LIBS := -ljemalloc $(FINAL_LIBS)
+else
DEPENDENCY_TARGETS+= jemalloc
FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
FINAL_LIBS := ../deps/jemalloc/lib/libjemalloc.a $(FINAL_LIBS)
endif
+endif
REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS) $(CPPFLAGS)
REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
diff --git a/src/object.c b/src/object.c
index 6987e1e..e49c2c2 100644
--- a/src/object.c
+++ b/src/object.c
@@ -36,6 +36,11 @@
#define strtold(a,b) ((long double)strtod((a),(b)))
#endif
+#if defined(USE_JEMALLOC) && (USE_SYSTEM_JEMALLOC == yes)
+#define je_mallctl mallctl
+#define je_malloc_stats_print malloc_stats_print
+#endif
+
/* ===================== Creation and parsing of objects ==================== */
robj *createObject(int type, void *ptr) {
diff --git a/src/zmalloc.c b/src/zmalloc.c
index 2482f51..80e6571 100644
--- a/src/zmalloc.c
+++ b/src/zmalloc.c
@@ -63,6 +63,15 @@ void zlibc_free(void *ptr) {
#define realloc(ptr,size) tc_realloc(ptr,size)
#define free(ptr) tc_free(ptr)
#elif defined(USE_JEMALLOC)
+#if USE_SYSTEM_JEMALLOC == yes
+#define malloc(size) malloc(size)
+#define calloc(count,size) calloc(count,size)
+#define realloc(ptr,size) realloc(ptr,size)
+#define free(ptr) free(ptr)
+#define mallocx(size,flags) mallocx(size,flags)
+#define dallocx(ptr,flags) dallocx(ptr,flags)
+#define je_mallctl mallctl
+#else
#define malloc(size) je_malloc(size)
#define calloc(count,size) je_calloc(count,size)
#define realloc(ptr,size) je_realloc(ptr,size)
@@ -70,6 +79,7 @@ void zlibc_free(void *ptr) {
#define mallocx(size,flags) je_mallocx(size,flags)
#define dallocx(ptr,flags) je_dallocx(ptr,flags)
#endif
+#endif
#define update_zmalloc_stat_alloc(__n) do { \
size_t _n = (__n); \
diff --git a/src/zmalloc.h b/src/zmalloc.h
index 6fb19b0..62ccf29 100644
--- a/src/zmalloc.h
+++ b/src/zmalloc.h
@@ -50,7 +50,11 @@
#include <jemalloc/jemalloc.h>
#if (JEMALLOC_VERSION_MAJOR == 2 && JEMALLOC_VERSION_MINOR >= 1) || (JEMALLOC_VERSION_MAJOR > 2)
#define HAVE_MALLOC_SIZE 1
+#if USE_SYSTEM_JEMALLOC == yes
+#define zmalloc_size(p) malloc_usable_size(p)
+#else
#define zmalloc_size(p) je_malloc_usable_size(p)
+#endif
#else
#error "Newer version of jemalloc required"
#endif
+2
View File
@@ -2,5 +2,7 @@
#debian-packaging/0003-dpkg-buildflags.patch
#debian-packaging/0007-Set-Debian-configuration-defaults.patch
#0010-Use-get_current_dir_name-over-PATHMAX-etc.patch
#0010-Add-support-for-USE_SYSTEM_JEMALLOC-flag.patch
#0011-Add-support-for-a-USE_SYSTEM_LUA-flag.patch
#0007-Add-support-for-a-USE_SYSTEM_HIREDIS-flag.patch
#test
+6 -3
View File
@@ -5,7 +5,10 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
version=$(grep KEYDB_REAL_VERSION $DIR/../../src/version.h | awk '{ printf $3 }' | tr -d \")
release=1 # by default this will always be 1 for keydb version structure. If build release version needs to be update you can modify here
arch=$(uname -m)
dist=$(rpm --eval '%{?dist}')
dist=el$(rpm -q --queryformat '%{VERSION}' centos-release | cut -d. -f1)
if [[ "$dist" == "elpackage centos-release is not installed" ]]; then
dist=el$(rpm -q --queryformat '%{VERSION}' centos-linux-release | cut -d. -f1)
fi
if [[ "$arch" != "aarch64" ]] && [[ "$arch" != "x86_64" ]]; then
echo "This script is only valid and tested for aarch64 and x86_64 architectures. You are trying to use: $arch"
@@ -36,8 +39,8 @@ sed -i -E "1a\Version : $version" $DIR/keydb_build/keydb.spec
sed -i '3d' $DIR/keydb_build/keydb.spec
sed -i -E "2a\Release : $release%{?dist}" $DIR/keydb_build/keydb.spec
mkdir -p /root/rpmbuild/BUILDROOT/keydb-$version-$release$dist.$arch
cp -r $DIR/keydb_build/keydb_rpm/* /root/rpmbuild/BUILDROOT/keydb-$version-$release$dist.$arch/
mkdir -p /root/rpmbuild/BUILDROOT/keydb-$version-$release.$dist.$arch
cp -r $DIR/keydb_build/keydb_rpm/* /root/rpmbuild/BUILDROOT/keydb-$version-$release.$dist.$arch/
rpmbuild -bb $DIR/keydb_build/keydb.spec
mv /root/rpmbuild/RPMS/$arch/* $DIR/rpm_files_generated
+8 -47
View File
@@ -20,7 +20,7 @@ release_hdr := $(shell sh -c './mkreleasehdr.sh')
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
OPTIMIZATION?=-O2 -flto
DEPENDENCY_TARGETS=linenoise lua hdr_histogram
DEPENDENCY_TARGETS=hiredis linenoise lua hdr_histogram
NODEPS:=clean distclean
# Default settings
@@ -73,19 +73,12 @@ ifneq ($(strip $(SANITIZE)),)
endif
ifeq ($(ENABLE_FLASH),yes)
STORAGE_OBJ+= storage/rocksdb.o storage/rocksdbfactory.o
ifeq ($(USE_SYSTEM_ROCKSDB),yes)
FINAL_LIBS+= $(shell pkg-config --libs rocksdb)
FINAL_CXXFLAGS+= $(shell pkg-config --cflags rocksdb) -DENABLE_ROCKSDB
else
FINAL_LIBS+= -lz -lcrypto -lbz2 -lzstd -llz4 -lsnappy
CXXFLAGS+= -I../deps/rocksdb/include/ -DENABLE_ROCKSDB
FINAL_CXXFLAGS+= -I../deps/rocksdb/include/
STORAGE_OBJ+= storage/rocksdb.o storage/rocksdbfactory.o
FINAL_LIBS+= ../deps/rocksdb/librocksdb.a
DEPENDENCY_TARGETS+= rocksdb
endif
endif
ifeq ($(CHECKED),true)
@@ -274,14 +267,8 @@ ifdef OPENSSL_PREFIX
endif
# Include paths to dependencies
FINAL_CFLAGS+= -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram
FINAL_CXXFLAGS+= -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram
ifeq ($(USE_SYSTEM_CONCURRENTQUEUE),yes)
FINAL_CXXFLAGS+= -I/usr/include/concurrentqueue/moodycamel
else
FINAL_CXXFLAGS+= -I../deps/concurrentqueue
endif
FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram
FINAL_CXXFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps/hdr_histogram -I../deps/rocksdb/include/ -I../deps/concurrentqueue
# Determine systemd support and/or build preference (defaulting to auto-detection)
BUILD_WITH_SYSTEMD=no
@@ -324,17 +311,11 @@ ifeq ($(MALLOC),tcmalloc_minimal)
endif
ifeq ($(MALLOC),jemalloc)
ifeq ($(USE_SYSTEM_JEMALLOC),yes)
FINAL_CFLAGS+= -DUSE_JEMALLOC $(shell $(PKG_CONFIG) --cflags jemalloc)
FINAL_CXXFLAGS+= -DUSE_JEMALLOC $(shell $(PKG_CONFIG) --cflags jemalloc)
FINAL_LIBS := $(shell $(PKG_CONFIG) --libs jemalloc) $(FINAL_LIBS)
else
DEPENDENCY_TARGETS+= jemalloc
FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
FINAL_CXXFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
FINAL_LIBS := ../deps/jemalloc/lib/libjemalloc.a $(FINAL_LIBS)
endif
endif
ifeq ($(MALLOC),memkind)
DEPENDENCY_TARGETS+= memkind
@@ -343,22 +324,6 @@ ifeq ($(MALLOC),memkind)
FINAL_LIBS := ../deps/memkind/src/.libs/libmemkind.a -lnuma $(FINAL_LIBS)
endif
ifeq ($(USE_SYSTEM_HIREDIS),yes)
HIREDIS_CFLAGS := $(shell $(PKG_CONFIG) --cflags hiredis) -DUSE_SYSTEM_HIREDIS=1
FINAL_CFLAGS+= $(HIREDIS_CFLAGS)
FINAL_CXXFLAGS+= $(HIREDIS_CFLAGS)
FINAL_LIBS+= $(shell $(PKG_CONFIG) --libs hiredis)
ifeq ($(BUILD_TLS),yes)
HIREDIS_TLS_CFLAGS := $(shell $(PKG_CONFIG) --cflags hiredis_ssl)
FINAL_CFLAGS+= $(HIREDIS_TLS_CFLAGS)
FINAL_CXXFLAGS+= $(HIREDIS_TLS_CFLAGS)
FINAL_LIBS+= $(shell $(PKG_CONFIG) --libs hiredis_ssl)
endif
else
DEPENDENCY_TARGETS+= hiredis
FINAL_CFLAGS+= -I../deps/hiredis
FINAL_CXXFLAGS+= -I../deps/hiredis
FINAL_LIBS+=../deps/hiredis/libhiredis.a
ifeq ($(BUILD_TLS),yes)
FINAL_CFLAGS+=-DUSE_OPENSSL $(OPENSSL_CFLAGS)
FINAL_CXXFLAGS+=-DUSE_OPENSSL $(OPENSSL_CXXFLAGS)
@@ -377,7 +342,6 @@ else
endif
FINAL_LIBS += ../deps/hiredis/libhiredis_ssl.a $(LIBSSL_LIBS) $(LIBCRYPTO_LIBS)
endif
endif
ifndef V
define MAKE_INSTALL
@@ -450,12 +414,9 @@ persist-settings: distclean
echo STD=$(STD) >> .make-settings
echo WARN=$(WARN) >> .make-settings
echo OPT=$(OPT) >> .make-settings
echo USE_SYSTEM_CONCURRENTQUEUE=$(USE_SYSTEM_CONCURRENTQUEUE) >> .make-settings
echo MALLOC=$(MALLOC) >> .make-settings
echo USE_SYSTEM_JEMALLOC=$(USE_SYSTEM_JEMALLOC) >> .make-settings
echo BUILD_TLS=$(BUILD_TLS) >> .make-settings
echo USE_SYSTEMD=$(USE_SYSTEMD) >> .make-settings
echo USE_SYSTEM_HIREDIS=$(USE_SYSTEM_HIREDIS) >> .make-settings
echo CFLAGS=$(CFLAGS) >> .make-settings
echo CXXFLAGS=$(CXXFLAGS) >> .make-settings
echo LDFLAGS=$(LDFLAGS) >> .make-settings
@@ -485,7 +446,7 @@ endif
# keydb-server
$(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ) $(KEYDB_SERVER_OBJ)
$(REDIS_LD) -o $@ $^ ../deps/lua/src/liblua.a $(FINAL_LIBS)
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS)
# keydb-sentinel
$(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)
@@ -501,15 +462,15 @@ $(REDIS_CHECK_AOF_NAME): $(REDIS_SERVER_NAME)
# keydb-cli
$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
$(REDIS_LD) -o $@ $^ ../deps/linenoise/linenoise.o $(FINAL_LIBS)
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
# keydb-benchmark
$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
$(REDIS_LD) -o $@ $^ ../deps/hdr_histogram/hdr_histogram.o $(FINAL_LIBS)
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/hdr_histogram/hdr_histogram.o $(FINAL_LIBS)
# keydb-diagnostic-tool
$(KEYDB_DIAGNOSTIC_NAME): $(KEYDB_DIAGNOSTIC_OBJ)
$(REDIS_LD) -o $@ $^ $(FINAL_LIBS)
$(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
DEP = $(REDIS_SERVER_OBJ:%.o=%.d) $(KEYDB_SERVER_OBJ:%.o=%.d) $(REDIS_CLI_OBJ:%.o=%.d) $(REDIS_BENCHMARK_OBJ:%.o=%.d)
-include $(DEP)
+2 -4
View File
@@ -208,8 +208,7 @@ void unblockClient(client *c) {
listDelNode(g_pserver->paused_clients,c->paused_list_node);
c->paused_list_node = NULL;
} else {
serverPanic("Unknown btype %d in unblockClient() for client %llu.",
c->btype, (unsigned long long) c->id);
serverPanic("Unknown btype in unblockClient().");
}
/* Reset the client for a new query since, for blocking commands
@@ -244,8 +243,7 @@ void replyToBlockedClientTimedOut(client *c) {
} else if (c->btype == BLOCKED_MODULE) {
moduleBlockedClientTimedOut(c);
} else {
serverPanic("Unknown btype %d in replyToBlockedClientTimedOut() for client %llu.",
c->btype, (unsigned long long) c->id);
serverPanic("Unknown btype in replyToBlockedClientTimedOut().");
}
}
+1 -1
View File
@@ -31,7 +31,7 @@
#include "cli_common.h"
#include <errno.h>
#include <hiredis.h>
#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
#include <sdscompat.h> /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
#include <sds.h> /* use sds.h from hiredis, so that only one set of sds functions will be present in the binary */
#ifdef USE_OPENSSL
#include <openssl/ssl.h>
+22 -31
View File
@@ -1723,17 +1723,16 @@ int dbSwapDatabases(int id1, int id2) {
id2 < 0 || id2 >= cserver.dbnum) return C_ERR;
if (id1 == id2) return C_OK;
std::swap(g_pserver->db[id1], g_pserver->db[id2]);
//swap db's id too, otherwise db does not match its id
std::swap(g_pserver->db[id1]->id, g_pserver->db[id2]->id);
/* Note that we don't swap blocking_keys,
* ready_keys and watched_keys, since we want clients to
* remain in the same DB they were. so put them back */
std::swap(g_pserver->db[id1]->blocking_keys, g_pserver->db[id2]->blocking_keys);
std::swap(g_pserver->db[id1]->ready_keys, g_pserver->db[id2]->ready_keys);
std::swap(g_pserver->db[id1]->watched_keys, g_pserver->db[id2]->watched_keys);
/* Don't swap the redisdb id, as it is expected to be same as database index everywhere else.
For example, flushdb, master/slave replication, etc. */
std::swap(g_pserver->db[id1]->id, g_pserver->db[id2]->id);
std::swap(g_pserver->db[id2]->ready_keys, g_pserver->db[id2]->ready_keys);
std::swap(g_pserver->db[id2]->watched_keys, g_pserver->db[id2]->watched_keys);
/* Now we need to handle clients blocked on lists: as an effect
* of swapping the two DBs, a client that was waiting for list
@@ -1756,11 +1755,7 @@ int dbSwapDatabases(int id1, int id2) {
/* SWAPDB db1 db2 */
void swapdbCommand(client *c) {
int id1, id2;
listNode *ln;
listIter li;
client *cl;
int id1, id2, oriIdx;
/* Not allowed in cluster mode: we have just DB 0 there. */
if (g_pserver->cluster_enabled) {
@@ -1777,6 +1772,14 @@ void swapdbCommand(client *c) {
"invalid second DB index") != C_OK)
return;
// get client's original db's index
for (int idb=0; idb < cserver.dbnum; ++idb) {
if (g_pserver->db[idb]->id == c->db->id) {
oriIdx = idb;
break;
}
}
/* Swap... */
if (dbSwapDatabases(id1,id2) == C_ERR) {
addReplyError(c,"DB index is out of range");
@@ -1786,29 +1789,18 @@ void swapdbCommand(client *c) {
moduleFireServerEvent(REDISMODULE_EVENT_SWAPDB,0,&si);
g_pserver->dirty++;
// Persist the databse index to storage dbid mapping into FLASH for later recovery.
// set client's db to original db
c->db=g_pserver->db[oriIdx];
// Persist the databse index to dbid mapping into FLASH for later recovery.
if (g_pserver->m_pstorageFactory != nullptr && g_pserver->metadataDb != nullptr) {
std::string dbid_key = "db-" + std::to_string(id1);
g_pserver->metadataDb->insert(dbid_key.c_str(), dbid_key.length(), &g_pserver->db[id1]->storage_id, sizeof(g_pserver->db[id1]->storage_id), true);
g_pserver->metadataDb->insert(dbid_key.c_str(), dbid_key.length(), &g_pserver->db[id1]->id, sizeof(g_pserver->db[id1]->id), true);
dbid_key = "db-" + std::to_string(id2);
g_pserver->metadataDb->insert(dbid_key.c_str(), dbid_key.length(), &g_pserver->db[id2]->storage_id, sizeof(g_pserver->db[id2]->storage_id), true);
g_pserver->metadataDb->insert(dbid_key.c_str(), dbid_key.length(), &g_pserver->db[id2]->id, sizeof(g_pserver->db[id2]->id), true);
}
addReply(c,shared.ok);
listRewind(g_pserver->clients,&li);
while ((ln = listNext(&li)) != NULL) {
cl = reinterpret_cast<struct client*>(listNodeValue(ln));
std::unique_lock<decltype(cl->lock)> lock(cl->lock);
if (cl->db->id == g_pserver->db[id1]->id) {
cl->db = g_pserver->db[id2];
updateDBWatchedKey(id1, cl);
}
else if (cl->db->id == g_pserver->db[id2]->id) {
cl->db = g_pserver->db[id1];
updateDBWatchedKey(id2, cl);
}
}
}
}
@@ -2639,14 +2631,13 @@ void moduleClusterLoadCallback(const char * rgchKey, size_t cchKey, void *data)
moduleLoadCallback(rgchKey, cchKey, data);
}
void redisDb::initialize(int id, int storage_id /* default no storage */)
void redisDb::initialize(int id)
{
redisDbPersistentData::initialize();
this->blocking_keys = dictCreate(&keylistDictType,NULL);
this->ready_keys = dictCreate(&objectKeyPointerValueDictType,NULL);
this->watched_keys = dictCreate(&keylistDictType,NULL);
this->id = id;
this->storage_id = storage_id;
this->avg_ttl = 0;
this->last_expire_set = 0;
this->defrag_later = listCreate();
@@ -2658,7 +2649,7 @@ void redisDb::storageProviderInitialize()
if (g_pserver->m_pstorageFactory != nullptr)
{
IStorageFactory::key_load_iterator itr = g_pserver->cluster_enabled ? moduleClusterLoadCallback : moduleLoadCallback;
this->setStorageProvider(StorageCache::create(g_pserver->m_pstorageFactory, storage_id, itr, &id));
this->setStorageProvider(StorageCache::create(g_pserver->m_pstorageFactory, id, itr, &id));
}
}
+1 -1
View File
@@ -1135,7 +1135,7 @@ static void *getMcontextEip(ucontext_t *uc) {
#elif defined(__i386__)
return (void*) uc->uc_mcontext->__ss.__eip;
#else
return (void*) uc->uc_mcontext->__ss.__pc;
return (void*) uc->uc_mcontext->__ss.__srr0;
#endif
#elif defined(__APPLE__) && defined(MAC_OS_X_VERSION_10_6)
/* OSX >= 10.6 */
+1 -1
View File
@@ -46,7 +46,7 @@
#include <deque>
extern "C" {
#include <sds.h> /* Use hiredis sds. */
#include "sdscompat.h"
#include <sdscompat.h>
#include "hiredis.h"
}
#include "ae.h"
+2 -2
View File
@@ -1,6 +1,6 @@
#ifdef CLIENT
extern "C" {
#include "sdscompat.h"
#include <sdscompat.h>
#include <sds.h>
}
#else
@@ -19,7 +19,7 @@ extern "C" {
#ifdef MOTD
#include <curl/curl.h>
#if !defined(USE_SYSTEM_HIREDIS) && defined(CLIENT)
#ifdef CLIENT
extern "C" {
__attribute__ ((weak)) hisds hi_sdscatlen(hisds s, const void *t, size_t len) {
return sdscatlen(s, t, len);
-18
View File
@@ -429,24 +429,6 @@ void touchAllWatchedKeysInDb(redisDb *emptied, redisDb *replaced_with) {
dictReleaseIterator(di);
}
/* Update the DB of the watchedKey structure incase if the c->db (currently selected DB) is updated.
* For example, it may happen during the SWAPDB.
* watchForKey() sets the original DB of the watchedKey structure with the c->db
* but the c->db can be updated incase of SWAPDB command. */
void updateDBWatchedKey(int dbid, client *c) {
listIter li;
listNode *ln;
watchedKey *wk;
listRewind(c->watched_keys,&li);
while((ln = listNext(&li))) {
wk = (watchedKey*)listNodeValue(ln);
if (wk->db->id == dbid) {
wk->db = c->db;
}
}
}
void watchCommand(client *c) {
int j;
+1 -1
View File
@@ -44,7 +44,7 @@
#include <pthread.h>
#include <string>
extern "C" {
#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
#include <sdscompat.h> /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
#include <sds.h> /* Use hiredis sds. */
#include <hiredis.h>
}
+1 -1
View File
@@ -54,7 +54,7 @@
#include <openssl/err.h>
#include <hiredis_ssl.h>
#endif
#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
#include <sdscompat.h> /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
#include <sds.h> /* use sds.h from hiredis, so that only one set of sds functions will be present in the binary */
#include "adlist.h"
#include "zmalloc.h"
+1 -1
View File
@@ -1,6 +1,6 @@
#pragma once
#include "cli_common.h"
#include "sdscompat.h" /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
#include <sdscompat.h> /* Use hiredis' sds compat header that maps sds calls to their hi_ variants */
#include <sds.h>
#ifdef __cplusplus
+2 -5
View File
@@ -2608,11 +2608,8 @@ bool readSnapshotBulkPayload(connection *conn, redisMaster *mi, rdbSaveInfo &rsi
if (mi->parseState->depth() != 0)
return false;
long long repl_stream_db = mi->parseState->getMetaDataLongLong("repl-stream-db");
if (repl_stream_db < INT_MIN || repl_stream_db > INT_MAX) {
throw "Invalid repl_stream_db value";
}
rsi.repl_stream_db = static_cast<int>(repl_stream_db);
static_assert(sizeof(long) == sizeof(long long),"");
rsi.repl_stream_db = mi->parseState->getMetaDataLongLong("repl-stream-db");
rsi.repl_offset = mi->parseState->getMetaDataLongLong("repl-offset");
sds str = mi->parseState->getMetaDataStr("repl-id");
if (sdslen(str) == CONFIG_RUN_ID_SIZE) {
+4 -4
View File
@@ -3925,18 +3925,18 @@ void initServer(void) {
g_pserver->db[j]->initialize(j);
}
} else {
// Read FLASH metadata and load the appropriate storage dbid into each databse index, as each DB index can have different storage dbid mapped due to the swapdb command.
// Read FLASH metadata and load the appropriate dbid into each databse index, as each DB index can have different dbid mapped due to the swapdb command.
g_pserver->metadataDb = g_pserver->m_pstorageFactory->createMetadataDb();
for (int idb = 0; idb < cserver.dbnum; ++idb)
{
int storage_dbid = idb;
int dbid = idb;
std::string dbid_key = "db-" + std::to_string(idb);
g_pserver->metadataDb->retrieve(dbid_key.c_str(), dbid_key.length(), [&](const char *, size_t, const void *data, size_t){
storage_dbid = *(int*)data;
dbid = *(int*)data;
});
g_pserver->db[idb] = new (MALLOC_LOCAL) redisDb();
g_pserver->db[idb]->initialize(idb, storage_dbid);
g_pserver->db[idb]->initialize(dbid);
}
}
+1 -3
View File
@@ -1325,7 +1325,7 @@ struct redisDb : public redisDbPersistentDataSnapshot
redisDb() = default;
void initialize(int id, int storage_id=-1 /* default no storage */);
void initialize(int id);
void storageProviderInitialize();
void storageProviderDelete();
virtual ~redisDb();
@@ -1389,7 +1389,6 @@ public:
dict *ready_keys; /* Blocked keys that received a PUSH */
dict *watched_keys; /* WATCHED keys for MULTI/EXEC CAS */
int id; /* Database ID */
int storage_id; /* Mapped storage provider DB id which is same as the redisdb id above. But, when the database is swapped, the redisdb id above might be swapped to be consistent with the database index (id <-> g_pserver->db[index]) however the storage_id remains unchanged in order to maintain correct mapping to the underlying storage provider DB. This is valid only if there is a storage provider set.*/
long long last_expire_set; /* when the last expire was set */
double avg_ttl; /* Average TTL, just for stats */
list *defrag_later; /* List of key names to attempt to defrag one by one, gradually. */
@@ -3115,7 +3114,6 @@ void queueMultiCommand(client *c);
void touchWatchedKey(redisDb *db, robj *key);
int isWatchedKeyExpired(client *c);
void touchAllWatchedKeysInDb(redisDb *emptied, redisDb *replaced_with);
void updateDBWatchedKey(int dbid, client *c);
void discardTransaction(client *c);
void flagTransaction(client *c);
void execCommandAbort(client *c, sds error);