zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hd...@apache.org
Subject svn commit: r1682521 - in /zookeeper/trunk: ./ src/ src/c/src/ src/java/main/org/apache/zookeeper/ src/java/main/org/apache/zookeeper/server/
Date Fri, 29 May 2015 17:45:53 GMT
Author: hdeng
Date: Fri May 29 17:45:53 2015
New Revision: 1682521

URL: http://svn.apache.org/r1682521
Log:
ZOOKEEPER-2187: remove duplicated code between CreateRequest{,2}
(Raul Gutierrez Segales via hdeng)

Modified:
    zookeeper/trunk/CHANGES.txt
    zookeeper/trunk/src/c/src/zookeeper.c
    zookeeper/trunk/src/java/main/org/apache/zookeeper/MultiTransactionRecord.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java
    zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
    zookeeper/trunk/src/zookeeper.jute

Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1682521&r1=1682520&r2=1682521&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Fri May 29 17:45:53 2015
@@ -155,6 +155,9 @@ IMPROVEMENTS:
   ZOOKEEPER-2191: Continue supporting prior Ant versions that don't implement the
   threads attribute for the JUnit task (Chris Nauroth via rakeshr)
 
+  ZOOKEEPER-2187: remove duplicated code between CreateRequest{,2}
+  (Raul Gutierrez Segales via hdeng)
+
 Release 3.5.0 - 8/4/2014
 
 NEW FEATURES:

Modified: zookeeper/trunk/src/c/src/zookeeper.c
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/c/src/zookeeper.c?rev=1682521&r1=1682520&r2=1682521&view=diff
==============================================================================
--- zookeeper/trunk/src/c/src/zookeeper.c (original)
+++ zookeeper/trunk/src/c/src/zookeeper.c Fri May 29 17:45:53 2015
@@ -3515,30 +3515,6 @@ static int CreateRequest_init(zhandle_t
     return ZOK;
 }
 
-static int Create2Request_init(zhandle_t *zh, struct Create2Request *req,
-        const char *path, const char *value,
-        int valuelen, const struct ACL_vector *acl_entries, int flags)
-{
-    int rc;
-    assert(req);
-    rc = Request_path_init(zh, flags, &req->path, path);
-    assert(req);
-    if (rc != ZOK) {
-        return rc;
-    }
-    req->flags = flags;
-    req->data.buff = (char*)value;
-    req->data.len = valuelen;
-    if (acl_entries == 0) {
-        req->acl.count = 0;
-        req->acl.data = 0;
-    } else {
-        req->acl = *acl_entries;
-    }
-
-    return ZOK;
-}
-
 int zoo_acreate(zhandle_t *zh, const char *path, const char *value,
         int valuelen, const struct ACL_vector *acl_entries, int flags,
         string_completion_t completion, const void *data)
