use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.
the class GridCacheAdapter method sizeLongAsync.
/**
* {@inheritDoc}
*/
@Override
public IgniteInternalFuture<Long> sizeLongAsync(final int part, final CachePeekMode[] peekModes) {
assert peekModes != null;
final PeekModes modes = parsePeekModes(peekModes, true);
IgniteClusterEx cluster = ctx.grid().cluster();
final GridCacheAffinityManager aff = ctx.affinity();
final AffinityTopologyVersion topVer = aff.affinityTopologyVersion();
ClusterGroup grp = cluster.forDataNodes(name());
Collection<ClusterNode> nodes = new ArrayList<>(grp.forPredicate(new IgnitePredicate<ClusterNode>() {
/**
* {@inheritDoc}
*/
@Override
public boolean apply(ClusterNode clusterNode) {
return ((modes.primary && aff.primaryByPartition(clusterNode, part, topVer)) || (modes.backup && aff.backupByPartition(clusterNode, part, topVer)));
}
}).nodes());
if (nodes.isEmpty())
return new GridFinishedFuture<>(0L);
ctx.kernalContext().task().setThreadContext(TC_SUBGRID, nodes);
return ctx.kernalContext().task().execute(new PartitionSizeLongTask(ctx.name(), ctx.affinity().affinityTopologyVersion(), peekModes, part), null);
}
use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.
the class GridBaselineCommandHandler method currentState.
/**
* Collect baseline topology command result.
*
* @return Baseline descriptor.
*/
private GridBaselineCommandResponse currentState() {
IgniteClusterEx cluster = ctx.grid().cluster();
Collection<? extends BaselineNode> srvrs = cluster.forServers().nodes();
return new GridBaselineCommandResponse(cluster.active(), cluster.topologyVersion(), currentBaseLine(), srvrs);
}
use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.
the class GridBaselineCommandHandler method handleAsync.
/**
* {@inheritDoc}
*/
@Override
public IgniteInternalFuture<GridRestResponse> handleAsync(GridRestRequest req) {
assert req != null;
assert SUPPORTED_COMMANDS.contains(req.command());
assert req instanceof GridRestBaselineRequest : "Invalid type of baseline request.";
if (log.isDebugEnabled())
log.debug("Handling baseline REST request: " + req);
GridRestBaselineRequest req0 = (GridRestBaselineRequest) req;
try {
IgniteClusterEx cluster = ctx.grid().cluster();
List<Object> consistentIds = req0.consistentIds();
switch(req0.command()) {
case BASELINE_CURRENT_STATE:
{
break;
}
case BASELINE_SET:
{
Long topVer = req0.topologyVersion();
if (topVer == null && consistentIds == null)
throw new IgniteCheckedException("Failed to handle request (either topVer or consistentIds should be specified).");
if (topVer != null)
cluster.setBaselineTopology(topVer);
else
cluster.setBaselineTopology(filterServerNodesByConsId(consistentIds));
break;
}
case BASELINE_ADD:
{
if (consistentIds == null)
throw new IgniteCheckedException(missingParameter("consistentIds"));
Set<BaselineNode> baselineTop = new HashSet<>(currentBaseLine());
baselineTop.addAll(filterServerNodesByConsId(consistentIds));
cluster.setBaselineTopology(baselineTop);
break;
}
case BASELINE_REMOVE:
{
if (consistentIds == null)
throw new IgniteCheckedException(missingParameter("consistentIds"));
Collection<BaselineNode> baseline = currentBaseLine();
Set<BaselineNode> baselineTop = new HashSet<>(baseline);
baselineTop.removeAll(filterNodesByConsId(baseline, consistentIds));
cluster.setBaselineTopology(baselineTop);
break;
}
default:
assert false : "Invalid command for baseline handler: " + req;
}
return new GridFinishedFuture<>(new GridRestResponse(currentState()));
} catch (IgniteCheckedException e) {
return new GridFinishedFuture<>(e);
} finally {
if (log.isDebugEnabled())
log.debug("Handled baseline REST request: " + req);
}
}
use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.
the class BaselineEventsTest method testChangeAutoAdjustTimeout.
/**
*/
@Test
public void testChangeAutoAdjustTimeout() throws Exception {
IgniteClusterEx cluster = startGrids(2).cluster();
cluster.active(true);
AtomicLong autoAdjustTimeout = new AtomicLong();
listen(grid(0), event -> {
BaselineConfigurationChangedEvent bltCfgChangedEvt = (BaselineConfigurationChangedEvent) event;
autoAdjustTimeout.set(bltCfgChangedEvt.autoAdjustTimeout());
return true;
}, EventType.EVT_BASELINE_AUTO_ADJUST_AWAITING_TIME_CHANGED);
assertEquals(CommandHandler.EXIT_CODE_OK, new CommandHandler().execute(Arrays.asList("--baseline", "auto_adjust", "enable", "timeout", "10", "--yes")));
assertTrue(GridTestUtils.waitForCondition(() -> autoAdjustTimeout.get() == 10L, 3_000));
cluster.baselineAutoAdjustTimeout(50);
assertTrue(GridTestUtils.waitForCondition(() -> autoAdjustTimeout.get() == 50L, 3_000));
}
use of org.apache.ignite.internal.cluster.IgniteClusterEx in project ignite by apache.
the class IgniteIndexReaderTest method populateData.
/**
* Filling node with data.
*
* @param node Node.
* @param insert {@code True} for inserting some data and creating tables and indexes,
* {@code false} for inserting, updating and deleting data and deleting indexes, {@code null} for all data processing.
* {@code True} if only insert data, {@code false} if delete from {@link #DEFAULT_CACHE_NAME} and {@code null} all at once.
* @throws Exception If fails.
*/
protected void populateData(IgniteEx node, @Nullable Boolean insert) throws Exception {
requireNonNull(node);
IgniteClusterEx cluster = node.cluster();
if (!cluster.active())
cluster.active(true);
IgniteCache<Integer, Object> qryCache = node.cache(QUERY_CACHE_NAME);
int s = isNull(insert) || insert ? 0 : 70;
int e = isNull(insert) || !insert ? 100 : 80;
for (int i = s; i < e; i++) qryCache.put(i, new TestClass1(i, valueOf(i)));
s = isNull(insert) || insert ? 0 : 50;
e = isNull(insert) || !insert ? 70 : 60;
for (int i = s; i < e; i++) qryCache.put(i, new TestClass2(i, valueOf(i)));
IgniteCache<Integer, Integer> cache = node.cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < CREATED_TABLES_CNT; i++) createAndFillTable(cache, TableInfo.generate(i), insert);
forceCheckpoint(node);
}
Aggregations