Skip to content

Commit

Permalink
fix:compact dead lock (#2581)
Browse files Browse the repository at this point in the history
* fix:compact dead lock

---------

Co-authored-by: chejinge <chejinge@360.cn>
  • Loading branch information
chejinge and brother-jin committed Apr 8, 2024
1 parent ea82487 commit b5d0b16
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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
11 changes: 11 additions & 0 deletions tests/integration/server_test.go
Original file line number Diff line number Diff line change
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 b5d0b16

Please sign in to comment.