Skip to content

Commit 8b2828f

Browse files
committed
Merge remote-tracking branch 'upstream/unstable' into dual_channel_replica_memory
Signed-off-by: Binbin <binloveplay1314@qq.com>
2 parents 8d6f8f0 + 73838a0 commit 8b2828f

40 files changed

+1804
-473
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ jobs:
7878
CFLAGS='-Werror' ./runtest-moduleapi --tags needs:other-server --verbose --dump-logs \
7979
--other-server-path tests/tmp/valkey-${{ matrix.server.version }}-noble-x86_64/bin/valkey-server
8080
81-
test-ubuntu-latest-cmake:
81+
test-ubuntu-latest-cmake-tls:
8282
runs-on: ubuntu-latest
8383
steps:
8484
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
@@ -91,14 +91,15 @@ jobs:
9191
make -j$(nproc)
9292
- name: test
9393
run: |
94-
sudo apt-get install -y tcl8.6 tclx
94+
sudo apt-get install -y tcl8.6 tclx tcl-tls
95+
./utils/gen-test-certs.sh
9596
ln -sf $(pwd)/build-release/bin/valkey-server $(pwd)/src/valkey-server
9697
ln -sf $(pwd)/build-release/bin/valkey-cli $(pwd)/src/valkey-cli
9798
ln -sf $(pwd)/build-release/bin/valkey-benchmark $(pwd)/src/valkey-benchmark
9899
ln -sf $(pwd)/build-release/bin/valkey-server $(pwd)/src/valkey-check-aof
99100
ln -sf $(pwd)/build-release/bin/valkey-server $(pwd)/src/valkey-check-rdb
100101
ln -sf $(pwd)/build-release/bin/valkey-server $(pwd)/src/valkey-sentinel
101-
./runtest --verbose --tags -slow --dump-logs
102+
./runtest --verbose --tags -slow --dump-logs --tls
102103
- name: unit tests
103104
run: |
104105
./build-release/bin/valkey-unit-tests

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,18 @@ To compile against jemalloc on Mac OS X systems, use:
143143

144144
## Monotonic clock
145145

146-
By default, Valkey will build using the POSIX clock_gettime function as the
147-
monotonic clock source. On most modern systems, the internal processor clock
148-
can be used to improve performance. Cautions can be found here:
146+
By default, Valkey uses the processor's internal instruction clock (TSC on x86,
147+
CNTVCT on ARM) for monotonic time tracking, which provides approximately 3x
148+
faster time access compared to POSIX clock_gettime (~10-30ns vs ~100ns).
149+
This is enabled by default on supported architectures (x86_64 Linux and aarch64)
150+
and automatically falls back to POSIX clock_gettime on unsupported systems.
151+
152+
For more information about processor clock usage, see:
149153
http://oliveryang.net/2015/09/pitfalls-of-TSC-usage/
150154

151-
To build with support for the processor's internal instruction clock, use:
155+
To disable the processor clock and force POSIX clock_gettime, use:
152156

153-
% make CFLAGS="-DUSE_PROCESSOR_CLOCK"
157+
% make CFLAGS="-DNO_PROCESSOR_CLOCK"
154158

155159
## Verbose build
156160

deps/fpconv/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ project(fpconv)
22

33
set(SRCS "${CMAKE_CURRENT_LIST_DIR}/fpconv_dtoa.c" "${CMAKE_CURRENT_LIST_DIR}/fpconv_dtoa.h")
44
add_library(fpconv STATIC ${SRCS})
5+
# Add -fPIC
6+
set_target_properties(fpconv PROPERTIES POSITION_INDEPENDENT_CODE ON)

src/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ if (BUILD_LUA)
2121
add_subdirectory(modules/lua)
2222
add_dependencies(valkey-server valkeylua)
2323
target_compile_definitions(valkey-server PRIVATE LUA_ENABLED)
24-
target_compile_definitions(valkey-server PRIVATE LUA_LIB=libvalkeylua.so)
25-
target_link_options(valkey-server PRIVATE -Wl,--disable-new-dtags)
26-
24+
if (UNIX AND NOT APPLE)
25+
target_compile_definitions(valkey-server PRIVATE LUA_LIB=libvalkeylua.so)
26+
target_link_options(valkey-server PRIVATE -Wl,--disable-new-dtags)
27+
else ()
28+
target_compile_definitions(valkey-server PRIVATE LUA_LIB=libvalkeylua.dylib)
29+
endif ()
2730
set(VALKEY_INSTALL_RPATH "")
2831
set_target_properties(valkey-server PROPERTIES
2932
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR};${CMAKE_LIBRARY_OUTPUT_DIRECTORY}"

src/Makefile

