You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by we...@apache.org on 2013/11/20 08:45:49 UTC

[1/4] refine cluster

Updated Branches:
  refs/heads/refine_cluster [created] 7ffc10a9c


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/P_ClusterInline.h
----------------------------------------------------------------------
diff --git a/iocore/cluster/P_ClusterInline.h b/iocore/cluster/P_ClusterInline.h
index c653956..1d26b3a 100644
--- a/iocore/cluster/P_ClusterInline.h
+++ b/iocore/cluster/P_ClusterInline.h
@@ -36,25 +36,30 @@ inline Action *
 Cluster_lookup(Continuation * cont, CacheKey * key, CacheFragType frag_type, char *hostname, int host_len)
 {
   // Try to send remote, if not possible, handle locally
-  Action *retAct;
-  ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
-  if (m && !clusterProcessor.disable_remote_cluster_ops(m)) {
-    CacheContinuation *cc = CacheContinuation::cacheContAllocator_alloc();
-    cc->action = cont;
-    cc->mutex = cont->mutex;
-    retAct = CacheContinuation::do_remote_lookup(cont, key, cc, frag_type, hostname, host_len);
-    if (retAct) {
-      return retAct;
-    } else {
-      // not remote, do local lookup
-      CacheContinuation::cacheContAllocator_free(cc);
-      return (Action *) NULL;
-    }
-  } else {
-    Action a;
-    a = cont;
-    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LOOKUP_FAILED, 0);
-  }
+//  Action *retAct;
+//  ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
+//  if (m && !clusterProcessor.disable_remote_cluster_ops(m)) {
+//    CacheContinuation *cc = CacheContinuation::cacheContAllocator_alloc();
+//    cc->action = cont;
+//    cc->mutex = cont->mutex;
+//    retAct = CacheContinuation::do_remote_lookup(cont, key, cc, frag_type, hostname, host_len);
+//    if (retAct) {
+//      return retAct;
+//    } else {
+//      // not remote, do local lookup
+//      CacheContinuation::cacheContAllocator_free(cc);
+//      return (Action *) NULL;
+//    }
+//  } else {
+//    Action a;
+//    a = cont;
+//    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LOOKUP_FAILED, 0);
+//  }
+  (void) cont;
+  (void) key;
+  (void) frag_type;
+  (void) hostname;
+  (void) host_len;
   return (Action *) NULL;
 }
 
@@ -66,18 +71,24 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
              time_t pin_in_cache, CacheFragType frag_type, char *hostname, int host_len)
 {
   (void) params;
-  if (clusterProcessor.disable_remote_cluster_ops(owner_machine)) {
-    Action a;
-    a = cont;
-    return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_READ_FAILED, 0);
+  ink_assert(cont);
+  ClusterSession session;
+  if (cluster_create_session(&session, owner_machine, NULL, 0)) {
+    cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, NULL);
+    return ACTION_RESULT_DONE;
   }
+
   int vers = CacheOpMsg_long::protoToVersion(owner_machine->msg_proto_major);
+  CacheOpArgs_General readArgs;
+  Ptr<IOBufferData> d;
+
   int flen;
   int len = 0;
   int cur_len;
   int res = 0;
-  char *msg;
+  char *msg = 0;
   char *data;
+  Action *action = NULL;
 
   if (vers == CacheOpMsg_long::CACHE_OP_LONG_MESSAGE_VERSION) {
     if ((opcode == CACHE_OPEN_READ_LONG)
@@ -87,20 +98,21 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
 
       const char *url_hostname;
       int url_hlen;
-      INK_MD5 url_only_md5;
+      INK_MD5 url_md5;
 
-      Cache::generate_key(&url_only_md5, url, 0);
+      Cache::generate_key(&url_md5, url);
       url_hostname = url->host_get(&url_hlen);
 
       len += request->m_heap->marshal_length();
-      len += params->marshal_length();
+      len += sizeof(CacheLookupHttpConfig) + params->marshal_length();
       len += url_hlen;
 
       if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)       // Bound marshalled data
         goto err_exit;
 
       // Perform data Marshal operation
-      msg = (char *) ALLOCA_DOUBLE(flen + len);
+      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
+      msg = (char *) d->data();
       data = msg + flen;
 
       cur_len = len;
@@ -110,6 +122,13 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
       }
       data += res;
       cur_len -= res;
+
+      if (cur_len < (int) sizeof(CacheLookupHttpConfig))
+        goto err_exit;
+      memcpy(data, params, sizeof(CacheLookupHttpConfig));
+      data += sizeof(CacheLookupHttpConfig);
+      cur_len -= sizeof(CacheLookupHttpConfig);
+
       if ((res = params->marshal(data, cur_len)) < 0)
         goto err_exit;
       data += res;
@@ -117,37 +136,33 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
       memcpy(data, url_hostname, url_hlen);
 
       CacheOpArgs_General readArgs;
-      readArgs.url_md5 = &url_only_md5;
+      readArgs.url_md5 = &url_md5;
       readArgs.pin_in_cache = pin_in_cache;
       readArgs.frag_type = frag_type;
-      return CacheContinuation::do_op(cont, owner_machine, (void *) &readArgs,
-                                      opcode, (char *) msg, (flen + len), -1, buf);
+
+      action = CacheContinuation::do_op(cont, session, (void *) &readArgs,
+                                            opcode, d, (flen + len), -1, buf);
     } else {
       // Build message if we have host data.
+      flen = op_to_sizeof_fixedlen_msg(opcode);
+      len = host_len;
 
-      if (host_len) {
-        // Determine length of data to Marshal
-        flen = op_to_sizeof_fixedlen_msg(opcode);
-        len = host_len;
-
-        if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
-          goto err_exit;
+      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
+        goto err_exit;
 
-        msg = (char *) ALLOCA_DOUBLE(flen + len);
-        data = msg + flen;
+      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
+      msg = (char *) d->data();
+      data = msg + flen;
+      if (host_len)
         memcpy(data, hostname, host_len);
 
-      } else {
-        msg = 0;
-        flen = 0;
-        len = 0;
-      }
-      CacheOpArgs_General readArgs;
       readArgs.url_md5 = key;
       readArgs.frag_type = frag_type;
-      return CacheContinuation::do_op(cont, owner_machine, (void *) &readArgs,
-                                      opcode, (char *) msg, (flen + len), -1, buf);
+
+      action = CacheContinuation::do_op(cont, session, (void *) &readArgs,
+                                            opcode, d, (flen + len), -1, buf);
     }
+    ink_assert(msg);
 
   } else {
     //////////////////////////////////////////////////////////////
@@ -155,10 +170,12 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
     //////////////////////////////////////////////////////////////
     ink_release_assert(!"CacheOpMsg_long [read] bad msg version");
   }
+
+  if (action)
+    return action;
 err_exit:
-  Action a;
-  a = cont;
-  return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_READ_FAILED, 0);
+  cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, NULL);
+  return ACTION_RESULT_DONE;
 }
 
 inline Action *
@@ -171,10 +188,11 @@ Cluster_write(Continuation * cont, int expected_size,
 {
   (void) key;
   (void) request;
-  if (clusterProcessor.disable_remote_cluster_ops(m)) {
-    Action a;
-    a = cont;
-    return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_WRITE_FAILED, 0);
+  ClusterSession session;
+  ink_assert(cont);
+  if (cluster_create_session(&session, m, NULL, 0)) {
+     cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, NULL);
+     return ACTION_RESULT_DONE;
   }
   char *msg = 0;
   char *data = 0;
@@ -182,24 +200,22 @@ Cluster_write(Continuation * cont, int expected_size,
   int len = 0;
   int flen = 0;
   int vers = CacheOpMsg_long::protoToVersion(m->msg_proto_major);
+  Ptr<IOBufferData> d;
 
   switch (opcode) {
   case CACHE_OPEN_WRITE:
     {
       // Build message if we have host data
-      if (host_len) {
-        // Determine length of data to Marshal
-        flen = op_to_sizeof_fixedlen_msg(CACHE_OPEN_WRITE);
-        len = host_len;
-
-        if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
-          goto err_exit;
-
-        msg = (char *) ALLOCA_DOUBLE(flen + len);
-        data = msg + flen;
+      len = host_len;
+      flen = op_to_sizeof_fixedlen_msg(CACHE_OPEN_WRITE);
+      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
+        goto err_exit;
 
+      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
+      msg = (char *) d->data();
+      data = msg + flen;
+      if (host_len)
         memcpy(data, hostname, host_len);
-      }
       break;
     }
   case CACHE_OPEN_WRITE_LONG:
@@ -223,8 +239,9 @@ Cluster_write(Continuation * cont, int expected_size,
       if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)       // Bound marshalled data
         goto err_exit;
 
+      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
+      msg = (char *) d->data();
       // Perform data Marshal operation
-      msg = (char *) ALLOCA_DOUBLE(flen + len);
       data = msg + flen;
       int res = 0;
 
@@ -257,7 +274,9 @@ Cluster_write(Continuation * cont, int expected_size,
     writeArgs.cfl_flags |= (old_info ? CFL_LOPENWRITE_HAVE_OLDINFO : 0);
     writeArgs.cfl_flags |= (allow_multiple_writes ? CFL_ALLOW_MULTIPLE_WRITES : 0);
 
-    return CacheContinuation::do_op(cont, m, (void *) &writeArgs, opcode, msg, flen + len, expected_size, buf);
+    Action *action = CacheContinuation::do_op(cont, session, (void *) &writeArgs, opcode, d, flen + len, expected_size, buf);
+    if (action)
+      return action;
   } else {
     //////////////////////////////////////////////////////////////
     // Create the specified down rev version of this message
@@ -267,19 +286,21 @@ Cluster_write(Continuation * cont, int expected_size,
   }
 
 err_exit:
-  Action a;
-  a = cont;
-  return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_WRITE_FAILED, 0);
+  cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, NULL);
+  return ACTION_RESULT_DONE;
 }
 
 inline Action *
 Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey * to,
              CacheFragType type, char *hostname, int host_len)
 {
-  if (clusterProcessor.disable_remote_cluster_ops(m)) {
-    Action a;
-    a = cont;
-    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LINK_FAILED, 0);
+  ClusterSession session;
+  Ptr<IOBufferData> d;
+  char *msg = NULL;
+
+  if (cluster_create_session(&session, m, NULL, 0)) {
+    cont->handleEvent(CACHE_EVENT_LINK_FAILED, NULL);
+    return ACTION_RESULT_DONE;
   }
 
   int vers = CacheOpMsg_short_2::protoToVersion(m->msg_proto_major);
@@ -293,7 +314,8 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
     if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
       goto err_exit;
 
-    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
+    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
+    msg = (char *) d->data();
     memcpy((msg + flen), hostname, host_len);
 
     // Setup args for remote link
@@ -301,7 +323,9 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
     linkArgs.from = from;
     linkArgs.to = to;
     linkArgs.frag_type = type;
-    return CacheContinuation::do_op(cont, m, (void *) &linkArgs, CACHE_LINK, msg, (flen + len));
+    Action *action = CacheContinuation::do_op(cont, session, (void *) &linkArgs, CACHE_LINK, d, (flen + len));
+    if (action)
+      return action;
   } else {
     //////////////////////////////////////////////////////////////
     // Create the specified down rev version of this message
@@ -311,18 +335,20 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
   }
 
 err_exit:
-  Action a;
-  a = cont;
-  return CacheContinuation::callback_failure(&a, CACHE_EVENT_LINK_FAILED, 0);
+  cont->handleEvent(CACHE_EVENT_LINK_FAILED, NULL);
+  return ACTION_RESULT_DONE;
 }
 
 inline Action *
 Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFragType type, char *hostname, int host_len)
 {
-  if (clusterProcessor.disable_remote_cluster_ops(m)) {
-    Action a;
-    a = cont;
-    return CacheContinuation::callback_failure(&a, CACHE_EVENT_DEREF_FAILED, 0);
+  ClusterSession session;
+  Ptr<IOBufferData> d;
+  char *msg = NULL;
+
+  if (cluster_create_session(&session, m, NULL, 0)) {
+    cont->handleEvent(CACHE_EVENT_DEREF_FAILED, NULL);
+    return ACTION_RESULT_DONE ;
   }
 
   int vers = CacheOpMsg_short::protoToVersion(m->msg_proto_major);
@@ -336,14 +362,17 @@ Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFrag
     if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
       goto err_exit;
 
-    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
+    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
+    msg = (char *) d->data();
     memcpy((msg + flen), hostname, host_len);
 
     // Setup args for remote deref
     CacheOpArgs_Deref drefArgs;
     drefArgs.md5 = key;
     drefArgs.frag_type = type;
-    return CacheContinuation::do_op(cont, m, (void *) &drefArgs, CACHE_DEREF, msg, (flen + len));
+    Action *action = CacheContinuation::do_op(cont, session, (void *) &drefArgs, CACHE_DEREF, d, (flen + len));
+    if (action)
+      return action;
   } else {
     //////////////////////////////////////////////////////////////
     // Create the specified down rev version of this message
@@ -353,19 +382,22 @@ Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFrag
   }
 
 err_exit:
-  Action a;
-  a = cont;
-  return CacheContinuation::callback_failure(&a, CACHE_EVENT_DEREF_FAILED, 0);
+  cont->handleEvent(CACHE_EVENT_DEREF_FAILED, NULL);
+  return ACTION_RESULT_DONE ;
 }
 
 inline Action *
 Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
                bool rm_user_agents, bool rm_link, CacheFragType frag_type, char *hostname, int host_len)
 {
-  if (clusterProcessor.disable_remote_cluster_ops(m)) {
-    Action a;
-    a = cont;
-    return CacheContinuation::callback_failure(&a, CACHE_EVENT_REMOVE_FAILED, 0);
+  ClusterSession session;
+  Ptr<IOBufferData> d;
+  char *msg = NULL;
+
+  if (cluster_create_session(&session, m, NULL, 0)) {
+    if (cont)
+      cont->handleEvent(CACHE_EVENT_REMOVE_FAILED, NULL);
+    return ACTION_RESULT_DONE;
   }
 
   int vers = CacheOpMsg_short::protoToVersion(m->msg_proto_major);
@@ -379,7 +411,8 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
     if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
       goto err_exit;
 
-    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
+    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
+    msg = (char *) d->data();
     memcpy((msg + flen), hostname, host_len);
 
     // Setup args for remote update
@@ -388,7 +421,9 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
     updateArgs.cfl_flags |= (rm_user_agents ? CFL_REMOVE_USER_AGENTS : 0);
     updateArgs.cfl_flags |= (rm_link ? CFL_REMOVE_LINK : 0);
     updateArgs.frag_type = frag_type;
-    return CacheContinuation::do_op(cont, m, (void *) &updateArgs, CACHE_REMOVE, msg, (flen + len));
+    Action *action = CacheContinuation::do_op(cont, session, (void *) &updateArgs, CACHE_REMOVE, d, (flen + len));
+    if (action)
+      return action;
   } else {
     //////////////////////////////////////////////////////////////
     // Create the specified down rev version of this message
@@ -398,9 +433,8 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
   }
 
 err_exit:
-  Action a;
-  a = cont;
-  return CacheContinuation::callback_failure(&a, CACHE_EVENT_REMOVE_FAILED, 0);
+  if (cont)
+    cont->handleEvent(CACHE_EVENT_REMOVE_FAILED, NULL);
+  return ACTION_RESULT_DONE;
 }
-
 #endif /* __CLUSTERINLINE_H__ */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/eventsystem/I_Event.h
----------------------------------------------------------------------
diff --git a/iocore/eventsystem/I_Event.h b/iocore/eventsystem/I_Event.h
index 7a37ea0..2659131 100644
--- a/iocore/eventsystem/I_Event.h
+++ b/iocore/eventsystem/I_Event.h
@@ -85,6 +85,7 @@
 #define BLOCK_CACHE_EVENT_EVENTS_START            4000
 #define UTILS_EVENT_EVENTS_START                  5000
 #define CONGESTION_EVENT_EVENTS_START             5100
+#define CLUSTER_MSG_START                         6000
 #define INK_API_EVENT_EVENTS_START                60000
 #define SRV_EVENT_EVENTS_START	                  62000
 #define REMAP_EVENT_EVENTS_START                  63000

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/eventsystem/P_IOBuffer.h
----------------------------------------------------------------------
diff --git a/iocore/eventsystem/P_IOBuffer.h b/iocore/eventsystem/P_IOBuffer.h
index 0842aff..261aa1f 100644
--- a/iocore/eventsystem/P_IOBuffer.h
+++ b/iocore/eventsystem/P_IOBuffer.h
@@ -203,7 +203,7 @@ new_IOBufferData_internal(
                            void *b, int64_t size, int64_t asize_index)
 {
   (void) size;
-  IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread());
+  IOBufferData *d = ioDataAllocator.alloc();
   d->_size_index = asize_index;
   ink_assert(BUFFER_SIZE_INDEX_IS_CONSTANT(asize_index)
              || size <= d->block_size());
@@ -263,7 +263,7 @@ new_IOBufferData_internal(
 #endif
                            int64_t size_index, AllocType type)
 {
-  IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread());
+  IOBufferData *d = ioDataAllocator.alloc();
 #ifdef TRACK_BUFFER_USER
   d->_location = loc;
 #endif
@@ -336,7 +336,7 @@ TS_INLINE void
 IOBufferData::free()
 {
   dealloc();
-  THREAD_FREE(this, ioDataAllocator, this_ethread());
+  ioDataAllocator.free(this);
 }
 
 //////////////////////////////////////////////////////////////////
@@ -352,7 +352,7 @@ new_IOBufferBlock_internal(
 #endif
   )
 {
-  IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread());
+  IOBufferBlock *b = ioBlockAllocator.alloc();
 #ifdef TRACK_BUFFER_USER
   b->_location = location;
 #endif
@@ -366,7 +366,7 @@ new_IOBufferBlock_internal(
 #endif
                             IOBufferData * d, int64_t len, int64_t offset)
 {
-  IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread());
+  IOBufferBlock *b = ioBlockAllocator.alloc();
 #ifdef TRACK_BUFFER_USER
   b->_location = location;
 #endif
@@ -468,7 +468,7 @@ TS_INLINE void
 IOBufferBlock::free()
 {
   dealloc();
-  THREAD_FREE(this, ioBlockAllocator, this_ethread());
+  ioBlockAllocator.free(this);
 }
 
 TS_INLINE void
@@ -777,7 +777,7 @@ TS_INLINE MIOBuffer * new_MIOBuffer_internal(
 #endif
                                                int64_t size_index)
 {
-  MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread());
+  MIOBuffer *b = ioAllocator.alloc();
 #ifdef TRACK_BUFFER_USER
   b->_location = location;
 #endif
@@ -790,7 +790,7 @@ free_MIOBuffer(MIOBuffer * mio)
 {
   mio->_writer = NULL;
   mio->dealloc_all_readers();
-  THREAD_FREE(mio, ioAllocator, this_ethread());
+  ioAllocator.free(mio);
 }
 
 TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
@@ -799,7 +799,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
 #endif
                                                      int64_t size_index)
 {
-  MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread());
+  MIOBuffer *b = ioAllocator.alloc();
   b->size_index = size_index;
 #ifdef TRACK_BUFFER_USER
   b->_location = location;
@@ -810,7 +810,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
 TS_INLINE void
 free_empty_MIOBuffer(MIOBuffer * mio)
 {
-  THREAD_FREE(mio, ioAllocator, this_ethread());
+  ioAllocator.free(mio);
 }
 
 TS_INLINE IOBufferReader *

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/mgmt/RecordsConfig.cc
----------------------------------------------------------------------
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index 4a73f19..7677471 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -814,6 +814,24 @@ RecordElement RecordsConfig[] = {
   ,
   {RECT_CONFIG, "proxy.config.cluster.cluster_port", RECD_INT, "8086", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
   ,
+  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_bps", RECD_INT, "804857600", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
+  ,
+  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_bps", RECD_INT, "4194304000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
+  ,
+  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_send_wait_time", RECD_INT, "1000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
+  ,
+  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_send_wait_time", RECD_INT, "5000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
+  ,
+  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_loop_interval", RECD_INT, "0", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
+  ,
+  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_loop_interval", RECD_INT, "1000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
+  ,
+  {RECT_CONFIG, "proxy.config.cluster.max_sessions_per_machine", RECD_INT, "1000000", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1000-4000000]", RECA_NULL}
+  ,
+  {RECT_CONFIG, "proxy.config.cluster.session_locks_per_machine", RECD_INT, "10949", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1-100000]", RECA_NULL}
+  ,
+  {RECT_CONFIG, "proxy.config.cluster.read_buffer_size", RECD_INT, "2097152", RECU_RESTART_TS, RR_NULL, RECC_INT, "[65536-2097152]", RECA_NULL}
+  ,
   {RECT_CONFIG, "proxy.config.cluster.cluster_configuration", RECD_STRING, "cluster.config", RECU_NULL, RR_NULL, RECC_NULL, NULL, RECA_NULL}
   ,
   {RECT_CONFIG, "proxy.config.cluster.ethernet_interface", RECD_STRING, TS_BUILD_DEFAULT_LOOPBACK_IFACE, RECU_RESTART_TS, RR_REQUIRED, RECC_STR, "^[^[:space:]]*$", RECA_NULL}


[2/4] refine cluster

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/ClusterConfig.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterConfig.cc b/iocore/cluster/ClusterConfig.cc
index a541364..b969f44 100644
--- a/iocore/cluster/ClusterConfig.cc
+++ b/iocore/cluster/ClusterConfig.cc
@@ -28,6 +28,9 @@
 ****************************************************************************/
 
 #include "P_Cluster.h"
+#include "machine.h"
+#include "connection.h"
+
 // updated from the cluster port configuration variable
 int cluster_port = DEFAULT_CLUSTER_PORT_NUMBER;
 
@@ -155,16 +158,30 @@ ClusterAccept::ClusterAcceptMachine(NetVConnection * NetVC)
 }
 
 static void
-make_cluster_connections(MachineList * l)
+make_cluster_connections(MachineList * l, MachineList * old)
 {
   //
   // Connect to all new machines.
   //
-  uint32_t ip = this_cluster_machine()->ip;
-  int num_connections = this_cluster_machine()->num_connections;
+  //uint32_t ip = this_cluster_machine()->ip;
+  //int num_connections = this_cluster_machine()->num_connections;
 
+  int i;
+  int k;
+  ClusterMachine *m;
   if (l) {
-    for (int i = 0; i < l->n; i++) {
+    for (i = 0; i < l->n; i++) {
+      struct in_addr in;
+      in.s_addr = l->machine[i].ip;
+      m = add_machine(l->machine[i].ip, l->machine[i].port);
+      if (m != NULL) {
+        machine_make_connections(m);
+      }
+
+      Debug(CL_NOTE, "do connect hostname: %u.%u.%u.%u:%d, %s, cluster_machine_count: %d\n",
+          DOT_SEPARATED(l->machine[i].ip), l->machine[i].port, inet_ntoa(in), cluster_machine_count);
+
+    /*
 #ifdef LOCAL_CLUSTER_TEST_MODE
       if (ip < l->machine[i].ip || (ip == l->machine[i].ip && (cluster_port < l->machine[i].port))) {
 #else
@@ -175,6 +192,48 @@ make_cluster_connections(MachineList * l)
         }
       }
     }
+    */
+    }
+  }
+
+  if (old == NULL) {
+    return;
+  }
+
+  //found down machines
+  if (l == NULL) {
+    for (i = 0; i < old->n; i++) {
+      struct in_addr in;
+      in.s_addr = old->machine[i].ip;
+      Debug(CL_NOTE, "stop connect hostname: %u.%u.%u.%u:%d, %s\n",
+          DOT_SEPARATED(old->machine[i].ip), old->machine[i].port, inet_ntoa(in));
+      m = get_machine(old->machine[i].ip, old->machine[i].port);
+      if (m != NULL) {
+        machine_stop_reconnect(m);
+      }
+    }
+  }
+  else {
+    for (i = 0; i < old->n; i++) {
+      for (k = 0; k < l->n; k++) {
+        if (l->machine[k].ip == old->machine[i].ip &&
+            l->machine[k].port == old->machine[i].port)
+        {
+          break;
+        }
+      }
+
+      if (k == l->n) {  //not found, machine down
+        struct in_addr in;
+        in.s_addr = old->machine[i].ip;
+        Debug(CL_NOTE, "stop connect hostname: %u.%u.%u.%u:%d, %s\n",
+            DOT_SEPARATED(old->machine[i].ip), old->machine[i].port, inet_ntoa(in));
+        m = get_machine(old->machine[i].ip, old->machine[i].port);
+        if (m != NULL) {
+          machine_stop_reconnect(m);
+        }
+      }
+    }
   }
 }
 
@@ -201,7 +260,7 @@ machine_config_change(const char * /* name ATS_UNUSED */, RecDataT /* data_type
   case CLUSTER_CONFIG:
     old = cluster_config;
     cluster_config = l;
-    make_cluster_connections(l);
+    make_cluster_connections(l, old);
     break;
   }
 #else
@@ -209,7 +268,7 @@ machine_config_change(const char * /* name ATS_UNUSED */, RecDataT /* data_type
   old = cluster_config;
   machines_config = l;
   cluster_config = l;
-  make_cluster_connections(l);
+  make_cluster_connections(l, old);
 #endif
   if (old)
     free_MachineList(old);
@@ -291,8 +350,10 @@ configuration_add_machine(ClusterConfiguration * c, ClusterMachine * m)
   // Build a new cluster configuration with the new machine.
   // Machines are stored in ip sorted order.
   //
+  /*
   EThread *thread = this_ethread();
   ProxyMutex *mutex = thread->mutex;
+  */
   int i = 0;
   ClusterConfiguration *cc = NEW(new ClusterConfiguration(*c));
 
@@ -319,7 +380,7 @@ configuration_add_machine(ClusterConfiguration * c, ClusterMachine * m)
 
   build_cluster_hash_table(cc);
   INK_MEMORY_BARRIER;           // commit writes before freeing old hash table
-  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONFIGURATION_CHANGES_STAT);
+  //CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONFIGURATION_CHANGES_STAT);
 
   free_configuration(c, cc);
   return cc;
@@ -328,9 +389,6 @@ configuration_add_machine(ClusterConfiguration * c, ClusterMachine * m)
 ClusterConfiguration *
 configuration_remove_machine(ClusterConfiguration * c, ClusterMachine * m)
 {
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
-
   //
   // Build a new cluster configuration without a machine
   //
@@ -350,7 +408,7 @@ configuration_remove_machine(ClusterConfiguration * c, ClusterMachine * m)
 
   build_cluster_hash_table(cc);
   INK_MEMORY_BARRIER;           // commit writes before freeing old hash table
-  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONFIGURATION_CHANGES_STAT);
+  //CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONFIGURATION_CHANGES_STAT);
 
   free_configuration(c, cc);
   return cc;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/ClusterMachine.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterMachine.cc b/iocore/cluster/ClusterMachine.cc
index 00e99e6..1ac4fae 100644
--- a/iocore/cluster/ClusterMachine.cc
+++ b/iocore/cluster/ClusterMachine.cc
@@ -77,9 +77,9 @@ ClusterMachine::ClusterMachine(char *ahostname, unsigned int aip, int aport)
     msg_proto_minor(0),
     clusterHandlers(0)
 {
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
-  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_MACHINES_ALLOCATED_STAT);
+  //EThread *thread = this_ethread();
+  //ProxyMutex *mutex = thread->mutex;
+  //CLUSTER_INCREMENT_DYN_STAT(CLUSTER_MACHINES_ALLOCATED_STAT);
   if (!aip) {
     char localhost[1024];
     if (!ahostname) {
@@ -166,7 +166,7 @@ ClusterHandler *ClusterMachine::pop_ClusterHandler(int no_rr)
 ClusterMachine::~ClusterMachine()
 {
   ats_free(hostname);
-  ats_free(clusterHandlers);
+  // ats_free(clusterHandlers);
 }
 
 struct MachineTimeoutContinuation;
@@ -193,10 +193,10 @@ struct MachineTimeoutContinuation: public Continuation
 void
 free_ClusterMachine(ClusterMachine * m)
 {
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
+  //EThread *thread = this_ethread();
+  //ProxyMutex *mutex = thread->mutex;
   // delay before the final free
-  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_MACHINES_FREED_STAT);
+  //CLUSTER_INCREMENT_DYN_STAT(CLUSTER_MACHINES_FREED_STAT);
   m->dead = true;
   eventProcessor.schedule_in(NEW(new MachineTimeoutContinuation(m)), MACHINE_TIMEOUT, ET_CALL);
 }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/ClusterProcessor.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterProcessor.cc b/iocore/cluster/ClusterProcessor.cc
index b01e0ff..ab6c0a0 100644
--- a/iocore/cluster/ClusterProcessor.cc
+++ b/iocore/cluster/ClusterProcessor.cc
@@ -28,21 +28,34 @@
 ****************************************************************************/
 
 #include "P_Cluster.h"
+#include "global.h"
+#include "connection.h"
+
 /*************************************************************************/
 // ClusterProcessor member functions (Public class)
 /*************************************************************************/
 int cluster_port_number = DEFAULT_CLUSTER_PORT_NUMBER;
 int cache_clustering_enabled = 0;
 int num_of_cluster_threads = DEFAULT_NUMBER_OF_CLUSTER_THREADS;
+int num_of_cluster_connections = 0;
 
 ClusterProcessor clusterProcessor;
 RecRawStatBlock *cluster_rsb = NULL;
 int ET_CLUSTER;
 
+void cluster_main_handler(ClusterSession session, void *context,
+    const int func_id, IOBufferBlock *data, const int data_len);
 ClusterProcessor::ClusterProcessor():accept_handler(NULL), this_cluster(NULL)
 {
 }
 
+
+//void cluster_error_handler(int event, void *arg);
+//void cluster_main_handler(ClusterSession *session, const int func_id,
+//  void *data, const int data_len) {
+//  ClusterRPC[func_id](session, data, data_len);
+//}
+
 ClusterProcessor::~ClusterProcessor()
 {
   if (accept_handler) {
@@ -55,98 +68,111 @@ int
 ClusterProcessor::internal_invoke_remote(ClusterHandler *ch, int cluster_fn,
                                          void *data, int len, int options, void *cmsg)
 {
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
-  //
-  // RPC facility for intercluster communication available to other
-  //  subsystems.
-  //
-  bool steal = (options & CLUSTER_OPT_STEAL ? true : false);
-  bool delay = (options & CLUSTER_OPT_DELAY ? true : false);
-  bool data_in_ocntl = (options & CLUSTER_OPT_DATA_IS_OCONTROL ? true : false);
-  bool malloced = (cluster_fn == CLUSTER_FUNCTION_MALLOCED);
-  OutgoingControl *c;
-
-  if (!ch || (!malloced && !((unsigned int) cluster_fn < (uint32_t) SIZE_clusterFunction))) {
-    // Invalid message or node is down, free message data
-    if (malloced) {
-      ats_free(data);
-    }
-    if (cmsg) {
-      invoke_remote_data_args *args = (invoke_remote_data_args *)
-        (((OutgoingControl *) cmsg)->data + sizeof(int32_t));
-      ink_assert(args->magicno == invoke_remote_data_args::MagicNo);
+//  EThread *thread = this_ethread();
+//  ProxyMutex *mutex = thread->mutex;
+//  //
+//  // RPC facility for intercluster communication available to other
+//  //  subsystems.
+//  //
+//  bool steal = (options & CLUSTER_OPT_STEAL ? true : false);
+//  bool delay = (options & CLUSTER_OPT_DELAY ? true : false);
+//  bool data_in_ocntl = (options & CLUSTER_OPT_DATA_IS_OCONTROL ? true : false);
+//  bool malloced = (cluster_fn == CLUSTER_FUNCTION_MALLOCED);
+//  OutgoingControl *c;
+//
+//  if (!ch || (!malloced && !((unsigned int) cluster_fn < (uint32_t) SIZE_clusterFunction))) {
+//    // Invalid message or node is down, free message data
+//    if (malloced) {
+//      ats_free(data);
+//    }
+//    if (cmsg) {
+//      invoke_remote_data_args *args = (invoke_remote_data_args *)
+//        (((OutgoingControl *) cmsg)->data + sizeof(int32_t));
+//      ink_assert(args->magicno == invoke_remote_data_args::MagicNo);
+//
+//      args->data_oc->freeall();
+//      ((OutgoingControl *) cmsg)->freeall();
+//    }
+//    if (data_in_ocntl) {
+//      c = *((OutgoingControl **) ((char *) data - sizeof(OutgoingControl *)));
+//      c->freeall();
+//    }
+//    return -1;
+//  }
+//
+//  if (data_in_ocntl) {
+//    c = *((OutgoingControl **) ((char *) data - sizeof(OutgoingControl *)));
+//  } else {
+//    c = OutgoingControl::alloc();
+//  }
+//  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CTRL_MSGS_SENT_STAT);
+//  c->submit_time = ink_get_hrtime();
+//  if ((c->zero_body = zero_body)) {
+//    c->free_proc = &CacheContinuation::disposeOfDataBuffer;
+//    c->free_proc_arg = cc;
+//  }
+//
+//  if (malloced) {
+//    c->set_data((char *) data, len);
+//  } else {
+//    if (!data_in_ocntl) {
+//      c->len = len + sizeof(int32_t);
+//      c->alloc_data();
+//    }
+//    if (!c->fast_data()) {
+//      CLUSTER_INCREMENT_DYN_STAT(CLUSTER_SLOW_CTRL_MSGS_SENT_STAT);
+//    }
+//    *(int32_t *) c->data = cluster_fn;
+//    if (!data_in_ocntl) {
+//      memcpy(c->data + sizeof(int32_t), data, len);
+//    }
+//  }
+//
+//  SET_CONTINUATION_HANDLER(c, (OutgoingCtrlHandler) & OutgoingControl::startEvent);
+//
+//  /////////////////////////////////////
+//  // Compound message adjustments
+//  /////////////////////////////////////
+//  if (cmsg) {
+//    invoke_remote_data_args *args = (invoke_remote_data_args *)
+//      (((OutgoingControl *) cmsg)->data + sizeof(int32_t));
+//    ink_assert(args->magicno == invoke_remote_data_args::MagicNo);
+//    args->msg_oc = c;
+//    c = (OutgoingControl *) cmsg;
+//  }
+//#ifndef CLUSTER_THREAD_STEALING
+//  delay = true;
+//#endif
+//  if (!delay) {
+//    EThread *tt = this_ethread();
+//    {
+//      int q = ClusterFuncToQpri(cluster_fn);
+//      ink_atomiclist_push(&ch->outgoing_control_al[q], (void *) c);
+//
+//      MUTEX_TRY_LOCK(lock, ch->mutex, tt);
+//      if (!lock) {
+//		if(ch->thread && ch->thread->signal_hook)
+//		  ch->thread->signal_hook(ch->thread);
+//		return 1;
+//      }
+//      if (steal)
+//        ch->steal_thread(tt);
+//      return 1;
+//    }
+//  } else {
+//    c->mutex = ch->mutex;
+//    eventProcessor.schedule_imm_signal(c);
+//    return 0;
+//  }
+
+  (void) ch;
+  (void) cluster_fn;
+  (void) data;
+  (void) len;
+  (void) options;
+  (void) cmsg;
 
-      args->data_oc->freeall();
-      ((OutgoingControl *) cmsg)->freeall();
-    }
-    if (data_in_ocntl) {
-      c = *((OutgoingControl **) ((char *) data - sizeof(OutgoingControl *)));
-      c->freeall();
-    }
-    return -1;
-  }
-
-  if (data_in_ocntl) {
-    c = *((OutgoingControl **) ((char *) data - sizeof(OutgoingControl *)));
-  } else {
-    c = OutgoingControl::alloc();
-  }
-  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CTRL_MSGS_SENT_STAT);
-  c->submit_time = ink_get_hrtime();
-
-  if (malloced) {
-    c->set_data((char *) data, len);
-  } else {
-    if (!data_in_ocntl) {
-      c->len = len + sizeof(int32_t);
-      c->alloc_data();
-    }
-    if (!c->fast_data()) {
-      CLUSTER_INCREMENT_DYN_STAT(CLUSTER_SLOW_CTRL_MSGS_SENT_STAT);
-    }
-    *(int32_t *) c->data = cluster_fn;
-    if (!data_in_ocntl) {
-      memcpy(c->data + sizeof(int32_t), data, len);
-    }
-  }
-
-  SET_CONTINUATION_HANDLER(c, (OutgoingCtrlHandler) & OutgoingControl::startEvent);
-
-  /////////////////////////////////////
-  // Compound message adjustments
-  /////////////////////////////////////
-  if (cmsg) {
-    invoke_remote_data_args *args = (invoke_remote_data_args *)
-      (((OutgoingControl *) cmsg)->data + sizeof(int32_t));
-    ink_assert(args->magicno == invoke_remote_data_args::MagicNo);
-    args->msg_oc = c;
-    c = (OutgoingControl *) cmsg;
-  }
-#ifndef CLUSTER_THREAD_STEALING
-  delay = true;
-#endif
-  if (!delay) {
-    EThread *tt = this_ethread();
-    {
-      int q = ClusterFuncToQpri(cluster_fn);
-      ink_atomiclist_push(&ch->outgoing_control_al[q], (void *) c);
-
-      MUTEX_TRY_LOCK(lock, ch->mutex, tt);
-      if (!lock) {
-		if(ch->thread && ch->thread->signal_hook)
-		  ch->thread->signal_hook(ch->thread);
-		return 1;
-      }
-      if (steal)
-        ch->steal_thread(tt);
-      return 1;
-    }
-  } else {
-    c->mutex = ch->mutex;
-    eventProcessor.schedule_imm_signal(c);
-    return 0;
-  }
+  return 0;
 }
 
 int
@@ -162,45 +188,56 @@ ClusterProcessor::invoke_remote_data(ClusterHandler *ch, int cluster_fn,
                                      int dest_channel, ClusterVCToken * token,
                                      void (*bufdata_free_proc) (void *), void *bufdata_free_proc_arg, int options)
 {
-  if (!buf) {
-    // No buffer data, translate this into a invoke_remote() request
-    return internal_invoke_remote(ch, cluster_fn, data, data_len, options, (void *) NULL);
-  }
-  ink_assert(data);
-  ink_assert(data_len);
-  ink_assert(dest_channel);
-  ink_assert(token);
-  ink_assert(bufdata_free_proc);
-  ink_assert(bufdata_free_proc_arg);
-
-  /////////////////////////////////////////////////////////////////////////
-  // Build the compound message as described by invoke_remote_data_args.
-  /////////////////////////////////////////////////////////////////////////
-
-  // Build OutgoingControl for buffer data
-  OutgoingControl *bufdata_oc = OutgoingControl::alloc();
-  bufdata_oc->set_data(buf, bufdata_free_proc, bufdata_free_proc_arg);
-
-  // Build OutgoingControl for compound message header
-  invoke_remote_data_args mh;
-  mh.msg_oc = 0;
-  mh.data_oc = bufdata_oc;
-  mh.dest_channel = dest_channel;
-  mh.token = *token;
-
-  OutgoingControl *chdr = OutgoingControl::alloc();
-  chdr->submit_time = ink_get_hrtime();
-  chdr->len = sizeof(int32_t) + sizeof(mh);
-  chdr->alloc_data();
-  *(int32_t *) chdr->data = -1;   // always -1 for compound message
-  memcpy(chdr->data + sizeof(int32_t), (char *) &mh, sizeof(mh));
-
-  return internal_invoke_remote(ch, cluster_fn, data, data_len, options, (void *) chdr);
+//  if (!buf) {
+//    // No buffer data, translate this into a invoke_remote() request
+//    return internal_invoke_remote(ch, cluster_fn, data, data_len, options, (void *) NULL, zero_body, bufdata_free_proc_arg);
+//  }
+//  ink_assert(data);
+//  ink_assert(data_len);
+//  ink_assert(dest_channel);
+//  ink_assert(token);
+//  ink_assert(bufdata_free_proc);
+//  ink_assert(bufdata_free_proc_arg);
+//
+//  /////////////////////////////////////////////////////////////////////////
+//  // Build the compound message as described by invoke_remote_data_args.
+//  /////////////////////////////////////////////////////////////////////////
+//
+//  // Build OutgoingControl for buffer data
+//  OutgoingControl *bufdata_oc = OutgoingControl::alloc();
+//  bufdata_oc->set_data(buf, bufdata_free_proc, bufdata_free_proc_arg);
+//
+//  // Build OutgoingControl for compound message header
+//  invoke_remote_data_args mh;
+//  mh.msg_oc = 0;
+//  mh.data_oc = bufdata_oc;
+//  mh.dest_channel = dest_channel;
+//  mh.token = *token;
+//
+//  OutgoingControl *chdr = OutgoingControl::alloc();
+//  chdr->submit_time = ink_get_hrtime();
+//  chdr->len = sizeof(int32_t) + sizeof(mh);
+//  chdr->alloc_data();
+//  *(int32_t *) chdr->data = -1;   // always -1 for compound message
+//  memcpy(chdr->data + sizeof(int32_t), (char *) &mh, sizeof(mh));
+//
+//  return internal_invoke_remote(ch, cluster_fn, data, data_len, options, (void *) chdr);
+
+  (void) ch;
+  (void) cluster_fn;
+  (void) data;
+  (void) data_len;
+  (void) buf;
+  (void) dest_channel;
+  (void) token;
+  (void) bufdata_free_proc;
+  (void) bufdata_free_proc_arg;
+  (void) options;
+  return 0;
 }
 
-// TODO: Why pass in the length here if not used ?
 void
-ClusterProcessor::free_remote_data(char *p, int /* l ATS_UNUSED */)
+ClusterProcessor::free_remote_data(char *p, int /* l */)
 {
   char *d = p - sizeof(int32_t);  // reset to ptr to function code
   int data_hdr = ClusterControl::DATA_HDR;
@@ -225,65 +262,70 @@ ClusterProcessor::free_remote_data(char *p, int /* l ATS_UNUSED */)
 }
 
 ClusterVConnection *
-ClusterProcessor::open_local(Continuation * cont, ClusterMachine */* m ATS_UNUSED */, ClusterVCToken & token, int options)
+ClusterProcessor::open_local(Continuation * cont, ClusterMachine * m, ClusterVCToken & token, int options)
 {
-  //
-  //  New connect protocol.
-  //  As a VC initiator, establish the VC connection to the remote node
-  //  by allocating the VC locally and requiring the caller to pass the
-  //  token and channel id in the remote request.  The remote handler calls
-  //  connect_local to establish the remote side of the connection.
-  //
-  bool immediate = ((options & CLUSTER_OPT_IMMEDIATE) ? true : false);
-  bool allow_immediate = ((options & CLUSTER_OPT_ALLOW_IMMEDIATE) ? true : false);
-
-  ClusterHandler *ch = ((CacheContinuation *)cont)->ch;
-  if (!ch)
-    return NULL;
-  EThread *t = ch->thread;
-  if (!t)
-    return NULL;
-
-  EThread *thread = this_ethread();
-  ProxyMutex *mutex = thread->mutex;
-  ClusterVConnection *vc = clusterVCAllocator.alloc();
-  vc->new_connect_read = (options & CLUSTER_OPT_CONN_READ ? 1 : 0);
-  vc->start_time = ink_get_hrtime();
-  vc->last_activity_time = vc->start_time;
-  vc->ch = ch;
-  vc->token.alloc();
-  vc->token.ch_id = ch->id;
-  token = vc->token;
-#ifdef CLUSTER_THREAD_STEALING
-  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONNECTIONS_OPENNED_STAT);
-  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONNECTIONS_OPEN_STAT);
-  MUTEX_TRY_LOCK(lock, ch->mutex, thread);
-  if (!lock) {
-#endif
-    if (immediate) {
-      clusterVCAllocator_free(vc);
-      return NULL;
-    }
-    vc->action_ = cont;
-    ink_atomiclist_push(&ch->external_incoming_open_local, (void *) vc);
-	if(ch->thread && ch->thread->signal_hook)
-	  ch->thread->signal_hook(ch->thread);
-    return CLUSTER_DELAYED_OPEN;
-
-#ifdef CLUSTER_THREAD_STEALING
-  } else {
-    if (!(immediate || allow_immediate))
-      vc->action_ = cont;
-    if (vc->start(thread) < 0) {
-      return NULL;
-    }
-    if (immediate || allow_immediate) {
-      return vc;
-    } else {
-      return CLUSTER_DELAYED_OPEN;
-    }
-  }
-#endif
+//  //
+//  //  New connect protocol.
+//  //  As a VC initiator, establish the VC connection to the remote node
+//  //  by allocating the VC locally and requiring the caller to pass the
+//  //  token and channel id in the remote request.  The remote handler calls
+//  //  connect_local to establish the remote side of the connection.
+//  //
+//  bool immediate = ((options & CLUSTER_OPT_IMMEDIATE) ? true : false);
+//  bool allow_immediate = ((options & CLUSTER_OPT_ALLOW_IMMEDIATE) ? true : false);
+//
+//  ClusterHandler *ch = ((CacheContinuation *)cont)->ch;
+//  if (!ch)
+//    return NULL;
+//  EThread *t = ch->thread;
+//  if (!t)
+//    return NULL;
+//
+//  EThread *thread = this_ethread();
+//  ProxyMutex *mutex = thread->mutex;
+//  ClusterVConnection *vc = clusterVCAllocator.alloc();
+//  vc->new_connect_read = (options & CLUSTER_OPT_CONN_READ ? 1 : 0);
+//  vc->start_time = ink_get_hrtime();
+//  vc->last_activity_time = vc->start_time;
+//  vc->ch = ch;
+//  vc->token.alloc();
+//  vc->token.ch_id = ch->id;
+//  token = vc->token;
+//#ifdef CLUSTER_THREAD_STEALING
+//  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONNECTIONS_OPENNED_STAT);
+//  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CONNECTIONS_OPEN_STAT);
+//  MUTEX_TRY_LOCK(lock, ch->mutex, thread);
+//  if (!lock) {
+//#endif
+//    if (immediate) {
+//      clusterVCAllocator_free(vc);
+//      return NULL;
+//    }
+//    vc->action_ = cont;
+//    ink_atomiclist_push(&ch->external_incoming_open_local, (void *) vc);
+//	if(ch->thread && ch->thread->signal_hook)
+//	  ch->thread->signal_hook(ch->thread);
+//    return CLUSTER_DELAYED_OPEN;
+//
+//#ifdef CLUSTER_THREAD_STEALING
+//  } else {
+//    if (!(immediate || allow_immediate))
+//      vc->action_ = cont;
+//    if (vc->start(thread) < 0) {
+//      return NULL;
+//    }
+//    if (immediate || allow_immediate) {
+//      return vc;
+//    } else {
+//      return CLUSTER_DELAYED_OPEN;
+//    }
+//  }
+//#endif
+  (void) cont;
+  (void) m;
+  (void) token;
+  (void) options;
+  return NULL;
 }
 
 ClusterVConnection *
@@ -367,9 +409,10 @@ bool ClusterProcessor::disable_remote_cluster_ops(ClusterMachine * m)
 // Simplify debug access to stats
 ////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////
-
+/*
 GlobalClusterPeriodicEvent *
   PeriodicClusterEvent;
+*/
 
 #ifdef CLUSTER_TOMCAT
 extern int cache_clustering_enabled;
@@ -386,6 +429,77 @@ unsigned long cluster_packet_tos = 0;
 int RPC_only_CacheCluster = 0;
 #endif
 
+static int machine_change_notify(ClusterMachine * m)
+{
+  //char textbuf[sizeof("255.255.255.255:65535")];
+  int result;
+
+  Debug("cluster_io", "start notify, machine %s %hhu.%hhu.%hhu.%hhu:%d, version: %d.%d",
+      m->dead ? "down" : "up",
+      DOT_SEPARATED(m->ip), m->cluster_port, m->msg_proto_major,
+      m->msg_proto_minor);
+
+  if (m->dead) {
+    ClusterConfiguration *c = this_cluster()->current_configuration();
+    if (c->find(m->ip, m->cluster_port)) {
+      ClusterConfiguration *cc = configuration_remove_machine(c, m);
+      //CLUSTER_DECREMENT_DYN_STAT(CLUSTER_NODES_STAT);
+      this_cluster()->configurations.push(cc);
+      result = 0;
+    }
+    else {
+      result = ENOENT;
+    }
+
+    Note("machine down %hhu.%hhu.%hhu.%hhu:%d, version=%d.%d",
+        DOT_SEPARATED(m->ip), m->cluster_port, m->msg_proto_major,
+        m->msg_proto_minor);
+    /*
+    snprintf(textbuf, sizeof(textbuf), "%hhu.%hhu.%hhu.%hhu:%d", DOT_SEPARATED(m->ip), m->cluster_port);
+    REC_SignalManager(REC_SIGNAL_MACHINE_DOWN, textbuf);
+    */
+  }
+  else {
+    ClusterConfiguration *c = this_cluster()->current_configuration();
+    if (c->find(m->ip, m->cluster_port)) {
+      Warning("machine %hhu.%hhu.%hhu.%hhu:%d already up",
+        DOT_SEPARATED(m->ip), m->cluster_port);
+      result = EEXIST;
+    }
+    else {
+        ClusterConfiguration *cconf = configuration_add_machine(c, m);
+        //CLUSTER_INCREMENT_DYN_STAT(CLUSTER_NODES_STAT);
+        this_cluster()->configurations.push(cconf);
+        result = 0;
+    }
+
+    Note("machine up %hhu.%hhu.%hhu.%hhu:%d, version=%d.%d",
+        DOT_SEPARATED(m->ip), m->cluster_port, m->msg_proto_major,
+        m->msg_proto_minor);
+
+    /*
+    snprintf(textbuf, sizeof(textbuf), "%hhu.%hhu.%hhu.%hhu:%d", DOT_SEPARATED(m->ip), m->cluster_port);
+    REC_SignalManager(REC_SIGNAL_MACHINE_UP, textbuf);
+    */
+  }
+
+  return result;
+}
+
+
+static int
+cluster_ping_config_cb(const char *name, RecDataT /* data_type */, RecData data, void * /* cookie */)
+{
+  if (strcmp(name, "proxy.config.cluster.ping_send_interval_msecs") == 0) {
+    cluster_ping_send_interval = data.rec_int * HRTIME_MSECOND;
+  }
+  else if (strcmp(name, "proxy.config.cluster.ping_latency_threshold_msecs") == 0) {
+    cluster_ping_latency_threshold =  data.rec_int * HRTIME_MSECOND;
+  }
+
+  return 0;
+}
+
 int
 ClusterProcessor::init()
 {
@@ -686,6 +800,11 @@ ClusterProcessor::init()
   if (num_of_cluster_threads == DEFAULT_NUMBER_OF_CLUSTER_THREADS)
     REC_ReadConfigInteger(num_of_cluster_threads, "proxy.config.cluster.threads");
 
+  REC_ReadConfigInteger(num_of_cluster_connections, "proxy.config.cluster.connections");
+  if (num_of_cluster_connections == 0) {
+    num_of_cluster_connections = num_of_cluster_threads;
+  }
+
   REC_EstablishStaticConfigInt32(CacheClusterMonitorEnabled, "proxy.config.cluster.enable_monitor");
   REC_EstablishStaticConfigInt32(CacheClusterMonitorIntervalSecs, "proxy.config.cluster.monitor_interval_secs");
   REC_ReadConfigInteger(cluster_receive_buffer_size, "proxy.config.cluster.receive_buffer_size");
@@ -695,17 +814,28 @@ ClusterProcessor::init()
   REC_ReadConfigInteger(cluster_packet_tos, "proxy.config.cluster.sock_packet_tos");
   REC_EstablishStaticConfigInt32(RPC_only_CacheCluster, "proxy.config.cluster.rpc_cache_cluster");
 
+  REC_EstablishStaticConfigInteger(cluster_flow_ctrl_min_bps, "proxy.config.cluster.flow_ctrl.min_bps");
+  REC_EstablishStaticConfigInteger(cluster_flow_ctrl_max_bps, "proxy.config.cluster.flow_ctrl.max_bps");
+  REC_EstablishStaticConfigInt32(cluster_send_min_wait_time, "proxy.config.cluster.flow_ctrl.min_send_wait_time");
+  REC_EstablishStaticConfigInt32(cluster_send_max_wait_time, "proxy.config.cluster.flow_ctrl.max_send_wait_time");
+  REC_EstablishStaticConfigInt32(cluster_min_loop_interval, "proxy.config.cluster.flow_ctrl.min_loop_interval");
+  REC_EstablishStaticConfigInt32(cluster_max_loop_interval, "proxy.config.cluster.flow_ctrl.max_loop_interval");
+
   int cluster_type = 0;
   REC_ReadConfigInteger(cluster_type, "proxy.local.cluster.type");
 
   create_this_cluster_machine();
+
+  /*
 #ifdef NON_MODULAR
   // Cluster API Initializations
   clusterAPI_init();
 #endif
+
   // Start global Cluster periodic event
   PeriodicClusterEvent = NEW(new GlobalClusterPeriodicEvent);
   PeriodicClusterEvent->init();
+  */
 
   this_cluster = NEW(new Cluster);
   ClusterConfiguration *cc = NEW(new ClusterConfiguration);
@@ -713,19 +843,61 @@ ClusterProcessor::init()
   cc->n_machines = 1;
   cc->machines[0] = this_cluster_machine();
   memset(cc->hash_table, 0, CLUSTER_HASH_TABLE_SIZE);
-  // 0 dummy output data
 
+  /*
+  // 0 dummy output data
   memset(channel_dummy_output, 0, sizeof(channel_dummy_output));
+  */
+
+  int result;
 
   if (cluster_type == 1) {
-    cache_clustering_enabled = 1;
-    Note("cache clustering enabled");
-    compute_cluster_mode();
+    REC_ReadConfigInteger(cluster_ping_send_interval, "proxy.config.cluster.ping_send_interval_msecs");
+    REC_ReadConfigInteger(cluster_ping_latency_threshold, "proxy.config.cluster.ping_latency_threshold_msecs");
+    cluster_ping_send_interval *= HRTIME_MSECOND;
+    cluster_ping_latency_threshold *= HRTIME_MSECOND;
+
+    REC_RegisterConfigUpdateFunc("proxy.config.cluster.ping_send_interval_msecs", cluster_ping_config_cb, NULL);
+    REC_RegisterConfigUpdateFunc("proxy.config.cluster.ping_latency_threshold_msecs", cluster_ping_config_cb, NULL);
+    REC_EstablishStaticConfigInt32(cluster_ping_retries, "proxy.config.cluster.ping_retries");
+
+    REC_ReadConfigInteger(max_session_count_per_machine, "proxy.config.cluster.max_sessions_per_machine");
+    REC_ReadConfigInteger(session_lock_count_per_machine, "proxy.config.cluster.session_locks_per_machine");
+
+    bool found;
+    IpEndpoint cluster_ip;    // ip addr of the cluster interface
+    char *intrName;               // Name of the interface we are to use
+    intrName = REC_readString("proxy.config.cluster.ethernet_interface", &found);
+    ink_assert(found && intrName != NULL);
+
+    found = mgmt_getAddrForIntr(intrName, &cluster_ip.sa);
+    if (!found) {
+      ink_fatal(1, "[ClusterProcessor::init] Unable to find network interface %s.  Exiting...\n", intrName);
+    } else if (!ats_is_ip4(&cluster_ip)) {
+      ink_fatal(1, "[ClusterProcessor::init] Unable to find IPv4 network interface %s.  Exiting...\n", intrName);
+    }
+
+    if (num_of_cluster_connections % 2 != 0) {
+      num_of_cluster_connections++;
+    }
+    cluster_global_init(cluster_main_handler, machine_change_notify);
+
+    result = connection_manager_init(cluster_ip.sin.sin_addr.s_addr);
+    if (result == 0) {
+      cache_clustering_enabled = 1;
+      Note("cache clustering enabled");
+      compute_cluster_mode();
+    }
+    else {
+      cache_clustering_enabled = 0;
+      Note("init fail, cache clustering disabled");
+    }
   } else {
     cache_clustering_enabled = 0;
     Note("cache clustering disabled");
+    result = 0;
   }
-  return 0;
+  return result;
 }
 
 // function added to adhere to the name calling convention of init functions
@@ -742,13 +914,18 @@ ClusterProcessor::start()
   this_cluster_machine()->cluster_port = cluster_port;
 #endif
   if (cache_clustering_enabled && (cacheProcessor.IsCacheEnabled() == CACHE_INITIALIZED)) {
-    size_t stacksize;
 
-    REC_ReadConfigInteger(stacksize, "proxy.config.thread.default.stacksize");
-    ET_CLUSTER = eventProcessor.spawn_event_threads(num_of_cluster_threads, "ET_CLUSTER", stacksize);
+    /*
+    ET_CLUSTER = eventProcessor.spawn_event_threads(num_of_cluster_threads, "ET_CLUSTER");
     for (int i = 0; i < eventProcessor.n_threads_for_type[ET_CLUSTER]; i++) {
-      initialize_thread_for_net(eventProcessor.eventthread[ET_CLUSTER][i]);
+      initialize_thread_for_net(eventProcessor.eventthread[ET_CLUSTER][i], i);
+#ifndef STANDALONE_IOCORE
+      extern void initialize_thread_for_http_sessions(EThread *thread, int thread_index);
+      initialize_thread_for_http_sessions(eventProcessor.eventthread[ET_CLUSTER][i], i);
+#endif
     }
+    */
+
     REC_RegisterConfigUpdateFunc("proxy.config.cluster.cluster_configuration", machine_config_change, (void *) CLUSTER_CONFIG);
     do_machine_config_change((void *) CLUSTER_CONFIG, "proxy.config.cluster.cluster_configuration");
     // TODO: Remove this?
@@ -757,9 +934,12 @@ ClusterProcessor::start()
     do_machine_config_change((void *) MACHINE_CONFIG, "proxy.config.cluster.machine_configuration");
 #endif
 
-    accept_handler = NEW(new ClusterAccept(&cluster_port, cluster_receive_buffer_size, cluster_send_buffer_size));
-    accept_handler->Init();
+    //accept_handler = NEW(new ClusterAccept(&cluster_port, cluster_receive_buffer_size, cluster_send_buffer_size));
+    //accept_handler->Init();
+
+    connection_manager_start();
   }
+
   return 0;
 }
 
@@ -846,4 +1026,53 @@ ClusterProcessor::compute_cluster_mode()
   }
 }
 
