fixing locking on the CLI & shared storage
The CLI lock was broken when two nodes were sharing the journals
This commit is contained in:
parent
1e27f1a658
commit
a82080978f
|
@ -102,10 +102,9 @@ public class Artemis {
|
||||||
String instance = artemisInstance != null ? artemisInstance.getAbsolutePath() : System.getProperty("artemis.instance");
|
String instance = artemisInstance != null ? artemisInstance.getAbsolutePath() : System.getProperty("artemis.instance");
|
||||||
Cli.CliBuilder<Action> builder = Cli.<Action>builder("artemis").withDescription("ActiveMQ Artemis Command Line").withCommand(HelpAction.class).withCommand(Producer.class).withCommand(Consumer.class).withCommand(Browse.class).withDefaultCommand(HelpAction.class);
|
Cli.CliBuilder<Action> builder = Cli.<Action>builder("artemis").withDescription("ActiveMQ Artemis Command Line").withCommand(HelpAction.class).withCommand(Producer.class).withCommand(Consumer.class).withCommand(Browse.class).withDefaultCommand(HelpAction.class);
|
||||||
|
|
||||||
builder.withGroup("data").withDescription("data tools group (print|exp|imp|exp|encode|decode|compact) (example ./artemis data print)").
|
|
||||||
withDefaultCommand(HelpData.class).withCommands(PrintData.class, XmlDataExporter.class, XmlDataImporter.class, DecodeJournal.class, EncodeJournal.class, CompactJournal.class);
|
|
||||||
|
|
||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
|
builder.withGroup("data").withDescription("data tools group (print|exp|imp|exp|encode|decode|compact) (example ./artemis data print)").
|
||||||
|
withDefaultCommand(HelpData.class).withCommands(PrintData.class, XmlDataExporter.class, XmlDataImporter.class, DecodeJournal.class, EncodeJournal.class, CompactJournal.class);
|
||||||
builder = builder.withCommands(Run.class, Stop.class, Kill.class);
|
builder = builder.withCommands(Run.class, Stop.class, Kill.class);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -80,13 +80,25 @@ public abstract class Configurable extends ActionAbstract {
|
||||||
private static RandomAccessFile serverLockFile = null;
|
private static RandomAccessFile serverLockFile = null;
|
||||||
private static FileLock serverLockLock = null;
|
private static FileLock serverLockLock = null;
|
||||||
|
|
||||||
protected static void lock(File journalPlace) throws Exception {
|
protected static void lockCLI(File lockPlace) throws Exception {
|
||||||
journalPlace.mkdirs();
|
if (lockPlace != null) {
|
||||||
File fileLock = new File(journalPlace, "cli.lock");
|
lockPlace.mkdirs();
|
||||||
RandomAccessFile file = new RandomAccessFile(fileLock, "rw");
|
File fileLock = new File(lockPlace, "cli.lock");
|
||||||
serverLockLock = file.getChannel().tryLock();
|
RandomAccessFile file = new RandomAccessFile(fileLock, "rw");
|
||||||
if (serverLockLock == null) {
|
serverLockLock = file.getChannel().tryLock();
|
||||||
throw new CLIException("Error: There is another process using the journal at " + journalPlace + ". Cannot start the process!");
|
if (serverLockLock == null) {
|
||||||
|
throw new CLIException("Error: There is another process using the server at " + lockPlace + ". Cannot start the process!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected File getLockPlace() throws Exception {
|
||||||
|
String brokerInstance = getBrokerInstance();
|
||||||
|
if (brokerInstance != null) {
|
||||||
|
return new File(new File(brokerInstance),"lock");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class Run extends Configurable {
|
||||||
|
|
||||||
FileConfiguration fileConfiguration = getFileConfiguration();
|
FileConfiguration fileConfiguration = getFileConfiguration();
|
||||||
|
|
||||||
lock(fileConfiguration.getJournalLocation());
|
lockCLI(getLockPlace());
|
||||||
|
|
||||||
Artemis.printBanner();
|
Artemis.printBanner();
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
package org.apache.activemq.artemis.cli.commands.tools;
|
package org.apache.activemq.artemis.cli.commands.tools;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import org.apache.activemq.artemis.cli.commands.Action;
|
import org.apache.activemq.artemis.cli.commands.Action;
|
||||||
import org.apache.activemq.artemis.cli.commands.ActionContext;
|
import org.apache.activemq.artemis.cli.commands.ActionContext;
|
||||||
|
|
||||||
|
@ -26,7 +24,7 @@ public abstract class LockAbstract extends DataAbstract implements Action {
|
||||||
@Override
|
@Override
|
||||||
public Object execute(ActionContext context) throws Exception {
|
public Object execute(ActionContext context) throws Exception {
|
||||||
super.execute(context);
|
super.execute(context);
|
||||||
lock(new File(getJournal()));
|
lockCLI(getLockPlace());
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue