trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bc...@apache.org
Subject git commit: TS-2113 - Porting balancer over to ATS, still more work to be done
Date Thu, 05 Sep 2013 00:32:01 GMT
Updated Branches:
  refs/heads/master 5ba16cb66 -> ae49e1663


TS-2113 - Porting balancer over to ATS, still more work to be done


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

Branch: refs/heads/master
Commit: ae49e16639b35e9304adf6a3ef41ce77bb2612f6
Parents: 5ba16cb
Author: Bryan Call <bcall@apache.org>
Authored: Wed Sep 4 17:31:12 2013 -0700
Committer: Bryan Call <bcall@apache.org>
Committed: Wed Sep 4 17:31:12 2013 -0700

----------------------------------------------------------------------
 plugins/experimental/balancer/balancer.cc | 46 ++++++++++++--------------
 plugins/experimental/balancer/hashkey.h   | 44 +++++++++++++-----------
 plugins/experimental/balancer/resources.h | 36 ++++++--------------
 3 files changed, 57 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ae49e166/plugins/experimental/balancer/balancer.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/balancer/balancer.cc b/plugins/experimental/balancer/balancer.cc
index 8b8a5a1..adc91ad 100644
--- a/plugins/experimental/balancer/balancer.cc
+++ b/plugins/experimental/balancer/balancer.cc
@@ -41,8 +41,8 @@
 
 #include <string>
 
-#include <ts/ts.h>
 #include <ts/remap.h>
+#include <ts/ts.h>
 
 #include "resources.h"
 #include "hashkey.h"
@@ -151,25 +151,24 @@ public:
         if (TSIsDebugTagSet("balancer")) {
           TSDebug("balancer", "Making %s hash ID's using %s", secondary ? "secondary" : "primary",
buf);
         }