Lines changed: 164 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,13 +442,173 @@ endif
442442
ENGINE_NAME=valkey
443443
SERVER_NAME=$(ENGINE_NAME)-server$(PROG_SUFFIX)
444444
ENGINE_SENTINEL_NAME=$(ENGINE_NAME)-sentinel$(PROG_SUFFIX)
445-
ENGINE_TRACE_OBJ=trace/trace.o trace/trace_commands.o trace/trace_db.o trace/trace_cluster.o trace/trace_server.o trace/trace_rdb.o trace/trace_aof.o
446-
ENGINE_SERVER_OBJ=threads_mngr.o adlist.o vector.o quicklist.o ae.o anet.o dict.o hashtable.o kvstore.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o memory_prefetch.o io_threads.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o cluster_legacy.o cluster_slot_stats.o crc16.o cluster_migrateslots.o endianconv.o commandlog.o eval.o bio.o rio.o rand.o memtest.o syscheck.o crcspeed.o crccombine.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o valkey-check-rdb.o valkey-check-aof.o geo.o lazyfree.o module.o lrulfu.o evict.o expire.o geohash.o geohash_helper.o childinfo.o allocator_defrag.o defrag.o siphash.o rax.o t_stream.o listpack.o localtime.o lolwut.o lolwut5.o lolwut6.o lolwut9.o acl.o tracking.o socket.o tls.o sha256.o timeout.o setcpuaffinity.o monotonic.o mt19937-64.o resp_parser.o call_reply.o script.o functions.o commands.o strl.o connection.o unix.o logreqres.o rdma.o scripting_engine.o entry.o vset.o fifo.o mutexqueue.o
445+
ENGINE_TRACE_OBJ = \
446+
trace/trace.o \
447+
trace/trace_aof.o \
448+
trace/trace_cluster.o \
449+
trace/trace_commands.o \
450+
trace/trace_db.o \
451+
trace/trace_rdb.o \
452+
trace/trace_server.o
453+
ENGINE_SERVER_OBJ = \
454+
acl.o \
455+
adlist.o \
456+
ae.o \
457+
allocator_defrag.o \
458+
anet.o \
459+
aof.o \
460+
bio.o \
461+
bitops.o \
462+
blocked.o \
463+
call_reply.o \
464+
childinfo.o \
465+
cluster.o \
466+
cluster_legacy.o \
467+
cluster_migrateslots.o \
468+
cluster_slot_stats.o \
469+
commandlog.o \
470+
commands.o \
471+
config.o \
472+
connection.o \
473+
crc16.o \
474+
crc64.o \
475+
crccombine.o \
476+
crcspeed.o \
477+
db.o \
478+
debug.o \
479+
defrag.o \
480+
dict.o \
481+
endianconv.o \
482+
entry.o \
483+
eval.o \
484+
evict.o \
485+
expire.o \
486+
fifo.o \
487+
functions.o \
488+
geo.o \
489+
geohash.o \
490+
geohash_helper.o \
491+
hashtable.o \
492+
hyperloglog.o \
493+
intset.o \
494+
io_threads.o \
495+
kvstore.o \
496+
latency.o \
497+
lazyfree.o \
498+
listpack.o \
499+
localtime.o \
500+
logreqres.o \
501+
lolwut.o \
502+
lolwut5.o \
503+
lolwut6.o \
504+
lolwut9.o \
505+
lrulfu.o \
506+
lzf_c.o \
507+
lzf_d.o \
508+
memory_prefetch.o \
509+
memtest.o \
510+
module.o \
511+
monotonic.o \
512+
mt19937-64.o \
513+
multi.o \
514+
mutexqueue.o \
515+
networking.o \
516+
notify.o \
517+
object.o \
518+
pqsort.o \
519+
pubsub.o \
520+
quicklist.o \
521+
rand.o \
522+
rax.o \
523+
rdb.o \
524+
rdma.o \
525+
release.o \
526+
replication.o \
527+
resp_parser.o \
528+
rio.o \
529+
script.o \
530+
scripting_engine.o \
531+
sds.o \
532+
sentinel.o \
533+
server.o \
534+
setcpuaffinity.o \
535+
setproctitle.o \
536+
sha1.o \
537+
sha256.o \
538+
siphash.o \
539+
socket.o \
540+
sort.o \
541+
sparkline.o \
542+
strl.o \
543+
syncio.o \
544+
syscheck.o \
545+
t_hash.o \
546+
t_list.o \
547+
t_set.o \
548+
t_stream.o \
549+
t_string.o \
550+
t_zset.o \
551+
threads_mngr.o \
552+
timeout.o \
553+
tls.o \
554+
tracking.o \
555+
unix.o \
556+
util.o \
557+
valkey-check-aof.o \
558+
valkey-check-rdb.o \
559+
vector.o \
560+
vset.o \
561+
ziplist.o \
562+
zipmap.o \
563+
zmalloc.o
447564
ENGINE_SERVER_OBJ+=$(ENGINE_TRACE_OBJ)
448565
ENGINE_CLI_NAME=$(ENGINE_NAME)-cli$(PROG_SUFFIX)
449-
ENGINE_CLI_OBJ=anet.o adlist.o dict.o valkey-cli.o zmalloc.o release.o ae.o serverassert.o crcspeed.o crccombine.o crc64.o siphash.o crc16.o monotonic.o cli_common.o mt19937-64.o strl.o cli_commands.o sds.o util.o sha256.o
566+
ENGINE_CLI_OBJ = \
567+
adlist.o \
568+
ae.o \
569+
anet.o \
570+
cli_commands.o \
571+
cli_common.o \
572+
crc16.o \
573+
crc64.o \
574+
crccombine.o \
575+
crcspeed.o \
576+
dict.o \
577+
monotonic.o \
578+
mt19937-64.o \
579+
release.o \
580+
sds.o \
581+
serverassert.o \
582+
sha256.o \
583+
siphash.o \
584+
strl.o \
585+
util.o \
586+
valkey-cli.o \
587+
zmalloc.o
450588
ENGINE_BENCHMARK_NAME=$(ENGINE_NAME)-benchmark$(PROG_SUFFIX)
451-
ENGINE_BENCHMARK_OBJ=ae.o anet.o valkey-benchmark.o adlist.o dict.o zmalloc.o serverassert.o release.o crcspeed.o crccombine.o crc64.o siphash.o crc16.o monotonic.o cli_common.o mt19937-64.o strl.o sds.o util.o sha256.o fuzzer_client.o fuzzer_command_generator.o
589+
ENGINE_BENCHMARK_OBJ = \
590+
adlist.o \
591+
ae.o \
592+
anet.o \
593+
cli_common.o \
594+
crc16.o \
595+
crc64.o \
596+
crccombine.o \
597+
crcspeed.o \
598+
dict.o \
599+
fuzzer_client.o \
600+
fuzzer_command_generator.o \
601+
monotonic.o \
602+
mt19937-64.o \
603+
release.o \
604+
sds.o \
605+
serverassert.o \
606+
sha256.o \
607+
siphash.o \
608+
strl.o \
609+
util.o \
610+
valkey-benchmark.o \
611+
zmalloc.o
452612
ENGINE_CHECK_RDB_NAME=$(ENGINE_NAME)-check-rdb$(PROG_SUFFIX)
453613
ENGINE_CHECK_AOF_NAME=$(ENGINE_NAME)-check-aof$(PROG_SUFFIX)
454614
ENGINE_LIB_NAME=lib$(ENGINE_NAME).a

