use of org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl in project ignite by apache.
the class AbstractDiscoverySelfTest method testLocalMetricsUpdate.
/**
* Tests whether local node metrics update cause METRICS_UPDATE event.
*
* @throws Exception If test failed.
*/
@Test
public void testLocalMetricsUpdate() throws Exception {
AtomicInteger[] locUpdCnts = new AtomicInteger[getSpiCount()];
int i = 0;
for (final DiscoverySpi spi : spis) {
final AtomicInteger spiCnt = new AtomicInteger(0);
DiscoverySpiListener locMetricsUpdateLsnr = new DiscoverySpiListener() {
/**
* {@inheritDoc}
*/
@Override
public void onLocalNodeInitialized(ClusterNode locNode) {
// No-op.
}
@Override
public IgniteFuture<?> onDiscovery(DiscoveryNotification notification) {
// If METRICS_UPDATED came from local node
if (notification.type() == EVT_NODE_METRICS_UPDATED && notification.getNode().id().equals(spi.getLocalNode().id()))
spiCnt.addAndGet(1);
return new IgniteFinishedFutureImpl<>();
}
};
locUpdCnts[i] = spiCnt;
spi.setListener(locMetricsUpdateLsnr);
i++;
}
// Sleep for 3 metrics update.
Thread.sleep(getMaxDiscoveryTime() * 3);
for (AtomicInteger cnt : locUpdCnts) assertTrue("One of the SPIs did not get at least 2 METRICS_UPDATE events from local node", cnt.get() > 1);
}
use of org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl in project ignite by apache.
the class GroupKeyChangeProcess method start.
/**
* Starts cache group encryption key change process.
*
* @param cacheOrGrpNames Cache or group names.
*/
public IgniteFuture<Void> start(Collection<String> cacheOrGrpNames) {
if (ctx.clientNode())
throw new UnsupportedOperationException("Client and daemon nodes can not perform this operation.");
if (!IgniteFeatures.allNodesSupports(ctx.grid().cluster().nodes(), CACHE_GROUP_KEY_CHANGE))
throw new IllegalStateException("Not all nodes in the cluster support this operation.");
if (!ctx.state().clusterState().state().active())
throw new IgniteException("Operation was rejected. The cluster is inactive.");
IgniteInternalFuture<Void> fut0 = fut;
if (fut0 != null && !fut0.isDone()) {
return new IgniteFinishedFutureImpl<>(new IgniteException("Cache group key change was rejected. " + "The previous change was not completed."));
}
int[] grpIds = new int[cacheOrGrpNames.size()];
byte[] keyIds = new byte[grpIds.length];
int n = 0;
for (String cacheOrGroupName : cacheOrGrpNames) {
CacheGroupDescriptor grpDesc = ctx.cache().cacheGroupDescriptor(CU.cacheId(cacheOrGroupName));
if (grpDesc == null) {
DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(cacheOrGroupName);
if (cacheDesc == null) {
throw new IgniteException("Cache group key change was rejected. " + "Cache or group \"" + cacheOrGroupName + "\" doesn't exists");
}
int grpId = cacheDesc.groupId();
grpDesc = ctx.cache().cacheGroupDescriptor(grpId);
if (grpDesc.sharedGroup()) {
throw new IgniteException("Cache group key change was rejected. " + "Cache or group \"" + cacheOrGroupName + "\" is a part of group \"" + grpDesc.groupName() + "\". Provide group name instead of cache name for shared groups.");
}
}
if (!grpDesc.config().isEncryptionEnabled()) {
throw new IgniteException("Cache group key change was rejected. " + "Cache or group \"" + cacheOrGroupName + "\" is not encrypted.");
}
if (ctx.encryption().reencryptionInProgress(grpDesc.groupId())) {
throw new IgniteException("Cache group key change was rejected. " + "Cache group reencryption is in progress [grp=" + cacheOrGroupName + "]");
}
grpIds[n] = grpDesc.groupId();
keyIds[n] = (byte) (ctx.encryption().getActiveKey(grpDesc.groupId()).unsignedId() + 1);
n += 1;
}
T2<Collection<byte[]>, byte[]> keysAndDigest = ctx.encryption().createKeys(grpIds.length);
ChangeCacheEncryptionRequest req = new ChangeCacheEncryptionRequest(grpIds, keysAndDigest.get1().toArray(new byte[grpIds.length][]), keyIds, keysAndDigest.get2());
fut = new GroupKeyChangeFuture(req);
prepareGKChangeProc.start(req.requestId(), req);
return new IgniteFutureImpl<>(fut);
}
use of org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl in project ignite by apache.
the class IgniteSnapshotManager method createSnapshot.
/**
* {@inheritDoc}
*/
@Override
public IgniteFuture<Void> createSnapshot(String name) {
A.notNullOrEmpty(name, "Snapshot name cannot be null or empty.");
A.ensure(U.alphanumericUnderscore(name), "Snapshot name must satisfy the following name pattern: a-zA-Z0-9_");
try {
cctx.kernalContext().security().authorize(ADMIN_SNAPSHOT);
if (!IgniteFeatures.allNodesSupports(cctx.discovery().aliveServerNodes(), PERSISTENCE_CACHE_SNAPSHOT))
throw new IgniteException("Not all nodes in the cluster support a snapshot operation.");
if (!CU.isPersistenceEnabled(cctx.gridConfig())) {
throw new IgniteException("Create snapshot request has been rejected. Snapshots on an in-memory " + "clusters are not allowed.");
}
if (!cctx.kernalContext().state().clusterState().state().active())
throw new IgniteException("Snapshot operation has been rejected. The cluster is inactive.");
DiscoveryDataClusterState clusterState = cctx.kernalContext().state().clusterState();
if (!clusterState.hasBaselineTopology())
throw new IgniteException("Snapshot operation has been rejected. The baseline topology is not configured for cluster.");
if (cctx.kernalContext().clientNode()) {
ClusterNode crd = U.oldest(cctx.kernalContext().discovery().aliveServerNodes(), null);
if (crd == null)
throw new IgniteException("There is no alive server nodes in the cluster");
return new IgniteSnapshotFutureImpl(cctx.kernalContext().closure().callAsyncNoFailover(BALANCE, new CreateSnapshotCallable(name), Collections.singletonList(crd), false, 0, true));
}
ClusterSnapshotFuture snpFut0;
synchronized (snpOpMux) {
if (clusterSnpFut != null && !clusterSnpFut.isDone()) {
throw new IgniteException("Create snapshot request has been rejected. The previous snapshot operation was not completed.");
}
if (clusterSnpReq != null)
throw new IgniteException("Create snapshot request has been rejected. Parallel snapshot processes are not allowed.");
if (localSnapshotNames().contains(name)) {
throw new IgniteException("Create snapshot request has been rejected. Snapshot with given name already exists on local node.");
}
if (isRestoring()) {
throw new IgniteException("Snapshot operation has been rejected. Cache group restore operation is currently in progress.");
}
snpFut0 = new ClusterSnapshotFuture(UUID.randomUUID(), name);
clusterSnpFut = snpFut0;
lastSeenSnpFut = snpFut0;
}
List<String> grps = cctx.cache().persistentGroups().stream().filter(g -> cctx.cache().cacheType(g.cacheOrGroupName()) == CacheType.USER).map(CacheGroupDescriptor::cacheOrGroupName).collect(Collectors.toList());
grps.add(METASTORAGE_CACHE_NAME);
List<ClusterNode> srvNodes = cctx.discovery().serverNodes(AffinityTopologyVersion.NONE);
snpFut0.listen(f -> {
if (f.error() == null)
recordSnapshotEvent(name, SNAPSHOT_FINISHED_MSG + grps, EVT_CLUSTER_SNAPSHOT_FINISHED);
else
recordSnapshotEvent(name, SNAPSHOT_FAILED_MSG + f.error().getMessage(), EVT_CLUSTER_SNAPSHOT_FAILED);
});
startSnpProc.start(snpFut0.rqId, new SnapshotOperationRequest(snpFut0.rqId, cctx.localNodeId(), name, grps, new HashSet<>(F.viewReadOnly(srvNodes, F.node2id(), (node) -> CU.baselineNode(node, clusterState)))));
String msg = "Cluster-wide snapshot operation started [snpName=" + name + ", grps=" + grps + ']';
recordSnapshotEvent(name, msg, EVT_CLUSTER_SNAPSHOT_STARTED);
if (log.isInfoEnabled())
log.info(msg);
return new IgniteFutureImpl<>(snpFut0);
} catch (Exception e) {
recordSnapshotEvent(name, SNAPSHOT_FAILED_MSG + e.getMessage(), EVT_CLUSTER_SNAPSHOT_FAILED);
U.error(log, SNAPSHOT_FAILED_MSG, e);
lastSeenSnpFut = new ClusterSnapshotFuture(name, e);
return new IgniteFinishedFutureImpl<>(e);
}
}
use of org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl in project ignite by apache.
the class GridClusterStateProcessor method publicApiStateAsync.
/**
* {@inheritDoc}
*/
@Override
public IgniteFuture<ClusterState> publicApiStateAsync(boolean asyncWaitForTransition) {
if (ctx.isDaemon())
return sendComputeCheckGlobalState();
DiscoveryDataClusterState globalState = this.globalState;
assert globalState != null;
if (globalState.transition() && globalState.state().active()) {
ClusterState transitionRes = globalState.transitionResult();
if (transitionRes != null)
return new IgniteFinishedFutureImpl<>(transitionRes);
else {
GridFutureAdapter<Void> fut = transitionFuts.get(globalState.transitionRequestId());
if (fut != null) {
if (asyncWaitForTransition) {
return new IgniteFutureImpl<>(fut.chain((C1<IgniteInternalFuture<Void>, ClusterState>) f -> {
ClusterState res = globalState.transitionResult();
assert res != null;
return res;
}));
} else
return new IgniteFinishedFutureImpl<>(stateWithMinimalFeatures(globalState.lastState(), globalState.state()));
}
transitionRes = globalState.transitionResult();
assert transitionRes != null;
return new IgniteFinishedFutureImpl<>(transitionRes);
}
} else
return new IgniteFinishedFutureImpl<>(globalState.state());
}
Aggregations