ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "aaron@tophold.com" <aa...@tophold.com>
Subject Re: Re: Where can we get the partition assignment of a Cache after the cluster changed?
Date Tue, 24 Oct 2017 11:05:09 GMT
Thanks Slava, yes after add those configuration, eventually I can receive those notification.


But seem all the cache's rebalanced event will be published to me with cache name as the cache
I monitored. 

Like I only care the CacheA 's events:

final CacheRebalancingEvent cre = (CacheRebalancingEvent) event;
if ("CacheA".equals(cre.cacheName())) {

}

But now even the CacheB join the cluster, I still get one event with 'CacheA'  as #cacheName.


If I compare local node's primary partition for CacheA, it's not changed actually. 


Regards
Aaron


aaron@tophold.com
 
From: slava.koptilin
Date: 2017-10-24 18:39
To: user
Subject: Re: Re: Where can we get the partition assignment of a Cache after the cluster changed?
Hi Aaron,
 
Please check that CACHE_REBALANCE events are registered in
IgniteConfiguration via xml or java code (by default, all these events are
disabled).
 
<property name="includeEventTypes">
    <list>
        <util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_STARTED"/>
        <util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_STOPPED"/>
        <util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_LOADED"/>
        <util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_UNLOADED"/>
        <util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_OBJECT_LOADED"/>
        <util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_OBJECT_UNLOADED"/>
        <util:constant
static-field="org.apache.ignite.events.EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST"/>
    </list>
</property>
 
Could you try the following code?
        IgnitePredicate<Event> rebalanceEventLsnr = evt -> {
            System.out.println("Received event [evt=" + evt.name() + ",
evt=" + evt.toString());
 
            if (evt instanceof CacheRebalancingEvent) {
                CacheRebalancingEvent rebalancingEvt =
(CacheRebalancingEvent) evt;
 
                if (rebalancingEvt.cacheName().equals(IG_CACHE_NAME)) {
                    IgniteCache c = ignite.cache(IG_CACHE_NAME);
                    ClusterNode localNode = ignite.cluster().localNode();
 
                    int[] backups =
ignite.affinity(c.getName()).backupPartitions(localNode);
                    int[] primaries =
ignite.affinity(c.getName()).primaryPartitions(localNode);
 
                    System.out.println("Local node : " + localNode.id());
                    System.out.println("\t primary: " +
Arrays.toString(primaries));
                    System.out.println("\t backups: " +
Arrays.toString(backups));
                   
System.out.println("-----------------------------------------");
                }
            }
 
            return true; // Continue listening.
        };
        ignite.events().localListen(rebalanceEventLsnr,
EventType.EVT_CACHE_REBALANCE_STOPPED);
 
 
 
 
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Mime
View raw message