-        //MD5(buf, key_len, id);
+        ycrMD5_r(buf, key_len, id);
       } else {
         if (secondary) {
           // Secondary ID defaults to IP (if none of the specified hashes computes)
           char buf[4];
 
-          
-          //*buf = resr.getRRI()->client_ip; // ToDo: this only works for IPv4
+          *buf = resr.getRRI()->client_ip; // ToDo: this only works for IPv4
 
           TSDebug("balancer", "Making secondary hash ID's using IP (default) = %s", buf);
-          //MD5(buf, key_len, id);
+          ycrMD5_r(buf, key_len, id);
         } else {
           // Primary ID defaults to URL (if none of the specified hashes computes)
-          char buf[resr._urlSize + 1];
+          char buf[resr.getRRI()->orig_url_size + 1];
 
-          memcpy(buf, resr._urlString, resr._urlSize);
-          buf[resr._urlSize] = '\0';
+          memcpy(buf, resr.getRRI()->orig_url, resr.getRRI()->orig_url_size);
+          buf[resr.getRRI()->orig_url_size] = '\0';
           TSDebug("balancer", "Making primary hash ID's using URL (default) = %s", buf);
-          //MD5(buf, key_len, id);
+          ycrMD5_r(buf, key_len, id);
         }
       }
     } else {
@@ -191,14 +190,14 @@ private:
 // Initialize the plugin.
 //
 int
-tsremap_init(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
+tsremap_init(TSREMAP_INTERFACE *api_info, char *errbuf, int errbuf_size)
 {
   if (!api_info) {
     strncpy(errbuf, "[tsremap_init] - Invalid TSREMAP_INTERFACE argument", errbuf_size -
1);
     return -1;
   }
 
-  if (api_info->size < sizeof(TSRemapInterface)) {
+  if (api_info->size < sizeof(TSREMAP_INTERFACE)) {
     strncpy(errbuf, "[tsremap_init] - Incorrect size of TSREMAP_INTERFACE structure", errbuf_size
- 1);
     return -2;
   }
@@ -217,19 +216,16 @@ tsremap_init(TSRemapInterface *api_info, char *errbuf, int errbuf_size)
 ///////////////////////////////////////////////////////////////////////////////
 // One instance per remap.config invocation.
 //
-TSReturnCode
-TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf, int errbuf_size)
+int
+tsremap_new_instance(int argc, char *argv[], ihandle *ih, char *errbuf, int errbuf_size)
 {
-  (void) errbuf;
-  (void) errbuf_size;
-
   BalancerInstance* ri = new BalancerInstance;
 
-  *ih = static_cast<void*>(ri);
+  *ih = static_cast<ihandle>(ri);
 
   if (ri == NULL) {
     TSError("Unable to create remap instance");
-    return TS_ERROR;
+    return -5;
   }
 
   for (int ix=2; ix < argc; ++ix) {
@@ -314,13 +310,13 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char *errbuf,
int errbuf_s
     }
   }
 
-  return TS_SUCCESS;
+  return 0;
 }
 
 void
-tsremap_delete_instance(void** ih)
+tsremap_delete_instance(ihandle ih)
 {
-  BalancerInstance* ri = static_cast<BalancerInstance*>(*ih);
+  BalancerInstance* ri = static_cast<BalancerInstance*>(ih);
 
   delete ri;
 }
@@ -329,8 +325,8 @@ tsremap_delete_instance(void** ih)
 ///////////////////////////////////////////////////////////////////////////////
 // This is the main "entry" point for the plugin, called for every request.
 //
-TSRemapStatus
-TSRemapDoRemap(void** ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
+int
+tsremap_remap(ihandle ih, rhandle rh, REMAP_REQUEST_INFO *rri)
 {
   BalancerInstance* balancer;
   int error = 0;
@@ -342,9 +338,9 @@ TSRemapDoRemap(void** ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
 
   if (NULL == ih) {
     TSDebug("balancer", "Falling back to default URL on remap without rules");
-    return TSREMAP_NO_REMAP;
+    return 0;
   }
-  balancer = static_cast<BalancerInstance*>(*ih);
+  balancer = static_cast<BalancerInstance*>(ih);
 
   // Get the rotation name to use.
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ae49e166/plugins/experimental/balancer/hashkey.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/balancer/hashkey.h b/plugins/experimental/balancer/hashkey.h
index 9cec9fd..856c84f 100644
--- a/plugins/experimental/balancer/hashkey.h
+++ b/plugins/experimental/balancer/hashkey.h
@@ -56,9 +56,6 @@ public:
   virtual int key(const void** data, Resources& resr) const = 0;
 
   virtual void free_key(const void* data, int len, Resources& resr) const {
-    (void) data;
-    (void) len;
-    (void) resr;
     // No-op by default
   }
 
@@ -89,9 +86,8 @@ class URLHashKey : public HashKey
  public:
   int
   key(const void** data, Resources& resr) const {
-    int size;
-    *data = resr.getUrl(&size);
-    return size;
+    *data = resr.getRRI()->orig_url;
+    return resr.getRRI()->orig_url_size;
   }
 };
 
@@ -104,9 +100,8 @@ class PathHashKey : public HashKey
  public:
   int
   key(const void** data, Resources& resr) const {
-    int size;
-    *data = TSUrlPathGet(resr._rri->requestBufp, resr._rri->requestUrl, &size);
-    return size;
+    *data = resr.getRRI()->request_path;
+    return resr.getRRI()->request_path_size;
   }
 };
 
@@ -157,9 +152,9 @@ class CookieHashKey : public HashKey
         const char* cookie;
 
         if (_sub) {
-          cookie = NULL; // TODO - get sub cookie
+          cookie = // TODO - get sub cookie
         } else {
-          cookie = NULL; // TODO - get full cookie
+          cookie = // TODO - get full cookie
         }
         if (cookie) {
           *data = cookie;
@@ -167,9 +162,9 @@ class CookieHashKey : public HashKey
         }
       }
     } else {
-      if (resr._cookie_size > 0) {
-        *data = resr._cookie;
-        return resr._cookie_size;
+      if (resr.getRRI()->request_cookie_size > 0) {
+        *data = resr.getRRI()->request_cookie;
+        return resr.getRRI()->request_cookie_size;
       }
     }
 
@@ -194,10 +189,8 @@ class IPHashKey : public HashKey
  public:
   int
   key(const void** data, Resources& resr) const {
-    const struct sockaddr *addr = TSHttpTxnClientAddrGet(resr._txnp);
-    (void) addr;
-    *data = NULL; // TODO set the right pointer
-    return 4; // TODO set the right size
+    *data = &(resr.getRRI()->client_ip);
+    return 4; // ToDo: This only works with IPV4, obviously
   }
 };
 
@@ -224,12 +217,17 @@ class HeaderHashKey : public HashKey
     TSMBuffer bufp = resr.getBufp();
     TSMLoc hdrLoc = resr.getHdrLoc();
     TSMLoc fieldLoc;
+    const char* val;
     int len = -1;
 
     // Note that hdrLoc is freed as part of the Resources dtor, and we free the "string"
value
     // in the free_key() implementation (after we're done with it).
     if (bufp && hdrLoc && (fieldLoc = TSMimeHdrFieldFind(bufp, hdrLoc, _header,
_header_len))) {
-      *data = TSMimeHdrFieldValueStringGet(bufp, hdrLoc, fieldLoc, 0, &len);
+      if (TS_ERROR != TSMimeHdrFieldValueStringGet(bufp, hdrLoc, fieldLoc, 0, &val, &len))
{
+        *data = val;
+      } else {
+        *data = NULL;
+      }
       TSHandleMLocRelease(bufp, hdrLoc, fieldLoc);
     } else {
       *data = NULL;
@@ -238,6 +236,14 @@ class HeaderHashKey : public HashKey
     return len;
   }
 
+  void free_key(const void* data, int len, Resources& resr) const {
+    TSMBuffer bufp = resr.getBufp();
+    TSMLoc hdrLoc = resr.getHdrLoc();
+
+    if (bufp && hdrLoc)
+      TSHandleStringRelease(bufp, hdrLoc, (const char*)data);
+  }
+
  private:
   const char* _header;
   int _header_len;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/ae49e166/plugins/experimental/balancer/resources.h
----------------------------------------------------------------------
diff --git a/plugins/experimental/balancer/resources.h b/plugins/experimental/balancer/resources.h
index 531278b..6188951 100644
--- a/plugins/experimental/balancer/resources.h
+++ b/plugins/experimental/balancer/resources.h
@@ -31,7 +31,7 @@
 
 #include <ts/remap.h>
 #include <ts/ts.h>
-#include <string.h>
+
 
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -41,7 +41,7 @@ class Resources
 {
 public:
   Resources(TSHttpTxn txnp, TSRemapRequestInfo *rri) :
-    _rri(rri), _txnp(txnp), _jar(NULL), _bufp(NULL), _hdrLoc(NULL), _urlString(NULL)
+    _txnp(txnp), _rri(rri), _jar(NULL), _bufp(NULL), _hdrLoc(NULL)
   { }
 
   ~Resources() {
@@ -54,28 +54,24 @@ public:
       TSDebug("balancer", "Destroying the cookie jar");
       // TODO - destroy cookies
     }
-
-    if (_urlString) {
-      TSfree(_urlString);
-    }
   }
 
   const TSHttpTxn getTxnp() const { return _txnp; }
     
   const TSRemapRequestInfo* getRRI() const { return _rri; }
 
-  const char*
+  const cookiejar_t
   getJar() {
     if (_jar)
       return _jar;
 
     // Setup the cookie jar for all processing
-    if (_cookie_size > 0) {
-      char cookie_hdr[_cookie_size + 1];
+    if (_rri->request_cookie_size > 0) {
+      char cookie_hdr[_rri->request_cookie_size + 1];
 
-      memcpy(cookie_hdr, _cookie, _cookie_size);
-      cookie_hdr[_cookie_size] = '\0';
-      _jar = NULL; // TODO - create cookies
+      memcpy(cookie_hdr, _rri->request_cookie, _rri->request_cookie_size);
+      cookie_hdr[_rri->request_cookie_size] = '\0';
+      _jar = // TODO - create cookies
       TSDebug("balancer", "Creating the cookie jar");
     }
 
@@ -103,22 +99,12 @@ public:
     return _hdrLoc;
   }
 
-  char* getUrl(int *size) {
-    _urlString = TSUrlStringGet(_rri->requestBufp, _rri->requestUrl, size);
-    _urlSize = *size;
-    return _urlString;
-  }
-
-public:
-  TSRemapRequestInfo* _rri;
+private:
   TSHttpTxn _txnp;
-  size_t _cookie_size;
-  char* _cookie;
-  char* _jar;
+  TSRemapRequestInfo* _rri;
+  cookiejar_t _jar;
   TSMBuffer _bufp;
   TSMLoc _hdrLoc;
-  int _urlSize;
-  char* _urlString;
 };
 
 


Mime
View raw message