[ 
https://issues.apache.org/jira/browse/TS-4707?focusedWorklogId=28821&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-28821
 ]

ASF GitHub Bot logged work on TS-4707:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Sep/16 17:15
            Start Date: 12/Sep/16 17:15
    Worklog Time Spent: 10m 
      Work Description: Github user pbchou commented on a diff in the pull 
request:

    https://github.com/apache/trafficserver/pull/834#discussion_r78413984
  
    --- Diff: proxy/ParentConsistentHash.cc ---
    @@ -63,21 +66,104 @@ ParentConsistentHash::getPathHash(HttpRequestData 
*hrdata, ATSHash64 *h)
     {
       const char *tmp = NULL;
       int len;
    -  URL *url = hrdata->hdr->url_get();
    +  URL *url     = hrdata->hdr->url_get();
    +  int num_dirs = 0;
    +
    +  // Use over-ride URL from HttpTransact::State's 
cache_info.parent_selection_url, if present.
    +  URL *ps_url = NULL;
    +  Debug("parent_select", "hrdata->cache_info_parent_selection_url = %p", 
hrdata->cache_info_parent_selection_url);
    +  if (hrdata->cache_info_parent_selection_url) {
    +    ps_url = *(hrdata->cache_info_parent_selection_url);
    +    Debug("parent_select", "ps_url = %p", ps_url);
    +    if (ps_url) {
    +      tmp = ps_url->string_get_ref(&len);
    +      if (tmp && len > 0) {
    +        // Print the over-ride URL
    +        Debug("parent_select", "Using Over-Ride String='%.*s'.", len, tmp);
    +        h->update(tmp, len);
    +        h->final();
    +        return h->get();
    +      }
    +    }
    +  }
     
       // Always hash on '/' because paths returned by ATS are always stripped 
of it
       h->update("/", 1);
     
       tmp = url->path_get(&len);
    -  if (tmp) {
    +
    +  if (tmp && len > 0) {
    +    // Print the Original path.
    +    Debug("parent_select", "Original Path='%.*s'.", len, tmp);
    +
    +    // Process the 'maxdirs' directive.
    +    if (max_dirs != 0) {
    +      // Determine number of directory components in the path.
    +      // NOTE: Leading '/' is gone already.
    +      for (int x = 0; x < len; x++) {
    +        if (tmp[x] == '/')
    +          num_dirs++;
    +      }
    +      // If max_dirs positive , include directory components from the left 
up to max_dirs.
    +      // If max_dirs negative , include directory components from the left 
up to num_dirs - ( abs(max_dirs) - 1 ).
    +      int limit = 0;
    +      if (max_dirs > 0)
    +        limit = max_dirs;
    +      else if (max_dirs < 0) {
    +        int md = abs(max_dirs) - 1;
    +        if (md < num_dirs)
    +          limit = num_dirs - md;
    +        else
    +          limit = 0;
    +      }
    +      if (limit > 0) {
    +        int x     = 0;
    +        int count = 0;
    +        for (; x < len; x++) {
    +          if (tmp[x] == '/')
    +            count++;
    +          if (count == limit) {
    +            len = x + 1;
    +            break;
    +          }
    +        }
    +      } else {
    +        len = 0;
    +      }
    +    }
    +
    +    // Print the post 'maxdirs' path.
    +    Debug("parent_select", "Post-maxdirs Path='%.*s'.", len, tmp);
    +
    +    // Process the 'fname' directive.
    +    // The file name (if any) is filtered out if set to ignore the file 
name or max_dirs was non-zero.
    +    // The file name (if any) consists of the characters at the end of the 
path beyond the final '/'.
    +    // The length of the path string (to be passed to the hash generator) 
is shortened to accomplish the filtering.
    +    if (ignore_fname || max_dirs != 0) {
    --- End diff --
    
    Well, the negative maxdirs used to mean INCLUDE from the end of the path 
rather than EXCLUDE from the end of the path. We changed the semantic 
internally before submitting to the community. I think that from the user 
perspective it is not a bad thing to be able to say "fname=ignore" when you 
don't want the file name instead of doing something like "max_dirs=-1". Yes, it 
achieves the same result, but this is a user-facing configuration file option.


Issue Time Tracking
-------------------

    Worklog Id:     (was: 28821)
    Time Spent: 10h 20m  (was: 10h 10m)

> Parent Consistent Hash Selection - add fname and maxdirs options.
> -----------------------------------------------------------------
>
>                 Key: TS-4707
>                 URL: https://issues.apache.org/jira/browse/TS-4707
>             Project: Traffic Server
>          Issue Type: Improvement
>          Components: Parent Proxy
>            Reporter: Peter Chou
>            Assignee: Peter Chou
>             Fix For: 7.0.0
>
>          Time Spent: 10h 20m
>  Remaining Estimate: 0h
>
> This enhancement adds two options, "fname" and "maxdirs", which can be used 
> to exclude the file-name and some of the directories in the path. The 
> remaining portions of the path are then used as part of the hash computation 
> for selecting among multiple parent caches.
> For our usage, it was desirable from an operational perspective to direct all 
> components of particular sub-tree to a single parent cache (to simplify 
> trouble-shooting, pre-loading, etc.). This can be achieved by excluding the 
> query-string, file-name, and right-most portions of the path from the hash 
> computation.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to