@@ -3577,15 +3553,15 @@ int zoo_acreate2(zhandle_t *zh, const ch
 {
     struct oarchive *oa;
     struct RequestHeader h = { get_xid(), ZOO_CREATE2_OP };
-    struct Create2Request req;
+    struct CreateRequest req;
 
-    int rc = Create2Request_init(zh, &req, path, value, valuelen, acl_entries, flags);
+    int rc = CreateRequest_init(zh, &req, path, value, valuelen, acl_entries, flags);
     if (rc != ZOK) {
         return rc;
     }
     oa = create_buffer_oarchive();
     rc = serialize_RequestHeader(oa, "header", &h);
-    rc = rc < 0 ? rc : serialize_Create2Request(oa, "req", &req);
+    rc = rc < 0 ? rc : serialize_CreateRequest(oa, "req", &req);
     enter_critical(zh);
     rc = rc < 0 ? rc : add_string_stat_completion(zh, h.xid, completion, data);
     rc = rc < 0 ? rc : queue_buffer_bytes(&zh->to_send, get_buffer(oa),

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/MultiTransactionRecord.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/MultiTransactionRecord.java?rev=1682521&r1=1682520&r2=1682521&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/MultiTransactionRecord.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/MultiTransactionRecord.java Fri May
29 17:45:53 2015
@@ -66,18 +66,10 @@ public class MultiTransactionRecord impl
             MultiHeader h = new MultiHeader(op.getType(), false, -1);
             h.serialize(archive, tag);
             switch (op.getType()) {
-               case ZooDefs.OpCode.create:
-                    op.toRequestRecord().serialize(archive, tag);
-                    break;
-               case ZooDefs.OpCode.create2:
-                   op.toRequestRecord().serialize(archive, tag);
-                   break;
+                case ZooDefs.OpCode.create:
+                case ZooDefs.OpCode.create2:
                 case ZooDefs.OpCode.delete:
-                    op.toRequestRecord().serialize(archive, tag);
-                    break;
                 case ZooDefs.OpCode.setData:
-                    op.toRequestRecord().serialize(archive, tag);
-                    break;
                 case ZooDefs.OpCode.check:
                     op.toRequestRecord().serialize(archive, tag);
                     break;
@@ -98,15 +90,11 @@ public class MultiTransactionRecord impl
         while (!h.getDone()) {
             switch (h.getType()) {
                case ZooDefs.OpCode.create:
+               case ZooDefs.OpCode.create2:
                     CreateRequest cr = new CreateRequest();
                     cr.deserialize(archive, tag);
                     add(Op.create(cr.getPath(), cr.getData(), cr.getAcl(), cr.getFlags()));
                     break;
-               case ZooDefs.OpCode.create2:
-                   Create2Request cr2 = new Create2Request();
-                   cr2.deserialize(archive, tag);
-                   add(Op.create(cr2.getPath(), cr2.getData(), cr2.getAcl(), cr2.getFlags()));
-                   break;
                 case ZooDefs.OpCode.delete:
                     DeleteRequest dr = new DeleteRequest();
                     dr.deserialize(archive, tag);

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java?rev=1682521&r1=1682520&r2=1682521&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/ZooKeeper.java Fri May 29 17:45:53
2015
@@ -53,7 +53,6 @@ import org.apache.zookeeper.common.Strin
 import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Stat;
 import org.apache.zookeeper.proto.CheckWatchesRequest;
-import org.apache.zookeeper.proto.Create2Request;
 import org.apache.zookeeper.proto.Create2Response;
 import org.apache.zookeeper.proto.CreateRequest;
 import org.apache.zookeeper.proto.CreateResponse;
@@ -1284,7 +1283,7 @@ public class ZooKeeper {
 
         RequestHeader h = new RequestHeader();
         h.setType(ZooDefs.OpCode.create2);
-        Create2Request request = new Create2Request();
+        CreateRequest request = new CreateRequest();
         Create2Response response = new Create2Response();
         request.setData(data);
         request.setFlags(createMode.toFlag());
@@ -1349,7 +1348,7 @@ public class ZooKeeper {
 
         RequestHeader h = new RequestHeader();
         h.setType(ZooDefs.OpCode.create2);
-        Create2Request request = new Create2Request();
+        CreateRequest request = new CreateRequest();
         Create2Response response = new Create2Response();
         ReplyHeader r = new ReplyHeader();
         request.setData(data);

Modified: zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java?rev=1682521&r1=1682520&r2=1682521&view=diff
==============================================================================
--- zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java (original)
+++ zookeeper/trunk/src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java Fri
May 29 17:45:53 2015
@@ -54,7 +54,6 @@ import org.apache.zookeeper.data.ACL;
 import org.apache.zookeeper.data.Id;
 import org.apache.zookeeper.data.StatPersisted;
 import org.apache.zookeeper.proto.CreateRequest;
-import org.apache.zookeeper.proto.Create2Request;
 import org.apache.zookeeper.proto.DeleteRequest;
 import org.apache.zookeeper.proto.ReconfigRequest;
 import org.apache.zookeeper.proto.SetACLRequest;
@@ -365,58 +364,9 @@ public class PrepRequestProcessor extend
                 Time.currentWallTime(), type));
 
         switch (type) {
-            case OpCode.create: {
-                CreateRequest createRequest = (CreateRequest)record;
-                if (deserialize) {
-                    ByteBufferInputStream.byteBuffer2Record(request.request, createRequest);
-                }
-                CreateMode createMode = CreateMode.fromFlag(createRequest.getFlags());
-                validateCreateRequest(createMode, request);
-                String path = createRequest.getPath();
-                String parentPath = validatePathForCreate(path, request.sessionId);
-
-                List<ACL> listACL = fixupACL(path, request.authInfo, createRequest.getAcl());
-                ChangeRecord parentRecord = getRecordForPath(parentPath);
-
-                checkACL(zks, parentRecord.acl, ZooDefs.Perms.CREATE, request.authInfo);
-                int parentCVersion = parentRecord.stat.getCversion();
-                if (createMode.isSequential()) {
-                    path = path + String.format(Locale.ENGLISH, "%010d", parentCVersion);
-                }
-                try {
-                    PathUtils.validatePath(path);
-                } catch(IllegalArgumentException ie) {
-                    LOG.info("Invalid path " + path + " with session 0x" +
-                            Long.toHexString(request.sessionId));
-                    throw new KeeperException.BadArgumentsException(path);
-                }
-                try {
-                    if (getRecordForPath(path) != null) {
-                        throw new KeeperException.NodeExistsException(path);
-                    }
-                } catch (KeeperException.NoNodeException e) {
-                    // ignore this one
-                }
-                boolean ephemeralParent = parentRecord.stat.getEphemeralOwner() != 0;
-                if (ephemeralParent) {
-                    throw new KeeperException.NoChildrenForEphemeralsException(path);
-                }
-                int newCversion = parentRecord.stat.getCversion()+1;
-                request.setTxn(new CreateTxn(path, createRequest.getData(), listACL, createMode.isEphemeral(),
-                        newCversion));
-                StatPersisted s = new StatPersisted();
-                if (createMode.isEphemeral()) {
-                    s.setEphemeralOwner(request.sessionId);
-                }
-                parentRecord = parentRecord.duplicate(request.getHdr().getZxid());
-                parentRecord.childCount++;
-                parentRecord.stat.setCversion(newCversion);
-                addChangeRecord(parentRecord);
-                addChangeRecord(new ChangeRecord(request.getHdr().getZxid(), path, s, 0,
listACL));
-                break;
-            }
+            case OpCode.create:
             case OpCode.create2: {
-                Create2Request createRequest = (Create2Request)record;
+                CreateRequest createRequest = (CreateRequest)record;
                 if (deserialize) {
                     ByteBufferInputStream.byteBuffer2Record(request.request, createRequest);
                 }
@@ -715,11 +665,8 @@ public class PrepRequestProcessor extend
         try {
             switch (request.type) {
             case OpCode.create:
-                CreateRequest createRequest = new CreateRequest();
-                pRequest2Txn(request.type, zks.getNextZxid(), request, createRequest, true);
-                break;
             case OpCode.create2:
-                Create2Request create2Request = new Create2Request();
+                CreateRequest create2Request = new CreateRequest();
                 pRequest2Txn(request.type, zks.getNextZxid(), request, create2Request, true);
                 break;
             case OpCode.delete:

Modified: zookeeper/trunk/src/zookeeper.jute
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/zookeeper.jute?rev=1682521&r1=1682520&r2=1682521&view=diff
==============================================================================
--- zookeeper/trunk/src/zookeeper.jute (original)
+++ zookeeper/trunk/src/zookeeper.jute Fri May 29 17:45:53 2015
@@ -127,12 +127,6 @@ module org.apache.zookeeper.proto {
         vector<org.apache.zookeeper.data.ACL> acl;
         int flags;
     }
-    class Create2Request {
-        ustring path;
-        buffer data;
-        vector<org.apache.zookeeper.data.ACL> acl;
-        int flags;
-    }
     class DeleteRequest {
         ustring path;
         int version;



Mime
View raw message