Skip to content

Commit 70d1d34

Browse files
committed
ARTEMIS-5100 support modifying journal-max-io on 'create' CLI command
1 parent d54c771 commit 70d1d34

File tree

2 files changed

+117
-3
lines changed

2 files changed

+117
-3
lines changed

artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java

+30-3
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ public String[] getStaticNodes() {
298298
@Option(names = "--security-manager", description = "Which security manager to use - jaas or basic. Default: jaas.")
299299
private String securityManager = "jaas";
300300

301+
@Option(names = "--journal-max-io", description = "The journal-max-io value to use when also using the ASYNCIO journal-type. When using NIO or MAPPED this value is always '1'. Default: 4096")
302+
private int journalMaxIo = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoAio();
303+
301304
@Option(names = "--jdbc-bindings-table-name", description = "Name of the jdbc bindings table.")
302305
private String jdbcBindings = ActiveMQDefaultConfiguration.getDefaultBindingsTableName();
303306

@@ -502,6 +505,30 @@ public void setRole(String role) {
502505
this.role = role;
503506
}
504507

508+
public int getJournalMaxIo() {
509+
return journalMaxIo;
510+
}
511+
512+
public void setJournalMaxIo(int journalMaxIo) {
513+
this.journalMaxIo = journalMaxIo;
514+
}
515+
516+
public boolean isAio() {
517+
return aio;
518+
}
519+
520+
public void setAio(boolean aio) {
521+
this.aio = aio;
522+
}
523+
524+
public boolean isNio() {
525+
return nio;
526+
}
527+
528+
public void setNio(boolean nio) {
529+
this.nio = nio;
530+
}
531+
505532
private boolean isBackup() {
506533
return slave || backup;
507534
}
@@ -862,7 +889,7 @@ public Object run(ActionContext context) throws Exception {
862889
context.out.println(String.format(" \"%s\" run", path(new File(directory, "bin/artemis"))));
863890

864891
File service = new File(directory, BIN_ARTEMIS_SERVICE);
865-
context.out.println("");
892+
context.out.println();
866893

867894
if (IS_NIX) {
868895
context.out.println("Or you can run the broker in the background using:");
@@ -1049,7 +1076,7 @@ private void performAutoTune(Map<String, String> filters, JournalType journalTyp
10491076
Map<String, String> syncFilter = new HashMap<>();
10501077
syncFilter.put("${nanoseconds}", "0");
10511078
syncFilter.put("${writesPerMillisecond}", "0");
1052-
syncFilter.put("${maxaio}", journalType == JournalType.ASYNCIO ? "" + ActiveMQDefaultConfiguration.getDefaultJournalMaxIoAio() : "1");
1079+
syncFilter.put("${maxaio}", "1");
10531080

10541081
getActionContext().out.println("...Since you disabled sync and are using MAPPED journal, we are diabling buffer times");
10551082

@@ -1066,7 +1093,7 @@ private void performAutoTune(Map<String, String> filters, JournalType journalTyp
10661093
Map<String, String> syncFilter = new HashMap<>();
10671094
syncFilter.put("${nanoseconds}", Long.toString(nanoseconds));
10681095
syncFilter.put("${writesPerMillisecond}", writesPerMillisecondStr);
1069-
syncFilter.put("${maxaio}", journalType == JournalType.ASYNCIO ? "" + ActiveMQDefaultConfiguration.getDefaultJournalMaxIoAio() : "1");
1096+
syncFilter.put("${maxaio}", journalType == JournalType.ASYNCIO ? "" + journalMaxIo : "1");
10701097

10711098
getActionContext().out.println("done! Your system can make " + writesPerMillisecondStr +
10721099
" writes per millisecond, your journal-buffer-timeout will be " + nanoseconds);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.artemis.cli.commands;
18+
19+
import java.io.BufferedReader;
20+
import java.io.File;
21+
import java.io.FileReader;
22+
import java.io.IOException;
23+
24+
import org.apache.activemq.artemis.tests.extensions.TargetTempDirFactory;
25+
import org.apache.activemq.artemis.utils.RandomUtil;
26+
import org.apache.activemq.cli.test.TestActionContext;
27+
import org.junit.jupiter.api.BeforeEach;
28+
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.api.io.TempDir;
30+
31+
import static org.junit.jupiter.api.Assertions.assertFalse;
32+
import static org.junit.jupiter.api.Assertions.assertTrue;
33+
34+
public class CreateTestIndividualSettings {
35+
36+
@TempDir(factory = TargetTempDirFactory.class)
37+
public File temporaryFolder;
38+
39+
public TestActionContext context;
40+
public File testInstance;
41+
42+
@BeforeEach
43+
public void setUp() {
44+
context = new TestActionContext();
45+
testInstance = new File(temporaryFolder, "test-instance");
46+
}
47+
48+
@Test
49+
public void testJournalMaxIo() throws Exception {
50+
int journalMaxIo = RandomUtil.randomInt();
51+
52+
Create c = new Create();
53+
c.setAio(true);
54+
c.setJournalMaxIo(journalMaxIo);
55+
c.setInstance(testInstance);
56+
c.execute(context);
57+
58+
assertTrue(fileContains(new File(testInstance, "etc/" + Create.ETC_BROKER_XML), "<journal-max-io>" + journalMaxIo + "</journal-max-io>"));
59+
}
60+
61+
@Test
62+
public void testJournalMaxIoNegative() throws Exception {
63+
int journalMaxIo = RandomUtil.randomInt();
64+
65+
Create c = new Create();
66+
c.setNio(true);
67+
c.setJournalMaxIo(journalMaxIo);
68+
c.setInstance(testInstance);
69+
c.execute(context);
70+
71+
assertFalse(fileContains(new File(testInstance, "etc/" + Create.ETC_BROKER_XML), "<journal-max-io>" + journalMaxIo + "</journal-max-io>"));
72+
assertTrue(fileContains(new File(testInstance, "etc/" + Create.ETC_BROKER_XML), "<journal-max-io>1</journal-max-io>"));
73+
}
74+
75+
private boolean fileContains(File file, String search) {
76+
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
77+
String line;
78+
while ((line = br.readLine()) != null) {
79+
if (line.contains(search)) {
80+
return true;
81+
}
82+
}
83+
} catch (IOException e) {
84+
}
85+
return false;
86+
}
87+
}

0 commit comments

Comments
 (0)