fixing locking on the CLI & shared storage

The CLI lock was broken when two nodes were sharing the journals
This commit is contained in:
Clebert Suconic 2015-09-04 12:05:20 -04:00
parent 1e27f1a658
commit a82080978f
4 changed files with 23 additions and 14 deletions

View File

@ -102,10 +102,9 @@ public class Artemis {
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);
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);
if (instance != null) {
builder = builder.withCommands(Run.class, Stop.class, Kill.class);
}
else {

View File

@ -80,13 +80,25 @@ public abstract class Configurable extends ActionAbstract {
private static RandomAccessFile serverLockFile = null;
private static FileLock serverLockLock = null;
protected static void lock(File journalPlace) throws Exception {
journalPlace.mkdirs();
File fileLock = new File(journalPlace, "cli.lock");
protected static void lockCLI(File lockPlace) throws Exception {
if (lockPlace != null) {
lockPlace.mkdirs();
File fileLock = new File(lockPlace, "cli.lock");
RandomAccessFile file = new RandomAccessFile(fileLock, "rw");
serverLockLock = file.getChannel().tryLock();
if (serverLockLock == null) {
throw new CLIException("Error: There is another process using the journal at " + journalPlace + ". Cannot start the process!");
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;
}
}

View File

@ -66,7 +66,7 @@ public class Run extends Configurable {
FileConfiguration fileConfiguration = getFileConfiguration();
lock(fileConfiguration.getJournalLocation());
lockCLI(getLockPlace());
Artemis.printBanner();

View File

@ -17,8 +17,6 @@
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.ActionContext;
@ -26,7 +24,7 @@ public abstract class LockAbstract extends DataAbstract implements Action {
@Override
public Object execute(ActionContext context) throws Exception {
super.execute(context);
lock(new File(getJournal()));
lockCLI(getLockPlace());
return null;
}