accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [4/5] git commit: Remove System.exit's from AdminUtil and lift them to the Admin class with the main method. Add UTF8 charset to AdminUtil where necessary.
Date Fri, 31 Jan 2014 18:54:13 GMT
Remove System.exit's from AdminUtil and lift them to the Admin class with the main method.
Add UTF8 charset to AdminUtil
where necessary.


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

Branch: refs/heads/2292-findbugs
Commit: e8be283ed65ab8c9f6bb394400fbe4cef84e5a29
Parents: 049d6cd
Author: Josh Elser <elserj@apache.org>
Authored: Fri Jan 31 13:25:14 2014 -0500
Committer: Josh Elser <elserj@apache.org>
Committed: Fri Jan 31 13:25:14 2014 -0500

----------------------------------------------------------------------
 .../org/apache/accumulo/fate/AdminUtil.java     | 33 ++++++++++++++------
 .../org/apache/accumulo/server/fate/Admin.java  |  8 +++--
 2 files changed, 29 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/e8be283e/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java
----------------------------------------------------------------------
diff --git a/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java b/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java
index bc6874f..0162466 100644
--- a/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java
+++ b/fate/src/main/java/org/apache/accumulo/fate/AdminUtil.java
@@ -16,6 +16,7 @@
  */
 package org.apache.accumulo.fate;
 
+import java.nio.charset.Charset;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -33,6 +34,8 @@ import org.apache.zookeeper.KeeperException;
  * A utility to administer FATE operations
  */
 public class AdminUtil<T> {
+  private static final Charset UTF8 = Charset.forName("UTF-8");
+  
   public void print(ZooStore<T> zs, IZooReaderWriter zk, String lockPath) throws KeeperException,
InterruptedException {
     Map<Long,List<String>> heldLocks = new HashMap<Long,List<String>>();
     Map<Long,List<String>> waitingLocks = new HashMap<Long,List<String>>();
@@ -51,7 +54,7 @@ public class AdminUtil<T> {
         for (String node : lockNodes) {
           try {
             byte[] data = zk.getData(lockPath + "/" + id + "/" + node, null);
-            String lda[] = new String(data).split(":");
+            String lda[] = new String(data, UTF8).split(":");
             
             if (lda[0].charAt(0) == 'W')
               sawWriteLock = true;
@@ -129,22 +132,30 @@ public class AdminUtil<T> {
     }
   }
   
-  public void prepDelete(ZooStore<T> zs, IZooReaderWriter zk, String path, String txidStr)
{
-    checkGlobalLock(zk, path);
+  public boolean prepDelete(ZooStore<T> zs, IZooReaderWriter zk, String path, String
txidStr) {
+    if (!checkGlobalLock(zk, path)) {
+      return false;
+    }
     
     long txid = Long.parseLong(txidStr, 16);
     zs.reserve(txid);
     zs.delete(txid);
     zs.unreserve(txid, 0);
+    
+    return true;
   }
   
-  public void prepFail(ZooStore<T> zs, IZooReaderWriter zk, String path, String txidStr)
{
-    checkGlobalLock(zk, path);
+  public boolean prepFail(ZooStore<T> zs, IZooReaderWriter zk, String path, String
txidStr) {
+    if (!checkGlobalLock(zk, path)) {
+      return false;
+    }
     
     long txid = Long.parseLong(txidStr, 16);
     zs.reserve(txid);
     zs.setStatus(txid, TStatus.FAILED_IN_PROGRESS);
     zs.unreserve(txid, 0);
+    
+    return true;
   }
   
   public void deleteLocks(ZooStore<T> zs, IZooReaderWriter zk, String path, String
txidStr) throws KeeperException, InterruptedException {
@@ -156,25 +167,27 @@ public class AdminUtil<T> {
       for (String node : lockNodes) {
         String lockPath = path + "/" + id + "/" + node;
         byte[] data = zk.getData(path + "/" + id + "/" + node, null);
-        String lda[] = new String(data).split(":");
+        String lda[] = new String(data, UTF8).split(":");
         if (lda[1].equals(txidStr))
           zk.recursiveDelete(lockPath, NodeMissingPolicy.SKIP);
       }
     }
   }
   
-  public void checkGlobalLock(IZooReaderWriter zk, String path) {
+  public boolean checkGlobalLock(IZooReaderWriter zk, String path) {
     try {
       if (ZooLock.getLockData(zk.getZooKeeper(), path) != null) {
         System.err.println("ERROR: Master lock is held, not running");
-        System.exit(-1);
+        return false;
       }
     } catch (KeeperException e) {
       System.err.println("ERROR: Could not read master lock, not running " + e.getMessage());
-      System.exit(-1);
+      return false;
     } catch (InterruptedException e) {
       System.err.println("ERROR: Could not read master lock, not running" + e.getMessage());
-      System.exit(-1);
+      return false;
     }
+    
+    return true;
   }
 }

http://git-wip-us.apache.org/repos/asf/accumulo/blob/e8be283e/server/src/main/java/org/apache/accumulo/server/fate/Admin.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/fate/Admin.java b/server/src/main/java/org/apache/accumulo/server/fate/Admin.java
index c375981..4a5f0bc 100644
--- a/server/src/main/java/org/apache/accumulo/server/fate/Admin.java
+++ b/server/src/main/java/org/apache/accumulo/server/fate/Admin.java
@@ -79,9 +79,13 @@ public class Admin {
     ZooStore<Master> zs = new ZooStore<Master>(path, zk);
     
     if (jc.getParsedCommand().equals("fail")) {
-      admin.prepFail(zs, zk, masterPath, args[1]);
+      if (!admin.prepFail(zs, zk, masterPath, args[1])) {
+        System.exit(1);
+      }
     } else if (jc.getParsedCommand().equals("delete")) {
-      admin.prepDelete(zs, zk, masterPath, args[1]);
+      if (!admin.prepDelete(zs, zk, masterPath, args[1])) {
+        System.exit(1);
+      }
       admin.deleteLocks(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS, args[1]);
     } else if (jc.getParsedCommand().equals("print")) {
       admin.print(zs, zk, ZooUtil.getRoot(instance) + Constants.ZTABLE_LOCKS);


Mime
View raw message