Hazelcast Ringbuffer readManyAsync returns empty results

I am trying to read N items from RingBuffer using readManyAsync, but always returns an empty result set. If I use readOne, I get the data.

I am using readManyAsync as indicated in the documentation. Is there any other way to do this?

Enviroment:

  • Java 8
  • Hazelcast 3.5.3

Example:

Ringbuffer<String> buffer = this.hazelcastInstance.getRingbuffer("testBuffer"); buffer.add("a"); buffer.add("b"); buffer.add("c"); Long sequence = buffer.headSequence(); ICompletableFuture<ReadResultSet<String>> resultSetFuture = buffer.readManyAsync(sequence, 0, 3, null); ReadResultSet<String> resultSet = resultSetFuture.get(); System.out.println("*** readManyAsync *** readCount: " + resultSet.readCount()); int count = 0; for (String s : resultSet) { System.out.println(count + " - " + s); count++; } System.out.println("*** readOne ***"); for (int i = 0; i < 3; i++) { System.out.println(i + " - " + buffer.readOne(i)); } 

Output:

 *** readManyAsync *** readCount: 0 *** readOne *** 0 - a 1 - b 2 - c 
+5
source share
2 answers

You are satisfied with getting zero results:

buffer.readManyAsync (sequence, 0, 3, null);

Try changing 0 to 1.

buffer.readManyAsync (sequence, 1, 3, null);

Now the call will be blocked until at least 1 result is achieved.

You can probably make things more efficient by requesting more than three items. In most cases, getting data is cheap, but io / operation planning is expensive. So try to get as far as you can. Therefore, try to get as many results as possible. 100 ... or 1000 (which is the maximum).

+5
source

Ok, but how do you use readManyAsync in a non-blocking way, from minCount to 0?

I made a minimal test case, and I really can't figure it out. I posted a support topic here:

https://groups.google.com/forum/#!topic/hazelcast/FGnLWDGrzb8

As an answer: I am using readManyAsync with a timeout, for example:

 try{ buffer.readManyAsync(sequence, 1, 3, null).get(500, TimeUnit.MILLISECONDS); } catch (TimeoutException e){ // We timed out, shame, let move on } 

This is the only way to make an elegant non-blocking thread, but while reading the document, I really thought minCount = 0 would do the trick.

+1
source

Source: https://habr.com/ru/post/1233651/


All Articles