use of org.apache.ignite.events.CacheRebalancingEvent in project ignite by apache.
the class PlatformContextImpl method writeEvent.
/** {@inheritDoc} */
@Override
public void writeEvent(BinaryRawWriterEx writer, Event evt) {
assert writer != null;
if (evt == null) {
writer.writeInt(-1);
return;
}
EventAdapter evt0 = (EventAdapter) evt;
if (evt0 instanceof CacheEvent) {
writer.writeInt(2);
writeCommonEventData(writer, evt0);
CacheEvent event0 = (CacheEvent) evt0;
writer.writeString(event0.cacheName());
writer.writeInt(event0.partition());
writer.writeBoolean(event0.isNear());
writeNode(writer, event0.eventNode());
writer.writeObject(event0.key());
writer.writeObject(event0.xid());
writer.writeObject(event0.newValue());
writer.writeObject(event0.oldValue());
writer.writeBoolean(event0.hasOldValue());
writer.writeBoolean(event0.hasNewValue());
writer.writeUuid(event0.subjectId());
writer.writeString(event0.closureClassName());
writer.writeString(event0.taskName());
} else if (evt0 instanceof CacheQueryExecutedEvent) {
writer.writeInt(3);
writeCommonEventData(writer, evt0);
CacheQueryExecutedEvent event0 = (CacheQueryExecutedEvent) evt0;
writer.writeString(event0.queryType());
writer.writeString(event0.cacheName());
writer.writeString(event0.className());
writer.writeString(event0.clause());
writer.writeUuid(event0.subjectId());
writer.writeString(event0.taskName());
} else if (evt0 instanceof CacheQueryReadEvent) {
writer.writeInt(4);
writeCommonEventData(writer, evt0);
CacheQueryReadEvent event0 = (CacheQueryReadEvent) evt0;
writer.writeString(event0.queryType());
writer.writeString(event0.cacheName());
writer.writeString(event0.className());
writer.writeString(event0.clause());
writer.writeUuid(event0.subjectId());
writer.writeString(event0.taskName());
writer.writeObject(event0.key());
writer.writeObject(event0.value());
writer.writeObject(event0.oldValue());
writer.writeObject(event0.row());
} else if (evt0 instanceof CacheRebalancingEvent) {
writer.writeInt(5);
writeCommonEventData(writer, evt0);
CacheRebalancingEvent event0 = (CacheRebalancingEvent) evt0;
writer.writeString(event0.cacheName());
writer.writeInt(event0.partition());
writeNode(writer, event0.discoveryNode());
writer.writeInt(event0.discoveryEventType());
writer.writeString(event0.discoveryEventName());
writer.writeLong(event0.discoveryTimestamp());
} else if (evt0 instanceof CheckpointEvent) {
writer.writeInt(6);
writeCommonEventData(writer, evt0);
CheckpointEvent event0 = (CheckpointEvent) evt0;
writer.writeString(event0.key());
} else if (evt0 instanceof DiscoveryEvent) {
writer.writeInt(7);
writeCommonEventData(writer, evt0);
DiscoveryEvent event0 = (DiscoveryEvent) evt0;
writeNode(writer, event0.eventNode());
writer.writeLong(event0.topologyVersion());
writeNodes(writer, event0.topologyNodes());
} else if (evt0 instanceof JobEvent) {
writer.writeInt(8);
writeCommonEventData(writer, evt0);
JobEvent event0 = (JobEvent) evt0;
writer.writeString(event0.taskName());
writer.writeString(event0.taskClassName());
writer.writeObject(event0.taskSessionId());
writer.writeObject(event0.jobId());
writeNode(writer, event0.taskNode());
writer.writeUuid(event0.taskSubjectId());
} else if (evt0 instanceof TaskEvent) {
writer.writeInt(10);
writeCommonEventData(writer, evt0);
TaskEvent event0 = (TaskEvent) evt0;
writer.writeString(event0.taskName());
writer.writeString(event0.taskClassName());
writer.writeObject(event0.taskSessionId());
writer.writeBoolean(event0.internal());
writer.writeUuid(event0.subjectId());
} else
throw new IgniteException("Unsupported event: " + evt);
}
use of org.apache.ignite.events.CacheRebalancingEvent in project ignite by apache.
the class GridCacheOrderedPreloadingSelfTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setCacheConfiguration(cacheConfig(firstCacheMode, 1, FIRST_CACHE_NAME), cacheConfig(secondCacheMode, 2, SECOND_CACHE_NAME));
TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
discoSpi.setIpFinder(IP_FINDER);
cfg.setDiscoverySpi(discoSpi);
Map<IgnitePredicate<? extends Event>, int[]> listeners = new HashMap<>();
listeners.put(new IgnitePredicate<CacheRebalancingEvent>() {
@Override
public boolean apply(CacheRebalancingEvent event) {
times.get(gridIdx(event)).putIfAbsent(event.cacheName(), event.timestamp());
return true;
}
}, new int[] { EventType.EVT_CACHE_REBALANCE_STOPPED });
cfg.setLocalEventListeners(listeners);
return cfg;
}
use of org.apache.ignite.events.CacheRebalancingEvent in project ignite by apache.
the class IgniteCachePartitionLossPolicySelfTest method prepareTopology.
/**
* @return Lost partition ID.
* @throws Exception If failed.
*/
private int prepareTopology() throws Exception {
startGrids(4);
Affinity<Object> aff = ignite(0).affinity(CACHE_NAME);
for (int i = 0; i < aff.partitions(); i++) ignite(0).cache(CACHE_NAME).put(i, i);
client = true;
startGrid(4);
client = false;
for (int i = 0; i < 5; i++) info(">>> Node [idx=" + i + ", nodeId=" + ignite(i).cluster().localNode().id() + ']');
awaitPartitionMapExchange();
ClusterNode killNode = ignite(3).cluster().localNode();
int part = -1;
for (int i = 0; i < aff.partitions(); i++) {
if (aff.isPrimary(killNode, i)) {
part = i;
break;
}
}
if (part == -1)
throw new IllegalStateException("No partition on node: " + killNode);
final CountDownLatch[] partLost = new CountDownLatch[3];
// Check events.
for (int i = 0; i < 3; i++) {
final CountDownLatch latch = new CountDownLatch(1);
partLost[i] = latch;
final int part0 = part;
grid(i).events().localListen(new P1<Event>() {
@Override
public boolean apply(Event evt) {
assert evt.type() == EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST;
CacheRebalancingEvent cacheEvt = (CacheRebalancingEvent) evt;
if (cacheEvt.partition() == part0 && F.eq(CACHE_NAME, cacheEvt.cacheName())) {
latch.countDown();
// Auto-unsubscribe.
return false;
}
return true;
}
}, EventType.EVT_CACHE_REBALANCE_PART_DATA_LOST);
}
ignite(3).close();
for (CountDownLatch latch : partLost) assertTrue("Failed to wait for partition LOST event", latch.await(10, TimeUnit.SECONDS));
return part;
}
use of org.apache.ignite.events.CacheRebalancingEvent in project ignite by apache.
the class GridCacheDhtPreloadSelfTest method checkNodes.
/**
* @param keyCnt Key count.
* @param nodeCnt Node count.
* @param sameCoord Same coordinator flag.
* @param shuffle Shuffle flag.
* @throws Exception If failed.
*/
private void checkNodes(int keyCnt, int nodeCnt, boolean sameCoord, boolean shuffle) throws Exception {
try {
Ignite ignite1 = startGrid(0);
IgniteCache<Integer, String> cache1 = ignite1.cache(DEFAULT_CACHE_NAME);
putKeys(cache1, keyCnt);
checkKeys(cache1, keyCnt, F.asList(ignite1));
List<Ignite> ignites = new ArrayList<>(nodeCnt + 1);
startGrids(nodeCnt, 1, ignites);
// Check all nodes.
for (Ignite g : ignites) {
IgniteCache<Integer, String> c = g.cache(DEFAULT_CACHE_NAME);
checkKeys(c, keyCnt, ignites);
}
if (shuffle)
Collections.shuffle(ignites);
if (sameCoord)
// Add last.
ignites.add(ignite1);
else
// Add first.
ignites.add(0, ignite1);
if (!sameCoord && shuffle)
Collections.shuffle(ignites);
info(">>> Finished checking nodes [keyCnt=" + keyCnt + ", nodeCnt=" + nodeCnt + ", grids=" + U.grids2names(ignites) + ']');
Ignite last = null;
for (Iterator<Ignite> it = ignites.iterator(); it.hasNext(); ) {
Ignite g = it.next();
if (!it.hasNext()) {
last = g;
break;
}
final UUID nodeId = g.cluster().localNode().id();
it.remove();
Collection<IgniteFuture<?>> futs = new LinkedList<>();
for (Ignite gg : ignites) futs.add(waitForLocalEvent(gg.events(), new P1<Event>() {
@Override
public boolean apply(Event e) {
CacheRebalancingEvent evt = (CacheRebalancingEvent) e;
ClusterNode node = evt.discoveryNode();
return evt.type() == EVT_CACHE_REBALANCE_STOPPED && node.id().equals(nodeId) && (evt.discoveryEventType() == EVT_NODE_LEFT || evt.discoveryEventType() == EVT_NODE_FAILED);
}
}, EVT_CACHE_REBALANCE_STOPPED));
info("Before grid stop [name=" + g.name() + ", fullTop=" + top2string(ignites));
stopGrid(g.name());
info(">>> Waiting for preload futures [leftNode=" + g.name() + ", remaining=" + U.grids2names(ignites) + ']');
X.waitAll(futs);
info("After grid stop [name=" + g.name() + ", fullTop=" + top2string(ignites));
// Check all left nodes.
for (Ignite gg : ignites) {
IgniteCache<Integer, String> c = gg.cache(DEFAULT_CACHE_NAME);
checkKeys(c, keyCnt, ignites);
}
}
assert last != null;
IgniteCache<Integer, String> lastCache = last.cache(DEFAULT_CACHE_NAME);
GridDhtCacheAdapter<Integer, String> dht = dht(lastCache);
Affinity<Integer> aff = affinity(lastCache);
for (int i = 0; i < keyCnt; i++) {
if (aff.mapPartitionToPrimaryAndBackups(aff.partition(i)).contains(last.cluster().localNode())) {
GridDhtPartitionTopology top = dht.topology();
for (GridDhtLocalPartition p : top.localPartitions()) {
Collection<ClusterNode> moving = top.moving(p.id());
assert moving.isEmpty() : "Nodes with partition in moving state [part=" + p + ", moving=" + moving + ']';
assert OWNING == p.state() : "Invalid partition state for partition [part=" + p + ", map=" + top.partitionMap(false) + ']';
}
}
}
} catch (Error | Exception e) {
error("Test failed.", e);
throw e;
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.events.CacheRebalancingEvent in project ignite by apache.
the class GridCacheDhtPreloadSelfTest method checkActivePartitionTransfer.
/**
* @param keyCnt Key count.
* @param nodeCnt Node count.
* @param sameCoord Same coordinator flag.
* @param shuffle Shuffle flag.
* @throws Exception If failed.
*/
private void checkActivePartitionTransfer(int keyCnt, int nodeCnt, boolean sameCoord, boolean shuffle) throws Exception {
try {
Ignite ignite1 = startGrid(0);
IgniteCache<Integer, String> cache1 = ignite1.cache(DEFAULT_CACHE_NAME);
putKeys(cache1, keyCnt);
checkKeys(cache1, keyCnt, F.asList(ignite1));
List<Ignite> ignites = new ArrayList<>(nodeCnt + 1);
startGrids(nodeCnt, 1, ignites);
// Check all nodes.
for (Ignite g : ignites) {
IgniteCache<Integer, String> c = g.cache(DEFAULT_CACHE_NAME);
checkKeys(c, keyCnt, ignites);
}
if (shuffle)
Collections.shuffle(ignites);
if (sameCoord)
// Add last.
ignites.add(ignite1);
else
// Add first.
ignites.add(0, ignite1);
if (!sameCoord && shuffle)
Collections.shuffle(ignites);
checkActiveState(ignites);
info(">>> Finished checking nodes [keyCnt=" + keyCnt + ", nodeCnt=" + nodeCnt + ", grids=" + U.grids2names(ignites) + ']');
Collection<IgniteFuture<?>> futs = new LinkedList<>();
Ignite last = F.last(ignites);
for (Iterator<Ignite> it = ignites.iterator(); it.hasNext(); ) {
Ignite g = it.next();
if (!it.hasNext()) {
assert last == g;
break;
}
checkActiveState(ignites);
final UUID nodeId = g.cluster().localNode().id();
it.remove();
futs.add(waitForLocalEvent(last.events(), new P1<Event>() {
@Override
public boolean apply(Event e) {
CacheRebalancingEvent evt = (CacheRebalancingEvent) e;
ClusterNode node = evt.discoveryNode();
return evt.type() == EVT_CACHE_REBALANCE_STOPPED && node.id().equals(nodeId) && (evt.discoveryEventType() == EVT_NODE_LEFT || evt.discoveryEventType() == EVT_NODE_FAILED);
}
}, EVT_CACHE_REBALANCE_STOPPED));
info("Before grid stop [name=" + g.name() + ", fullTop=" + top2string(ignites));
stopGrid(g.name());
info("After grid stop [name=" + g.name() + ", fullTop=" + top2string(ignites));
// Check all left nodes.
checkActiveState(ignites);
}
info("Waiting for preload futures: " + F.view(futs, new IgnitePredicate<IgniteFuture<?>>() {
@Override
public boolean apply(IgniteFuture<?> fut) {
return !fut.isDone();
}
}));
X.waitAll(futs);
info("Finished waiting for preload futures.");
assert last != null;
IgniteCache<Integer, String> lastCache = last.cache(DEFAULT_CACHE_NAME);
GridDhtCacheAdapter<Integer, String> dht = dht(lastCache);
Affinity<Integer> aff = affinity(lastCache);
info("Finished waiting for all exchange futures...");
for (int i = 0; i < keyCnt; i++) {
if (aff.mapPartitionToPrimaryAndBackups(aff.partition(i)).contains(last.cluster().localNode())) {
GridDhtPartitionTopology top = dht.topology();
for (GridDhtLocalPartition p : top.localPartitions()) {
Collection<ClusterNode> moving = top.moving(p.id());
assert moving.isEmpty() : "Nodes with partition in moving state [part=" + p + ", moving=" + moving + ']';
assert OWNING == p.state() : "Invalid partition state for partition [part=" + p + ", map=" + top.partitionMap(false) + ']';
}
}
}
checkActiveState(ignites);
} catch (Error | Exception e) {
error("Test failed.", e);
throw e;
} finally {
stopAllGrids();
}
}
Aggregations