+
+void cluster_main_handler(ClusterSession session, void *context,
+    const int func_id, IOBufferBlock *data, const int data_len)
+{
+  int event = func_id < 0 ? -func_id: func_id;
+  switch (event) {
+    case CLUSTER_CACHE_DATA_ABORT:
+    case CLUSTER_CACHE_DATA_READ_REENABLE: {
+      ink_assert(data_len == 0 && context && data == NULL);
+      CacheContinuation *cc = (CacheContinuation *) context;
+      cc->thread->schedule_imm(cc, event);
+      return;
+    }
+    default: {
+      ClusterCont *cc = clusterContAllocator.alloc();
+      SET_CONTINUATION_HANDLER(cc, &ClusterCont::handleEvent);
+      cc->session = session;
+      cc->context = context;
+      cc->func_id = event;
+      cc->data = data;
+      cc->data_len = data_len;
+      cc->_action = (Continuation *) context;
+      if (cc->_action.continuation) {
+        cc->mutex = cc->_action.mutex;
+      }
+#ifdef DEBUG
+      int64_t nbytes = 0;
+      for (IOBufferBlock *b = data; b; b = b->next) {
+        nbytes += b->read_avail();
+      }
+      ink_assert(data_len == nbytes);
+#endif
+
+      if (event == CLUSTER_CACHE_DATA_READ_DONE
+          || event == CLUSTER_CACHE_DATA_ERROR
+          || event == CLUSTER_CACHE_OP_RESULT_CLUSTER_FUNCTION) {
+        ink_assert(context);
+        ClusterCacheVC *cvc = (ClusterCacheVC *) context;
+        cvc->initial_thread->schedule_imm(cc);
+        return;
+      }
+
+      eventProcessor.schedule_imm(cc);
+      return;
+    }
+  }
+}
+
+
 // End of ClusterProcessor.cc

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/ClusterVConnection.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterVConnection.cc b/iocore/cluster/ClusterVConnection.cc
index 0630edf..a76c912 100644
--- a/iocore/cluster/ClusterVConnection.cc
+++ b/iocore/cluster/ClusterVConnection.cc
@@ -30,6 +30,17 @@
 #include "P_Cluster.h"
 ClassAllocator<ClusterVConnection> clusterVCAllocator("clusterVCAllocator");
 ClassAllocator<ByteBankDescriptor> byteBankAllocator("byteBankAllocator");
+ClassAllocator<ClusterCacheVC> clusterCacheVCAllocator("custerCacheVCAllocator");
+
+int ClusterCacheVC::size_to_init = -1;
+
+#define CLUSTER_WRITE_MIN_SIZE (1 << 16)
+
+#define CLUSTER_CACHE_VC_CLOSE_SESSION \
+{ \
+  cluster_close_session(cs); \
+  session_closed = true; \
+}
 
 ByteBankDescriptor *
 ByteBankDescriptor::ByteBankDescriptor_alloc(IOBufferBlock * iob)
@@ -271,13 +282,13 @@ ClusterVConnection::do_io_write(Continuation * c, int64_t nbytes, IOBufferReader
 void
 ClusterVConnection::do_io_close(int alerrno)
 {
-  if ((type == VC_CLUSTER) && current_cont) {
-    if (((CacheContinuation *)current_cont)->read_cluster_vc == this)
-      type = VC_CLUSTER_READ;
-    else if (((CacheContinuation *)current_cont)->write_cluster_vc == this)
-      type = VC_CLUSTER_WRITE;
-  }
-  ch->vcs_push(this, type);
+//  if ((type == VC_CLUSTER) && current_cont) {
+//    if (((CacheContinuation *)current_cont)->read_cluster_vc == this)
+//      type = VC_CLUSTER_READ;
+//    else if (((CacheContinuation *)current_cont)->write_cluster_vc == this)
+//      type = VC_CLUSTER_WRITE;
+//  }
+//  ch->vcs_push(this, type);
 
   ClusterVConnectionBase::do_io_close(alerrno);
 }
@@ -650,4 +661,527 @@ ClusterVConnection::get_disk_io_priority()
   return disk_io_priority;
 }
 
+
+ClusterCacheVC::ClusterCacheVC() {
+  size_to_init = sizeof(ClusterCacheVC) - (size_t) & ((ClusterCacheVC *) 0)->vio;
+  memset((char *) &vio, 0, size_to_init);
+}
+
+int
+ClusterCacheVC::handleRead(int, void *)
+{
+  ink_assert(!in_progress && !remote_closed);
+  PUSH_HANDLER(&ClusterCacheVC::openReadReadDone);
+  if (vio.nbytes > 0 && total_len == 0) {
+    SetIOReadMessage msg;
+    msg.nbytes = vio.nbytes;
+    msg.offset = seek_to;
+    if (!cluster_send_message(cs, -CLUSTER_CACHE_DATA_READ_BEGIN, (char *) &msg,
+        sizeof(msg), PRIORITY_HIGH)) {
+      in_progress = true;
+      cluster_set_events(cs, RESPONSE_EVENT_NOTIFY_DEALER);
+      return EVENT_CONT;
+    }
+    goto Lfailed;
+  }
+
+  if (!cluster_send_message(cs, -CLUSTER_CACHE_DATA_READ_REENABLE, NULL, 0,
+      PRIORITY_HIGH)) {
+    in_progress = true;
+    cluster_set_events(cs, RESPONSE_EVENT_NOTIFY_DEALER);
+    return EVENT_CONT;
+  }
+  Lfailed:
+  CLUSTER_CACHE_VC_CLOSE_SESSION;
+  return calluser(VC_EVENT_ERROR);
+}
+
+int
+ClusterCacheVC::openReadReadDone(int event, void *data)
+{
+  cancel_trigger();
+  ink_assert(in_progress);
+  if (event == EVENT_IMMEDIATE)
+    return EVENT_CONT;
+
+  in_progress = false;
+  POP_HANDLER;
+
+  switch (event) {
+    case CLUSTER_CACHE_DATA_ERROR:
+    {
+      ClusterCont *cc = (ClusterCont *) data;
+      ink_assert(cc && cc->data_len > 0);
+      remote_closed = true;
+      event = *(int *) cc->data->start();
+      break;
+    }
+    case CLUSTER_CACHE_DATA_READ_DONE:
+    {
+      ClusterCont *cc = (ClusterCont *) data;
+      ink_assert(cc && d_len == 0);
+
+      d_len = cc->data_len;
+      total_len += d_len;
+      blocks = cc->data;
+      if (total_len >= vio.nbytes)
+        remote_closed = true;
+      break;
+    }
+    case CLUSTER_INTERNEL_ERROR:
+    default:
+      event = VC_EVENT_ERROR;
+      remote_closed = true;
+      break;
+  }
+
+  if (closed) {
+    if (!remote_closed)
+      cluster_send_message(cs, CLUSTER_CACHE_DATA_ABORT, NULL, 0, PRIORITY_HIGH);
+
+    free_ClusterCacheVC(this);
+    return EVENT_DONE;
+  }
+  // recevied data from cluster
+
+  return handleEvent(event, data);
+}
+
+int
+ClusterCacheVC::openReadStart(int event, void *data)
+{
+  ink_assert(in_progress);
+  in_progress = false;
+  if (_action.cancelled) {
+    if (!remote_closed)
+      cluster_send_message(cs, CLUSTER_CACHE_DATA_ABORT, NULL, 0, PRIORITY_HIGH);
+    free_ClusterCacheVC(this);
+    return EVENT_DONE;
+  }
+  if (event != CACHE_EVENT_OPEN_READ) {
+    if (event == CACHE_EVENT_OPEN_WRITE) {
+      // the remote side do the pre_write
+      vio.op = VIO::WRITE;
+      SET_HANDLER(&ClusterCacheVC::openWriteMain);
+      _action.continuation->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, this);
+      return EVENT_DONE;
+    }
+    // prevent further trigger
+    remote_closed = true;
+    CLUSTER_CACHE_VC_CLOSE_SESSION;
+    _action.continuation->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, data);
+    free_ClusterCacheVC(this);
+    return EVENT_DONE;
+  }
+
+  SET_HANDLER(&ClusterCacheVC::openReadMain);
+  callcont(CACHE_EVENT_OPEN_READ);
+  return EVENT_CONT;
+}
+int
+ClusterCacheVC::openReadMain(int event, void *e)
+{
+  cancel_trigger();
+  ink_assert(!in_progress);
+  if (event == VC_EVENT_ERROR || event == VC_EVENT_EOS) {
+    remote_closed = true;
+    CLUSTER_CACHE_VC_CLOSE_SESSION;
+    return calluser(event);
+  }
+
+  int64_t bytes = d_len;
+  int64_t ntodo = vio.ntodo();
+  if (ntodo <= 0)
+    return EVENT_CONT;
+  if (vio.buffer.writer()->max_read_avail() > vio.buffer.writer()->water_mark && vio.ndone) // initiate read of first block
+    return EVENT_CONT;
+  if (!blocks && vio.ntodo() > 0)
+    goto Lread;
+
+  if (bytes > vio.ntodo())
+    bytes = vio.ntodo();
+  vio.buffer.writer()->append_block(blocks);
+  vio.ndone += bytes;
+  blocks = NULL;
+  d_len -= bytes;
+
+  if (vio.ntodo() <= 0)
+    return calluser(VC_EVENT_READ_COMPLETE);
+  else {
+    if (calluser(VC_EVENT_READ_READY) == EVENT_DONE)
+      return EVENT_DONE;
+    // we have to keep reading until we give the user all the
+    // bytes it wanted or we hit the watermark.
+    if (vio.ntodo() > 0 && !vio.buffer.writer()->high_water())
+      goto Lread;
+    return EVENT_CONT;
+  }
+Lread:
+  if (vio.ndone >= (int64_t) doc_len) {
+    // reached the end of the document and the user still wants more
+    return calluser(VC_EVENT_EOS);
+  }
+  // if the state machine calls reenable on the callback from the cache,
+  // we set up a schedule_imm event. The openReadReadDone discards
+  // EVENT_IMMEDIATE events. So, we have to cancel that trigger and set
+  // a new EVENT_INTERVAL event.
+  cancel_trigger();
+  return handleRead(event, e);
+}
+
+int
+ClusterCacheVC::openWriteStart(int event, void *data)
+{
+  ink_assert(in_progress);
+  in_progress = false;
+  if (_action.cancelled) {
+    if (!remote_closed)
+      cluster_send_message(cs, CLUSTER_CACHE_DATA_ABORT, NULL, 0, PRIORITY_HIGH);
+    free_ClusterCacheVC(this);
+    return EVENT_DONE;
+  }
+  // process the data
+  if (event != CACHE_EVENT_OPEN_WRITE) {
+    // prevent further trigger
+    remote_closed = true;
+    CLUSTER_CACHE_VC_CLOSE_SESSION;
+    _action.continuation->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, data);
+    free_ClusterCacheVC(this);
+    return EVENT_DONE;
+  }
+  SET_HANDLER(&ClusterCacheVC::openWriteMain);
+  return callcont(CACHE_EVENT_OPEN_WRITE);
+}
+int
+ClusterCacheVC::openWriteMain(int , void *)
+{
+  cancel_trigger();
+  ink_assert(!in_progress);
+
+Lagain:
+  if (remote_closed) {
+    if (calluser(VC_EVENT_ERROR) == EVENT_DONE)
+      return EVENT_DONE;
+    return EVENT_CONT;
+  }
+
+  if (!vio.buffer.writer()) {
+    if (calluser(VC_EVENT_WRITE_READY) == EVENT_DONE)
+      return EVENT_DONE;
+    if (!vio.buffer.writer())
+      return EVENT_CONT;
+  }
+
+  int64_t ntodo = vio.ntodo();
+
+  if (ntodo <= 0) {
+    if (calluser(VC_EVENT_WRITE_COMPLETE) == EVENT_DONE)
+      return EVENT_DONE;
+    ink_assert(!"close expected after write COMPLETE");
+    if (vio.ntodo() <= 0)
+      return EVENT_CONT;
+  }
+
+  ntodo = vio.ntodo() + length;
+  int64_t total_avail = vio.buffer.reader()->read_avail();
+  int64_t avail = total_avail;
+  int64_t towrite = avail + length;
+  if (towrite > ntodo) {
+    avail -= (towrite - ntodo);
+    towrite = ntodo;
+  }
+
+  if (!blocks && towrite) {
+    blocks = vio.buffer.reader()->block;
+    offset = vio.buffer.reader()->start_offset;
+  }
+
+  if (avail > 0) {
+    vio.buffer.reader()->consume(avail);
+    vio.ndone += avail;
+    total_len += avail;
+  }
+
+  ink_assert(towrite >= 0);
+  length = towrite;
+
+  int flen = cache_config_target_fragment_size;
+
+  while (length >= flen) {
+    IOBufferBlock *r = clone_IOBufferBlockList(blocks, offset, flen);
+    blocks = iobufferblock_skip(blocks, &offset, &length, flen);
+
+    remote_closed = cluster_send_message(cs, CLUSTER_CACHE_DATA_WRITE_DONE, r, -1,
+        priority);
+    if (remote_closed)
+      goto Lagain;
+
+    data_sent += flen;
+    Debug("data_sent", "sent bytes %d, reminds %"PRId64"", flen, length);
+  }
+  // for the read_from_writer work better,
+  // especailly the slow original
+  flen = CLUSTER_WRITE_MIN_SIZE;
+  if (length >= flen || (vio.ntodo() <= 0 && length > 0)) {
+    data_sent += length;
+    IOBufferBlock *r = clone_IOBufferBlockList(blocks, offset, length);
+    blocks = iobufferblock_skip(blocks, &offset, &length, length);
+    remote_closed = cluster_send_message(cs, CLUSTER_CACHE_DATA_WRITE_DONE, r,
+              -1, priority);
+    if (remote_closed)
+      goto Lagain;
+    Debug("data_sent", "sent bytes %d, reminds %"PRId64"", flen, length);
+  }
+
+  if (vio.ntodo() <= 0) {
+    ink_assert(length == 0 && total_len == vio.nbytes);
+    return calluser(VC_EVENT_WRITE_COMPLETE);
+  }
+  return calluser(VC_EVENT_WRITE_READY);
+}
+
+int
+ClusterCacheVC::removeEvent(int event, void *data)
+{
+  ink_assert(in_progress);
+  in_progress = false;
+  remote_closed = true;
+  CLUSTER_CACHE_VC_CLOSE_SESSION;
+  if (!_action.cancelled)
+    _action.continuation->handleEvent(event, data);
+  free_ClusterCacheVC(this);
+  return EVENT_DONE;
+}
+
+VIO *
+ClusterCacheVC::do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *abuf)
+{
+  ink_assert(vio.op == VIO::READ && alternate.valid());
+  vio.buffer.writer_for(abuf);
+  vio.set_continuation(c);
+  vio.ndone = 0;
+  vio.nbytes = nbytes;
+  vio.vc_server = this;
+  seek_to = 0;
+  ink_assert(c->mutex->thread_holding);
+
+  ink_assert(!in_progress);
+  if (!trigger && !recursive)
+    trigger = c->mutex->thread_holding->schedule_imm_local(this);
+  return &vio;
+}
+
+VIO *
+ClusterCacheVC::do_io_pread(Continuation *c, int64_t nbytes, MIOBuffer *abuf, int64_t offset)
+{
+  ink_assert(vio.op == VIO::READ && alternate.valid());
+  vio.buffer.writer_for(abuf);
+  vio.set_continuation(c);
+  vio.ndone = 0;
+  vio.nbytes = nbytes;
+  vio.vc_server = this;
+  seek_to = offset;
+  ink_assert(c->mutex->thread_holding);
+
+  ink_assert(!in_progress);
+  if (!trigger && !recursive)
+    trigger = c->mutex->thread_holding->schedule_imm_local(this);
+  return &vio;
+}
+
+VIO *
+ClusterCacheVC::do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *abuf, bool owner)
+{
+  ink_assert(vio.op == VIO::WRITE);
+  ink_assert(!owner && !in_progress);
+  vio.buffer.reader_for(abuf);
+  vio.set_continuation(c);
+  vio.ndone = 0;
+  vio.nbytes = nbytes;
+  doc_len = nbytes; // note: the doc_len maybe not the real length of the body
+  vio.vc_server = this;
+  ink_assert(c->mutex->thread_holding);
+
+  if (nbytes < (1 << 20))
+    priority = PRIORITY_MID;
+  else
+    priority = PRIORITY_LOW;
+
+  CacheHTTPInfo *r = &alternate;
+  SetIOWriteMessage msg;
+  msg.nbytes = nbytes;
+  int len = r->valid() ? r->marshal_length() : 0;
+  msg.hdr_len = len;
+  ink_assert(total_len == 0);
+  ink_assert((frag_type == CACHE_FRAG_TYPE_HTTP && len > 0) ||
+      (frag_type != CACHE_FRAG_TYPE_HTTP && len == 0));
+
+  if (len > 0) {
+    Ptr<IOBufferData> data;
+    data = new_IOBufferData(iobuffer_size_to_index(sizeof msg + len, MAX_BUFFER_SIZE_INDEX));
+    memcpy((char *) data->data(), &msg, sizeof(msg));
+    char *p = (char *) data->data() + sizeof msg;
+    int res = r->marshal(p, len);
+    ink_assert(res >= 0);
+    IOBufferBlock *ret = new_IOBufferBlock(data, sizeof msg + len, 0);
+    ret->_buf_end = ret->_end;
+    remote_closed = cluster_send_message(cs, CLUSTER_CACHE_DATA_WRITE_BEGIN, ret, -1, priority);
+  } else
+    remote_closed = cluster_send_message(cs, -CLUSTER_CACHE_DATA_WRITE_BEGIN, &msg, sizeof msg, priority);
+
+  if (!trigger && !recursive)
+    trigger = c->mutex->thread_holding->schedule_imm_local(this);
+  return &vio;
+}
+
+void
+ClusterCacheVC::do_io_close(int alerrno)
+{
+  ink_assert(mutex->thread_holding == this_ethread());
+  int previous_closed = closed;
+  closed = (alerrno == -1) ? 1 : -1;    // Stupid default arguments
+  DDebug("cache_close", "do_io_close %p %d %d", this, alerrno, closed);
+
+  // special case: to cache 0 bytes document
+  if (f.force_empty)
+    closed = 1;
+
+  if (!remote_closed) {
+    if (closed > 0 && vio.op == VIO::WRITE) {
+      if ((f.update && vio.nbytes == 0) || f.force_empty) {
+        //header only update
+        //
+        if (frag_type == CACHE_FRAG_TYPE_HTTP) {
+          if (alternate.valid()) {
+            SetIOCloseMessage msg;
+            msg.h_len = alternate.marshal_length();
+            msg.d_len = 0;
+            msg.total_len = 0;
+
+            Ptr<IOBufferData> d;
+            d = new_IOBufferData(iobuffer_size_to_index(sizeof msg + msg.h_len));
+            char *data = d->data();
+            memcpy(data, &msg, sizeof msg);
+
+            int res = alternate.marshal((char *) data + sizeof msg, msg.h_len);
+            ink_assert(res >= 0 && res <= msg.h_len);
+
+            IOBufferBlock *ret = new_IOBufferBlock(d, sizeof msg + msg.h_len, 0);
+            ret->_buf_end = ret->_end;
+
+            remote_closed = cluster_send_message(cs,
+                -CLUSTER_CACHE_HEADER_ONLY_UPDATE, ret, -1, PRIORITY_HIGH);
+          } else
+            remote_closed = cluster_send_message(cs, -CLUSTER_CACHE_DATA_CLOSE, &total_len,
+                sizeof total_len, PRIORITY_HIGH);
+        } else {
+          remote_closed = cluster_send_message(cs, -CLUSTER_CACHE_DATA_CLOSE,
+              &total_len, sizeof total_len, priority);
+        }
+
+        goto Lfree;
+      } else if ((total_len < vio.nbytes) || length > 0) {
+        int64_t ntodo = vio.ntodo() + length;
+        int64_t total_avail = vio.buffer.reader()->read_avail();
+        int64_t avail = total_avail;
+        int64_t towrite = avail + length;
+        if (towrite > ntodo) {
+          avail -= (towrite - ntodo);
+          towrite = ntodo;
+        }
+
+        if (!blocks && towrite) {
+          blocks = vio.buffer.reader()->block;
+          offset = vio.buffer.reader()->start_offset;
+        }
+
+        if (avail > 0) {
+          vio.buffer.reader()->consume(avail);
+          vio.ndone += avail;
+          total_len += avail;
+        }
+
+        if (vio.ntodo() > 0) {
+          Warning("writer closed success but still want more data");
+          remote_closed = cluster_send_message(cs, CLUSTER_CACHE_DATA_ABORT, NULL, 0,
+                        priority);
+          goto Lfree;
+        }
+
+        length = towrite;
+        ink_assert(total_len == vio.nbytes);
+        int flen = cache_config_target_fragment_size;
+        while (length >= flen) {
+          IOBufferBlock *ret = clone_IOBufferBlockList(blocks, offset, flen);
+          blocks = iobufferblock_skip(blocks, &offset, &length, flen);
+
+          remote_closed = cluster_send_message(cs, CLUSTER_CACHE_DATA_WRITE_DONE, ret,
+              -1, priority);
+          if (remote_closed)
+            goto Lfree;
+
+          data_sent += flen;
+          Debug("data_sent", "sent bytes %d, reminds %"PRId64"", flen, length);
+        }
+
+        if (length > 0) {
+          data_sent += length;
+          IOBufferBlock *ret = clone_IOBufferBlockList(blocks, offset, length);
+          blocks = iobufferblock_skip(blocks, &offset, &length, length);
+          remote_closed = cluster_send_message(cs, CLUSTER_CACHE_DATA_WRITE_DONE, ret, -1,
+              priority);
+          if (remote_closed)
+            goto Lfree;
+          Debug("data_sent", "sent bytes done: %"PRId64", reminds %"PRId64"", data_sent, length);
+        }
+      }
+
+      if (doc_len != vio.nbytes) {
+        // for trunk
+        ink_assert(total_len == vio.nbytes && length == 0);
+        remote_closed = cluster_send_message(cs, CLUSTER_CACHE_DATA_CLOSE,
+            &total_len, sizeof total_len, priority);
+        goto Lfree;
+      }
+      ink_assert(data_sent == total_len);
+    }
+
+    if (closed < 0 && vio.op == VIO::WRITE)
+      remote_closed = cluster_send_message(cs, CLUSTER_CACHE_DATA_ABORT, NULL, 0, PRIORITY_HIGH);
+
+    if (vio.op == VIO::READ && !in_progress) {
+      remote_closed = cluster_send_message(cs, CLUSTER_CACHE_DATA_ABORT, NULL, 0, PRIORITY_HIGH);
+    }
+  }
+Lfree:
+  if (!previous_closed && !recursive && !in_progress) {
+    free_ClusterCacheVC(this);
+  }
+}
+
+void
+ClusterCacheVC::reenable(VIO *avio)
+{
+  DDebug("cache_reenable", "reenable %p, trigger %p, in_progress %d", this, trigger, in_progress);
+  (void) avio;
+  ink_assert(avio->mutex->thread_holding);
+  if (!trigger && !in_progress) {
+    trigger = avio->mutex->thread_holding->schedule_imm_local(this);
+  }
+}
+
+void
+ClusterCacheVC::reenable_re(VIO *avio)
+{
+  DDebug("cache_reenable", "reenable %p", this);
+  (void) avio;
+  ink_assert(avio->mutex->thread_holding);
+
+  if (!trigger) {
+    if (!in_progress && !recursive) {
+      handleEvent(EVENT_NONE, (void *) 0);
+    } else if (!in_progress)
+      trigger = avio->mutex->thread_holding->schedule_imm_local(this);
+  }
+}
 // End of ClusterVConnection.cc

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/Makefile.am
----------------------------------------------------------------------
diff --git a/iocore/cluster/Makefile.am b/iocore/cluster/Makefile.am
index 1d8266d..a937cb6 100644
--- a/iocore/cluster/Makefile.am
+++ b/iocore/cluster/Makefile.am
@@ -57,5 +57,11 @@ libinkcluster_a_SOURCES = \
   P_ClusterLoadMonitor.h \
   P_ClusterMachine.h \
   P_TimeTrace.h \
