Search code examples
cratedb

Writing values in serial fails to update immediately


I am trying to write many values into the create-io DB using a python script. Since crate does not support an auto-incrementer for fiels like ID, I query the last ID and use (+1) for the next one. However, when I send a "insert into..." command, the data is not written immediately. So even if I close the connection and call select count(id) from mytable I still receive the old id counter. For now, I am forced to use time.sleep(0.5) after each insert, which is "not good" .

Can someone guide me here into a direction?

Thanks alot!


Solution

  • CrateDB is eventual consistent (https://crate.io/docs/reference/en/0.54.4/storage_consistency.html) but provides e.g. read-after write consistency.

    so if you query a document by its primary key - it will be immediately available.

    if this is not enough or you can't query by primary key you can issue the REFRESH TABLEcommand - but this comes at a performance penalty.