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

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

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

    https://github.com/apache/trafficserver/pull/843#discussion_r74263649
  
    --- Diff: plugins/experimental/carp/CarpHashAlgorithm.cc ---
    @@ -0,0 +1,396 @@
    +/** @file
    +
    +  Implements the CARP hash algorithm
    +
    +  @section license License
    +
    +  Licensed to the Apache Software Foundation (ASF) under one
    +  or more contributor license agreements.  See the NOTICE file
    +  distributed with this work for additional information
    +  regarding copyright ownership.  The ASF licenses this file
    +  to you under the Apache License, Version 2.0 (the
    +  "License"); you may not use this file except in compliance
    +  with the License.  You may obtain a copy of the License at
    +
    +      http://www.apache.org/licenses/LICENSE-2.0
    +
    +  Unless required by applicable law or agreed to in writing, software
    +  distributed under the License is distributed on an "AS IS" BASIS,
    +  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +  See the License for the specific language governing permissions and
    +  limitations under the License.
    + */
    +#include <ts/ts.h>
    +#include <stdio.h>
    +#include <memory.h>
    +#include <list>
    +
    +#include <iostream>
    +#include <sstream>
    +
    +#include "Common.h"
    +#include "CarpHashAlgorithm.h"
    +
    +using namespace std;
    +
    +/*****************************************************************/
    +void
    +HashNode::dump(string& s)
    +{
    +  stringstream ss;
    +  string sSockaddr;
    +  getStringFromSockaddr(reinterpret_cast<const struct sockaddr *>( 
&forwardAddr), sSockaddr);
    +  
    +  ss << scheme << "://" << name << ":"<<listenPort<<" ("<<sSockaddr<<") 
weight:"<<weight<< (_status ?  string(" UP ") : string(" DOWN ")); 
    +  if(_statusTime) {
    +    ss << "(" << time(NULL)-_statusTime<< "s ago in "<< _statusLatencyMs 
<< "mS)";
    +  }
    +  ss << " hits:" << _hits;
    +  ss << " carp_noforwarded:" << _carp_noforwarded;
    +  ss << " carp_forwarded:" << _carp_forwarded;
    +  ss << endl;
    +  s += ss.str();
    +}
    +
    +/*****************************************************************/
    +void
    +HashAlgorithm::addHost(std::string name, unsigned int port, std::string 
scheme, double weight, bool self, struct sockaddr_storage fwdAddr)
    +{
    +  HashNode* node = new HashNode(name, port, scheme, weight, self, fwdAddr);
    +  TSAssert(NULL != node);
    +  addHost(node);
    +}
    +
    +/*****************************************************************/
    +void
    +HashAlgorithm::addHost(HashNode* node)
    +{
    +  if (!node) return;
    +  _hostList.push_back(node);
    +}
    +
    +/*****************************************************************/
    +HashNode*
    +HashAlgorithm::findStatusByNameAndPort(const string& name, unsigned int 
port,
    +    size_t* index) {
    +  /*
    +   * Todo: This use loop to find the corresponding HashNode
    +   *               But the HttpClient and the Hash was related, so we
    +   *               could use more easier method to write the status
    +   */
    +  for (size_t ptr = 0; ptr < _hostList.size(); ptr++) {
    +    if (_hostList[ptr]->listenPort == port
    +        && _hostList[ptr]->name.compare(name) == 0) { // found it
    +      if (index) {
    +        *index = ptr;
    +      }
    +      return _hostList[ptr];
    +    }
    +  }
    +  return NULL;
    +}
    +
    +size_t
    +HashAlgorithm::findHashNodeIndex(HashNode *node) {
    +  for (size_t ptr = 0; ptr < _hostList.size(); ptr++) {
    +    if ( _hostList[ptr] == node) {
    +      return ptr;
    +    }
    +  }
    +  return -1;
    +}
    +
    +/*****************************************************************/
    +void
    +HashAlgorithm::setStatus(const string& name, unsigned int port, bool 
status, time_t time, uint64_t latencyMs)
    +{
    +  TSDebug(DEBUG_TAG_INIT, "HashAlgorithm::setStatus name=%s status=%d", 
name.c_str(), status);
    +  
    +  HashNode* node = findStatusByNameAndPort(name,port);
    +  if(node) {
    +    node->setStatus(status,time,latencyMs);
    +  } else {
    +    TSError("Carp internal error setStatus host %s not 
found",name.c_str());
    +  }
    +}
    +
    +void
    +HashAlgorithm::setStatus(HashNode * node, bool status, time_t time, 
uint64_t latencyMs)
    +{
    +  TSDebug(DEBUG_TAG_INIT, "HashAlgorithm::setStatus name=%s status=%d", 
node->name.c_str(), status);
    +
    +//  HashNode* node = findStatusByNameAndPort(name,port);
    +  if(node) {
    --- End diff --
    
    Why is `node` checked if it's passed in? That seems more like an assert or 
shouldn't be checked at all.


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

    Worklog Id:     (was: 26281)
    Time Spent: 2h 50m  (was: 2h 40m)

> ATS CARP Plugin
> ---------------
>
>                 Key: TS-4723
>                 URL: https://issues.apache.org/jira/browse/TS-4723
>             Project: Traffic Server
>          Issue Type: New Feature
>          Components: Plugins
>            Reporter: Eric Schwartz
>            Assignee: Eric Schwartz
>             Fix For: 7.0.0
>
>          Time Spent: 2h 50m
>  Remaining Estimate: 0h
>
> Open sourcing this plugin we use internally within Yahoo in place of 
> hierarchical caching.
> CARP is a plugin that allows you to group a bunch of ATS hosts into a cluster 
> and share cache space across the entire group. This is done with consistent 
> hashing on the object URL to generate an "owner" node in the cluster. 
> Requests to any other node in the cluster will be forwarded on to the 
> corresponding owner. More info in the README.
> Difference from internal version of note:
> I've ripped out some code we weren't entirely sure we could open source 
> because of a hash function. If it turns out that we can open source this, 
> I'll do so. The CarpHashAlgorithm class is meant to be extensible, so any 
> consistent hash function can replace it. The function included here is pretty 
> straightforward but not what we use in production, so just wanted to use that 
> caveat.
> One last caveat:
> You'll see some code and documentation in here for object replication. This 
> is something I added recently to CARP that allows you to specify an object be 
> replicated a certain number of times in the cluster. This is useful if you 
> have a network partition or if you're performing some sort of update. When an 
> object's primary owner is unreachable, a node in the cluster can go to the 
> secondary owner if it's available rather than having to fall all the way back 
> to origin. While I've done some initial testing on this with my own cluster 
> of hosts, it's not been tested in production so use at your own risk for now. 
> I'll be sure to keep the open source community informed on the progress of 
> our tests with this feature.



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

Reply via email to