-  Inline.cc
+  Inline.cc \
+  global.cc  \
+  nio.cc \
+  session.cc  \
+  message.cc \
+  connection.cc \
+  machine.cc 
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/P_Cluster.h
----------------------------------------------------------------------
diff --git a/iocore/cluster/P_Cluster.h b/iocore/cluster/P_Cluster.h
index aa3d6a5..f24d3de 100644
--- a/iocore/cluster/P_Cluster.h
+++ b/iocore/cluster/P_Cluster.h
@@ -123,6 +123,8 @@ enum
   cluster_stat_count
 };
 
+#define SIZE_OF_FRAGEMENT ((1 << 20) - 128)
+
 extern RecRawStatBlock *cluster_rsb;
 #define CLUSTER_INCREMENT_DYN_STAT(x) \
 	RecIncrRawStat(cluster_rsb, mutex->thread_holding, (int) x, 1);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/P_ClusterCache.h
----------------------------------------------------------------------
diff --git a/iocore/cluster/P_ClusterCache.h b/iocore/cluster/P_ClusterCache.h
index 10fc46a..162fef0 100644
--- a/iocore/cluster/P_ClusterCache.h
+++ b/iocore/cluster/P_ClusterCache.h
@@ -53,6 +53,9 @@
 /****************************************************************************/
 
 #include "P_ClusterMachine.h"
+#include "clusterinterface.h"
+
+extern int enable_cache_empty_http_doc;
 
 //
 // Cluster Processor
@@ -310,6 +313,7 @@ struct ClusterVCToken
 //
 typedef void ClusterFunction(ClusterHandler * ch, void *data, int len);
 typedef ClusterFunction *ClusterFunctionPtr;
+typedef void ClusterFunctionExt(ClusterSession cs, void *context, void *data);
 
 struct ClusterVConnectionBase;
 
@@ -512,7 +516,9 @@ struct ClusterVConnection: public ClusterVConnectionBase
   ClusterVConnection(int is_new_connect_read = 0);
   ~ClusterVConnection();
   void free();                  // Destructor actions (we are using ClassAllocator)
-
+  virtual bool is_read_from_writer() {
+    return false;
+  }
   virtual void do_io_close(int lerrno = -1);
   virtual VIO *do_io_read(Continuation * c, int64_t nbytes, MIOBuffer * buf);
   virtual VIO *do_io_write(Continuation * c, int64_t nbytes, IOBufferReader * buf, bool owner = false);
@@ -739,9 +745,9 @@ extern ClusterFunction close_channel_ClusterFunction;
 extern ClusterFunction get_hostinfo_ClusterFunction;
 extern ClusterFunction put_hostinfo_ClusterFunction;
 extern ClusterFunction cache_lookup_ClusterFunction;
-extern ClusterFunction cache_op_ClusterFunction;
+//extern ClusterFunction cache_op_ClusterFunction;
 extern ClusterFunction cache_op_malloc_ClusterFunction;
-extern ClusterFunction cache_op_result_ClusterFunction;
+//extern ClusterFunction cache_op_result_ClusterFunction;
 extern ClusterFunction set_channel_data_ClusterFunction;
 extern ClusterFunction post_setchan_send_ClusterFunction;
 extern ClusterFunction set_channel_pin_ClusterFunction;
@@ -750,6 +756,9 @@ extern ClusterFunction set_channel_priority_ClusterFunction;
 extern ClusterFunction post_setchan_priority_ClusterFunction;
 extern ClusterFunction default_api_ClusterFunction;
 
+extern ClusterFunctionExt cache_op_ClusterFunction;
+extern ClusterFunctionExt cache_op_result_ClusterFunction;
+
 struct ClusterFunctionDescriptor
 {
   bool fMalloced;               // the function will free the data
@@ -767,7 +776,8 @@ struct ClusterFunctionDescriptor
 #ifndef DEFINE_CLUSTER_FUNCTIONS
 extern
 #endif
-ClusterFunctionDescriptor clusterFunction[]
+ClusterFunctionDescriptor clusterFunction[1]
+#if 0
 #ifdef DEFINE_CLUSTER_FUNCTIONS
   = {
   {false, true, CMSG_LOW_PRI, test_ClusterFunction, 0},
@@ -863,7 +873,7 @@ ClusterFunctionDescriptor clusterFunction[]
   // ********** ADD NEW ENTRIES ABOVE THIS LINE ************
 }
 #endif
-
+#endif
 ;
 extern unsigned SIZE_clusterFunction;        // clusterFunction[] entries
 
@@ -983,10 +993,27 @@ ClusterFuncToQpri(int cluster_func)
 #define API_F29_CLUSTER_FUNCTION  	     	     79
 #define API_F30_CLUSTER_FUNCTION  	     	     80
 
-#define API_STARECT_CLUSTER_FUNCTION		     API_F01_CLUSTER_FUNCTION
-#define API_END_CLUSTER_FUNCTION		     API_F30_CLUSTER_FUNCTION
+#define CLUSTER_CACHE_OP_CLUSTER_FUNCTION      (CLUSTER_MSG_START+81)
+#define CLUSTER_CACHE_DATA_READ_BEGIN          (CLUSTER_MSG_START+82)
+#define CLUSTER_CACHE_DATA_READ_REENABLE       (CLUSTER_MSG_START+83)
+#define CLUSTER_CACHE_DATA_WRITE_BEGIN         (CLUSTER_MSG_START+84)
+#define CLUSTER_CACHE_HEADER_ONLY_UPDATE       (CLUSTER_MSG_START+85)
+#define CLUSTER_CACHE_DATA_CLOSE               (CLUSTER_MSG_START+86)
+#define CLUSTER_CACHE_DATA_ABORT               (CLUSTER_MSG_START+87)
+#define CLUSTER_CACHE_DATA_WRITE_DONE          (CLUSTER_MSG_START+88)
+
+#define CLUSTER_CACHE_OP_RESULT_CLUSTER_FUNCTION (CLUSTER_MSG_START+89)
+#define CLUSTER_CACHE_DATA_READ_DONE           (CLUSTER_MSG_START+90)
+#define CLUSTER_CACHE_DATA_ERROR               (CLUSTER_MSG_START+91)
 
-#define UNDEFINED_CLUSTER_FUNCTION                   0xFDEFFDEF
+#define CLUSTER_INTERNEL_ERROR                 (CLUSTER_MSG_START+100)
+#define CLUSTER_PING_CLUSTER_FUNCTION          (CLUSTER_MSG_START+101)                        1
+#define CLUSTER_PING_REPLY_CLUSTER_FUNCTION    (CLUSTER_MSG_START+102)
+
+#define API_STARECT_CLUSTER_FUNCTION           API_F01_CLUSTER_FUNCTION
+#define API_END_CLUSTER_FUNCTION               API_F30_CLUSTER_FUNCTION
+
+#define UNDEFINED_CLUSTER_FUNCTION             0xFDEFFDEF
 
 //////////////////////////////////////////////
 // Initial cluster connect exchange message
@@ -1171,4 +1198,328 @@ ClusterVC_remove_write(ClusterVConnectionBase * vc)
 }
 
 
+struct ClusterCacheVC: public CacheVConnection
+{
+  static int size_to_init;
+  Action _action;
+  Ptr<IOBufferData> buf;          // for read
+  Ptr<IOBufferData> first_buf;    // the head fragment
+  Ptr<IOBufferBlock> blocks; // data available to write
+
+  CacheHTTPInfo alternate;
+
+  VIO vio;
+  ink_hrtime start_time;
+  CacheFragType frag_type;
+  int64_t seek_to;                // pread offset
+  int64_t offset;                 // offset into 'blocks' of data to write
+  int64_t length;                 // length of data available to write
+  int64_t total_len;
+  int64_t data_sent;
+  int64_t doc_len;
+
+  int doc_pos;                // read position in 'buf'
+  int d_len;                  // the length of data in 'buf'
+
+  int closed;
+  int recursive;
+  int disk_io_priority;
+  int probe_depth;
+  MessagePriority priority;
+
+  time_t time_pin;
+  EThread *initial_thread;  // initial thread open_XX was called on
+  ClusterSession cs;
+  Event *trigger;
+  ContinuationHandler save_handler;
+
+
+  bool in_progress; //
+  bool remote_closed;
+  bool session_closed;
+
+  union
+  {
+    uint32_t flags;
+    struct
+    {
+      unsigned int use_first_key:1;
+      unsigned int overwrite:1; // overwrite first_key Dir if it exists
+      unsigned int close_complete:1; // WRITE_COMPLETE is final
+      unsigned int sync:1; // write to be committed to durable storage before WRITE_COMPLETE
+      unsigned int evacuator:1;
+      unsigned int single_fragment:1;
+      unsigned int evac_vector:1;
+      unsigned int lookup:1;
+      unsigned int update:1;
+      unsigned int remove:1;
+      unsigned int remove_aborted_writers:1;
+      unsigned int open_read_timeout:1; // UNUSED
+      unsigned int data_done:1;
+      unsigned int read_from_writer_called:1;
+      unsigned int not_from_ram_cache:1;        // entire object was from ram cache
+      unsigned int rewrite_resident_alt:1;
+      unsigned int readers:1;
+      unsigned int doc_from_ram_cache:1;
+#ifdef HIT_EVACUATE
+      unsigned int hit_evacuate:1;
+#endif
+#ifdef HTTP_CACHE
+      unsigned int force_empty:1; // used for cache empty http document
+#endif
+#ifdef SSD_CACHE
+      unsigned int read_from_ssd:1;
+      unsigned int write_into_ssd:1;
+      unsigned int ram_fixup:1;
+      unsigned int transistor:1;
+#endif
+    } f;
+  };
+  ClusterCacheVC();
+  VIO *do_io_read(Continuation *c, int64_t nbytes, MIOBuffer *buf); // invoke remote
+  VIO *do_io_pread(Continuation *c, int64_t nbytes, MIOBuffer *buf, int64_t offset); // invoke remote
+  VIO *do_io_write(Continuation *c, int64_t nbytes, IOBufferReader *buf, bool owner = false); // invoke remote
+  void do_io_close(int lerrno = -1); // invoke remote ?
+  void reenable(VIO *avio); // invoke remote ?
+  void reenable_re(VIO *avio); // invoke remote ?
+
+  void do_remote_close(); // invoke remote, for cancel or error
+
+  virtual int get_header(void **, int *)
+  {
+    ink_assert(!"implemented");
+    return -1;
+  }
+  virtual int set_header(void *, int)
+  {
+    ink_assert(!"implemented");
+    return -1;
+  }
+  virtual int get_single_data(void **, int *)
+  {
+    ink_assert(!"implemented");
+    return -1;
+  }
+
+#ifdef HTTP_CACHE
+  virtual void set_http_info(CacheHTTPInfo *info) {
+    if (enable_cache_empty_http_doc) {
+      MIMEField *field = info->m_alt->m_response_hdr.field_find(
+          MIME_FIELD_CONTENT_LENGTH, MIME_LEN_CONTENT_LENGTH);
+      if (field && !field->value_get_int64())
+        f.force_empty = 1;
+      else
+        f.force_empty = 0;
+    } else
+      f.force_empty = 0;
+    alternate.copy_shallow(info);
+    info->clear();
+  }
+  virtual void get_http_info(CacheHTTPInfo ** info) {
+    *info = &alternate;
+  }
+#endif
+
+  bool is_ram_cache_hit() {
+    ink_assert(vio.op == VIO::READ);
+    return !f.not_from_ram_cache;
+  }
+  virtual bool set_disk_io_priority(int priority)
+  {
+    disk_io_priority = priority;
+    return true;
+  }
+  virtual int get_disk_io_priority() {
+    return disk_io_priority;
+  }
+  virtual bool set_pin_in_cache(time_t t) {
+    time_pin = t;
+    return true;
+  }
+  virtual time_t get_pin_in_cache() {
+    return time_pin;
+  }
+  virtual int64_t get_object_size()
+  {
+    return alternate.object_size_get();
+  }
+  virtual bool is_read_from_writer()
+  {
+    return f.read_from_writer_called;
+  }
+  virtual bool is_ram_cache_hit() const
+  {
+    return !f.not_from_ram_cache;
+  }
+  virtual bool is_pread_capable()
+  {
+    return true;
+  }
+  void
+  cancel_trigger()
+  {
+    if (trigger) {
+      trigger->cancel_action();
+      trigger = NULL;
+    }
+  }
+
+  int calluser(int event);
+  int callcont(int event);
+  int handleRead(int event, void *data);
+  int openReadReadDone(int event, void *data);
+//  int handleWrite(int event, void *data);
+//  int openWriteWriteDone(int event, void *data);
+  int openReadStart(int event, void *data);
+  int openWriteStart(int event, void *data);
+  int openReadMain(int event, void *data);
+  int openWriteMain(int event, void *data);
+  int removeEvent(int event, void *data);
+};
+
+
+
+struct SetIOReadMessage: public ClusterMessageHeader
+{
+  int64_t nbytes;
+  int64_t offset;
+};
+
+struct SetIOWriteMessage: public ClusterMessageHeader
+{
+  int32_t hdr_len;
+  int64_t nbytes;
+};
+
+struct SetIOCloseMessage: public ClusterMessageHeader
+{
+  int h_len;
+  int d_len;
+  int64_t total_len;
+};
+
+struct SetIOReenableMessage: public ClusterMessageHeader
+{
+  int reenable;
+};
+struct SetResponseMessage: public ClusterMessageHeader
+{
+
+};
+
+inline IOBufferBlock *
+clone_IOBufferBlockList(IOBufferBlock *ab, int64_t offset, int64_t len)
+{
+  IOBufferBlock *b = ab;
+  IOBufferBlock *head = NULL;
+  IOBufferBlock *clone = NULL;
+
+  while (b && len >= 0) {
+    int64_t max_bytes = b->read_avail();
+    max_bytes -= offset;
+    if (max_bytes <= 0) {
+      offset = -max_bytes;
+      b = b->next;
+      continue;
+    }
+
+    if (!head) {
+      head = b->clone();
+      head->consume(offset);
+      clone = head;
+    } else {
+      clone->next = b->clone();
+      clone = clone->next;
+    }
+
+    len -= max_bytes;
+    b = b->next;
+    offset = 0;
+  }
+  if (clone && len < 0)
+    clone->fill(len);
+  return head;
+}
+
+ClusterCacheVC *new_ClusterCacheVC();
+void free_ClusterCacheVC(ClusterCacheVC *ccvc);
+
+inline int
+ClusterCacheVC::calluser(int event)
+{
+  recursive++;
+  ink_assert(this_ethread() == vio._cont->mutex->thread_holding);
+  vio._cont->handleEvent(event, (void *) &vio);
+  recursive--;
+  if (closed && !in_progress) {
+    free_ClusterCacheVC(this);
+    return EVENT_DONE;
+  }
+  return EVENT_CONT;
+}
+
+inline int
+ClusterCacheVC::callcont(int event)
+{
+  recursive++;
+  ink_assert(this_ethread() == _action.mutex->thread_holding);
+  _action.continuation->handleEvent(event, this);
+  recursive--;
+  if (closed && !in_progress) {
+    free_ClusterCacheVC(this);
+    return EVENT_DONE;
+  } else if (vio.vc_server)
+    handleEvent(EVENT_IMMEDIATE, 0);
+  return EVENT_DONE;
+}
+
+extern ClassAllocator<ClusterCacheVC> clusterCacheVCAllocator;
+
+inline ClusterCacheVC *
+new_ClusterCacheVC(Continuation *cont)
+{
+  EThread *t = cont->mutex->thread_holding;
+  ClusterCacheVC *c = clusterCacheVCAllocator.alloc();
+  c->_action = cont;
+  c->initial_thread = t;
+  c->mutex = cont->mutex;
+  c->start_time = ink_get_hrtime();
+  ink_assert(c->trigger == NULL);
+
+  Debug("cluster_cache_new", "new %p", c);
+  return c;
+}
+
+inline void
+free_ClusterCacheVC(ClusterCacheVC *cont)
+{
+  Debug("cluster_cache_free", "free %p", cont);
+  ink_assert(cont->mutex->thread_holding == this_ethread());
+
+  if (cont->trigger)
+    cont->trigger->cancel();
+  ink_assert(!cont->in_progress);
+
+  if (!cont->session_closed)
+    cluster_close_session(cont->cs);
+
+  cont->vio.buffer.clear();
+  cont->vio.mutex.clear();
+#ifdef HTTP_CACHE
+  if (cont->vio.op == VIO::WRITE)
+    cont->alternate.destroy();
+  else
+    cont->alternate.clear();
+#endif
+  cont->_action.cancelled = 0;
+  cont->_action.mutex.clear();
+  cont->mutex.clear();
+  cont->buf.clear();
+  cont->first_buf.clear();
+  cont->blocks.clear();
+
+  memset((char *) &cont->vio, 0, cont->size_to_init);
+
+  clusterCacheVCAllocator.free(cont);
+}
 #endif /* _Cluster_h */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/P_ClusterCacheInternal.h
----------------------------------------------------------------------
diff --git a/iocore/cluster/P_ClusterCacheInternal.h b/iocore/cluster/P_ClusterCacheInternal.h
index 8b62d44..44b675c 100644
--- a/iocore/cluster/P_ClusterCacheInternal.h
+++ b/iocore/cluster/P_ClusterCacheInternal.h
@@ -81,6 +81,88 @@ extern int ET_CLUSTER;
 #define PROBE_LOCAL_CACHE_FIRST        DO_REPLICATION
 #define PROBE_LOCAL_CACHE_LAST         false
 
+struct ClusterCont: public Continuation
+{
+  ClusterSession session;
+  Ptr<IOBufferBlock> data;
+  void *context;
+  int func_id;
+  int data_len;
+
+  Action _action;
+  int handleEvent(int event, void *d);
+  IOBufferData *copy_data();
+  int copy_data(char *buf, int size);
+  void consume(int size);
+};
+
+inline IOBufferData *
+ClusterCont::copy_data() {
+  IOBufferData *buf = new_IOBufferData(iobuffer_size_to_index(data_len, MAX_BUFFER_SIZE_INDEX));
+  char *p = buf->data();
+  for (IOBufferBlock *b = data; b; b = b->next) {
+    memcpy(p, b->_start, b->_end - b->_start);
+    p += b->_end - b->_start;
+  }
+  return buf;
+}
+
+inline void
+ClusterCont::consume(int size) {
+
+  int64_t sz = size;
+  while (data && sz >= data->read_avail()) {
+    sz -= data->read_avail();
+    data = data->next;
+  }
+  if (data)
+    data->_start += sz;
+
+  data_len = data_len > size ? (data_len - size) : 0;
+}
+
+inline int
+ClusterCont::copy_data(char *buf, int len)
+{
+  ink_assert(data_len >= len);
+  IOBufferBlock *b = data;
+  int64_t sz = len;
+  while (len > 0 && b) {
+    int64_t avail = b->read_avail();
+    sz -= avail;
+    if (sz < 0) {
+      memcpy(buf, b->_start, avail + sz);
+      sz = 0;
+      break;
+    } else {
+      memcpy(buf, b->_start, avail);
+      buf += avail;
+      b = b->next;
+    }
+  }
+  return len - (int) sz;
+}
+extern ClassAllocator<ClusterCont> clusterContAllocator;
+
+inline int
+ClusterCont::handleEvent(int, void *) {
+  if (func_id == CLUSTER_CACHE_OP_CLUSTER_FUNCTION)
+    cache_op_ClusterFunction(session, context, this);
+  else if (func_id == CLUSTER_CACHE_OP_RESULT_CLUSTER_FUNCTION)
+    cache_op_result_ClusterFunction(session, context, this);
+  else if (func_id == CLUSTER_INTERNEL_ERROR)
+    _action.continuation->handleEvent(func_id, NULL);
+  else
+    _action.continuation->handleEvent(func_id, this);
+
+  mutex.clear();
+  _action.mutex.clear();
+  data = NULL;
+
+  clusterContAllocator.free(this);
+  return EVENT_DONE;
+}
+
 //
 // This continuation handles all cache cluster traffic, on both
 // sides (state machine client and cache server)
