Skip to content

Error: Cannot find prevKey when creating shard_id #41

@redpanda-f

Description

@redpanda-f

Hi,
we seem to have a simple setup where we try to populate the DB with some keys and values as follows:

fn main() {
    std::fs::remove_dir_all("qmdb_testdir").unwrap();
    std::fs::create_dir_all("qmdb_testdir").unwrap();
    let config = Config::from_dir("qmdb_testdir");
    AdsCore::init_dir(&config);
    let mut ads = AdsWrap::<SimpleTask>::new(&config);

    let tasks_per_block = 10_000;

    if tasks_per_block >= (1 << IN_BLOCK_IDX_BITS) {
        panic!("tasks_per_block {} is too large", tasks_per_block);
    }

    let mut cset = ChangeSet::new();
    let mut rng = rng();
    let mut known_keys = HashSet::new();
    for i in 0..1_000 {
        let key = {
            loop {
                let key: Vec<u8> = (0..32).map(|_| rng.random()).collect(); // Generate a random 32-byte key
                if !known_keys.contains(&key) {
                    known_keys.insert(key.clone());
                    break key;
                }
            }
        };
        known_keys.insert(key.clone());
        let value: Vec<u8> = (0..32).map(|_| rng.random()).collect(); // Generate a random 32-byte value
        let shard_id = byte0_to_shard_id(key[0]) as u8;
        let mut key_array = [0u8; 32];
        key_array.clone_from_slice(&key[..32]); // Copy the first 32 bytes into the array
        cset.add_op(OP_CREATE, shard_id, &key_array, &key[..], &value[..], None);
    }
    cset.sort();
    let task = SimpleTask::new(vec![cset]);
    let task_list = vec![RwLock::new(Some(task))];
    let height = 1;
    let task_count = task_list.len() as i64;
    println!("task count {}", task_count);
    // task id's high 40 bits is block height and low 24 bits is task index
    let last_task_id = (height << IN_BLOCK_IDX_BITS) | (task_count - 1);
    println!("last task id {}", last_task_id);

    ads.start_block(height, Arc::new(TasksManager::new(task_list, last_task_id)));
    let shared_ads = ads.get_shared();
    shared_ads.add_task((height << IN_BLOCK_IDX_BITS) | (task_count - 1));
    ads.flush();
}

However, we face the following error:

task count 1
last task id 16777216
FF key = [0, 108, 70, 149, 121, 15, 101, 231, 142, 0] file_pos = 360880

thread '<unnamed>' panicked at /home/useruser/.cargo/git/checkouts/qmdb-cd830a515878d17f/8def52e/qmdb/src/updater.rs:288:13:
Cannot find prevKey when creating shard_id=0 key=[0, 108, 198, 199, 203, 97, 109, 156, 191, 210, 198, 95, 229, 45, 47, 196, 143, 176, 226, 10, 122, 103, 17, 158, 83, 242, 218, 0, 169, 2, 21, 64]
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
FF key = [209, 152, 131, 169, 164, 169, 42, 223, 38, 0] file_pos = 362176

thread '<unnamed>' panicked at /home/useruser/.cargo/git/checkouts/qmdb-cd830a515878d17f/8def52e/qmdb/src/updater.rs:288:13:
Cannot find prevKey when creating shard_id=13 key=[209, 152, 241, 2, 85, 83, 240, 255, 61, 21, 92, 240, 207, 62, 174, 73, 253, 9, 86, 245, 45, 146, 221, 220, 35, 43, 90, 62, 119, 120, 152, 172]
...

What is going wrong here, especially when this is the first set of additions to DB with all distinct keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions