Merge in local trunk
authorBrian Aker <brian@tangent.org>
Tue, 24 May 2011 20:43:14 +0000 (13:43 -0700)
committerBrian Aker <brian@tangent.org>
Tue, 24 May 2011 20:43:14 +0000 (13:43 -0700)
1  2 
ChangeLog
libmemcached/hosts.cc
libmemcached/server.h

diff --combined ChangeLog
index 43d3eef6a2fc84d3f9ca31471d14beee3b43be4a,afbfce1af91ab5235b5e40b2b0bf4371249c0abf..388721a710c0d7edb7d48a54300098e1fbbb1233
+++ b/ChangeLog
@@@ -1,12 -1,14 +1,15 @@@
+  * Updates to C++ interface 
+  * Custom free allocators need to now check for value before calling free.
  0.49 Thu Apr 14 08:43:37 PDT 2011
    * Fix calls to auto methods so that if value is not passed in nothing bad happens.
    * New parser calls for generating memcached_st objects.
    * New error system.
    * New flow control for messages means faster get/set calls.
    * Added new documentation system.
 +  * A behavior change has been now made that if you specify a weight for any
 +  server, we enable the weight flag and do weight balancing.
    * A behavior change has been now made that if you specify a weight for any server, we enable the weight flag and do weight balancing.  
 -  
    * Added MEMCACHED_BEHAVIOR_REMOVE_FAILED_SERVERS to simplify the setting of AUTO REJECT for servers.
  
  0.48 Tue Mar 15 23:05:18 PDT 2011
diff --combined libmemcached/hosts.cc
index d38b12e9337d17281c1c66e412863fda68ebd0e9,4aee163cda51781d665c2422fe807b70342a1e4c..1852e540eca11ecd87f6623fc371cd87b8065203
@@@ -1,16 -1,44 +1,44 @@@
- /* LibMemcached
-  * Copyright (C) 2006-2010 Brian Aker
-  * All rights reserved.
+ /*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+  * 
+  *  Libmemcached library
   *
-  * Use and distribution licensed under the BSD license.  See
-  * the COPYING file in the parent directory for full text.
+  *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+  *  Copyright (C) 2006-2010 Brian Aker All rights reserved.
   *
-  * Summary: 
+  *  Redistribution and use in source and binary forms, with or without
+  *  modification, are permitted provided that the following conditions are
+  *  met:
+  *
+  *      * Redistributions of source code must retain the above copyright
+  *  notice, this list of conditions and the following disclaimer.
+  *
+  *      * Redistributions in binary form must reproduce the above
+  *  copyright notice, this list of conditions and the following disclaimer
+  *  in the documentation and/or other materials provided with the
+  *  distribution.
+  *
+  *      * The names of its contributors may not be used to endorse or
+  *  promote products derived from this software without specific prior
+  *  written permission.
+  *
+  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   */
  
- #include "common.h"
- #include <math.h>
+ #include <libmemcached/common.h>
+ #include <cmath>
+ #include <sys/time.h>
  
  /* Protoypes (static) */
  static memcached_return_t server_add(memcached_st *ptr, const char *hostname,
@@@ -112,10 -140,9 +140,9 @@@ static memcached_return_t update_contin
    uint32_t live_servers= 0;
    struct timeval now;
  
-   if (gettimeofday(&now, NULL) != 0)
+   if (gettimeofday(&now, NULL))
    {
-     memcached_set_errno(ptr, errno, NULL);
-     return MEMCACHED_ERRNO;
+     return memcached_set_errno(*ptr, errno, MEMCACHED_AT);
    }
  
    list= memcached_server_list(ptr);
      for (uint32_t host_index= 0; host_index < memcached_server_count(ptr); ++host_index)
      {
        if (list[host_index].next_retry <= now.tv_sec)
+       {
          live_servers++;
+       }
        else
        {
          if (ptr->ketama.next_distribution_rebuild == 0 || list[host_index].next_retry < ptr->ketama.next_distribution_rebuild)
+         {
            ptr->ketama.next_distribution_rebuild= list[host_index].next_retry;
+         }
        }
      }
    }
    uint64_t is_ketama_weighted= memcached_behavior_get(ptr, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
    uint32_t points_per_server= (uint32_t) (is_ketama_weighted ? MEMCACHED_POINTS_PER_SERVER_KETAMA : MEMCACHED_POINTS_PER_SERVER);
  
-   if (live_servers == 0)
+   if (not live_servers)
+   {
      return MEMCACHED_SUCCESS;
+   }
  
    if (live_servers > ptr->ketama.continuum_count)
    {
            for (uint32_t x= 0; x < pointer_per_hash; x++)
            {
              uint32_t value= ketama_server_hash(sort_host, (size_t)sort_host_length, x);
 -             ptr->ketama.continuum[continuum_index].index= host_index;
 -             ptr->ketama.continuum[continuum_index++].value= value;
 +            ptr->ketama.continuum[continuum_index].index= host_index;
 +            ptr->ketama.continuum[continuum_index++].value= value;
            }
          }
          else
          {
-           uint32_t value= hashkit_digest(&ptr->distribution_hashkit, sort_host, (size_t)sort_host_length);
+           uint32_t value= hashkit_digest(&ptr->hashkit, sort_host, (size_t)sort_host_length);
            ptr->ketama.continuum[continuum_index].index= host_index;
            ptr->ketama.continuum[continuum_index++].value= value;
          }
          {
            for (uint32_t x = 0; x < pointer_per_hash; x++)
            {
 -             uint32_t value= ketama_server_hash(sort_host, (size_t)sort_host_length, x);
 -             ptr->ketama.continuum[continuum_index].index= host_index;
 -             ptr->ketama.continuum[continuum_index++].value= value;
 +            uint32_t value= ketama_server_hash(sort_host, (size_t)sort_host_length, x);
 +            ptr->ketama.continuum[continuum_index].index= host_index;
 +            ptr->ketama.continuum[continuum_index++].value= value;
            }
          }
          else
          {
-           uint32_t value= hashkit_digest(&ptr->distribution_hashkit, sort_host, (size_t)sort_host_length);
+           uint32_t value= hashkit_digest(&ptr->hashkit, sort_host, (size_t)sort_host_length);
            ptr->ketama.continuum[continuum_index].index= host_index;
            ptr->ketama.continuum[continuum_index++].value= value;
          }
@@@ -343,10 -376,16 +376,16 @@@ memcached_return_t memcached_server_pus
      /* TODO check return type */
      instance= memcached_server_create_with(ptr, instance, list[x].hostname,
                                             list[x].port, list[x].weight, list[x].type);
-     if (! instance)
+     if (not instance)
      {
-       return memcached_set_error(ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, NULL);
+       return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT);
      }