@@ -89,111 +171,91 @@ struct CacheContinuation;
 typedef int (CacheContinuation::*CacheContHandler) (int, void *);
 struct CacheContinuation:public Continuation
 {
+  static int size_to_init;
   enum
   {
     MagicNo = 0x92183123
   };
   int magicno;
-  void *callback_data;
-  void *callback_data_2;
   INK_MD5 url_md5;
-  Event *timeout;
-  Action action;
-  ClusterMachine *target_machine;
-  int probe_depth;
+
   ClusterMachine *past_probes[CONFIGURATION_HISTORY_PROBE_DEPTH];
+
+  ClusterVCToken token;
+
+  CacheHTTPInfo cache_vc_info; // for get_http_info
+//  MIOBuffer doc_data;
+  Ptr<IOBufferBlock> doc_data;
+  // Incoming data generated from unmarshaling request/response ops
+  Ptr<IOBufferData> rw_buf_msg;
+  Arena ic_arena;
+  CacheHTTPHdr ic_request; // for lookup or read
+  CacheHTTPInfo ic_old_info; // for update
+  CacheHTTPInfo ic_new_info; // for set_http_info
+
+  ClusterSession cs;
+  char *ic_hostname;
+  int ic_hostname_len;
+
   ink_hrtime start_time;
-  ClusterMachine *from;
-  ClusterHandler *ch;
-  VConnection *cache_vc;
+  ClusterMachine *target_machine;
+  int probe_depth;
+
+  CacheVC *cache_vc;
+  Action *pending_action;
   bool cache_read;
+  bool request_purge;
+  bool have_all_data;           // all object data in response
+  bool expect_next;
+  bool writer_aborted;
   int result;                   // return event code
   int result_error;             // error code associated with event
-  ClusterVCToken token;
-  unsigned int seq_number;
   uint16_t cfl_flags;             // Request flags; see CFL_XXX defines
+
+  unsigned int seq_number;
   CacheFragType frag_type;
-  int nbytes;
+  int nbytes;       // the msg nbyts
   unsigned int target_ip;
   int request_opcode;
-  bool request_purge;
-  bool local_lookup_only;
-  bool no_reply_message;
-  bool request_timeout;         // timeout occurred before
-  //   op complete
-  bool expect_cache_callback;
-
-  // remove_and_delete() specific data
-  bool use_deferred_callback;
-
-  // open_read/write data
-
-  time_t pin_in_cache;
-
-  // setMsgBufferLen(), allocMsgBuffer() and freeMsgBuffer() data
-
-    Ptr<IOBufferData> rw_buf_msg;
+  int header_len;
   int rw_buf_msg_len;
 
-  // open data
-
-  ClusterVConnection *read_cluster_vc;
-  ClusterVConnection *write_cluster_vc;
-  int cluster_vc_channel;
-  ClusterVCToken open_local_token;
-
-  // Readahead on open read specific data
-
-  int caller_buf_freebytes;     // remote bufsize for
-  //  initial data
-  VIO *readahead_vio;
-  IOBufferReader *readahead_reader;
-    Ptr<IOBufferBlock> readahead_data;
-  bool have_all_data;           // all object data in response
-
-  CacheHTTPInfo cache_vc_info;
-  OneWayTunnel *tunnel;
-    Ptr<ProxyMutex> tunnel_mutex;
-  CacheContinuation *tunnel_cont;
-  bool tunnel_closed;
-  Action *cache_action;
-  Event *lookup_open_write_vc_event;
-
-  // Incoming data generated from unmarshaling request/response ops
-
-  Arena ic_arena;
-  CacheHTTPHdr ic_request;
-  CacheHTTPHdr ic_response;
+  time_t pin_in_cache;
+  int64_t doc_size;
+  int64_t total_length;
+  VIO *vio;                  //
+  IOBufferReader *reader;    // for normal read
   CacheLookupHttpConfig *ic_params;
-  CacheHTTPInfo ic_old_info;
-  CacheHTTPInfo ic_new_info;
-    Ptr<IOBufferData> ic_hostname;
-  int ic_hostname_len;
-
-  // debugging
-  int cache_op_ClusterFunction;
-
-  int lookupEvent(int event, void *d);
-  int probeLookupEvent(int event, void *d);
-  int remoteOpEvent(int event, Event * e);
-  int replyLookupEvent(int event, void *d);
-  int replyOpEvent(int event, VConnection * vc);
-  int handleReplyEvent(int event, Event * e);
-  int callbackEvent(int event, Event * e);
-  int setupVCdataRead(int event, VConnection * vc);
-  int VCdataRead(int event, VIO * target_vio);
-  int setupReadWriteVC(int, VConnection *);
-  ClusterVConnection *lookupOpenWriteVC();
-  int lookupOpenWriteVCEvent(int, Event *);
-  int localVCsetupEvent(int event, ClusterVConnection * vc);
-  void insert_cache_callback_user(ClusterVConnection *, int, void *);
-  int insertCallbackEvent(int, Event *);
-  void callback_user(int result, void *d);
-  void defer_callback_result(int result, void *d);
-  int callbackResultEvent(int event, Event * e);
-  void setupReadBufTunnel(VConnection *, VConnection *);
-  int tunnelClosedEvent(int event, void *);
-  int remove_and_delete(int, Event *);
+  MIOBuffer *mbuf;
+  EThread *thread;
+
+//  int lookupEvent(int event, void *d);
+//  int probeLookupEvent(int event, void *d);
+//  int remoteOpEvent(int event, Event * e);
+//  int replyLookupEvent(int event, void *d);
+  int replyOpEvent();
+//  int handleReplyEvent(int event, Event * e);
+//  int callbackEvent(int event, Event * e);
+  int setupVCdataRead(int event, void *data);
+  int setupVCdataWrite(int event, void *data);
+  int setupVCdataRemove(int event, void *data);
+  int setupVCdataLink(int event, void *data);
+  int setupVCdataDeref(int event, void *data);
+  int VCdataRead(int event, void *data);
+  int VCdataWrite(int event, void *data);
+  int VCSmallDataRead(int event, void *data);
+//  int setupReadWriteVC(int, VConnection *);
+//  ClusterVConnection *lookupOpenWriteVC();
+//  int lookupOpenWriteVCEvent(int, Event *);
+//  int localVCsetupEvent(int event, ClusterVConnection * vc);
+//  void insert_cache_callback_user(ClusterVConnection *, int, void *);
+//  int insertCallbackEvent(int, Event *);
+//  void callback_user(int result, void *d);
+//  void defer_callback_result(int result, void *d);
+//  int callbackResultEvent(int event, Event * e);
+//  void setupReadBufTunnel(VConnection *, VConnection *);
+//  int tunnelClosedEvent(int event, void *);
+//  int remove_and_delete(int, Event *);
 
 
   inline void setMsgBufferLen(int l, IOBufferData * b = 0) {
@@ -254,66 +316,26 @@ struct CacheContinuation:public Continuation
     if (ic_request.valid()) {
       ic_request.clear();
     }
-    if (ic_response.valid()) {
-      ic_response.clear();
-    }
+//    if (ic_response.valid()) {
+//      ic_response.clear();
+//    }
     if (ic_old_info.valid()) {
       ic_old_info.destroy();
     }
     if (ic_new_info.valid()) {
       ic_new_info.destroy();
     }
-    ic_arena.reset();
+//    ic_arena.reset();
     freeMsgBuffer();
-
-    tunnel_mutex = 0;
-    readahead_data = 0;
+//
+//    tunnel_mutex = 0;
+//    readahead_data = 0;
     ic_hostname = 0;
   }
 
-CacheContinuation():
-  Continuation(NULL),
-    magicno(MagicNo),
-    callback_data(0),
-    callback_data_2(0),
-    timeout(0),
-    target_machine(0),
-    probe_depth(0),
-    start_time(0),
-    cache_read(false),
-    result(0),
-    result_error(0),
-    seq_number(0),
-    cfl_flags(0),
-    frag_type(CACHE_FRAG_TYPE_NONE),
-    nbytes(0),
-    target_ip(0),
-    request_opcode(0),
-    request_purge(false),
-    local_lookup_only(0),
-    no_reply_message(0),
-    request_timeout(0),
-    expect_cache_callback(true),
-    use_deferred_callback(0),
-    pin_in_cache(0),
-    rw_buf_msg_len(0),
-    read_cluster_vc(0),
-    write_cluster_vc(0),
-    cluster_vc_channel(0),
-    caller_buf_freebytes(0),
-    readahead_vio(0),
-    readahead_reader(0),
-    have_all_data(false),
-    cache_vc_info(),
-    tunnel(0),
-    tunnel_cont(0),
-    tunnel_closed(0),
-    lookup_open_write_vc_event(0),
-    ic_arena(),
-    ic_request(),
-    ic_response(), ic_params(0), ic_old_info(), ic_new_info(), ic_hostname_len(0), cache_op_ClusterFunction(0) {
-    token.clear();
-    SET_HANDLER((CacheContHandler) & CacheContinuation::remoteOpEvent);
+  CacheContinuation(): magicno(MagicNo) {
+    size_to_init = sizeof(CacheContinuation) - (size_t) & ((CacheContinuation *) 0)->cs;
+    memset((char *) &cs, 0, size_to_init);
   }
 
   inline static bool is_ClusterThread(EThread * et)
@@ -334,14 +356,66 @@ CacheContinuation():
   static void cacheContAllocator_free(CacheContinuation *);
   inkcoreapi static Action *callback_failure(Action *, int, int, CacheContinuation * this_cc = 0);
   static Action *do_remote_lookup(Continuation *, CacheKey *, CacheContinuation *, CacheFragType, char *, int);
-  inkcoreapi static Action *do_op(Continuation *, ClusterMachine *, void *, int, char *, int,
-                                  int nbytes = -1, MIOBuffer * b = 0);
+  inkcoreapi static Action *do_op(Continuation * c, ClusterSession cs, void *args,
+                           int user_opcode, IOBufferData *data, int data_len, int nbytes = -1, MIOBuffer * b = 0);
   static int setup_local_vc(char *data, int data_len, CacheContinuation * cc, ClusterMachine * mp, Action **);
   static void disposeOfDataBuffer(void *buf);
   static int handleDisposeEvent(int event, CacheContinuation * cc);
-  static int32_t getObjectSize(VConnection *, int, CacheHTTPInfo *);
+  int32_t getObjectSize(VConnection *, int, CacheHTTPInfo *);
 };
 
+extern ClassAllocator<CacheContinuation> cacheContAllocator;
+
+inline CacheContinuation *
+new_CacheCont(EThread *t) {
+  ink_assert(t == this_ethread());
+  CacheContinuation *c = cacheContAllocator.alloc();
+  c->mutex = new_ProxyMutex();
+  c->start_time = ink_get_hrtime();
+  c->thread = t;
+  return c;
+}
+
+inline void
+free_CacheCont(CacheContinuation *c) {
+  ink_assert(c->magicno == (int) c->MagicNo && !c->expect_next);
+//  ink_assert(!c->cache_op_ClusterFunction);
+  if (c->pending_action) {
+    c->pending_action->cancel();
+    c->pending_action = NULL;
+  }
+  if (c->cache_vc) {
+    if (c->cache_vc->vio.op == VIO::READ)
+      c->cache_vc->do_io(VIO::CLOSE);
+    else
+      c->cache_vc->do_io(VIO::ABORT);
+    c->cache_vc = NULL;
+  }
+  if (c->mbuf) {
+    free_MIOBuffer(c->mbuf);
+    c->mbuf = NULL;
+  }
+
+  c->magicno = -1;
+  c->token.clear();
+  c->cache_vc_info.clear();
+  if (c->ic_params) {
+    delete c->ic_params;
+    c->ic_params = 0;
+  }
+  c->ic_request.clear();
+  c->ic_old_info.clear();
+  c->ic_new_info.destroy();
+  c->ic_arena.reset();
+  c->freeMsgBuffer();
+  c->ic_hostname = 0;
+  c->mutex.clear();
+
+  c->doc_data = NULL;
+
+  cacheContAllocator.free(c);
+}
+
 /////////////////////////////////////////
 // Cache OP specific args for do_op()  //
 /////////////////////////////////////////
@@ -595,18 +669,19 @@ struct CacheOpReplyMsg:public ClusterMessageHeader
 {
   uint32_t seq_number;
   int32_t result;
-  ClusterVCToken token;
-  bool is_ram_cache_hit;          // Entire object was from ram cache
-  Alias32 moi;                 // Used by CACHE_OPEN_READ & CACHE_LINK reply
+  int32_t h_len;
+  int32_t d_len;
+  int32_t reason; // // Used by CACHE_OPEN_READ & CACHE_LINK reply
+  int64_t doc_size;
+
   enum
   {
     MIN_VERSION = 1,
     MAX_VERSION = 1,
     CACHE_OP_REPLY_MESSAGE_VERSION = MAX_VERSION
   };
-  CacheOpReplyMsg(uint16_t vers = CACHE_OP_REPLY_MESSAGE_VERSION)
-    : ClusterMessageHeader(vers), seq_number(0), result(0), is_ram_cache_hit(false) {
-    moi.u32 = 0;
+  CacheOpReplyMsg(uint16_t vers = CACHE_OP_REPLY_MESSAGE_VERSION):
+  ClusterMessageHeader(vers), seq_number(0), result(0), h_len(0), d_len(0), reason(0), doc_size(0) {
   }
 
   //////////////////////////////////////////////////////////////////////////
@@ -617,7 +692,7 @@ struct CacheOpReplyMsg:public ClusterMessageHeader
   }
   static int sizeof_fixedlen_msg()
   {
-    return (int) ALIGN_DOUBLE(offsetof(CacheOpReplyMsg, moi));
+    return INK_ALIGN(sizeof (CacheOpReplyMsg), 16);
   }
   void init(uint16_t vers = CACHE_OP_REPLY_MESSAGE_VERSION) {
     _init(vers);
@@ -627,12 +702,12 @@ struct CacheOpReplyMsg:public ClusterMessageHeader
     if (NeedByteSwap()) {
       ats_swap32(&seq_number);
       ats_swap32((uint32_t *) & result);
-      token.SwapBytes();
+      ats_swap32((uint32_t *) & reason);
+      ats_swap64((uint64_t *) & doc_size);
     }
   }
   //////////////////////////////////////////////////////////////////////////
 };
-
 inline int
 maxval(int a, int b)
 {
@@ -795,6 +870,7 @@ event_reply_may_have_moi(int event)
 {
   switch (event) {
   case CACHE_EVENT_OPEN_READ:
+  case CACHE_EVENT_OPEN_WRITE:
   case CACHE_EVENT_LINK:
   case CACHE_EVENT_LINK_FAILED:
   case CACHE_EVENT_OPEN_READ_FAILED:


[4/4] git commit: refine cluster

Posted by we...@apache.org.
refine cluster


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

Branch: refs/heads/refine_cluster
Commit: 7ffc10a9c8009429f4cf445c0f7db1fd7299905f
Parents: 27246a5
Author: weijin <ta...@taobao.com>
Authored: Wed Nov 20 15:44:31 2013 +0800
Committer: weijin <ta...@taobao.com>
Committed: Wed Nov 20 15:44:31 2013 +0800

----------------------------------------------------------------------
 iocore/cache/Cache.cc                   |    2 +-
 iocore/cache/CacheRead.cc               |    2 +-
 iocore/cache/I_Cache.h                  |    2 +-
 iocore/cache/P_Cache.h                  |    2 +
 iocore/cache/P_CacheInternal.h          |    7 +-
 iocore/cluster/ClusterCache.cc          | 4679 +++++++++++++++-----------
 iocore/cluster/ClusterConfig.cc         |   80 +-
 iocore/cluster/ClusterMachine.cc        |   14 +-
 iocore/cluster/ClusterProcessor.cc      |  623 ++--
 iocore/cluster/ClusterVConnection.cc    |  548 ++-
 iocore/cluster/Makefile.am              |    8 +-
 iocore/cluster/P_Cluster.h              |    2 +
 iocore/cluster/P_ClusterCache.h         |  367 +-
 iocore/cluster/P_ClusterCacheInternal.h |  374 +-
 iocore/cluster/P_ClusterInline.h        |  232 +-
 iocore/eventsystem/I_Event.h            |    1 +
 iocore/eventsystem/P_IOBuffer.h         |   20 +-
 mgmt/RecordsConfig.cc                   |   18 +
 18 files changed, 4597 insertions(+), 2384 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cache/Cache.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index 66f2b70..8d4b1e5 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -82,7 +82,7 @@ int cache_config_read_while_writer = 0;
 char cache_system_config_directory[PATH_NAME_MAX + 1];
 int cache_config_mutex_retry_delay = 2;
 #ifdef HTTP_CACHE
-static int enable_cache_empty_http_doc = 0;
+int enable_cache_empty_http_doc = 0;
 #endif
 
 #if TS_USE_INTERIM_CACHE == 1

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cache/CacheRead.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheRead.cc b/iocore/cache/CacheRead.cc
index 3c97305..90a7bd5 100644
--- a/iocore/cache/CacheRead.cc
+++ b/iocore/cache/CacheRead.cc
@@ -722,7 +722,7 @@ CacheVC::openReadMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
       return EVENT_DONE;
     // we have to keep reading until we give the user all the
     // bytes it wanted or we hit the watermark.
-    if (vio.ntodo() > 0 && !vio.buffer.writer()->high_water())
+    if (!f.cluster && vio.ntodo() > 0 && !vio.buffer.writer()->high_water())
       goto Lread;
     return EVENT_CONT;
   }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cache/I_Cache.h
----------------------------------------------------------------------
diff --git a/iocore/cache/I_Cache.h b/iocore/cache/I_Cache.h
index 00e4791..cd8dda9 100644
--- a/iocore/cache/I_Cache.h
+++ b/iocore/cache/I_Cache.h
@@ -193,7 +193,7 @@ struct CacheVConnection:public VConnection
   virtual void set_http_info(CacheHTTPInfo *info) = 0;
   virtual void get_http_info(CacheHTTPInfo **info) = 0;
 #endif
-
+  virtual bool is_read_from_writer() = 0;
   virtual bool is_ram_cache_hit() const = 0;
   virtual bool set_disk_io_priority(int priority) = 0;
   virtual int get_disk_io_priority() = 0;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cache/P_Cache.h
----------------------------------------------------------------------
diff --git a/iocore/cache/P_Cache.h b/iocore/cache/P_Cache.h
index ed738e3..e6bba36 100644
--- a/iocore/cache/P_Cache.h
+++ b/iocore/cache/P_Cache.h
@@ -44,4 +44,6 @@
 #include "P_CacheInternal.h"
 #include "P_CacheHosting.h"
 #include "P_CacheHttp.h"
+#include "clusterinterface.h"
+
 #endif /* _P_CACHE_H */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cache/P_CacheInternal.h
----------------------------------------------------------------------
diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h
index 4f33fdc..e5f0a11 100644
--- a/iocore/cache/P_CacheInternal.h
+++ b/iocore/cache/P_CacheInternal.h
@@ -368,7 +368,9 @@ struct CacheVC: public CacheVConnection
   virtual time_t get_pin_in_cache();
   virtual bool set_disk_io_priority(int priority);
   virtual int get_disk_io_priority();
-
+  virtual bool is_read_from_writer() {
+    return f.read_from_writer_called;
+  }
   /** Get the fragment table.
       @return The address of the start of the fragment table,
       or @c NULL if there is no fragment table.
@@ -505,6 +507,7 @@ struct CacheVC: public CacheVConnection
 #ifdef HTTP_CACHE
       unsigned int allow_empty_doc:1; // used for cache empty http document
 #endif
+      unsigned int cluster:1;
     } f;
   };
   // BTF optimization used to skip reading stuff in cache partition that doesn't contain any
@@ -1054,7 +1057,7 @@ struct Cache
   Action *open_write(Continuation *cont, URL *url, CacheHTTPHdr *request,
                      CacheHTTPInfo *old_info, time_t pin_in_cache = (time_t) 0,
                      CacheFragType type = CACHE_FRAG_TYPE_HTTP);
-  static void generate_key(INK_MD5 *md5, URL *url, CacheHTTPHdr *request);
+  static void generate_key(INK_MD5 *md5, URL *url, CacheHTTPHdr *request = 0);
 #endif
 
   Action *link(Continuation *cont, CacheKey *from, CacheKey *to, CacheFragType type, char *hostname, int host_len);


[3/4] refine cluster

Posted by we...@apache.org.
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/ClusterCache.cc
----------------------------------------------------------------------
diff --git a/iocore/cluster/ClusterCache.cc b/iocore/cluster/ClusterCache.cc
index 8d4b6e5..9b3be6c 100644
--- a/iocore/cluster/ClusterCache.cc
+++ b/iocore/cluster/ClusterCache.cc
@@ -28,6 +28,10 @@
 
 #include "P_Cluster.h"
 
+//ClassAllocator<ClusterBuffer> clusterBufferAllocator("clusterBufferAllocator");
+
+int CacheContinuation::size_to_init = -1;
+
 #ifdef DEBUG
 #define CLUSTER_TEST_DEBUG	1
 #endif
@@ -53,31 +57,34 @@ int open_delay_events = 0;
 // default will be read from config
 int cache_migrate_on_demand = false;
 
-/////////////////
-// Static Data //
-/////////////////
-static ClassAllocator<CacheContinuation> cacheContAllocator("cacheContAllocator");
+ClassAllocator<CacheContinuation> cacheContAllocator("cacheContAllocator");
+ClassAllocator<ClusterCont> clusterContAllocator("clusterContAllocator");
 
-static Queue<CacheContinuation> remoteCacheContQueue[REMOTE_CONNECT_HASH];
-static Ptr<ProxyMutex> remoteCacheContQueueMutex[REMOTE_CONNECT_HASH];
+//static Queue<CacheContinuation> remoteCacheContQueue[REMOTE_CONNECT_HASH];
+//static Ptr<ProxyMutex> remoteCacheContQueueMutex[REMOTE_CONNECT_HASH];
 
 // 0 is an illegal sequence number
 #define CACHE_NO_RESPONSE            0
 static int cluster_sequence_number = 1;
 
 #ifdef CLUSTER_TEST_DEBUG
-static ink_hrtime cache_cluster_timeout = HRTIME_SECONDS(65536);
+//static ink_hrtime cache_cluster_timeout = HRTIME_SECONDS(65536);
 #else
-static ink_hrtime cache_cluster_timeout = CACHE_CLUSTER_TIMEOUT;
+//static ink_hrtime cache_cluster_timeout = CACHE_CLUSTER_TIMEOUT;
 #endif
 
 ///////////////////
 // Declarations  //
 ///////////////////
-static CacheContinuation *find_cache_continuation(unsigned int, unsigned int);
+//static CacheContinuation *find_cache_continuation(unsigned int, unsigned int);
 
 static unsigned int new_cache_sequence_number();
 
+#ifdef DEBUG
+int64_t num_of_cachecontinuation = 0;
+int64_t num_of_cluster_cachevc = 0;
+#endif
+
 #define DOT_SEPARATED(_x)                             \
 ((unsigned char*)&(_x))[0], ((unsigned char*)&(_x))[1],   \
   ((unsigned char*)&(_x))[2], ((unsigned char*)&(_x))[3]
@@ -310,7 +317,7 @@ ClusterVConnectionCache::lookup(INK_MD5 * key)
 }
 
 int
-ClusterVConnectionCacheEvent::eventHandler(int /* event ATS_UNUSED */, Event * e)
+ClusterVConnectionCacheEvent::eventHandler(int , Event * e)
 {
   CLUSTER_INCREMENT_DYN_STAT(CLUSTER_VC_CACHE_SCANS_STAT);
   MUTEX_TRY_LOCK(lock, cache->hash_lock[hash_index], this_ethread());
@@ -358,12 +365,12 @@ ClusterVConnectionCacheEvent::eventHandler(int /* event ATS_UNUSED */, Event * e
 int
 CacheContinuation::init()
 {
-  int n;
-  for (n = 0; n < REMOTE_CONNECT_HASH; ++n)
-    remoteCacheContQueueMutex[n] = new_ProxyMutex();
-
-  GlobalOpenWriteVCcache = new ClusterVConnectionCache;
-  GlobalOpenWriteVCcache->init();
+//  int n;
+//  for (n = 0; n < REMOTE_CONNECT_HASH; ++n)
+//    remoteCacheContQueueMutex[n] = new_ProxyMutex();
+//
+//  GlobalOpenWriteVCcache = new ClusterVConnectionCache;
+//  GlobalOpenWriteVCcache->init();
   return 0;
 }
 
@@ -371,14 +378,269 @@ CacheContinuation::init()
 // do_op()
 //   Main function to do a cluster cache operation
 ///////////////////////////////////////////////////////////////////////
+//Action *
+//CacheContinuation::do_op(Continuation * c, ClusterMachine * mp, void *args,
+//                         int user_opcode, char *data, int data_len, int nbytes, MIOBuffer * b)
+//{
+//  CacheContinuation *cc = 0;
+//  Action *act = 0;
+//  char *msg = 0;
+//
+//  /////////////////////////////////////////////////////////////////////
+//  // Unconditionally map open read buffer interfaces to open read.
+//  // open read buffer interfaces are now deprecated.
+//  /////////////////////////////////////////////////////////////////////
+//  int opcode = user_opcode;
+//  switch (opcode) {
+//  case CACHE_OPEN_READ_BUFFER:
+//    opcode = CACHE_OPEN_READ;
+//    break;
+//  case CACHE_OPEN_READ_BUFFER_LONG:
+//    opcode = CACHE_OPEN_READ_LONG;
+//    break;
+//  default:
+//    break;
+//  }
+//
+//  if (!ch)
+//    goto no_send_exit;
+//
+//  if (c) {
+//    cc = cacheContAllocator_alloc();
+//    cc->ch = ch;
+//    cc->target_machine = mp;
+//    cc->request_opcode = opcode;
+//    cc->mutex = c->mutex;
+//    cc->action = c;
+//    cc->action.cancelled = false;
+//    cc->start_time = ink_get_hrtime();
+//    cc->from = mp;
+//    cc->result = op_failure(opcode);
+//    SET_CONTINUATION_HANDLER(cc, (CacheContHandler)
+//                             & CacheContinuation::remoteOpEvent);
+//    act = &cc->action;
+//
+//    // set up sequence number so we can find this continuation
+//
+//    cc->target_ip = mp->ip;
+//    cc->seq_number = new_cache_sequence_number();
+//
+//    // establish timeout for cache op
+//
+//    unsigned int hash = FOLDHASH(cc->target_ip, cc->seq_number);
+//    MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], this_ethread());
+//    if (!queuelock) {
+//
+//      // failed to acquire lock: no problem, retry later
+//      cc->timeout = eventProcessor.schedule_in(cc, CACHE_RETRY_PERIOD, ET_CACHE_CONT_SM);
+//    } else {
+//      remoteCacheContQueue[hash].enqueue(cc);
+//      MUTEX_RELEASE(queuelock);
+//      cc->timeout = eventProcessor.schedule_in(cc, cache_cluster_timeout, ET_CACHE_CONT_SM);
+//    }
+//  }
+//  //
+//  // Determine the type of the "Over The Wire" (OTW) message header and
+//  //   initialize it.
+//  //
+//  Debug("cache_msg",
+//        "do_op opcode=%d seqno=%d Machine=%p data=%p datalen=%d mio=%p",
+//        opcode, (c ? cc->seq_number : CACHE_NO_RESPONSE), mp, data, data_len, b);
+//
+//  switch (opcode) {
+//  case CACHE_OPEN_WRITE_BUFFER:
+//  case CACHE_OPEN_WRITE_BUFFER_LONG:
+//    {
+//      ink_release_assert(!"write buffer not supported");
+//      break;
+//    }
+//  case CACHE_OPEN_READ_BUFFER:
+//  case CACHE_OPEN_READ_BUFFER_LONG:
+//    {
+//      ink_release_assert(!"read buffer not supported");
+//      break;
+//    }
+//  case CACHE_OPEN_WRITE:
+//  case CACHE_OPEN_READ:
+//    {
+//      ink_release_assert(c > 0);
+//      //////////////////////
+//      // Use short format //
+//      //////////////////////
+//      if (!data) {
+//        data_len = op_to_sizeof_fixedlen_msg(opcode);
+//        data = (char *) ALLOCA_DOUBLE(data_len);
+//      }
+//      msg = (char *) data;
+//      CacheOpMsg_short *m = (CacheOpMsg_short *) msg;
+//      m->init();
+//      m->opcode = opcode;
+//      m->cfl_flags = ((CacheOpArgs_General *) args)->cfl_flags;
+//      m->md5 = *((CacheOpArgs_General *) args)->url_md5;
+//      cc->url_md5 = m->md5;
+//      m->seq_number = (c ? cc->seq_number : CACHE_NO_RESPONSE);
+//      m->frag_type = ((CacheOpArgs_General *) args)->frag_type;
+//      if (opcode == CACHE_OPEN_WRITE) {
+//        m->nbytes = nbytes;
+//        m->data = (uint32_t) ((CacheOpArgs_General *) args)->pin_in_cache;
+//      } else {
+//        m->nbytes = 0;
+//        m->data = 0;
+//      }
+//
+//      if (opcode == CACHE_OPEN_READ) {
+//        //
+//        // Set upper limit on initial data received with response
+//        // for open read response
+//        //
+//        m->buffer_size = DEFAULT_MAX_BUFFER_SIZE;
+//      } else {
+//        m->buffer_size = 0;
+//      }
+//
+//      //
+//      // Establish the local VC
+//      //
+//      int res = setup_local_vc(msg, data_len, cc, mp, &act);
+//      if (!res) {
+//        /////////////////////////////////////////////////////
+//        // Unable to setup local VC, request aborted.
+//        // Remove request from pending list and deallocate.
+//        /////////////////////////////////////////////////////
+//        cc->remove_and_delete(0, (Event *) 0);
+//        return act;
+//
+//      } else if (res != -1) {
+//        ///////////////////////////////////////
+//        // VC established, send request
+//        ///////////////////////////////////////
+//        break;
+//
+//      } else {
+//        //////////////////////////////////////////////////////
+//        // Unable to setup VC, delay required, await callback
+//        //////////////////////////////////////////////////////
+//        goto no_send_exit;
+//      }
+//    }
+//
+//  case CACHE_OPEN_READ_LONG:
+//  case CACHE_OPEN_WRITE_LONG:
+//    {
+//      ink_release_assert(c > 0);
+//      //////////////////////
+//      // Use long format  //
+//      //////////////////////
+//      msg = data;
+//      CacheOpMsg_long *m = (CacheOpMsg_long *) msg;
+//      m->init();
+//      m->opcode = opcode;
+//      m->cfl_flags = ((CacheOpArgs_General *) args)->cfl_flags;
+//      m->url_md5 = *((CacheOpArgs_General *) args)->url_md5;
+//      cc->url_md5 = m->url_md5;
+//      m->seq_number = (c ? cc->seq_number : CACHE_NO_RESPONSE);
+//      m->nbytes = nbytes;
+//      m->data = (uint32_t) ((CacheOpArgs_General *) args)->pin_in_cache;
+//      m->frag_type = (uint32_t) ((CacheOpArgs_General *) args)->frag_type;
+//
+//      if (opcode == CACHE_OPEN_READ_LONG) {
+//        //
+//        // Set upper limit on initial data received with response
+//        // for open read response
+//        //
+//        m->buffer_size = DEFAULT_MAX_BUFFER_SIZE;
+//      } else {
+//        m->buffer_size = 0;
+//      }
+//      //
+//      // Establish the local VC
+//      //
+//      int res = setup_local_vc(msg, data_len, cc, mp, &act);
+//      if (!res) {
+//        /////////////////////////////////////////////////////
+//        // Unable to setup local VC, request aborted.
+//        // Remove request from pending list and deallocate.
+//        /////////////////////////////////////////////////////
+//        cc->remove_and_delete(0, (Event *) 0);
+//        return act;
+//
+//      } else if (res != -1) {
+//        ///////////////////////////////////////
+//        // VC established, send request
+//        ///////////////////////////////////////
+//        break;
+//
+//      } else {
+//        //////////////////////////////////////////////////////
+//        // Unable to setup VC, delay required, await callback
+//        //////////////////////////////////////////////////////
+//        goto no_send_exit;
+//      }
+//    }
+//  case CACHE_UPDATE:
+//  case CACHE_REMOVE:
+//  case CACHE_DEREF:
+//    {
+//      //////////////////////
+//      // Use short format //
+//      //////////////////////
+//      msg = data;
+//      CacheOpMsg_short *m = (CacheOpMsg_short *) msg;
+//      m->init();
+//      m->opcode = opcode;
+//      m->frag_type = ((CacheOpArgs_Deref *) args)->frag_type;
+//      m->cfl_flags = ((CacheOpArgs_Deref *) args)->cfl_flags;
+//      if (opcode == CACHE_DEREF)
+//        m->md5 = *((CacheOpArgs_Deref *) args)->md5;
+//      else
+//        m->md5 = *((CacheOpArgs_General *) args)->url_md5;
+//      m->seq_number = (c ? cc->seq_number : CACHE_NO_RESPONSE);
+//      break;
+//    }
+//  case CACHE_LINK:
+//    {
+//      ////////////////////////
+//      // Use short_2 format //
+//      ////////////////////////
+//      msg = data;
+//      CacheOpMsg_short_2 *m = (CacheOpMsg_short_2 *) msg;
+//      m->init();
+//      m->opcode = opcode;
+//      m->cfl_flags = ((CacheOpArgs_Link *) args)->cfl_flags;
+//      m->md5_1 = *((CacheOpArgs_Link *) args)->from;
+//      m->md5_2 = *((CacheOpArgs_Link *) args)->to;
+//      m->seq_number = (c ? cc->seq_number : CACHE_NO_RESPONSE);
+//      m->frag_type = ((CacheOpArgs_Link *) args)->frag_type;
+//      break;
+//    }
+//  default:
+//    msg = 0;
+//    break;
+//  }
+//#ifdef CACHE_MSG_TRACE
+//  log_cache_op_sndmsg((c ? cc->seq_number : CACHE_NO_RESPONSE), 0, "do_op");
+//#endif
+//  clusterProcessor.invoke_remote(ch,
+//                                 op_needs_marshalled_coi(opcode) ? CACHE_OP_MALLOCED_CLUSTER_FUNCTION
+//                                 : CACHE_OP_CLUSTER_FUNCTION, (char *) msg, data_len);
+//
+//no_send_exit:
+//  if (c) {
+//    return act;
+//  } else {
+//    return (Action *) 0;
+//  }
+//}
+
+
 Action *
-CacheContinuation::do_op(Continuation * c, ClusterMachine * mp, void *args,
-                         int user_opcode, char *data, int data_len, int nbytes, MIOBuffer * b)
+CacheContinuation::do_op(Continuation * c, ClusterSession cs, void *args,
+                         int user_opcode, IOBufferData *data, int data_len, int nbytes, MIOBuffer * b)
 {
-  CacheContinuation *cc = 0;
-  Action *act = 0;
-  char *msg = 0;
-  ClusterHandler *ch = mp->pop_ClusterHandler();
+  ink_assert(data && !b);
+
+  ClusterCacheVC *ccvc = 0;
+  char *msg = data->data();
 
   /////////////////////////////////////////////////////////////////////
   // Unconditionally map open read buffer interfaces to open read.
@@ -396,50 +658,29 @@ CacheContinuation::do_op(Continuation * c, ClusterMachine * mp, void *args,
     break;
   }
 
-  if (!ch)
-    goto no_send_exit;
-
   if (c) {
-    cc = cacheContAllocator_alloc();
-    cc->ch = ch;
-    cc->target_machine = mp;
-    cc->request_opcode = opcode;
-    cc->mutex = c->mutex;
-    cc->action = c;
-    cc->action.cancelled = false;
-    cc->start_time = ink_get_hrtime();
-    cc->from = mp;
-    cc->result = op_failure(opcode);
-    SET_CONTINUATION_HANDLER(cc, (CacheContHandler)
-                             & CacheContinuation::remoteOpEvent);
-    act = &cc->action;
-
-    // set up sequence number so we can find this continuation
-
-    cc->target_ip = mp->ip;
-    cc->seq_number = new_cache_sequence_number();
-
-    // establish timeout for cache op
-
-    unsigned int hash = FOLDHASH(cc->target_ip, cc->seq_number);
-    MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], this_ethread());
-    if (!queuelock) {
-
-      // failed to acquire lock: no problem, retry later
-      cc->timeout = eventProcessor.schedule_in(cc, CACHE_RETRY_PERIOD, ET_CACHE_CONT_SM);
-    } else {
-      remoteCacheContQueue[hash].enqueue(cc);
-      MUTEX_RELEASE(queuelock);
-      cc->timeout = eventProcessor.schedule_in(cc, cache_cluster_timeout, ET_CACHE_CONT_SM);
+    ccvc = new_ClusterCacheVC(c);
+
+    if (opcode == CACHE_OPEN_READ || opcode == CACHE_OPEN_READ_LONG) {
+      SET_CONTINUATION_HANDLER(ccvc, &ClusterCacheVC::openReadStart);
+      ccvc->vio.op = VIO::READ;
+      ccvc->frag_type = ((CacheOpArgs_General *) args)->frag_type;
+    } else if (opcode == CACHE_OPEN_WRITE || opcode == CACHE_OPEN_WRITE_LONG) {
+      SET_CONTINUATION_HANDLER(ccvc, &ClusterCacheVC::openWriteStart);
+      ccvc->vio.op = VIO::WRITE;
+      ccvc->frag_type = ((CacheOpArgs_General *) args)->frag_type;
+    } else if (opcode == CACHE_REMOVE) {
+      SET_CONTINUATION_HANDLER(ccvc, &ClusterCacheVC::removeEvent);
+      ccvc->frag_type = ((CacheOpArgs_General *) args)->frag_type;
     }
+
+    cluster_bind_session(cs, ccvc);
+    ccvc->cs = cs;
   }
-  //
-  // Determine the type of the "Over The Wire" (OTW) message header and
-  //   initialize it.
-  //
+
   Debug("cache_msg",
-        "do_op opcode=%d seqno=%d Machine=%p data=%p datalen=%d mio=%p",
-        opcode, (c ? cc->seq_number : CACHE_NO_RESPONSE), mp, data, data_len, b);
+        "do_op opcode=%d data=%p datalen=%d mio=%p",
+        opcode, data, data_len, b);
 
   switch (opcode) {
   case CACHE_OPEN_WRITE_BUFFER:
@@ -461,61 +702,26 @@ CacheContinuation::do_op(Continuation * c, ClusterMachine * mp, void *args,
       //////////////////////
       // Use short format //
       //////////////////////
-      if (!data) {
-        data_len = op_to_sizeof_fixedlen_msg(opcode);
-        data = (char *) ALLOCA_DOUBLE(data_len);
-      }
-      msg = (char *) data;
       CacheOpMsg_short *m = (CacheOpMsg_short *) msg;
       m->init();
       m->opcode = opcode;
       m->cfl_flags = ((CacheOpArgs_General *) args)->cfl_flags;
       m->md5 = *((CacheOpArgs_General *) args)->url_md5;
-      cc->url_md5 = m->md5;
-      m->seq_number = (c ? cc->seq_number : CACHE_NO_RESPONSE);
+      //cc->url_md5 = m->md5;
+      m->seq_number = new_cache_sequence_number();
       m->frag_type = ((CacheOpArgs_General *) args)->frag_type;
       if (opcode == CACHE_OPEN_WRITE) {
         m->nbytes = nbytes;
         m->data = (uint32_t) ((CacheOpArgs_General *) args)->pin_in_cache;
+        ink_assert(ccvc);
+        ccvc->time_pin = ((CacheOpArgs_General *) args)->pin_in_cache;
       } else {
         m->nbytes = 0;
         m->data = 0;
       }
 
-      if (opcode == CACHE_OPEN_READ) {
-        //
-        // Set upper limit on initial data received with response
-        // for open read response
-        //
-        m->buffer_size = DEFAULT_MAX_BUFFER_SIZE;
-      } else {
-        m->buffer_size = 0;
-      }
-
-      //
-      // Establish the local VC
-      //
-      int res = setup_local_vc(msg, data_len, cc, mp, &act);
-      if (!res) {
-        /////////////////////////////////////////////////////
-        // Unable to setup local VC, request aborted.
-        // Remove request from pending list and deallocate.
-        /////////////////////////////////////////////////////
-        cc->remove_and_delete(0, (Event *) 0);
-        return act;
-
-      } else if (res != -1) {
-        ///////////////////////////////////////
-        // VC established, send request
-        ///////////////////////////////////////
-        break;
-
-      } else {
-        //////////////////////////////////////////////////////
-        // Unable to setup VC, delay required, await callback
-        //////////////////////////////////////////////////////
-        goto no_send_exit;
-      }
+      m->buffer_size = 0;
+      break;
     }
 
   case CACHE_OPEN_READ_LONG:
@@ -525,51 +731,21 @@ CacheContinuation::do_op(Continuation * c, ClusterMachine * mp, void *args,
       //////////////////////
       // Use long format  //
       //////////////////////
-      msg = data;
       CacheOpMsg_long *m = (CacheOpMsg_long *) msg;
       m->init();
       m->opcode = opcode;
       m->cfl_flags = ((CacheOpArgs_General *) args)->cfl_flags;
       m->url_md5 = *((CacheOpArgs_General *) args)->url_md5;
-      cc->url_md5 = m->url_md5;
-      m->seq_number = (c ? cc->seq_number : CACHE_NO_RESPONSE);
+      //cc->url_md5 = m->url_md5;
+      m->seq_number = new_cache_sequence_number();
       m->nbytes = nbytes;
       m->data = (uint32_t) ((CacheOpArgs_General *) args)->pin_in_cache;
+      ink_assert(ccvc);
+      ccvc->time_pin = (uint32_t) ((CacheOpArgs_General *) args)->pin_in_cache;
       m->frag_type = (uint32_t) ((CacheOpArgs_General *) args)->frag_type;
 
-      if (opcode == CACHE_OPEN_READ_LONG) {
-        //
-        // Set upper limit on initial data received with response
-        // for open read response
-        //
-        m->buffer_size = DEFAULT_MAX_BUFFER_SIZE;
-      } else {
-        m->buffer_size = 0;
-      }
-      //
-      // Establish the local VC
-      //
-      int res = setup_local_vc(msg, data_len, cc, mp, &act);
-      if (!res) {
-        /////////////////////////////////////////////////////
-        // Unable to setup local VC, request aborted.
-        // Remove request from pending list and deallocate.
-        /////////////////////////////////////////////////////
-        cc->remove_and_delete(0, (Event *) 0);
-        return act;
-
-      } else if (res != -1) {
-        ///////////////////////////////////////
-        // VC established, send request
-        ///////////////////////////////////////
-        break;
-
-      } else {
-        //////////////////////////////////////////////////////
-        // Unable to setup VC, delay required, await callback
-        //////////////////////////////////////////////////////
-        goto no_send_exit;
-      }
+      m->buffer_size = 0;
+      break;
     }
   case CACHE_UPDATE:
   case CACHE_REMOVE:
@@ -578,7 +754,6 @@ CacheContinuation::do_op(Continuation * c, ClusterMachine * mp, void *args,
       //////////////////////
       // Use short format //
       //////////////////////
-      msg = data;
       CacheOpMsg_short *m = (CacheOpMsg_short *) msg;
       m->init();
       m->opcode = opcode;
@@ -588,7 +763,7 @@ CacheContinuation::do_op(Continuation * c, ClusterMachine * mp, void *args,
         m->md5 = *((CacheOpArgs_Deref *) args)->md5;
       else
         m->md5 = *((CacheOpArgs_General *) args)->url_md5;
-      m->seq_number = (c ? cc->seq_number : CACHE_NO_RESPONSE);
+      m->seq_number = new_cache_sequence_number();
       break;
     }
   case CACHE_LINK:
@@ -596,369 +771,375 @@ CacheContinuation::do_op(Continuation * c, ClusterMachine * mp, void *args,
       ////////////////////////
       // Use short_2 format //
       ////////////////////////
-      msg = data;
       CacheOpMsg_short_2 *m = (CacheOpMsg_short_2 *) msg;
       m->init();
       m->opcode = opcode;
       m->cfl_flags = ((CacheOpArgs_Link *) args)->cfl_flags;
       m->md5_1 = *((CacheOpArgs_Link *) args)->from;
       m->md5_2 = *((CacheOpArgs_Link *) args)->to;
-      m->seq_number = (c ? cc->seq_number : CACHE_NO_RESPONSE);
+      m->seq_number = new_cache_sequence_number();
       m->frag_type = ((CacheOpArgs_Link *) args)->frag_type;
       break;
     }
   default:
-    msg = 0;
+    ink_release_assert(!"error request_op");
     break;
   }
 #ifdef CACHE_MSG_TRACE
   log_cache_op_sndmsg((c ? cc->seq_number : CACHE_NO_RESPONSE), 0, "do_op");
 #endif
-  clusterProcessor.invoke_remote(ch,
-                                 op_needs_marshalled_coi(opcode) ? CACHE_OP_MALLOCED_CLUSTER_FUNCTION
-                                 : CACHE_OP_CLUSTER_FUNCTION, (char *) msg, data_len);
-
-no_send_exit:
-  if (c) {
-    return act;
-  } else {
-    return (Action *) 0;
-  }
-}
-
-int
-CacheContinuation::setup_local_vc(char *data, int data_len, CacheContinuation * cc, ClusterMachine * mp, Action ** act)
-{
-  bool read_op = op_is_read(cc->request_opcode);
-  bool short_msg = op_is_shortform(cc->request_opcode);
-
-  // Alloc buffer, copy message and attach to continuation
-  cc->setMsgBufferLen(data_len);
-  cc->allocMsgBuffer();
-  memcpy(cc->getMsgBuffer(), data, data_len);
-
-  SET_CONTINUATION_HANDLER(cc, (CacheContHandler)
-                           & CacheContinuation::localVCsetupEvent);
-
-  if (short_msg) {
-    Debug("cache_proto", "open_local-s (%s) seqno=%d", (read_op ? "R" : "W"), ((CacheOpMsg_short *) data)->seq_number);
-  } else {
-    Debug("cache_proto", "open_local-l (%s) seqno=%d", (read_op ? "R" : "W"), ((CacheOpMsg_long *) data)->seq_number);
-  }
 
-  // Create local VC
-  ClusterVConnection *vc;
+  IOBufferBlock *ret = new_IOBufferBlock(data, data_len, 0);
+  ret->_buf_end = ret->_end;
 
-  if (!read_op && (cc->request_opcode == CACHE_OPEN_WRITE_LONG)) {
-    // Determine if the open_write has already been established.
-    vc = cc->lookupOpenWriteVC();
-
-  } else {
-    vc = clusterProcessor.open_local(cc, mp, cc->open_local_token,
-                                     (CLUSTER_OPT_ALLOW_IMMEDIATE |
-                                      (read_op ? CLUSTER_OPT_CONN_READ : CLUSTER_OPT_CONN_WRITE)));
-  }
-  if (!vc) {
-    // Error, abort request
-    if (short_msg) {
-      Debug("cache_proto", "0open_local-s (%s) failed, seqno=%d",
-            (read_op ? "R" : "W"), ((CacheOpMsg_short *) data)->seq_number);
-    } else {
-      Debug("cache_proto", "1open_local-l (%s) failed, seqno=%d",
-            (read_op ? "R" : "W"), ((CacheOpMsg_long *) data)->seq_number);
-    }
-    cc->freeMsgBuffer();
-    if (cc->timeout)
-      cc->timeout->cancel();
-    cc->timeout = NULL;
-
-    // Post async failure callback on a different continuation.
-    *act = callback_failure(&cc->action, (read_op ? CACHE_EVENT_OPEN_READ_FAILED : CACHE_EVENT_OPEN_WRITE_FAILED), 0);
-    return 0;
-
-  } else if (vc != CLUSTER_DELAYED_OPEN) {
-    // We have established the VC
-    if (read_op) {
-      cc->read_cluster_vc = vc;
-    } else {
-      cc->write_cluster_vc = vc;
-    }
-    cc->cluster_vc_channel = vc->channel;
-    vc->current_cont = cc;
-
-    if (short_msg) {
-      CacheOpMsg_short *ms = (CacheOpMsg_short *) data;
-      ms->channel = vc->channel;
-      ms->token = cc->open_local_token;
-      Debug("cache_proto",
-            "0open_local-s (%s) success, seqno=%d chan=%d token=%d,%d VC=%p",
-            (read_op ? "R" : "W"), ms->seq_number, vc->channel, ms->token.ip_created, ms->token.sequence_number, vc);
-    } else {
-      CacheOpMsg_long *ml = (CacheOpMsg_long *) data;
-      ml->channel = vc->channel;
-      ml->token = cc->open_local_token;
-      Debug("cache_proto",
-            "1open_local-l (%s) success, seqno=%d chan=%d token=%d,%d VC=%p",
-            (read_op ? "R" : "W"), ml->seq_number, vc->channel, ml->token.ip_created, ml->token.sequence_number, vc);
-    }
-    cc->freeMsgBuffer();
-    SET_CONTINUATION_HANDLER(cc, (CacheContHandler)
-                             & CacheContinuation::remoteOpEvent);
-    return 1;
-
-  } else {
-    //////////////////////////////////////////////////////
-    // Unable to setup VC, delay required, await callback
-    //////////////////////////////////////////////////////
-    return -1;
-  }
-}
-
-ClusterVConnection *
-CacheContinuation::lookupOpenWriteVC()
-{
-  ///////////////////////////////////////////////////////////////
-  // See if we already have an open_write ClusterVConnection
-  // which was established in a previous remote open_read which
-  // failed.
-  ///////////////////////////////////////////////////////////////
-  ClusterVConnection *vc;
-  CacheOpMsg_long *ml = (CacheOpMsg_long *) getMsgBuffer();
-
-  vc = GlobalOpenWriteVCcache->lookup(&ml->url_md5);
-
-  if (vc == ((ClusterVConnection *) 0)) {
-    // Retry lookup
-    SET_CONTINUATION_HANDLER(this, (CacheContHandler)
-                             & CacheContinuation::lookupOpenWriteVCEvent);
-    //
-    // Note: In the lookupOpenWriteVCEvent handler, we use EVENT_IMMEDIATE
-    //       to distinguish the lookup retry from a request timeout
-    //       which uses EVENT_INTERVAL.
-    //
-    lookup_open_write_vc_event = eventProcessor.schedule_imm(this, ET_CACHE_CONT_SM);
-
-  } else if (vc != ((ClusterVConnection *) - 1)) {
-    // Hit, found open_write VC in cache.
-    // Post open_write completion by simulating a
-    // remote cache op result message.
-
-    vc->action_ = action;       // establish new continuation
-
-    SET_CONTINUATION_HANDLER(this, (CacheContHandler)
-                             & CacheContinuation::localVCsetupEvent);
-    this->handleEvent(CLUSTER_EVENT_OPEN_EXISTS, vc);
-
-    CacheOpReplyMsg msg;
-    int msglen;
-
-    msglen = CacheOpReplyMsg::sizeof_fixedlen_msg();
-    msg.result = CACHE_EVENT_OPEN_WRITE;
-    msg.seq_number = seq_number;
-    msg.token = vc->token;
-
-    cache_op_result_ClusterFunction(ch, (void *) &msg, msglen);
-
-  } else {
-    // Miss, establish local VC and send remote open_write request
-
-    SET_CONTINUATION_HANDLER(this, (CacheContHandler)
-                             & CacheContinuation::localVCsetupEvent);
-    vc = clusterProcessor.open_local(this, from, open_local_token,
-                                     (CLUSTER_OPT_ALLOW_IMMEDIATE | CLUSTER_OPT_CONN_WRITE));
-    if (!vc) {
-      this->handleEvent(CLUSTER_EVENT_OPEN_FAILED, 0);
-
-    } else if (vc != CLUSTER_DELAYED_OPEN) {
-      this->handleEvent(CLUSTER_EVENT_OPEN, vc);
-    }
-  }
-  return CLUSTER_DELAYED_OPEN;  // force completion in callback
-}
-
-int
-CacheContinuation::lookupOpenWriteVCEvent(int event, Event * e)
-{
-  if (event == EVENT_IMMEDIATE) {
-    // Retry open_write VC lookup
-    lookupOpenWriteVC();
-
-  } else {
-    lookup_open_write_vc_event->cancel();
-    SET_CONTINUATION_HANDLER(this, (CacheContHandler)
-                             & CacheContinuation::localVCsetupEvent);
-    this->handleEvent(event, e);
-  }
-  return EVENT_DONE;
-}
-
-int
-CacheContinuation::remove_and_delete(int /* event ATS_UNUSED */, Event * e)
-{
-  unsigned int hash = FOLDHASH(target_ip, seq_number);
-  MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], this_ethread());
-  if (queuelock) {
-    if (remoteCacheContQueue[hash].in(this)) {
-      remoteCacheContQueue[hash].remove(this);
-    }
-    MUTEX_RELEASE(queuelock);
-    if (use_deferred_callback)
-      callback_failure(&action, result, result_error, this);
-    else
-      cacheContAllocator_free(this);
-
-  } else {
-    SET_HANDLER((CacheContHandler) & CacheContinuation::remove_and_delete);
-    if (!e) {
-      timeout = eventProcessor.schedule_in(this, cache_cluster_timeout, ET_CACHE_CONT_SM);
-    } else {
-      e->schedule_in(cache_cluster_timeout);
+  if (!cluster_send_message(cs, CLUSTER_CACHE_OP_CLUSTER_FUNCTION, ret, -1, PRIORITY_HIGH)) {
+    if (ccvc) {
+      ccvc->in_progress = true;
+      cluster_set_events(cs, RESPONSE_EVENT_NOTIFY_DEALER);
+      return &ccvc->_action;
     }
   }
-  return EVENT_DONE;
-}
-
-int
-CacheContinuation::localVCsetupEvent(int event, ClusterVConnection * vc)
-{
-  ink_assert(magicno == (int) MagicNo);
-  ink_assert(getMsgBuffer());
-  bool short_msg = op_is_shortform(request_opcode);
-  bool read_op = op_is_read(request_opcode);
-
-  if (event == EVENT_INTERVAL) {
-    Event *e = (Event *) vc;
-    unsigned int hash = FOLDHASH(target_ip, seq_number);
-
-    MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], e->ethread);
-    if (!queuelock) {
-      e->schedule_in(CACHE_RETRY_PERIOD);
-      return EVENT_CONT;
-    }
-
-    if (!remoteCacheContQueue[hash].in(this)) {
-      ////////////////////////////////////////////////////
-      // Not yet queued on outstanding operations list
-      ////////////////////////////////////////////////////
-      remoteCacheContQueue[hash].enqueue(this);
-      ink_assert(timeout == e);
-      MUTEX_RELEASE(queuelock);
-      e->schedule_in(cache_cluster_timeout);
-      return EVENT_CONT;
-
-    } else {
-      /////////////////////////////////////////////////////
-      // Timeout occurred
-      /////////////////////////////////////////////////////
-      remoteCacheContQueue[hash].remove(this);
-      MUTEX_RELEASE(queuelock);
-      Debug("cluster_timeout", "0cluster op timeout %d", seq_number);
-      CLUSTER_INCREMENT_DYN_STAT(CLUSTER_REMOTE_OP_TIMEOUTS_STAT);
-      timeout = (Event *) 1;    // Note timeout
-      /////////////////////////////////////////////////////////////////
-      // Note: Failure callback is sent now, but the deallocation of
-      //       the CacheContinuation is deferred until we receive the
-      //       open_local() callback.
-      /////////////////////////////////////////////////////////////////
-      if (!action.cancelled)
-        action.continuation->handleEvent((read_op ? CACHE_EVENT_OPEN_READ_FAILED : CACHE_EVENT_OPEN_WRITE_FAILED), 0);
-      return EVENT_DONE;
-    }
-
-  } else if (((event == CLUSTER_EVENT_OPEN) || (event == CLUSTER_EVENT_OPEN_EXISTS))
-             && (((ptrdiff_t) timeout & (ptrdiff_t) 1) == 0)) {
-    ink_hrtime now;
-    now = ink_get_hrtime();
-    CLUSTER_SUM_DYN_STAT(CLUSTER_OPEN_DELAY_TIME_STAT, now - start_time);
-    LOG_EVENT_TIME(start_time, open_delay_time_dist, open_delay_events);
-    if (read_op) {
-      read_cluster_vc = vc;
-    } else {
-      write_cluster_vc = vc;
-    }
-    cluster_vc_channel = vc->channel;
-    vc->current_cont = this;
-
-    if (short_msg) {
-      CacheOpMsg_short *ms = (CacheOpMsg_short *) getMsgBuffer();
-      ms->channel = vc->channel;
-      ms->token = open_local_token;
-
-      Debug("cache_proto",
-            "2open_local-s (%s) success, seqno=%d chan=%d token=%d,%d VC=%p",
-            (read_op ? "R" : "W"), ms->seq_number, vc->channel, ms->token.ip_created, ms->token.sequence_number, vc);
-
-    } else {
-      CacheOpMsg_long *ml = (CacheOpMsg_long *) getMsgBuffer();
-      ml->channel = vc->channel;
-      ml->token = open_local_token;
-
-      Debug("cache_proto",
-            "3open_local-l (%s) success, seqno=%d chan=%d token=%d,%d VC=%p",
-            (read_op ? "R" : "W"), ml->seq_number, vc->channel, ml->token.ip_created, ml->token.sequence_number, vc);
-    }
-    SET_HANDLER((CacheContHandler) & CacheContinuation::remoteOpEvent);
-
-    if (event != CLUSTER_EVENT_OPEN_EXISTS) {
-      // Send request message
-      clusterProcessor.invoke_remote(ch,
-                                     (op_needs_marshalled_coi(request_opcode) ?
-                                      CACHE_OP_MALLOCED_CLUSTER_FUNCTION :
-                                      CACHE_OP_CLUSTER_FUNCTION), (char *) getMsgBuffer(), getMsgBufferLen());
-    }
-
-  } else {
-    int send_failure_callback = 1;
-
-    if (((ptrdiff_t) timeout & (ptrdiff_t) 1) == 0) {
-      if (short_msg) {
-        Debug("cache_proto", "2open_local-s (%s) failed, seqno=%d",
-              (read_op ? "R" : "W"), ((CacheOpMsg_short *) getMsgBuffer())->seq_number);
-      } else {
-        Debug("cache_proto", "3open_local-l (%s) failed, seqno=%d",
-              (read_op ? "R" : "W"), ((CacheOpMsg_long *) getMsgBuffer())->seq_number);
-      }
-
-    } else {
-      Debug("cache_proto", "4open_local cancelled due to timeout, seqno=%d", seq_number);
-      this->timeout = 0;
-
-      // Deallocate VC if successfully acquired
-
-      if (event == CLUSTER_EVENT_OPEN) {
-        vc->pending_remote_fill = 0;
-        vc->remote_closed = 1;  // avoid remote close msg
-        vc->do_io(VIO::CLOSE);
-      }
-      send_failure_callback = 0;        // already sent.
-    }
-
-    if (this->timeout)
-      this->timeout->cancel();
-    this->timeout = NULL;
-
-    freeMsgBuffer();
-    if (send_failure_callback) {
-      //
-      // Action corresponding to "this" already sent back to user,
-      //   use "this" to establish the failure callback after
-      //   removing ourselves from the active list.
-      //
-      this->use_deferred_callback = true;
-      this->result = (read_op ? CACHE_EVENT_OPEN_READ_FAILED : CACHE_EVENT_OPEN_WRITE_FAILED);
-      this->result_error = 0;
-      remove_and_delete(0, (Event *) 0);
-
-    } else {
-      cacheContAllocator_free(this);
-    }
-    return EVENT_DONE;
+  cluster_close_session(cs);
+  if (ccvc) {
+    ccvc->session_closed = true;
+    free_ClusterCacheVC(ccvc);
   }
-  // Free message
-  freeMsgBuffer();
-
-  return EVENT_DONE;
+  return 0;
 }
+//int
+//CacheContinuation::setup_local_vc(char *data, int data_len, CacheContinuation * cc, ClusterMachine * mp, Action ** act)
+//{
+//  bool read_op = op_is_read(cc->request_opcode);
+//  bool short_msg = op_is_shortform(cc->request_opcode);
+//
+//  // Alloc buffer, copy message and attach to continuation
+//  cc->setMsgBufferLen(data_len);
+//  cc->allocMsgBuffer();
+//  memcpy(cc->getMsgBuffer(), data, data_len);
+//
+//  SET_CONTINUATION_HANDLER(cc, (CacheContHandler)
+//                           & CacheContinuation::localVCsetupEvent);
+//
+//  if (short_msg) {
+//    Debug("cache_proto", "open_local-s (%s) seqno=%d", (read_op ? "R" : "W"), ((CacheOpMsg_short *) data)->seq_number);
+//  } else {
+//    Debug("cache_proto", "open_local-l (%s) seqno=%d", (read_op ? "R" : "W"), ((CacheOpMsg_long *) data)->seq_number);
+//  }
+//
+//  // Create local VC
+//  ClusterVConnection *vc;
+//
+//  if (!read_op && (cc->request_opcode == CACHE_OPEN_WRITE_LONG)) {
+//    // Determine if the open_write has already been established.
+//    vc = cc->lookupOpenWriteVC();
+//
+//  } else {
+//    vc = clusterProcessor.open_local(cc, mp, cc->open_local_token,
+//                                     (CLUSTER_OPT_ALLOW_IMMEDIATE |
+//                                      (read_op ? CLUSTER_OPT_CONN_READ : CLUSTER_OPT_CONN_WRITE)));
+//  }
+//  if (!vc) {
+//    // Error, abort request
+//    if (short_msg) {
+//      Debug("cache_proto", "0open_local-s (%s) failed, seqno=%d",
+//            (read_op ? "R" : "W"), ((CacheOpMsg_short *) data)->seq_number);
+//    } else {
+//      Debug("cache_proto", "1open_local-l (%s) failed, seqno=%d",
+//            (read_op ? "R" : "W"), ((CacheOpMsg_long *) data)->seq_number);
+//    }
+//    cc->freeMsgBuffer();
+//    if (cc->timeout)
+//      cc->timeout->cancel();
+//    cc->timeout = NULL;
+//
+//    // Post async failure callback on a different continuation.
+//    *act = callback_failure(&cc->action, (read_op ? CACHE_EVENT_OPEN_READ_FAILED : CACHE_EVENT_OPEN_WRITE_FAILED), 0);
+//    return 0;
+//
+//  } else if (vc != CLUSTER_DELAYED_OPEN) {
+//    // We have established the VC
+//    if (read_op) {
+//      cc->read_cluster_vc = vc;
+//    } else {
+//      cc->write_cluster_vc = vc;
+//    }
+//    cc->cluster_vc_channel = vc->channel;
+//    vc->current_cont = cc;
+//
+//    if (short_msg) {
+//      CacheOpMsg_short *ms = (CacheOpMsg_short *) data;
+//      ms->channel = vc->channel;
+//      ms->token = cc->open_local_token;
+//      Debug("cache_proto",
+//            "0open_local-s (%s) success, seqno=%d chan=%d token=%d,%d VC=%p",
+//            (read_op ? "R" : "W"), ms->seq_number, vc->channel, ms->token.ip_created, ms->token.sequence_number, vc);
+//    } else {
+//      CacheOpMsg_long *ml = (CacheOpMsg_long *) data;
+//      ml->channel = vc->channel;
+//      ml->token = cc->open_local_token;
+//      Debug("cache_proto",
+//            "1open_local-l (%s) success, seqno=%d chan=%d token=%d,%d VC=%p",
+//            (read_op ? "R" : "W"), ml->seq_number, vc->channel, ml->token.ip_created, ml->token.sequence_number, vc);
+//    }
+//    cc->freeMsgBuffer();
+//    SET_CONTINUATION_HANDLER(cc, (CacheContHandler)
+//                             & CacheContinuation::remoteOpEvent);
+//    return 1;
+//
+//  } else {
+//    //////////////////////////////////////////////////////
+//    // Unable to setup VC, delay required, await callback
+//    //////////////////////////////////////////////////////
+//    return -1;
+//  }
+//}
+//
+//ClusterVConnection *
+//CacheContinuation::lookupOpenWriteVC()
+//{
+//  ///////////////////////////////////////////////////////////////
+//  // See if we already have an open_write ClusterVConnection
+//  // which was established in a previous remote open_read which
+//  // failed.
+//  ///////////////////////////////////////////////////////////////
+//  ClusterVConnection *vc;
+//  CacheOpMsg_long *ml = (CacheOpMsg_long *) getMsgBuffer();
+//
+//  vc = GlobalOpenWriteVCcache->lookup(&ml->url_md5);
+//
+//  if (vc == ((ClusterVConnection *) 0)) {
+//    // Retry lookup
+//    SET_CONTINUATION_HANDLER(this, (CacheContHandler)
+//                             & CacheContinuation::lookupOpenWriteVCEvent);
+//    //
+//    // Note: In the lookupOpenWriteVCEvent handler, we use EVENT_IMMEDIATE
+//    //       to distinguish the lookup retry from a request timeout
+//    //       which uses EVENT_INTERVAL.
+//    //
+//    lookup_open_write_vc_event = eventProcessor.schedule_imm(this, ET_CACHE_CONT_SM);
+//
+//  } else if (vc != ((ClusterVConnection *) - 1)) {
+//    // Hit, found open_write VC in cache.
+//    // Post open_write completion by simulating a
+//    // remote cache op result message.
+//
+//    vc->action_ = action;       // establish new continuation
+//
+//    SET_CONTINUATION_HANDLER(this, (CacheContHandler)
+//                             & CacheContinuation::localVCsetupEvent);
+//    this->handleEvent(CLUSTER_EVENT_OPEN_EXISTS, vc);
+//
+//    CacheOpReplyMsg msg;
+//    int msglen;
+//
+//    msglen = CacheOpReplyMsg::sizeof_fixedlen_msg();
+//    msg.result = CACHE_EVENT_OPEN_WRITE;
+//    msg.seq_number = seq_number;
+//    msg.token = vc->token;
+//
+//    cache_op_result_ClusterFunction(ch, (void *) &msg, msglen);
+//
+//  } else {
+//    // Miss, establish local VC and send remote open_write request
+//
+//    SET_CONTINUATION_HANDLER(this, (CacheContHandler)
+//                             & CacheContinuation::localVCsetupEvent);
+//    vc = clusterProcessor.open_local(this, from, open_local_token,
+//                                     (CLUSTER_OPT_ALLOW_IMMEDIATE | CLUSTER_OPT_CONN_WRITE));
+//    if (!vc) {
+//      this->handleEvent(CLUSTER_EVENT_OPEN_FAILED, 0);
+//
+//    } else if (vc != CLUSTER_DELAYED_OPEN) {
+//      this->handleEvent(CLUSTER_EVENT_OPEN, vc);
+//    }
+//  }
+//  return CLUSTER_DELAYED_OPEN;  // force completion in callback
+//}
+//
+//int
+//CacheContinuation::lookupOpenWriteVCEvent(int event, Event * e)
+//{
+//  if (event == EVENT_IMMEDIATE) {
+//    // Retry open_write VC lookup
+//    lookupOpenWriteVC();
+//
+//  } else {
+//    lookup_open_write_vc_event->cancel();
+//    SET_CONTINUATION_HANDLER(this, (CacheContHandler)
+//                             & CacheContinuation::localVCsetupEvent);
+//    this->handleEvent(event, e);
+//  }
+//  return EVENT_DONE;
+//}
+//
+//int
+//CacheContinuation::remove_and_delete(int event, Event * e)
+//{
+//  NOWARN_UNUSED(event);
+//  unsigned int hash = FOLDHASH(target_ip, seq_number);
+//  MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], this_ethread());
+//  if (queuelock) {
+//    if (remoteCacheContQueue[hash].in(this)) {
+//      remoteCacheContQueue[hash].remove(this);
+//    }
+//    MUTEX_RELEASE(queuelock);
+//    if (use_deferred_callback)
+//      callback_failure(&action, result, result_error, this);
+//    else
+//      cacheContAllocator_free(this);
+//
+//  } else {
+//    SET_HANDLER((CacheContHandler) & CacheContinuation::remove_and_delete);
+//    if (!e) {
+//      timeout = eventProcessor.schedule_in(this, cache_cluster_timeout, ET_CACHE_CONT_SM);
+//    } else {
+//      e->schedule_in(cache_cluster_timeout);
+//    }
+//  }
+//  return EVENT_DONE;
+//}
+//
+//int
+//CacheContinuation::localVCsetupEvent(int event, ClusterVConnection * vc)
+//{
+//  ink_assert(magicno == (int) MagicNo);
+//  ink_assert(getMsgBuffer());
+//  bool short_msg = op_is_shortform(request_opcode);
+//  bool read_op = op_is_read(request_opcode);
+//
+//  if (event == EVENT_INTERVAL) {
+//    Event *e = (Event *) vc;
+//    unsigned int hash = FOLDHASH(target_ip, seq_number);
+//
+//    MUTEX_TRY_LOCK(queuelock, remoteCacheContQueueMutex[hash], e->ethread);
+//    if (!queuelock) {
+//      e->schedule_in(CACHE_RETRY_PERIOD);
+//      return EVENT_CONT;
+//    }
+//
+//    if (!remoteCacheContQueue[hash].in(this)) {
+//      ////////////////////////////////////////////////////
+//      // Not yet queued on outstanding operations list
+//      ////////////////////////////////////////////////////
+//      remoteCacheContQueue[hash].enqueue(this);
+//      ink_assert(timeout == e);
+//      MUTEX_RELEASE(queuelock);
+//      e->schedule_in(cache_cluster_timeout);
+//      return EVENT_CONT;
+//
+//    } else {
+//      /////////////////////////////////////////////////////
+//      // Timeout occurred
+//      /////////////////////////////////////////////////////
+//      remoteCacheContQueue[hash].remove(this);
+//      MUTEX_RELEASE(queuelock);
+//      Debug("cluster_timeout", "0cluster op timeout %d", seq_number);
+//      CLUSTER_INCREMENT_DYN_STAT(CLUSTER_REMOTE_OP_TIMEOUTS_STAT);
+//      timeout = (Event *) 1;    // Note timeout
+//      /////////////////////////////////////////////////////////////////
+//      // Note: Failure callback is sent now, but the deallocation of
+//      //       the CacheContinuation is deferred until we receive the
+//      //       open_local() callback.
+//      /////////////////////////////////////////////////////////////////
+//      if (!action.cancelled)
+//        action.continuation->handleEvent((read_op ? CACHE_EVENT_OPEN_READ_FAILED : CACHE_EVENT_OPEN_WRITE_FAILED), 0);
+//      return EVENT_DONE;
+//    }
+//
+//  } else if (((event == CLUSTER_EVENT_OPEN) || (event == CLUSTER_EVENT_OPEN_EXISTS))
+//             && (((ptrdiff_t) timeout & (ptrdiff_t) 1) == 0)) {
+//    ink_hrtime now;
+//    now = ink_get_hrtime();
+//    CLUSTER_SUM_DYN_STAT(CLUSTER_OPEN_DELAY_TIME_STAT, now - start_time);
+//    LOG_EVENT_TIME(start_time, open_delay_time_dist, open_delay_events);
+//    if (read_op) {
+//      read_cluster_vc = vc;
+//    } else {
+//      write_cluster_vc = vc;
+//    }
+//    cluster_vc_channel = vc->channel;
+//    vc->current_cont = this;
+//
+//    if (short_msg) {
+//      CacheOpMsg_short *ms = (CacheOpMsg_short *) getMsgBuffer();
+//      ms->channel = vc->channel;
+//      ms->token = open_local_token;
+//
+//      Debug("cache_proto",
+//            "2open_local-s (%s) success, seqno=%d chan=%d token=%d,%d VC=%p",
+//            (read_op ? "R" : "W"), ms->seq_number, vc->channel, ms->token.ip_created, ms->token.sequence_number, vc);
+//
+//    } else {
+//      CacheOpMsg_long *ml = (CacheOpMsg_long *) getMsgBuffer();
+//      ml->channel = vc->channel;
+//      ml->token = open_local_token;
+//
+//      Debug("cache_proto",
+//            "3open_local-l (%s) success, seqno=%d chan=%d token=%d,%d VC=%p",
+//            (read_op ? "R" : "W"), ml->seq_number, vc->channel, ml->token.ip_created, ml->token.sequence_number, vc);
+//    }
+//    SET_HANDLER((CacheContHandler) & CacheContinuation::remoteOpEvent);
+//
+//    if (event != CLUSTER_EVENT_OPEN_EXISTS) {
+//      // Send request message
+//      clusterProcessor.invoke_remote(ch,
+//                                     (op_needs_marshalled_coi(request_opcode) ?
+//                                      CACHE_OP_MALLOCED_CLUSTER_FUNCTION :
+//                                      CACHE_OP_CLUSTER_FUNCTION), (char *) getMsgBuffer(), getMsgBufferLen());
+//    }
+//
+//  } else {
+//    int send_failure_callback = 1;
+//
+//    if (((ptrdiff_t) timeout & (ptrdiff_t) 1) == 0) {
+//      if (short_msg) {
+//        Debug("cache_proto", "2open_local-s (%s) failed, seqno=%d",
+//              (read_op ? "R" : "W"), ((CacheOpMsg_short *) getMsgBuffer())->seq_number);
+//      } else {
+//        Debug("cache_proto", "3open_local-l (%s) failed, seqno=%d",
+//              (read_op ? "R" : "W"), ((CacheOpMsg_long *) getMsgBuffer())->seq_number);
+//      }
+//
+//    } else {
+//      Debug("cache_proto", "4open_local cancelled due to timeout, seqno=%d", seq_number);
+//      this->timeout = 0;
+//
+//      // Deallocate VC if successfully acquired
+//
+//      if (event == CLUSTER_EVENT_OPEN) {
+//        vc->pending_remote_fill = 0;
+//        vc->remote_closed = 1;  // avoid remote close msg
+//        vc->do_io(VIO::CLOSE);
+//      }
+//      send_failure_callback = 0;        // already sent.
+//    }
+//
+//    if (this->timeout)
+//      this->timeout->cancel();
+//    this->timeout = NULL;
+//
+//    freeMsgBuffer();
+//    if (send_failure_callback) {
+//      //
+//      // Action corresponding to "this" already sent back to user,
+//      //   use "this" to establish the failure callback after
+//      //   removing ourselves from the active list.
+//      //
+//      this->use_deferred_callback = true;
+//      this->result = (read_op ? CACHE_EVENT_OPEN_READ_FAILED : CACHE_EVENT_OPEN_WRITE_FAILED);
+//      this->result_error = 0;
+//      remove_and_delete(0, (Event *) 0);
+//
+//    } else {
+//      cacheContAllocator_free(this);
+//    }
+//    return EVENT_DONE;
+//  }
+//  // Free message
+//  freeMsgBuffer();
+//
+//  return EVENT_DONE;
+//}
 
 ///////////////////////////////////////////////////////////////////////////
 // cache_op_ClusterFunction()
@@ -995,14 +1176,13 @@ unmarshal_CacheOpMsg_short_2(void *data, int NeedByteSwap)
 
 // init_from_long() support routine for cache_op_ClusterFunction()
 inline void
-init_from_long(CacheContinuation * cont, CacheOpMsg_long * msg, ClusterMachine * m)
+init_from_long(CacheContinuation * cont, CacheOpMsg_long * msg)
 {
-  cont->no_reply_message = (msg->seq_number == CACHE_NO_RESPONSE);
+//  cont->no_reply_message = (msg->seq_number == CACHE_NO_RESPONSE);
   cont->seq_number = msg->seq_number;
   cont->cfl_flags = msg->cfl_flags;
-  cont->from = m;
   cont->url_md5 = msg->url_md5;
-  cont->cluster_vc_channel = msg->channel;
+//  cont->cluster_vc_channel = msg->channel;
   cont->frag_type = (CacheFragType) msg->frag_type;
   if ((cont->request_opcode == CACHE_OPEN_WRITE_LONG)
       || (cont->request_opcode == CACHE_OPEN_READ_LONG)) {
@@ -1013,23 +1193,22 @@ init_from_long(CacheContinuation * cont, CacheOpMsg_long * msg, ClusterMachine *
   cont->token = msg->token;
   cont->nbytes = (((int) msg->nbytes < 0) ? 0 : msg->nbytes);
 
-  if (cont->request_opcode == CACHE_OPEN_READ_LONG) {
-    cont->caller_buf_freebytes = msg->buffer_size;
-  } else {
-    cont->caller_buf_freebytes = 0;
-  }
+//  if (cont->request_opcode == CACHE_OPEN_READ_LONG) {
+//    cont->caller_buf_freebytes = msg->buffer_size;
+//  } else {
+//    cont->caller_buf_freebytes = 0;
+//  }
 }
 
 // init_from_short() support routine for cache_op_ClusterFunction()
 inline void
-init_from_short(CacheContinuation * cont, CacheOpMsg_short * msg, ClusterMachine * m)
+init_from_short(CacheContinuation * cont, CacheOpMsg_short * msg)
 {
-  cont->no_reply_message = (msg->seq_number == CACHE_NO_RESPONSE);
+//  cont->no_reply_message = (msg->seq_number == CACHE_NO_RESPONSE);
   cont->seq_number = msg->seq_number;
   cont->cfl_flags = msg->cfl_flags;
-  cont->from = m;
   cont->url_md5 = msg->md5;
-  cont->cluster_vc_channel = msg->channel;
+//  cont->cluster_vc_channel = msg->channel;
   cont->token = msg->token;
   cont->nbytes = (((int) msg->nbytes < 0) ? 0 : msg->nbytes);
   cont->frag_type = (CacheFragType) msg->frag_type;
@@ -1040,29 +1219,436 @@ init_from_short(CacheContinuation * cont, CacheOpMsg_short * msg, ClusterMachine
     cont->pin_in_cache = 0;
   }
 
-  if (cont->request_opcode == CACHE_OPEN_READ) {
-    cont->caller_buf_freebytes = msg->buffer_size;
-  } else {
-    cont->caller_buf_freebytes = 0;
-  }
+//  if (cont->request_opcode == CACHE_OPEN_READ) {
+//    cont->caller_buf_freebytes = msg->buffer_size;
+//  } else {
+//    cont->caller_buf_freebytes = 0;
+//  }
 }
 
 // init_from_short_2() support routine for cache_op_ClusterFunction()
 inline void
-init_from_short_2(CacheContinuation * cont, CacheOpMsg_short_2 * msg, ClusterMachine * m)
+init_from_short_2(CacheContinuation * cont, CacheOpMsg_short_2 * msg)
 {
-  cont->no_reply_message = (msg->seq_number == CACHE_NO_RESPONSE);
+//  cont->no_reply_message = (msg->seq_number == CACHE_NO_RESPONSE);
   cont->seq_number = msg->seq_number;
   cont->cfl_flags = msg->cfl_flags;
-  cont->from = m;
   cont->url_md5 = msg->md5_1;
   cont->frag_type = (CacheFragType) msg->frag_type;
 }
 
+//void
+//cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
+//{
+//  EThread *thread = this_ethread();
+//  ProxyMutex *mutex = thread->mutex;
+//  ////////////////////////////////////////////////////////
+//  // Note: we are running on the ET_CLUSTER thread
+//  ////////////////////////////////////////////////////////
+//  CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CACHE_OUTSTANDING_STAT);
+//
+//  int opcode;
+//  ClusterMessageHeader *mh = (ClusterMessageHeader *) data;
+//
+//  if (mh->GetMsgVersion() != CacheOpMsg_long::CACHE_OP_LONG_MESSAGE_VERSION) {  ////////////////////////////////////////////////
+//    // Convert from old to current message format
+//    ////////////////////////////////////////////////
+//    ink_release_assert(!"cache_op_ClusterFunction() bad msg version");
+//  }
+//  opcode = ((CacheOpMsg_long *) data)->opcode;
+//
+//  // If necessary, create a continuation to reflect the response back
+//
+//  CacheContinuation *c = CacheContinuation::cacheContAllocator_alloc();
+//  c->mutex = new_ProxyMutex();
+//  MUTEX_TRY_LOCK(lock, c->mutex, this_ethread());
+//  c->request_opcode = opcode;
+//  c->token.clear();
+//  c->start_time = ink_get_hrtime();
+//  c->ch = ch;
+//  SET_CONTINUATION_HANDLER(c, (CacheContHandler)
+//                           & CacheContinuation::replyOpEvent);
+//
+//  switch (opcode) {
+//  case CACHE_OPEN_WRITE_BUFFER:
+//  case CACHE_OPEN_WRITE_BUFFER_LONG:
+//    ink_release_assert(!"cache_op_ClusterFunction WRITE_BUFFER not supported");
+//    break;
+//
+//  case CACHE_OPEN_READ_BUFFER:
+//  case CACHE_OPEN_READ_BUFFER_LONG:
+//    ink_release_assert(!"cache_op_ClusterFunction READ_BUFFER not supported");
+//    break;
+//
+//  case CACHE_OPEN_READ:
+//    {
+//      CacheOpMsg_short *msg = unmarshal_CacheOpMsg_short(data, mh->NeedByteSwap());
+//      init_from_short(c, msg, ch->machine);
+//      Debug("cache_msg",
+//            "cache_op-s op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+//      //
+//      // Establish the remote side of the ClusterVConnection
+//      //
+//      c->write_cluster_vc = clusterProcessor.connect_local((Continuation *) 0,
+//                                                           &c->token,
+//                                                           c->cluster_vc_channel,
+//                                                           (CLUSTER_OPT_IMMEDIATE | CLUSTER_OPT_CONN_READ));
+//      if (!c->write_cluster_vc) {
+//        // Unable to setup channel, abort processing.
+//        CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CHAN_INUSE_STAT);
+//        Debug("chan_inuse",
+//              "1Remote chan=%d inuse tok.ip=%u.%u.%u.%u tok.seqno=%d seqno=%d",
+//              c->cluster_vc_channel, DOT_SEPARATED(c->token.ip_created), c->token.sequence_number, c->seq_number);
+//
+//        // Send cluster op failed reply
+//        c->replyOpEvent(CACHE_EVENT_OPEN_READ_FAILED, (VConnection *) - ECLUSTER_CHANNEL_INUSE);
+//        break;
+//
+//      } else {
+//        c->write_cluster_vc->current_cont = c;
+//      }
+//      ink_release_assert(c->write_cluster_vc != CLUSTER_DELAYED_OPEN);
+//      ink_release_assert((opcode == CACHE_OPEN_READ)
+//                         || c->write_cluster_vc->pending_remote_fill);
+//
+//      SET_CONTINUATION_HANDLER(c, (CacheContHandler)
+//                               & CacheContinuation::setupVCdataRead);
+//      Debug("cache_proto",
+//            "0read op, seqno=%d chan=%d bufsize=%d token=%d,%d",
+//            msg->seq_number, msg->channel, msg->buffer_size, msg->token.ip_created, msg->token.sequence_number);
+//#ifdef CACHE_MSG_TRACE
+//      log_cache_op_msg(msg->seq_number, len, "cache_op_open_read");
+//#endif
+//      CacheKey key(msg->md5);
+//
+//      char *hostname = NULL;
+//      int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
+//      if (host_len) {
+//        hostname = (char *) msg->moi;
+//      }
+//      Cache *call_cache = caches[c->frag_type];
+//      c->cache_action = call_cache->open_read(c, &key, c->frag_type, hostname, host_len);
+//      break;
+//    }
+//  case CACHE_OPEN_READ_LONG:
+//    {
+//      // Cache needs message data, copy it.
+//      c->setMsgBufferLen(len);
+//      c->allocMsgBuffer();
+//      memcpy(c->getMsgBuffer(), (char *) data, len);
+//
+//      int flen = CacheOpMsg_long::sizeof_fixedlen_msg();
+//      CacheOpMsg_long *msg = unmarshal_CacheOpMsg_long(c->getMsgBuffer(), mh->NeedByteSwap());
+//      init_from_long(c, msg, ch->machine);
+//      Debug("cache_msg",
+//            "cache_op-l op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+//#ifdef CACHE_MSG_TRACE
+//      log_cache_op_msg(msg->seq_number, len, "cache_op_open_read_long");
+//#endif
+//      //
+//      // Establish the remote side of the ClusterVConnection
+//      //
+//      c->write_cluster_vc = clusterProcessor.connect_local((Continuation *) 0,
+//                                                           &c->token,
+//                                                           c->cluster_vc_channel,
+//                                                           (CLUSTER_OPT_IMMEDIATE | CLUSTER_OPT_CONN_READ));
+//      if (!c->write_cluster_vc) {
+//        // Unable to setup channel, abort processing.
+//        CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CHAN_INUSE_STAT);
+//        Debug("chan_inuse",
+//              "2Remote chan=%d inuse tok.ip=%u.%u.%u.%u tok.seqno=%d seqno=%d",
+//              c->cluster_vc_channel, DOT_SEPARATED(c->token.ip_created), c->token.sequence_number, c->seq_number);
+//
+//        // Send cluster op failed reply
+//        c->replyOpEvent(CACHE_EVENT_OPEN_READ_FAILED, (VConnection *) - ECLUSTER_CHANNEL_INUSE);
+//        break;
+//
+//      } else {
+//        c->write_cluster_vc->current_cont = c;
+//      }
+//      ink_release_assert(c->write_cluster_vc != CLUSTER_DELAYED_OPEN);
+//      ink_release_assert((opcode == CACHE_OPEN_READ_LONG)
+//                         || c->write_cluster_vc->pending_remote_fill);
+//
+//      SET_CONTINUATION_HANDLER(c, (CacheContHandler)
+//                               & CacheContinuation::setupReadWriteVC);
+//      Debug("cache_proto",
+//            "1read op, seqno=%d chan=%d bufsize=%d token=%d,%d",
+//            msg->seq_number, msg->channel, msg->buffer_size, msg->token.ip_created, msg->token.sequence_number);
+//
+//      const char *p = (const char *) msg + flen;
+//      int moi_len = len - flen;
+//      int res;
+//
+//      ink_assert(moi_len > 0);
+//
+//      // Unmarshal CacheHTTPHdr
+//      res = c->ic_request.unmarshal((char *) p, moi_len, NULL);
+//      ink_assert(res > 0);
+//      ink_assert(c->ic_request.valid());
+//      c->request_purge = c->ic_request.method_get_wksidx() == HTTP_WKSIDX_PURGE || c->ic_request.method_get_wksidx() == HTTP_WKSIDX_DELETE;
+//      moi_len -= res;
+//      p += res;
+//      ink_assert(moi_len > 0);
+//      // Unmarshal CacheLookupHttpConfig
+//      c->ic_params = new(CacheLookupHttpConfigAllocator.alloc())
+//        CacheLookupHttpConfig();
+//      res = c->ic_params->unmarshal(&c->ic_arena, (const char *) p, moi_len);
+//      ink_assert(res > 0);
+//
+//      moi_len -= res;
+//      p += res;
+//
+//      CacheKey key(msg->url_md5);
+//
+//      char *hostname = NULL;
+//      int host_len = 0;
+//
+//      if (moi_len) {
+//        hostname = (char *) p;
+//        host_len = moi_len;
+//
+//        // Save hostname and attach it to the continuation since we may
+//        //  need it if we convert this to an open_write.
+//
+//        c->ic_hostname = new_IOBufferData(iobuffer_size_to_index(host_len));
+//        c->ic_hostname_len = host_len;
+//
+//        memcpy(c->ic_hostname->data(), hostname, host_len);
+//      }
+//
+//      Cache *call_cache = caches[c->frag_type];
+//      Action *a = call_cache->open_read(c, &key, &c->ic_request,
+//                                        c->ic_params,
+//                                        c->frag_type, hostname, host_len);
+//      // Get rid of purify warnings since 'c' can be freed by open_read.
+//      if (a != ACTION_RESULT_DONE) {
+//        c->cache_action = a;
+//      }
+//      break;
+//    }
+//  case CACHE_OPEN_WRITE:
+//    {
+//      CacheOpMsg_short *msg = unmarshal_CacheOpMsg_short(data, mh->NeedByteSwap());
+//      init_from_short(c, msg, ch->machine);
+//      Debug("cache_msg",
+//            "cache_op-s op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+//#ifdef CACHE_MSG_TRACE
+//      log_cache_op_msg(msg->seq_number, len, "cache_op_open_write");
+//#endif
+//      //
+//      // Establish the remote side of the ClusterVConnection
+//      //
+//      c->read_cluster_vc = clusterProcessor.connect_local((Continuation *) 0,
+//                                                          &c->token,
+//                                                          c->cluster_vc_channel,
+//                                                          (CLUSTER_OPT_IMMEDIATE | CLUSTER_OPT_CONN_WRITE));
+//      if (!c->read_cluster_vc) {
+//        // Unable to setup channel, abort processing.
+//        CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CHAN_INUSE_STAT);
+//        Debug("chan_inuse",
+//              "3Remote chan=%d inuse tok.ip=%u.%u.%u.%u tok.seqno=%d seqno=%d",
+//              c->cluster_vc_channel, DOT_SEPARATED(c->token.ip_created), c->token.sequence_number, c->seq_number);
+//
+//        // Send cluster op failed reply
+//        c->replyOpEvent(CACHE_EVENT_OPEN_WRITE_FAILED, (VConnection *) - ECLUSTER_CHANNEL_INUSE);
+//        break;
+//
+//      } else {
+//        c->read_cluster_vc->current_cont = c;
+//      }
+//      ink_release_assert(c->read_cluster_vc != CLUSTER_DELAYED_OPEN);
+//
+//      CacheKey key(msg->md5);
+//
+//      char *hostname = NULL;
+//      int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
+//      if (host_len) {
+//        hostname = (char *) msg->moi;
+//      }
+//
+//      Cache *call_cache = caches[c->frag_type];
+//      Action *a = call_cache->open_write(c, &key, c->frag_type,
+//                                         !!(c->cfl_flags & CFL_OVERWRITE_ON_WRITE),
+//                                         c->pin_in_cache, hostname, host_len);
+//      if (a != ACTION_RESULT_DONE) {
+//        c->cache_action = a;
+//      }
+//      break;
+//    }
+//  case CACHE_OPEN_WRITE_LONG:
+//    {
+//      // Cache needs message data, copy it.
+//      c->setMsgBufferLen(len);
+//      c->allocMsgBuffer();
+//      memcpy(c->getMsgBuffer(), (char *) data, len);
+//
+//      int flen = CacheOpMsg_long::sizeof_fixedlen_msg();
+//      CacheOpMsg_long *msg = unmarshal_CacheOpMsg_long(c->getMsgBuffer(), mh->NeedByteSwap());
+//      init_from_long(c, msg, ch->machine);
+//      Debug("cache_msg",
+//            "cache_op-l op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+//#ifdef CACHE_MSG_TRACE
+//      log_cache_op_msg(msg->seq_number, len, "cache_op_open_write_long");
+//#endif
+//      //
+//      // Establish the remote side of the ClusterVConnection
+//      //
+//      c->read_cluster_vc = clusterProcessor.connect_local((Continuation *) 0,
+//                                                          &c->token,
+//                                                          c->cluster_vc_channel,
+//                                                          (CLUSTER_OPT_IMMEDIATE | CLUSTER_OPT_CONN_WRITE));
+//      if (!c->read_cluster_vc) {
+//        // Unable to setup channel, abort processing.
+//        CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CHAN_INUSE_STAT);
+//        Debug("chan_inuse",
+//              "4Remote chan=%d inuse tok.ip=%u.%u.%u.%u tok.seqno=%d seqno=%d",
+//              c->cluster_vc_channel, DOT_SEPARATED(c->token.ip_created), c->token.sequence_number, c->seq_number);
+//
+//        // Send cluster op failed reply
+//        c->replyOpEvent(CACHE_EVENT_OPEN_WRITE_FAILED, (VConnection *) - ECLUSTER_CHANNEL_INUSE);
+//        break;
+//
+//      } else {
+//        c->read_cluster_vc->current_cont = c;
+//      }
+//      ink_release_assert(c->read_cluster_vc != CLUSTER_DELAYED_OPEN);
+//
+//      CacheHTTPInfo *ci = 0;
+//      const char *p;
+//      int res = 0;
+//      int moi_len = len - flen;
+//
+//      if (moi_len && c->cfl_flags & CFL_LOPENWRITE_HAVE_OLDINFO) {
+//        p = (const char *) msg + flen;
+//
+//        // Unmarshal old CacheHTTPInfo
+//        res = HTTPInfo::unmarshal((char *) p, moi_len, NULL);
+//        ink_assert(res > 0);
+//        c->ic_old_info.get_handle((char *) p, moi_len);
+//        ink_assert(c->ic_old_info.valid());
+//        ci = &c->ic_old_info;
+//      } else {
+//        p = (const char *) 0;
+//      }
+//      if (c->cfl_flags & CFL_ALLOW_MULTIPLE_WRITES) {
+//        ink_assert(!ci);
+//        ci = (CacheHTTPInfo *) CACHE_ALLOW_MULTIPLE_WRITES;
+//      }
+//      moi_len -= res;
+//      p += res;
+//
+//      CacheKey key(msg->url_md5);
+//      char *hostname = NULL;
+//
+//      if (moi_len) {
+//        hostname = (char *) p;
+//      }
+//
+//      Cache *call_cache = caches[c->frag_type];
+//      Action *a = call_cache->open_write(c, &key, ci, c->pin_in_cache,
+//                                         NULL, c->frag_type, hostname, len);
+//      if (a != ACTION_RESULT_DONE) {
+//        c->cache_action = a;
+//      }
+//      break;
+//    }
+//  case CACHE_REMOVE:
+//    {
+//      CacheOpMsg_short *msg = unmarshal_CacheOpMsg_short(data, mh->NeedByteSwap());
+//      init_from_short(c, msg, ch->machine);
+//      Debug("cache_msg",
+//            "cache_op op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+//#ifdef CACHE_MSG_TRACE
+//      log_cache_op_msg(msg->seq_number, len, "cache_op_remove");
+//#endif
+//      CacheKey key(msg->md5);
+//
+//      char *hostname = NULL;
+//      int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
+//      if (host_len) {
+//        hostname = (char *) msg->moi;
+//      }
+//
+//      Cache *call_cache = caches[c->frag_type];
+//      Action *a = call_cache->remove(c, &key, c->frag_type,
+//                                     !!(c->cfl_flags & CFL_REMOVE_USER_AGENTS),
+//                                     !!(c->cfl_flags & CFL_REMOVE_LINK),
+//                                     hostname, host_len);
+//      if (a != ACTION_RESULT_DONE) {
+//        c->cache_action = a;
+//      }
+//      break;
+//    }
+//  case CACHE_LINK:
+//    {
+//      CacheOpMsg_short_2 *msg = unmarshal_CacheOpMsg_short_2(data, mh->NeedByteSwap());
+//      init_from_short_2(c, msg, ch->machine);
+//      Debug("cache_msg",
+//            "cache_op op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+//#ifdef CACHE_MSG_TRACE
+//      log_cache_op_msg(msg->seq_number, len, "cache_op_link");
+//#endif
+//
+//      CacheKey key1(msg->md5_1);
+//      CacheKey key2(msg->md5_2);
+//
+//      char *hostname = NULL;
+//      int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
+//      if (host_len) {
+//        hostname = (char *) msg->moi;
+//      }
+//
+//      Cache *call_cache = caches[c->frag_type];
+//      Action *a = call_cache->link(c, &key1, &key2, c->frag_type,
+//                                   hostname, host_len);
+//      if (a != ACTION_RESULT_DONE) {
+//        c->cache_action = a;
+//      }
+//      break;
+//    }
+//  case CACHE_DEREF:
+//    {
+//      CacheOpMsg_short *msg = unmarshal_CacheOpMsg_short(data, mh->NeedByteSwap());
+//      init_from_short(c, msg, ch->machine);
+//      Debug("cache_msg",
+//            "cache_op op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+//#ifdef CACHE_MSG_TRACE
+//      log_cache_op_msg(msg->seq_number, len, "cache_op_deref");
+//#endif
+//
+//      CacheKey key(msg->md5);
+//
+//      char *hostname = NULL;
+//      int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
+//      if (host_len) {
+//        hostname = (char *) msg->moi;
+//      }
+//
+//      Cache *call_cache = caches[c->frag_type];
+//      Action *a = call_cache->deref(c, &key, c->frag_type,
+//                                    hostname, host_len);
+//      if (a != ACTION_RESULT_DONE) {
+//        c->cache_action = a;
+//      }
+//      break;
+//    }
+//
+//  default:
+//    {
+//      ink_release_assert(0);
+//    }
+//  }                             // End of switch
+//}
+
+
 void
-cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
+cache_op_ClusterFunction(ClusterSession cs, void *context, void *d)
 {
-  EThread *thread = this_ethread();
+  ClusterCont *cc = (ClusterCont *) d;
+  ink_assert(cc && !context);
+
+  EThread *thread = cc->mutex->thread_holding;
   ProxyMutex *mutex = thread->mutex;
   ////////////////////////////////////////////////////////
   // Note: we are running on the ET_CLUSTER thread
@@ -1070,26 +1656,37 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
   CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CACHE_OUTSTANDING_STAT);
 
   int opcode;
-  ClusterMessageHeader *mh = (ClusterMessageHeader *) data;
+  int len = cc->data_len;
+
+  // memcpy to release the reference early
+  Ptr<IOBufferData> buf;
+  buf = new_IOBufferData(iobuffer_size_to_index(len, MAX_BUFFER_SIZE_INDEX));
+  char *data = buf.m_ptr->data();
+  for (IOBufferBlock *b = cc->data; b; b = b->next) {
+    memcpy(data, b->_start, b->_end - b->_start);
+    data += b->_end - b->_start;
+  }
+  data = buf->data();
 
-  if (mh->GetMsgVersion() != CacheOpMsg_long::CACHE_OP_LONG_MESSAGE_VERSION) {  ////////////////////////////////////////////////
-    // Convert from old to current message format
-    ////////////////////////////////////////////////
-    ink_release_assert(!"cache_op_ClusterFunction() bad msg version");
+  ClusterMessageHeader *mh = (ClusterMessageHeader *) data;
+  ink_assert(mh->GetMsgVersion() == CacheOpMsg_long::CACHE_OP_LONG_MESSAGE_VERSION);
+
+  opcode = ((CacheOpMsg_long *) mh)->opcode;
+  CacheContinuation *c = new_CacheCont(thread);
+  if (cluster_bind_session(cs, c)) {
+    cluster_close_session(cs);
+    free_CacheCont(c);
+    return;
   }
-  opcode = ((CacheOpMsg_long *) data)->opcode;
-
-  // If necessary, create a continuation to reflect the response back
 
-  CacheContinuation *c = CacheContinuation::cacheContAllocator_alloc();
-  c->mutex = new_ProxyMutex();
-  MUTEX_TRY_LOCK(lock, c->mutex, this_ethread());
   c->request_opcode = opcode;
+  c->frag_type = (CacheFragType) ((CacheOpMsg_long *) mh)->frag_type;
   c->token.clear();
-  c->start_time = ink_get_hrtime();
-  c->ch = ch;
-  SET_CONTINUATION_HANDLER(c, (CacheContHandler)
-                           & CacheContinuation::replyOpEvent);
+  c->rw_buf_msg = buf;
+  c->rw_buf_msg_len = len;
+  c->cs = cs;
+
+  MUTEX_TRY_LOCK(lock, c->mutex, c->thread);
 
   switch (opcode) {
   case CACHE_OPEN_WRITE_BUFFER:
@@ -1105,33 +1702,9 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
   case CACHE_OPEN_READ:
     {
       CacheOpMsg_short *msg = unmarshal_CacheOpMsg_short(data, mh->NeedByteSwap());
-      init_from_short(c, msg, ch->machine);
+      init_from_short(c, msg);
       Debug("cache_msg",
-            "cache_op-s op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
-      //
-      // Establish the remote side of the ClusterVConnection
-      //
-      c->write_cluster_vc = clusterProcessor.connect_local((Continuation *) 0,
-                                                           &c->token,
-                                                           c->cluster_vc_channel,
-                                                           (CLUSTER_OPT_IMMEDIATE | CLUSTER_OPT_CONN_READ));
-      if (!c->write_cluster_vc) {
-        // Unable to setup channel, abort processing.
-        CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CHAN_INUSE_STAT);
-        Debug("chan_inuse",
-              "1Remote chan=%d inuse tok.ip=%u.%u.%u.%u tok.seqno=%d seqno=%d",
-              c->cluster_vc_channel, DOT_SEPARATED(c->token.ip_created), c->token.sequence_number, c->seq_number);
-
-        // Send cluster op failed reply
-        c->replyOpEvent(CACHE_EVENT_OPEN_READ_FAILED, (VConnection *) - ECLUSTER_CHANNEL_INUSE);
-        break;
-
-      } else {
-        c->write_cluster_vc->current_cont = c;
-      }
-      ink_release_assert(c->write_cluster_vc != CLUSTER_DELAYED_OPEN);
-      ink_release_assert((opcode == CACHE_OPEN_READ)
-                         || c->write_cluster_vc->pending_remote_fill);
+            "cache_op-s op=%d seqno=%d data=%p len=%d", opcode, c->seq_number, data, len);
 
       SET_CONTINUATION_HANDLER(c, (CacheContHandler)
                                & CacheContinuation::setupVCdataRead);
@@ -1143,57 +1716,31 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
 #endif
       CacheKey key(msg->md5);
 
-      char *hostname = NULL;
-      int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
-      if (host_len) {
-        hostname = (char *) msg->moi.byte;
-      }
+      int flen = op_to_sizeof_fixedlen_msg(opcode);
+      c->ic_hostname_len = len - flen;
+      c->ic_hostname = (char *) msg + flen;
       Cache *call_cache = caches[c->frag_type];
-      c->cache_action = call_cache->open_read(c, &key, c->frag_type, hostname, host_len);
+      c->pending_action = call_cache->open_read(c, &key, c->frag_type, c->ic_hostname, c->ic_hostname_len);
       break;
     }
   case CACHE_OPEN_READ_LONG:
     {
       // Cache needs message data, copy it.
-      c->setMsgBufferLen(len);
-      c->allocMsgBuffer();
-      memcpy(c->getMsgBuffer(), (char *) data, len);
+//      c->setMsgBufferLen(len);
+//      c->allocMsgBuffer();
+//      memcpy(c->getMsgBuffer(), (char *) data, len);
 
       int flen = CacheOpMsg_long::sizeof_fixedlen_msg();
-      CacheOpMsg_long *msg = unmarshal_CacheOpMsg_long(c->getMsgBuffer(), mh->NeedByteSwap());
-      init_from_long(c, msg, ch->machine);
+      CacheOpMsg_long *msg = unmarshal_CacheOpMsg_long(data, mh->NeedByteSwap());
+      init_from_long(c, msg);
       Debug("cache_msg",
-            "cache_op-l op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+            "cache_op-l op=%d seqno=%d data=%p len=%d", opcode, c->seq_number, data, len);
 #ifdef CACHE_MSG_TRACE
       log_cache_op_msg(msg->seq_number, len, "cache_op_open_read_long");
 #endif
-      //
-      // Establish the remote side of the ClusterVConnection
-      //
-      c->write_cluster_vc = clusterProcessor.connect_local((Continuation *) 0,
-                                                           &c->token,
-                                                           c->cluster_vc_channel,
-                                                           (CLUSTER_OPT_IMMEDIATE | CLUSTER_OPT_CONN_READ));
-      if (!c->write_cluster_vc) {
-        // Unable to setup channel, abort processing.
-        CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CHAN_INUSE_STAT);
-        Debug("chan_inuse",
-              "2Remote chan=%d inuse tok.ip=%u.%u.%u.%u tok.seqno=%d seqno=%d",
-              c->cluster_vc_channel, DOT_SEPARATED(c->token.ip_created), c->token.sequence_number, c->seq_number);
-
-        // Send cluster op failed reply
-        c->replyOpEvent(CACHE_EVENT_OPEN_READ_FAILED, (VConnection *) - ECLUSTER_CHANNEL_INUSE);
-        break;
-
-      } else {
-        c->write_cluster_vc->current_cont = c;
-      }
-      ink_release_assert(c->write_cluster_vc != CLUSTER_DELAYED_OPEN);
-      ink_release_assert((opcode == CACHE_OPEN_READ_LONG)
-                         || c->write_cluster_vc->pending_remote_fill);
 
       SET_CONTINUATION_HANDLER(c, (CacheContHandler)
-                               & CacheContinuation::setupReadWriteVC);
+                                     & CacheContinuation::setupVCdataRead);
       Debug("cache_proto",
             "1read op, seqno=%d chan=%d bufsize=%d token=%d,%d",
             msg->seq_number, msg->channel, msg->buffer_size, msg->token.ip_created, msg->token.sequence_number);
@@ -1215,6 +1762,11 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
       // Unmarshal CacheLookupHttpConfig
       c->ic_params = new(CacheLookupHttpConfigAllocator.alloc())
         CacheLookupHttpConfig();
+      memcpy(c->ic_params, p, sizeof(CacheLookupHttpConfig));
+      moi_len -= sizeof(CacheLookupHttpConfig);
+      p += sizeof(CacheLookupHttpConfig);
+
+      ink_assert(moi_len > 0);
       res = c->ic_params->unmarshal(&c->ic_arena, (const char *) p, moi_len);
       ink_assert(res > 0);
 
@@ -1223,132 +1775,81 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
 
       CacheKey key(msg->url_md5);
 
-      char *hostname = NULL;
-      int host_len = 0;
-
       if (moi_len) {
-        hostname = (char *) p;
-        host_len = moi_len;
-
-        // Save hostname and attach it to the continuation since we may
-        //  need it if we convert this to an open_write.
-
-        c->ic_hostname = new_IOBufferData(iobuffer_size_to_index(host_len));
-        c->ic_hostname_len = host_len;
-
-        memcpy(c->ic_hostname->data(), hostname, host_len);
+        c->ic_hostname = (char *) p;
+        c->ic_hostname_len = moi_len;
       }
 
       Cache *call_cache = caches[c->frag_type];
       Action *a = call_cache->open_read(c, &key, &c->ic_request,
                                         c->ic_params,
-                                        c->frag_type, hostname, host_len);
+                                        c->frag_type, c->ic_hostname, c->ic_hostname_len);
       // Get rid of purify warnings since 'c' can be freed by open_read.
       if (a != ACTION_RESULT_DONE) {
-        c->cache_action = a;
+        c->pending_action = a;
       }
       break;
     }
   case CACHE_OPEN_WRITE:
     {
       CacheOpMsg_short *msg = unmarshal_CacheOpMsg_short(data, mh->NeedByteSwap());
-      init_from_short(c, msg, ch->machine);
+      init_from_short(c, msg);
       Debug("cache_msg",
-            "cache_op-s op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+            "cache_op-s op=%d seqno=%d data=%p len=%d", opcode, c->seq_number, data, len);
 #ifdef CACHE_MSG_TRACE
       log_cache_op_msg(msg->seq_number, len, "cache_op_open_write");
 #endif
-      //
-      // Establish the remote side of the ClusterVConnection
-      //
-      c->read_cluster_vc = clusterProcessor.connect_local((Continuation *) 0,
-                                                          &c->token,
-                                                          c->cluster_vc_channel,
-                                                          (CLUSTER_OPT_IMMEDIATE | CLUSTER_OPT_CONN_WRITE));
-      if (!c->read_cluster_vc) {
-        // Unable to setup channel, abort processing.
-        CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CHAN_INUSE_STAT);
-        Debug("chan_inuse",
-              "3Remote chan=%d inuse tok.ip=%u.%u.%u.%u tok.seqno=%d seqno=%d",
-              c->cluster_vc_channel, DOT_SEPARATED(c->token.ip_created), c->token.sequence_number, c->seq_number);
-
-        // Send cluster op failed reply
-        c->replyOpEvent(CACHE_EVENT_OPEN_WRITE_FAILED, (VConnection *) - ECLUSTER_CHANNEL_INUSE);
-        break;
-
-      } else {
-        c->read_cluster_vc->current_cont = c;
-      }
-      ink_release_assert(c->read_cluster_vc != CLUSTER_DELAYED_OPEN);
 
       CacheKey key(msg->md5);
 
-      char *hostname = NULL;
-      int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
-      if (host_len) {
-        hostname = (char *) msg->moi.byte;
+      int flen = op_to_sizeof_fixedlen_msg(opcode);
+      c->ic_hostname_len = len - flen;
+      if (c->ic_hostname_len) {
+        c->ic_hostname = (char *) msg + flen;
       }
 
+      SET_CONTINUATION_HANDLER(c, (CacheContHandler)
+                                           & CacheContinuation::setupVCdataWrite);
       Cache *call_cache = caches[c->frag_type];
       Action *a = call_cache->open_write(c, &key, c->frag_type,
                                          !!(c->cfl_flags & CFL_OVERWRITE_ON_WRITE),
-                                         c->pin_in_cache, hostname, host_len);
+                                         c->pin_in_cache, c->ic_hostname, c->ic_hostname_len);
       if (a != ACTION_RESULT_DONE) {
-        c->cache_action = a;
+        c->pending_action = a;
       }
       break;
     }
   case CACHE_OPEN_WRITE_LONG:
     {
       // Cache needs message data, copy it.
-      c->setMsgBufferLen(len);
-      c->allocMsgBuffer();
-      memcpy(c->getMsgBuffer(), (char *) data, len);
+//      c->setMsgBufferLen(len);
+//      c->allocMsgBuffer();
+//      memcpy(c->getMsgBuffer(), (char *) data, len);
 
       int flen = CacheOpMsg_long::sizeof_fixedlen_msg();
       CacheOpMsg_long *msg = unmarshal_CacheOpMsg_long(c->getMsgBuffer(), mh->NeedByteSwap());
-      init_from_long(c, msg, ch->machine);
+      init_from_long(c, msg);
       Debug("cache_msg",
-            "cache_op-l op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+            "cache_op-l op=%d seqno=%d data=%p len=%d", opcode, c->seq_number, data, len);
 #ifdef CACHE_MSG_TRACE
       log_cache_op_msg(msg->seq_number, len, "cache_op_open_write_long");
 #endif
-      //
-      // Establish the remote side of the ClusterVConnection
-      //
-      c->read_cluster_vc = clusterProcessor.connect_local((Continuation *) 0,
-                                                          &c->token,
-                                                          c->cluster_vc_channel,
-                                                          (CLUSTER_OPT_IMMEDIATE | CLUSTER_OPT_CONN_WRITE));
-      if (!c->read_cluster_vc) {
-        // Unable to setup channel, abort processing.
-        CLUSTER_INCREMENT_DYN_STAT(CLUSTER_CHAN_INUSE_STAT);
-        Debug("chan_inuse",
-              "4Remote chan=%d inuse tok.ip=%u.%u.%u.%u tok.seqno=%d seqno=%d",
-              c->cluster_vc_channel, DOT_SEPARATED(c->token.ip_created), c->token.sequence_number, c->seq_number);
-
-        // Send cluster op failed reply
-        c->replyOpEvent(CACHE_EVENT_OPEN_WRITE_FAILED, (VConnection *) - ECLUSTER_CHANNEL_INUSE);
-        break;
-
-      } else {
-        c->read_cluster_vc->current_cont = c;
-      }
-      ink_release_assert(c->read_cluster_vc != CLUSTER_DELAYED_OPEN);
 
       CacheHTTPInfo *ci = 0;
-      const char *p = (const char *) msg + flen;
+      const char *p;
       int res = 0;
       int moi_len = len - flen;
 
-      if (moi_len && c->cfl_flags & CFL_LOPENWRITE_HAVE_OLDINFO) {
-
+      if (moi_len && (c->cfl_flags & CFL_LOPENWRITE_HAVE_OLDINFO)) {
+        p = (const char *) msg + flen;
         // Unmarshal old CacheHTTPInfo
         res = HTTPInfo::unmarshal((char *) p, moi_len, NULL);
         ink_assert(res > 0);
         c->ic_old_info.get_handle((char *) p, moi_len);
         ink_assert(c->ic_old_info.valid());
         ci = &c->ic_old_info;
+      } else {
+        p = (const char *) 0;
       }
       if (c->cfl_flags & CFL_ALLOW_MULTIPLE_WRITES) {
         ink_assert(!ci);
@@ -1358,53 +1859,60 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
       p += res;
 
       CacheKey key(msg->url_md5);
-      char *hostname = NULL;
 
       if (moi_len) {
-        hostname = (char *) p;
+        c->ic_hostname = (char *) p;
+        c->ic_hostname_len = moi_len;
       }
 
+      SET_CONTINUATION_HANDLER(c, (CacheContHandler)
+                                                 & CacheContinuation::setupVCdataWrite);
+
       Cache *call_cache = caches[c->frag_type];
       Action *a = call_cache->open_write(c, &key, ci, c->pin_in_cache,
-                                         NULL, c->frag_type, hostname, moi_len);
+                                         NULL, c->frag_type, c->ic_hostname, c->ic_hostname_len);
       if (a != ACTION_RESULT_DONE) {
-        c->cache_action = a;
+        c->pending_action = a;
       }
       break;
     }
   case CACHE_REMOVE:
     {
       CacheOpMsg_short *msg = unmarshal_CacheOpMsg_short(data, mh->NeedByteSwap());
-      init_from_short(c, msg, ch->machine);
+      init_from_short(c, msg);
       Debug("cache_msg",
-            "cache_op op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+            "cache_op op=%d seqno=%d data=%p len=%d", opcode, c->seq_number, data, len);
 #ifdef CACHE_MSG_TRACE
       log_cache_op_msg(msg->seq_number, len, "cache_op_remove");
 #endif
       CacheKey key(msg->md5);
 
-      char *hostname = NULL;
-      int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
+      int flen = op_to_sizeof_fixedlen_msg(opcode);
+      int host_len = len - flen;
       if (host_len) {
-        hostname = (char *) msg->moi.byte;
+        c->ic_hostname = (char *) msg + flen;
+        c->ic_hostname_len = host_len;
       }
 
+      SET_CONTINUATION_HANDLER(c, (CacheContHandler)
+                                                       & CacheContinuation::setupVCdataRemove);
+
       Cache *call_cache = caches[c->frag_type];
       Action *a = call_cache->remove(c, &key, c->frag_type,
                                      !!(c->cfl_flags & CFL_REMOVE_USER_AGENTS),
                                      !!(c->cfl_flags & CFL_REMOVE_LINK),
-                                     hostname, host_len);
+                                     c->ic_hostname, c->ic_hostname_len);
       if (a != ACTION_RESULT_DONE) {
-        c->cache_action = a;
+        c->pending_action = a;
       }
       break;
     }
   case CACHE_LINK:
     {
       CacheOpMsg_short_2 *msg = unmarshal_CacheOpMsg_short_2(data, mh->NeedByteSwap());
-      init_from_short_2(c, msg, ch->machine);
+      init_from_short_2(c, msg);
       Debug("cache_msg",
-            "cache_op op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+            "cache_op op=%d seqno=%d data=%p len=%d", opcode, c->seq_number, data, len);
 #ifdef CACHE_MSG_TRACE
       log_cache_op_msg(msg->seq_number, len, "cache_op_link");
 #endif
@@ -1412,364 +1920,671 @@ cache_op_ClusterFunction(ClusterHandler * ch, void *data, int len)
       CacheKey key1(msg->md5_1);
       CacheKey key2(msg->md5_2);
 
-      char *hostname = NULL;
-      int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
+      int flen = op_to_sizeof_fixedlen_msg(opcode);
+      int host_len = len - flen;
       if (host_len) {
-        hostname = (char *) msg->moi.byte;
+        c->ic_hostname = (char *) msg + flen;
+        c->ic_hostname_len = host_len;
       }
 
+      SET_CONTINUATION_HANDLER(c, (CacheContHandler)
+                                                       & CacheContinuation::setupVCdataLink);
+
       Cache *call_cache = caches[c->frag_type];
       Action *a = call_cache->link(c, &key1, &key2, c->frag_type,
-                                   hostname, host_len);
+                                   c->ic_hostname, c->ic_hostname_len);
       if (a != ACTION_RESULT_DONE) {
-        c->cache_action = a;
+        c->pending_action = a;
       }
       break;
     }
   case CACHE_DEREF:
     {
       CacheOpMsg_short *msg = unmarshal_CacheOpMsg_short(data, mh->NeedByteSwap());
-      init_from_short(c, msg, ch->machine);
+      init_from_short(c, msg);
       Debug("cache_msg",
-            "cache_op op=%d seqno=%d data=%p len=%d machine=%p", opcode, c->seq_number, data, len, ch->machine);
+            "cache_op op=%d seqno=%d data=%p len=%d", opcode, c->seq_number, data, len);
 #ifdef CACHE_MSG_TRACE
       log_cache_op_msg(msg->seq_number, len, "cache_op_deref");
 #endif
 
       CacheKey key(msg->md5);
 
-      char *hostname = NULL;
-      int host_len = len - op_to_sizeof_fixedlen_msg(opcode);
+      int flen = op_to_sizeof_fixedlen_msg(opcode);
+      int host_len = len - flen;
       if (host_len) {
-        hostname = (char *) msg->moi.byte;
+        c->ic_hostname = (char *) msg + flen;
+        c->ic_hostname_len = host_len;
       }
 
+      SET_CONTINUATION_HANDLER(c, (CacheContHandler)
+                                                       & CacheContinuation::setupVCdataDeref);
+
       Cache *call_cache = caches[c->frag_type];
       Action *a = call_cache->deref(c, &key, c->frag_type,
-                                    hostname, host_len);
+          c->ic_hostname, c->ic_hostname_len);
       if (a != ACTION_RESULT_DONE) {
-        c->cache_action = a;
+        c->pending_action = a;
       }
       break;
     }
 
   default:
     {
-      ink_release_assert(0);
+      ink_assert(0);
+      break;
     }
   }                             // End of switch
 }
-
 void
 cache_op_malloc_ClusterFunction(ClusterHandler *ch, void *data, int len)
 {
-  cache_op_ClusterFunction(ch, data, len);
-  // We own the message data, free it back to the Cluster subsystem
-  clusterProcessor.free_remote_data((char *) data, len);
+//  cache_op_ClusterFunction(ch, data, len);
+//  // We own the message data, free it back to the Cluster subsystem
+//  clusterProcessor.free_remote_data((char *) data, len);
+  (void) ch;
+  (void) data;
+  (void) len;
+  return;
 }
 
+//struct HeadData
+//{
+//  int32_t magic; // feedbabe
+//  int32_t h_len;
+//  int32_t d_len;
+//  uint32_t flags;
+//
+//  char *hdr() {
+//    return (char *)this + sizeof(HeadData);
+//  }
+//
+//  int32_t hdr_len() {
+//    return h_len;
+//  }
+//
+//  int32_t data_len() {
+//    return d_len;
+//  }
+//
+//  char *data() {
+//    return (char *)this + hdr_len + sizeof(HeadData);
+//  }
+//};
+
 int
-CacheContinuation::setupVCdataRead(int event, VConnection * vc)
+CacheContinuation::setupVCdataRead(int event, void *data)
 {
   ink_assert(magicno == (int) MagicNo);
   //
   // Setup the initial data read for the given Cache VC.
   // This data is sent back in the response message.
   //
+  if (event > CLUSTER_MSG_START && event <= CLUSTER_INTERNEL_ERROR) {
+    Debug("cache_proto", "replyOpEvent: freeing this=%p", this);
+    ink_assert(cluster_close_session(cs));
+    free_CacheCont(this);
+    return EVENT_DONE;
+  }
+
+  pending_action = NULL;
+  result = (event == CACHE_EVENT_OPEN_READ ? CACHE_EVENT_OPEN_READ : CACHE_EVENT_OPEN_READ_FAILED);
+
   if (event == CACHE_EVENT_OPEN_READ) {
     //////////////////////////////////////////
     // Allocate buffer and initiate read.
     //////////////////////////////////////////
     Debug("cache_proto", "setupVCdataRead CACHE_EVENT_OPEN_READ seqno=%d", seq_number);
-    ink_release_assert(c

<TRUNCATED>

Re: [1/4] refine cluster

Posted by James Peach <jp...@apache.org>.
On Nov 20, 2013, at 9:50 AM, James Peach <jp...@apache.org> wrote:

> This is a huge commit with
> 
> 	- no links back to the Jira ticket
> 	- no source code comments
> 	- no indication of the problem that it is solving or how it solves it
> 	- no performance comparison (I assume this for performance)
> 	- no documentation of the new configuration parameters
> 	- no indication of compatibility (is it really OK to the 4.x branch?)
> 	- no tests

Oh, I didn't notice that this was on a branch. Thanks, that's excellent!

> 
> Please, can we talk about the above issues?
> 
> On Nov 19, 2013, at 11:45 PM, weijin@apache.org wrote:
> 
>> Updated Branches:
>> refs/heads/refine_cluster [created] 7ffc10a9c
>> 
>> 
>> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/P_ClusterInline.h
>> ----------------------------------------------------------------------
>> diff --git a/iocore/cluster/P_ClusterInline.h b/iocore/cluster/P_ClusterInline.h
>> index c653956..1d26b3a 100644
>> --- a/iocore/cluster/P_ClusterInline.h
>> +++ b/iocore/cluster/P_ClusterInline.h
>> @@ -36,25 +36,30 @@ inline Action *
>> Cluster_lookup(Continuation * cont, CacheKey * key, CacheFragType frag_type, char *hostname, int host_len)
>> {
>>  // Try to send remote, if not possible, handle locally
>> -  Action *retAct;
>> -  ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
>> -  if (m && !clusterProcessor.disable_remote_cluster_ops(m)) {
>> -    CacheContinuation *cc = CacheContinuation::cacheContAllocator_alloc();
>> -    cc->action = cont;
>> -    cc->mutex = cont->mutex;
>> -    retAct = CacheContinuation::do_remote_lookup(cont, key, cc, frag_type, hostname, host_len);
>> -    if (retAct) {
>> -      return retAct;
>> -    } else {
>> -      // not remote, do local lookup
>> -      CacheContinuation::cacheContAllocator_free(cc);
>> -      return (Action *) NULL;
>> -    }
>> -  } else {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LOOKUP_FAILED, 0);
>> -  }
>> +//  Action *retAct;
>> +//  ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
>> +//  if (m && !clusterProcessor.disable_remote_cluster_ops(m)) {
>> +//    CacheContinuation *cc = CacheContinuation::cacheContAllocator_alloc();
>> +//    cc->action = cont;
>> +//    cc->mutex = cont->mutex;
>> +//    retAct = CacheContinuation::do_remote_lookup(cont, key, cc, frag_type, hostname, host_len);
>> +//    if (retAct) {
>> +//      return retAct;
>> +//    } else {
>> +//      // not remote, do local lookup
>> +//      CacheContinuation::cacheContAllocator_free(cc);
>> +//      return (Action *) NULL;
>> +//    }
>> +//  } else {
>> +//    Action a;
>> +//    a = cont;
>> +//    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LOOKUP_FAILED, 0);
>> +//  }
>> +  (void) cont;
>> +  (void) key;
>> +  (void) frag_type;
>> +  (void) hostname;
>> +  (void) host_len;
>>  return (Action *) NULL;
>> }
>> 
>> @@ -66,18 +71,24 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>>             time_t pin_in_cache, CacheFragType frag_type, char *hostname, int host_len)
>> {
>>  (void) params;
>> -  if (clusterProcessor.disable_remote_cluster_ops(owner_machine)) {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_READ_FAILED, 0);
>> +  ink_assert(cont);
>> +  ClusterSession session;
>> +  if (cluster_create_session(&session, owner_machine, NULL, 0)) {
>> +    cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, NULL);
>> +    return ACTION_RESULT_DONE;
>>  }
>> +
>>  int vers = CacheOpMsg_long::protoToVersion(owner_machine->msg_proto_major);
>> +  CacheOpArgs_General readArgs;
>> +  Ptr<IOBufferData> d;
>> +
>>  int flen;
>>  int len = 0;
>>  int cur_len;
>>  int res = 0;
>> -  char *msg;
>> +  char *msg = 0;
>>  char *data;
>> +  Action *action = NULL;
>> 
>>  if (vers == CacheOpMsg_long::CACHE_OP_LONG_MESSAGE_VERSION) {
>>    if ((opcode == CACHE_OPEN_READ_LONG)
>> @@ -87,20 +98,21 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>> 
>>      const char *url_hostname;
>>      int url_hlen;
>> -      INK_MD5 url_only_md5;
>> +      INK_MD5 url_md5;
>> 
>> -      Cache::generate_key(&url_only_md5, url, 0);
>> +      Cache::generate_key(&url_md5, url);
>>      url_hostname = url->host_get(&url_hlen);
>> 
>>      len += request->m_heap->marshal_length();
>> -      len += params->marshal_length();
>> +      len += sizeof(CacheLookupHttpConfig) + params->marshal_length();
>>      len += url_hlen;
>> 
>>      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)       // Bound marshalled data
>>        goto err_exit;
>> 
>>      // Perform data Marshal operation
>> -      msg = (char *) ALLOCA_DOUBLE(flen + len);
>> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +      msg = (char *) d->data();
>>      data = msg + flen;
>> 
>>      cur_len = len;
>> @@ -110,6 +122,13 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>>      }
>>      data += res;
>>      cur_len -= res;
>> +
>> +      if (cur_len < (int) sizeof(CacheLookupHttpConfig))
>> +        goto err_exit;
>> +      memcpy(data, params, sizeof(CacheLookupHttpConfig));
>> +      data += sizeof(CacheLookupHttpConfig);
>> +      cur_len -= sizeof(CacheLookupHttpConfig);
>> +
>>      if ((res = params->marshal(data, cur_len)) < 0)
>>        goto err_exit;
>>      data += res;
>> @@ -117,37 +136,33 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>>      memcpy(data, url_hostname, url_hlen);
>> 
>>      CacheOpArgs_General readArgs;
>> -      readArgs.url_md5 = &url_only_md5;
>> +      readArgs.url_md5 = &url_md5;
>>      readArgs.pin_in_cache = pin_in_cache;
>>      readArgs.frag_type = frag_type;
>> -      return CacheContinuation::do_op(cont, owner_machine, (void *) &readArgs,
>> -                                      opcode, (char *) msg, (flen + len), -1, buf);
>> +
>> +      action = CacheContinuation::do_op(cont, session, (void *) &readArgs,
>> +                                            opcode, d, (flen + len), -1, buf);
>>    } else {
>>      // Build message if we have host data.
>> +      flen = op_to_sizeof_fixedlen_msg(opcode);
>> +      len = host_len;
>> 
>> -      if (host_len) {
>> -        // Determine length of data to Marshal
>> -        flen = op_to_sizeof_fixedlen_msg(opcode);
>> -        len = host_len;
>> -
>> -        if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
>> -          goto err_exit;
>> +      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
>> +        goto err_exit;
>> 
>> -        msg = (char *) ALLOCA_DOUBLE(flen + len);
>> -        data = msg + flen;
>> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +      msg = (char *) d->data();
>> +      data = msg + flen;
>> +      if (host_len)
>>        memcpy(data, hostname, host_len);
>> 
>> -      } else {
>> -        msg = 0;
>> -        flen = 0;
>> -        len = 0;
>> -      }
>> -      CacheOpArgs_General readArgs;
>>      readArgs.url_md5 = key;
>>      readArgs.frag_type = frag_type;
>> -      return CacheContinuation::do_op(cont, owner_machine, (void *) &readArgs,
>> -                                      opcode, (char *) msg, (flen + len), -1, buf);
>> +
>> +      action = CacheContinuation::do_op(cont, session, (void *) &readArgs,
>> +                                            opcode, d, (flen + len), -1, buf);
>>    }
>> +    ink_assert(msg);
>> 
>>  } else {
>>    //////////////////////////////////////////////////////////////
>> @@ -155,10 +170,12 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>>    //////////////////////////////////////////////////////////////
>>    ink_release_assert(!"CacheOpMsg_long [read] bad msg version");
>>  }
>> +
>> +  if (action)
>> +    return action;
>> err_exit:
>> -  Action a;
>> -  a = cont;
>> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_READ_FAILED, 0);
>> +  cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, NULL);
>> +  return ACTION_RESULT_DONE;
>> }
>> 
>> inline Action *
>> @@ -171,10 +188,11 @@ Cluster_write(Continuation * cont, int expected_size,
>> {
>>  (void) key;
>>  (void) request;
>> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_WRITE_FAILED, 0);
>> +  ClusterSession session;
>> +  ink_assert(cont);
>> +  if (cluster_create_session(&session, m, NULL, 0)) {
>> +     cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, NULL);
>> +     return ACTION_RESULT_DONE;
>>  }
>>  char *msg = 0;
>>  char *data = 0;
>> @@ -182,24 +200,22 @@ Cluster_write(Continuation * cont, int expected_size,
>>  int len = 0;
>>  int flen = 0;
>>  int vers = CacheOpMsg_long::protoToVersion(m->msg_proto_major);
>> +  Ptr<IOBufferData> d;
>> 
>>  switch (opcode) {
>>  case CACHE_OPEN_WRITE:
>>    {
>>      // Build message if we have host data
>> -      if (host_len) {
>> -        // Determine length of data to Marshal
>> -        flen = op_to_sizeof_fixedlen_msg(CACHE_OPEN_WRITE);
>> -        len = host_len;
>> -
>> -        if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
>> -          goto err_exit;
>> -
>> -        msg = (char *) ALLOCA_DOUBLE(flen + len);
>> -        data = msg + flen;
>> +      len = host_len;
>> +      flen = op_to_sizeof_fixedlen_msg(CACHE_OPEN_WRITE);
>> +      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
>> +        goto err_exit;
>> 
>> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +      msg = (char *) d->data();
>> +      data = msg + flen;
>> +      if (host_len)
>>        memcpy(data, hostname, host_len);
>> -      }
>>      break;
>>    }
>>  case CACHE_OPEN_WRITE_LONG:
>> @@ -223,8 +239,9 @@ Cluster_write(Continuation * cont, int expected_size,
>>      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)       // Bound marshalled data
>>        goto err_exit;
>> 
>> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +      msg = (char *) d->data();
>>      // Perform data Marshal operation
>> -      msg = (char *) ALLOCA_DOUBLE(flen + len);
>>      data = msg + flen;
>>      int res = 0;
>> 
>> @@ -257,7 +274,9 @@ Cluster_write(Continuation * cont, int expected_size,
>>    writeArgs.cfl_flags |= (old_info ? CFL_LOPENWRITE_HAVE_OLDINFO : 0);
>>    writeArgs.cfl_flags |= (allow_multiple_writes ? CFL_ALLOW_MULTIPLE_WRITES : 0);
>> 
>> -    return CacheContinuation::do_op(cont, m, (void *) &writeArgs, opcode, msg, flen + len, expected_size, buf);
>> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &writeArgs, opcode, d, flen + len, expected_size, buf);
>> +    if (action)
>> +      return action;
>>  } else {
>>    //////////////////////////////////////////////////////////////
>>    // Create the specified down rev version of this message
>> @@ -267,19 +286,21 @@ Cluster_write(Continuation * cont, int expected_size,
>>  }
>> 
>> err_exit:
>> -  Action a;
>> -  a = cont;
>> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_WRITE_FAILED, 0);
>> +  cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, NULL);
>> +  return ACTION_RESULT_DONE;
>> }
>> 
>> inline Action *
>> Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey * to,
>>             CacheFragType type, char *hostname, int host_len)
>> {
>> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LINK_FAILED, 0);
>> +  ClusterSession session;
>> +  Ptr<IOBufferData> d;
>> +  char *msg = NULL;
>> +
>> +  if (cluster_create_session(&session, m, NULL, 0)) {
>> +    cont->handleEvent(CACHE_EVENT_LINK_FAILED, NULL);
>> +    return ACTION_RESULT_DONE;
>>  }
>> 
>>  int vers = CacheOpMsg_short_2::protoToVersion(m->msg_proto_major);
>> @@ -293,7 +314,8 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>>    if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>>      goto err_exit;
>> 
>> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
>> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +    msg = (char *) d->data();
>>    memcpy((msg + flen), hostname, host_len);
>> 
>>    // Setup args for remote link
>> @@ -301,7 +323,9 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>>    linkArgs.from = from;
>>    linkArgs.to = to;
>>    linkArgs.frag_type = type;
>> -    return CacheContinuation::do_op(cont, m, (void *) &linkArgs, CACHE_LINK, msg, (flen + len));
>> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &linkArgs, CACHE_LINK, d, (flen + len));
>> +    if (action)
>> +      return action;
>>  } else {
>>    //////////////////////////////////////////////////////////////
>>    // Create the specified down rev version of this message
>> @@ -311,18 +335,20 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>>  }
>> 
>> err_exit:
>> -  Action a;
>> -  a = cont;
>> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_LINK_FAILED, 0);
>> +  cont->handleEvent(CACHE_EVENT_LINK_FAILED, NULL);
>> +  return ACTION_RESULT_DONE;
>> }
>> 
>> inline Action *
>> Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFragType type, char *hostname, int host_len)
>> {
>> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_DEREF_FAILED, 0);
>> +  ClusterSession session;
>> +  Ptr<IOBufferData> d;
>> +  char *msg = NULL;
>> +
>> +  if (cluster_create_session(&session, m, NULL, 0)) {
>> +    cont->handleEvent(CACHE_EVENT_DEREF_FAILED, NULL);
>> +    return ACTION_RESULT_DONE ;
>>  }
>> 
>>  int vers = CacheOpMsg_short::protoToVersion(m->msg_proto_major);
>> @@ -336,14 +362,17 @@ Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFrag
>>    if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>>      goto err_exit;
>> 
>> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
>> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +    msg = (char *) d->data();
>>    memcpy((msg + flen), hostname, host_len);
>> 
>>    // Setup args for remote deref
>>    CacheOpArgs_Deref drefArgs;
>>    drefArgs.md5 = key;
>>    drefArgs.frag_type = type;
>> -    return CacheContinuation::do_op(cont, m, (void *) &drefArgs, CACHE_DEREF, msg, (flen + len));
>> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &drefArgs, CACHE_DEREF, d, (flen + len));
>> +    if (action)
>> +      return action;
>>  } else {
>>    //////////////////////////////////////////////////////////////
>>    // Create the specified down rev version of this message
>> @@ -353,19 +382,22 @@ Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFrag
>>  }
>> 
>> err_exit:
>> -  Action a;
>> -  a = cont;
>> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_DEREF_FAILED, 0);
>> +  cont->handleEvent(CACHE_EVENT_DEREF_FAILED, NULL);
>> +  return ACTION_RESULT_DONE ;
>> }
>> 
>> inline Action *
>> Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>>               bool rm_user_agents, bool rm_link, CacheFragType frag_type, char *hostname, int host_len)
>> {
>> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_REMOVE_FAILED, 0);
>> +  ClusterSession session;
>> +  Ptr<IOBufferData> d;
>> +  char *msg = NULL;
>> +
>> +  if (cluster_create_session(&session, m, NULL, 0)) {
>> +    if (cont)
>> +      cont->handleEvent(CACHE_EVENT_REMOVE_FAILED, NULL);
>> +    return ACTION_RESULT_DONE;
>>  }
>> 
>>  int vers = CacheOpMsg_short::protoToVersion(m->msg_proto_major);
>> @@ -379,7 +411,8 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>>    if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>>      goto err_exit;
>> 
>> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
>> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +    msg = (char *) d->data();
>>    memcpy((msg + flen), hostname, host_len);
>> 
>>    // Setup args for remote update
>> @@ -388,7 +421,9 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>>    updateArgs.cfl_flags |= (rm_user_agents ? CFL_REMOVE_USER_AGENTS : 0);
>>    updateArgs.cfl_flags |= (rm_link ? CFL_REMOVE_LINK : 0);
>>    updateArgs.frag_type = frag_type;
>> -    return CacheContinuation::do_op(cont, m, (void *) &updateArgs, CACHE_REMOVE, msg, (flen + len));
>> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &updateArgs, CACHE_REMOVE, d, (flen + len));
>> +    if (action)
>> +      return action;
>>  } else {
>>    //////////////////////////////////////////////////////////////
>>    // Create the specified down rev version of this message
>> @@ -398,9 +433,8 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>>  }
>> 
>> err_exit:
>> -  Action a;
>> -  a = cont;
>> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_REMOVE_FAILED, 0);
>> +  if (cont)
>> +    cont->handleEvent(CACHE_EVENT_REMOVE_FAILED, NULL);
>> +  return ACTION_RESULT_DONE;
>> }
>> -
>> #endif /* __CLUSTERINLINE_H__ */
>> 
>> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/eventsystem/I_Event.h
>> ----------------------------------------------------------------------
>> diff --git a/iocore/eventsystem/I_Event.h b/iocore/eventsystem/I_Event.h
>> index 7a37ea0..2659131 100644
>> --- a/iocore/eventsystem/I_Event.h
>> +++ b/iocore/eventsystem/I_Event.h
>> @@ -85,6 +85,7 @@
>> #define BLOCK_CACHE_EVENT_EVENTS_START            4000
>> #define UTILS_EVENT_EVENTS_START                  5000
>> #define CONGESTION_EVENT_EVENTS_START             5100
>> +#define CLUSTER_MSG_START                         6000
>> #define INK_API_EVENT_EVENTS_START                60000
>> #define SRV_EVENT_EVENTS_START	                  62000
>> #define REMAP_EVENT_EVENTS_START                  63000
>> 
>> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/eventsystem/P_IOBuffer.h
>> ----------------------------------------------------------------------
>> diff --git a/iocore/eventsystem/P_IOBuffer.h b/iocore/eventsystem/P_IOBuffer.h
>> index 0842aff..261aa1f 100644
>> --- a/iocore/eventsystem/P_IOBuffer.h
>> +++ b/iocore/eventsystem/P_IOBuffer.h
>> @@ -203,7 +203,7 @@ new_IOBufferData_internal(
>>                           void *b, int64_t size, int64_t asize_index)
>> {
>>  (void) size;
>> -  IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread());
>> +  IOBufferData *d = ioDataAllocator.alloc();
>>  d->_size_index = asize_index;
>>  ink_assert(BUFFER_SIZE_INDEX_IS_CONSTANT(asize_index)
>>             || size <= d->block_size());
>> @@ -263,7 +263,7 @@ new_IOBufferData_internal(
>> #endif
>>                           int64_t size_index, AllocType type)
>> {
>> -  IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread());
>> +  IOBufferData *d = ioDataAllocator.alloc();
>> #ifdef TRACK_BUFFER_USER
>>  d->_location = loc;
>> #endif
>> @@ -336,7 +336,7 @@ TS_INLINE void
>> IOBufferData::free()
>> {
>>  dealloc();
>> -  THREAD_FREE(this, ioDataAllocator, this_ethread());
>> +  ioDataAllocator.free(this);
>> }
>> 
>> //////////////////////////////////////////////////////////////////
>> @@ -352,7 +352,7 @@ new_IOBufferBlock_internal(
>> #endif
>>  )
>> {
>> -  IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread());
>> +  IOBufferBlock *b = ioBlockAllocator.alloc();
>> #ifdef TRACK_BUFFER_USER
>>  b->_location = location;
>> #endif
>> @@ -366,7 +366,7 @@ new_IOBufferBlock_internal(
>> #endif
>>                            IOBufferData * d, int64_t len, int64_t offset)
>> {
>> -  IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread());
>> +  IOBufferBlock *b = ioBlockAllocator.alloc();
>> #ifdef TRACK_BUFFER_USER
>>  b->_location = location;
>> #endif
>> @@ -468,7 +468,7 @@ TS_INLINE void
>> IOBufferBlock::free()
>> {
>>  dealloc();
>> -  THREAD_FREE(this, ioBlockAllocator, this_ethread());
>> +  ioBlockAllocator.free(this);
>> }
>> 
>> TS_INLINE void
>> @@ -777,7 +777,7 @@ TS_INLINE MIOBuffer * new_MIOBuffer_internal(
>> #endif
>>                                               int64_t size_index)
>> {
>> -  MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread());
>> +  MIOBuffer *b = ioAllocator.alloc();
>> #ifdef TRACK_BUFFER_USER
>>  b->_location = location;
>> #endif
>> @@ -790,7 +790,7 @@ free_MIOBuffer(MIOBuffer * mio)
>> {
>>  mio->_writer = NULL;
>>  mio->dealloc_all_readers();
>> -  THREAD_FREE(mio, ioAllocator, this_ethread());
>> +  ioAllocator.free(mio);
>> }
>> 
>> TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
>> @@ -799,7 +799,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
>> #endif
>>                                                     int64_t size_index)
>> {
>> -  MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread());
>> +  MIOBuffer *b = ioAllocator.alloc();
>>  b->size_index = size_index;
>> #ifdef TRACK_BUFFER_USER
>>  b->_location = location;
>> @@ -810,7 +810,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
>> TS_INLINE void
>> free_empty_MIOBuffer(MIOBuffer * mio)
>> {
>> -  THREAD_FREE(mio, ioAllocator, this_ethread());
>> +  ioAllocator.free(mio);
>> }
>> 
>> TS_INLINE IOBufferReader *
>> 
>> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/mgmt/RecordsConfig.cc
>> ----------------------------------------------------------------------
>> diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
>> index 4a73f19..7677471 100644
>> --- a/mgmt/RecordsConfig.cc
>> +++ b/mgmt/RecordsConfig.cc
>> @@ -814,6 +814,24 @@ RecordElement RecordsConfig[] = {
>>  ,
>>  {RECT_CONFIG, "proxy.config.cluster.cluster_port", RECD_INT, "8086", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>>  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_bps", RECD_INT, "804857600", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_bps", RECD_INT, "4194304000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_send_wait_time", RECD_INT, "1000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_send_wait_time", RECD_INT, "5000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_loop_interval", RECD_INT, "0", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_loop_interval", RECD_INT, "1000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.max_sessions_per_machine", RECD_INT, "1000000", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1000-4000000]", RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.session_locks_per_machine", RECD_INT, "10949", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1-100000]", RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.read_buffer_size", RECD_INT, "2097152", RECU_RESTART_TS, RR_NULL, RECC_INT, "[65536-2097152]", RECA_NULL}
>> +  ,
>>  {RECT_CONFIG, "proxy.config.cluster.cluster_configuration", RECD_STRING, "cluster.config", RECU_NULL, RR_NULL, RECC_NULL, NULL, RECA_NULL}
>>  ,
>>  {RECT_CONFIG, "proxy.config.cluster.ethernet_interface", RECD_STRING, TS_BUILD_DEFAULT_LOOPBACK_IFACE, RECU_RESTART_TS, RR_REQUIRED, RECC_STR, "^[^[:space:]]*$", RECA_NULL}
>> 
> 


Re: [1/4] refine cluster

Posted by James Peach <jp...@apache.org>.
On Nov 20, 2013, at 9:50 AM, James Peach <jp...@apache.org> wrote:

> This is a huge commit with
> 
> 	- no links back to the Jira ticket
> 	- no source code comments
> 	- no indication of the problem that it is solving or how it solves it
> 	- no performance comparison (I assume this for performance)
> 	- no documentation of the new configuration parameters
> 	- no indication of compatibility (is it really OK to the 4.x branch?)
> 	- no tests

Oh, I didn't notice that this was on a branch. Thanks, that's excellent!

> 
> Please, can we talk about the above issues?
> 
> On Nov 19, 2013, at 11:45 PM, weijin@apache.org wrote:
> 
>> Updated Branches:
>> refs/heads/refine_cluster [created] 7ffc10a9c
>> 
>> 
>> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/P_ClusterInline.h
>> ----------------------------------------------------------------------
>> diff --git a/iocore/cluster/P_ClusterInline.h b/iocore/cluster/P_ClusterInline.h
>> index c653956..1d26b3a 100644
>> --- a/iocore/cluster/P_ClusterInline.h
>> +++ b/iocore/cluster/P_ClusterInline.h
>> @@ -36,25 +36,30 @@ inline Action *
>> Cluster_lookup(Continuation * cont, CacheKey * key, CacheFragType frag_type, char *hostname, int host_len)
>> {
>>  // Try to send remote, if not possible, handle locally
>> -  Action *retAct;
>> -  ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
>> -  if (m && !clusterProcessor.disable_remote_cluster_ops(m)) {
>> -    CacheContinuation *cc = CacheContinuation::cacheContAllocator_alloc();
>> -    cc->action = cont;
>> -    cc->mutex = cont->mutex;
>> -    retAct = CacheContinuation::do_remote_lookup(cont, key, cc, frag_type, hostname, host_len);
>> -    if (retAct) {
>> -      return retAct;
>> -    } else {
>> -      // not remote, do local lookup
>> -      CacheContinuation::cacheContAllocator_free(cc);
>> -      return (Action *) NULL;
>> -    }
>> -  } else {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LOOKUP_FAILED, 0);
>> -  }
>> +//  Action *retAct;
>> +//  ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
>> +//  if (m && !clusterProcessor.disable_remote_cluster_ops(m)) {
>> +//    CacheContinuation *cc = CacheContinuation::cacheContAllocator_alloc();
>> +//    cc->action = cont;
>> +//    cc->mutex = cont->mutex;
>> +//    retAct = CacheContinuation::do_remote_lookup(cont, key, cc, frag_type, hostname, host_len);
>> +//    if (retAct) {
>> +//      return retAct;
>> +//    } else {
>> +//      // not remote, do local lookup
>> +//      CacheContinuation::cacheContAllocator_free(cc);
>> +//      return (Action *) NULL;
>> +//    }
>> +//  } else {
>> +//    Action a;
>> +//    a = cont;
>> +//    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LOOKUP_FAILED, 0);
>> +//  }
>> +  (void) cont;
>> +  (void) key;
>> +  (void) frag_type;
>> +  (void) hostname;
>> +  (void) host_len;
>>  return (Action *) NULL;
>> }
>> 
>> @@ -66,18 +71,24 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>>             time_t pin_in_cache, CacheFragType frag_type, char *hostname, int host_len)
>> {
>>  (void) params;
>> -  if (clusterProcessor.disable_remote_cluster_ops(owner_machine)) {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_READ_FAILED, 0);
>> +  ink_assert(cont);
>> +  ClusterSession session;
>> +  if (cluster_create_session(&session, owner_machine, NULL, 0)) {
>> +    cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, NULL);
>> +    return ACTION_RESULT_DONE;
>>  }
>> +
>>  int vers = CacheOpMsg_long::protoToVersion(owner_machine->msg_proto_major);
>> +  CacheOpArgs_General readArgs;
>> +  Ptr<IOBufferData> d;
>> +
>>  int flen;
>>  int len = 0;
>>  int cur_len;
>>  int res = 0;
>> -  char *msg;
>> +  char *msg = 0;
>>  char *data;
>> +  Action *action = NULL;
>> 
>>  if (vers == CacheOpMsg_long::CACHE_OP_LONG_MESSAGE_VERSION) {
>>    if ((opcode == CACHE_OPEN_READ_LONG)
>> @@ -87,20 +98,21 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>> 
>>      const char *url_hostname;
>>      int url_hlen;
>> -      INK_MD5 url_only_md5;
>> +      INK_MD5 url_md5;
>> 
>> -      Cache::generate_key(&url_only_md5, url, 0);
>> +      Cache::generate_key(&url_md5, url);
>>      url_hostname = url->host_get(&url_hlen);
>> 
>>      len += request->m_heap->marshal_length();
>> -      len += params->marshal_length();
>> +      len += sizeof(CacheLookupHttpConfig) + params->marshal_length();
>>      len += url_hlen;
>> 
>>      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)       // Bound marshalled data
>>        goto err_exit;
>> 
>>      // Perform data Marshal operation
>> -      msg = (char *) ALLOCA_DOUBLE(flen + len);
>> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +      msg = (char *) d->data();
>>      data = msg + flen;
>> 
>>      cur_len = len;
>> @@ -110,6 +122,13 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>>      }
>>      data += res;
>>      cur_len -= res;
>> +
>> +      if (cur_len < (int) sizeof(CacheLookupHttpConfig))
>> +        goto err_exit;
>> +      memcpy(data, params, sizeof(CacheLookupHttpConfig));
>> +      data += sizeof(CacheLookupHttpConfig);
>> +      cur_len -= sizeof(CacheLookupHttpConfig);
>> +
>>      if ((res = params->marshal(data, cur_len)) < 0)
>>        goto err_exit;
>>      data += res;
>> @@ -117,37 +136,33 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>>      memcpy(data, url_hostname, url_hlen);
>> 
>>      CacheOpArgs_General readArgs;
>> -      readArgs.url_md5 = &url_only_md5;
>> +      readArgs.url_md5 = &url_md5;
>>      readArgs.pin_in_cache = pin_in_cache;
>>      readArgs.frag_type = frag_type;
>> -      return CacheContinuation::do_op(cont, owner_machine, (void *) &readArgs,
>> -                                      opcode, (char *) msg, (flen + len), -1, buf);
>> +
>> +      action = CacheContinuation::do_op(cont, session, (void *) &readArgs,
>> +                                            opcode, d, (flen + len), -1, buf);
>>    } else {
>>      // Build message if we have host data.
>> +      flen = op_to_sizeof_fixedlen_msg(opcode);
>> +      len = host_len;
>> 
>> -      if (host_len) {
>> -        // Determine length of data to Marshal
>> -        flen = op_to_sizeof_fixedlen_msg(opcode);
>> -        len = host_len;
>> -
>> -        if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
>> -          goto err_exit;
>> +      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
>> +        goto err_exit;
>> 
>> -        msg = (char *) ALLOCA_DOUBLE(flen + len);
>> -        data = msg + flen;
>> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +      msg = (char *) d->data();
>> +      data = msg + flen;
>> +      if (host_len)
>>        memcpy(data, hostname, host_len);
>> 
>> -      } else {
>> -        msg = 0;
>> -        flen = 0;
>> -        len = 0;
>> -      }
>> -      CacheOpArgs_General readArgs;
>>      readArgs.url_md5 = key;
>>      readArgs.frag_type = frag_type;
>> -      return CacheContinuation::do_op(cont, owner_machine, (void *) &readArgs,
>> -                                      opcode, (char *) msg, (flen + len), -1, buf);
>> +
>> +      action = CacheContinuation::do_op(cont, session, (void *) &readArgs,
>> +                                            opcode, d, (flen + len), -1, buf);
>>    }
>> +    ink_assert(msg);
>> 
>>  } else {
>>    //////////////////////////////////////////////////////////////
>> @@ -155,10 +170,12 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>>    //////////////////////////////////////////////////////////////
>>    ink_release_assert(!"CacheOpMsg_long [read] bad msg version");
>>  }
>> +
>> +  if (action)
>> +    return action;
>> err_exit:
>> -  Action a;
>> -  a = cont;
>> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_READ_FAILED, 0);
>> +  cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, NULL);
>> +  return ACTION_RESULT_DONE;
>> }
>> 
>> inline Action *
>> @@ -171,10 +188,11 @@ Cluster_write(Continuation * cont, int expected_size,
>> {
>>  (void) key;
>>  (void) request;
>> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_WRITE_FAILED, 0);
>> +  ClusterSession session;
>> +  ink_assert(cont);
>> +  if (cluster_create_session(&session, m, NULL, 0)) {
>> +     cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, NULL);
>> +     return ACTION_RESULT_DONE;
>>  }
>>  char *msg = 0;
>>  char *data = 0;
>> @@ -182,24 +200,22 @@ Cluster_write(Continuation * cont, int expected_size,
>>  int len = 0;
>>  int flen = 0;
>>  int vers = CacheOpMsg_long::protoToVersion(m->msg_proto_major);
>> +  Ptr<IOBufferData> d;
>> 
>>  switch (opcode) {
>>  case CACHE_OPEN_WRITE:
>>    {
>>      // Build message if we have host data
>> -      if (host_len) {
>> -        // Determine length of data to Marshal
>> -        flen = op_to_sizeof_fixedlen_msg(CACHE_OPEN_WRITE);
>> -        len = host_len;
>> -
>> -        if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
>> -          goto err_exit;
>> -
>> -        msg = (char *) ALLOCA_DOUBLE(flen + len);
>> -        data = msg + flen;
>> +      len = host_len;
>> +      flen = op_to_sizeof_fixedlen_msg(CACHE_OPEN_WRITE);
>> +      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
>> +        goto err_exit;
>> 
>> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +      msg = (char *) d->data();
>> +      data = msg + flen;
>> +      if (host_len)
>>        memcpy(data, hostname, host_len);
>> -      }
>>      break;
>>    }
>>  case CACHE_OPEN_WRITE_LONG:
>> @@ -223,8 +239,9 @@ Cluster_write(Continuation * cont, int expected_size,
>>      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)       // Bound marshalled data
>>        goto err_exit;
>> 
>> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +      msg = (char *) d->data();
>>      // Perform data Marshal operation
>> -      msg = (char *) ALLOCA_DOUBLE(flen + len);
>>      data = msg + flen;
>>      int res = 0;
>> 
>> @@ -257,7 +274,9 @@ Cluster_write(Continuation * cont, int expected_size,
>>    writeArgs.cfl_flags |= (old_info ? CFL_LOPENWRITE_HAVE_OLDINFO : 0);
>>    writeArgs.cfl_flags |= (allow_multiple_writes ? CFL_ALLOW_MULTIPLE_WRITES : 0);
>> 
>> -    return CacheContinuation::do_op(cont, m, (void *) &writeArgs, opcode, msg, flen + len, expected_size, buf);
>> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &writeArgs, opcode, d, flen + len, expected_size, buf);
>> +    if (action)
>> +      return action;
>>  } else {
>>    //////////////////////////////////////////////////////////////
>>    // Create the specified down rev version of this message
>> @@ -267,19 +286,21 @@ Cluster_write(Continuation * cont, int expected_size,
>>  }
>> 
>> err_exit:
>> -  Action a;
>> -  a = cont;
>> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_WRITE_FAILED, 0);
>> +  cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, NULL);
>> +  return ACTION_RESULT_DONE;
>> }
>> 
>> inline Action *
>> Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey * to,
>>             CacheFragType type, char *hostname, int host_len)
>> {
>> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LINK_FAILED, 0);
>> +  ClusterSession session;
>> +  Ptr<IOBufferData> d;
>> +  char *msg = NULL;
>> +
>> +  if (cluster_create_session(&session, m, NULL, 0)) {
>> +    cont->handleEvent(CACHE_EVENT_LINK_FAILED, NULL);
>> +    return ACTION_RESULT_DONE;
>>  }
>> 
>>  int vers = CacheOpMsg_short_2::protoToVersion(m->msg_proto_major);
>> @@ -293,7 +314,8 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>>    if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>>      goto err_exit;
>> 
>> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
>> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +    msg = (char *) d->data();
>>    memcpy((msg + flen), hostname, host_len);
>> 
>>    // Setup args for remote link
>> @@ -301,7 +323,9 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>>    linkArgs.from = from;
>>    linkArgs.to = to;
>>    linkArgs.frag_type = type;
>> -    return CacheContinuation::do_op(cont, m, (void *) &linkArgs, CACHE_LINK, msg, (flen + len));
>> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &linkArgs, CACHE_LINK, d, (flen + len));
>> +    if (action)
>> +      return action;
>>  } else {
>>    //////////////////////////////////////////////////////////////
>>    // Create the specified down rev version of this message
>> @@ -311,18 +335,20 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>>  }
>> 
>> err_exit:
>> -  Action a;
>> -  a = cont;
>> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_LINK_FAILED, 0);
>> +  cont->handleEvent(CACHE_EVENT_LINK_FAILED, NULL);
>> +  return ACTION_RESULT_DONE;
>> }
>> 
>> inline Action *
>> Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFragType type, char *hostname, int host_len)
>> {
>> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_DEREF_FAILED, 0);
>> +  ClusterSession session;
>> +  Ptr<IOBufferData> d;
>> +  char *msg = NULL;
>> +
>> +  if (cluster_create_session(&session, m, NULL, 0)) {
>> +    cont->handleEvent(CACHE_EVENT_DEREF_FAILED, NULL);
>> +    return ACTION_RESULT_DONE ;
>>  }
>> 
>>  int vers = CacheOpMsg_short::protoToVersion(m->msg_proto_major);
>> @@ -336,14 +362,17 @@ Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFrag
>>    if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>>      goto err_exit;
>> 
>> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
>> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +    msg = (char *) d->data();
>>    memcpy((msg + flen), hostname, host_len);
>> 
>>    // Setup args for remote deref
>>    CacheOpArgs_Deref drefArgs;
>>    drefArgs.md5 = key;
>>    drefArgs.frag_type = type;
>> -    return CacheContinuation::do_op(cont, m, (void *) &drefArgs, CACHE_DEREF, msg, (flen + len));
>> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &drefArgs, CACHE_DEREF, d, (flen + len));
>> +    if (action)
>> +      return action;
>>  } else {
>>    //////////////////////////////////////////////////////////////
>>    // Create the specified down rev version of this message
>> @@ -353,19 +382,22 @@ Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFrag
>>  }
>> 
>> err_exit:
>> -  Action a;
>> -  a = cont;
>> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_DEREF_FAILED, 0);
>> +  cont->handleEvent(CACHE_EVENT_DEREF_FAILED, NULL);
>> +  return ACTION_RESULT_DONE ;
>> }
>> 
>> inline Action *
>> Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>>               bool rm_user_agents, bool rm_link, CacheFragType frag_type, char *hostname, int host_len)
>> {
>> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
>> -    Action a;
>> -    a = cont;
>> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_REMOVE_FAILED, 0);
>> +  ClusterSession session;
>> +  Ptr<IOBufferData> d;
>> +  char *msg = NULL;
>> +
>> +  if (cluster_create_session(&session, m, NULL, 0)) {
>> +    if (cont)
>> +      cont->handleEvent(CACHE_EVENT_REMOVE_FAILED, NULL);
>> +    return ACTION_RESULT_DONE;
>>  }
>> 
>>  int vers = CacheOpMsg_short::protoToVersion(m->msg_proto_major);
>> @@ -379,7 +411,8 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>>    if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>>      goto err_exit;
>> 
>> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
>> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
>> +    msg = (char *) d->data();
>>    memcpy((msg + flen), hostname, host_len);
>> 
>>    // Setup args for remote update
>> @@ -388,7 +421,9 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>>    updateArgs.cfl_flags |= (rm_user_agents ? CFL_REMOVE_USER_AGENTS : 0);
>>    updateArgs.cfl_flags |= (rm_link ? CFL_REMOVE_LINK : 0);
>>    updateArgs.frag_type = frag_type;
>> -    return CacheContinuation::do_op(cont, m, (void *) &updateArgs, CACHE_REMOVE, msg, (flen + len));
>> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &updateArgs, CACHE_REMOVE, d, (flen + len));
>> +    if (action)
>> +      return action;
>>  } else {
>>    //////////////////////////////////////////////////////////////
>>    // Create the specified down rev version of this message
>> @@ -398,9 +433,8 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>>  }
>> 
>> err_exit:
>> -  Action a;
>> -  a = cont;
>> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_REMOVE_FAILED, 0);
>> +  if (cont)
>> +    cont->handleEvent(CACHE_EVENT_REMOVE_FAILED, NULL);
>> +  return ACTION_RESULT_DONE;
>> }
>> -
>> #endif /* __CLUSTERINLINE_H__ */
>> 
>> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/eventsystem/I_Event.h
>> ----------------------------------------------------------------------
>> diff --git a/iocore/eventsystem/I_Event.h b/iocore/eventsystem/I_Event.h
>> index 7a37ea0..2659131 100644
>> --- a/iocore/eventsystem/I_Event.h
>> +++ b/iocore/eventsystem/I_Event.h
>> @@ -85,6 +85,7 @@
>> #define BLOCK_CACHE_EVENT_EVENTS_START            4000
>> #define UTILS_EVENT_EVENTS_START                  5000
>> #define CONGESTION_EVENT_EVENTS_START             5100
>> +#define CLUSTER_MSG_START                         6000
>> #define INK_API_EVENT_EVENTS_START                60000
>> #define SRV_EVENT_EVENTS_START	                  62000
>> #define REMAP_EVENT_EVENTS_START                  63000
>> 
>> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/eventsystem/P_IOBuffer.h
>> ----------------------------------------------------------------------
>> diff --git a/iocore/eventsystem/P_IOBuffer.h b/iocore/eventsystem/P_IOBuffer.h
>> index 0842aff..261aa1f 100644
>> --- a/iocore/eventsystem/P_IOBuffer.h
>> +++ b/iocore/eventsystem/P_IOBuffer.h
>> @@ -203,7 +203,7 @@ new_IOBufferData_internal(
>>                           void *b, int64_t size, int64_t asize_index)
>> {
>>  (void) size;
>> -  IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread());
>> +  IOBufferData *d = ioDataAllocator.alloc();
>>  d->_size_index = asize_index;
>>  ink_assert(BUFFER_SIZE_INDEX_IS_CONSTANT(asize_index)
>>             || size <= d->block_size());
>> @@ -263,7 +263,7 @@ new_IOBufferData_internal(
>> #endif
>>                           int64_t size_index, AllocType type)
>> {
>> -  IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread());
>> +  IOBufferData *d = ioDataAllocator.alloc();
>> #ifdef TRACK_BUFFER_USER
>>  d->_location = loc;
>> #endif
>> @@ -336,7 +336,7 @@ TS_INLINE void
>> IOBufferData::free()
>> {
>>  dealloc();
>> -  THREAD_FREE(this, ioDataAllocator, this_ethread());
>> +  ioDataAllocator.free(this);
>> }
>> 
>> //////////////////////////////////////////////////////////////////
>> @@ -352,7 +352,7 @@ new_IOBufferBlock_internal(
>> #endif
>>  )
>> {
>> -  IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread());
>> +  IOBufferBlock *b = ioBlockAllocator.alloc();
>> #ifdef TRACK_BUFFER_USER
>>  b->_location = location;
>> #endif
>> @@ -366,7 +366,7 @@ new_IOBufferBlock_internal(
>> #endif
>>                            IOBufferData * d, int64_t len, int64_t offset)
>> {
>> -  IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread());
>> +  IOBufferBlock *b = ioBlockAllocator.alloc();
>> #ifdef TRACK_BUFFER_USER
>>  b->_location = location;
>> #endif
>> @@ -468,7 +468,7 @@ TS_INLINE void
>> IOBufferBlock::free()
>> {
>>  dealloc();
>> -  THREAD_FREE(this, ioBlockAllocator, this_ethread());
>> +  ioBlockAllocator.free(this);
>> }
>> 
>> TS_INLINE void
>> @@ -777,7 +777,7 @@ TS_INLINE MIOBuffer * new_MIOBuffer_internal(
>> #endif
>>                                               int64_t size_index)
>> {
>> -  MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread());
>> +  MIOBuffer *b = ioAllocator.alloc();
>> #ifdef TRACK_BUFFER_USER
>>  b->_location = location;
>> #endif
>> @@ -790,7 +790,7 @@ free_MIOBuffer(MIOBuffer * mio)
>> {
>>  mio->_writer = NULL;
>>  mio->dealloc_all_readers();
>> -  THREAD_FREE(mio, ioAllocator, this_ethread());
>> +  ioAllocator.free(mio);
>> }
>> 
>> TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
>> @@ -799,7 +799,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
>> #endif
>>                                                     int64_t size_index)
>> {
>> -  MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread());
>> +  MIOBuffer *b = ioAllocator.alloc();
>>  b->size_index = size_index;
>> #ifdef TRACK_BUFFER_USER
>>  b->_location = location;
>> @@ -810,7 +810,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
>> TS_INLINE void
>> free_empty_MIOBuffer(MIOBuffer * mio)
>> {
>> -  THREAD_FREE(mio, ioAllocator, this_ethread());
>> +  ioAllocator.free(mio);
>> }
>> 
>> TS_INLINE IOBufferReader *
>> 
>> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/mgmt/RecordsConfig.cc
>> ----------------------------------------------------------------------
>> diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
>> index 4a73f19..7677471 100644
>> --- a/mgmt/RecordsConfig.cc
>> +++ b/mgmt/RecordsConfig.cc
>> @@ -814,6 +814,24 @@ RecordElement RecordsConfig[] = {
>>  ,
>>  {RECT_CONFIG, "proxy.config.cluster.cluster_port", RECD_INT, "8086", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>>  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_bps", RECD_INT, "804857600", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_bps", RECD_INT, "4194304000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_send_wait_time", RECD_INT, "1000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_send_wait_time", RECD_INT, "5000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_loop_interval", RECD_INT, "0", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_loop_interval", RECD_INT, "1000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.max_sessions_per_machine", RECD_INT, "1000000", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1000-4000000]", RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.session_locks_per_machine", RECD_INT, "10949", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1-100000]", RECA_NULL}
>> +  ,
>> +  {RECT_CONFIG, "proxy.config.cluster.read_buffer_size", RECD_INT, "2097152", RECU_RESTART_TS, RR_NULL, RECC_INT, "[65536-2097152]", RECA_NULL}
>> +  ,
>>  {RECT_CONFIG, "proxy.config.cluster.cluster_configuration", RECD_STRING, "cluster.config", RECU_NULL, RR_NULL, RECC_NULL, NULL, RECA_NULL}
>>  ,
>>  {RECT_CONFIG, "proxy.config.cluster.ethernet_interface", RECD_STRING, TS_BUILD_DEFAULT_LOOPBACK_IFACE, RECU_RESTART_TS, RR_REQUIRED, RECC_STR, "^[^[:space:]]*$", RECA_NULL}
>> 
> 


Re: [1/4] refine cluster

Posted by James Peach <jp...@apache.org>.
This is a huge commit with

	- no links back to the Jira ticket
	- no source code comments
	- no indication of the problem that it is solving or how it solves it
	- no performance comparison (I assume this for performance)
	- no documentation of the new configuration parameters
	- no indication of compatibility (is it really OK to the 4.x branch?)
	- no tests

Please, can we talk about the above issues?

On Nov 19, 2013, at 11:45 PM, weijin@apache.org wrote:

> Updated Branches:
>  refs/heads/refine_cluster [created] 7ffc10a9c
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/P_ClusterInline.h
> ----------------------------------------------------------------------
> diff --git a/iocore/cluster/P_ClusterInline.h b/iocore/cluster/P_ClusterInline.h
> index c653956..1d26b3a 100644
> --- a/iocore/cluster/P_ClusterInline.h
> +++ b/iocore/cluster/P_ClusterInline.h
> @@ -36,25 +36,30 @@ inline Action *
> Cluster_lookup(Continuation * cont, CacheKey * key, CacheFragType frag_type, char *hostname, int host_len)
> {
>   // Try to send remote, if not possible, handle locally
> -  Action *retAct;
> -  ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
> -  if (m && !clusterProcessor.disable_remote_cluster_ops(m)) {
> -    CacheContinuation *cc = CacheContinuation::cacheContAllocator_alloc();
> -    cc->action = cont;
> -    cc->mutex = cont->mutex;
> -    retAct = CacheContinuation::do_remote_lookup(cont, key, cc, frag_type, hostname, host_len);
> -    if (retAct) {
> -      return retAct;
> -    } else {
> -      // not remote, do local lookup
> -      CacheContinuation::cacheContAllocator_free(cc);
> -      return (Action *) NULL;
> -    }
> -  } else {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LOOKUP_FAILED, 0);
> -  }
> +//  Action *retAct;
> +//  ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
> +//  if (m && !clusterProcessor.disable_remote_cluster_ops(m)) {
> +//    CacheContinuation *cc = CacheContinuation::cacheContAllocator_alloc();
> +//    cc->action = cont;
> +//    cc->mutex = cont->mutex;
> +//    retAct = CacheContinuation::do_remote_lookup(cont, key, cc, frag_type, hostname, host_len);
> +//    if (retAct) {
> +//      return retAct;
> +//    } else {
> +//      // not remote, do local lookup
> +//      CacheContinuation::cacheContAllocator_free(cc);
> +//      return (Action *) NULL;
> +//    }
> +//  } else {
> +//    Action a;
> +//    a = cont;
> +//    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LOOKUP_FAILED, 0);
> +//  }
> +  (void) cont;
> +  (void) key;
> +  (void) frag_type;
> +  (void) hostname;
> +  (void) host_len;
>   return (Action *) NULL;
> }
> 
> @@ -66,18 +71,24 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>              time_t pin_in_cache, CacheFragType frag_type, char *hostname, int host_len)
> {
>   (void) params;
> -  if (clusterProcessor.disable_remote_cluster_ops(owner_machine)) {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_READ_FAILED, 0);
> +  ink_assert(cont);
> +  ClusterSession session;
> +  if (cluster_create_session(&session, owner_machine, NULL, 0)) {
> +    cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, NULL);
> +    return ACTION_RESULT_DONE;
>   }
> +
>   int vers = CacheOpMsg_long::protoToVersion(owner_machine->msg_proto_major);
> +  CacheOpArgs_General readArgs;
> +  Ptr<IOBufferData> d;
> +
>   int flen;
>   int len = 0;
>   int cur_len;
>   int res = 0;
> -  char *msg;
> +  char *msg = 0;
>   char *data;
> +  Action *action = NULL;
> 
>   if (vers == CacheOpMsg_long::CACHE_OP_LONG_MESSAGE_VERSION) {
>     if ((opcode == CACHE_OPEN_READ_LONG)
> @@ -87,20 +98,21 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
> 
>       const char *url_hostname;
>       int url_hlen;
> -      INK_MD5 url_only_md5;
> +      INK_MD5 url_md5;
> 
> -      Cache::generate_key(&url_only_md5, url, 0);
> +      Cache::generate_key(&url_md5, url);
>       url_hostname = url->host_get(&url_hlen);
> 
>       len += request->m_heap->marshal_length();
> -      len += params->marshal_length();
> +      len += sizeof(CacheLookupHttpConfig) + params->marshal_length();
>       len += url_hlen;
> 
>       if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)       // Bound marshalled data
>         goto err_exit;
> 
>       // Perform data Marshal operation
> -      msg = (char *) ALLOCA_DOUBLE(flen + len);
> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +      msg = (char *) d->data();
>       data = msg + flen;
> 
>       cur_len = len;
> @@ -110,6 +122,13 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>       }
>       data += res;
>       cur_len -= res;
> +
> +      if (cur_len < (int) sizeof(CacheLookupHttpConfig))
> +        goto err_exit;
> +      memcpy(data, params, sizeof(CacheLookupHttpConfig));
> +      data += sizeof(CacheLookupHttpConfig);
> +      cur_len -= sizeof(CacheLookupHttpConfig);
> +
>       if ((res = params->marshal(data, cur_len)) < 0)
>         goto err_exit;
>       data += res;
> @@ -117,37 +136,33 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>       memcpy(data, url_hostname, url_hlen);
> 
>       CacheOpArgs_General readArgs;
> -      readArgs.url_md5 = &url_only_md5;
> +      readArgs.url_md5 = &url_md5;
>       readArgs.pin_in_cache = pin_in_cache;
>       readArgs.frag_type = frag_type;
> -      return CacheContinuation::do_op(cont, owner_machine, (void *) &readArgs,
> -                                      opcode, (char *) msg, (flen + len), -1, buf);
> +
> +      action = CacheContinuation::do_op(cont, session, (void *) &readArgs,
> +                                            opcode, d, (flen + len), -1, buf);
>     } else {
>       // Build message if we have host data.
> +      flen = op_to_sizeof_fixedlen_msg(opcode);
> +      len = host_len;
> 
> -      if (host_len) {
> -        // Determine length of data to Marshal
> -        flen = op_to_sizeof_fixedlen_msg(opcode);
> -        len = host_len;
> -
> -        if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
> -          goto err_exit;
> +      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
> +        goto err_exit;
> 
> -        msg = (char *) ALLOCA_DOUBLE(flen + len);
> -        data = msg + flen;
> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +      msg = (char *) d->data();
> +      data = msg + flen;
> +      if (host_len)
>         memcpy(data, hostname, host_len);
> 
> -      } else {
> -        msg = 0;
> -        flen = 0;
> -        len = 0;
> -      }
> -      CacheOpArgs_General readArgs;
>       readArgs.url_md5 = key;
>       readArgs.frag_type = frag_type;
> -      return CacheContinuation::do_op(cont, owner_machine, (void *) &readArgs,
> -                                      opcode, (char *) msg, (flen + len), -1, buf);
> +
> +      action = CacheContinuation::do_op(cont, session, (void *) &readArgs,
> +                                            opcode, d, (flen + len), -1, buf);
>     }
> +    ink_assert(msg);
> 
>   } else {
>     //////////////////////////////////////////////////////////////
> @@ -155,10 +170,12 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>     //////////////////////////////////////////////////////////////
>     ink_release_assert(!"CacheOpMsg_long [read] bad msg version");
>   }
> +
> +  if (action)
> +    return action;
> err_exit:
> -  Action a;
> -  a = cont;
> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_READ_FAILED, 0);
> +  cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, NULL);
> +  return ACTION_RESULT_DONE;
> }
> 
> inline Action *
> @@ -171,10 +188,11 @@ Cluster_write(Continuation * cont, int expected_size,
> {
>   (void) key;
>   (void) request;
> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_WRITE_FAILED, 0);
> +  ClusterSession session;
> +  ink_assert(cont);
> +  if (cluster_create_session(&session, m, NULL, 0)) {
> +     cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, NULL);
> +     return ACTION_RESULT_DONE;
>   }
>   char *msg = 0;
>   char *data = 0;
> @@ -182,24 +200,22 @@ Cluster_write(Continuation * cont, int expected_size,
>   int len = 0;
>   int flen = 0;
>   int vers = CacheOpMsg_long::protoToVersion(m->msg_proto_major);
> +  Ptr<IOBufferData> d;
> 
>   switch (opcode) {
>   case CACHE_OPEN_WRITE:
>     {
>       // Build message if we have host data
> -      if (host_len) {
> -        // Determine length of data to Marshal
> -        flen = op_to_sizeof_fixedlen_msg(CACHE_OPEN_WRITE);
> -        len = host_len;
> -
> -        if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
> -          goto err_exit;
> -
> -        msg = (char *) ALLOCA_DOUBLE(flen + len);
> -        data = msg + flen;
> +      len = host_len;
> +      flen = op_to_sizeof_fixedlen_msg(CACHE_OPEN_WRITE);
> +      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
> +        goto err_exit;
> 
> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +      msg = (char *) d->data();
> +      data = msg + flen;
> +      if (host_len)
>         memcpy(data, hostname, host_len);
> -      }
>       break;
>     }
>   case CACHE_OPEN_WRITE_LONG:
> @@ -223,8 +239,9 @@ Cluster_write(Continuation * cont, int expected_size,
>       if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)       // Bound marshalled data
>         goto err_exit;
> 
> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +      msg = (char *) d->data();
>       // Perform data Marshal operation
> -      msg = (char *) ALLOCA_DOUBLE(flen + len);
>       data = msg + flen;
>       int res = 0;
> 
> @@ -257,7 +274,9 @@ Cluster_write(Continuation * cont, int expected_size,
>     writeArgs.cfl_flags |= (old_info ? CFL_LOPENWRITE_HAVE_OLDINFO : 0);
>     writeArgs.cfl_flags |= (allow_multiple_writes ? CFL_ALLOW_MULTIPLE_WRITES : 0);
> 
> -    return CacheContinuation::do_op(cont, m, (void *) &writeArgs, opcode, msg, flen + len, expected_size, buf);
> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &writeArgs, opcode, d, flen + len, expected_size, buf);
> +    if (action)
> +      return action;
>   } else {
>     //////////////////////////////////////////////////////////////
>     // Create the specified down rev version of this message
> @@ -267,19 +286,21 @@ Cluster_write(Continuation * cont, int expected_size,
>   }
> 
> err_exit:
> -  Action a;
> -  a = cont;
> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_WRITE_FAILED, 0);
> +  cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, NULL);
> +  return ACTION_RESULT_DONE;
> }
> 
> inline Action *
> Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey * to,
>              CacheFragType type, char *hostname, int host_len)
> {
> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LINK_FAILED, 0);
> +  ClusterSession session;
> +  Ptr<IOBufferData> d;
> +  char *msg = NULL;
> +
> +  if (cluster_create_session(&session, m, NULL, 0)) {
> +    cont->handleEvent(CACHE_EVENT_LINK_FAILED, NULL);
> +    return ACTION_RESULT_DONE;
>   }
> 
>   int vers = CacheOpMsg_short_2::protoToVersion(m->msg_proto_major);
> @@ -293,7 +314,8 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>     if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>       goto err_exit;
> 
> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +    msg = (char *) d->data();
>     memcpy((msg + flen), hostname, host_len);
> 
>     // Setup args for remote link
> @@ -301,7 +323,9 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>     linkArgs.from = from;
>     linkArgs.to = to;
>     linkArgs.frag_type = type;
> -    return CacheContinuation::do_op(cont, m, (void *) &linkArgs, CACHE_LINK, msg, (flen + len));
> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &linkArgs, CACHE_LINK, d, (flen + len));
> +    if (action)
> +      return action;
>   } else {
>     //////////////////////////////////////////////////////////////
>     // Create the specified down rev version of this message
> @@ -311,18 +335,20 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>   }
> 
> err_exit:
> -  Action a;
> -  a = cont;
> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_LINK_FAILED, 0);
> +  cont->handleEvent(CACHE_EVENT_LINK_FAILED, NULL);
> +  return ACTION_RESULT_DONE;
> }
> 
> inline Action *
> Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFragType type, char *hostname, int host_len)
> {
> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_DEREF_FAILED, 0);
> +  ClusterSession session;
> +  Ptr<IOBufferData> d;
> +  char *msg = NULL;
> +
> +  if (cluster_create_session(&session, m, NULL, 0)) {
> +    cont->handleEvent(CACHE_EVENT_DEREF_FAILED, NULL);
> +    return ACTION_RESULT_DONE ;
>   }
> 
>   int vers = CacheOpMsg_short::protoToVersion(m->msg_proto_major);
> @@ -336,14 +362,17 @@ Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFrag
>     if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>       goto err_exit;
> 
> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +    msg = (char *) d->data();
>     memcpy((msg + flen), hostname, host_len);
> 
>     // Setup args for remote deref
>     CacheOpArgs_Deref drefArgs;
>     drefArgs.md5 = key;
>     drefArgs.frag_type = type;
> -    return CacheContinuation::do_op(cont, m, (void *) &drefArgs, CACHE_DEREF, msg, (flen + len));
> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &drefArgs, CACHE_DEREF, d, (flen + len));
> +    if (action)
> +      return action;
>   } else {
>     //////////////////////////////////////////////////////////////
>     // Create the specified down rev version of this message
> @@ -353,19 +382,22 @@ Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFrag
>   }
> 
> err_exit:
> -  Action a;
> -  a = cont;
> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_DEREF_FAILED, 0);
> +  cont->handleEvent(CACHE_EVENT_DEREF_FAILED, NULL);
> +  return ACTION_RESULT_DONE ;
> }
> 
> inline Action *
> Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>                bool rm_user_agents, bool rm_link, CacheFragType frag_type, char *hostname, int host_len)
> {
> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_REMOVE_FAILED, 0);
> +  ClusterSession session;
> +  Ptr<IOBufferData> d;
> +  char *msg = NULL;
> +
> +  if (cluster_create_session(&session, m, NULL, 0)) {
> +    if (cont)
> +      cont->handleEvent(CACHE_EVENT_REMOVE_FAILED, NULL);
> +    return ACTION_RESULT_DONE;
>   }
> 
>   int vers = CacheOpMsg_short::protoToVersion(m->msg_proto_major);
> @@ -379,7 +411,8 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>     if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>       goto err_exit;
> 
> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +    msg = (char *) d->data();
>     memcpy((msg + flen), hostname, host_len);
> 
>     // Setup args for remote update
> @@ -388,7 +421,9 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>     updateArgs.cfl_flags |= (rm_user_agents ? CFL_REMOVE_USER_AGENTS : 0);
>     updateArgs.cfl_flags |= (rm_link ? CFL_REMOVE_LINK : 0);
>     updateArgs.frag_type = frag_type;
> -    return CacheContinuation::do_op(cont, m, (void *) &updateArgs, CACHE_REMOVE, msg, (flen + len));
> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &updateArgs, CACHE_REMOVE, d, (flen + len));
> +    if (action)
> +      return action;
>   } else {
>     //////////////////////////////////////////////////////////////
>     // Create the specified down rev version of this message
> @@ -398,9 +433,8 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>   }
> 
> err_exit:
> -  Action a;
> -  a = cont;
> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_REMOVE_FAILED, 0);
> +  if (cont)
> +    cont->handleEvent(CACHE_EVENT_REMOVE_FAILED, NULL);
> +  return ACTION_RESULT_DONE;
> }
> -
> #endif /* __CLUSTERINLINE_H__ */
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/eventsystem/I_Event.h
> ----------------------------------------------------------------------
> diff --git a/iocore/eventsystem/I_Event.h b/iocore/eventsystem/I_Event.h
> index 7a37ea0..2659131 100644
> --- a/iocore/eventsystem/I_Event.h
> +++ b/iocore/eventsystem/I_Event.h
> @@ -85,6 +85,7 @@
> #define BLOCK_CACHE_EVENT_EVENTS_START            4000
> #define UTILS_EVENT_EVENTS_START                  5000
> #define CONGESTION_EVENT_EVENTS_START             5100
> +#define CLUSTER_MSG_START                         6000
> #define INK_API_EVENT_EVENTS_START                60000
> #define SRV_EVENT_EVENTS_START	                  62000
> #define REMAP_EVENT_EVENTS_START                  63000
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/eventsystem/P_IOBuffer.h
> ----------------------------------------------------------------------
> diff --git a/iocore/eventsystem/P_IOBuffer.h b/iocore/eventsystem/P_IOBuffer.h
> index 0842aff..261aa1f 100644
> --- a/iocore/eventsystem/P_IOBuffer.h
> +++ b/iocore/eventsystem/P_IOBuffer.h
> @@ -203,7 +203,7 @@ new_IOBufferData_internal(
>                            void *b, int64_t size, int64_t asize_index)
> {
>   (void) size;
> -  IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread());
> +  IOBufferData *d = ioDataAllocator.alloc();
>   d->_size_index = asize_index;
>   ink_assert(BUFFER_SIZE_INDEX_IS_CONSTANT(asize_index)
>              || size <= d->block_size());
> @@ -263,7 +263,7 @@ new_IOBufferData_internal(
> #endif
>                            int64_t size_index, AllocType type)
> {
> -  IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread());
> +  IOBufferData *d = ioDataAllocator.alloc();
> #ifdef TRACK_BUFFER_USER
>   d->_location = loc;
> #endif
> @@ -336,7 +336,7 @@ TS_INLINE void
> IOBufferData::free()
> {
>   dealloc();
> -  THREAD_FREE(this, ioDataAllocator, this_ethread());
> +  ioDataAllocator.free(this);
> }
> 
> //////////////////////////////////////////////////////////////////
> @@ -352,7 +352,7 @@ new_IOBufferBlock_internal(
> #endif
>   )
> {
> -  IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread());
> +  IOBufferBlock *b = ioBlockAllocator.alloc();
> #ifdef TRACK_BUFFER_USER
>   b->_location = location;
> #endif
> @@ -366,7 +366,7 @@ new_IOBufferBlock_internal(
> #endif
>                             IOBufferData * d, int64_t len, int64_t offset)
> {
> -  IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread());
> +  IOBufferBlock *b = ioBlockAllocator.alloc();
> #ifdef TRACK_BUFFER_USER
>   b->_location = location;
> #endif
> @@ -468,7 +468,7 @@ TS_INLINE void
> IOBufferBlock::free()
> {
>   dealloc();
> -  THREAD_FREE(this, ioBlockAllocator, this_ethread());
> +  ioBlockAllocator.free(this);
> }
> 
> TS_INLINE void
> @@ -777,7 +777,7 @@ TS_INLINE MIOBuffer * new_MIOBuffer_internal(
> #endif
>                                                int64_t size_index)
> {
> -  MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread());
> +  MIOBuffer *b = ioAllocator.alloc();
> #ifdef TRACK_BUFFER_USER
>   b->_location = location;
> #endif
> @@ -790,7 +790,7 @@ free_MIOBuffer(MIOBuffer * mio)
> {
>   mio->_writer = NULL;
>   mio->dealloc_all_readers();
> -  THREAD_FREE(mio, ioAllocator, this_ethread());
> +  ioAllocator.free(mio);
> }
> 
> TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
> @@ -799,7 +799,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
> #endif
>                                                      int64_t size_index)
> {
> -  MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread());
> +  MIOBuffer *b = ioAllocator.alloc();
>   b->size_index = size_index;
> #ifdef TRACK_BUFFER_USER
>   b->_location = location;
> @@ -810,7 +810,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
> TS_INLINE void
> free_empty_MIOBuffer(MIOBuffer * mio)
> {
> -  THREAD_FREE(mio, ioAllocator, this_ethread());
> +  ioAllocator.free(mio);
> }
> 
> TS_INLINE IOBufferReader *
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/mgmt/RecordsConfig.cc
> ----------------------------------------------------------------------
> diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
> index 4a73f19..7677471 100644
> --- a/mgmt/RecordsConfig.cc
> +++ b/mgmt/RecordsConfig.cc
> @@ -814,6 +814,24 @@ RecordElement RecordsConfig[] = {
>   ,
>   {RECT_CONFIG, "proxy.config.cluster.cluster_port", RECD_INT, "8086", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>   ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_bps", RECD_INT, "804857600", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_bps", RECD_INT, "4194304000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_send_wait_time", RECD_INT, "1000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_send_wait_time", RECD_INT, "5000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_loop_interval", RECD_INT, "0", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_loop_interval", RECD_INT, "1000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.max_sessions_per_machine", RECD_INT, "1000000", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1000-4000000]", RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.session_locks_per_machine", RECD_INT, "10949", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1-100000]", RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.read_buffer_size", RECD_INT, "2097152", RECU_RESTART_TS, RR_NULL, RECC_INT, "[65536-2097152]", RECA_NULL}
> +  ,
>   {RECT_CONFIG, "proxy.config.cluster.cluster_configuration", RECD_STRING, "cluster.config", RECU_NULL, RR_NULL, RECC_NULL, NULL, RECA_NULL}
>   ,
>   {RECT_CONFIG, "proxy.config.cluster.ethernet_interface", RECD_STRING, TS_BUILD_DEFAULT_LOOPBACK_IFACE, RECU_RESTART_TS, RR_REQUIRED, RECC_STR, "^[^[:space:]]*$", RECA_NULL}
> 


Re: [1/4] refine cluster

Posted by James Peach <jp...@apache.org>.
This is a huge commit with

	- no links back to the Jira ticket
	- no source code comments
	- no indication of the problem that it is solving or how it solves it
	- no performance comparison (I assume this for performance)
	- no documentation of the new configuration parameters
	- no indication of compatibility (is it really OK to the 4.x branch?)
	- no tests

Please, can we talk about the above issues?

On Nov 19, 2013, at 11:45 PM, weijin@apache.org wrote:

> Updated Branches:
>  refs/heads/refine_cluster [created] 7ffc10a9c
> 
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/cluster/P_ClusterInline.h
> ----------------------------------------------------------------------
> diff --git a/iocore/cluster/P_ClusterInline.h b/iocore/cluster/P_ClusterInline.h
> index c653956..1d26b3a 100644
> --- a/iocore/cluster/P_ClusterInline.h
> +++ b/iocore/cluster/P_ClusterInline.h
> @@ -36,25 +36,30 @@ inline Action *
> Cluster_lookup(Continuation * cont, CacheKey * key, CacheFragType frag_type, char *hostname, int host_len)
> {
>   // Try to send remote, if not possible, handle locally
> -  Action *retAct;
> -  ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
> -  if (m && !clusterProcessor.disable_remote_cluster_ops(m)) {
> -    CacheContinuation *cc = CacheContinuation::cacheContAllocator_alloc();
> -    cc->action = cont;
> -    cc->mutex = cont->mutex;
> -    retAct = CacheContinuation::do_remote_lookup(cont, key, cc, frag_type, hostname, host_len);
> -    if (retAct) {
> -      return retAct;
> -    } else {
> -      // not remote, do local lookup
> -      CacheContinuation::cacheContAllocator_free(cc);
> -      return (Action *) NULL;
> -    }
> -  } else {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LOOKUP_FAILED, 0);
> -  }
> +//  Action *retAct;
> +//  ClusterMachine *m = cluster_machine_at_depth(cache_hash(*key));
> +//  if (m && !clusterProcessor.disable_remote_cluster_ops(m)) {
> +//    CacheContinuation *cc = CacheContinuation::cacheContAllocator_alloc();
> +//    cc->action = cont;
> +//    cc->mutex = cont->mutex;
> +//    retAct = CacheContinuation::do_remote_lookup(cont, key, cc, frag_type, hostname, host_len);
> +//    if (retAct) {
> +//      return retAct;
> +//    } else {
> +//      // not remote, do local lookup
> +//      CacheContinuation::cacheContAllocator_free(cc);
> +//      return (Action *) NULL;
> +//    }
> +//  } else {
> +//    Action a;
> +//    a = cont;
> +//    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LOOKUP_FAILED, 0);
> +//  }
> +  (void) cont;
> +  (void) key;
> +  (void) frag_type;
> +  (void) hostname;
> +  (void) host_len;
>   return (Action *) NULL;
> }
> 
> @@ -66,18 +71,24 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>              time_t pin_in_cache, CacheFragType frag_type, char *hostname, int host_len)
> {
>   (void) params;
> -  if (clusterProcessor.disable_remote_cluster_ops(owner_machine)) {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_READ_FAILED, 0);
> +  ink_assert(cont);
> +  ClusterSession session;
> +  if (cluster_create_session(&session, owner_machine, NULL, 0)) {
> +    cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, NULL);
> +    return ACTION_RESULT_DONE;
>   }
> +
>   int vers = CacheOpMsg_long::protoToVersion(owner_machine->msg_proto_major);
> +  CacheOpArgs_General readArgs;
> +  Ptr<IOBufferData> d;
> +
>   int flen;
>   int len = 0;
>   int cur_len;
>   int res = 0;
> -  char *msg;
> +  char *msg = 0;
>   char *data;
> +  Action *action = NULL;
> 
>   if (vers == CacheOpMsg_long::CACHE_OP_LONG_MESSAGE_VERSION) {
>     if ((opcode == CACHE_OPEN_READ_LONG)
> @@ -87,20 +98,21 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
> 
>       const char *url_hostname;
>       int url_hlen;
> -      INK_MD5 url_only_md5;
> +      INK_MD5 url_md5;
> 
> -      Cache::generate_key(&url_only_md5, url, 0);
> +      Cache::generate_key(&url_md5, url);
>       url_hostname = url->host_get(&url_hlen);
> 
>       len += request->m_heap->marshal_length();
> -      len += params->marshal_length();
> +      len += sizeof(CacheLookupHttpConfig) + params->marshal_length();
>       len += url_hlen;
> 
>       if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)       // Bound marshalled data
>         goto err_exit;
> 
>       // Perform data Marshal operation
> -      msg = (char *) ALLOCA_DOUBLE(flen + len);
> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +      msg = (char *) d->data();
>       data = msg + flen;
> 
>       cur_len = len;
> @@ -110,6 +122,13 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>       }
>       data += res;
>       cur_len -= res;
> +
> +      if (cur_len < (int) sizeof(CacheLookupHttpConfig))
> +        goto err_exit;
> +      memcpy(data, params, sizeof(CacheLookupHttpConfig));
> +      data += sizeof(CacheLookupHttpConfig);
> +      cur_len -= sizeof(CacheLookupHttpConfig);
> +
>       if ((res = params->marshal(data, cur_len)) < 0)
>         goto err_exit;
>       data += res;
> @@ -117,37 +136,33 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>       memcpy(data, url_hostname, url_hlen);
> 
>       CacheOpArgs_General readArgs;
> -      readArgs.url_md5 = &url_only_md5;
> +      readArgs.url_md5 = &url_md5;
>       readArgs.pin_in_cache = pin_in_cache;
>       readArgs.frag_type = frag_type;
> -      return CacheContinuation::do_op(cont, owner_machine, (void *) &readArgs,
> -                                      opcode, (char *) msg, (flen + len), -1, buf);
> +
> +      action = CacheContinuation::do_op(cont, session, (void *) &readArgs,
> +                                            opcode, d, (flen + len), -1, buf);
>     } else {
>       // Build message if we have host data.
> +      flen = op_to_sizeof_fixedlen_msg(opcode);
> +      len = host_len;
> 
> -      if (host_len) {
> -        // Determine length of data to Marshal
> -        flen = op_to_sizeof_fixedlen_msg(opcode);
> -        len = host_len;
> -
> -        if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
> -          goto err_exit;
> +      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
> +        goto err_exit;
> 
> -        msg = (char *) ALLOCA_DOUBLE(flen + len);
> -        data = msg + flen;
> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +      msg = (char *) d->data();
> +      data = msg + flen;
> +      if (host_len)
>         memcpy(data, hostname, host_len);
> 
> -      } else {
> -        msg = 0;
> -        flen = 0;
> -        len = 0;
> -      }
> -      CacheOpArgs_General readArgs;
>       readArgs.url_md5 = key;
>       readArgs.frag_type = frag_type;
> -      return CacheContinuation::do_op(cont, owner_machine, (void *) &readArgs,
> -                                      opcode, (char *) msg, (flen + len), -1, buf);
> +
> +      action = CacheContinuation::do_op(cont, session, (void *) &readArgs,
> +                                            opcode, d, (flen + len), -1, buf);
>     }
> +    ink_assert(msg);
> 
>   } else {
>     //////////////////////////////////////////////////////////////
> @@ -155,10 +170,12 @@ Cluster_read(ClusterMachine * owner_machine, int opcode,
>     //////////////////////////////////////////////////////////////
>     ink_release_assert(!"CacheOpMsg_long [read] bad msg version");
>   }
> +
> +  if (action)
> +    return action;
> err_exit:
> -  Action a;
> -  a = cont;
> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_READ_FAILED, 0);
> +  cont->handleEvent(CACHE_EVENT_OPEN_READ_FAILED, NULL);
> +  return ACTION_RESULT_DONE;
> }
> 
> inline Action *
> @@ -171,10 +188,11 @@ Cluster_write(Continuation * cont, int expected_size,
> {
>   (void) key;
>   (void) request;
> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_WRITE_FAILED, 0);
> +  ClusterSession session;
> +  ink_assert(cont);
> +  if (cluster_create_session(&session, m, NULL, 0)) {
> +     cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, NULL);
> +     return ACTION_RESULT_DONE;
>   }
>   char *msg = 0;
>   char *data = 0;
> @@ -182,24 +200,22 @@ Cluster_write(Continuation * cont, int expected_size,
>   int len = 0;
>   int flen = 0;
>   int vers = CacheOpMsg_long::protoToVersion(m->msg_proto_major);
> +  Ptr<IOBufferData> d;
> 
>   switch (opcode) {
>   case CACHE_OPEN_WRITE:
>     {
>       // Build message if we have host data
> -      if (host_len) {
> -        // Determine length of data to Marshal
> -        flen = op_to_sizeof_fixedlen_msg(CACHE_OPEN_WRITE);
> -        len = host_len;
> -
> -        if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
> -          goto err_exit;
> -
> -        msg = (char *) ALLOCA_DOUBLE(flen + len);
> -        data = msg + flen;
> +      len = host_len;
> +      flen = op_to_sizeof_fixedlen_msg(CACHE_OPEN_WRITE);
> +      if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)     // Bound marshalled data
> +        goto err_exit;
> 
> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +      msg = (char *) d->data();
> +      data = msg + flen;
> +      if (host_len)
>         memcpy(data, hostname, host_len);
> -      }
>       break;
>     }
>   case CACHE_OPEN_WRITE_LONG:
> @@ -223,8 +239,9 @@ Cluster_write(Continuation * cont, int expected_size,
>       if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE)       // Bound marshalled data
>         goto err_exit;
> 
> +      d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +      msg = (char *) d->data();
>       // Perform data Marshal operation
> -      msg = (char *) ALLOCA_DOUBLE(flen + len);
>       data = msg + flen;
>       int res = 0;
> 
> @@ -257,7 +274,9 @@ Cluster_write(Continuation * cont, int expected_size,
>     writeArgs.cfl_flags |= (old_info ? CFL_LOPENWRITE_HAVE_OLDINFO : 0);
>     writeArgs.cfl_flags |= (allow_multiple_writes ? CFL_ALLOW_MULTIPLE_WRITES : 0);
> 
> -    return CacheContinuation::do_op(cont, m, (void *) &writeArgs, opcode, msg, flen + len, expected_size, buf);
> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &writeArgs, opcode, d, flen + len, expected_size, buf);
> +    if (action)
> +      return action;
>   } else {
>     //////////////////////////////////////////////////////////////
>     // Create the specified down rev version of this message
> @@ -267,19 +286,21 @@ Cluster_write(Continuation * cont, int expected_size,
>   }
> 
> err_exit:
> -  Action a;
> -  a = cont;
> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_OPEN_WRITE_FAILED, 0);
> +  cont->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, NULL);
> +  return ACTION_RESULT_DONE;
> }
> 
> inline Action *
> Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey * to,
>              CacheFragType type, char *hostname, int host_len)
> {
> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_LINK_FAILED, 0);
> +  ClusterSession session;
> +  Ptr<IOBufferData> d;
> +  char *msg = NULL;
> +
> +  if (cluster_create_session(&session, m, NULL, 0)) {
> +    cont->handleEvent(CACHE_EVENT_LINK_FAILED, NULL);
> +    return ACTION_RESULT_DONE;
>   }
> 
>   int vers = CacheOpMsg_short_2::protoToVersion(m->msg_proto_major);
> @@ -293,7 +314,8 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>     if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>       goto err_exit;
> 
> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +    msg = (char *) d->data();
>     memcpy((msg + flen), hostname, host_len);
> 
>     // Setup args for remote link
> @@ -301,7 +323,9 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>     linkArgs.from = from;
>     linkArgs.to = to;
>     linkArgs.frag_type = type;
> -    return CacheContinuation::do_op(cont, m, (void *) &linkArgs, CACHE_LINK, msg, (flen + len));
> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &linkArgs, CACHE_LINK, d, (flen + len));
> +    if (action)
> +      return action;
>   } else {
>     //////////////////////////////////////////////////////////////
>     // Create the specified down rev version of this message
> @@ -311,18 +335,20 @@ Cluster_link(ClusterMachine * m, Continuation * cont, CacheKey * from, CacheKey
>   }
> 
> err_exit:
> -  Action a;
> -  a = cont;
> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_LINK_FAILED, 0);
> +  cont->handleEvent(CACHE_EVENT_LINK_FAILED, NULL);
> +  return ACTION_RESULT_DONE;
> }
> 
> inline Action *
> Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFragType type, char *hostname, int host_len)
> {
> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_DEREF_FAILED, 0);
> +  ClusterSession session;
> +  Ptr<IOBufferData> d;
> +  char *msg = NULL;
> +
> +  if (cluster_create_session(&session, m, NULL, 0)) {
> +    cont->handleEvent(CACHE_EVENT_DEREF_FAILED, NULL);
> +    return ACTION_RESULT_DONE ;
>   }
> 
>   int vers = CacheOpMsg_short::protoToVersion(m->msg_proto_major);
> @@ -336,14 +362,17 @@ Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFrag
>     if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>       goto err_exit;
> 
> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +    msg = (char *) d->data();
>     memcpy((msg + flen), hostname, host_len);
> 
>     // Setup args for remote deref
>     CacheOpArgs_Deref drefArgs;
>     drefArgs.md5 = key;
>     drefArgs.frag_type = type;
> -    return CacheContinuation::do_op(cont, m, (void *) &drefArgs, CACHE_DEREF, msg, (flen + len));
> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &drefArgs, CACHE_DEREF, d, (flen + len));
> +    if (action)
> +      return action;
>   } else {
>     //////////////////////////////////////////////////////////////
>     // Create the specified down rev version of this message
> @@ -353,19 +382,22 @@ Cluster_deref(ClusterMachine * m, Continuation * cont, CacheKey * key, CacheFrag
>   }
> 
> err_exit:
> -  Action a;
> -  a = cont;
> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_DEREF_FAILED, 0);
> +  cont->handleEvent(CACHE_EVENT_DEREF_FAILED, NULL);
> +  return ACTION_RESULT_DONE ;
> }
> 
> inline Action *
> Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>                bool rm_user_agents, bool rm_link, CacheFragType frag_type, char *hostname, int host_len)
> {
> -  if (clusterProcessor.disable_remote_cluster_ops(m)) {
> -    Action a;
> -    a = cont;
> -    return CacheContinuation::callback_failure(&a, CACHE_EVENT_REMOVE_FAILED, 0);
> +  ClusterSession session;
> +  Ptr<IOBufferData> d;
> +  char *msg = NULL;
> +
> +  if (cluster_create_session(&session, m, NULL, 0)) {
> +    if (cont)
> +      cont->handleEvent(CACHE_EVENT_REMOVE_FAILED, NULL);
> +    return ACTION_RESULT_DONE;
>   }
> 
>   int vers = CacheOpMsg_short::protoToVersion(m->msg_proto_major);
> @@ -379,7 +411,8 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>     if ((flen + len) > DEFAULT_MAX_BUFFER_SIZE) // Bound marshalled data
>       goto err_exit;
> 
> -    char *msg = (char *) ALLOCA_DOUBLE(flen + len);
> +    d = new_IOBufferData(iobuffer_size_to_index(flen + len));
> +    msg = (char *) d->data();
>     memcpy((msg + flen), hostname, host_len);
> 
>     // Setup args for remote update
> @@ -388,7 +421,9 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>     updateArgs.cfl_flags |= (rm_user_agents ? CFL_REMOVE_USER_AGENTS : 0);
>     updateArgs.cfl_flags |= (rm_link ? CFL_REMOVE_LINK : 0);
>     updateArgs.frag_type = frag_type;
> -    return CacheContinuation::do_op(cont, m, (void *) &updateArgs, CACHE_REMOVE, msg, (flen + len));
> +    Action *action = CacheContinuation::do_op(cont, session, (void *) &updateArgs, CACHE_REMOVE, d, (flen + len));
> +    if (action)
> +      return action;
>   } else {
>     //////////////////////////////////////////////////////////////
>     // Create the specified down rev version of this message
> @@ -398,9 +433,8 @@ Cluster_remove(ClusterMachine * m, Continuation * cont, CacheKey * key,
>   }
> 
> err_exit:
> -  Action a;
> -  a = cont;
> -  return CacheContinuation::callback_failure(&a, CACHE_EVENT_REMOVE_FAILED, 0);
> +  if (cont)
> +    cont->handleEvent(CACHE_EVENT_REMOVE_FAILED, NULL);
> +  return ACTION_RESULT_DONE;
> }
> -
> #endif /* __CLUSTERINLINE_H__ */
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/eventsystem/I_Event.h
> ----------------------------------------------------------------------
> diff --git a/iocore/eventsystem/I_Event.h b/iocore/eventsystem/I_Event.h
> index 7a37ea0..2659131 100644
> --- a/iocore/eventsystem/I_Event.h
> +++ b/iocore/eventsystem/I_Event.h
> @@ -85,6 +85,7 @@
> #define BLOCK_CACHE_EVENT_EVENTS_START            4000
> #define UTILS_EVENT_EVENTS_START                  5000
> #define CONGESTION_EVENT_EVENTS_START             5100
> +#define CLUSTER_MSG_START                         6000
> #define INK_API_EVENT_EVENTS_START                60000
> #define SRV_EVENT_EVENTS_START	                  62000
> #define REMAP_EVENT_EVENTS_START                  63000
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/iocore/eventsystem/P_IOBuffer.h
> ----------------------------------------------------------------------
> diff --git a/iocore/eventsystem/P_IOBuffer.h b/iocore/eventsystem/P_IOBuffer.h
> index 0842aff..261aa1f 100644
> --- a/iocore/eventsystem/P_IOBuffer.h
> +++ b/iocore/eventsystem/P_IOBuffer.h
> @@ -203,7 +203,7 @@ new_IOBufferData_internal(
>                            void *b, int64_t size, int64_t asize_index)
> {
>   (void) size;
> -  IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread());
> +  IOBufferData *d = ioDataAllocator.alloc();
>   d->_size_index = asize_index;
>   ink_assert(BUFFER_SIZE_INDEX_IS_CONSTANT(asize_index)
>              || size <= d->block_size());
> @@ -263,7 +263,7 @@ new_IOBufferData_internal(
> #endif
>                            int64_t size_index, AllocType type)
> {
> -  IOBufferData *d = THREAD_ALLOC(ioDataAllocator, this_ethread());
> +  IOBufferData *d = ioDataAllocator.alloc();
> #ifdef TRACK_BUFFER_USER
>   d->_location = loc;
> #endif
> @@ -336,7 +336,7 @@ TS_INLINE void
> IOBufferData::free()
> {
>   dealloc();
> -  THREAD_FREE(this, ioDataAllocator, this_ethread());
> +  ioDataAllocator.free(this);
> }
> 
> //////////////////////////////////////////////////////////////////
> @@ -352,7 +352,7 @@ new_IOBufferBlock_internal(
> #endif
>   )
> {
> -  IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread());
> +  IOBufferBlock *b = ioBlockAllocator.alloc();
> #ifdef TRACK_BUFFER_USER
>   b->_location = location;
> #endif
> @@ -366,7 +366,7 @@ new_IOBufferBlock_internal(
> #endif
>                             IOBufferData * d, int64_t len, int64_t offset)
> {
> -  IOBufferBlock *b = THREAD_ALLOC(ioBlockAllocator, this_ethread());
> +  IOBufferBlock *b = ioBlockAllocator.alloc();
> #ifdef TRACK_BUFFER_USER
>   b->_location = location;
> #endif
> @@ -468,7 +468,7 @@ TS_INLINE void
> IOBufferBlock::free()
> {
>   dealloc();
> -  THREAD_FREE(this, ioBlockAllocator, this_ethread());
> +  ioBlockAllocator.free(this);
> }
> 
> TS_INLINE void
> @@ -777,7 +777,7 @@ TS_INLINE MIOBuffer * new_MIOBuffer_internal(
> #endif
>                                                int64_t size_index)
> {
> -  MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread());
> +  MIOBuffer *b = ioAllocator.alloc();
> #ifdef TRACK_BUFFER_USER
>   b->_location = location;
> #endif
> @@ -790,7 +790,7 @@ free_MIOBuffer(MIOBuffer * mio)
> {
>   mio->_writer = NULL;
>   mio->dealloc_all_readers();
> -  THREAD_FREE(mio, ioAllocator, this_ethread());
> +  ioAllocator.free(mio);
> }
> 
> TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
> @@ -799,7 +799,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
> #endif
>                                                      int64_t size_index)
> {
> -  MIOBuffer *b = THREAD_ALLOC(ioAllocator, this_ethread());
> +  MIOBuffer *b = ioAllocator.alloc();
>   b->size_index = size_index;
> #ifdef TRACK_BUFFER_USER
>   b->_location = location;
> @@ -810,7 +810,7 @@ TS_INLINE MIOBuffer * new_empty_MIOBuffer_internal(
> TS_INLINE void
> free_empty_MIOBuffer(MIOBuffer * mio)
> {
> -  THREAD_FREE(mio, ioAllocator, this_ethread());
> +  ioAllocator.free(mio);
> }
> 
> TS_INLINE IOBufferReader *
> 
> http://git-wip-us.apache.org/repos/asf/trafficserver/blob/7ffc10a9/mgmt/RecordsConfig.cc
> ----------------------------------------------------------------------
> diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
> index 4a73f19..7677471 100644
> --- a/mgmt/RecordsConfig.cc
> +++ b/mgmt/RecordsConfig.cc
> @@ -814,6 +814,24 @@ RecordElement RecordsConfig[] = {
>   ,
>   {RECT_CONFIG, "proxy.config.cluster.cluster_port", RECD_INT, "8086", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
>   ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_bps", RECD_INT, "804857600", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_bps", RECD_INT, "4194304000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_send_wait_time", RECD_INT, "1000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_send_wait_time", RECD_INT, "5000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.min_loop_interval", RECD_INT, "0", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.flow_ctrl.max_loop_interval", RECD_INT, "1000", RECU_RESTART_TS, RR_REQUIRED, RECC_NULL, NULL, RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.max_sessions_per_machine", RECD_INT, "1000000", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1000-4000000]", RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.session_locks_per_machine", RECD_INT, "10949", RECU_RESTART_TS, RR_NULL, RECC_INT, "[1-100000]", RECA_NULL}
> +  ,
> +  {RECT_CONFIG, "proxy.config.cluster.read_buffer_size", RECD_INT, "2097152", RECU_RESTART_TS, RR_NULL, RECC_INT, "[65536-2097152]", RECA_NULL}
> +  ,
>   {RECT_CONFIG, "proxy.config.cluster.cluster_configuration", RECD_STRING, "cluster.config", RECU_NULL, RR_NULL, RECC_NULL, NULL, RECA_NULL}
>   ,
>   {RECT_CONFIG, "proxy.config.cluster.ethernet_interface", RECD_STRING, TS_BUILD_DEFAULT_LOOPBACK_IFACE, RECU_RESTART_TS, RR_REQUIRED, RECC_STR, "^[^[:space:]]*$", RECA_NULL}
>