Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPS_FIND_GEQ_MATCH finds erased item in env with UPS_ENABLE_TRANSACTIONS #105

Open
Amadeszueusz opened this issue Jan 8, 2018 · 2 comments

Comments

@Amadeszueusz
Copy link

Hello,
Please consider following sample:

int main()
{
    ups_env_t* env;
    ups_env_create(&env, "test.db", UPS_ENABLE_TRANSACTIONS, 0664, 0);
    //ups_env_create(&env, "test.db", 0, 0664, 0);

    ups_parameter_t params[] = {
    {UPS_PARAM_KEY_TYPE, UPS_TYPE_UINT32},
    {0, }
    };

    ups_db_t* db;
    ups_env_create_db(env, &db, 1, 0, &params[0]);

    const int item_count = 50;

    for (int i = 0; i < item_count; i++)
    {
        ups_key_t key = ups_make_key(&i, sizeof(i));
        ups_record_t record = {0};

        ups_db_insert(db, 0, &key, &record, 0);
    }

    for(int i = 0; i < item_count / 2; i++)
    {
        ups_key_t key = ups_make_key(&i, sizeof(i));

        ups_db_erase(db, 0, &key, 0);
    }

    uint64_t count = 0;
    ups_db_count(db,0, 0, &count);

    if(count != item_count / 2){
        std::cout << "Item count after delete: " << count << std::endl;
    }

    for(int i = 0; i < item_count / 2; i++)
    {
        ups_key_t key = ups_make_key(&i, sizeof(i));
        ups_record_t record = {0};

        ups_cursor_t* cursor;
        ups_cursor_create(&cursor, db, 0, 0);
        ups_status_t st = ups_cursor_find(cursor, &key, &record, UPS_FIND_GEQ_MATCH);
        //ups_status_t st = ups_db_find(db, 0, &key, &record, UPS_FIND_GEQ_MATCH);

        if(st == UPS_SUCCESS && *reinterpret_cast<int*>(key.data) == i){
            std::cout << "Found deleted item: " << i << std::endl;
        }

        ups_cursor_close(cursor);
    }

    ups_db_close(db, 0);

    return 0;
}

What is printed in the standard output:

Item count after delete: 30
Found deleted item: 24

This occurs only when transactions are enabled.
Both ups_cursor_find and ups_db_find are affected.
Also ups_db_count returns invalid value after erase operation. (should be 25)

Both bugs occurrence seems to be related to number of inserted items (for example when item_count=100 these issues are not occurring)

@cruppstahl
Copy link
Owner

Thanks for the test. I discovered that ups_db_count is deeply flawed when counting deleted items. I have at least pushed a fix for the sample you provided. (The bug in UPS_FIND_GEQ_MATCH is NOT yet fixed though. I will provide that asap.)

@Amadeszueusz
Copy link
Author

Thanks for quick response. I'll be waiting for fix ;)

veloman-yunkan pushed a commit to veloman-yunkan/upscaledb that referenced this issue Sep 5, 2018
Added unittests/issue105.cc as a slightly modified copy of the code
from the description of issue cruppstahl#105 of the upstream repo (the only
change is the correct exit status of the test program).

Also added issue101 and issue105 to the list of tests executed
by 'make test'
veloman-yunkan added a commit to veloman-yunkan/upscaledb that referenced this issue Sep 5, 2018
Added unittests/issue105.cc as a slightly modified copy of the code
from the description of issue cruppstahl#105 of the upstream repo (the only
change is the correct exit status of the test program).

Also added issue101 and issue105 to the list of tests executed
by 'make test'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants