Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Result of influxDB#write() #47

Closed
drb-digital opened this issue Jul 1, 2015 · 10 comments
Closed

Result of influxDB#write() #47

drb-digital opened this issue Jul 1, 2015 · 10 comments

Comments

@drb-digital
Copy link

Hi Stefan,

first of all thanks for your great work on InfluxDB implementation for java. Including your commits from the last days it is working quite well in my 0.9.0 environment.

I was wondering if there is any possibility to get the result of writing a point (or batched points) to database? Somehow like boolean true/false. I'd like to store my data locally if there is any error (e.g. no connection) and try again later.

Thanks,
Dennis

@majst01
Copy link
Collaborator

majst01 commented Jul 1, 2015

Hi Dennis,

the write is as long as you did not enable batchMode a synchronous call which will throw a RuntimeException if something went wrong, so you will notice it in you app.

If batchMode is enabled, this exception will be thrown in the flusher thread.
I dont see how we could change this behaviour in a way you will get informed about write errors.

Any hints welcome
Stefan

@drb-digital
Copy link
Author

Hi Stefan,

thanks for your reply. Unfortunately I am using batch mode. I'll give it some thought and let you know if I am coming any closer to a possible solution.

One more thing: I am using strings containing lineProtocol to store points/batch points locally. But as far as I can see there is no method to write lineProtocol instead of points/batch points. I tried using query instead, but that wasn't working for me. So I implemented an additional method to InfluxDBImpl.java. I think this is useful for others too, so probably you could include some method like this.

Dennis

public void write(final String database, final String retentionPolicy, final String getLineProtocol) {
        TypedString lineProtocol = new TypedString(getLineProtocol);
        this.influxDBService.writePoints(
                this.username,
                this.password,
                database,
                retentionPolicy,
                TimeUtil.toTimePrecision(TimeUnit.NANOSECONDS),
                ConsistencyLevel.ONE.toString(),
                lineProtocol);

    }

@majst01
Copy link
Collaborator

majst01 commented Jul 1, 2015

Hi,
do you have any special requirements to the content of the lineprotocol which are not fulfilled with the implementation present in Point.java ? If yes please describe these and i will try to implement. Otherwise i want to keep the API as small as possible because this keeps the implementation simple with fewer bugs.

Greetings
Stefan

@drb-digital
Copy link
Author

Hi Stefan,

no, Point.java is allright. What I want to achieve is the following. My influxdb instance is running on a server, data is collected on a mobile device. Every time an exception is thrown, I am storing the point which haven't been sent to influxdb to a local SQLite database. Therefore I am using the method Point#lineProtocol(), which is working fine.

try {
  InfluxDB influxDB = InfluxDBFactory.connect(dbUrl, dbUser, dbPassword);
  influxDB.write(dbName, dbRetentionPolicy, point);
} catch (Exception e) {
  DatabaseSQLite databaseSQLite = new DatabaseSQLite();
  databaseSQLite.openConnection();
  databaseSQLite.insertLineProtocol(point.lineProtocol());
  databaseSQLite.closeConnection();
}

What I am missing is a possibility to send these stored points to influxdb after retrieving them from local database. Therefore I implemented the method mentioned in my comment above and use it as follows:

DatabaseSQLite databaseSQLite = new DatabaseSQLite();
databaseSQLite.openConnection();
String lineProtocol = databaseSQLite.getLineProtocol(id);
databaseSQLite.closeConnection();

InfluxDB influxDB = InfluxDBFactory.connect(dbUrl, dbUser, dbPassword);
influxDB.write(dbName, dbRetentionPolicy, lineProtocol);

Another solution would be to convert lineProtocol strings back to points, which could then be sent by the already existing API.

Hope this explanation helps.

Greetings
Dennis

@majst01
Copy link
Collaborator

majst01 commented Jul 1, 2015

Hi Dennis,

ok got it, but why not serialize/deserialize The Point instance which failed to json and back to a instance for example with GSON:

Gson gson = new Gson();
String pointAsJson = gson.toJson(point);  
// persist to SQLite
Point point = gson.fromJson(pointAsJson,Point.class);  
// persist in influxdb

IMHO lineprotocol is not a proper serialization of points.

@majst01
Copy link
Collaborator

majst01 commented Jul 3, 2015

Close this ticket because there seem to be urgent demand.

@majst01 majst01 closed this as completed Jul 3, 2015
@drb-digital
Copy link
Author

Hi Stefan,

sorry for the delayed reply. That was my first guess too. But when I used JSON parser by Jackson execution failed every time (I cant't remember the error message, but it was something like error while building json from Point). Therefore I was looking into the lineProtocol and didn't try GSON. I'll gave it a try now and it seems to work pretty well. Thanks for your hint!

Greetings
Dennis

@Danushka96
Copy link

Hi Stefan,

Is there a way to catch the exceptions while writing to influx in batch mode in the newer versions of Influx?

@majst01
Copy link
Collaborator

majst01 commented Jul 30, 2020

Yes please read the documentation carefully.

@Danushka96
Copy link

Got it, Thanks @majst01

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants