Skip to content

Commit

Permalink
IGNITE-15629 Cache contention command implemented (#10744)
Browse files Browse the repository at this point in the history
  • Loading branch information
nizhikov committed Jun 2, 2023
1 parent 08069c3 commit ab91727
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 243 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.ignite.internal.commandline.cache.argument.IndexRebuildCommandArg;
import org.apache.ignite.internal.management.cache.CacheCheckIndexInlineSizesCommand;
import org.apache.ignite.internal.management.cache.CacheClearCommand;
import org.apache.ignite.internal.management.cache.CacheContentionCommand;
import org.apache.ignite.internal.management.cache.CacheCreateCommand;
import org.apache.ignite.internal.management.cache.CacheDestroyCommand;
import org.apache.ignite.internal.management.cache.CacheIndexesForceRebuildCommand;
Expand Down Expand Up @@ -86,7 +87,7 @@ public enum CacheSubcommands {
/**
* Prints info about contended keys (the keys concurrently locked from multiple transactions).
*/
CONTENTION("contention", null, new CacheContention()),
CONTENTION(new CacheContentionCommand()),

/**
* Collect information on the distribution of partitions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ public static <T> T parseVal(String val, Class<T> type) {
.orElse(null);
}

/** */
public static Collection<UUID> nodeOrNull(@Nullable UUID nodeId) {
return nodeId == null ? null : Collections.singleton(nodeId);
}

/**
* @param nodes Nodes.
* @return Server nodes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public CacheCommand() {
new CacheClearCommand(),
new CacheValidateIndexesCommand(),
new CacheCheckIndexInlineSizesCommand(),
new CacheContentionCommand(),
new CacheResetLostPartitionsCommand(),
new CacheIndexesListCommand(),
new CacheIndexesRebuildStatusCommand(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.management.cache;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;
import java.util.function.Consumer;
import org.apache.ignite.internal.management.api.CommandUtils;
import org.apache.ignite.internal.management.api.ComputeCommand;
import org.apache.ignite.internal.processors.cache.verify.ContentionInfo;
import org.apache.ignite.internal.util.typedef.T3;
import org.apache.ignite.internal.visor.verify.VisorContentionTask;
import org.apache.ignite.internal.visor.verify.VisorContentionTaskResult;

/** */
public class CacheContentionCommand implements ComputeCommand<CacheContentionCommandArg, VisorContentionTaskResult> {
/** {@inheritDoc} */
@Override public String description() {
return "Show the keys that are point of contention for multiple transactions";
}

/** {@inheritDoc} */
@Override public Class<CacheContentionCommandArg> argClass() {
return CacheContentionCommandArg.class;
}

/** {@inheritDoc} */
@Override public Class<VisorContentionTask> taskClass() {
return VisorContentionTask.class;
}

/** {@inheritDoc} */
@Override public Collection<UUID> nodes(Map<UUID, T3<Boolean, Object, Long>> nodes, CacheContentionCommandArg arg) {
return arg.nodeId() == null ? nodes.keySet() : Collections.singleton(arg.nodeId());
}

/** {@inheritDoc} */
@Override public void printResult(CacheContentionCommandArg arg, VisorContentionTaskResult res, Consumer<String> printer) {
CommandUtils.printErrors(res.exceptions(), "Contention check failed on nodes:", printer);

for (ContentionInfo info : res.getInfos())
info.print();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.management.cache;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.UUID;
import org.apache.ignite.internal.dto.IgniteDataTransferObject;
import org.apache.ignite.internal.management.api.Argument;
import org.apache.ignite.internal.management.api.Positional;
import org.apache.ignite.internal.util.typedef.internal.U;

/** */
public class CacheContentionCommandArg extends IgniteDataTransferObject {
/** */
private static final long serialVersionUID = 0;

/** Min queue size. */
@Positional
@Argument(example = "minQueueSize")
private int minQueueSize;

/** Node id. */
@Positional
@Argument(optional = true, example = "nodeId")
private UUID nodeId;

/** Max print. */
@Positional
@Argument(optional = true, example = "maxPrint")
private int maxPrint = 10;

/** {@inheritDoc} */
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
U.writeUuid(out, nodeId);
out.writeInt(minQueueSize);
out.writeInt(maxPrint);
}

/** {@inheritDoc} */
@Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException {
nodeId = U.readUuid(in);
minQueueSize = in.readInt();
maxPrint = in.readInt();
}

/** */
public UUID nodeId() {
return nodeId;
}

/** */
public void nodeId(UUID nodeId) {
this.nodeId = nodeId;
}

/** */
public int minQueueSize() {
return minQueueSize;
}

/** */
public void minQueueSize(int minQueueSize) {
this.minQueueSize = minQueueSize;
}

/** */
public int maxPrint() {
return maxPrint;
}

/** */
public void maxPrint(int maxPrint) {
this.maxPrint = maxPrint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand All @@ -31,6 +30,7 @@
import org.apache.ignite.internal.visor.metric.VisorMetricTask;
import static java.util.Arrays.asList;
import static org.apache.ignite.internal.management.SystemViewCommand.printTable;
import static org.apache.ignite.internal.management.api.CommandUtils.nodeOrNull;
import static org.apache.ignite.internal.visor.systemview.VisorSystemViewTask.SimpleType.STRING;

/** */
Expand Down Expand Up @@ -61,7 +61,7 @@ public MetricCommand() {

/** {@inheritDoc} */
@Override public Collection<UUID> nodes(Map<UUID, T3<Boolean, Object, Long>> nodes, MetricCommandArg arg) {
return arg.nodeId() == null ? null : Collections.singleton(arg.nodeId());
return nodeOrNull(arg.nodeId());
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
package org.apache.ignite.internal.management.metric;

import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;
import org.apache.ignite.internal.management.api.ComputeCommand;
import org.apache.ignite.internal.util.typedef.T3;
import org.apache.ignite.internal.visor.metric.VisorMetricTask;
import static org.apache.ignite.internal.management.api.CommandUtils.nodeOrNull;

/** */
public class MetricConfigureHistogramCommand implements ComputeCommand<MetricCommandArg, Map<String, ?>> {
Expand All @@ -44,6 +44,6 @@ public class MetricConfigureHistogramCommand implements ComputeCommand<MetricCom

/** {@inheritDoc} */
@Override public Collection<UUID> nodes(Map<UUID, T3<Boolean, Object, Long>> nodes, MetricCommandArg arg) {
return arg.nodeId() == null ? null : Collections.singleton(arg.nodeId());
return nodeOrNull(arg.nodeId());
}
}

0 comments on commit ab91727

Please sign in to comment.