Skip to content

Commit 31e602a

Browse files
author
litongxin
committed
update delete and reformat
1 parent b9a6914 commit 31e602a

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

src/storage/disk_table.cc

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,30 +316,43 @@ bool DiskTable::Delete(const std::string& pk, uint32_t idx) {
316316
std::string combine_key1 = CombineKeyTs(pk, UINT64_MAX, ts_col->GetId());
317317
std::string combine_key2 = CombineKeyTs(pk, 0, ts_col->GetId());
318318
it->Seek(rocksdb::Slice(combine_key1));
319-
while (it->Valid() && it->key().compare(rocksdb::Slice(combine_key2)) != 0) {
319+
while (it->Valid()) {
320+
std::string cur_pk;
321+
uint64_t cur_ts;
322+
uint32_t cur_ts_idx;
323+
ParseKeyAndTs(true, it->key(), cur_pk, cur_ts, cur_ts_idx);
324+
if (pk.compare(cur_pk) != 0 || cur_ts_idx != ts_col->GetId()) {
325+
break;
326+
}
320327
if (delete_idx_cnt.find(index->GetId()) != delete_idx_cnt.end()) {
321328
delete_idx_cnt[index->GetId()]++;
322329
} else {
323330
delete_idx_cnt.emplace(index->GetId(), 1);
324331
}
325332
it->Next();
326333
}
327-
batch.DeleteRange(cf_hs_[idx + 1], rocksdb::Slice(combine_key1), rocksdb::Slice(combine_key2));
334+
batch.DeleteRange(cf_hs_[index_def->GetInnerPos() + 1], rocksdb::Slice(combine_key1), rocksdb::Slice(combine_key2));
328335
}
329336
} else {
330337
std::string combine_key1 = CombineKeyTs(pk, UINT64_MAX);
331338
std::string combine_key2 = CombineKeyTs(pk, 0);
332339
it->Seek(rocksdb::Slice(combine_key1));
333340
const auto& index = inner_index->GetIndex().front();
334-
while (it->Valid() && it->key().compare(rocksdb::Slice(combine_key2)) != 0) {
341+
while (it->Valid()) {
342+
std::string cur_pk;
343+
uint64_t cur_ts;
344+
ParseKeyAndTs(it->key(), cur_pk, cur_ts);
345+
if (pk.compare(cur_pk) != 0) {
346+
break;
347+
}
335348
if (delete_idx_cnt.find(index->GetId()) != delete_idx_cnt.end()) {
336349
delete_idx_cnt[index->GetId()]++;
337350
} else {
338351
delete_idx_cnt.emplace(index->GetId(), 1);
339352
}
340353
it->Next();
341354
}
342-
batch.DeleteRange(cf_hs_[idx + 1], rocksdb::Slice(combine_key1), rocksdb::Slice(combine_key2));
355+
rocksdb::Status s = batch.DeleteRange(cf_hs_[index_def->GetInnerPos() + 1], rocksdb::Slice(combine_key1), rocksdb::Slice(combine_key2));
343356
}
344357
rocksdb::Status s = db_->Write(write_opts_, &batch);
345358
if (s.ok()) {
@@ -559,7 +572,7 @@ void DiskTable::GcHead() {
559572

560573
void DiskTable::GcTTL() {
561574
auto inner_indexs = table_index_.GetAllInnerIndex();
562-
for (int i = 0; i < inner_indexs->size(); i++) {
575+
for (uint32_t i = 0; i < inner_indexs->size(); i++) {
563576
auto s = db_->CompactRange(rocksdb::CompactRangeOptions(), cf_hs_[i + 1], nullptr, nullptr);
564577
if (!s.ok()) {
565578
PDLOG(WARNING, "Manual Compaction failed");
@@ -1345,7 +1358,7 @@ bool BloomFilter::getBit(uint32_t bit) {
13451358

13461359
void BloomFilter::Set(const char *str)
13471360
{
1348-
for (int i = 0; i < k_; ++i)
1361+
for (uint32_t i = 0; i < k_; ++i)
13491362
{
13501363
uint32_t p = hash(str, base_[i]) % bitset_size_;
13511364
setBit(p);
@@ -1355,7 +1368,7 @@ void BloomFilter::Set(const char *str)
13551368

13561369
bool BloomFilter::Valid(const char *str)
13571370
{
1358-
for (int i = 0; i < k_; ++i)
1371+
for (uint32_t i = 0; i < k_; ++i)
13591372
{
13601373
uint32_t p = hash(str, base_[i]) % bitset_size_;
13611374
if (!getBit(p)) {

src/storage/disk_table.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ class AbsoluteTTLAndCountCompactionFilter : public rocksdb::CompactionFilter {
283283
return true;
284284
}
285285
idx_cnt_vec_->at(idx)->fetch_add(1, std::memory_order_relaxed);
286-
uint32_t inner_pos = inner_index_->GetId();
287286
std::string pk;
288287
if (indexs.size() > 1) {
289288
pk.assign(key.data(), key.size() - TS_LEN - TS_POS_LEN);

src/storage/table_test.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2010,7 +2010,7 @@ TEST_F(TableTest, GetRecordAbsTTL) {
20102010
uint32_t size = 0;
20112011
ASSERT_TRUE(table->GetRecordIdxCnt(1, &stats, &size));
20122012
int ts_count = 0;
2013-
for (int i = 0; i < size; i++) {
2013+
for (uint32_t i = 0; i < size; i++) {
20142014
ts_count += stats[i];
20152015
}
20162016
EXPECT_EQ(100, ts_count);
@@ -2019,7 +2019,7 @@ TEST_F(TableTest, GetRecordAbsTTL) {
20192019
size = 0;
20202020
ASSERT_TRUE(table->GetRecordIdxCnt(2, &stats, &size));
20212021
ts_count = 0;
2022-
for (int i = 0; i < size; i++) {
2022+
for (uint32_t i = 0; i < size; i++) {
20232023
ts_count += stats[i];
20242024
}
20252025
EXPECT_EQ(100, ts_count);
@@ -2033,7 +2033,7 @@ TEST_F(TableTest, GetRecordAbsTTL) {
20332033
size = 0;
20342034
ASSERT_TRUE(table->GetRecordIdxCnt(1, &stats, &size));
20352035
ts_count = 0;
2036-
for (int i = 0; i < size; i++) {
2036+
for (uint32_t i = 0; i < size; i++) {
20372037
ts_count += stats[i];
20382038
}
20392039
EXPECT_EQ(50, ts_count);
@@ -2042,7 +2042,7 @@ TEST_F(TableTest, GetRecordAbsTTL) {
20422042
size = 0;
20432043
ASSERT_TRUE(table->GetRecordIdxCnt(2, &stats, &size));
20442044
ts_count = 0;
2045-
for (int i = 0; i < size; i++) {
2045+
for (uint32_t i = 0; i < size; i++) {
20462046
ts_count += stats[i];
20472047
}
20482048
EXPECT_EQ(40, ts_count);
@@ -2137,7 +2137,7 @@ TEST_F(TableTest, GetRecordLatTTL) {
21372137
uint32_t size = 0;
21382138
ASSERT_TRUE(table->GetRecordIdxCnt(1, &stats, &size));
21392139
int ts_count = 0;
2140-
for (int i = 0; i < size; i++) {
2140+
for (uint32_t i = 0; i < size; i++) {
21412141
ts_count += stats[i];
21422142
}
21432143
EXPECT_EQ(50, ts_count);
@@ -2146,7 +2146,7 @@ TEST_F(TableTest, GetRecordLatTTL) {
21462146
size = 0;
21472147
ASSERT_TRUE(table->GetRecordIdxCnt(2, &stats, &size));
21482148
ts_count = 0;
2149-
for (int i = 0; i < size; i++) {
2149+
for (uint32_t i = 0; i < size; i++) {
21502150
ts_count += stats[i];
21512151
}
21522152
EXPECT_EQ(40, ts_count);
@@ -2155,15 +2155,15 @@ TEST_F(TableTest, GetRecordLatTTL) {
21552155
size = 0;
21562156
ASSERT_TRUE(table->GetRecordIdxCnt(0, &stats, &size));
21572157
ts_count = 0;
2158-
for (int i = 0; i < size; i++) {
2158+
for (uint32_t i = 0; i < size; i++) {
21592159
ts_count += stats[i];
21602160
}
21612161
EXPECT_EQ(70, ts_count);
21622162

21632163
table->Delete("test0", 0);
21642164
table->Delete("testnew0", 1);
21652165
EXPECT_EQ(18, (int64_t)table->GetRecordPkCnt());
2166-
EXPECT_EQ(114, (int64_t)table->GetRecordIdxCnt());
2166+
EXPECT_EQ(108, (int64_t)table->GetRecordIdxCnt());
21672167

21682168

21692169
delete table;
@@ -2256,7 +2256,7 @@ TEST_F(TableTest, GetRecordAbsAndLatTTL) {
22562256
uint32_t size = 0;
22572257
ASSERT_TRUE(table->GetRecordIdxCnt(1, &stats, &size));
22582258
int ts_count = 0;
2259-
for (int i = 0; i < size; i++) {
2259+
for (uint32_t i = 0; i < size; i++) {
22602260
ts_count += stats[i];
22612261
}
22622262
EXPECT_EQ(50, ts_count);
@@ -2265,7 +2265,7 @@ TEST_F(TableTest, GetRecordAbsAndLatTTL) {
22652265
size = 0;
22662266
ASSERT_TRUE(table->GetRecordIdxCnt(2, &stats, &size));
22672267
ts_count = 0;
2268-
for (int i = 0; i < size; i++) {
2268+
for (uint32_t i = 0; i < size; i++) {
22692269
ts_count += stats[i];
22702270
}
22712271
EXPECT_EQ(40, ts_count);
@@ -2274,7 +2274,7 @@ TEST_F(TableTest, GetRecordAbsAndLatTTL) {
22742274
size = 0;
22752275
ASSERT_TRUE(table->GetRecordIdxCnt(0, &stats, &size));
22762276
ts_count = 0;
2277-
for (int i = 0; i < size; i++) {
2277+
for (uint32_t i = 0; i < size; i++) {
22782278
ts_count += stats[i];
22792279
}
22802280
EXPECT_EQ(70, ts_count);

0 commit comments

Comments
 (0)