Search code examples
pythoninfluxdb

Influxdb read/write operations


Influxdb version - 0.9rc30. influxdb-python - 2.3.0

Trying example from here.

If I use client.query(query) right after client.write_points(data) there is no data in query result. But, when I try python's sleep function like

client.write_points(data)

sleep(0.5)

result = client.query(query)

print("Result: {0}".format(result))

I do get a proper response. Does it mean, that when script tries to get some data from db (without sleep), this data is not there yet?

Is there any way to solve it using other approach?

Thanks in advance.


Solution

  • The data is not instantaneously available, depending on your setup and the amount of data written. Writes can be accepted before they are fully replicated to the datastore, as long as an outage wouldn't lead to data loss. I doubt you need a 0.5 second sleep, though, a few tens of milliseconds should be enough.

    If this was a brand new database, there's also a bug in RC30 that was just patched (https://github.com/influxdb/influxdb/pull/2610) which led to slow writes for the first batch written to the database.