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

CASSANDRA-20362: add setcacheperiod to nodetool #3925

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/java/org/apache/cassandra/tools/NodeProbe.java
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,14 @@ public void setCacheKeysToSave(int keyCacheKeysToSave, int rowCacheKeysToSave, i
cacheMBean.setCounterCacheKeysToSave(counterCacheKeysToSave);
}

public void setCachePeriod(int keyCachePeriod, int rowCachePeriod, int counterPeriod)
{
CacheServiceMBean cacheMBean = getCacheServiceMBean();
cacheMBean.setKeyCacheSavePeriodInSeconds(keyCachePeriod);
cacheMBean.setRowCacheSavePeriodInSeconds(rowCachePeriod);
cacheMBean.setCounterCacheSavePeriodInSeconds(counterPeriod);
}

public void setHintedHandoffThrottleInKB(int throttleInKB)
{
ssProxy.setHintedHandoffThrottleInKB(throttleInKB);
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 @@ -202,6 +202,7 @@ public int execute(String... args)
SetBatchlogReplayThrottle.class,
SetCacheCapacity.class,
SetCacheKeysToSave.class,
SetCachePeriod.class,
SetColumnIndexSize.class,
SetCompactionThreshold.class,
SetCompactionThroughput.class,
Expand Down
45 changes: 45 additions & 0 deletions src/java/org/apache/cassandra/tools/nodetool/SetCachePeriod.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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 java.util.ArrayList;
import java.util.List;

import io.airlift.airline.Arguments;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See CASSANDRA-17445 airlift will be deprecated

import io.airlift.airline.Command;
import org.apache.cassandra.tools.NodeProbe;
import org.apache.cassandra.tools.NodeTool.NodeToolCmd;

import static com.google.common.base.Preconditions.checkArgument;

@Command(name = "setcacheperiod", description = "Set global key, row, and counter cache period in second units")
public class SetCachePeriod extends NodeToolCmd
{
@Arguments(title = "<key-cache-period> <row-cache-period> <counter-cache-period>",
usage = "<key-cache-period> <row-cache-period> <counter-cache-period>",
description = "Key cache, row cache, and counter period in second units",
required = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add test case for this

private List<Integer> args = new ArrayList<>();

@Override
public void execute(NodeProbe probe)
{
checkArgument(args.size() == 3, "setcacheperiod requires key-cache-period, row-cache-period, and counter-cache-period args.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can add some argument -k for keyache , -r for row cache, -c for counter
And I think not all of these arguments are needed at one time for user.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found your code has the same format with SetCacheCapacity/SetCacheKeysToSave , I'm not forcing you to do this now.

probe.setCachePeriod(args.get(0), args.get(1), args.get(2));
}
}
106 changes: 106 additions & 0 deletions test/unit/org/apache/cassandra/tools/nodetool/SetCachePeriodTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* 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 org.junit.BeforeClass;
import org.junit.Test;

import org.apache.cassandra.cql3.CQLTester;
import org.apache.cassandra.service.CacheService;
import org.apache.cassandra.tools.ToolRunner;

import static org.assertj.core.api.Assertions.assertThat;

public class SetCachePeriodTest extends CQLTester
{
private static CacheService cacheService;

@BeforeClass
public static void setup() throws Exception
{
requireNetwork();
startJMXServer();
cacheService = CacheService.instance;
}

@Test
public void testHelp()
{
ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("help", "setcacheperiod");
tool.assertOnExitCode();

String help = "NAME\n" +
" nodetool setcacheperiod - Set global key, row, and counter cache period\n" +
" in second units\n" +
"\n" +
"SYNOPSIS\n" +
" nodetool [(-h <host> | --host <host>)] [(-p <port> | --port <port>)]\n" +
" [(-pp | --print-port)] [(-pw <password> | --password <password>)]\n" +
" [(-pwf <passwordFilePath> | --password-file <passwordFilePath>)]\n" +
" [(-u <username> | --username <username>)] setcacheperiod [--]\n" +
" <key-cache-period> <row-cache-period> <counter-cache-period>\n" +
"\n" +
"OPTIONS\n" +
" -h <host>, --host <host>\n" +
" Node hostname or ip address\n" +
"\n" +
" -p <port>, --port <port>\n" +
" Remote jmx agent port number\n" +
"\n" +
" -pp, --print-port\n" +
" Operate in 4.0 mode with hosts disambiguated by port number\n" +
"\n" +
" -pw <password>, --password <password>\n" +
" Remote jmx agent password\n" +
"\n" +
" -pwf <passwordFilePath>, --password-file <passwordFilePath>\n" +
" Path to the JMX password file\n" +
"\n" +
" -u <username>, --username <username>\n" +
" Remote jmx agent username\n" +
"\n" +
" --\n" +
" This option can be used to separate command-line options from the\n" +
" list of argument, (useful when arguments might be mistaken for\n" +
" command-line options\n" +
"\n" +
" <key-cache-period> <row-cache-period> <counter-cache-period>\n" +
" Key cache, row cache, and counter period in second units\n" +
"\n" +
"\n";
assertThat(tool.getStdout()).isEqualTo(help);
}

@Test
public void testOptionalParameters()
{
int keyPeriodSetting = 333;
int rowPeriodSetting = 444;
int counterPeriodSetting = 555;
ToolRunner.ToolResult tool = ToolRunner.invokeNodetool("setcacheperiod",
String.valueOf(keyPeriodSetting),
String.valueOf(rowPeriodSetting),
String.valueOf(counterPeriodSetting));
tool.assertOnCleanExit();
assertThat(tool.getStdout()).isEmpty();

assertThat(cacheService.getKeyCacheSavePeriodInSeconds()).isEqualTo(keyPeriodSetting);
assertThat(cacheService.getRowCacheSavePeriodInSeconds()).isEqualTo(rowPeriodSetting);
assertThat(cacheService.getCounterCacheSavePeriodInSeconds()).isEqualTo(counterPeriodSetting);
}
}