Skip to content

Commit

Permalink
nodetool: add triggeroffstrategycompaction
Browse files Browse the repository at this point in the history
Invoke new api to trigger offstrategy compaction
on keyspaces/tables.

Signed-off-by: Benny Halevy <[email protected]>
  • Loading branch information
bhalevy committed Jul 26, 2021
1 parent 4ef8049 commit 1f79949
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/java/org/apache/cassandra/service/StorageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,16 @@ public int forceKeyspaceCleanup(int jobs, String keyspaceName, String... tables)
return status.statusCode;
}

public int triggerKeyspaceOffstrategyCompaction(String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException
{
return triggerKeyspaceOffstrategyCompaction(0, keyspaceName, tables);
}

public int triggerKeyspaceOffstrategyCompaction(int jobs, String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException
{
throw new RuntimeException("triggerKeyspaceOffstrategyCompaction is not implemented");
}

public int scrub(boolean disableSnapshot, boolean skipCorrupted, String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException
{
return scrub(disableSnapshot, skipCorrupted, true, 0, keyspaceName, tables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ public interface StorageServiceMBean extends NotificationEmitter
public int forceKeyspaceCleanup(String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException;
public int forceKeyspaceCleanup(int jobs, String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException;

/**
* Trigger offstrategy compaction aon tables in single keyspace
*/
@Deprecated
public int triggerKeyspaceOffstrategyCompaction(String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException;
public int triggerKeyspaceOffstrategyCompaction(int jobs, String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException;

/**
* Scrub (deserialize + reserialize at the latest version, skipping bad rows if any) the given keyspace.
* If tableNames array is empty, all CFs are scrubbed.
Expand Down
21 changes: 21 additions & 0 deletions src/java/org/apache/cassandra/tools/NodeProbe.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,11 @@ public int forceKeyspaceCleanup(int jobs, String keyspaceName, String... tables)
return ssProxy.forceKeyspaceCleanup(jobs, keyspaceName, tables);
}

public int triggerKeyspaceOffstrategyCompaction(int jobs, String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException
{
return ssProxy.triggerKeyspaceOffstrategyCompaction(jobs, keyspaceName, tables);
}

public int scrub(boolean disableSnapshot, boolean skipCorrupted, boolean checkData, boolean reinsertOverflowedTTL, int jobs, String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException
{
return ssProxy.scrub(disableSnapshot, skipCorrupted, checkData, reinsertOverflowedTTL, jobs, keyspaceName, tables);
Expand Down Expand Up @@ -356,6 +361,22 @@ public void forceKeyspaceCleanup(PrintStream out, int jobs, String keyspaceName,
}
}

public void triggerKeyspaceOffstrategyCompaction(PrintStream out, int jobs, String keyspaceName, String... tableNames) throws IOException, ExecutionException, InterruptedException
{
checkJobs(out, jobs);
switch (triggerKeyspaceOffstrategyCompaction(jobs, keyspaceName, tableNames))
{
case 1:
failed = true;
out.println("Aborted offstrategy compaction of some tables in keyspace "+keyspaceName+", check server logs for more information.");
break;
case 2:
failed = true;
out.println("Failed offstrategy compaction of some tables in keyspace "+keyspaceName+", check server logs for more information");
break;
}
}

public void scrub(PrintStream out, boolean disableSnapshot, boolean skipCorrupted, boolean checkData, boolean reinsertOverflowedTTL, int jobs, String keyspaceName, String... tables) throws IOException, ExecutionException, InterruptedException
{
checkJobs(out, jobs);
Expand Down
1 change: 1 addition & 0 deletions src/java/org/apache/cassandra/tools/NodeTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public static void main(String... args)
// Remove for GA: InvalidateCounterCache.class,
// Remove for GA: Join.class,
Move.class,
OffstrategyCompaction.class,
// Remove for GA: PauseHandoff.class,
// Remove for GA: ResumeHandoff.class,
ProxyHistograms.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.cassandra.tools.nodetool;

import io.airlift.command.Arguments;
import io.airlift.command.Command;

import java.util.ArrayList;
import java.util.List;

import io.airlift.command.Option;
import org.apache.cassandra.config.SchemaConstants;
import org.apache.cassandra.tools.NodeProbe;
import org.apache.cassandra.tools.NodeTool.NodeToolCmd;

@Command(name = "triggeroffstrategycompaction", description = "Triggers offstrategy compaction of tables, if pending (e.g. post repair). By default, trigger offstrategy compaction in all keyspaces")
public class OffstrategyCompaction extends NodeToolCmd
{
@Arguments(usage = "[<keyspace> [<tables>...]]", description = "The keyspace followed by zero or more tables")
private List<String> args = new ArrayList<>();

@Option(title = "jobs",
name = {"-j", "--jobs"},
description = "Number of tables to trigger offstrategy compaction for simultanously, set to 0 to use all available compaction threads")
private int jobs = 0;

@Override
public void execute(NodeProbe probe)
{
List<String> keyspaces = parseOptionalKeyspace(args, probe, KeyspaceSet.NON_LOCAL_STRATEGY);
String[] tableNames = parseOptionalTables(args);

for (String keyspace : keyspaces)
{
if (SchemaConstants.isLocalSystemKeyspace(keyspace))
continue;

try
{
probe.triggerKeyspaceOffstrategyCompaction(System.out, jobs, keyspace, tableNames);
}
catch (Exception e)
{
throw new RuntimeException("Error occurred during trigger offstrategy compaction", e);
}
}
}
}

0 comments on commit 1f79949

Please sign in to comment.