V2 Async Insert missing documents


#1

Hi

I started using the version 2 of the SDK. I like how it is developed.
However I am experiencing an undesired behaviour.

I am trying to write large volume of data at once. So I am using the asynchronous bucket.
But I sometimes miss between %10 to %20 of my documents and I don’t see any errors.

Has anyone had similar problems?

Sample samplePdf = new Sample("Alex", "Dorandish");

    InputStream inputStream = CacheClientTestOffline.class.getResourceAsStream("1.pdf");
    byte[] pdf = new byte[inputStream.available()];
    inputStream.read(pdf,0, inputStream.available());
    samplePdf.setPdf(pdf);

    String id = System.currentTimeMillis()+"-";
    for(int i=0;i<5000;i++) {
        CouchbaseDao.getInstance().insertObject(id+i, samplePdf);
    }

Then I change the asynchronous to synchronous in this method:

public void insertObject(final String key, final Serializable document) {
    final Document doc = SerializableDocument.create(key, document);
    this.bucketSynch.insert(doc);
}

Same problem. what am I doing wrong? It is simple sequential insertion. why am I missing data?


#2

It looks like you are using Rx Observables not to their fortune :wink:

I’m assuming bucketSynch is the asynchronous bucket reference?
You need to make sure to subscribe and assign error handlers so you can detect errors properly.

I would recommend you to check out http://docs.couchbase.com/developer/java-2.0/observables.html, but at least add error handler to log them when they happen, but in practice you want retry behavior. I’m currently developing a doc on error handling with Observables, you can start reading it here already: https://gist.github.com/daschl/db9fcc9d2b932115b679

If possible, can you post the full code somewhere so I can run it and enhance it for you?