Changeset 70e5d7
- Timestamp:
- 01/06/08 21:55:16 (4 years ago)
- Branches:
- master, ketama-compat
- Children:
- 4c792d
- Parents:
- 3a7104
- git-author:
- Tomash Brechko <tomash.brechko@…> (01/06/08 18:37:10)
- git-committer:
- Tomash Brechko <tomash.brechko@…> (01/06/08 21:55:16)
- Files:
-
- 2 added
- 5 edited
-
MANIFEST (modified) (1 diff)
-
TODO (modified) (3 diffs)
-
src/array.c (added)
-
src/array.h (added)
-
src/client.c (modified) (36 diffs)
-
src/dispatch_key.c (modified) (14 diffs)
-
src/dispatch_key.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
MANIFEST
r381e4f r70e5d7 24 24 src/genparser.pl 25 25 src/reply.kw 26 src/array.h 27 src/array.c 26 28 src/client.h 27 29 src/client.c -
TODO
r3a7104 r70e5d7 21 21 - UDP (?). 22 22 23 - Investigate why there are read() errors in no_eagain branch. 24 25 - In find_bin() replace binary search with interpolation search. 26 27 - Add test for noreply, do not list it in MANIFEST. 28 23 29 24 30 For 0.07: … … 29 35 instance. 30 36 31 - Add test for noreply, do not list it in MANIFEST.32 33 37 - Clean warnings for gcc 4.2.2. 34 38 35 39 - Fix all ugliness introduced in 0.06 ;). 36 37 - Investigate why there are read() errors in no_eagain branch.38 40 39 41 - Replace av_push() with av_store(), test result. … … 45 47 - Rename bins to buckets. 46 48 47 - In find_bin() replace binary search with interpolation search.48 49 49 - Improve server_versions command. -
src/client.c
r3a7104 r70e5d7 23 23 24 24 #include "client.h" 25 #include "array.h" 25 26 #include "connect.h" 26 27 #include "parse_keyword.h" … … 284 285 struct client 285 286 { 286 struct server *servers; 287 int server_count; 288 int server_capacity; 287 struct array servers; 289 288 290 289 struct dispatch_state dispatch; … … 301 300 int nowait; 302 301 303 struct key_node *key_list; 304 int key_list_count; 305 int key_list_capacity; 302 struct array key_list; 306 303 307 304 generation_type generation; … … 357 354 get_key_index(struct command_state *state) 358 355 { 359 return state->client->key_list[state->key_head].key; 356 struct key_node *node = 357 array_elem(state->client->key_list, struct key_node, state->key_head); 358 return node->key; 360 359 } 361 360 … … 365 364 next_key_index(struct command_state *state) 366 365 { 367 state->key_head = state->client->key_list[state->key_head].next; 366 struct key_node *node = 367 array_elem(state->client->key_list, struct key_node, state->key_head); 368 state->key_head = node->next; 368 369 } 369 370 … … 376 377 return NULL; 377 378 378 c->servers = NULL;379 c->server_count = c->server_capacity = 0;379 array_init(&c->servers); 380 array_init(&c->key_list); 380 381 381 382 dispatch_init(&c->dispatch); … … 392 393 c->nowait = 0; 393 394 394 c->key_list = NULL;395 c->key_list_count = c->key_list_capacity = 0;396 397 395 c->generation = 1; /* Different from initial command state. */ 398 396 … … 404 402 client_destroy(struct client *c) 405 403 { 404 struct server *s; 406 405 int i; 407 406 408 407 client_nowait_push(c); 409 408 410 for (i = 0; i < c->server_count; ++i) 411 server_destroy(&c->servers[i]); 409 for (s = array_beg(c->servers, struct server); 410 s != array_end(c->servers, struct server); 411 ++s) 412 server_destroy(s); 412 413 413 414 dispatch_destroy(&c->dispatch); 414 415 415 free(c->servers); 416 array_destroy(&c->servers); 417 array_destroy(&c->key_list); 416 418 free(c->prefix); 417 free(c->key_list);418 419 free(c); 419 420 } … … 424 425 { 425 426 /* Should be called before we added any server. */ 426 if ( c->server_count > 0|| ketama_points < 0)427 if (! array_empty(c->servers) || ketama_points < 0) 427 428 return MEMCACHED_FAILURE; 428 429 … … 485 486 return MEMCACHED_FAILURE; 486 487 487 if (c->server_count == c->server_capacity) 488 { 489 int capacity = (c->server_capacity > 0 ? c->server_capacity + 1 : 1); 490 struct server *s = 491 (struct server *) realloc(c->servers, 492 capacity * sizeof(struct server)); 493 if (! s) 494 return MEMCACHED_FAILURE; 495 496 c->servers = s; 497 c->server_capacity = capacity; 498 } 499 500 res = server_init(&c->servers[c->server_count], c, 488 if (array_extend(c->servers, struct server, 1, ARRAY_EXTEND_EXACT) == -1) 489 return MEMCACHED_FAILURE; 490 491 res = server_init(array_end(c->servers, struct server), c, 501 492 host, host_len, port, port_len, noreply); 502 493 if (res != MEMCACHED_SUCCESS) … … 504 495 505 496 res = dispatch_add_server(&c->dispatch, host, host_len, port, port_len, 506 weight, c->server_count);497 weight, array_size(c->servers)); 507 498 if (res == -1) 508 499 return MEMCACHED_FAILURE; 509 500 510 ++c->server_count;501 array_push(c->servers); 511 502 512 503 return MEMCACHED_SUCCESS; … … 1260 1251 static 1261 1252 void 1262 client_mark_failed(struct client *c, int server_index) 1263 { 1264 struct server *s; 1265 1266 s = &c->servers[server_index]; 1267 1253 client_mark_failed(struct client *c, struct server *s) 1254 { 1268 1255 if (s->cmd_state.fd != -1) 1269 1256 { … … 1318 1305 while (1) 1319 1306 { 1320 int max_fd, i, res; 1307 struct server *s; 1308 int max_fd, res; 1321 1309 1322 1310 max_fd = -1; 1323 for (i = 0; i < c->server_count; ++i) 1311 for (s = array_beg(c->servers, struct server); 1312 s != array_end(c->servers, struct server); 1313 ++s) 1324 1314 { 1325 1315 int may_write, may_read; 1326 struct command_state *state = & c->servers[i].cmd_state;1316 struct command_state *state = &s->cmd_state; 1327 1317 1328 1318 if (! is_active(state)) … … 1390 1380 case MEMCACHED_CLOSED: 1391 1381 deactivate(state); 1392 client_mark_failed(c, i);1382 client_mark_failed(c, s); 1393 1383 break; 1394 1384 } … … 1412 1402 FD_ZERO(&write_set); 1413 1403 FD_ZERO(&read_set); 1414 for (i = 0; i < c->server_count; ++i) 1404 for (s = array_beg(c->servers, struct server); 1405 s != array_end(c->servers, struct server); 1406 ++s) 1415 1407 { 1416 struct command_state *state = & c->servers[i].cmd_state;1408 struct command_state *state = &s->cmd_state; 1417 1409 1418 1410 if (is_active(state)) … … 1447 1439 if (res <= 0) 1448 1440 { 1449 for (i = 0; i < c->server_count; ++i) 1441 for (s = array_beg(c->servers, struct server); 1442 s != array_end(c->servers, struct server); 1443 ++s) 1450 1444 { 1451 struct command_state *state = & c->servers[i].cmd_state;1445 struct command_state *state = &s->cmd_state; 1452 1446 1453 1447 if (is_active(state)) … … 1460 1454 state->u.value.object->free(state->u.value.opaque); 1461 1455 1462 client_mark_failed(c, i);1456 client_mark_failed(c, s); 1463 1457 } 1464 1458 } … … 1484 1478 static 1485 1479 int 1486 get_server_fd(struct client *c, int index) 1487 { 1488 struct server *s; 1480 get_server_fd(struct client *c, struct server *s) 1481 { 1489 1482 struct command_state *state; 1490 1491 s = &c->servers[index];1492 1483 1493 1484 /* … … 1518 1509 1519 1510 if (state->fd == -1) 1520 client_mark_failed(c, index);1511 client_mark_failed(c, s); 1521 1512 1522 1513 return state->fd; … … 1525 1516 1526 1517 static 1527 int 1528 client_get_server_index(struct client *c, const char *key, size_t key_len) 1529 { 1518 struct server * 1519 client_get_server(struct client *c, const char *key, size_t key_len) 1520 { 1521 struct server *s; 1530 1522 int index, fd; 1531 1523 1532 1524 index = dispatch_key(&c->dispatch, key, key_len); 1533 1525 if (index == -1) 1534 return -1; 1535 1536 fd = get_server_fd(c, index); 1526 return NULL; 1527 1528 s = array_elem(c->servers, struct server, index); 1529 1530 fd = get_server_fd(c, s); 1537 1531 if (fd == -1) 1538 return -1;1539 1540 return index;1532 return NULL; 1533 1534 return s; 1541 1535 } 1542 1536 … … 1581 1575 1582 1576 c = state->client; 1583 if (c->key_list_count == c->key_list_capacity) 1584 { 1585 int capacity = (c->key_list_capacity > 0 ? c->key_list_capacity * 2 : 1); 1586 struct key_node *list = 1587 (struct key_node *) realloc(c->key_list, 1588 sizeof(struct key_node) * capacity); 1589 if (! list) 1590 return MEMCACHED_FAILURE; 1591 1592 c->key_list = list; 1593 c->key_list_capacity = capacity; 1594 } 1577 if (array_extend(c->key_list, struct key_node, 1, ARRAY_EXTEND_TWICE) == -1) 1578 return MEMCACHED_FAILURE; 1595 1579 1596 1580 if (state->key_tail != -1) 1597 c->key_list[state->key_tail].next = c->key_list_count; 1581 array_elem(c->key_list, struct key_node, state->key_tail)->next = 1582 array_size(c->key_list); 1598 1583 else 1599 state->key_head = c->key_list_count;1600 1601 state->key_tail = c->key_list_count;1602 1603 node = &c->key_list[state->key_tail];1584 state->key_head = array_size(c->key_list); 1585 1586 state->key_tail = array_size(c->key_list); 1587 1588 node = array_elem(c->key_list, struct key_node, state->key_tail); 1604 1589 node->key = key_index; 1605 1590 node->next = -1; 1606 1591 1607 ++c->key_list_count;1592 array_push(c->key_list); 1608 1593 1609 1594 return MEMCACHED_SUCCESS; … … 1615 1600 client_reset_for_command(struct client *c) 1616 1601 { 1617 c->key_list_count = 0;1602 array_clear(c->key_list); 1618 1603 ++c->generation; 1619 1604 } … … 1635 1620 + sizeof(" " FLAGS_STUB " " EXPTIME_STUB " " VALUE_SIZE_STUB 1636 1621 " " NOREPLY "\r\n")); 1622 struct server *s; 1637 1623 struct command_state *state; 1638 1624 struct iovec *buf_iov; 1639 1625 char *buf; 1640 int server_index,res;1626 int res; 1641 1627 1642 1628 client_reset_for_command(c); 1643 1629 1644 s erver_index = client_get_server_index(c, key, key_len);1645 if ( server_index == -1)1630 s = client_get_server(c, key, key_len); 1631 if (! s) 1646 1632 return MEMCACHED_CLOSED; 1647 1633 1648 state = & c->servers[server_index].cmd_state;1634 state = &s->cmd_state; 1649 1635 use_noreply = (noreply && state->noreply); 1650 1636 command_state_reset(state, (c->prefix_len ? 2 : 1), 1, … … 1712 1698 + sizeof(" " FLAGS_STUB " " EXPTIME_STUB " " VALUE_SIZE_STUB 1713 1699 " " CAS_STUB " " NOREPLY "\r\n")); 1700 struct server *s; 1714 1701 struct command_state *state; 1715 1702 struct iovec *buf_iov; 1716 1703 char *buf; 1717 int server_index,res;1704 int res; 1718 1705 1719 1706 client_reset_for_command(c); 1720 1707 1721 s erver_index = client_get_server_index(c, key, key_len);1722 if ( server_index == -1)1708 s = client_get_server(c, key, key_len); 1709 if (! s) 1723 1710 return MEMCACHED_CLOSED; 1724 1711 1725 state = & c->servers[server_index].cmd_state;1712 state = &s->cmd_state; 1726 1713 use_noreply = (noreply && state->noreply); 1727 1714 command_state_reset(state, (c->prefix_len ? 2 : 1), 1, … … 1762 1749 { 1763 1750 size_t request_size = (sizeof(struct iovec) * (c->prefix_len ? 4 : 3)); 1751 struct server *s; 1764 1752 struct command_state *state; 1765 int server_index,res;1753 int res; 1766 1754 1767 1755 client_reset_for_command(c); 1768 1756 1769 s erver_index = client_get_server_index(c, key, key_len);1770 if ( server_index == -1)1757 s = client_get_server(c, key, key_len); 1758 if (! s) 1771 1759 return MEMCACHED_CLOSED; 1772 1760 1773 state = & c->servers[server_index].cmd_state;1761 state = &s->cmd_state; 1774 1762 command_state_reset(state, (c->prefix_len ? 2 : 1), 1, parse_get_reply); 1775 1763 value_state_reset(&state->u.value, o, (cmd == CMD_GETS)); … … 1809 1797 size_t min_request_size = 1810 1798 (sizeof(struct iovec) * ((c->prefix_len ? 3 : 2) + 2)); 1799 struct server *s; 1811 1800 struct command_state *state; 1812 1801 int i; … … 1819 1808 size_t key_len; 1820 1809 size_t size; 1821 int server_index,res;1810 int res; 1822 1811 1823 1812 key = get_key(o->arg, i, &key_len); 1824 1813 1825 s erver_index = client_get_server_index(c, key, key_len);1826 if ( server_index == -1)1814 s = client_get_server(c, key, key_len); 1815 if (! s) 1827 1816 continue; 1828 1817 1829 state = & c->servers[server_index].cmd_state;1818 state = &s->cmd_state; 1830 1819 1831 1820 if (is_active(state)) … … 1873 1862 } 1874 1863 1875 for (i = 0; i < c->server_count; ++i) 1876 { 1877 state = &c->servers[i].cmd_state; 1864 for (s = array_beg(c->servers, struct server); 1865 s != array_end(c->servers, struct server); 1866 ++s) 1867 { 1868 state = &s->cmd_state; 1878 1869 1879 1870 if (is_active(state)) … … 1898 1889 (sizeof(struct iovec) * (c->prefix_len ? 4 : 3) 1899 1890 + sizeof(" " ARITH_STUB " " NOREPLY "\r\n")); 1891 struct server *s; 1900 1892 struct command_state *state; 1901 1893 struct iovec *buf_iov; 1902 1894 char *buf; 1903 int server_index,res;1895 int res; 1904 1896 1905 1897 client_reset_for_command(c); 1906 1898 1907 s erver_index = client_get_server_index(c, key, key_len);1908 if ( server_index == -1)1899 s = client_get_server(c, key, key_len); 1900 if (! s) 1909 1901 return MEMCACHED_CLOSED; 1910 1902 1911 state = & c->servers[server_index].cmd_state;1903 state = &s->cmd_state; 1912 1904 use_noreply = (noreply && state->noreply); 1913 1905 command_state_reset(state, (c->prefix_len ? 2 : 1), 1, … … 1958 1950 (sizeof(struct iovec) * (c->prefix_len ? 4 : 3) 1959 1951 + sizeof(" " DELAY_STUB " " NOREPLY "\r\n")); 1952 struct server *s; 1960 1953 struct command_state *state; 1961 1954 struct iovec *buf_iov; 1962 1955 char *buf; 1963 int server_index,res;1956 int res; 1964 1957 1965 1958 client_reset_for_command(c); 1966 1959 1967 s erver_index = client_get_server_index(c, key, key_len);1968 if ( server_index == -1)1960 s = client_get_server(c, key, key_len); 1961 if (! s) 1969 1962 return MEMCACHED_CLOSED; 1970 1963 1971 state = & c->servers[server_index].cmd_state;1964 state = &s->cmd_state; 1972 1965 use_noreply = (noreply && state->noreply); 1973 1966 command_state_reset(state, (c->prefix_len ? 2 : 1), 1, … … 2005 1998 (sizeof(struct iovec) * 1 2006 1999 + sizeof("flush_all " DELAY_STUB " " NOREPLY "\r\n")); 2000 struct server *s; 2007 2001 double ddelay = delay, delay_step = 0.0; 2008 2002 int i; … … 2010 2004 client_reset_for_command(c); 2011 2005 2012 if ( c->server_count> 1)2013 delay_step = ddelay / ( c->server_count- 1);2006 if (array_size(c->servers) > 1) 2007 delay_step = ddelay / (array_size(c->servers) - 1); 2014 2008 ddelay += delay_step; 2015 2009 2016 for (i = 0; i < c->server_count; ++i) 2010 for (s = array_beg(c->servers, struct server); 2011 s != array_end(c->servers, struct server); 2012 ++s) 2017 2013 { 2018 2014 int use_noreply; … … 2024 2020 ddelay -= delay_step; 2025 2021 2026 fd = get_server_fd(c, i);2022 fd = get_server_fd(c, s); 2027 2023 if (fd == -1) 2028 2024 continue; 2029 2025 2030 state = & c->servers[i].cmd_state;2026 state = &s->cmd_state; 2031 2027 use_noreply = (noreply && state->noreply); 2032 2028 command_state_reset(state, 0, 0, … … 2056 2052 client_nowait_push(struct client *c) 2057 2053 { 2054 struct server *s; 2058 2055 int i; 2059 2056 … … 2063 2060 client_reset_for_command(c); 2064 2061 2065 for (i = 0; i < c->server_count; ++i) 2062 for (s = array_beg(c->servers, struct server); 2063 s != array_end(c->servers, struct server); 2064 ++s) 2066 2065 { 2067 2066 struct command_state *state; 2068 2067 int fd, res; 2069 2068 2070 state = & c->servers[i].cmd_state;2069 state = &s->cmd_state; 2071 2070 if (state->nowait_count == 0) 2072 2071 continue; 2073 2072 2074 fd = get_server_fd(c, i);2073 fd = get_server_fd(c, s); 2075 2074 if (fd == -1) 2076 2075 continue; … … 2092 2091 { 2093 2092 static const size_t request_size = (sizeof(struct iovec) * 1); 2093 struct server *s; 2094 2094 int i; 2095 2095 2096 2096 client_reset_for_command(c); 2097 2097 2098 for (i = 0; i < c->server_count; ++i) 2098 for (s = array_beg(c->servers, struct server); 2099 s != array_end(c->servers, struct server); 2100 ++s) 2099 2101 { 2100 2102 struct command_state *state; 2101 2103 int fd, res; 2102 2104 2103 fd = get_server_fd(c, i);2105 fd = get_server_fd(c, s); 2104 2106 if (fd == -1) 2105 2107 continue; 2106 2108 2107 state = & c->servers[i].cmd_state;2109 state = &s->cmd_state; 2108 2110 command_state_reset(state, 0, 0, parse_version_reply); 2109 2111 embedded_state_reset(&state->u.embedded, o); -
src/dispatch_key.c
rcd76f9 r70e5d7 39 39 40 40 41 struct dispatch_continuum_point41 struct continuum_point 42 42 { 43 43 unsigned int point; … … 46 46 47 47 48 static inline49 int50 extend_bins(struct dispatch_state *state, int add)51 {52 int capacity =53 (state->bins_capacity > 0 ? state->bins_capacity + add : add);54 struct dispatch_continuum_point *b =55 (struct dispatch_continuum_point *)56 realloc(state->bins,57 capacity * sizeof(struct dispatch_continuum_point));58 59 if (! b)60 return -1;61 62 state->bins = b;63 state->bins_capacity = capacity;64 65 return 0;66 }67 68 69 48 static 70 int 49 struct continuum_point * 71 50 dispatch_find_bin(struct dispatch_state *state, unsigned int point) 72 51 { 73 struct dispatch_continuum_point*left, *right;74 75 left = state->bins;76 right = state->bins + state->bins_count;52 struct continuum_point *beg, *end, *left, *right; 53 54 beg = left = array_beg(state->bins, struct continuum_point); 55 end = right = array_end(state->bins, struct continuum_point); 77 56 78 57 while (left < right) 79 58 { 80 struct dispatch_continuum_point *middle = left + (right - left) / 2;59 struct continuum_point *middle = left + (right - left) / 2; 81 60 if (middle->point < point) 82 61 left = middle + 1; … … 84 63 right = middle; 85 64 else 86 return (middle - state->bins);65 return middle; 87 66 } 88 67 89 68 /* Wrap around. */ 90 if (left == state->bins + state->bins_count)91 left = state->bins;92 93 return (left - state->bins);69 if (left == end) 70 left = beg; 71 72 return left; 94 73 } 95 74 … … 106 85 int i; 107 86 double scale; 108 109 if (state->bins_count == state->bins_capacity) 110 { 111 int res = extend_bins(state, 1); 112 if (res == -1) 113 return -1; 114 } 87 struct continuum_point *p; 88 89 if (array_extend(state->bins, struct continuum_point, 90 1, ARRAY_EXTEND_EXACT) == -1) 91 return -1; 115 92 116 93 state->total_weight += weight; 117 94 scale = (1 - weight / state->total_weight); 118 for (i = 0; i < state->bins_count; ++i) 119 state->bins[i].point = ((double) state->bins[i].point * scale + 0.5); 120 121 state->bins[state->bins_count].point = DISPATCH_MAX_POINT; 122 state->bins[state->bins_count].index = index; 123 124 ++state->bins_count; 95 for (p = array_beg(state->bins, struct continuum_point); 96 p != array_end(state->bins, struct continuum_point); 97 ++p) 98 p->point = ((double) p->point * scale + 0.5); 99 100 p->point = DISPATCH_MAX_POINT; 101 p->index = index; 102 array_push(state->bins); 125 103 126 104 return 0; … … 143 121 server index. 144 122 */ 145 int bin;123 struct continuum_point *p; 146 124 unsigned int crc32 = compute_crc32(key, key_len); 147 125 unsigned int hash = ((crc32 >> 16) & 0x00007fff); … … 155 133 point += 1; 156 134 157 bin= dispatch_find_bin(state, point);158 return state->bins[bin].index;135 p = dispatch_find_bin(state, point); 136 return p->index; 159 137 } 160 138 … … 173 151 count = (state->ketama_points * weight + 0.5); 174 152 175 if (state->bins_count + count > state->bins_capacity) 176 { 177 int add = state->bins_count + count - state->bins_capacity; 178 int res = extend_bins(state, add); 179 if (res == -1) 180 return -1; 181 } 153 if (array_extend(state->bins, struct continuum_point, 154 count, ARRAY_EXTEND_EXACT) == -1) 155 return -1; 182 156 183 157 crc32 = compute_crc32(host, host_len); … … 189 163 char buf[4]; 190 164 unsigned int point; 191 int bin;165 struct continuum_point *p; 192 166 193 167 /* … … 202 176 point = compute_crc32_add(crc32, buf, 4); 203 177 204 if ( state->bins_count > 0)178 if (! array_empty(state->bins)) 205 179 { 206 bin= dispatch_find_bin(state, point);180 p = dispatch_find_bin(state, point); 207 181 208 182 /* Check if we wrapped around but actually have new max point. */ 209 if (bin == 0 && point > state->bins[0].point) 183 if (p == array_beg(state->bins, struct continuum_point) 184 && point > p->point) 210 185 { 211 bin = state->bins_count;186 p = array_end(state->bins, struct continuum_point); 212 187 } 213 188 else 214 189 { 215 if (point == state->bins[bin].point)190 if (point == p->point) 216 191 { 217 192 /* … … 222 197 distribution. 223 198 */ 224 ++ bin;199 ++p; 225 200 } 226 201 227 202 /* Move the tail one position forward. */ 228 memmove(state->bins + bin + 1, state->bins + bin, 229 (state->bins_count - bin) * sizeof(*state->bins)); 203 memmove(p + 1, p, 204 ((array_end(state->bins, struct continuum_point) - p) 205 * sizeof(*p))); 230 206 } 231 207 } 232 208 else 233 209 { 234 bin = 0;210 p = array_beg(state->bins, struct continuum_point); 235 211 } 236 212 237 state->bins[bin].point = point; 238 state->bins[bin].index = index; 239 240 ++state->bins_count; 213 p->point = point; 214 p->index = index; 215 array_push(state->bins); 241 216 } 242 217 … … 251 226 { 252 227 unsigned int point = compute_crc32(key, key_len); 253 int bin= dispatch_find_bin(state, point);254 return state->bins[bin].index;228 struct continuum_point *p = dispatch_find_bin(state, point); 229 return p->index; 255 230 } 256 231 … … 259 234 dispatch_init(struct dispatch_state *state) 260 235 { 261 state->bins = NULL; 262 state->bins_count = state->bins_capacity = 0; 236 array_init(&state->bins); 263 237 state->total_weight = 0.0; 264 238 state->ketama_points = 0; … … 269 243 dispatch_destroy(struct dispatch_state *state) 270 244 { 271 free(state->bins);245 array_destroy(&state->bins); 272 246 } 273 247 … … 297 271 dispatch_key(struct dispatch_state *state, const char *key, size_t key_len) 298 272 { 299 if ( state->bins_count == 0)273 if (array_empty(state->bins)) 300 274 return -1; 301 275 302 if (state->bins_count == 1) 303 { 304 return state->bins[0].index; 276 if (array_size(state->bins) == 1) 277 { 278 struct continuum_point *p = 279 array_beg(state->bins, struct continuum_point); 280 return p->index; 305 281 } 306 282 else -
src/dispatch_key.h
rcd76f9 r70e5d7 25 25 #define DISPATCH_KEY_H 1 26 26 27 #include "array.h" 27 28 #include <stddef.h> 28 29 30 struct dispatch_continuum_point;31 29 32 30 33 31 struct dispatch_state 34 32 { 35 struct dispatch_continuum_point *bins; 36 int bins_count; 37 int bins_capacity; 33 struct array bins; 38 34 double total_weight; 39 35 int ketama_points;
Note: See TracChangeset
for help on using the changeset viewer.
