Skip to content

Commit 1ecf84f

Browse files
committed
fix comments
1 parent fdf9bd8 commit 1ecf84f

4 files changed

Lines changed: 22 additions & 26 deletions

File tree

src/commands/cmd_stream.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -566,17 +566,13 @@ class CommandXGroup : public Commander {
566566
}
567567

568568
if (subcommand_ == "destroy") {
569-
uint64_t delete_cnt = 0;
570-
auto s = stream_db.DestroyGroup(ctx, stream_name_, group_name_, &delete_cnt);
569+
bool destroyed = false;
570+
auto s = stream_db.DestroyGroup(ctx, stream_name_, group_name_, &destroyed);
571571
if (!s.ok()) {
572572
return {Status::RedisExecErr, s.ToString()};
573573
}
574574

575-
if (delete_cnt > 0) {
576-
*output = redis::Integer(1);
577-
} else {
578-
*output = redis::Integer(0);
579-
}
575+
*output = redis::Integer(destroyed ? 1 : 0);
580576
}
581577

582578
if (subcommand_ == "createconsumer") {

src/types/redis_stream.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,8 @@ rocksdb::Status Stream::CreateGroup(engine::Context &ctx, const Slice &stream_na
738738
}
739739

740740
rocksdb::Status Stream::DestroyGroup(engine::Context &ctx, const Slice &stream_name, const std::string &group_name,
741-
uint64_t *delete_cnt) {
742-
*delete_cnt = 0;
741+
bool *destroyed) {
742+
*destroyed = false;
743743
std::string ns_key = AppendNamespacePrefix(stream_name);
744744

745745
StreamMetadata metadata;
@@ -782,7 +782,7 @@ rocksdb::Status Stream::DestroyGroup(engine::Context &ctx, const Slice &stream_n
782782
if (!s.ok()) return s;
783783
}
784784

785-
*delete_cnt = 1;
785+
*destroyed = true;
786786
metadata.group_number -= 1;
787787
std::string metadata_bytes;
788788
metadata.Encode(&metadata_bytes);

src/types/redis_stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Stream : public SubKeyScanner {
4242
rocksdb::Status CreateGroup(engine::Context &ctx, const Slice &stream_name, const StreamXGroupCreateOptions &options,
4343
const std::string &group_name);
4444
rocksdb::Status DestroyGroup(engine::Context &ctx, const Slice &stream_name, const std::string &group_name,
45-
uint64_t *delete_cnt);
45+
bool *destroyed);
4646
rocksdb::Status CreateConsumer(engine::Context &ctx, const Slice &stream_name, const std::string &group_name,
4747
const std::string &consumer_name, int *created_number);
4848
rocksdb::Status DestroyConsumer(engine::Context &ctx, const Slice &stream_name, const std::string &group_name,

tests/cppunit/types/stream_test.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,12 +2518,12 @@ TEST_F(RedisStreamTest, StreamConsumerGroupCreateAndDestroy) {
25182518
std::string group_name = "TestGroup";
25192519
auto s = stream_->CreateGroup(*ctx_, stream_name, create_options, group_name);
25202520
EXPECT_TRUE(s.ok());
2521-
uint64_t delete_cnt = 0;
2522-
s = stream_->DestroyGroup(*ctx_, stream_name, group_name, &delete_cnt);
2523-
EXPECT_TRUE(delete_cnt != 0);
2524-
delete_cnt = 0;
2525-
s = stream_->DestroyGroup(*ctx_, stream_name, group_name, &delete_cnt);
2526-
EXPECT_TRUE(delete_cnt == 0);
2521+
bool destroyed = false;
2522+
s = stream_->DestroyGroup(*ctx_, stream_name, group_name, &destroyed);
2523+
EXPECT_TRUE(destroyed);
2524+
destroyed = false;
2525+
s = stream_->DestroyGroup(*ctx_, stream_name, group_name, &destroyed);
2526+
EXPECT_FALSE(destroyed);
25272527
}
25282528

25292529
TEST_F(RedisStreamTest, DestroyGroupCleansUpConsumersAndPelEntries) {
@@ -2557,15 +2557,15 @@ TEST_F(RedisStreamTest, DestroyGroupCleansUpConsumersAndPelEntries) {
25572557
EXPECT_TRUE(s.ok());
25582558
EXPECT_EQ(entries.size(), 2);
25592559

2560-
uint64_t delete_cnt = 0;
2561-
s = stream_->DestroyGroup(*ctx_, stream_name, group_name, &delete_cnt);
2560+
bool destroyed = false;
2561+
s = stream_->DestroyGroup(*ctx_, stream_name, group_name, &destroyed);
25622562
EXPECT_TRUE(s.ok());
2563-
EXPECT_GT(delete_cnt, 0);
2563+
EXPECT_TRUE(destroyed);
25642564

25652565
// Verify re-destroying the same group deletes nothing
2566-
delete_cnt = 0;
2567-
s = stream_->DestroyGroup(*ctx_, stream_name, group_name, &delete_cnt);
2568-
EXPECT_EQ(delete_cnt, 0);
2566+
destroyed = false;
2567+
s = stream_->DestroyGroup(*ctx_, stream_name, group_name, &destroyed);
2568+
EXPECT_FALSE(destroyed);
25692569

25702570
// Verify stream entries are still intact after group destruction
25712571
std::vector<redis::StreamEntry> remaining;
@@ -2623,10 +2623,10 @@ TEST_F(RedisStreamTest, DestroyGroupDoesNotAffectOtherGroups) {
26232623
EXPECT_TRUE(s.ok());
26242624

26252625
// Destroy group1
2626-
uint64_t delete_cnt = 0;
2627-
s = stream_->DestroyGroup(*ctx_, stream_name, group1, &delete_cnt);
2626+
bool destroyed = false;
2627+
s = stream_->DestroyGroup(*ctx_, stream_name, group1, &destroyed);
26282628
EXPECT_TRUE(s.ok());
2629-
EXPECT_GT(delete_cnt, 0);
2629+
EXPECT_TRUE(destroyed);
26302630

26312631
// Verify group2 still exists with its consumer
26322632
std::vector<std::pair<std::string, redis::StreamConsumerGroupMetadata>> group_metadata;

0 commit comments

Comments
 (0)