From 8f202d20df7eae349ea1bc7a3c68cd7c7da3f559 Mon Sep 17 00:00:00 2001 From: Shivshankar Date: Wed, 24 Apr 2024 12:01:33 -0400 Subject: [PATCH 01/25] Rename remaining test procedures (#355) Renamed below procedures and variables (missed in #287) as follows. redis_cluster -> valkey_cluster redis1 -> valkey1 redis2 -> valkey2 get_redis_dir -> get_valkey_dir test_redis_cli_rdb_dump -> test_valkey_cli_rdb_dump test_redis_cli_repl -> test_valkey_cli_repl redis-cli -> valkey-cli redis_reset_state -> valkey_reset_state redisHandle -> valkeyHandle redis_safe_read -> valkey_safe_read redis_safe_gets -> valkey_safe_gets redis_write -> valkey_write redis_read_reply -> valkey_read_reply redis_readable -> valkey_readable redis_readnl -> valkey_readnl redis_writenl -> valkey_writenl redis_read_map -> valkey_read_map redis_read_line -> valkey_read_line redis_read_null -> valkey_read_null redis_read_bool -> valkey_read_bool redis_read_double -> valkey_read_double redis_read_verbatim_str -> valkey_read_verbatim_str redis_call_callback -> valkey_call_callback --------- Signed-off-by: Shivshankar-Reddy Signed-off-by: Sher Sun --- tests/cluster/cluster.tcl | 2 +- tests/cluster/tests/03-failover-loop.tcl | 2 +- tests/cluster/tests/04-resharding.tcl | 4 +- tests/cluster/tests/05-slave-selection.tcl | 2 +- tests/cluster/tests/10-manual-failover.tcl | 2 +- tests/cluster/tests/14-consistency-check.tcl | 2 +- tests/cluster/tests/15-cluster-slots.tcl | 6 +- tests/cluster/tests/20-half-migrated-slot.tcl | 2 +- .../cluster/tests/21-many-slot-migration.tcl | 2 +- .../tests/25-pubsubshard-slot-migration.tcl | 4 +- tests/cluster/tests/26-pubsubshard.tcl | 2 +- .../tests/29-slot-migration-response.tcl | 2 +- tests/cluster/tests/includes/utils.tcl | 4 +- tests/integration/aof-multi-part.tcl | 62 ++++----- tests/integration/valkey-cli.tcl | 16 +-- tests/support/aofmanifest.tcl | 2 +- tests/support/cluster.tcl | 128 +++++++++--------- tests/support/redis.tcl | 124 ++++++++--------- tests/unit/cluster/cluster-response-tls.tcl | 8 +- 19 files changed, 188 insertions(+), 188 deletions(-) diff --git a/tests/cluster/cluster.tcl b/tests/cluster/cluster.tcl index 3b99fe27de..0080501bf4 100644 --- a/tests/cluster/cluster.tcl +++ b/tests/cluster/cluster.tcl @@ -171,7 +171,7 @@ proc set_cluster_node_timeout {to} { proc cluster_write_test {id} { set prefix [randstring 20 20 alpha] set port [get_instance_attrib valkey $id port] - set cluster [redis_cluster 127.0.0.1:$port] + set cluster [valkey_cluster 127.0.0.1:$port] for {set j 0} {$j < 100} {incr j} { $cluster set key.$j $prefix.$j } diff --git a/tests/cluster/tests/03-failover-loop.tcl b/tests/cluster/tests/03-failover-loop.tcl index 548e15824d..5423349276 100644 --- a/tests/cluster/tests/03-failover-loop.tcl +++ b/tests/cluster/tests/03-failover-loop.tcl @@ -14,7 +14,7 @@ test "Cluster is up" { } set iterations 20 -set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] +set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] while {[incr iterations -1]} { set tokill [randomInt 10] diff --git a/tests/cluster/tests/04-resharding.tcl b/tests/cluster/tests/04-resharding.tcl index 5c289a238b..e063dc0694 100644 --- a/tests/cluster/tests/04-resharding.tcl +++ b/tests/cluster/tests/04-resharding.tcl @@ -55,11 +55,11 @@ proc process_is_running {pid} { set numkeys 50000 set numops 200000 set start_node_port [get_instance_attrib valkey 0 port] -set cluster [redis_cluster 127.0.0.1:$start_node_port] +set cluster [valkey_cluster 127.0.0.1:$start_node_port] if {$::tls} { # setup a non-TLS cluster client to the TLS cluster set plaintext_port [get_instance_attrib valkey 0 plaintext-port] - set cluster_plaintext [redis_cluster 127.0.0.1:$plaintext_port 0] + set cluster_plaintext [valkey_cluster 127.0.0.1:$plaintext_port 0] puts "Testing TLS cluster on start node 127.0.0.1:$start_node_port, plaintext port $plaintext_port" } else { set cluster_plaintext $cluster diff --git a/tests/cluster/tests/05-slave-selection.tcl b/tests/cluster/tests/05-slave-selection.tcl index 3cf1f1af35..bb3a06134e 100644 --- a/tests/cluster/tests/05-slave-selection.tcl +++ b/tests/cluster/tests/05-slave-selection.tcl @@ -48,7 +48,7 @@ test "Instance #5 and #10 synced with the master" { } } -set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] +set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] test "Slaves are both able to receive and acknowledge writes" { for {set j 0} {$j < 100} {incr j} { diff --git a/tests/cluster/tests/10-manual-failover.tcl b/tests/cluster/tests/10-manual-failover.tcl index 7f758f05be..4af4148cee 100644 --- a/tests/cluster/tests/10-manual-failover.tcl +++ b/tests/cluster/tests/10-manual-failover.tcl @@ -30,7 +30,7 @@ set current_epoch [CI 1 cluster_current_epoch] set numkeys 50000 set numops 10000 -set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] +set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] catch {unset content} array set content {} diff --git a/tests/cluster/tests/14-consistency-check.tcl b/tests/cluster/tests/14-consistency-check.tcl index 6a3c99eb7c..bc7c893214 100644 --- a/tests/cluster/tests/14-consistency-check.tcl +++ b/tests/cluster/tests/14-consistency-check.tcl @@ -38,7 +38,7 @@ proc get_one_of_my_replica {id} { proc cluster_write_keys_with_expire {id ttl} { set prefix [randstring 20 20 alpha] set port [get_instance_attrib valkey $id port] - set cluster [redis_cluster 127.0.0.1:$port] + set cluster [valkey_cluster 127.0.0.1:$port] for {set j 100} {$j < 200} {incr j} { $cluster setex key_expire.$j $ttl $prefix.$j } diff --git a/tests/cluster/tests/15-cluster-slots.tcl b/tests/cluster/tests/15-cluster-slots.tcl index 096f54f9f8..927c1ff0dd 100644 --- a/tests/cluster/tests/15-cluster-slots.tcl +++ b/tests/cluster/tests/15-cluster-slots.tcl @@ -44,13 +44,13 @@ test "client do not break when cluster slot" { } test "client can handle keys with hash tag" { - set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] + set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] $cluster set foo{tag} bar $cluster close } test "slot migration is valid from primary to another primary" { - set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] + set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set key order1 set slot [$cluster cluster keyslot $key] array set nodefrom [$cluster masternode_for_slot $slot] @@ -61,7 +61,7 @@ test "slot migration is valid from primary to another primary" { } test "slot migration is invalid from primary to replica" { - set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] + set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] set key order1 set slot [$cluster cluster keyslot $key] array set nodefrom [$cluster masternode_for_slot $slot] diff --git a/tests/cluster/tests/20-half-migrated-slot.tcl b/tests/cluster/tests/20-half-migrated-slot.tcl index 529823b119..8049ca1be4 100644 --- a/tests/cluster/tests/20-half-migrated-slot.tcl +++ b/tests/cluster/tests/20-half-migrated-slot.tcl @@ -21,7 +21,7 @@ test "Cluster is up" { assert_cluster_state ok } -set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] +set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] catch {unset nodefrom} catch {unset nodeto} diff --git a/tests/cluster/tests/21-many-slot-migration.tcl b/tests/cluster/tests/21-many-slot-migration.tcl index 7d447653f5..703cf58614 100644 --- a/tests/cluster/tests/21-many-slot-migration.tcl +++ b/tests/cluster/tests/21-many-slot-migration.tcl @@ -21,7 +21,7 @@ test "Cluster is up" { assert_cluster_state ok } -set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] +set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] catch {unset nodefrom} catch {unset nodeto} diff --git a/tests/cluster/tests/25-pubsubshard-slot-migration.tcl b/tests/cluster/tests/25-pubsubshard-slot-migration.tcl index 98baa3a3db..45ec500eb7 100644 --- a/tests/cluster/tests/25-pubsubshard-slot-migration.tcl +++ b/tests/cluster/tests/25-pubsubshard-slot-migration.tcl @@ -8,10 +8,10 @@ test "Cluster is up" { assert_cluster_state ok } -set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] +set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] proc get_addr_replica_serving_slot slot { - set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] + set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] array set node [$cluster masternode_for_slot $slot] set replicanodeinfo [$cluster cluster replicas $node(id)] diff --git a/tests/cluster/tests/26-pubsubshard.tcl b/tests/cluster/tests/26-pubsubshard.tcl index 77ed52006e..fe0e7d39ab 100644 --- a/tests/cluster/tests/26-pubsubshard.tcl +++ b/tests/cluster/tests/26-pubsubshard.tcl @@ -6,7 +6,7 @@ test "Create a 3 nodes cluster" { cluster_create_with_continuous_slots 3 3 } -set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] +set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] test "Pub/Sub shard basics" { set slot [$cluster cluster keyslot "channel.0"] diff --git a/tests/cluster/tests/29-slot-migration-response.tcl b/tests/cluster/tests/29-slot-migration-response.tcl index 75be29e970..bc76735591 100644 --- a/tests/cluster/tests/29-slot-migration-response.tcl +++ b/tests/cluster/tests/29-slot-migration-response.tcl @@ -12,7 +12,7 @@ test "Cluster is up" { assert_cluster_state ok } -set cluster [redis_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] +set cluster [valkey_cluster 127.0.0.1:[get_instance_attrib valkey 0 port]] catch {unset nodefrom} catch {unset nodeto} diff --git a/tests/cluster/tests/includes/utils.tcl b/tests/cluster/tests/includes/utils.tcl index 84a6255766..9182b984cc 100644 --- a/tests/cluster/tests/includes/utils.tcl +++ b/tests/cluster/tests/includes/utils.tcl @@ -11,7 +11,7 @@ proc fix_cluster {addr} { exec ../../../src/valkey-cli {*}[valkeycli_tls_config "../../../tests"] --cluster fix $addr << yes } result] if {$code != 0} { - puts "redis-cli --cluster fix returns non-zero exit code, output below:\n$result" + puts "valkey-cli --cluster fix returns non-zero exit code, output below:\n$result" } # Note: valkey-cli --cluster fix may return a non-zero exit code if nodes don't agree, # but we can ignore that and rely on the check below. @@ -19,7 +19,7 @@ proc fix_cluster {addr} { wait_for_condition 100 100 { [catch {exec ../../../src/valkey-cli {*}[valkeycli_tls_config "../../../tests"] --cluster check $addr} result] == 0 } else { - puts "redis-cli --cluster check returns non-zero exit code, output below:\n$result" + puts "valkey-cli --cluster check returns non-zero exit code, output below:\n$result" fail "Cluster could not settle with configuration" } } diff --git a/tests/integration/aof-multi-part.tcl b/tests/integration/aof-multi-part.tcl index ac4a637665..977bb11e4c 100644 --- a/tests/integration/aof-multi-part.tcl +++ b/tests/integration/aof-multi-part.tcl @@ -604,71 +604,71 @@ tags {"external:skip"} { } start_server_aof [list dir $server_path] { - set redis1 [valkey [srv host] [srv port] 0 $::tls] + set valkey1 [valkey [srv host] [srv port] 0 $::tls] start_server [list overrides [list dir $server_path appendonly yes appendfilename appendonly.aof2]] { - set redis2 [valkey [srv host] [srv port] 0 $::tls] + set valkey2 [valkey [srv host] [srv port] 0 $::tls] test "Multi Part AOF can upgrade when when two servers share the same server dir (server1)" { - wait_done_loading $redis1 - assert_equal v1 [$redis1 get k1] - assert_equal v2 [$redis1 get k2] - assert_equal v3 [$redis1 get k3] + wait_done_loading $valkey1 + assert_equal v1 [$valkey1 get k1] + assert_equal v2 [$valkey1 get k2] + assert_equal v3 [$valkey1 get k3] - assert_equal 0 [$redis1 exists k4] - assert_equal 0 [$redis1 exists k5] - assert_equal 0 [$redis1 exists k6] + assert_equal 0 [$valkey1 exists k4] + assert_equal 0 [$valkey1 exists k5] + assert_equal 0 [$valkey1 exists k6] assert_aof_manifest_content $aof_manifest_file { {file appendonly.aof seq 1 type b} {file appendonly.aof.1.incr.aof seq 1 type i} } - $redis1 bgrewriteaof - waitForBgrewriteaof $redis1 + $valkey1 bgrewriteaof + waitForBgrewriteaof $valkey1 - assert_equal OK [$redis1 set k v] + assert_equal OK [$valkey1 set k v] assert_aof_manifest_content $aof_manifest_file { {file appendonly.aof.2.base.rdb seq 2 type b} {file appendonly.aof.2.incr.aof seq 2 type i} } - set d1 [$redis1 debug digest] - $redis1 debug loadaof - set d2 [$redis1 debug digest] + set d1 [$valkey1 debug digest] + $valkey1 debug loadaof + set d2 [$valkey1 debug digest] assert {$d1 eq $d2} } test "Multi Part AOF can upgrade when when two servers share the same server dir (server2)" { - wait_done_loading $redis2 + wait_done_loading $valkey2 - assert_equal 0 [$redis2 exists k1] - assert_equal 0 [$redis2 exists k2] - assert_equal 0 [$redis2 exists k3] + assert_equal 0 [$valkey2 exists k1] + assert_equal 0 [$valkey2 exists k2] + assert_equal 0 [$valkey2 exists k3] - assert_equal v4 [$redis2 get k4] - assert_equal v5 [$redis2 get k5] - assert_equal v6 [$redis2 get k6] + assert_equal v4 [$valkey2 get k4] + assert_equal v5 [$valkey2 get k5] + assert_equal v6 [$valkey2 get k6] assert_aof_manifest_content $aof_manifest_file2 { {file appendonly.aof2 seq 1 type b} {file appendonly.aof2.1.incr.aof seq 1 type i} } - $redis2 bgrewriteaof - waitForBgrewriteaof $redis2 + $valkey2 bgrewriteaof + waitForBgrewriteaof $valkey2 - assert_equal OK [$redis2 set k v] + assert_equal OK [$valkey2 set k v] assert_aof_manifest_content $aof_manifest_file2 { {file appendonly.aof2.2.base.rdb seq 2 type b} {file appendonly.aof2.2.incr.aof seq 2 type i} } - set d1 [$redis2 debug digest] - $redis2 debug loadaof - set d2 [$redis2 debug digest] + set d1 [$valkey2 debug digest] + $valkey2 debug loadaof + set d2 [$valkey2 debug digest] assert {$d1 eq $d2} } } @@ -677,7 +677,7 @@ tags {"external:skip"} { test {Multi Part AOF can handle appendfilename contains whitespaces} { start_server [list overrides [list appendonly yes appendfilename "\" file seq \\n\\n.aof \""]] { - set dir [get_redis_dir] + set dir [get_valkey_dir] set aof_manifest_name [format "%s/%s/%s%s" $dir "appendonlydir" " file seq \n\n.aof " $::manifest_suffix] set valkey [valkey [srv host] [srv port] 0 $::tls] @@ -756,7 +756,7 @@ tags {"external:skip"} { start_server {tags {"Multi Part AOF"} overrides {aof-use-rdb-preamble {yes} appendonly {no} save {}}} { - set dir [get_redis_dir] + set dir [get_valkey_dir] set aof_basename "appendonly.aof" set aof_dirname "appendonlydir" set aof_dirpath "$dir/$aof_dirname" @@ -1174,7 +1174,7 @@ tags {"external:skip"} { } start_server {overrides {aof-use-rdb-preamble {yes} appendonly {no} save {}}} { - set dir [get_redis_dir] + set dir [get_valkey_dir] set aof_basename "appendonly.aof" set aof_dirname "appendonlydir" set aof_dirpath "$dir/$aof_dirname" diff --git a/tests/integration/valkey-cli.tcl b/tests/integration/valkey-cli.tcl index c3497d95b9..04b91caf80 100644 --- a/tests/integration/valkey-cli.tcl +++ b/tests/integration/valkey-cli.tcl @@ -444,7 +444,7 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS r acl deluser clitest } - proc test_redis_cli_rdb_dump {functions_only} { + proc test_valkey_cli_rdb_dump {functions_only} { r flushdb r function flush @@ -480,12 +480,12 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS test "Dumping an RDB - functions only: $functions_only" { # Disk-based master assert_match "OK" [r config set repl-diskless-sync no] - test_redis_cli_rdb_dump $functions_only + test_valkey_cli_rdb_dump $functions_only # Disk-less master assert_match "OK" [r config set repl-diskless-sync yes] assert_match "OK" [r config set repl-diskless-sync-delay 0] - test_redis_cli_rdb_dump $functions_only + test_valkey_cli_rdb_dump $functions_only } {} {needs:repl needs:debug} } ;# foreach functions_only @@ -504,12 +504,12 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS assert_equal {key:2} [run_cli --scan --quoted-pattern {"*:\x32"}] } - proc test_redis_cli_repl {} { + proc test_valkey_cli_repl {} { set fd [open_cli "--replica"] wait_for_condition 500 100 { [string match {*slave0:*state=online*} [r info]] } else { - fail "redis-cli --replica did not connect" + fail "valkey-cli --replica did not connect" } for {set i 0} {$i < 100} {incr i} { @@ -519,7 +519,7 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS wait_for_condition 500 100 { [string match {*test-value-99*} [read_cli $fd]] } else { - fail "redis-cli --replica didn't read commands" + fail "valkey-cli --replica didn't read commands" } fconfigure $fd -blocking true @@ -531,12 +531,12 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS test "Connecting as a replica" { # Disk-based master assert_match "OK" [r config set repl-diskless-sync no] - test_redis_cli_repl + test_valkey_cli_repl # Disk-less master assert_match "OK" [r config set repl-diskless-sync yes] assert_match "OK" [r config set repl-diskless-sync-delay 0] - test_redis_cli_repl + test_valkey_cli_repl } {} {needs:repl} test "Piping raw protocol" { diff --git a/tests/support/aofmanifest.tcl b/tests/support/aofmanifest.tcl index 151626294f..308d1172aa 100644 --- a/tests/support/aofmanifest.tcl +++ b/tests/support/aofmanifest.tcl @@ -12,7 +12,7 @@ proc join_path {dir1 dir2} { return [format "%s/%s" $dir1 $dir2] } -proc get_redis_dir {} { +proc get_valkey_dir {} { set config [srv config] set _ [dict get $config "dir"] } diff --git a/tests/support/cluster.tcl b/tests/support/cluster.tcl index 59f6767b88..5027bacb78 100644 --- a/tests/support/cluster.tcl +++ b/tests/support/cluster.tcl @@ -4,25 +4,25 @@ # # Example usage: # -# set c [redis_cluster {127.0.0.1:6379 127.0.0.1:6380}] +# set c [valkey_cluster {127.0.0.1:6379 127.0.0.1:6380}] # $c set foo # $c get foo # $c close package require Tcl 8.5 -package provide redis_cluster 0.1 +package provide valkey_cluster 0.1 -namespace eval redis_cluster {} -set ::redis_cluster::internal_id 0 -set ::redis_cluster::id 0 -array set ::redis_cluster::startup_nodes {} -array set ::redis_cluster::nodes {} -array set ::redis_cluster::slots {} -array set ::redis_cluster::tls {} +namespace eval valkey_cluster {} +set ::valkey_cluster::internal_id 0 +set ::valkey_cluster::id 0 +array set ::valkey_cluster::startup_nodes {} +array set ::valkey_cluster::nodes {} +array set ::valkey_cluster::slots {} +array set ::valkey_cluster::tls {} # List of "plain" commands, which are commands where the sole key is always # the first argument. -set ::redis_cluster::plain_commands { +set ::valkey_cluster::plain_commands { get set setnx setex psetex append strlen exists setbit getbit setrange getrange substr incr decr rpush lpush rpushx lpushx linsert rpop lpop brpop llen lindex lset lrange ltrim lrem @@ -39,34 +39,34 @@ set ::redis_cluster::plain_commands { # Create a cluster client. The nodes are given as a list of host:port. The TLS # parameter (1 or 0) is optional and defaults to the global $::tls. -proc redis_cluster {nodes {tls -1}} { - set id [incr ::redis_cluster::id] - set ::redis_cluster::startup_nodes($id) $nodes - set ::redis_cluster::nodes($id) {} - set ::redis_cluster::slots($id) {} - set ::redis_cluster::tls($id) [expr $tls == -1 ? $::tls : $tls] - set handle [interp alias {} ::redis_cluster::instance$id {} ::redis_cluster::__dispatch__ $id] +proc valkey_cluster {nodes {tls -1}} { + set id [incr ::valkey_cluster::id] + set ::valkey_cluster::startup_nodes($id) $nodes + set ::valkey_cluster::nodes($id) {} + set ::valkey_cluster::slots($id) {} + set ::valkey_cluster::tls($id) [expr $tls == -1 ? $::tls : $tls] + set handle [interp alias {} ::valkey_cluster::instance$id {} ::valkey_cluster::__dispatch__ $id] $handle refresh_nodes_map return $handle } # Totally reset the slots / nodes state for the client, calls # CLUSTER NODES in the first startup node available, populates the -# list of nodes ::redis_cluster::nodes($id) with an hash mapping node +# list of nodes ::valkey_cluster::nodes($id) with an hash mapping node # ip:port to a representation of the node (another hash), and finally -# maps ::redis_cluster::slots($id) with an hash mapping slot numbers +# maps ::valkey_cluster::slots($id) with an hash mapping slot numbers # to node IDs. # # This function is called when a new Cluster client is initialized # and every time we get a -MOVED redirection error. -proc ::redis_cluster::__method__refresh_nodes_map {id} { +proc ::valkey_cluster::__method__refresh_nodes_map {id} { # Contact the first responding startup node. set idx 0; # Index of the node that will respond. set errmsg {} - foreach start_node $::redis_cluster::startup_nodes($id) { + foreach start_node $::valkey_cluster::startup_nodes($id) { set ip_port [lindex [split $start_node @] 0] lassign [split $ip_port :] start_host start_port - set tls $::redis_cluster::tls($id) + set tls $::valkey_cluster::tls($id) if {[catch { set r {} set r [valkey $start_host $start_port 0 $tls] @@ -84,18 +84,18 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} { } } - if {$idx == [llength $::redis_cluster::startup_nodes($id)]} { + if {$idx == [llength $::valkey_cluster::startup_nodes($id)]} { error "No good startup node found. $errmsg" } # Put the node that responded as first in the list if it is not # already the first. if {$idx != 0} { - set l $::redis_cluster::startup_nodes($id) + set l $::valkey_cluster::startup_nodes($id) set left [lrange $l 0 [expr {$idx-1}]] set right [lrange $l [expr {$idx+1}] end] set l [concat [lindex $l $idx] $left $right] - set ::redis_cluster::startup_nodes($id) $l + set ::valkey_cluster::startup_nodes($id) $l } # Parse CLUSTER NODES output to populate the nodes description. @@ -114,7 +114,7 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} { # Connect to the node set link {} - set tls $::redis_cluster::tls($id) + set tls $::valkey_cluster::tls($id) catch {set link [valkey $host $port 0 $tls]} # Build this node description as an hash. @@ -130,17 +130,17 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} { link $link \ ] dict set nodes $addr $node - lappend ::redis_cluster::startup_nodes($id) $addr + lappend ::valkey_cluster::startup_nodes($id) $addr } # Close all the existing links in the old nodes map, and set the new # map as current. - foreach n $::redis_cluster::nodes($id) { + foreach n $::valkey_cluster::nodes($id) { catch { [dict get $n link] close } } - set ::redis_cluster::nodes($id) $nodes + set ::valkey_cluster::nodes($id) $nodes # Populates the slots -> nodes map. dict for {addr node} $nodes { @@ -148,47 +148,47 @@ proc ::redis_cluster::__method__refresh_nodes_map {id} { lassign [split $slotrange -] start end if {$end == {}} {set end $start} for {set j $start} {$j <= $end} {incr j} { - dict set ::redis_cluster::slots($id) $j $addr + dict set ::valkey_cluster::slots($id) $j $addr } } } # Only retain unique entries in the startup nodes list - set ::redis_cluster::startup_nodes($id) [lsort -unique $::redis_cluster::startup_nodes($id)] + set ::valkey_cluster::startup_nodes($id) [lsort -unique $::valkey_cluster::startup_nodes($id)] } -# Free a redis_cluster handle. -proc ::redis_cluster::__method__close {id} { +# Free a valkey_cluster handle. +proc ::valkey_cluster::__method__close {id} { catch { - set nodes $::redis_cluster::nodes($id) + set nodes $::valkey_cluster::nodes($id) dict for {addr node} $nodes { catch { [dict get $node link] close } } } - catch {unset ::redis_cluster::startup_nodes($id)} - catch {unset ::redis_cluster::nodes($id)} - catch {unset ::redis_cluster::slots($id)} - catch {unset ::redis_cluster::tls($id)} - catch {interp alias {} ::redis_cluster::instance$id {}} + catch {unset ::valkey_cluster::startup_nodes($id)} + catch {unset ::valkey_cluster::nodes($id)} + catch {unset ::valkey_cluster::slots($id)} + catch {unset ::valkey_cluster::tls($id)} + catch {interp alias {} ::valkey_cluster::instance$id {}} } -proc ::redis_cluster::__method__masternode_for_slot {id slot} { +proc ::valkey_cluster::__method__masternode_for_slot {id slot} { # Get the node mapped to this slot. - set node_addr [dict get $::redis_cluster::slots($id) $slot] + set node_addr [dict get $::valkey_cluster::slots($id) $slot] if {$node_addr eq {}} { error "No mapped node for slot $slot." } - return [dict get $::redis_cluster::nodes($id) $node_addr] + return [dict get $::valkey_cluster::nodes($id) $node_addr] } -proc ::redis_cluster::__method__masternode_notfor_slot {id slot} { +proc ::valkey_cluster::__method__masternode_notfor_slot {id slot} { # Get a node that is not mapped to this slot. - set node_addr [dict get $::redis_cluster::slots($id) $slot] - set addrs [dict keys $::redis_cluster::nodes($id)] + set node_addr [dict get $::valkey_cluster::slots($id) $slot] + set addrs [dict keys $::valkey_cluster::nodes($id)] foreach addr [lshuffle $addrs] { - set node [dict get $::redis_cluster::nodes($id) $addr] + set node [dict get $::valkey_cluster::nodes($id) $addr] if {$node_addr ne $addr && [dict get $node slaveof] eq "-"} { return $node } @@ -196,22 +196,22 @@ proc ::redis_cluster::__method__masternode_notfor_slot {id slot} { error "Slot $slot is everywhere" } -proc ::redis_cluster::__dispatch__ {id method args} { - if {[info command ::redis_cluster::__method__$method] eq {}} { +proc ::valkey_cluster::__dispatch__ {id method args} { + if {[info command ::valkey_cluster::__method__$method] eq {}} { # Get the keys from the command. - set keys [::redis_cluster::get_keys_from_command $method $args] + set keys [::valkey_cluster::get_keys_from_command $method $args] if {$keys eq {}} { - error "Redis command '$method' is not supported by redis_cluster." + error "Redis command '$method' is not supported by valkey_cluster." } # Resolve the keys in the corresponding hash slot they hash to. - set slot [::redis_cluster::get_slot_from_keys $keys] + set slot [::valkey_cluster::get_slot_from_keys $keys] if {$slot eq {}} { error "Invalid command: multiple keys not hashing to the same slot." } # Get the node mapped to this slot. - set node_addr [dict get $::redis_cluster::slots($id) $slot] + set node_addr [dict get $::valkey_cluster::slots($id) $slot] if {$node_addr eq {}} { error "No mapped node for slot $slot." } @@ -221,7 +221,7 @@ proc ::redis_cluster::__dispatch__ {id method args} { set asking 0 while {[incr retry -1]} { if {$retry < 5} {after 100} - set node [dict get $::redis_cluster::nodes($id) $node_addr] + set node [dict get $::valkey_cluster::nodes($id) $node_addr] set link [dict get $node link] if {$asking} { $link ASKING @@ -233,8 +233,8 @@ proc ::redis_cluster::__dispatch__ {id method args} { [string range $e 0 2] eq {I/O} \ } { # MOVED redirection. - ::redis_cluster::__method__refresh_nodes_map $id - set node_addr [dict get $::redis_cluster::slots($id) $slot] + ::valkey_cluster::__method__refresh_nodes_map $id + set node_addr [dict get $::valkey_cluster::slots($id) $slot] continue } elseif {[string range $e 0 2] eq {ASK}} { # ASK redirection. @@ -252,14 +252,14 @@ proc ::redis_cluster::__dispatch__ {id method args} { } error "Too many redirections or failures contacting Redis Cluster." } else { - uplevel 1 [list ::redis_cluster::__method__$method $id] $args + uplevel 1 [list ::valkey_cluster::__method__$method $id] $args } } -proc ::redis_cluster::get_keys_from_command {cmd argv} { +proc ::valkey_cluster::get_keys_from_command {cmd argv} { set cmd [string tolower $cmd] # Most commands get just one key as first argument. - if {[lsearch -exact $::redis_cluster::plain_commands $cmd] != -1} { + if {[lsearch -exact $::valkey_cluster::plain_commands $cmd] != -1} { return [list [lindex $argv 0]] } @@ -277,7 +277,7 @@ proc ::redis_cluster::get_keys_from_command {cmd argv} { # Returns the CRC16 of the specified string. # The CRC parameters are described in the Cluster specification. -set ::redis_cluster::XMODEMCRC16Lookup { +set ::valkey_cluster::XMODEMCRC16Lookup { 0x0000 0x1021 0x2042 0x3063 0x4084 0x50a5 0x60c6 0x70e7 0x8108 0x9129 0xa14a 0xb16b 0xc18c 0xd1ad 0xe1ce 0xf1ef 0x1231 0x0210 0x3273 0x2252 0x52b5 0x4294 0x72f7 0x62d6 @@ -312,19 +312,19 @@ set ::redis_cluster::XMODEMCRC16Lookup { 0x6e17 0x7e36 0x4e55 0x5e74 0x2e93 0x3eb2 0x0ed1 0x1ef0 } -proc ::redis_cluster::crc16 {s} { +proc ::valkey_cluster::crc16 {s} { set s [encoding convertto ascii $s] set crc 0 foreach char [split $s {}] { scan $char %c byte - set crc [expr {(($crc<<8)&0xffff) ^ [lindex $::redis_cluster::XMODEMCRC16Lookup [expr {(($crc>>8)^$byte) & 0xff}]]}] + set crc [expr {(($crc<<8)&0xffff) ^ [lindex $::valkey_cluster::XMODEMCRC16Lookup [expr {(($crc>>8)^$byte) & 0xff}]]}] } return $crc } # Hash a single key returning the slot it belongs to, Implemented hash # tags as described in the Cluster specification. -proc ::redis_cluster::hash {key} { +proc ::valkey_cluster::hash {key} { set keylen [string length $key] set s {} set e {} @@ -353,10 +353,10 @@ proc ::redis_cluster::hash {key} { # Return the slot the specified keys hash to. # If the keys hash to multiple slots, an empty string is returned to # signal that the command can't be run in Cluster. -proc ::redis_cluster::get_slot_from_keys {keys} { +proc ::valkey_cluster::get_slot_from_keys {keys} { set slot {} foreach k $keys { - set s [::redis_cluster::hash $k] + set s [::valkey_cluster::hash $k] if {$slot eq {}} { set slot $s } elseif {$slot != $s} { diff --git a/tests/support/redis.tcl b/tests/support/redis.tcl index 4050d4065a..9797fc0147 100644 --- a/tests/support/redis.tcl +++ b/tests/support/redis.tcl @@ -72,13 +72,13 @@ proc valkey {{server 127.0.0.1} {port 6379} {defer 0} {tls 0} {tlsoptions {}} {r set ::valkey::curr_argv($id) 0 set ::valkey::testing_resp3($id) 0 set ::valkey::tls($id) $tls - ::valkey::redis_reset_state $id - interp alias {} ::valkey::redisHandle$id {} ::valkey::__dispatch__ $id + ::valkey::valkey_reset_state $id + interp alias {} ::valkey::valkeyHandle$id {} ::valkey::__dispatch__ $id } # On recent versions of tcl-tls/OpenSSL, reading from a dropped connection # results with an error we need to catch and mimic the old behavior. -proc ::valkey::redis_safe_read {fd len} { +proc ::valkey::valkey_safe_read {fd len} { if {$len == -1} { set err [catch {set val [read $fd]} msg] } else { @@ -93,7 +93,7 @@ proc ::valkey::redis_safe_read {fd len} { error $msg } -proc ::valkey::redis_safe_gets {fd} { +proc ::valkey::valkey_safe_gets {fd} { if {[catch {set val [gets $fd]} msg]} { if {[string match "*connection abort*" $msg]} { return {} @@ -162,7 +162,7 @@ proc ::valkey::__dispatch__raw__ {id method argv} { foreach a $argv { append cmd "$[string length $a]\r\n$a\r\n" } - ::valkey::redis_write $fd $cmd + ::valkey::valkey_write $fd $cmd if {[catch {flush $fd}]} { catch {close $fd} set ::valkey::fd($id) {} @@ -172,13 +172,13 @@ proc ::valkey::__dispatch__raw__ {id method argv} { set ::valkey::curr_argv($id) [concat $method $argv] if {!$deferred} { if {$blocking} { - ::valkey::redis_read_reply $id $fd + ::valkey::valkey_read_reply $id $fd } else { # Every well formed reply read will pop an element from this # list and use it as a callback. So pipelining is supported # in non blocking mode. lappend ::valkey::callback($id) $callback - fileevent $fd readable [list ::valkey::redis_readable $fd $id] + fileevent $fd readable [list ::valkey::valkey_readable $fd $id] } } } else { @@ -196,15 +196,15 @@ proc ::valkey::__method__reconnect {id fd val} { } proc ::valkey::__method__read {id fd} { - ::valkey::redis_read_reply $id $fd + ::valkey::valkey_read_reply $id $fd } proc ::valkey::__method__rawread {id fd {len -1}} { - return [redis_safe_read $fd $len] + return [valkey_safe_read $fd $len] } proc ::valkey::__method__write {id fd buf} { - ::valkey::redis_write $fd $buf + ::valkey::valkey_write $fd $buf } proc ::valkey::__method__flush {id fd} { @@ -226,7 +226,7 @@ proc ::valkey::__method__close {id fd} { catch {unset ::valkey::callback($id)} catch {unset ::valkey::curr_argv($id)} catch {unset ::valkey::testing_resp3($id)} - catch {interp alias {} ::valkey::redisHandle$id {}} + catch {interp alias {} ::valkey::valkeyHandle$id {}} } proc ::valkey::__method__channel {id fd} { @@ -249,37 +249,37 @@ proc ::valkey::__method__attributes {id fd} { set _ $::valkey::attributes($id) } -proc ::valkey::redis_write {fd buf} { +proc ::valkey::valkey_write {fd buf} { puts -nonewline $fd $buf } -proc ::valkey::redis_writenl {fd buf} { - redis_write $fd $buf - redis_write $fd "\r\n" +proc ::valkey::valkey_writenl {fd buf} { + valkey_write $fd $buf + valkey_write $fd "\r\n" flush $fd } -proc ::valkey::redis_readnl {fd len} { - set buf [redis_safe_read $fd $len] - redis_safe_read $fd 2 ; # discard CR LF +proc ::valkey::valkey_readnl {fd len} { + set buf [valkey_safe_read $fd $len] + valkey_safe_read $fd 2 ; # discard CR LF return $buf } proc ::valkey::valkey_bulk_read {fd} { - set count [redis_read_line $fd] + set count [valkey_read_line $fd] if {$count == -1} return {} - set buf [redis_readnl $fd $count] + set buf [valkey_readnl $fd $count] return $buf } proc ::valkey::redis_multi_bulk_read {id fd} { - set count [redis_read_line $fd] + set count [valkey_read_line $fd] if {$count == -1} return {} set l {} set err {} for {set i 0} {$i < $count} {incr i} { if {[catch { - lappend l [redis_read_reply_logic $id $fd] + lappend l [valkey_read_reply_logic $id $fd] } e] && $err eq {}} { set err $e } @@ -288,15 +288,15 @@ proc ::valkey::redis_multi_bulk_read {id fd} { return $l } -proc ::valkey::redis_read_map {id fd} { - set count [redis_read_line $fd] +proc ::valkey::valkey_read_map {id fd} { + set count [valkey_read_line $fd] if {$count == -1} return {} set d {} set err {} for {set i 0} {$i < $count} {incr i} { if {[catch { - set k [redis_read_reply_logic $id $fd] ; # key - set v [redis_read_reply_logic $id $fd] ; # value + set k [valkey_read_reply_logic $id $fd] ; # key + set v [valkey_read_reply_logic $id $fd] ; # value dict set d $k $v } e] && $err eq {}} { set err $e @@ -306,24 +306,24 @@ proc ::valkey::redis_read_map {id fd} { return $d } -proc ::valkey::redis_read_line fd { - string trim [redis_safe_gets $fd] +proc ::valkey::valkey_read_line fd { + string trim [valkey_safe_gets $fd] } -proc ::valkey::redis_read_null fd { - redis_safe_gets $fd +proc ::valkey::valkey_read_null fd { + valkey_safe_gets $fd return {} } -proc ::valkey::redis_read_bool fd { - set v [redis_read_line $fd] +proc ::valkey::valkey_read_bool fd { + set v [valkey_read_line $fd] if {$v == "t"} {return 1} if {$v == "f"} {return 0} return -code error "Bad protocol, '$v' as bool type" } -proc ::valkey::redis_read_double {id fd} { - set v [redis_read_line $fd] +proc ::valkey::valkey_read_double {id fd} { + set v [valkey_read_line $fd] # unlike many other DTs, there is a textual difference between double and a string with the same value, # so we need to transform to double if we are testing RESP3 (i.e. some tests check that a # double reply is "1.0" and not "1") @@ -334,35 +334,35 @@ proc ::valkey::redis_read_double {id fd} { } } -proc ::valkey::redis_read_verbatim_str fd { +proc ::valkey::valkey_read_verbatim_str fd { set v [valkey_bulk_read $fd] # strip the first 4 chars ("txt:") return [string range $v 4 end] } -proc ::valkey::redis_read_reply_logic {id fd} { +proc ::valkey::valkey_read_reply_logic {id fd} { if {$::valkey::readraw($id)} { - return [redis_read_line $fd] + return [valkey_read_line $fd] } while {1} { - set type [redis_safe_read $fd 1] + set type [valkey_safe_read $fd 1] switch -exact -- $type { - _ {return [redis_read_null $fd]} + _ {return [valkey_read_null $fd]} : - ( - - + {return [redis_read_line $fd]} - , {return [redis_read_double $id $fd]} - # {return [redis_read_bool $fd]} - = {return [redis_read_verbatim_str $fd]} - - {return -code error [redis_read_line $fd]} + + {return [valkey_read_line $fd]} + , {return [valkey_read_double $id $fd]} + # {return [valkey_read_bool $fd]} + = {return [valkey_read_verbatim_str $fd]} + - {return -code error [valkey_read_line $fd]} $ {return [valkey_bulk_read $fd]} > - ~ - * {return [redis_multi_bulk_read $id $fd]} - % {return [redis_read_map $id $fd]} + % {return [valkey_read_map $id $fd]} | { - set attrib [redis_read_map $id $fd] + set attrib [valkey_read_map $id $fd] set ::valkey::attributes($id) $attrib continue } @@ -378,27 +378,27 @@ proc ::valkey::redis_read_reply_logic {id fd} { } } -proc ::valkey::redis_read_reply {id fd} { - set response [redis_read_reply_logic $id $fd] +proc ::valkey::valkey_read_reply {id fd} { + set response [valkey_read_reply_logic $id $fd] ::response_transformers::transform_response_if_needed $id $::valkey::curr_argv($id) $response } -proc ::valkey::redis_reset_state id { +proc ::valkey::valkey_reset_state id { set ::valkey::state($id) [dict create buf {} mbulk -1 bulk -1 reply {}] set ::valkey::statestack($id) {} } -proc ::valkey::redis_call_callback {id type reply} { +proc ::valkey::valkey_call_callback {id type reply} { set cb [lindex $::valkey::callback($id) 0] set ::valkey::callback($id) [lrange $::valkey::callback($id) 1 end] - uplevel #0 $cb [list ::valkey::redisHandle$id $type $reply] - ::valkey::redis_reset_state $id + uplevel #0 $cb [list ::valkey::valkeyHandle$id $type $reply] + ::valkey::valkey_reset_state $id } # Read a reply in non-blocking mode. -proc ::valkey::redis_readable {fd id} { +proc ::valkey::valkey_readable {fd id} { if {[eof $fd]} { - redis_call_callback $id eof {} + valkey_call_callback $id eof {} ::valkey::__method__close $id $fd return } @@ -407,9 +407,9 @@ proc ::valkey::redis_readable {fd id} { if {$line eq {}} return ;# No complete line available, return switch -exact -- [string index $line 0] { : - - + {redis_call_callback $id reply [string range $line 1 end-1]} - - {redis_call_callback $id err [string range $line 1 end-1]} - ( {redis_call_callback $id reply [string range $line 1 end-1]} + + {valkey_call_callback $id reply [string range $line 1 end-1]} + - {valkey_call_callback $id err [string range $line 1 end-1]} + ( {valkey_call_callback $id reply [string range $line 1 end-1]} $ { dict set ::valkey::state($id) bulk \ [expr [string range $line 1 end-1]+2] @@ -417,18 +417,18 @@ proc ::valkey::redis_readable {fd id} { # We got a $-1, hack the state to play well with this. dict set ::valkey::state($id) bulk 2 dict set ::valkey::state($id) buf "\r\n" - ::valkey::redis_readable $fd $id + ::valkey::valkey_readable $fd $id } } * { dict set ::valkey::state($id) mbulk [string range $line 1 end-1] # Handle *-1 if {[dict get $::valkey::state($id) mbulk] == -1} { - redis_call_callback $id reply {} + valkey_call_callback $id reply {} } } default { - redis_call_callback $id err \ + valkey_call_callback $id err \ "Bad protocol, $type as reply type byte" } } @@ -443,7 +443,7 @@ proc ::valkey::redis_readable {fd id} { if {[string length [dict get $::valkey::state($id) buf]] == [dict get $::valkey::state($id) bulk]} { if {[dict get $::valkey::state($id) mbulk] == -1} { - redis_call_callback $id reply \ + valkey_call_callback $id reply \ [string range [dict get $::valkey::state($id) buf] 0 end-2] } else { dict with ::valkey::state($id) { @@ -452,7 +452,7 @@ proc ::valkey::redis_readable {fd id} { set bulk -1 } if {[dict get $::valkey::state($id) mbulk] == 0} { - redis_call_callback $id reply \ + valkey_call_callback $id reply \ [dict get $::valkey::state($id) reply] } } diff --git a/tests/unit/cluster/cluster-response-tls.tcl b/tests/unit/cluster/cluster-response-tls.tcl index a099fa7f05..9b4e165e99 100644 --- a/tests/unit/cluster/cluster-response-tls.tcl +++ b/tests/unit/cluster/cluster-response-tls.tcl @@ -27,7 +27,7 @@ proc cluster_response_tls {tls_cluster} { test "CLUSTER SLOTS with different connection type -- tls-cluster $tls_cluster" { set slots1 [R 0 cluster slots] set pport [srv 0 pport] - set cluster_client [redis_cluster 127.0.0.1:$pport 0] + set cluster_client [valkey_cluster 127.0.0.1:$pport 0] set slots2 [$cluster_client cluster slots] $cluster_client close # Compare the ports in the first row @@ -38,15 +38,15 @@ proc cluster_response_tls {tls_cluster} { set nodes [R 0 cluster nodes] set port1 [get_port_from_node_info [lindex [split $nodes "\r\n"] 0]] set pport [srv 0 pport] - set cluster_client [redis_cluster 127.0.0.1:$pport 0] + set cluster_client [valkey_cluster 127.0.0.1:$pport 0] set nodes [$cluster_client cluster nodes] set port2 [get_port_from_node_info [lindex [split $nodes "\r\n"] 0]] $cluster_client close assert_not_equal $port1 $port2 } - set cluster [redis_cluster 127.0.0.1:[srv 0 port]] - set cluster_pport [redis_cluster 127.0.0.1:[srv 0 pport] 0] + set cluster [valkey_cluster 127.0.0.1:[srv 0 port]] + set cluster_pport [valkey_cluster 127.0.0.1:[srv 0 pport] 0] $cluster refresh_nodes_map test "Set many keys in the cluster -- tls-cluster $tls_cluster" { From 4bdc9234d76ae556706f64c8920b64317a793c0c Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Wed, 24 Apr 2024 16:02:58 +0000 Subject: [PATCH 02/25] Add support for compiling with mimalloc Signed-off-by: Sher Sun --- .gitmodules | 3 +++ deps/Makefile | 13 +++++++++++++ deps/mimalloc | 1 + src/Makefile | 13 +++++++++++++ src/zmalloc.h | 15 ++++++++++++++- 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 .gitmodules create mode 160000 deps/mimalloc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000000..2b3ffa4080 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "deps/mimalloc"] + path = deps/mimalloc + url = https://github.com/microsoft/mimalloc.git diff --git a/deps/Makefile b/deps/Makefile index 67b7d41026..eadd555a7b 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -12,6 +12,10 @@ BINCOLOR="\033[37;1m" MAKECOLOR="\033[32;1m" ENDCOLOR="\033[0m" +MIMALLOC_DIR := mimalloc +MIMALLOC_BUILD_DIR := $(MIMALLOC_DIR)/out/release +MIMALLOC_LIB := $(MIMALLOC_BUILD_DIR)/libmimalloc.a + default: @echo "Explicit target required" @@ -42,6 +46,7 @@ distclean: -(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true -(cd hdr_histogram && $(MAKE) clean) > /dev/null || true -(cd fpconv && $(MAKE) clean) > /dev/null || true + -rm -rf $(MIMALLOC_BUILD_DIR) -(rm -f .make-*) .PHONY: distclean @@ -116,3 +121,11 @@ jemalloc: .make-prerequisites cd jemalloc && $(MAKE) lib/libjemalloc.a .PHONY: jemalloc + +.PHONY: mimalloc + +mimalloc: .make-prerequisites + @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) + @[ -d $(MIMALLOC_BUILD_DIR) ] || mkdir -p $(MIMALLOC_BUILD_DIR) + cd $(MIMALLOC_BUILD_DIR) && cmake ../.. -DCMAKE_BUILD_TYPE=Release + $(MAKE) -C $(MIMALLOC_BUILD_DIR) \ No newline at end of file diff --git a/deps/mimalloc b/deps/mimalloc new file mode 160000 index 0000000000..77eb3a366b --- /dev/null +++ b/deps/mimalloc @@ -0,0 +1 @@ +Subproject commit 77eb3a366b0355a0a90e2a0a8b6ac03757b4a1f6 diff --git a/src/Makefile b/src/Makefile index 47b961862a..4a11836f54 100644 --- a/src/Makefile +++ b/src/Makefile @@ -98,6 +98,10 @@ ifeq ($(USE_JEMALLOC),no) MALLOC=libc endif +ifeq ($(USE_MIMALLOC),yes) + MALLOC=mimalloc +endif + ifdef SANITIZER ifeq ($(SANITIZER),address) MALLOC=libc @@ -285,6 +289,15 @@ ifeq ($(MALLOC),jemalloc) FINAL_LIBS := ../deps/jemalloc/lib/libjemalloc.a $(FINAL_LIBS) endif +ifeq ($(MALLOC),mimalloc) + DEPENDENCY_TARGETS+= mimalloc + MIMALLOC_DIR= ../deps/mimalloc + MIMALLOC_LIB= $(MIMALLOC_DIR)/out/release/libmimalloc.a + FINAL_CFLAGS+= -DUSE_MIMALLOC -I$(MIMALLOC_DIR)/include + FINAL_LIBS := $(MIMALLOC_LIB) $(FINAL_LIBS) +endif + + # LIBSSL & LIBCRYPTO LIBSSL_LIBS= LIBSSL_PKGCONFIG := $(shell $(PKG_CONFIG) --exists libssl && echo $$?) diff --git a/src/zmalloc.h b/src/zmalloc.h index 1cf4af96c4..82a8440a2d 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -34,6 +34,9 @@ /* Double expansion needed for stringification of macro values. */ #define __xstr(s) __str(s) #define __str(s) #s +#define MI_VERSION_MAJOR 1 +#define MI_VERSION_MINOR 8 +#define MI_VERSION_PATCH 5 #if defined(USE_TCMALLOC) #define ZMALLOC_LIB ("tcmalloc-" __xstr(TC_VERSION_MAJOR) "." __xstr(TC_VERSION_MINOR)) @@ -55,6 +58,16 @@ #error "Newer version of jemalloc required" #endif +#elif defined(USE_MIMALLOC) +#define ZMALLOC_LIB ("mimalloc-" __xstr(MI_VERSION_MAJOR) "." __xstr(MI_VERSION_MINOR) "." __xstr(MI_VERSION_PATCH)) +#include +#if (MI_VERSION_MAJOR == 1 && MI_VERSION_MINOR >= 8) || (MI_VERSION_MAJOR > 1) +#define HAVE_MALLOC_SIZE 1 +#define zmalloc_size(p) mi_usable_size(p) +#else +#error "Newer version of mimalloc required" +#endif + #elif defined(__APPLE__) #include #define HAVE_MALLOC_SIZE 1 @@ -172,4 +185,4 @@ int get_proc_stat_ll(int i, long long *res); int zmalloc_test(int argc, char **argv, int flags); #endif -#endif /* __ZMALLOC_H */ +#endif /* __ZMALLOC_H */ \ No newline at end of file From c5d5199f41067ff56235fd08ea074d71180902fa Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Wed, 24 Apr 2024 16:34:06 +0000 Subject: [PATCH 03/25] fix Signed-off-by: Sher Sun --- src/zmalloc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zmalloc.h b/src/zmalloc.h index 82a8440a2d..ee0eed6a33 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -185,4 +185,4 @@ int get_proc_stat_ll(int i, long long *res); int zmalloc_test(int argc, char **argv, int flags); #endif -#endif /* __ZMALLOC_H */ \ No newline at end of file +#endif /* __ZMALLOC_H */ From 0d7c60a7847805ef036894e329aa6b03fa08af6b Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Wed, 24 Apr 2024 18:38:15 +0000 Subject: [PATCH 04/25] Add support to use system libraries Signed-off-by: Sher Sun --- src/Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Makefile b/src/Makefile index 4a11836f54..8891e276c1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -290,12 +290,17 @@ ifeq ($(MALLOC),jemalloc) endif ifeq ($(MALLOC),mimalloc) +ifeq ($(USE_SYSTEM_MIMALLOC),yes) + FINAL_CFLAGS+= -DUSE_JEMALLOC $(shell $(PKG_CONFIG) --cflags mimalloc) + FINAL_LIBS := $(shell $(PKG_CONFIG) --libs mimalloc) $(FINAL_LIBS) +else DEPENDENCY_TARGETS+= mimalloc MIMALLOC_DIR= ../deps/mimalloc MIMALLOC_LIB= $(MIMALLOC_DIR)/out/release/libmimalloc.a FINAL_CFLAGS+= -DUSE_MIMALLOC -I$(MIMALLOC_DIR)/include FINAL_LIBS := $(MIMALLOC_LIB) $(FINAL_LIBS) endif +endif # LIBSSL & LIBCRYPTO @@ -424,6 +429,7 @@ persist-settings: distclean echo WARN=$(WARN) >> .make-settings echo OPT=$(OPT) >> .make-settings echo MALLOC=$(MALLOC) >> .make-settings + echo USE_SYSTEM_MIMALLOC=$(USE_SYSTEM_MIMALLOC) >> .make-settings echo BUILD_TLS=$(BUILD_TLS) >> .make-settings echo USE_SYSTEMD=$(USE_SYSTEMD) >> .make-settings echo CFLAGS=$(CFLAGS) >> .make-settings From 743d97852dbcb04d958583901bef59043c918f07 Mon Sep 17 00:00:00 2001 From: Wen Hui Date: Wed, 24 Apr 2024 14:54:52 -0400 Subject: [PATCH 05/25] Rename redis.tcl to valkey.tcl (#283) Includes some more changes e.g. the README under tests and some script under utils. Signed-off-by: hwware Signed-off-by: Sher Sun --- tests/README.md | 2 +- tests/helpers/bg_block_op.tcl | 2 +- tests/helpers/bg_complex_data.tcl | 2 +- tests/helpers/gen_write_load.tcl | 2 +- tests/instances.tcl | 2 +- tests/support/{redis.tcl => valkey.tcl} | 0 tests/test_helper.tcl | 6 +++--- utils/speed-regression.tcl | 14 +++++++------- 8 files changed, 15 insertions(+), 15 deletions(-) rename tests/support/{redis.tcl => valkey.tcl} (100%) diff --git a/tests/README.md b/tests/README.md index 8165f832ca..9d9c657760 100644 --- a/tests/README.md +++ b/tests/README.md @@ -16,7 +16,7 @@ match different external server configurations: | `--singledb` | Only use database 0, don't assume others are supported. | | `--ignore-encoding` | Skip all checks for specific encoding. | | `--ignore-digest` | Skip key value digest validations. | -| `--cluster-mode` | Run in strict Redis Cluster compatibility mode. | +| `--cluster-mode` | Run in strict Valkey Cluster compatibility mode. | | `--large-memory` | Enables tests that consume more than 100mb | Tags diff --git a/tests/helpers/bg_block_op.tcl b/tests/helpers/bg_block_op.tcl index eb02b12273..094397225f 100644 --- a/tests/helpers/bg_block_op.tcl +++ b/tests/helpers/bg_block_op.tcl @@ -1,4 +1,4 @@ -source tests/support/redis.tcl +source tests/support/valkey.tcl source tests/support/util.tcl set ::tlsdir "tests/tls" diff --git a/tests/helpers/bg_complex_data.tcl b/tests/helpers/bg_complex_data.tcl index fc4bf4237f..6bc5c59598 100644 --- a/tests/helpers/bg_complex_data.tcl +++ b/tests/helpers/bg_complex_data.tcl @@ -1,4 +1,4 @@ -source tests/support/redis.tcl +source tests/support/valkey.tcl source tests/support/util.tcl set ::tlsdir "tests/tls" diff --git a/tests/helpers/gen_write_load.tcl b/tests/helpers/gen_write_load.tcl index a5da6d9f4a..9a148b73cc 100644 --- a/tests/helpers/gen_write_load.tcl +++ b/tests/helpers/gen_write_load.tcl @@ -1,4 +1,4 @@ -source tests/support/redis.tcl +source tests/support/valkey.tcl set ::tlsdir "tests/tls" diff --git a/tests/instances.tcl b/tests/instances.tcl index 8b5c3ecaff..baeaddfe2e 100644 --- a/tests/instances.tcl +++ b/tests/instances.tcl @@ -10,7 +10,7 @@ package require Tcl 8.5 set tcl_precision 17 -source ../support/redis.tcl +source ../support/valkey.tcl source ../support/util.tcl source ../support/aofmanifest.tcl source ../support/server.tcl diff --git a/tests/support/redis.tcl b/tests/support/valkey.tcl similarity index 100% rename from tests/support/redis.tcl rename to tests/support/valkey.tcl diff --git a/tests/test_helper.tcl b/tests/test_helper.tcl index 3f75378e80..4df9110552 100644 --- a/tests/test_helper.tcl +++ b/tests/test_helper.tcl @@ -5,7 +5,7 @@ package require Tcl 8.5 set tcl_precision 17 -source tests/support/redis.tcl +source tests/support/valkey.tcl source tests/support/aofmanifest.tcl source tests/support/server.tcl source tests/support/cluster_util.tcl @@ -424,7 +424,7 @@ proc kill_clients {} { proc force_kill_all_servers {} { foreach p $::active_servers { - puts "Killing still running Redis server $p" + puts "Killing still running Valkey server $p" catch {exec kill -9 $p} } } @@ -560,7 +560,7 @@ proc print_help_screen {} { "--wait-server Wait after server is started (so that you can attach a debugger)." "--dump-logs Dump server log on test failure." "--tls Run tests in TLS mode." - "--tls-module Run tests in TLS mode with Redis module." + "--tls-module Run tests in TLS mode with Valkey module." "--host Run tests against an external host." "--port TCP port to use against external host." "--baseport Initial port number for spawned valkey servers." diff --git a/utils/speed-regression.tcl b/utils/speed-regression.tcl index 6802d8cd5e..2a4ecde452 100755 --- a/utils/speed-regression.tcl +++ b/utils/speed-regression.tcl @@ -2,7 +2,7 @@ # Copyright (C) 2011 Salvatore Sanfilippo # Released under the BSD license like Redis itself -source ../tests/support/redis.tcl +source ../tests/support/valkey.tcl set ::port 12123 set ::tests {PING,SET,GET,INCR,LPUSH,LPOP,SADD,SPOP,LRANGE_100,LRANGE_600,MSET} set ::datasize 16 @@ -20,25 +20,25 @@ proc run-tests branches { exec -ignorestderr make 2> /dev/null if {$branch_id == 0} { - puts " copy redis-benchmark from unstable to /tmp..." - exec -ignorestderr cp ./redis-benchmark /tmp + puts " copy valkey-benchmark from unstable to /tmp..." + exec -ignorestderr cp ./valkey-benchmark /tmp incr branch_id continue } # Start the server - puts " starting the server... [exec ./redis-server -v]" - set pids [exec echo "port $::port\nloglevel warning\n" | ./redis-server - > /dev/null 2> /dev/null &] + puts " starting the server... [exec ./valkey-server -v]" + set pids [exec echo "port $::port\nloglevel warning\n" | ./valkey-server - > /dev/null 2> /dev/null &] puts " pids: $pids" after 1000 puts " running the benchmark" set r [redis 127.0.0.1 $::port] set i [$r info] - puts " redis INFO shows version: [lindex [split $i] 0]" + puts " valkey INFO shows version: [lindex [split $i] 0]" $r close - set output [exec /tmp/redis-benchmark -n $::requests -t $::tests -d $::datasize --csv -p $::port] + set output [exec /tmp/valkey-benchmark -n $::requests -t $::tests -d $::datasize --csv -p $::port] lappend runs $b $output puts " killing server..." catch {exec kill -9 [lindex $pids 0]} From 2778f3b7ef223959c1cd13dcc3854f80a6f8862d Mon Sep 17 00:00:00 2001 From: PatrickJS Date: Wed, 24 Apr 2024 13:40:30 -0700 Subject: [PATCH 06/25] Update COPYING to Valkey (#32) Add License Copyright description for Valkey contributors in COPYING --------- Signed-off-by: PatrickJS Signed-off-by: Madelyn Olson <34459052+madolson@users.noreply.github.com> Co-authored-by: Madelyn Olson <34459052+madolson@users.noreply.github.com> Co-authored-by: Madelyn Olson Signed-off-by: Sher Sun --- COPYING | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/COPYING b/COPYING index a381681a1c..10928babb3 100644 --- a/COPYING +++ b/COPYING @@ -1,3 +1,18 @@ +# License 1 + +Copyright (c) 2024-present, Valkey contributors +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# License 2 + Copyright (c) 2006-2020, Salvatore Sanfilippo All rights reserved. From 9fc71a382873ac20d4ddf5d0a3137b18a9be779b Mon Sep 17 00:00:00 2001 From: Wen Hui Date: Wed, 24 Apr 2024 22:34:37 -0400 Subject: [PATCH 07/25] Update redis* to valkey* in syscheck.c (#365) Fixes #352 Signed-off-by: hwware Signed-off-by: Sher Sun --- src/syscheck.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/syscheck.c b/src/syscheck.c index 008e28bbff..90689ba36c 100644 --- a/src/syscheck.c +++ b/src/syscheck.c @@ -127,7 +127,7 @@ int checkXenClocksource(sds *error_msg) { } else if (strcmp(curr, "xen") == 0) { *error_msg = sdsnew( "Your system is configured to use the 'xen' clocksource which might lead to degraded performance. " - "Check the result of the [slow-clocksource] system check: run 'redis-server --check-system' to check if " + "Check the result of the [slow-clocksource] system check: run 'valkey-server --check-system' to check if " "the system's clocksource isn't degrading performance."); res = -1; } @@ -180,10 +180,10 @@ int checkTHPEnabled(sds *error_msg) { if (strstr(buf,"[always]") != NULL) { *error_msg = sdsnew( "You have Transparent Huge Pages (THP) support enabled in your kernel. " - "This will create latency and memory usage issues with Redis. " + "This will create latency and memory usage issues with Valkey. " "To fix this issue run the command 'echo madvise > /sys/kernel/mm/transparent_hugepage/enabled' as root, " "and add it to your /etc/rc.local in order to retain the setting after a reboot. " - "Redis must be restarted after THP is disabled (set to 'madvise' or 'never')."); + "Valkey must be restarted after THP is disabled (set to 'madvise' or 'never')."); return -1; } else { return 1; From 08684dabf58bce3c5090e6e82ecf09fed3f15e30 Mon Sep 17 00:00:00 2001 From: artikell <739609084@qq.com> Date: Thu, 25 Apr 2024 10:35:12 +0800 Subject: [PATCH 08/25] Update redis* to valkey* in server.c and module.c (#367) it's a supplementary modification from #352. Signed-off-by: artikell <739609084@qq.com> Signed-off-by: Sher Sun --- src/dict.c | 2 +- src/kvstore.c | 2 +- src/server.c | 2 +- src/tls.c | 2 +- src/ziplist.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dict.c b/src/dict.c index e3ba5189cd..8a9227629c 100644 --- a/src/dict.c +++ b/src/dict.c @@ -1809,7 +1809,7 @@ dictType BenchmarkDictType = { printf(msg ": %ld items in %lld ms\n", count, elapsed); \ } while(0) -/* ./redis-server test dict [ | --accurate] */ +/* ./valkey-server test dict [ | --accurate] */ int dictTest(int argc, char **argv, int flags) { long j; long long start, elapsed; diff --git a/src/kvstore.c b/src/kvstore.c index b3b166a0aa..2f954157b3 100644 --- a/src/kvstore.c +++ b/src/kvstore.c @@ -903,7 +903,7 @@ char *stringFromInt(int value) { return s; } -/* ./redis-server test kvstore */ +/* ./valkey-server test kvstore */ int kvstoreTest(int argc, char **argv, int flags) { UNUSED(argc); UNUSED(argv); diff --git a/src/server.c b/src/server.c index 3fbbd8cead..0864ec7d4c 100644 --- a/src/server.c +++ b/src/server.c @@ -7052,7 +7052,7 @@ int main(int argc, char **argv) { exit(0); } else { fprintf(stderr,"Please specify the amount of memory to test in megabytes.\n"); - fprintf(stderr,"Example: ./redis-server --test-memory 4096\n\n"); + fprintf(stderr,"Example: ./valkey-server --test-memory 4096\n\n"); exit(1); } } if (strcmp(argv[1], "--check-system") == 0) { diff --git a/src/tls.c b/src/tls.c index ad35ca2c2f..956b4b67c3 100644 --- a/src/tls.c +++ b/src/tls.c @@ -1177,7 +1177,7 @@ int ValkeyModule_OnLoad(void *ctx, ValkeyModuleString **argv, int argc) { /* Connection modules must be part of the same build as the server. */ if (strcmp(REDIS_BUILD_ID_RAW, serverBuildIdRaw())) { - serverLog(LL_NOTICE, "Connection type %s was not built together with the redis-server used.", CONN_TYPE_TLS); + serverLog(LL_NOTICE, "Connection type %s was not built together with the valkey-server used.", CONN_TYPE_TLS); return VALKEYMODULE_ERR; } diff --git a/src/ziplist.c b/src/ziplist.c index 677fe44233..413b7a8d25 100644 --- a/src/ziplist.c +++ b/src/ziplist.c @@ -1845,7 +1845,7 @@ static size_t strEntryBytesLarge(size_t slen) { return slen + zipStorePrevEntryLength(NULL, ZIP_BIG_PREVLEN) + zipStoreEntryEncoding(NULL, 0, slen); } -/* ./redis-server test ziplist */ +/* ./valkey-server test ziplist */ int ziplistTest(int argc, char **argv, int flags) { int accurate = (flags & TEST_ACCURATE); unsigned char *zl, *p; From f144dc01b4f1bf41fcd3f20ac2cc7ec11076b93c Mon Sep 17 00:00:00 2001 From: Shivshankar Date: Thu, 25 Apr 2024 03:13:21 -0400 Subject: [PATCH 09/25] Rename redis to valkey in test suite logs and test names. (#366) This PR covers below cases. 1. test suite's prints(i.e., puts statement logs). 2. Links refering to redis issues. 3. test names contains redis. Signed-off-by: Shivshankar-Reddy Signed-off-by: Sher Sun --- tests/instances.tcl | 20 ++++++++++---------- tests/integration/valkey-cli.tcl | 2 +- tests/sentinel/tests/00-base.tcl | 2 +- tests/sentinel/tests/02-slaves-reconf.tcl | 2 +- tests/sentinel/tests/05-manual.tcl | 2 +- tests/sentinel/tests/12-master-reboot.tcl | 2 +- tests/support/cluster.tcl | 4 ++-- tests/support/server.tcl | 2 +- tests/support/test.tcl | 2 +- tests/support/valkey.tcl | 2 +- tests/unit/expire.tcl | 2 +- tests/unit/geo.tcl | 4 ++-- tests/unit/introspection-2.tcl | 2 +- tests/unit/introspection.tcl | 6 +++--- tests/unit/maxmemory.tcl | 2 +- tests/unit/moduleapi/moduleauth.tcl | 2 +- tests/unit/other.tcl | 6 +++--- tests/unit/printver.tcl | 2 +- tests/unit/protocol.tcl | 2 +- tests/unit/pubsub.tcl | 2 +- tests/unit/scripting.tcl | 2 +- 21 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tests/instances.tcl b/tests/instances.tcl index baeaddfe2e..5b90a60093 100644 --- a/tests/instances.tcl +++ b/tests/instances.tcl @@ -40,7 +40,7 @@ set ::loop 0 if {[catch {cd tmp}]} { puts "tmp directory not found." - puts "Please run this test from the Redis source root." + puts "Please run this test from the Valkey source root." exit 1 } @@ -313,7 +313,7 @@ proc parse_options {} { puts "--fail Simulate a test failure." puts "--valgrind Run with valgrind." puts "--tls Run tests in TLS mode." - puts "--tls-module Run tests in TLS mode with Redis module." + puts "--tls-module Run tests in TLS mode with Valkey module." puts "--host Use hostname instead of 127.0.0.1." puts "--config Extra config argument(s)." puts "--stop Blocks once the first test fails." @@ -342,12 +342,12 @@ proc pause_on_error {} { set cmd [lindex $argv 0] if {$cmd eq {continue}} { break - } elseif {$cmd eq {show-redis-logs}} { + } elseif {$cmd eq {show-valkey-logs}} { set count 10 if {[lindex $argv 1] ne {}} {set count [lindex $argv 1]} foreach_valkey_id id { - puts "=== REDIS $id ====" - puts [exec tail -$count redis_$id/log.txt] + puts "=== VALKEY $id ====" + puts [exec tail -$count valkey_$id/log.txt] puts "---------------------\n" } } elseif {$cmd eq {show-sentinel-logs}} { @@ -360,7 +360,7 @@ proc pause_on_error {} { } } elseif {$cmd eq {ls}} { foreach_valkey_id id { - puts -nonewline "Redis $id" + puts -nonewline "Valkey $id" set errcode [catch { set str {} append str "@[RI $id tcp_port]: " @@ -391,13 +391,13 @@ proc pause_on_error {} { } } } elseif {$cmd eq {help}} { - puts "ls List Sentinel and Redis instances." + puts "ls List Sentinel and Valkey instances." puts "show-sentinel-logs \[N\] Show latest N lines of logs." - puts "show-redis-logs \[N\] Show latest N lines of logs." + puts "show-valkey-logs \[N\] Show latest N lines of logs." puts "S cmd ... arg Call command in Sentinel ." - puts "R cmd ... arg Call command in Redis ." + puts "R cmd ... arg Call command in Valkey ." puts "SI Show Sentinel INFO ." - puts "RI Show Redis INFO ." + puts "RI Show Valkey INFO ." puts "continue Resume test." } else { set errcode [catch {eval $line} retval] diff --git a/tests/integration/valkey-cli.tcl b/tests/integration/valkey-cli.tcl index 04b91caf80..066a70a6a8 100644 --- a/tests/integration/valkey-cli.tcl +++ b/tests/integration/valkey-cli.tcl @@ -375,7 +375,7 @@ if {!$::tls} { ;# fake_redis_node doesn't support TLS [catch {close [socket "127.0.0.1" $port1]}] == 0 && \ [catch {close [socket "127.0.0.1" $port2]}] == 0 } else { - fail "Failed to start fake Redis nodes" + fail "Failed to start fake Valkey nodes" } # Run the cli assert_equal "OK" [run_cli_host_port_db "127.0.0.1" $port1 0 -c SET foo bar] diff --git a/tests/sentinel/tests/00-base.tcl b/tests/sentinel/tests/00-base.tcl index 274a84316a..ee88469ec3 100644 --- a/tests/sentinel/tests/00-base.tcl +++ b/tests/sentinel/tests/00-base.tcl @@ -104,7 +104,7 @@ test "All the other slaves now point to the new master" { wait_for_condition 1000 50 { [RI $id master_port] == [lindex $addr 1] } else { - fail "Redis ID $id not configured to replicate with new master" + fail "Valkey ID $id not configured to replicate with new master" } } } diff --git a/tests/sentinel/tests/02-slaves-reconf.tcl b/tests/sentinel/tests/02-slaves-reconf.tcl index 5bbd80feca..32e18d0eb2 100644 --- a/tests/sentinel/tests/02-slaves-reconf.tcl +++ b/tests/sentinel/tests/02-slaves-reconf.tcl @@ -18,7 +18,7 @@ proc 02_test_slaves_replication {} { ([RI $id master_port] == $master_port) && ([RI $id master_link_status] eq {up}) } else { - fail "Redis slave $id is replicating from wrong master" + fail "Valkey slave $id is replicating from wrong master" } } } diff --git a/tests/sentinel/tests/05-manual.tcl b/tests/sentinel/tests/05-manual.tcl index f3cfb1e3a2..1834085645 100644 --- a/tests/sentinel/tests/05-manual.tcl +++ b/tests/sentinel/tests/05-manual.tcl @@ -48,7 +48,7 @@ test "All the other slaves now point to the new master" { wait_for_condition 1000 50 { [RI $id master_port] == [lindex $addr 1] } else { - fail "Redis ID $id not configured to replicate with new master" + fail "Valkey ID $id not configured to replicate with new master" } } } diff --git a/tests/sentinel/tests/12-master-reboot.tcl b/tests/sentinel/tests/12-master-reboot.tcl index df6ff49b7c..ad536f7e37 100644 --- a/tests/sentinel/tests/12-master-reboot.tcl +++ b/tests/sentinel/tests/12-master-reboot.tcl @@ -88,7 +88,7 @@ test "All the other slaves now point to the new master" { wait_for_condition 1000 50 { [RI $id master_port] == [lindex $addr 1] } else { - fail "Redis ID $id not configured to replicate with new master" + fail "Valkey ID $id not configured to replicate with new master" } } } diff --git a/tests/support/cluster.tcl b/tests/support/cluster.tcl index 5027bacb78..2b9e44f64f 100644 --- a/tests/support/cluster.tcl +++ b/tests/support/cluster.tcl @@ -201,7 +201,7 @@ proc ::valkey_cluster::__dispatch__ {id method args} { # Get the keys from the command. set keys [::valkey_cluster::get_keys_from_command $method $args] if {$keys eq {}} { - error "Redis command '$method' is not supported by valkey_cluster." + error "Valkey command '$method' is not supported by valkey_cluster." } # Resolve the keys in the corresponding hash slot they hash to. @@ -250,7 +250,7 @@ proc ::valkey_cluster::__dispatch__ {id method args} { return $e } } - error "Too many redirections or failures contacting Redis Cluster." + error "Too many redirections or failures contacting Valkey Cluster." } else { uplevel 1 [list ::valkey_cluster::__method__$method $id] $args } diff --git a/tests/support/server.tcl b/tests/support/server.tcl index 813f240bf1..ddcdbcddbc 100644 --- a/tests/support/server.tcl +++ b/tests/support/server.tcl @@ -4,7 +4,7 @@ set ::valgrind_errors {} proc start_server_error {config_file error} { set err {} - append err "Can't start the Redis server\n" + append err "Can't start the Valkey server\n" append err "CONFIGURATION:\n" append err [exec cat $config_file] append err "\nERROR:\n" diff --git a/tests/support/test.tcl b/tests/support/test.tcl index 3f2200b114..9c959d9de7 100644 --- a/tests/support/test.tcl +++ b/tests/support/test.tcl @@ -258,7 +258,7 @@ proc test {name code {okpattern undefined} {tags {}}} { } if {$::traceleaks} { - set output [exec leaks redis-server] + set output [exec leaks valkey-server] if {![string match {*0 leaks*} $output]} { send_data_packet $::test_server_fd err "Detected a memory leak in test '$name': $output" } diff --git a/tests/support/valkey.tcl b/tests/support/valkey.tcl index 9797fc0147..6f8727ace8 100644 --- a/tests/support/valkey.tcl +++ b/tests/support/valkey.tcl @@ -19,7 +19,7 @@ # } # } # -# set r [redis] +# set r [valkey] # $r blocking 0 # $r get fo [list handlePong] # diff --git a/tests/unit/expire.tcl b/tests/unit/expire.tcl index e34686a4eb..ff97a475e5 100644 --- a/tests/unit/expire.tcl +++ b/tests/unit/expire.tcl @@ -455,7 +455,7 @@ start_server {tags {"expire"}} { # to replication lag. # 2) We want to unify the way TTLs are replicated in both RDB and replication # stream, which is as absolute timestamps. - # See: https://github.com/redis/redis/issues/8433 + # See Redis OSS issue: https://github.com/redis/redis/issues/8433 r flushall ; # Clean up keyspace to avoid interference by keys from other tests set repl [attach_to_replication_stream] diff --git a/tests/unit/geo.tcl b/tests/unit/geo.tcl index 19af863993..1e87e1eb47 100644 --- a/tests/unit/geo.tcl +++ b/tests/unit/geo.tcl @@ -656,7 +656,7 @@ start_server {tags {"geo"}} { if {$res != $res2} { set diff [compare_lists $res $res2] puts "*** Possible problem in GEO radius query ***" - puts "Redis: $res" + puts "Valkey: $res" puts "Tcl : $res2" puts "Diff : $diff" puts [join $debuginfo "\n"] @@ -664,7 +664,7 @@ start_server {tags {"geo"}} { if {[lsearch -exact $res2 $place] != -1} { set where "(only in Tcl)" } else { - set where "(only in Redis)" + set where "(only in Valkey)" } lassign [lindex [r geopos mypoints $place] 0] lon lat set mydist [geo_distance $lon $lat $search_lon $search_lat] diff --git a/tests/unit/introspection-2.tcl b/tests/unit/introspection-2.tcl index 89cb4b122c..b8f4e0aed4 100644 --- a/tests/unit/introspection-2.tcl +++ b/tests/unit/introspection-2.tcl @@ -118,7 +118,7 @@ start_server {tags {"introspection"}} { assert_match {*calls=1,*} [cmdstat geoadd] } {} {needs:config-resetstat} - test {COMMAND COUNT get total number of Redis commands} { + test {COMMAND COUNT get total number of commands} { assert_morethan [r command count] 0 } diff --git a/tests/unit/introspection.tcl b/tests/unit/introspection.tcl index 78ae945dd4..582a019d2d 100644 --- a/tests/unit/introspection.tcl +++ b/tests/unit/introspection.tcl @@ -1,8 +1,8 @@ start_server {tags {"introspection"}} { test "PING" { assert_equal {PONG} [r ping] - assert_equal {redis} [r ping redis] - assert_error {*wrong number of arguments for 'ping' command} {r ping hello redis} + assert_equal {valkey} [r ping valkey] + assert_error {*wrong number of arguments for 'ping' command} {r ping hello valkey} } test {CLIENT LIST} { @@ -739,7 +739,7 @@ start_server {tags {"introspection"}} { catch {exec src/valkey-server --shutdown-on-sigint "now force" --shutdown-on-sigterm} err assert_match {*'shutdown-on-sigterm'*argument(s) must be one of the following*} $err - # Something like `redis-server --some-config --config-value1 --config-value2 --loglevel debug` would break, + # Something like `valkey-server --some-config --config-value1 --config-value2 --loglevel debug` would break, # because if you want to pass a value to a config starting with `--`, it can only be a single value. catch {exec src/valkey-server --replicaof 127.0.0.1 abc} err assert_match {*'replicaof "127.0.0.1" "abc"'*Invalid master port*} $err diff --git a/tests/unit/maxmemory.tcl b/tests/unit/maxmemory.tcl index 19b05cc9cb..92e68ac1ed 100644 --- a/tests/unit/maxmemory.tcl +++ b/tests/unit/maxmemory.tcl @@ -225,7 +225,7 @@ start_server {tags {"maxmemory external:skip"}} { } # If we add the same number of keys already added again and # the policy is allkeys-* we should still be under the limit. - # Otherwise we should see an error reported by Redis. + # Otherwise we should see an error reported by Server. set err 0 for {set j 0} {$j < $numkeys} {incr j} { if {[catch {r set [randomKey] x} e]} { diff --git a/tests/unit/moduleapi/moduleauth.tcl b/tests/unit/moduleapi/moduleauth.tcl index d7399d0ff1..745285312b 100644 --- a/tests/unit/moduleapi/moduleauth.tcl +++ b/tests/unit/moduleapi/moduleauth.tcl @@ -286,7 +286,7 @@ start_server {tags {"modules"}} { assert_match {*calls=2,*,rejected_calls=0,failed_calls=1} [cmdstat auth] } - test {Disabling Redis User during blocking module auth} { + test {Disabling Valkey User during blocking module auth} { r config resetstat r acl setuser foo >pwd on ~* &* +@all set rd [valkey_deferring_client] diff --git a/tests/unit/other.tcl b/tests/unit/other.tcl index 72781838d5..503ee391a9 100644 --- a/tests/unit/other.tcl +++ b/tests/unit/other.tcl @@ -466,7 +466,7 @@ start_server {tags {"other external:skip"}} { start_cluster 1 0 {tags {"other external:skip cluster slow"}} { r config set dynamic-hz no hz 500 - test "Redis can trigger resizing" { + test "Server can trigger resizing" { r flushall # hashslot(foo) is 12182 for {set j 1} {$j <= 128} {incr j} { @@ -496,7 +496,7 @@ start_cluster 1 0 {tags {"other external:skip cluster slow"}} { } } {} {needs:debug} - test "Redis can rewind and trigger smaller slot resizing" { + test "Server can rewind and trigger smaller slot resizing" { # hashslot(foo) is 12182 # hashslot(alice) is 749, smaller than hashslot(foo), # attempt to trigger a resize on it, see details in #12802. @@ -526,7 +526,7 @@ start_cluster 1 0 {tags {"other external:skip cluster slow"}} { } start_server {tags {"other external:skip"}} { - test "Redis can resize empty dict" { + test "Server can resize empty dict" { # Write and then delete 128 keys, creating an empty dict r flushall for {set j 1} {$j <= 128} {incr j} { diff --git a/tests/unit/printver.tcl b/tests/unit/printver.tcl index c80f45144d..53cfed8ee6 100644 --- a/tests/unit/printver.tcl +++ b/tests/unit/printver.tcl @@ -2,5 +2,5 @@ start_server {} { set i [r info] regexp {redis_version:(.*?)\r\n} $i - version regexp {redis_git_sha1:(.*?)\r\n} $i - sha1 - puts "Testing Redis version $version ($sha1)" + puts "Testing Valkey version $version ($sha1)" } diff --git a/tests/unit/protocol.tcl b/tests/unit/protocol.tcl index cd7dbe9e5a..f3a2b8e1a8 100644 --- a/tests/unit/protocol.tcl +++ b/tests/unit/protocol.tcl @@ -94,7 +94,7 @@ start_server {tags {"protocol network"}} { set elapsed [expr {[clock seconds]-$test_start}] if {$elapsed > $test_time_limit} { close $s - error "assertion:Redis did not closed connection after protocol desync" + error "assertion:Valkey did not closed connection after protocol desync" } } } diff --git a/tests/unit/pubsub.tcl b/tests/unit/pubsub.tcl index 5a2439814f..2f336dfcb9 100644 --- a/tests/unit/pubsub.tcl +++ b/tests/unit/pubsub.tcl @@ -483,7 +483,7 @@ start_server {tags {"pubsub network"}} { r hello 3 # Note: SUBSCRIBE and UNSUBSCRIBE with multiple channels in the same command, - # breaks the multi response, see https://github.com/redis/redis/issues/12207 + # breaks the multi response, see Redis OSS issue: https://github.com/redis/redis/issues/12207 # this is just a temporary sanity test to detect unintended breakage. # subscribe for 3 channels actually emits 3 "responses" diff --git a/tests/unit/scripting.tcl b/tests/unit/scripting.tcl index 126f4eba4a..ea5c1b899f 100644 --- a/tests/unit/scripting.tcl +++ b/tests/unit/scripting.tcl @@ -1055,7 +1055,7 @@ start_server {tags {"scripting"}} { test "Try trick global protection 3" { catch { run_script { - valkey = function() return 1 end + redis = function() return 1 end } 0 } e set _ $e From 345e7a697c8712b9dd2642252d6c11cd7d14c304 Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Thu, 25 Apr 2024 22:20:40 +0800 Subject: [PATCH 10/25] Detect accept4() on specific versions of various platforms (#294) This PR has mainly done three things: 1. Enable `accept4()` on DragonFlyBSD 2. Fix the failures of determining the presence of `accept4()` due to the missing on two OSs: NetBSD, OpenBSD 3. Drop the support of FreeBSD < 10.0 for `valkey` ### References - [param.h in DragonFlyBSD](https://github.com/DragonFlyBSD/DragonFlyBSD/blob/7485684fa5c3fadb6c7a1da0d8bb6ea5da4e0f2f/sys/sys/param.h#L129-L257) - [param.h in FreeBSD](https://github.com/freebsd/freebsd-src/blob/main/sys/sys/param.h#L46-L76) - [param.h in NetBSD](https://github.com/NetBSD/src/blob/b5f8d2f930b7ef226d4dc1b4f7017e998c0e5cde/sys/sys/param.h#L53-L70) - [param.h in OpenBSD](https://github.com/openbsd/src/blob/d9c286e032a7cee9baaecdd54eb0d43f658ae696/sys/sys/param.h#L40-L45) --------- Signed-off-by: Andy Pan Signed-off-by: Sher Sun --- src/config.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/config.h b/src/config.h index dd741ac7ae..ff37991558 100644 --- a/src/config.h +++ b/src/config.h @@ -30,6 +30,8 @@ #ifndef CONFIG_H #define CONFIG_H +#include + #ifdef __APPLE__ #include // for fcntl(fd, F_FULLFSYNC) #include @@ -96,9 +98,11 @@ #endif /* Test for accept4() */ -#if defined(__linux__) || defined(OpenBSD5_7) || \ - (__FreeBSD__ >= 10 || __FreeBSD_version >= 1000000) || \ - (defined(NetBSD8_0) || __NetBSD_Version__ >= 800000000) +#if defined(__linux__) || \ + defined(__FreeBSD__) || \ + defined(OpenBSD5_7) || \ + (defined(__DragonFly__) && __DragonFly_version >= 400305) || \ + (defined(__NetBSD__) && (defined(NetBSD8_0) || __NetBSD_Version__ >= 800000000)) #define HAVE_ACCEPT4 1 #endif @@ -316,7 +320,7 @@ void setcpuaffinity(const char *cpulist); #endif /* Test for posix_fadvise() */ -#if defined(__linux__) || __FreeBSD__ >= 10 +#if defined(__linux__) || defined(__FreeBSD__) #define HAVE_FADVISE #endif From 9f938232f9e4265f5d96155baeb6af0ef7ee569d Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Fri, 26 Apr 2024 17:33:53 +0000 Subject: [PATCH 11/25] Remove the option for vendored mimalloc Signed-off-by: Sher Sun --- deps/mimalloc | 1 - src/Makefile | 13 +++---------- 2 files changed, 3 insertions(+), 11 deletions(-) delete mode 160000 deps/mimalloc diff --git a/deps/mimalloc b/deps/mimalloc deleted file mode 160000 index 77eb3a366b..0000000000 --- a/deps/mimalloc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 77eb3a366b0355a0a90e2a0a8b6ac03757b4a1f6 diff --git a/src/Makefile b/src/Makefile index 8891e276c1..c3b5813493 100644 --- a/src/Makefile +++ b/src/Makefile @@ -290,16 +290,9 @@ ifeq ($(MALLOC),jemalloc) endif ifeq ($(MALLOC),mimalloc) -ifeq ($(USE_SYSTEM_MIMALLOC),yes) - FINAL_CFLAGS+= -DUSE_JEMALLOC $(shell $(PKG_CONFIG) --cflags mimalloc) - FINAL_LIBS := $(shell $(PKG_CONFIG) --libs mimalloc) $(FINAL_LIBS) -else - DEPENDENCY_TARGETS+= mimalloc - MIMALLOC_DIR= ../deps/mimalloc - MIMALLOC_LIB= $(MIMALLOC_DIR)/out/release/libmimalloc.a - FINAL_CFLAGS+= -DUSE_MIMALLOC -I$(MIMALLOC_DIR)/include - FINAL_LIBS := $(MIMALLOC_LIB) $(FINAL_LIBS) -endif + FINAL_CFLAGS+= -DUSE_MIMALLOC -I/usr/local/include + FINAL_LDFLAGS+= -L/usr/local/lib + FINAL_LIBS := -lmimalloc $(FINAL_LIBS) endif From c4b890ae3d58eaef738f17033c8f09740abd15ff Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Fri, 26 Apr 2024 17:35:44 +0000 Subject: [PATCH 12/25] remove mimalloc submodule Signed-off-by: Sher Sun --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 2b3ffa4080..e69de29bb2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +0,0 @@ -[submodule "deps/mimalloc"] - path = deps/mimalloc - url = https://github.com/microsoft/mimalloc.git From 4a39d8c8c127517ba4b7e526a69fa1f3c534df9d Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Fri, 26 Apr 2024 17:46:05 +0000 Subject: [PATCH 13/25] remove changes in the deps/Makefile Signed-off-by: Sher Sun --- deps/Makefile | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/deps/Makefile b/deps/Makefile index eadd555a7b..67b7d41026 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -12,10 +12,6 @@ BINCOLOR="\033[37;1m" MAKECOLOR="\033[32;1m" ENDCOLOR="\033[0m" -MIMALLOC_DIR := mimalloc -MIMALLOC_BUILD_DIR := $(MIMALLOC_DIR)/out/release -MIMALLOC_LIB := $(MIMALLOC_BUILD_DIR)/libmimalloc.a - default: @echo "Explicit target required" @@ -46,7 +42,6 @@ distclean: -(cd jemalloc && [ -f Makefile ] && $(MAKE) distclean) > /dev/null || true -(cd hdr_histogram && $(MAKE) clean) > /dev/null || true -(cd fpconv && $(MAKE) clean) > /dev/null || true - -rm -rf $(MIMALLOC_BUILD_DIR) -(rm -f .make-*) .PHONY: distclean @@ -121,11 +116,3 @@ jemalloc: .make-prerequisites cd jemalloc && $(MAKE) lib/libjemalloc.a .PHONY: jemalloc - -.PHONY: mimalloc - -mimalloc: .make-prerequisites - @printf '%b %b\n' $(MAKECOLOR)MAKE$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) - @[ -d $(MIMALLOC_BUILD_DIR) ] || mkdir -p $(MIMALLOC_BUILD_DIR) - cd $(MIMALLOC_BUILD_DIR) && cmake ../.. -DCMAKE_BUILD_TYPE=Release - $(MAKE) -C $(MIMALLOC_BUILD_DIR) \ No newline at end of file From 658aec361823e5fd1b96aa64cfd318a51af508d5 Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Fri, 26 Apr 2024 17:47:33 +0000 Subject: [PATCH 14/25] remove USE_SYSTEM_MIMALLOC option Signed-off-by: Sher Sun --- src/Makefile | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 3e97e4bcea..36e45fcd42 100644 --- a/src/Makefile +++ b/src/Makefile @@ -421,7 +421,6 @@ persist-settings: distclean echo WARN=$(WARN) >> .make-settings echo OPT=$(OPT) >> .make-settings echo MALLOC=$(MALLOC) >> .make-settings - echo USE_SYSTEM_MIMALLOC=$(USE_SYSTEM_MIMALLOC) >> .make-settings echo BUILD_TLS=$(BUILD_TLS) >> .make-settings echo USE_SYSTEMD=$(USE_SYSTEMD) >> .make-settings echo CFLAGS=$(CFLAGS) >> .make-settings From f16f92f1ad7da42b50827c3356be9a6273ad5ab6 Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Fri, 26 Apr 2024 19:22:19 +0000 Subject: [PATCH 15/25] Explicitly override malloc/free etc when using mimalloc Signed-off-by: Sher Sun --- src/zmalloc.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/zmalloc.c b/src/zmalloc.c index 550752240f..d1ab8969bc 100644 --- a/src/zmalloc.c +++ b/src/zmalloc.c @@ -85,6 +85,12 @@ void zlibc_free(void *ptr) { #define free(ptr) je_free(ptr) #define mallocx(size,flags) je_mallocx(size,flags) #define dallocx(ptr,flags) je_dallocx(ptr,flags) +/* Explicitly override malloc/free etc when using mimalloc. */ +#elif defined(USE_MIMALLOC) +#define malloc(size) mi_malloc(size) +#define calloc(count,size) mi_calloc(count,size) +#define realloc(ptr,size) mi_realloc(ptr,size) +#define free(ptr) mi_free(ptr) #endif #define update_zmalloc_stat_alloc(__n) atomicIncr(used_memory,(__n)) From 32d07dd205c4a8e71144fa20ba33305f580d9b22 Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Mon, 29 Apr 2024 14:54:11 +0000 Subject: [PATCH 16/25] update the README.md with mimalloc install instructions and zmalloc.h Signed-off-by: Sher Sun --- .gitmodules | 0 README.md | 19 +++++++++++++++++++ src/zmalloc.h | 11 ++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/README.md b/README.md index b958a90b61..99e4f6846f 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,25 @@ If you want to see a more verbose output, use the following: % make V=1 +Using mimalloc with Valkey +------------- + +[mimalloc](https://github.com/microsoft/mimalloc) is an advanced memory allocator that can improve the performance of applications. You can optionally build Valkey using mimalloc by following these steps: + +Before building Valkey with mimalloc, you need to install mimalloc on your system. + + % git clone https://github.com/microsoft/mimalloc.git + % mkdir -p mimalloc/out/release + % cd mimalloc/out/release + % cmake ../.. -DMI_INSTALL_TOPLEVEL=ON + % sudo make install + +This will install mimalloc libraries and headers in /usr/local/lib and /usr/local/include. + +Build Valkey with mimalloc: + + % make MALLOC=mimalloc + Running Valkey ------------- diff --git a/src/zmalloc.h b/src/zmalloc.h index ee0eed6a33..518f06e564 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -34,9 +34,7 @@ /* Double expansion needed for stringification of macro values. */ #define __xstr(s) __str(s) #define __str(s) #s -#define MI_VERSION_MAJOR 1 -#define MI_VERSION_MINOR 8 -#define MI_VERSION_PATCH 5 +#define __str_version(s) __xstr(s) #if defined(USE_TCMALLOC) #define ZMALLOC_LIB ("tcmalloc-" __xstr(TC_VERSION_MAJOR) "." __xstr(TC_VERSION_MINOR)) @@ -59,9 +57,12 @@ #endif #elif defined(USE_MIMALLOC) -#define ZMALLOC_LIB ("mimalloc-" __xstr(MI_VERSION_MAJOR) "." __xstr(MI_VERSION_MINOR) "." __xstr(MI_VERSION_PATCH)) #include -#if (MI_VERSION_MAJOR == 1 && MI_VERSION_MINOR >= 8) || (MI_VERSION_MAJOR > 1) +#define ZMALLOC_LIB ("mimalloc-" __xstr(MI_MALLOC_VERSION)) +#define MI_VERSION_MAJOR (MI_MALLOC_VERSION / 100) +#define MI_VERSION_MINOR ((MI_MALLOC_VERSION / 10) % 10) +#define MI_VERSION_PATCH (MI_MALLOC_VERSION % 10) +#if (MI_VERSION_MAJOR == 1 && MI_VERSION_MINOR >= 8) || (MI_VERSION_PATCH > 1) #define HAVE_MALLOC_SIZE 1 #define zmalloc_size(p) mi_usable_size(p) #else From 1219f1c40bcc36d328aec4e67ae2e0a207ddba1f Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Mon, 29 Apr 2024 15:24:34 +0000 Subject: [PATCH 17/25] remove unused expansion Signed-off-by: Sher Sun --- src/zmalloc.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/zmalloc.h b/src/zmalloc.h index 518f06e564..ca93b1ea92 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -34,7 +34,6 @@ /* Double expansion needed for stringification of macro values. */ #define __xstr(s) __str(s) #define __str(s) #s -#define __str_version(s) __xstr(s) #if defined(USE_TCMALLOC) #define ZMALLOC_LIB ("tcmalloc-" __xstr(TC_VERSION_MAJOR) "." __xstr(TC_VERSION_MINOR)) From 65ef92f9401dfbe8d4d4459b69a4ce462f914a52 Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Mon, 29 Apr 2024 16:01:20 +0000 Subject: [PATCH 18/25] add defrag_supported field to INFO command Signed-off-by: Sher Sun --- src/server.c | 3 ++- src/zmalloc.h | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/server.c b/src/server.c index 02191da785..3c7fbcd111 100644 --- a/src/server.c +++ b/src/server.c @@ -5757,7 +5757,8 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) { "mem_overhead_db_hashtable_rehashing:%zu\r\n", mh->overhead_db_hashtable_rehashing, "active_defrag_running:%d\r\n", server.active_defrag_running, "lazyfree_pending_objects:%zu\r\n", lazyfreeGetPendingObjectsCount(), - "lazyfreed_objects:%zu\r\n", lazyfreeGetFreedObjectsCount())); + "lazyfreed_objects:%zu\r\n", lazyfreeGetFreedObjectsCount(), + "defrag_supported: %s\r\n", defrag_supported)); freeMemoryOverheadData(mh); } diff --git a/src/zmalloc.h b/src/zmalloc.h index ca93b1ea92..f05c13ae3f 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -37,6 +37,7 @@ #if defined(USE_TCMALLOC) #define ZMALLOC_LIB ("tcmalloc-" __xstr(TC_VERSION_MAJOR) "." __xstr(TC_VERSION_MINOR)) +#define defrag_supported "no" #include #if (TC_VERSION_MAJOR == 1 && TC_VERSION_MINOR >= 6) || (TC_VERSION_MAJOR > 1) #define HAVE_MALLOC_SIZE 1 @@ -47,6 +48,7 @@ #elif defined(USE_JEMALLOC) #define ZMALLOC_LIB ("jemalloc-" __xstr(JEMALLOC_VERSION_MAJOR) "." __xstr(JEMALLOC_VERSION_MINOR) "." __xstr(JEMALLOC_VERSION_BUGFIX)) +#define defrag_supported "yes" #include #if (JEMALLOC_VERSION_MAJOR == 2 && JEMALLOC_VERSION_MINOR >= 1) || (JEMALLOC_VERSION_MAJOR > 2) #define HAVE_MALLOC_SIZE 1 @@ -56,6 +58,7 @@ #endif #elif defined(USE_MIMALLOC) +#define defrag_supported "no" #include #define ZMALLOC_LIB ("mimalloc-" __xstr(MI_MALLOC_VERSION)) #define MI_VERSION_MAJOR (MI_MALLOC_VERSION / 100) From 371641d30a2e48a9b631192ae47e6c6524cb5fda Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Mon, 29 Apr 2024 16:09:35 +0000 Subject: [PATCH 19/25] fix Signed-off-by: Sher Sun --- src/zmalloc.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/zmalloc.h b/src/zmalloc.h index f05c13ae3f..3714abdd93 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -89,6 +89,10 @@ #define ZMALLOC_LIB "libc" #define USE_LIBC 1 +#ifndef defrag_supported +#define defrag_supported "no" +#endif + #if !defined(NO_MALLOC_USABLE_SIZE) && \ (defined(__GLIBC__) || defined(__FreeBSD__) || \ defined(__DragonFly__) || defined(__HAIKU__) || \ From b1431fafaca30fc413817b67c07a146c256c2f2a Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Tue, 30 Apr 2024 17:18:31 +0000 Subject: [PATCH 20/25] remove defrag_supported macro Signed-off-by: Sher Sun --- src/server.c | 8 ++++++-- src/zmalloc.h | 7 ------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/server.c b/src/server.c index 3c7fbcd111..eef241a3bd 100644 --- a/src/server.c +++ b/src/server.c @@ -5757,8 +5757,12 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) { "mem_overhead_db_hashtable_rehashing:%zu\r\n", mh->overhead_db_hashtable_rehashing, "active_defrag_running:%d\r\n", server.active_defrag_running, "lazyfree_pending_objects:%zu\r\n", lazyfreeGetPendingObjectsCount(), - "lazyfreed_objects:%zu\r\n", lazyfreeGetFreedObjectsCount(), - "defrag_supported: %s\r\n", defrag_supported)); +#ifdef USE_JEMALLOC + "defrag_supported: %s\r\n", "yes", +#else + "defrag_supported: %s\r\n", "no", +#endif + "lazyfreed_objects:%zu\r\n", lazyfreeGetFreedObjectsCount())); freeMemoryOverheadData(mh); } diff --git a/src/zmalloc.h b/src/zmalloc.h index 3714abdd93..ca93b1ea92 100644 --- a/src/zmalloc.h +++ b/src/zmalloc.h @@ -37,7 +37,6 @@ #if defined(USE_TCMALLOC) #define ZMALLOC_LIB ("tcmalloc-" __xstr(TC_VERSION_MAJOR) "." __xstr(TC_VERSION_MINOR)) -#define defrag_supported "no" #include #if (TC_VERSION_MAJOR == 1 && TC_VERSION_MINOR >= 6) || (TC_VERSION_MAJOR > 1) #define HAVE_MALLOC_SIZE 1 @@ -48,7 +47,6 @@ #elif defined(USE_JEMALLOC) #define ZMALLOC_LIB ("jemalloc-" __xstr(JEMALLOC_VERSION_MAJOR) "." __xstr(JEMALLOC_VERSION_MINOR) "." __xstr(JEMALLOC_VERSION_BUGFIX)) -#define defrag_supported "yes" #include #if (JEMALLOC_VERSION_MAJOR == 2 && JEMALLOC_VERSION_MINOR >= 1) || (JEMALLOC_VERSION_MAJOR > 2) #define HAVE_MALLOC_SIZE 1 @@ -58,7 +56,6 @@ #endif #elif defined(USE_MIMALLOC) -#define defrag_supported "no" #include #define ZMALLOC_LIB ("mimalloc-" __xstr(MI_MALLOC_VERSION)) #define MI_VERSION_MAJOR (MI_MALLOC_VERSION / 100) @@ -89,10 +86,6 @@ #define ZMALLOC_LIB "libc" #define USE_LIBC 1 -#ifndef defrag_supported -#define defrag_supported "no" -#endif - #if !defined(NO_MALLOC_USABLE_SIZE) && \ (defined(__GLIBC__) || defined(__FreeBSD__) || \ defined(__DragonFly__) || defined(__HAIKU__) || \ From 2f0091066623e39e379eba6dc12079da853ad83c Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Tue, 30 Apr 2024 18:58:20 +0000 Subject: [PATCH 21/25] fix Signed-off-by: Sher Sun --- src/server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server.c b/src/server.c index eef241a3bd..6d4dc46fe4 100644 --- a/src/server.c +++ b/src/server.c @@ -5757,8 +5757,8 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) { "mem_overhead_db_hashtable_rehashing:%zu\r\n", mh->overhead_db_hashtable_rehashing, "active_defrag_running:%d\r\n", server.active_defrag_running, "lazyfree_pending_objects:%zu\r\n", lazyfreeGetPendingObjectsCount(), -#ifdef USE_JEMALLOC - "defrag_supported: %s\r\n", "yes", +#if defined(USE_JEMALLOC) + "defrag_supported: %s\r\n", "yes", #else "defrag_supported: %s\r\n", "no", #endif From c9c37336b5240cfec25fb62759372f01911e7699 Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Tue, 30 Apr 2024 19:25:50 +0000 Subject: [PATCH 22/25] fix2 Signed-off-by: Sher Sun --- src/server.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/server.c b/src/server.c index 6d4dc46fe4..3702b3bc17 100644 --- a/src/server.c +++ b/src/server.c @@ -5682,6 +5682,7 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) { long long memory_lua = evalMemory(); long long memory_functions = functionsMemory(); struct serverMemOverhead *mh = getMemoryOverheadData(); + char mem_allocator[64] = ZMALLOC_LIB; /* Peak memory is updated from time to time by serverCron() so it * may happen that the instantaneous value is slightly bigger than @@ -5757,11 +5758,7 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) { "mem_overhead_db_hashtable_rehashing:%zu\r\n", mh->overhead_db_hashtable_rehashing, "active_defrag_running:%d\r\n", server.active_defrag_running, "lazyfree_pending_objects:%zu\r\n", lazyfreeGetPendingObjectsCount(), -#if defined(USE_JEMALLOC) - "defrag_supported: %s\r\n", "yes", -#else - "defrag_supported: %s\r\n", "no", -#endif + "defrag_supported: %s\r\n", (mem_allocator[0]=='j') ? "yes" : "no", "lazyfreed_objects:%zu\r\n", lazyfreeGetFreedObjectsCount())); freeMemoryOverheadData(mh); } From a594b55ea532be602787147921f6f205bf36f66d Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Tue, 30 Apr 2024 20:10:55 +0000 Subject: [PATCH 23/25] fix Signed-off-by: Sher Sun --- src/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server.c b/src/server.c index 3702b3bc17..0d5280521d 100644 --- a/src/server.c +++ b/src/server.c @@ -5682,7 +5682,7 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) { long long memory_lua = evalMemory(); long long memory_functions = functionsMemory(); struct serverMemOverhead *mh = getMemoryOverheadData(); - char mem_allocator[64] = ZMALLOC_LIB; + unsigned char mem_allocator[64] = ZMALLOC_LIB; /* Peak memory is updated from time to time by serverCron() so it * may happen that the instantaneous value is slightly bigger than From 2466cb4af7f9458dd7cbf507bb91ee57a8fe4517 Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Tue, 30 Apr 2024 20:31:49 +0000 Subject: [PATCH 24/25] fix3 Signed-off-by: Sher Sun --- src/server.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/server.c b/src/server.c index 0d5280521d..6e7f31c5ea 100644 --- a/src/server.c +++ b/src/server.c @@ -5682,8 +5682,11 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) { long long memory_lua = evalMemory(); long long memory_functions = functionsMemory(); struct serverMemOverhead *mh = getMemoryOverheadData(); - unsigned char mem_allocator[64] = ZMALLOC_LIB; - +#if defined(USE_JEMALLOC) + char defrag_supported[] = "yes"; +#else + char defrag_supported[] = "no"; +#endif /* Peak memory is updated from time to time by serverCron() so it * may happen that the instantaneous value is slightly bigger than * the peak value. This may confuse users, so we update the peak @@ -5758,8 +5761,8 @@ sds genRedisInfoString(dict *section_dict, int all_sections, int everything) { "mem_overhead_db_hashtable_rehashing:%zu\r\n", mh->overhead_db_hashtable_rehashing, "active_defrag_running:%d\r\n", server.active_defrag_running, "lazyfree_pending_objects:%zu\r\n", lazyfreeGetPendingObjectsCount(), - "defrag_supported: %s\r\n", (mem_allocator[0]=='j') ? "yes" : "no", - "lazyfreed_objects:%zu\r\n", lazyfreeGetFreedObjectsCount())); + "lazyfreed_objects:%zu\r\n", lazyfreeGetFreedObjectsCount(), + "defrag_supported: %s\r\n", defrag_supported)); freeMemoryOverheadData(mh); } From 1854578ddc4d4a73ea8a1442693969ce8e099265 Mon Sep 17 00:00:00 2001 From: Sher Sun Date: Thu, 2 May 2024 18:09:40 +0000 Subject: [PATCH 25/25] add tcl test for defrag_supported Signed-off-by: Sher Sun --- tests/unit/other.tcl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/unit/other.tcl b/tests/unit/other.tcl index 503ee391a9..5e1f4f511b 100644 --- a/tests/unit/other.tcl +++ b/tests/unit/other.tcl @@ -30,6 +30,13 @@ start_server {tags {"other"}} { } } + test {INFO MEMORY: defrag_supported} { + if {[string match {*jemalloc*} [s mem_allocator]]} { + set info_mem [r info memory] + assert_equal [getInfoProperty $info_mem defrag_supported] { yes} + } + } + test {SAVE - make sure there are all the types as values} { # Wait for a background saving in progress to terminate waitForBgsave r