Changeset 7fe430


Ignore:
Timestamp:
01/18/08 16:37:01 (4 years ago)
Author:
Tomash Brechko <tomash.brechko@…>
Branches:
master-v0.7, master-v0.6, memcached_hash, upstream_count_limit
Children:
1e6e0c
Parents:
cab62c
git-author:
Tomash Brechko <tomash.brechko@…> (01/18/08 16:37:01)
git-committer:
Tomash Brechko <tomash.brechko@…> (01/18/08 16:37:01)
Message:

Rename bins to buckets.

Location:
memcached_hash
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • memcached_hash/TODO

    r4cec36 r7fe430  
    55- Add populate.pl to the distribution. 
    66 
    7 - Rename bins to buckets. 
     7- Implement cache of open connections to upstreams. 
  • memcached_hash/ngx_http_upstream_memcached_hash_module.c

    rc90b2b r7fe430  
    3636struct memcached_hash 
    3737{ 
    38   struct memcached_hash_continuum *bins; 
     38  struct memcached_hash_continuum *buckets; 
    3939  struct memcached_hash_peer *peers; 
    40   unsigned int bins_count; 
     40  unsigned int buckets_count; 
    4141  unsigned int peer_count; 
    4242  unsigned int total_weight; 
     
    5656static 
    5757unsigned int 
    58 memcached_hash_find_bin(struct memcached_hash *memd, unsigned int point) 
     58memcached_hash_find_bucket(struct memcached_hash *memd, unsigned int point) 
    5959{ 
    6060  struct memcached_hash_continuum *left, *right; 
    6161 
    62   left = memd->bins; 
    63   right = memd->bins + memd->bins_count; 
     62  left = memd->buckets; 
     63  right = memd->buckets + memd->buckets_count; 
    6464 
    6565  while (left < right) 
     
    7171        right = middle; 
    7272      else 
    73         return (middle - memd->bins); 
     73        return (middle - memd->buckets); 
    7474    } 
    7575 
    7676  /* Wrap around.  */ 
    77   if (left == memd->bins + memd->bins_count) 
    78     left = memd->bins; 
    79  
    80   return (left - memd->bins); 
     77  if (left == memd->buckets + memd->buckets_count) 
     78    left = memd->buckets; 
     79 
     80  return (left - memd->buckets); 
    8181} 
    8282 
     
    125125  u_char *key; 
    126126  size_t len; 
    127   unsigned int point, bin, index; 
     127  unsigned int point, bucket, index; 
    128128 
    129129  if (memd->peer_count == 1) 
     
    153153          /* 
    154154            Shift point one step forward to possibly get from the 
    155             border point which belongs to the previous bin. 
     155            border point which belongs to the previous bucket. 
    156156          */ 
    157157          point += 1; 
    158158        } 
    159159 
    160       bin = memcached_hash_find_bin(memd, point); 
    161       index = memd->bins[bin].index; 
     160      bucket = memcached_hash_find_bucket(memd, point); 
     161      index = memd->buckets[bucket].index; 
    162162    } 
    163163 
     
    241241  struct memcached_hash *memd = us->peer.data; 
    242242  ngx_http_upstream_server_t *server; 
    243   unsigned int bins_count, i; 
     243  unsigned int buckets_count, i; 
    244244 
    245245  if (! us->servers) 
     
    267267  if (memd->ketama_points == 0) 
    268268    { 
    269       bins_count = us->servers->nelts; 
     269      buckets_count = us->servers->nelts; 
    270270    } 
    271271  else 
    272272    { 
    273       bins_count = 0; 
     273      buckets_count = 0; 
    274274      for (i = 0; i < us->servers->nelts; ++i) 
    275         bins_count += (memd->ketama_points * server[i].weight 
    276                        + memd->scale / 2) / memd->scale; 
    277     } 
    278  
    279   memd->bins = ngx_palloc(cf->pool, sizeof(*memd->bins) * bins_count); 
    280   if (! memd->bins) 
     275        buckets_count += (memd->ketama_points * server[i].weight 
     276                          + memd->scale / 2) / memd->scale; 
     277    } 
     278 
     279  memd->buckets = ngx_palloc(cf->pool, sizeof(*memd->buckets) * buckets_count); 
     280  if (! memd->buckets) 
    281281    return NGX_ERROR; 
    282282 
     
    291291          for (j = 0; j < i; ++j) 
    292292            { 
    293               memd->bins[j].point = 
    294                 (memd->bins[j].point 
    295                  - ((uint64_t) memd->bins[j].point * server[i].weight 
     293              memd->buckets[j].point = 
     294                (memd->buckets[j].point 
     295                 - ((uint64_t) memd->buckets[j].point * server[i].weight 
    296296                    + total_weight / 2) / total_weight); 
    297297            } 
    298298 
    299           memd->bins[i].point = CONTINUUM_MAX_POINT; 
    300           memd->bins[i].index = i; 
    301         } 
    302       memd->bins_count = bins_count; 
     299          memd->buckets[i].point = CONTINUUM_MAX_POINT; 
     300          memd->buckets[i].index = i; 
     301        } 
     302      memd->buckets_count = buckets_count; 
    303303    } 
    304304  else 
    305305    { 
    306       memd->bins_count = 0; 
     306      memd->buckets_count = 0; 
    307307      for (i = 0; i < us->servers->nelts; ++i) 
    308308        { 
     
    344344            { 
    345345              u_char buf[4]; 
    346               unsigned int point = crc32, bin; 
     346              unsigned int point = crc32, bucket; 
    347347 
    348348              /* 
     
    358358              ngx_crc32_final(point); 
    359359 
    360               if (memd->bins_count > 0) 
     360              if (memd->buckets_count > 0) 
    361361                { 
    362                   bin = memcached_hash_find_bin(memd, point); 
     362                  bucket = memcached_hash_find_bucket(memd, point); 
    363363 
    364364                  /* 
     
    366366                    max point. 
    367367                  */ 
    368                   if (bin == 0 && point > memd->bins[0].point) 
     368                  if (bucket == 0 && point > memd->buckets[0].point) 
    369369                    { 
    370                       bin = memd->bins_count; 
     370                      bucket = memd->buckets_count; 
    371371                    } 
    372372                  else 
    373373                    { 
    374                       if (point == memd->bins[bin].point) 
     374                      if (point == memd->buckets[bucket].point) 
    375375                        { 
    376376                          /* 
     
    381381                            server for not to change key distribution. 
    382382                            */ 
    383                           ++bin; 
     383                          ++bucket; 
    384384                        } 
    385385 
    386386                      /* Move the tail one position forward.  */ 
    387                       ngx_memmove(memd->bins + bin + 1, memd->bins + bin, 
    388                                   ((memd->bins_count - bin) 
    389                                    * sizeof(*memd->bins))); 
     387                      ngx_memmove(memd->buckets + bucket + 1, 
     388                                  memd->buckets + bucket, 
     389                                  ((memd->buckets_count - bucket) 
     390                                   * sizeof(*memd->buckets))); 
    390391                    } 
    391392                } 
    392393              else 
    393394                { 
    394                   bin = 0; 
     395                  bucket = 0; 
    395396                } 
    396397 
    397               memd->bins[bin].point = point; 
    398               memd->bins[bin].index = i; 
    399  
    400               ++memd->bins_count; 
     398              memd->buckets[bucket].point = point; 
     399              memd->buckets[bucket].index = i; 
     400 
     401              ++memd->buckets_count; 
    401402            } 
    402403        } 
Note: See TracChangeset for help on using the changeset viewer.