From 0ed10f08983bde6155ac3145ad265789f8700a4b Mon Sep 17 00:00:00 2001 From: chejinge Date: Sun, 7 Apr 2024 16:29:52 +0800 Subject: [PATCH] fix:compact dead lock --- conf/pika.conf | 24 +++++++++++++----------- src/pika_command.cc | 4 ++-- tests/integration/server_test.go | 13 ++++++++++++- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/conf/pika.conf b/conf/pika.conf index 5bc7509445..3e4492a762 100644 --- a/conf/pika.conf +++ b/conf/pika.conf @@ -32,7 +32,7 @@ thread-pool-size : 12 slow-cmd-thread-pool-size : 4 # Slow cmd list e.g. hgetall, mset -slow-cmd-list : +slow-cmd-list : # The number of sync-thread for data replication from master, those are the threads work on slave nodes # and are used to execute commands sent from master node when replicating. @@ -51,13 +51,13 @@ db-path : ./db/ # but this will generate heavier IO load when flushing from buffer to disk, # you should configure it based on you usage scenario. # Supported Units [K|M|G], write-buffer-size default unit is in [bytes]. -write-buffer-size : 256M +write-buffer-size : 268435456 # The size of one block in arena memory allocation. # If <= 0, a proper value is automatically calculated. # (usually 1/8 of writer-buffer-size, rounded up to a multiple of 4KB) # Supported Units [K|M|G], arena-block-size default unit is in [bytes]. -arena-block-size : +arena-block-size : 33554432 # Timeout of Pika's connection, counting down starts When there are no requests # on a connection (it enters sleep state), when the countdown reaches 0, the connection @@ -72,12 +72,12 @@ timeout : 60 # the value of userpass will be ignored and all users are considered as administrators, # in this scenario, users are not subject to the restrictions imposed by the userblacklist. # PS: "user password" refers to value of the parameter below: userpass. -requirepass : +requirepass : # Password for replication verify, used for authentication when a slave # connects to a master to request replication. # [NOTICE] The value of this parameter must match the "requirepass" setting on the master. -masterauth : +masterauth : # The [password of user], which is empty by default. # [NOTICE] If this user password is the same as admin password (including both being empty), @@ -116,7 +116,7 @@ consensus-level : 0 # The Prefix of dump file's name. # All the files that generated by command "bgsave" will be name with this prefix. -dump-prefix : +dump-prefix : # daemonize [yes | no]. #daemonize : yes @@ -184,7 +184,7 @@ db-sync-path : ./dbsync/ # [NOTICE] If this parameter is set to an invalid value(smaller than 0 or bigger than 1024), # it will be automatically reset to 1024. # The default value of db-sync-speed is -1 (1024MB/s). -db-sync-speed : -1 +db-sync-speed : 1024 # The priority of slave node when electing new master node. # The slave node with [lower] value of slave-priority will have [higher priority] to be elected as the new master node. @@ -363,7 +363,7 @@ max-bytes-for-level-multiplier : 10 slotmigrate : no # slotmigrate thread num -slotmigrate-thread-num : 8 +slotmigrate-thread-num : 4 # thread-migrate-keys-num 1/8 of the write_buffer_size_ thread-migrate-keys-num : 64 @@ -472,7 +472,7 @@ cache-num : 16 # cache-model 0:cache_none 1:cache_read cache-model : 1 # cache-type: string, set, zset, list, hash, bit -cache-type: string, set, zset, list, hash, bit +cache-type : string,set,zset,list,hash,bit # Maximum number of keys in the zset redis cache # On the disk DB, a zset field may have many fields. In the memory cache, we limit the maximum @@ -503,10 +503,10 @@ cache-maxmemory : 10737418240 cache-maxmemory-policy : 1 # cache-maxmemory-samples -cache-maxmemory-samples: 5 +cache-maxmemory-samples : 5 # cache-lfu-decay-time -cache-lfu-decay-time: 1 +cache-lfu-decay-time : 1 # is possible to manage access to Pub/Sub channels with ACL rules as well. The @@ -554,3 +554,5 @@ cache-lfu-decay-time: 1 # # Example: # rename-command : FLUSHDB 360flushdb +# Generated by CONFIG REWRITE +run-id : 474141572feb8397e5f76e13f32b41a70a202fe6 diff --git a/src/pika_command.cc b/src/pika_command.cc index 6d370735a6..bfe1b418f1 100644 --- a/src/pika_command.cc +++ b/src/pika_command.cc @@ -54,10 +54,10 @@ void InitCmdTable(CmdTable* cmd_table) { cmd_table->insert(std::pair>(kCmdNameBgsave, std::move(bgsaveptr))); std::unique_ptr compactptr = - std::make_unique(kCmdNameCompact, -1, kCmdFlagsRead | kCmdFlagsAdmin | kCmdFlagsSlow); + std::make_unique(kCmdNameCompact, -1, kCmdFlagsRead | kCmdFlagsAdmin | kCmdFlagsSlow | kCmdFlagsSuspend); cmd_table->insert(std::pair>(kCmdNameCompact, std::move(compactptr))); - std::unique_ptr compactrangeptr = std::make_unique(kCmdNameCompactRange, 5, kCmdFlagsRead | kCmdFlagsAdmin); + std::unique_ptr compactrangeptr = std::make_unique(kCmdNameCompactRange, 5, kCmdFlagsRead | kCmdFlagsAdmin | kCmdFlagsSuspend); cmd_table->insert(std::pair>(kCmdNameCompactRange, std::move(compactrangeptr))); std::unique_ptr purgelogsto = std::make_unique(kCmdNamePurgelogsto, -2, kCmdFlagsRead | kCmdFlagsAdmin); diff --git a/tests/integration/server_test.go b/tests/integration/server_test.go index b07b98cc99..fd83919f25 100644 --- a/tests/integration/server_test.go +++ b/tests/integration/server_test.go @@ -9,7 +9,7 @@ import ( "github.com/redis/go-redis/v9" ) -var _ = Describe("Server", func() { +var _ = FDescribe("Server", func() { ctx := context.TODO() var client *redis.Client @@ -708,5 +708,16 @@ var _ = Describe("Server", func() { Expect(client.Exists(ctx, "foo").Val()).To(Equal(int64(0))) }) + It("should Compact", func() { + Expect(client.Set(ctx, "foo", "bar", 0).Val()).To(Equal("OK")) + Expect(client.Set(ctx, "key1", "value1", 0).Val()).To(Equal("OK")) + Expect(client.Expire(ctx, "foo", 2*time.Second).Val()).To(Equal(true)) + Expect(client.Expire(ctx, "key1", 2*time.Second).Val()).To(Equal(true)) + time.Sleep(3 * time.Second) + Expect(client.Do(ctx, "compact").Val()).To(Equal("OK")) + Expect(client.Exists(ctx, "foo").Val()).To(Equal(int64(0))) + Expect(client.Get(ctx, "foo").Err()).To(MatchError(redis.Nil)) + Expect(client.Get(ctx, "key1").Err()).To(MatchError(redis.Nil)) + }) }) })