HTTP connection - caching, or flush data? Inconsistencies

Hi,

I have a table with a timestamp as the primary key.

I’ve discovered that if I do an INSERT immediately followed immediately by a SELECT, the newly inserted one isn’t listed.

I’m doing all of this using the python crate module.

For example, if I run the following SQL in immediate succession, I get nothing out.

$ INSERT INTO crate.temp (time, value) VALUES (1711829022368, 0.8540778019242715)
$ SELECT * FROM crate.temp
[]

Do I need to flush something along the way?

Thanks

EDIT: I’ve found that doing a 500ms pause after each query gives me the right output about 90% of the time. A 1s pause seems to be reliable. This is obviously not ideal, but it just adds about 60s to a script that runs once every 15 minutes, so it’s not a show-stopper.

1 Like

Dear Hugh,

thank you for writing in.

If you want to flush manually, instantly and purposely, you will need to invoke the REFRESH TABLE statement to synchronize writes, because of CrateDB’s eventual consistency properties. However, data also converges automatically after one second by default, see below.

REFRESH TABLE crate.temp;

That’s correct. By default, data automatically converges after 1000ms, but you can also adjust that on behalf of the refresh_interval table setting, to match your needs.

@hammerhead and @proddata also shared excellent details about this topic over here, including relevant pointers to the reference documentation. Enjoy reading, and don’t hesitate to come back with relevant questions.

With kind regards,
Andreas.

1 Like