use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class IgnitionEx method start0.
/**
* Starts grid with given configuration.
*
* @param startCtx Start context.
* @param failIfStarted Throw or not an exception if grid is already started.
* @return Tuple with: grid instance and flag to indicate the instance is started by this call.
* So, when the new ignite instance is started the flag is {@code true}. If an existing instance is returned
* the flag is {@code false}.
* @throws IgniteCheckedException If grid could not be started.
*/
private static T2<IgniteNamedInstance, Boolean> start0(GridStartContext startCtx, boolean failIfStarted) throws IgniteCheckedException {
assert startCtx != null;
String name = startCtx.config().getIgniteInstanceName();
if (name != null && name.isEmpty())
throw new IgniteCheckedException("Non default Ignite instances cannot have empty string name.");
IgniteNamedInstance grid = new IgniteNamedInstance(name);
IgniteNamedInstance old;
if (name != null)
old = grids.putIfAbsent(name, grid);
else {
synchronized (dfltGridMux) {
old = dfltGrid;
if (old == null)
dfltGrid = grid;
}
}
if (old != null)
if (failIfStarted) {
if (name == null)
throw new IgniteCheckedException("Default Ignite instance has already been started.");
else
throw new IgniteCheckedException("Ignite instance with this name has already been started: " + name);
} else
return new T2<>(old, false);
if (startCtx.config().getWarmupClosure() != null)
startCtx.config().getWarmupClosure().apply(startCtx.config());
startCtx.single(grids.size() == 1);
boolean success = false;
try {
try {
grid.start(startCtx);
} catch (IgniteInterruptedCheckedException e) {
if (grid.starterThreadInterrupted)
Thread.interrupted();
throw e;
}
notifyStateChange(name, STARTED);
success = true;
} finally {
if (!success) {
if (name != null)
grids.remove(name, grid);
else {
synchronized (dfltGridMux) {
if (dfltGrid == grid)
dfltGrid = null;
}
}
grid = null;
}
}
if (grid == null)
throw new IgniteCheckedException("Failed to start grid with provided configuration.");
return new T2<>(grid, true);
}
use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class GridCachePartitionExchangeManager method createPartitionsSingleMessage.
/**
* @param targetNode Target node.
* @param exchangeId ID.
* @param clientOnlyExchange Client exchange flag.
* @param sndCounters {@code True} if need send partition update counters.
* @return Message.
*/
public GridDhtPartitionsSingleMessage createPartitionsSingleMessage(ClusterNode targetNode, @Nullable GridDhtPartitionExchangeId exchangeId, boolean clientOnlyExchange, boolean sndCounters) {
GridDhtPartitionsSingleMessage m = new GridDhtPartitionsSingleMessage(exchangeId, clientOnlyExchange, cctx.versions().last(), true);
Map<Object, T2<Integer, Map<Integer, GridDhtPartitionState>>> dupData = new HashMap<>();
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (!cacheCtx.isLocal()) {
GridDhtPartitionMap locMap = cacheCtx.topology().localPartitionMap();
addPartitionMap(m, dupData, true, cacheCtx.cacheId(), locMap, cacheCtx.affinity().affinityCache().similarAffinityKey());
if (sndCounters)
m.partitionUpdateCounters(cacheCtx.cacheId(), cacheCtx.topology().updateCounters(true));
}
}
for (GridClientPartitionTopology top : clientTops.values()) {
if (m.partitions() != null && m.partitions().containsKey(top.cacheId()))
continue;
GridDhtPartitionMap locMap = top.localPartitionMap();
addPartitionMap(m, dupData, true, top.cacheId(), locMap, top.similarAffinityKey());
if (sndCounters)
m.partitionUpdateCounters(top.cacheId(), top.updateCounters(true));
}
return m;
}
use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class GridDhtPartitionTopologyImpl method update.
/** {@inheritDoc} */
@SuppressWarnings({ "MismatchedQueryAndUpdateOfCollection" })
@Override
public GridDhtPartitionMap update(@Nullable GridDhtPartitionExchangeId exchId, GridDhtPartitionFullMap partMap, @Nullable Map<Integer, T2<Long, Long>> cntrMap) {
if (log.isDebugEnabled())
log.debug("Updating full partition map [exchId=" + exchId + ", parts=" + fullMapString() + ']');
assert partMap != null;
lock.writeLock().lock();
try {
if (stopping)
return null;
if (cntrMap != null) {
// update local map partition counters
for (Map.Entry<Integer, T2<Long, Long>> e : cntrMap.entrySet()) {
T2<Long, Long> cntr = this.cntrMap.get(e.getKey());
if (cntr == null || cntr.get2() < e.getValue().get2())
this.cntrMap.put(e.getKey(), e.getValue());
}
// update local counters in partitions
for (int i = 0; i < locParts.length(); i++) {
GridDhtLocalPartition part = locParts.get(i);
if (part == null)
continue;
T2<Long, Long> cntr = cntrMap.get(part.id());
if (cntr != null)
part.updateCounter(cntr.get2());
}
}
//if need skip
if (exchId != null && lastExchangeId != null && lastExchangeId.compareTo(exchId) >= 0) {
if (log.isDebugEnabled())
log.debug("Stale exchange id for full partition map update (will ignore) [lastExchId=" + lastExchangeId + ", exchId=" + exchId + ']');
return null;
}
if (node2part != null && node2part.compareTo(partMap) >= 0) {
if (log.isDebugEnabled())
log.debug("Stale partition map for full partition map update (will ignore) [lastExchId=" + lastExchangeId + ", exchId=" + exchId + ", curMap=" + node2part + ", newMap=" + partMap + ']');
return null;
}
long updateSeq = this.updateSeq.incrementAndGet();
if (exchId != null)
lastExchangeId = exchId;
if (node2part != null) {
for (GridDhtPartitionMap part : node2part.values()) {
GridDhtPartitionMap newPart = partMap.get(part.nodeId());
// then we keep the newer value.
if (newPart != null && (newPart.updateSequence() < part.updateSequence() || (cctx.startTopologyVersion().compareTo(newPart.topologyVersion()) > 0))) {
if (log.isDebugEnabled())
log.debug("Overriding partition map in full update map [exchId=" + exchId + ", curPart=" + mapString(part) + ", newPart=" + mapString(newPart) + ']');
partMap.put(part.nodeId(), part);
}
}
// Remove entry if node left.
for (Iterator<UUID> it = partMap.keySet().iterator(); it.hasNext(); ) {
UUID nodeId = it.next();
if (!cctx.discovery().alive(nodeId)) {
if (log.isDebugEnabled())
log.debug("Removing left node from full map update [nodeId=" + nodeId + ", partMap=" + partMap + ']');
it.remove();
}
}
}
node2part = partMap;
Map<Integer, Set<UUID>> p2n = new HashMap<>(cctx.affinity().partitions(), 1.0f);
for (Map.Entry<UUID, GridDhtPartitionMap> e : partMap.entrySet()) {
for (Integer p : e.getValue().keySet()) {
Set<UUID> ids = p2n.get(p);
if (ids == null)
// Initialize HashSet to size 3 in anticipation that there won't be
// more than 3 nodes per partitions.
p2n.put(p, ids = U.newHashSet(3));
ids.add(e.getKey());
}
}
part2node = p2n;
boolean changed = false;
AffinityTopologyVersion affVer = cctx.affinity().affinityTopologyVersion();
GridDhtPartitionMap nodeMap = partMap.get(cctx.localNodeId());
if (nodeMap != null && cctx.shared().database().persistenceEnabled()) {
for (Map.Entry<Integer, GridDhtPartitionState> e : nodeMap.entrySet()) {
int p = e.getKey();
GridDhtPartitionState state = e.getValue();
if (state == MOVING) {
GridDhtLocalPartition locPart = locParts.get(p);
assert locPart != null;
if (locPart.state() == OWNING) {
locPart.moving();
changed = true;
}
if (cntrMap != null) {
T2<Long, Long> cntr = cntrMap.get(p);
if (cntr != null && cntr.get2() > locPart.updateCounter())
locPart.updateCounter(cntr.get2());
}
}
}
}
if (!affVer.equals(AffinityTopologyVersion.NONE) && affVer.compareTo(topVer) >= 0) {
List<List<ClusterNode>> aff = cctx.affinity().assignments(topVer);
changed |= checkEvictions(updateSeq, aff);
updateRebalanceVersion(aff);
}
consistencyCheck();
if (log.isDebugEnabled())
log.debug("Partition map after full update: " + fullMapString());
if (changed)
cctx.shared().exchange().scheduleResendPartitions();
return changed ? localPartitionMap() : null;
} finally {
lock.writeLock().unlock();
}
}
use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class CacheContinuousQueryHandler method getOrCreatePartitionRecovery.
/**
* @param ctx Context.
* @param partId Partition id.
* @param topVer Topology version for current operation.
* @return Partition recovery.
*/
@NotNull
private CacheContinuousQueryPartitionRecovery getOrCreatePartitionRecovery(GridKernalContext ctx, int partId, AffinityTopologyVersion topVer) {
assert topVer != null && topVer.topologyVersion() > 0 : topVer;
CacheContinuousQueryPartitionRecovery rec = rcvs.get(partId);
if (rec == null) {
T2<Long, Long> partCntrs = null;
Map<UUID, Map<Integer, T2<Long, Long>>> initUpdCntrsPerNode = this.initUpdCntrsPerNode;
if (initUpdCntrsPerNode != null) {
GridCacheContext<K, V> cctx = cacheContext(ctx);
GridCacheAffinityManager aff = cctx.affinity();
for (ClusterNode node : aff.nodesByPartition(partId, topVer)) {
Map<Integer, T2<Long, Long>> map = initUpdCntrsPerNode.get(node.id());
if (map != null) {
partCntrs = map.get(partId);
break;
}
}
} else if (initUpdCntrs != null)
partCntrs = initUpdCntrs.get(partId);
rec = new CacheContinuousQueryPartitionRecovery(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), topVer, partCntrs != null ? partCntrs.get2() : null);
CacheContinuousQueryPartitionRecovery oldRec = rcvs.putIfAbsent(partId, rec);
if (oldRec != null)
rec = oldRec;
}
return rec;
}
use of org.apache.ignite.internal.util.typedef.T2 in project ignite by apache.
the class DataStructuresProcessor method removeDataStructure.
/**
* @param c Closure.
* @param name Data structure name.
* @param type Data structure type.
* @param afterRmv Optional closure to run after data structure removed.
* @throws IgniteCheckedException If failed.
*/
private <T> void removeDataStructure(final IgniteOutClosureX<T> c, String name, DataStructureType type, @Nullable final IgniteInClosureX<T> afterRmv) throws IgniteCheckedException {
Map<String, DataStructureInfo> dsMap = utilityCache.get(DATA_STRUCTURES_KEY);
if (dsMap == null || !dsMap.containsKey(name))
return;
final DataStructureInfo dsInfo = new DataStructureInfo(name, type, null);
IgniteCheckedException err = validateDataStructure(dsMap, dsInfo, false);
if (err != null)
throw err;
retryTopologySafe(new IgniteOutClosureX<Void>() {
@Override
public Void applyx() throws IgniteCheckedException {
try (GridNearTxLocal tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
T2<Boolean, IgniteCheckedException> res = utilityCache.invoke(DATA_STRUCTURES_KEY, new RemoveDataStructureProcessor(dsInfo)).get();
IgniteCheckedException err = res.get2();
if (err != null)
throw err;
assert res.get1() != null;
boolean exists = res.get1();
if (!exists)
return null;
T rmvInfo = c.applyx();
tx.commit();
if (afterRmv != null && rmvInfo != null)
afterRmv.applyx(rmvInfo);
return null;
}
}
});
}
Aggregations