ignite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitriy Setrakyan <dsetrak...@apache.org>
Subject Fwd: Re: When cache node switch between primary and backup any notification be received?
Date Tue, 12 Sep 2017 05:43:27 GMT
Cross-sending to dev@.

Igniters, is it really this difficult to iterate over local partitions, or
is there a simpler way? What is worse, is that I could not find a single
example anywhere of how to do it. Seems like a pretty common use case.

D.

---------- Forwarded message ----------
From: Dmitriy Setrakyan <dsetrakyan@apache.org>
Date: Mon, Sep 11, 2017 at 10:41 PM
Subject: Re: Re: When cache node switch between primary and backup any
notification be received?
To: user <user@ignite.apache.org>
Cc: aaron@tophold.com




On Mon, Sep 11, 2017 at 6:54 PM, aaron@tophold.com <aaron@tophold.com>
wrote:

> Thanks Alexey!   what we real want, we deploy service on each Cache Node.
>  those service will use data from its' local cache.
>
> Client will call those remote service, Client should only call  the
> service on primary node,  this make those nodes work like master-slave mode
> automatically.
>

In Ignite, a node is a primary node for a certain partition. A key belongs
to a partition and a partition belongs to a node. A node may be primary for
key1 (partition N)  and the same node may be a back up for key 2 (partition
M).

I think you simply should invoke your service on each node and only check
or iterate through primary keys stored on that node. You can get a list of
primary keys by using org.apache.ignite.cache.affinity.Affinity API, for
example Affinty.primaryPartitions(ClusterNode) method.

*int[] primaryPartitions =
> Ignite.affinity("cacheName").primaryPartitions(Ignite.cluster().localNode());*




>
> *for (int primaryPartition : primaryPartitions) {    // Cursor over local
> entries for the given partition.    QueryCursor<Entry<K,V>> cur =
> cache.query(new ScanQuery(primaryPartition));*




>
>
> * for (Entry<K, V> entry : cur) { // Do something on local entries. }}*


Does this make sense?

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message