activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject activemq-artemis git commit: fixing locking on the CLI & shared storage
Date Fri, 04 Sep 2015 16:22:00 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 1e27f1a65 -> a82080978


fixing locking on the CLI & shared storage

The CLI lock was broken when two nodes were sharing the journals


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/a8208097
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/a8208097
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/a8208097

Branch: refs/heads/master
Commit: a82080978fa63a320bf30d5891a0d81f5be1b1b0
Parents: 1e27f1a
Author: Clebert Suconic <clebertsuconic@apache.org>
Authored: Fri Sep 4 12:05:20 2015 -0400
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Fri Sep 4 12:21:49 2015 -0400

----------------------------------------------------------------------
 .../apache/activemq/artemis/cli/Artemis.java    |  5 ++--
 .../artemis/cli/commands/Configurable.java      | 26 ++++++++++++++------
 .../activemq/artemis/cli/commands/Run.java      |  2 +-
 .../cli/commands/tools/LockAbstract.java        |  4 +--
 4 files changed, 23 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a8208097/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
index e094751..a72ee51 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Artemis.java
@@ -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);
 
-      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.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);
       }
       else {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a8208097/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java
index f29a3e3..c4bd2d4 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java
@@ -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");
-      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!");
+   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 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;
       }
    }
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a8208097/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java
index d585b90..ca13356 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java
@@ -66,7 +66,7 @@ public class Run extends Configurable {
 
       FileConfiguration fileConfiguration = getFileConfiguration();
 
-      lock(fileConfiguration.getJournalLocation());
+      lockCLI(getLockPlace());
 
       Artemis.printBanner();
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a8208097/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/LockAbstract.java
----------------------------------------------------------------------
diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/LockAbstract.java
b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/LockAbstract.java
index e451ef5..9a6984d 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/LockAbstract.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/LockAbstract.java
@@ -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;
    }


Mime
View raw message