4paradigm / 4paradigm/OpenMLDB

Wrong result for MemTableTraverseIterator::GetCount()

Aperta
#1,227 1 commento 0 reazioni 1 assegnatario Assegnata a @dl239 Vedi su GitHub
bug storage-engine
Lingua principale
C++
Stelle
1.7k
Fork
331
Merge medio
12g 12h
PR unite (30g)
1

Descrizione

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)

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
cpp
Ambito
databases
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.