Skip to content

Commit

Permalink
fix:compact dead lock
Browse files Browse the repository at this point in the history
  • Loading branch information
brother-jin committed Apr 7, 2024
1 parent c5e4546 commit 0ed10f0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
24 changes: 13 additions & 11 deletions conf/pika.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -554,3 +554,5 @@ cache-lfu-decay-time: 1
#
# Example:
# rename-command : FLUSHDB 360flushdb
# Generated by CONFIG REWRITE
run-id : 474141572feb8397e5f76e13f32b41a70a202fe6
4 changes: 2 additions & 2 deletions src/pika_command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void InitCmdTable(CmdTable* cmd_table) {
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNameBgsave, std::move(bgsaveptr)));

std::unique_ptr<Cmd> compactptr =
std::make_unique<CompactCmd>(kCmdNameCompact, -1, kCmdFlagsRead | kCmdFlagsAdmin | kCmdFlagsSlow);
std::make_unique<CompactCmd>(kCmdNameCompact, -1, kCmdFlagsRead | kCmdFlagsAdmin | kCmdFlagsSlow | kCmdFlagsSuspend);
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNameCompact, std::move(compactptr)));

std::unique_ptr<Cmd> compactrangeptr = std::make_unique<CompactRangeCmd>(kCmdNameCompactRange, 5, kCmdFlagsRead | kCmdFlagsAdmin);
std::unique_ptr<Cmd> compactrangeptr = std::make_unique<CompactRangeCmd>(kCmdNameCompactRange, 5, kCmdFlagsRead | kCmdFlagsAdmin | kCmdFlagsSuspend);
cmd_table->insert(std::pair<std::string, std::unique_ptr<Cmd>>(kCmdNameCompactRange, std::move(compactrangeptr)));
std::unique_ptr<Cmd> purgelogsto =
std::make_unique<PurgelogstoCmd>(kCmdNamePurgelogsto, -2, kCmdFlagsRead | kCmdFlagsAdmin);
Expand Down
13 changes: 12 additions & 1 deletion tests/integration/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
})
})
})

0 comments on commit 0ed10f0

Please sign in to comment.