src/config.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "module.h"
3838
#include "cluster_migrateslots.h"
3939
#include "eval.h"
40+
#include "lrulfu.h"
4041

4142
#include <fcntl.h>
4243
#include <sys/stat.h>
@@ -3330,8 +3331,8 @@ standardConfig static_configs[] = {
33303331
createIntConfig("active-defrag-threshold-lower", NULL, MODIFIABLE_CONFIG, 0, 1000, server.active_defrag_threshold_lower, 10, INTEGER_CONFIG, NULL, NULL), /* Default: don't defrag when fragmentation is below 10% */
33313332
createIntConfig("active-defrag-threshold-upper", NULL, MODIFIABLE_CONFIG, 0, 1000, server.active_defrag_threshold_upper, 100, INTEGER_CONFIG, NULL, updateDefragConfiguration), /* Default: maximum defrag force at 100% fragmentation */
33323333
createIntConfig("active-defrag-cycle-us", NULL, MODIFIABLE_CONFIG, 0, 100000, server.active_defrag_cycle_us, 500, INTEGER_CONFIG, NULL, updateDefragConfiguration),
3333-
createIntConfig("lfu-log-factor", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.lfu_log_factor, 10, INTEGER_CONFIG, NULL, NULL),
3334-
createIntConfig("lfu-decay-time", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.lfu_decay_time, 1, INTEGER_CONFIG, NULL, NULL),
3334+
createIntConfig("lfu-log-factor", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, lfu_config_log_factor, 10, INTEGER_CONFIG, NULL, NULL),
3335+
createIntConfig("lfu-decay-time", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, lfu_config_decay_time, 1, INTEGER_CONFIG, NULL, NULL),
33353336
createIntConfig("replica-priority", "slave-priority", MODIFIABLE_CONFIG, 0, INT_MAX, server.replica_priority, 100, INTEGER_CONFIG, NULL, NULL),
33363337
createIntConfig("repl-diskless-sync-delay", NULL, MODIFIABLE_CONFIG, 0, INT_MAX, server.repl_diskless_sync_delay, 5, INTEGER_CONFIG, NULL, NULL),
33373338
createIntConfig("maxmemory-samples", NULL, MODIFIABLE_CONFIG, 1, 64, server.maxmemory_samples, 5, INTEGER_CONFIG, NULL, NULL),

src/db.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,12 +1986,15 @@ void propagateDeletion(serverDb *db, robj *key, int lazy, int slot) {
19861986
*
19871987
* This function builds and propagates a single HDEL command with multiple fields
19881988
* for the given hash object `o`. It temporarily enables replication (if needed),
1989-
* constructs the command using the field names, and sends it via alsoPropagate(). */
1990-
static void propagateFieldsDeletion(serverDb *db, robj *o, size_t n_fields, robj *fields[], int didx) {
1989+
* constructs the command using the field names, and sends it via alsoPropagate().
1990+
* Returns how many fields where propagated */
1991+
int propagateFieldsDeletion(serverDb *db, robj *o, size_t n_fields, robj *fields[], int didx) {
19911992
int prev_replication_allowed = server.replication_allowed;
19921993
server.replication_allowed = 1;
19931994

19941995
robj *argv[EXPIRE_BULK_LIMIT + 2]; /* HDEL + key + fields */
1996+
if (n_fields > EXPIRE_BULK_LIMIT) n_fields = EXPIRE_BULK_LIMIT;
1997+
19951998
int argc = 0;
19961999
robj *keyobj = createStringObjectFromSds(objectGetKey(o));
19972000
argv[argc++] = shared.hdel; // HDEL command
@@ -2006,6 +2009,7 @@ static void propagateFieldsDeletion(serverDb *db, robj *o, size_t n_fields, robj
20062009
for (int i = 0; i < argc; i++) {
20072010
decrRefCount(argv[i]);
20082011
}
2012+
return n_fields;
20092013
}
20102014

20112015
/* Process expired fields for a hash delete them and propagate changes to replicas and AOF.

src/defrag.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,16 +239,16 @@ robj *activeDefragStringOb(robj *ob) {
239239
/* Internal function used by zslDefrag */
240240
static void zslUpdateNode(zskiplist *zsl, zskiplistNode *oldnode, zskiplistNode *newnode, zskiplistNode **update) {
241241
int i;
242-
for (i = 0; i < zsl->level; i++) {
242+
for (i = 0; i < zslGetHeight(zsl); i++) {
243243
if (update[i]->level[i].forward == oldnode) update[i]->level[i].forward = newnode;
244244
}
245-
serverAssert(zsl->header != oldnode);
245+
serverAssert(zslGetHeader(zsl) != oldnode);
246246
if (newnode->level[0].forward) {
247247
serverAssert(newnode->level[0].forward->backward == oldnode);
248248
newnode->level[0].forward->backward = newnode;
249249
} else {
250-
serverAssert(zsl->tail == oldnode);
251-
zsl->tail = newnode;
250+
serverAssert(zslGetTail(zsl) == oldnode);
251+
zslSetTail(zsl, newnode);
252252
}
253253
}
254254

@@ -269,8 +269,8 @@ static void activeDefragZsetNode(void *privdata, void *entry_ref) {
269269
/* find skiplist pointers that need to be updated if we end up moving the
270270
* skiplist node. */
271271
zskiplistNode *update[ZSKIPLIST_MAXLEVEL];
272-
zskiplistNode *x = zsl->header;
273-
for (int i = zsl->level - 1; i >= 0; i--) {
272+
zskiplistNode *x = zslGetHeader(zsl);
273+
for (int i = zslGetHeight(zsl) - 1; i >= 0; i--) {
274274
/* stop when we've reached the end of this level or the next node comes
275275
* after our target in sorted order */
276276
zskiplistNode *next = x->level[i].forward;
@@ -453,13 +453,11 @@ static void defragZsetSkiplist(robj *ob) {
453453

454454
zset *newzs;
455455
zskiplist *newzsl;
456-
struct zskiplistNode *newheader;
457456
if ((newzs = activeDefragAlloc(zs))) {
458457
objectSetVal(ob, newzs);
459458
zs = newzs;
460459
}
461460
if ((newzsl = activeDefragAlloc(zs->zsl))) zs->zsl = newzsl;
462-
if ((newheader = activeDefragAlloc(zs->zsl->header))) zs->zsl->header = newheader;
463461

464462
hashtable *newtable;
465463
if ((newtable = hashtableDefragTables(zs->ht, activeDefragAlloc))) zs->ht = newtable;

0 commit comments

Comments
 (0)