When cache node switch between primary and backup any notification be received?

classic Classic list List threaded Threaded
5 messages Options
aaron@tophold.com aaron@tophold.com
Reply | Threaded
Open this post in threaded view
|

When cache node switch between primary and backup any notification be received?

Hi All, 

When the topology cluster change, possible a backup cache become primary. 

Is there any notification to tell this node, said you are the primary now -- if my cache in REPLICATION mode. 

Maybe other part logic do some preparation stuff related with business. 


Regards
Aaron

Alexey Kukushkin Alexey Kukushkin
Reply | Threaded
Open this post in threaded view
|

Re: When cache node switch between primary and backup any notification be received?

Hi,

Unless you customize affinity function there are always 1024 partitions and every node holds one or more primary partitions evenly distributed among the nodes. The affinity function tries to minimize re-partitioning as topology changes. Just want to confirm - are you really looking for an event like "node 4 is no longer primary for partition 367" ? I feel like you might be looking for nodes with no primary partitions at all but that should not happen with default affinity settings.

On Mon, Sep 11, 2017 at 2:54 PM, [hidden email] <[hidden email]> wrote:
Hi All, 

When the topology cluster change, possible a backup cache become primary. 

Is there any notification to tell this node, said you are the primary now -- if my cache in REPLICATION mode. 

Maybe other part logic do some preparation stuff related with business. 


Regards
Aaron




--
Best regards,
Alexey
aaron@tophold.com aaron@tophold.com
Reply | Threaded
Open this post in threaded view
|

Re: Re: When cache node switch between primary and backup any notification be received?

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. 

Not sure this is a normal use case, or any other way can achieve this in ignite? 

Regards
Aaron

 
Date: 2017-09-11 20:33
Subject: Re: When cache node switch between primary and backup any notification be received?
Hi,

Unless you customize affinity function there are always 1024 partitions and every node holds one or more primary partitions evenly distributed among the nodes. The affinity function tries to minimize re-partitioning as topology changes. Just want to confirm - are you really looking for an event like "node 4 is no longer primary for partition 367" ? I feel like you might be looking for nodes with no primary partitions at all but that should not happen with default affinity settings.

On Mon, Sep 11, 2017 at 2:54 PM, [hidden email] <[hidden email]> wrote:
Hi All, 

When the topology cluster change, possible a backup cache become primary. 

Is there any notification to tell this node, said you are the primary now -- if my cache in REPLICATION mode. 

Maybe other part logic do some preparation stuff related with business. 


Regards
Aaron




--
Best regards,
Alexey
dsetrakyan dsetrakyan
Reply | Threaded
Open this post in threaded view
|

Re: Re: When cache node switch between primary and backup any notification be received?



On Mon, Sep 11, 2017 at 6:54 PM, [hidden email] <[hidden email]> 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?

aaron@tophold.com aaron@tophold.com
Reply | Threaded
Open this post in threaded view
|

Re: Re: When cache node switch between primary and backup any notification be received?

Thanks Dimitriy!

We try use this node predicate :      ignite.affinity("CacheNM").isPrimary(clusterNode, "Key1")

To located the Primary service of the a specific key;  when call ignite#services();   not verified,  but should can work. 


Regards
Aaron

 
Date: 2017-09-12 13:41
Subject: Re: Re: When cache node switch between primary and backup any notification be received?


On Mon, Sep 11, 2017 at 6:54 PM, [hidden email] <[hidden email]> 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?