Changeset 620

Show
Ignore:
Timestamp:
10/03/07 22:27:28 (1 year ago)
Author:
plindner
Message:

Add append command support written by Filipe Laborde. Tests/protocol doc updates by me.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/server/ChangeLog

    r619 r620  
    1515        * Switch to unsigned 64-bit increment/decrement counters 
    1616          from Evan Miller and Dusgtin Sallings. 
     17 
     18        * Add append command support written by Filipe Laborde. 
     19          Tests/protocol doc updates by myself. 
    1720 
    18212007-08-21 Paul Lindner <lindner@inuus.com> 
  • trunk/server/doc/protocol.txt

    r619 r620  
    5454There are three types of commands.  
    5555 
    56 Storage commands (there are four: "set", "add", "replace", and "cas") 
    57 ask the server to store some data identified by a key. The client 
    58 sends a command line, and then a data block; after that the client 
    59 expects one line of response, which will indicate success or faulure. 
     56Storage commands (there are five: "set", "add", "replace", "append" 
     57and "cas") ask the server to store some data identified by a key. The 
     58client sends a command line, and then a data block; after that the 
     59client expects one line of response, which will indicate success or 
     60faulure. 
    6061 
    6162Retrieval commands (there are two: "get" and "gets") ask the server to 
     
    128129<command name> <key> <flags> <exptime> <bytes> [<unqiue>]\r\n 
    129130 
    130 - <command name> is "set", "add", "replace", or "cas" 
     131- <command name> is "set", "add", "replace", "append", or "cas" 
    131132 
    132133  "set" means "store this data".   
     
    137138  "replace" means "store this data, but only if the server *does* 
    138139  already hold data for this key". 
     140 
     141  "append" means "add this data to an existing key". 
    139142 
    140143  "cas" is a check and set operation which means "store this data but 
     
    183186- "EXISTS\r\n" to indicate that the item you are trying to store with 
    184187a "cas" command has been modified since you last fetched it. 
     188 
    185189 
    186190Retrieval command: 
  • trunk/server/memcached.c

    r619 r620  
    11601160    int flags; 
    11611161    time_t exptime; 
    1162     int vlen
     1162    int vlen, old_vlen
    11631163    uint32_t req_memory_ptr, in_memory_ptr; 
    1164  
    1165     item *it; 
     1164    item *it, *old_it; 
    11661165 
    11671166    assert(c != NULL); 
     
    12071206    } 
    12081207 
     1208    /* Check if append -- if yes, search for previous entry, and allocate memory for both */ 
     1209    if( comm == NREAD_APPEND ){ 
     1210       old_it = assoc_find(key,nkey); 
     1211 
     1212       if( old_it && (old_it->nbytes)>2 ){ // previous must be more than \r\n 
     1213          old_vlen = old_it->nbytes - 2; 
     1214          vlen += old_vlen;                // append the length of old data 
     1215       } else { 
     1216          comm = NREAD_REPLACE;            // no old entry: treat as replace 
     1217       } 
     1218    } 
     1219 
    12091220    it = item_alloc(key, nkey, flags, realtime(exptime), vlen+2); 
    12101221 
    12111222    /* HANDLE_CAS VALIDATION */ 
    1212     if(handle_cas == true) 
     1223    if (handle_cas == true) 
    12131224    { 
    12141225      item *itmp=item_get(key, it->nkey); 
     
    12521263    } 
    12531264 
    1254     c->item_comm = comm; 
    12551265    c->item = it; 
    12561266    c->ritem = ITEM_data(it); 
    12571267    c->rlbytes = it->nbytes; 
     1268 
     1269 
     1270    /* If append, prepend old data before new - adjust item, rlbytes variables too 
     1271     * Now that data has been merged, treat simply as a replace command 
     1272     */ 
     1273    if (comm == NREAD_APPEND ){ 
     1274       memcpy( c->ritem, ITEM_data(old_it), old_vlen ); 
     1275       c->ritem += old_vlen; 
     1276       c->rlbytes -= old_vlen; 
     1277       comm = NREAD_REPLACE; 
     1278    } 
     1279 
     1280    c->item_comm = comm; 
    12581281    conn_set_state(c, conn_nread); 
    12591282} 
     
    14881511               ((strcmp(tokens[COMMAND_TOKEN].value, "add") == 0 && (comm = NREAD_ADD)) || 
    14891512                (strcmp(tokens[COMMAND_TOKEN].value, "set") == 0 && (comm = NREAD_SET)) || 
    1490                 (strcmp(tokens[COMMAND_TOKEN].value, "replace") == 0 && (comm = NREAD_REPLACE)))) { 
     1513                (strcmp(tokens[COMMAND_TOKEN].value, "replace") == 0 && (comm = NREAD_REPLACE)) || 
     1514                (strcmp(tokens[COMMAND_TOKEN].value, "append") == 0 && (comm = NREAD_APPEND)) )) { 
    14911515 
    14921516        process_update_command(c, tokens, ntokens, comm, false); 
  • trunk/server/memcached.h

    r619 r620  
    138138#define NREAD_SET 2 
    139139#define NREAD_REPLACE 3 
     140#define NREAD_APPEND 4 
    140141 
    141142typedef struct {