4paradigm / 4paradigm/OpenMLDB

Wrong result for MemTableTraverseIterator::GetCount()

Đang mở
#1,227 1 bình luận 0 reaction 1 người được giao Được giao cho @dl239 Xem trên GitHub
bug storage-engine
Ngôn ngữ chính
C++
Star
1.7k
Fork
331
Merge trung bình
12 ngày 12 giờ
Pull request đã merge (30 ngày)
1

Mô tả

When using traverseIterator to traverse Memtable, GetCount() is used to get the traverse count. The meaning of 'traverse count' is not clear. and if we regard it as 'how many pieces of data it has traversed' then the result is not correct.

## Situation
``` cpp
TEST_F(TableTest, TraverseIteratorCount) {
::openmldb::api::TableMeta table_meta;
table_meta.set_name("table1");
table_meta.set_tid(1);
table_meta.set_pid(0);
table_meta.set_seg_cnt(8);
table_meta.set_mode(::openmldb::api::TableMode::kTableLeader);
table_meta.set_key_entry_max_height(8);
table_meta.set_format_version(1);
SchemaCodec::SetColumnDesc(table_meta.add_column_desc(), "card", ::openmldb::type::kString);
SchemaCodec::SetColumnDesc(table_meta.add_column_desc(), "mcc", ::openmldb::type::kString);
SchemaCodec::SetColumnDesc(table_meta.add_column_desc(), "price", ::openmldb::type::kBigInt);
SchemaCodec::SetColumnDesc(table_meta.add_column_desc(), "ts1", ::openmldb::type::kBigInt);
SchemaCodec::SetColumnDesc(table_meta.add_column_desc(), "ts2", ::openmldb::type::kBigInt);
SchemaCodec::SetIndex(table_meta.add_column_key(), "card", "card", "ts1", ::openmldb::type::kAbsoluteTime, 0, 0);
SchemaCodec::SetIndex(table_meta.add_column_key(), "card1", "card", "ts2", ::openmldb::type::kAbsoluteTime, 0, 0);
SchemaCodec::SetIndex(table_meta.add_column_key(), "mcc", "mcc", "ts1", ::openmldb::type::kAbsoluteTime, 0, 0);

MemTable table(table_meta);
table.Init();
codec::SDKCodec codec(table_meta);

for (int i = 0; i < 1000; i++) {
std::vector row = {"card" + std::to_string(i % 100), "mcc" + std::to_string(i),
"13", std::to_string(1000 + i), std::to_string(10000 + i)};
::openmldb::api::PutRequest request;
::openmldb::api::Dimension* dim = request.add_dimensions();
dim->set_idx(0);
dim->set_key(row[0]);
dim = request.add_dimensions();
dim->set_idx(1);
dim->set_key(row[0]);
dim = request.add_dimensions();
dim->set_idx(2);
dim->set_key(row[1]);
std::string value;
ASSERT_EQ(0, codec.EncodeRow(row, &value));
table.Put(0, value, request.dimensions());
}
TableIterator* it = table.NewTraverseIterator(0);
it->SeekToFirst();
int count = 0;
while (it->Valid()) {
count++;
it->Next();
}
ASSERT_EQ(1000, count);
ASSERT_EQ(1100, (int64_t)it->GetCount());
delete it;
}
```

## Expected Behavior

The result of (int64_t)it->GetCount() should probably be 1000

## Current Behavior

It's 1100 as the test says.

## Steps to Reproduce
make and run table_test, in TEST_F(TableTest, TraverseIteratorCount)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

The issue is in MemTableTraverseIterator::GetCount() within the OpenMLDB codebase. Start by examining the table_test.cpp file and the specific test case 'TraverseIteratorCount'. Look at the MemTable and MemTableTraverseIterator implementations to understand how the count is incremented. The test inserts 1000 rows but expects GetCount() to return 1000, not 1100. Run the test to reproduce the failure, then trace the logic in GetCount() to identify why it overcounts.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
cpp
Lĩnh vực
databases
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
45/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.