[infinispan-dev] Distributed Counter Discussion

Pedro Ruivo pedro at infinispan.org
Tue Mar 29 13:25:40 EDT 2016


== Status update ==

Hi all,

The work in progress can be found in [1].

The main interface is:

CompletableFuture<Long> addAndGet(long)

The CompletableFuture will allow to cover a more use cases, for example, 
if you need to count the number of visits, you can increment without 
waiting it to complete. On other hand, if you need "unique ids", it is 
possible to increment and wait for the result.

* Let me know any concerns with it.

Currently, two types of counters can be returned by the counter manager: 
"unlimited" and limited (i.e. with thresholds).

"Unlimited" is actually limited to Long.MAX_VALUE but will never throw 
any exception when reached.
The limited version throws a CounterException when the min or max 
threshold is reached.
In both cases, it doesn't overflow the counter value.

Currently, I'm working in the notification mechanism. So, just ignore 
that part of the code :)

Moving to the next problem, I need an opinion how to create the counter 
manager.

The current implementation is using a private cache. It has the 
advantage of starting the cache when a cache manager starts, however, it 
is a bit difficult to configure (e.g. persistence). Also, it does not 
allow different configuration for the counter (replicated vs 
distributed, persisted or not).

Another alternative, it to construct the counter manager with the cache 
manager and a cache name. This looks simpler and it allows the user to 
configure it properly and have different counter manager with different 
configurations.

* Comments are welcome.

Cheers,
Pedro

[1] https://github.com/pruivo/infinispan/tree/t_counters/distributed-counter


More information about the infinispan-dev mailing list