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

Cursor skip entry during iteration #6

Open
billon-pl opened this issue Jun 13, 2018 · 1 comment
Open

Cursor skip entry during iteration #6

billon-pl opened this issue Jun 13, 2018 · 1 comment

Comments

@billon-pl
Copy link
Owner

This is issue is identical to issue-106 from https://github.com/cruppstahl/upscaledb
See cruppstahl/upscaledb#106

Please consider following sample:

int main()
{
    ups_env_t* env;
    ups_env_create(&env, "test.db", UPS_ENABLE_TRANSACTIONS, 0664, 0); // required to reproduce
    //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]);

    int item_count = 57;

    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);
    }

    ups_cursor_t* cur;

    ups_cursor_create(&cur, db, 0, 0);

    int key_data = 0;
    ups_key_t key = {0}; key.data = &key_data; key.size = sizeof(key_data);
    ups_record_t rec = {0};

    auto st = ups_cursor_find(cur, &key, &rec, UPS_FIND_GEQ_MATCH); // required to reproduce

    int counter = 0;
    do{
        ups_cursor_move(cur, &key, &rec, 0); // required to reproduce
        if(counter != *reinterpret_cast<int*>(key.data)){
            std::cout << "Invalid entry: " << counter << std::endl;
        }
        counter++;
    }while(UPS_SUCCESS == ups_cursor_move(cur, &key, &rec, UPS_CURSOR_NEXT));

    ups_cursor_close(cur);

    ups_db_close(db, 0);

    return 0;
}

What is printed to the output:

    Invalid entry: 51 Should be:50
    Invalid entry: 52 Should be:51
    Invalid entry: 53 Should be:52
    Invalid entry: 54 Should be:53
    Invalid entry: 55 Should be:54
    Invalid entry: 56 Should be:55

50th entry is skipped by the cursor during iteration.

In this case ups_cursor_move(cur, &key, &rec, 0) was inserted to simulate situation when there is a possibility for invalidation of key/rec values by subsequent ups api calls, so just before reading them I want to update their values according to cursor position. (I actually experience this scenario in my app).

Since ups_cursor_find(cur, &key, &rec, UPS_FIND_GEQ_MATCH) is also required is this issue connected to 105 ?

@billon-pl
Copy link
Owner Author

  • This case is added to test suite of the project.

  • The source code can be found in file issue106.cc

  • There is work around for this issue: do not use ups_cursor_move(cur, &key, &rec, 0)

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

1 participant