zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From iv...@apache.org
Subject svn commit: r1232890 - in /zookeeper/bookkeeper/trunk: ./ bookkeeper-server/src/main/java/org/apache/bookkeeper/client/ bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/
Date Wed, 18 Jan 2012 14:11:47 GMT
Author: ivank
Date: Wed Jan 18 14:11:46 2012
New Revision: 1232890

URL: http://svn.apache.org/viewvc?rev=1232890&view=rev
Log:
BOOKKEEPER-153: Ledger can't be opened or closed due to zero-length metadata (Sijie Guo via
ivank)

Modified:
    zookeeper/bookkeeper/trunk/CHANGES.txt
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerCreateOp.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerMetadata.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/FlatLedgerManager.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/HierarchicalLedgerManager.java
    zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerManager.java

Modified: zookeeper/bookkeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/CHANGES.txt?rev=1232890&r1=1232889&r2=1232890&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/CHANGES.txt (original)
+++ zookeeper/bookkeeper/trunk/CHANGES.txt Wed Jan 18 14:11:46 2012
@@ -24,6 +24,8 @@ Trunk (unreleased changes)
 
         BOOKKEEPER-95: extends zookeeper JMX to monitor and manage bookie server (Sijie Guo
via ivank)
 
+        BOOKKEEPER-153: Ledger can't be opened or closed due to zero-length metadata (Sijie
Guo via ivank)
+
       hedwig-server/
       
         BOOKKEEPER-140: Hub server doesn't subscribe remote region correctly when a region
is down. (Sijie Gou via ivank)

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerCreateOp.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerCreateOp.java?rev=1232890&r1=1232889&r2=1232890&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerCreateOp.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerCreateOp.java
Wed Jan 18 14:11:46 2012
@@ -32,14 +32,13 @@ import org.apache.bookkeeper.proto.Bookk
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.zookeeper.KeeperException;
-import org.apache.zookeeper.AsyncCallback.StatCallback;
 import org.apache.zookeeper.data.Stat;
 
 /**
  * Encapsulates asynchronous ledger create operation
  *
  */
