influxdb-java
influxdb-java copied to clipboard
Inconsistent handling of retention policies in single vs batch points
There is no way to write single points to a default retention policy in case it is not named "autogen". The following code will fail:
InfluxDB influxDB = influxDB.setDatabase("mydb");
influxDB.write(Point.measurement("msmt").tag("tag", "x").addField("field", 42).build());
Expected behaviour is to omit retention policy in the queries to InfluxDB if user did not explicitly specified it.
On the other hand, BatchPoints
do support default retention policy but if any other RP is to be used, it has to be set on BatchPoints
separately and the value set upon the client initialization is ignored:
InfluxDB influxDB = influxDB.setDatabase("mydb").setRetentionPolicy("non_default_rp");
influxDB.write(BatchPoints.database("mydb").tag("tag", "x").addField("field", 42).build());
- points from the batch get written to the default RP. Perhaps it makes sense to make a getter for
BatchPoints.Builder
inInfluxDB
- this way database and retention policy would be automatically populated from the client instance.
@nebehr be aware: you can write to a database using a non-default RP but you cannot easily query the same non-default RP. The only way to do it is providing the full qualified table name <retentionpolicy>.<tablename>
in your query.
Something that new InfluxDB users are not aware is the "data visibility limitation" when you are using different retention policies: data written with a RP "A" can only be queried if you use the same RP "A" later.
With your example, the only way to query msmt
using a retention policy named non_default_rp
is:
Query query = new Query("SELECT * FROM non_default_rp.msmt", "mydb");
Regarding the inconsistency, an easy way to fix it IMO is by doing the following changes:
- set org.influxdb.impl.InfluxDBImpl.retentionPolicy to
null
by default; - create another
writePoints
method in InfluxDBService without the@Query(RP) String retentionPolicy
parameter; - call this new method only if org.influxdb.impl.InfluxDBImpl.retentionPolicy is null;
- update the docs to make it clear that any RP definition passed to
BatchPoints
will be used even if there is a RP defined with the InfluxDB client.
For more info about RP, check https://docs.influxdata.com/influxdb/v1.3/guides/downsampling_and_retention/ and https://docs.influxdata.com/influxdb/v1.3/query_language/database_management/#retention-policy-management
@fmachado thanks for the explanation. I am aware of this limitation although I admit it did catch me unawares when I first discovered it.
I guess my main point is, the Java client cannot just assume the default retention policy is named "autogen". Its default value should be null
(or, better still, Optional<String>
), and if it is empty, the client should attempt to write/read to the default RP whatever its actual name is. Then there would be no need for another writePoints
method.
As for BatchPoints
, I agree that perhaps documentation update will be sufficient.
Just had the same issue as my default retention policy is not named autogen and I wondered, where my data is. When selection without any RP, there is nothing returned.
Any update on this?
Same issue here, my default retention policy is not named autogen and the write method causes unexpected troubles due to the fact that it doesn't try to write to the default RP but to the "autogen" one...
I started looking into the code for this one, and currently see no way for the client to know the default retention policy's name. Does the server react to "rp" by using a retention policy that it already knows is "default"?