microsoft / ALEX

A library for building an in-memory, Adaptive Learned indEX
MIT License
656 stars 112 forks source link

Segmentation fault problem when lookup after bulk load #4

Closed zhczhong closed 3 years ago

zhczhong commented 3 years ago

I write a simple test where the index first bulk load 2000000 keys, then carry out lookup operation one by one. But there will be a segmentation fault.

TEST(Alex, TestLookup) {
    Alex<int, int> index;
    Alex<int, int>::V values[2000000];

    for (int i = 0; i < 2000000; i++) {
        values[i].first = i;
        values[i].second = i;
    }

    std::sort(values, values + 2000000,
        [](auto const &a, auto const &b) { return a.first < b.first; });
    index.bulk_load(values, 2000000);
    EXPECT_EQ(2000000, index.size());

    for (int i = 0; i < 2000000; i++)
    {
        EXPECT_EQ(2000000, index.size());

        auto it = index.find(i);
        EXPECT_TRUE(!it.is_end()) << "The index of iterator is " << i;
        EXPECT_EQ(i, it.key());

        int *p = index.get_payload(i);
        EXPECT_TRUE(p);
        EXPECT_EQ(i, *p);

        EXPECT_EQ(2000000, index.size());
    }

    for (int i = 0; i < 2000000; i++)
    {
        auto it = index.find(i);
        EXPECT_TRUE(!it.is_end()) << "The index of iterator is " << i;
        EXPECT_EQ(i, it.key());

        int *p = index.get_payload(i);
        EXPECT_TRUE(p);
        EXPECT_EQ(i, *p);
    }
}

image

jialinding commented 3 years ago

Thanks for bringing this issue to our attention. We'll look into it.

jialinding commented 3 years ago

The issue should now be fixed, based on #6

zhczhong commented 3 years ago

The issue is fixed. Thanks for your great work.