Permalink
Browse files

misc fixes as suggested by avva. lot of comment updates, mostly.

git-svn-id: http://code.sixapart.com/svn/memcached/trunk@35 b0b603af-a30f-0410-a34e-baf09ae79d0b
  • Loading branch information...
1 parent f6d334e commit 7917af40da246fa99ca27734b31af2ae2ac1b54a @bradfitz bradfitz committed Jun 22, 2003
Showing with 25 additions and 26 deletions.
  1. +3 −2 BUILD
  2. +0 −1 README
  3. +7 −8 assoc.c
  4. +1 −1 items.c
  5. +12 −12 memcached.c
  6. +2 −2 memcached.h
View
5 BUILD
@@ -1,10 +1,11 @@
Ideally, you want to make a static binary, otherwise the dynamic
linker pollutes your address space with shared libs right in the
-middle.
+middle. (NOTE: actually, this shouldn't matter so much anymore, now
+that we only allocate huge, fixed-size slabs)
Make sure your libevent has epoll (Linux) or kqueue (BSD) support.
Using poll or select only is slow, and works for testing, but
-shouldn't be used for high-traffice memcache installations.
+shouldn't be used for high-traffic memcache installations.
To build libevent with epoll on Linux, you need:
View
1 README
@@ -1,6 +1,5 @@
Dependencies:
- -- Judy, http://judy.sf.net/ (Debian package libjudy-dev)
-- libevent, http://www.monkey.org/~provos/libevent/ (libevent-dev)
If using Linux, you need a kernel with epoll. Sure, libevent will
View
15 assoc.c
@@ -151,8 +151,8 @@ item *assoc_find(char *key) {
return 0;
}
-/* returns the address of a item* before the key. if *item == 0,
- the item wasn't found, and a new node should be allocated */
+/* returns the address of the item pointer before the key. if *item == 0,
+ the item wasn't found */
static item** _hashitem_before (char *key) {
ub4 hv = hash(key, strlen(key), 0) & hashmask(HASHPOWER);
@@ -164,12 +164,11 @@ static item** _hashitem_before (char *key) {
return pos;
}
+/* Note: this isn't an assoc_update. The key must not already exist to call this */
int assoc_insert(char *key, item *it) {
- item **before = _hashitem_before(key);
- /* Note: in practice, *before is always 0, as the callers always unlink the old
- item before replacing it with a new item of the same key. TODO: assert? */
- it->h_next = *before ? (*before)->h_next : 0;
- *before = it;
+ ub4 hv = hash(key, strlen(key), 0) & hashmask(HASHPOWER);
+ it->h_next = hashtable[hv];
+ hashtable[hv] = it;
return 1;
}
@@ -181,7 +180,7 @@ void assoc_delete(char *key) {
*before = nxt;
return;
}
- /* Note: we actually get here. the callers don't delete things
+ /* Note: we never actually get here. the callers don't delete things
they can't find. TODO: assert? */
}
View
@@ -129,7 +129,7 @@ void item_unlink_q(item *it) {
int item_link(item *it) {
it->it_flags |= ITEM_LINKED;
it->time = time(0);
- assoc_insert(ITEM_key(it), (void *)it);
+ assoc_insert(ITEM_key(it), it);
stats.curr_bytes += ITEM_ntotal(it);
stats.curr_items += 1;
View
@@ -219,7 +219,7 @@ void complete_nread(conn *c) {
break;
}
- old_it = (item *)assoc_find(ITEM_key(it));
+ old_it = assoc_find(ITEM_key(it));
if (old_it && old_it->exptime && old_it->exptime < now) {
item_unlink(old_it);
@@ -420,13 +420,13 @@ void process_command(conn *c, char *command) {
(strncmp(command, "set ", 4) == 0 && (comm = NREAD_SET)) ||
(strncmp(command, "replace ", 8) == 0 && (comm = NREAD_REPLACE))) {
- char key[256];
+ char key[251];
int flags;
time_t expire;
int len, res;
item *it;
- res = sscanf(command, "%*s %255s %u %lu %d\n", key, &flags, &expire, &len);
+ res = sscanf(command, "%*s %250s %u %lu %d\n", key, &flags, &expire, &len);
if (res!=4 || strlen(key)==0 ) {
out_string(c, "CLIENT_ERROR bad command line format");
return;
@@ -454,12 +454,12 @@ void process_command(conn *c, char *command) {
unsigned int value;
item *it;
unsigned int delta;
- char key[255];
+ char key[251];
int res;
char *ptr;
time_t now = time(0);
- res = sscanf(command, "%*s %255s %u\n", key, &delta);
+ res = sscanf(command, "%*s %250s %u\n", key, &delta);
if (res!=2 || strlen(key)==0 ) {
out_string(c, "CLIENT_ERROR bad command line format");
return;
@@ -514,16 +514,16 @@ void process_command(conn *c, char *command) {
if (strncmp(command, "get ", 4) == 0) {
char *start = command + 4;
- char key[256];
+ char key[251];
int next;
int i = 0;
item *it;
time_t now = time(0);
- while(sscanf(start, " %255s%n", key, &next) >= 1) {
+ while(sscanf(start, " %250s%n", key, &next) >= 1) {
start+=next;
stats.get_cmds++;
- it = (item *)assoc_find(key);
+ it = assoc_find(key);
if (it && (it->it_flags & ITEM_DELETED)) {
it = 0;
}
@@ -558,11 +558,11 @@ void process_command(conn *c, char *command) {
}
if (strncmp(command, "delete ", 7) == 0) {
- char key[256];
+ char key[251];
char *start = command+7;
item *it;
- sscanf(start, " %255s", key);
+ sscanf(start, " %250s", key);
it = assoc_find(key);
if (!it) {
out_string(c, "NOT_FOUND");
@@ -862,10 +862,10 @@ void drive_machine(conn *c) {
case conn_mwrite:
/*
* we're writing ibytes bytes from iptr. iptr alternates between
- * ibuf, where we build a string "VALUE...", and it->data for the
+ * ibuf, where we build a string "VALUE...", and ITEM_data(it) for the
* current item. When we finish a chunk, we choose the next one using
* ipart, which has the following semantics: 0 - start the loop, 1 -
- * we finished ibuf, go to current it->data; 2 - we finished it->data,
+ * we finished ibuf, go to current ITEM_data(it); 2 - we finished ITEM_data(it),
* move to the next item and build its ibuf; 3 - we finished all items,
* write "END".
*/
View
@@ -52,7 +52,7 @@ typedef struct _stritem {
#define ITEM_key(item) ((char*)&((item)->end[0]))
/* warning: don't use these macros with a function, as it evals its arg twice */
-#define ITEM_data(item) ((void*) &((item)->end[0]) + (item)->nkey)
+#define ITEM_data(item) ((char*) &((item)->end[0]) + (item)->nkey)
#define ITEM_ntotal(item) (sizeof(struct _stritem) + (item)->nkey + (item)->nbytes)
enum conn_states {
@@ -95,7 +95,7 @@ typedef struct {
/*
* item is used to hold an item structure created after reading the command
* line of set/add/replace commands, but before we finished reading the actual
- * data. The data is read into item->data to avoid extra copying.
+ * data. The data is read into ITEM_data(item) to avoid extra copying.
*/
void *item; /* for commands set/add/replace */

0 comments on commit 7917af4

Please sign in to comment.