in modules/core/src/main/java/org/apache/ignite/internal/management/tx/TxTask.java [237:402]
public static TxTaskResult run(IgniteEx ignite, TxCommandArg arg, @Nullable TxInfoCommandArg infoArg) {
if (arg == null)
return new TxTaskResult(Collections.emptyList());
IgniteTxManager tm = ignite.context().cache().context().tm();
Collection<IgniteInternalTx> transactions = tm.activeTransactions();
List<TxInfo> infos = new ArrayList<>();
int limit = arg.limit() == null ? DEFAULT_LIMIT : arg.limit();
Pattern lbMatch = null;
if (arg.label() != null) {
try {
lbMatch = Pattern.compile(arg.label());
}
catch (PatternSyntaxException ignored) {
// No-op.
}
}
for (IgniteInternalTx locTx : transactions) {
if (infoArg != null && !Objects.equals(infoArg.gridCacheVersion(), locTx.nearXidVersion()))
continue;
if (arg.xid() != null && !locTx.xid().toString().equals(arg.xid()))
continue;
long duration = U.currentTimeMillis() - locTx.startTime();
if (arg.minDuration() != null && duration < arg.minDuration())
continue;
String lb = null;
int size = 0;
Collection<UUID> mappings = null;
TxKillClosure killClo = null;
// This filter conditions have meaning only for near txs, so we skip dht because it will never match.
boolean skip = arg.minSize() != null || lbMatch != null;
if (locTx instanceof GridNearTxLocal) {
GridNearTxLocal locTx0 = (GridNearTxLocal)locTx;
lb = locTx0.label();
if (lbMatch != null && !lbMatch.matcher(lb == null ? "null" : lb).matches())
continue;
mappings = new ArrayList<>();
if (locTx0.mappings() != null) {
IgniteTxMappings txMappings = locTx0.mappings();
for (GridDistributedTxMapping mapping :
txMappings.single() ? Collections.singleton(txMappings.singleMapping()) : txMappings.mappings()) {
if (mapping == null)
continue;
mappings.add(mapping.primary().id());
size += mapping.entries().size(); // Entries are not synchronized so no visibility guaranties for size.
}
}
if (arg.minSize() != null && size < arg.minSize())
continue;
killClo = NEAR_KILL_CLOSURE;
}
else if (locTx instanceof GridDhtTxLocal) {
if (skip)
continue;
GridDhtTxLocal locTx0 = (GridDhtTxLocal)locTx;
Map<UUID, GridDistributedTxMapping> dhtMap = U.field(locTx0, "dhtMap");
mappings = new ArrayList<>();
if (dhtMap != null) {
for (GridDistributedTxMapping mapping : dhtMap.values()) {
mappings.add(mapping.primary().id());
size += mapping.entries().size();
}
}
Map<UUID, GridDistributedTxMapping> nearMap = U.field(locTx, "nearMap");
if (nearMap != null) {
for (GridDistributedTxMapping mapping : nearMap.values()) {
mappings.add(mapping.primary().id());
size += mapping.entries().size();
}
}
killClo = LOCAL_KILL_CLOSURE;
}
else if (locTx instanceof GridDhtTxRemote) {
if (skip)
continue;
GridDhtTxRemote locTx0 = (GridDhtTxRemote)locTx;
size = locTx0.readMap().size() + locTx.writeMap().size();
killClo = REMOTE_KILL_CLOSURE;
}
TxVerboseInfo verboseInfo = infoArg != null ? createVerboseInfo(ignite, locTx) : null;
infos.add(new TxInfo(locTx.xid(), locTx.startTime(), duration, locTx.isolation(),
locTx.concurrency(), locTx.timeout(), lb, mappings, locTx.state(), size,
locTx.nearXidVersion().asIgniteUuid(), locTx.masterNodeIds(), locTx.topologyVersionSnapshot(),
verboseInfo));
if (arg.kill())
killClo.apply(locTx, tm);
if (infos.size() == limit)
break;
}
// If transaction was not found in verbose --tx --info mode, try to fetch it from history.
if (infoArg != null && infos.isEmpty()) {
Object completed = infoArg == null ? null : tm.peekCompletedVersionsHistory(infoArg.gridCacheVersion());
if (completed != null) {
if (Boolean.TRUE.equals(completed))
infos.add(new TxInfo(infoArg.gridCacheVersion().asIgniteUuid(), COMMITTED));
else if (Boolean.FALSE.equals(completed))
infos.add(new TxInfo(infoArg.gridCacheVersion().asIgniteUuid(), ROLLED_BACK));
}
}
Comparator<TxInfo> comp = TxDurationComparator.INSTANCE;
if (arg.order() != null) {
switch (arg.order()) {
case DURATION:
comp = TxDurationComparator.INSTANCE;
break;
case SIZE:
comp = TxSizeComparator.INSTANCE;
break;
case START_TIME:
comp = TxStartTimeComparator.INSTANCE;
break;
default:
}
}
Collections.sort(infos, comp);
return new TxTaskResult(infos);
}