fix: delete_by_filter should use g_doc_id (#84)
This commit is contained in:
@@ -122,7 +122,7 @@ class SegmentImpl : public Segment,
|
||||
|
||||
Status Delete(const std::string &pk) override;
|
||||
|
||||
Status Delete(uint64_t segment_doc_id) override;
|
||||
Status Delete(uint64_t g_doc_id) override;
|
||||
|
||||
Doc::Ptr Fetch(uint64_t g_doc_id) override;
|
||||
|
||||
@@ -911,20 +911,15 @@ Status SegmentImpl::Delete(const std::string &pk) {
|
||||
return internal_delete(mutable_doc);
|
||||
}
|
||||
|
||||
Status SegmentImpl::Delete(uint64_t segment_doc_id) {
|
||||
// Note: Here we have no way to determine if g_doc_id is valid
|
||||
Status SegmentImpl::Delete(uint64_t g_doc_id) {
|
||||
std::lock_guard lock(seg_mtx_);
|
||||
if (segment_doc_id >= doc_ids_.size()) {
|
||||
return Status::InvalidArgument("segment_doc_id:", segment_doc_id,
|
||||
" out of range");
|
||||
}
|
||||
auto global_doc_id = doc_ids_[segment_doc_id];
|
||||
if (delete_store_->is_deleted(global_doc_id)) {
|
||||
return Status::NotFound("global_doc_id:", global_doc_id,
|
||||
" already deleted");
|
||||
if (delete_store_->is_deleted(g_doc_id)) {
|
||||
return Status::NotFound("g_doc_id:", g_doc_id, " already deleted");
|
||||
}
|
||||
|
||||
Doc mutable_doc;
|
||||
mutable_doc.set_doc_id(global_doc_id);
|
||||
mutable_doc.set_doc_id(g_doc_id);
|
||||
mutable_doc.set_operator(Operator::DELETE);
|
||||
|
||||
// append wal
|
||||
|
||||
@@ -134,9 +134,9 @@ class Segment {
|
||||
|
||||
virtual Status Delete(const std::string &pk) = 0;
|
||||
|
||||
virtual Status Delete(uint64_t doc_id) = 0;
|
||||
virtual Status Delete(uint64_t g_doc_id) = 0;
|
||||
|
||||
virtual Doc::Ptr Fetch(uint64_t doc_id) = 0;
|
||||
virtual Doc::Ptr Fetch(uint64_t g_doc_id) = 0;
|
||||
|
||||
// for sqlengine
|
||||
virtual TablePtr fetch(const std::vector<std::string> &columns,
|
||||
|
||||
@@ -2799,9 +2799,18 @@ TEST_F(CollectionTest, Feature_Optimize_Delete) {
|
||||
check_doc();
|
||||
std::cout << "check success 2" << std::endl;
|
||||
|
||||
// delete by filter
|
||||
s = collection->DeleteByFilter("int32 < 10");
|
||||
if (!s.ok()) {
|
||||
std::cout << s.message() << std::endl;
|
||||
}
|
||||
ASSERT_TRUE(s.ok());
|
||||
stats = collection->Stats().value();
|
||||
ASSERT_EQ(stats.doc_count, doc_count - 10);
|
||||
|
||||
// delete all docs
|
||||
std::vector<std::string> pks;
|
||||
for (int i = 0; i < doc_count; ++i) {
|
||||
for (int i = 10; i < doc_count; ++i) {
|
||||
pks.push_back(TestHelper::MakePK(i));
|
||||
}
|
||||
auto res = collection->Delete(pks);
|
||||
|
||||
@@ -814,9 +814,9 @@ TEST_P(SegmentTest, DeleteDoc) {
|
||||
count = segment->doc_count(segment->get_filter());
|
||||
EXPECT_EQ(count, 9);
|
||||
|
||||
// Delete a document by local doc id
|
||||
// Delete a document by global doc id
|
||||
status = segment->Delete(3);
|
||||
EXPECT_TRUE(status.ok()) << "Delete by local doc id failed: "
|
||||
EXPECT_TRUE(status.ok()) << "Delete by global doc id failed: "
|
||||
<< status.message();
|
||||
|
||||
count = segment->doc_count(segment->get_filter());
|
||||
@@ -942,6 +942,33 @@ TEST_P(SegmentTest, Flush) {
|
||||
EXPECT_TRUE(status.ok()) << "Flush failed: " << status.message();
|
||||
}
|
||||
|
||||
TEST_P(SegmentTest, FlushAfterInsert) {
|
||||
auto segment = test::TestHelper::CreateSegmentWithDoc(
|
||||
col_path, *schema, 0, 0, id_map, delete_store, version_manager, options,
|
||||
0, 100);
|
||||
ASSERT_TRUE(segment != nullptr);
|
||||
|
||||
// Flush the segment
|
||||
auto status = segment->flush();
|
||||
EXPECT_TRUE(status.ok()) << "Flush failed: " << status.message();
|
||||
|
||||
test::TestHelper::SegmentInsertDoc(segment, *schema, 100, 150);
|
||||
|
||||
ASSERT_EQ(segment->doc_count(), 150);
|
||||
|
||||
for (int i = 0; i < 150; i++) {
|
||||
auto ret_doc = segment->Fetch(i);
|
||||
EXPECT_TRUE(ret_doc != nullptr);
|
||||
|
||||
Doc verify_doc = test::TestHelper::CreateDoc(i, *schema);
|
||||
auto vv = verify_doc.get<std::vector<float>>("dense_fp32").value();
|
||||
auto v = ret_doc->get<std::vector<float>>("dense_fp32").value();
|
||||
for (uint32_t j = 0; j < vv.size(); j++) {
|
||||
ASSERT_FLOAT_EQ(v[j], vv[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(SegmentTest, Dump) {
|
||||
auto segment = test::TestHelper::CreateSegmentWithDoc(
|
||||
col_path, *schema, 0, 0, id_map, delete_store, version_manager, options,
|
||||
@@ -1273,9 +1300,6 @@ TEST_P(SegmentTest, DeleteNonExistentDoc) {
|
||||
|
||||
auto status1 = segment->Delete("pk_999");
|
||||
EXPECT_FALSE(status1.ok()) << "Delete non-existent pk should fail";
|
||||
|
||||
auto status2 = segment->Delete(999);
|
||||
EXPECT_FALSE(status2.ok()) << "Delete non-existent doc_id should fail";
|
||||
}
|
||||
|
||||
TEST_P(SegmentTest, UpdateNonExistentDoc) {
|
||||
|
||||
Reference in New Issue
Block a user