-class LedgerCreateOp implements GenericCallback<String>, StatCallback {
+class LedgerCreateOp implements GenericCallback<String> {
 
     static final Logger LOG = LoggerFactory.getLogger(LedgerCreateOp.class);
 
@@ -83,7 +82,28 @@ class LedgerCreateOp implements GenericC
      * Initiates the operation
      */
     public void initiate() {
-        bk.getLedgerManager().newLedgerPath(this);
+        // allocate ensemble first
+
+        /*
+         * Adding bookies to ledger handle
+         */
+
+        ArrayList<InetSocketAddress> ensemble;
+        try {
+            ensemble = bk.bookieWatcher.getNewBookies(metadata.ensembleSize);
+        } catch (BKNotEnoughBookiesException e) {
+            LOG.error("Not enough bookies to create ledger");
+            cb.createComplete(e.getCode(), null, this.ctx);
+            return;
+        }
+
+        /*
+         * Add ensemble to the configuration
+         */
+        metadata.addEnsemble(new Long(0), ensemble);
+
+        // create a ledger path with metadata
+        bk.getLedgerManager().newLedgerPath(this, metadata);
     }
 
     /**
@@ -111,23 +131,6 @@ class LedgerCreateOp implements GenericC
             return;
         }
 
-        /*
-         * Adding bookies to ledger handle
-         */
-
-        ArrayList<InetSocketAddress> ensemble;
-        try {
-            ensemble = bk.bookieWatcher.getNewBookies(metadata.ensembleSize);
-        } catch (BKNotEnoughBookiesException e) {
-            LOG.error("Not enough bookies to create ledger" + ledgerId);
-            cb.createComplete(e.getCode(), null, this.ctx);
-            return;
-        }
-
-        /*
-         * Add ensemble to the configuration
-         */
-        metadata.addEnsemble(new Long(0), ensemble);
         try {
             lh = new LedgerHandle(bk, ledgerId, metadata, digestType, passwd);
         } catch (GeneralSecurityException e) {
@@ -140,18 +143,8 @@ class LedgerCreateOp implements GenericC
             return;
         }
 
-        lh.writeLedgerConfig(this, null);
-
-    }
-
-    /**
-     * Implements ZooKeeper stat callback.
-     *
-     * @see org.apache.zookeeper.AsyncCallback.StatCallback#processResult(int, String, Object,
Stat)
-     */
-    public void processResult(int rc, String path, Object ctx, Stat stat) {
-        metadata.znodeVersion = stat.getVersion();
-        cb.createComplete(rc, lh, this.ctx);
+        // return the ledger handle back
+        cb.createComplete(BKException.Code.OK, lh, this.ctx);
     }
 
 }

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerMetadata.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerMetadata.java?rev=1232890&r1=1232889&r2=1232890&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerMetadata.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/LedgerMetadata.java
Wed Jan 18 14:11:46 2012
@@ -240,7 +240,17 @@ public class LedgerMetadata {
     public void updateZnodeStatus(Stat stat) {
         this.znodeVersion = stat.getVersion();
     }
-    
+
+    /**
+     * Update the znode version of this metadata
+     *
+     * @param znodeVersion
+     *        Znode version of this metadata
+     */
+    public void updateZnodeStatus(int znodeVersion) {
+        this.znodeVersion = znodeVersion;
+    }
+
     /**
      * Returns the last znode version.
      * 

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/FlatLedgerManager.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/FlatLedgerManager.java?rev=1232890&r1=1232889&r2=1232890&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/FlatLedgerManager.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/FlatLedgerManager.java
Wed Jan 18 14:11:46 2012
@@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentMa
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.HashSet;
 
+import org.apache.bookkeeper.client.LedgerMetadata;
 import org.apache.bookkeeper.conf.AbstractConfiguration;
 import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback;
 import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.Processor;
@@ -94,7 +95,7 @@ class FlatLedgerManager extends Abstract
     }
 
     @Override
-    public void newLedgerPath(final GenericCallback<String> cb) {
+    public void newLedgerPath(final GenericCallback<String> cb, final LedgerMetadata
metadata) {
         StringCallback scb = new StringCallback() {
             @Override
             public void processResult(int rc, String path, Object ctx,
@@ -102,11 +103,13 @@ class FlatLedgerManager extends Abstract
                 if (Code.OK.intValue() != rc) {
                     cb.operationComplete(rc, null);
                 } else {
+                    // update znode status
+                    metadata.updateZnodeStatus(0);
                     cb.operationComplete(rc, name);
                 }
             }
         };
-        ZkUtils.createFullPathOptimistic(zk, ledgerPrefix, new byte[0],
+        ZkUtils.createFullPathOptimistic(zk, ledgerPrefix, metadata.serialize(),
             Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL, scb, null);
     }
 

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/HierarchicalLedgerManager.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/HierarchicalLedgerManager.java?rev=1232890&r1=1232889&r2=1232890&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/HierarchicalLedgerManager.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/HierarchicalLedgerManager.java
Wed Jan 18 14:11:46 2012
@@ -27,6 +27,7 @@ import java.util.concurrent.atomic.Atomi
 import java.util.HashSet;
 import java.util.List;
 
+import org.apache.bookkeeper.client.LedgerMetadata;
 import org.apache.bookkeeper.conf.AbstractConfiguration;
 import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback;
 import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.Processor;
@@ -135,7 +136,7 @@ class HierarchicalLedgerManager extends 
     }
 
     @Override
-    public void newLedgerPath(final GenericCallback<String> ledgerCb) {
+    public void newLedgerPath(final GenericCallback<String> ledgerCb, final LedgerMetadata
metadata) {
         ZkUtils.createFullPathOptimistic(zk, idGenPath, new byte[0], Ids.OPEN_ACL_UNSAFE,
             CreateMode.EPHEMERAL_SEQUENTIAL, new StringCallback() {
             @Override
@@ -164,12 +165,14 @@ class HierarchicalLedgerManager extends 
                         if (rc != KeeperException.Code.OK.intValue()) {
                             ledgerCb.operationComplete(rc, null);
                         } else {
+                            // update znode status
+                            metadata.updateZnodeStatus(0);
                             ledgerCb.operationComplete(rc, name);
                         }
                     }
                 };
                 String ledgerPath = getLedgerPath(ledgerId);
-                ZkUtils.createFullPathOptimistic(zk, ledgerPath, new byte[0],
+                ZkUtils.createFullPathOptimistic(zk, ledgerPath, metadata.serialize(),
                     Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, scb, null);
                 // delete the znode for id generation
                 scheduler.submit(new Runnable() {

Modified: zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerManager.java
URL: http://svn.apache.org/viewvc/zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerManager.java?rev=1232890&r1=1232889&r2=1232890&view=diff
==============================================================================
--- zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerManager.java
(original)
+++ zookeeper/bookkeeper/trunk/bookkeeper-server/src/main/java/org/apache/bookkeeper/meta/LedgerManager.java
Wed Jan 18 14:11:46 2012
@@ -21,6 +21,7 @@ package org.apache.bookkeeper.meta;
 import java.io.IOException;
 
 import org.apache.zookeeper.AsyncCallback;
+import org.apache.bookkeeper.client.LedgerMetadata;
 import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.GenericCallback;
 import org.apache.bookkeeper.proto.BookkeeperInternalCallbacks.Processor;
 
@@ -55,12 +56,14 @@ public interface LedgerManager {
     public long getLedgerId(String ledgerPath) throws IOException;
 
     /**
-     * Create a new zk ledger path.
+     * Create a new zk ledger path with provided metadata
      *
      * @param cb
      *        Callback when getting new zk ledger path to create.
+     * @param metadata
+     *        Metadata provided when creating a new ledger
      */
-    public abstract void newLedgerPath(GenericCallback<String> cb);
+    public abstract void newLedgerPath(GenericCallback<String> cb, LedgerMetadata metadata);
 
     /**
      * Loop to process all ledgers.



Mime
View raw message