Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toppartitions: Fix toppartitions to only jmx once #250

Merged
merged 1 commit into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/java/org/apache/cassandra/service/StorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5205,4 +5205,9 @@ public CompositeData getToppartitions(String sampler, List<String> keyspaceFilte
{
return null;
}

public Map<String, CompositeData> getToppartitions(List<String> samplers, List<String> keyspaceFilters, List<String> tableFilters, int duration, int capacity, int count) throws OpenDataException
{
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,8 @@ public interface StorageServiceMBean extends NotificationEmitter

public CompositeData getToppartitions(String sampler, List<String> keyspaceFilters, List<String> tableFilters, int duration, int capacity, int count) throws OpenDataException;

public Map<String, CompositeData> getToppartitions(List<String> samplers, List<String> keyspaceFilters, List<String> tableFilters, int duration, int capacity, int count) throws OpenDataException;

/**
* Resume bootstrap streaming when there is failed data streaming.
*
Expand Down
26 changes: 24 additions & 2 deletions src/java/org/apache/cassandra/tools/NodeProbe.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

import javax.management.InstanceNotFoundException;
import javax.management.JMX;
Expand Down Expand Up @@ -483,10 +484,31 @@ public Map<Sampler, CompositeData> getPartitionSample(String ks, String cf, int
public Map<Sampler, CompositeData> getToppartitions(List<String> keyspaceFilters, List<String> tableFilters, int capacity, int duration, int count, List<Sampler> samplers) throws OpenDataException
{
Map<Sampler, CompositeData> result = Maps.newHashMap();

try
{
Class[] cArg = new Class[6];
cArg[0] = cArg[1] = cArg[2] = (Class<List<String>>) Collections.<String>emptyList().getClass();
cArg[3] = cArg[4] = cArg[5] = int.class;

// make sure that JMX has the newer API, throws NoSuchMethodException if not
ssProxy.getClass().getMethod("getToppartitions", cArg);

for (Sampler sampler : samplers)
Map<String, CompositeData> toppartitions = ssProxy.getToppartitions(samplers.stream().map(sampler -> sampler.name().toLowerCase()).collect(Collectors.toList()),
keyspaceFilters, tableFilters, duration, capacity, count);

for (Sampler sampler : samplers)
{
result.put(sampler, toppartitions.get(sampler.name().toLowerCase()));
}
}
catch (NoSuchMethodException e)
{
result.put(sampler, ssProxy.getToppartitions(sampler.name(), keyspaceFilters, tableFilters, duration, capacity, count));
// fall back to the old JMX API
for (Sampler sampler : samplers)
{
result.put(sampler, ssProxy.getToppartitions(sampler.name(), keyspaceFilters, tableFilters, duration, capacity, count));
}
}

return result;
Expand Down