+     if (list[x].weight > 1)
+     {
+       ptr->ketama.weighted= true;
+     }
      ptr->number_of_hosts++;
    }
  
@@@ -388,10 -427,10 +427,10 @@@ memcached_return_t memcached_server_add
                                                          in_port_t port,
                                                          uint32_t weight)
  {
-   if (! port)
+   if (not port)
      port= MEMCACHED_DEFAULT_PORT;
  
-   if (! hostname)
+   if (not hostname)
      hostname= "localhost";
  
    return server_add(ptr, hostname, port, weight, MEMCACHED_CONNECTION_UDP);
@@@ -440,7 -479,14 +479,14 @@@ static memcached_return_t server_add(me
  
    /* TODO: Check return type */
    instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr));
    (void)memcached_server_create_with(ptr, instance, hostname, port, weight, type);
+   if (weight > 1)
+   {
+     ptr->ketama.weighted= true;
+   }
    ptr->number_of_hosts++;
  
    instance= memcached_server_instance_fetch(ptr, 0);
  
    return run_distribution(ptr);
  }
 +
 +memcached_return_t memcached_server_add_parsed(memcached_st *ptr,
 +                                               const char *hostname,
 +                                               size_t hostname_length,
 +                                               in_port_t port,
 +                                               uint32_t weight)
 +{
 +  char buffer[NI_MAXHOST];
 +
 +  memcpy(buffer, hostname, hostname_length);
 +  buffer[hostname_length]= 0;
 +
 +  return server_add(ptr, buffer,
 +                    port,
 +                    weight,
 +                    MEMCACHED_CONNECTION_TCP);
 +}
diff --combined libmemcached/server.h
index 98f5ed68553d1d29e069859a7c967d510fd34547,d4005f89c222cfb456916a2fdacc50e8e887aeae..b04410d64646a47cddf22c50ca740e64bf42cdb6
@@@ -1,17 -1,42 +1,42 @@@
- /* LibMemcached
-  * Copyright (C) 2006-2009 Brian Aker
-  * All rights reserved.
+ /*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+  * 
+  *  Libmemcached library
   *
-  * Use and distribution licensed under the BSD license.  See
-  * the COPYING file in the parent directory for full text.
+  *  Copyright (C) 2011 Data Differential, http://datadifferential.com/
+  *  Copyright (C) 2006-2009 Brian Aker All rights reserved.
   *
-  * Summary: String structure used for libmemcached.
+  *  Redistribution and use in source and binary forms, with or without
+  *  modification, are permitted provided that the following conditions are
+  *  met:
+  *
+  *      * Redistributions of source code must retain the above copyright
+  *  notice, this list of conditions and the following disclaimer.
+  *
+  *      * Redistributions in binary form must reproduce the above
+  *  copyright notice, this list of conditions and the following disclaimer
+  *  in the documentation and/or other materials provided with the
+  *  distribution.
+  *
+  *      * The names of its contributors may not be used to endorse or
+  *  promote products derived from this software without specific prior
+  *  written permission.
+  *
+  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   */
  
- #ifndef __LIBMEMCACHED_SERVER_H__
- #define __LIBMEMCACHED_SERVER_H__
  
+ #pragma once
  
  struct memcached_server_st {
    struct {
@@@ -44,7 -69,7 +69,7 @@@
    struct addrinfo *address_info;
    struct addrinfo *address_info_next;
    time_t next_retry;
-   const memcached_st *root;
+   memcached_st *root;
    uint64_t limit_maxbytes;
    char read_buffer[MEMCACHED_MAX_BUFFER];
    char write_buffer[MEMCACHED_MAX_BUFFER];
@@@ -93,13 -118,6 +118,13 @@@ LIBMEMCACHED_AP
  memcached_return_t memcached_server_add(memcached_st *ptr,
                                          const char *hostname, in_port_t port);
  
 +LIBMEMCACHED_LOCAL
 +  memcached_return_t memcached_server_add_parsed(memcached_st *ptr,
 +                                                 const char *hostname,
 +                                                 size_t hostname_length,
 +                                                 in_port_t port,
 +                                                 uint32_t weight);
 +
  LIBMEMCACHED_API
  memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr,
                                                          const char *hostname,
@@@ -134,5 -152,3 +159,3 @@@ const char *memcached_server_error(memc
  #ifdef __cplusplus
  } // extern "C"
  #endif
- #endif /* __LIBMEMCACHED_SERVER_H__ */