Changeset 620
- Timestamp:
- 10/03/07 22:27:28 (1 year ago)
- Files:
-
- trunk/server/ChangeLog (modified) (1 diff)
- trunk/server/doc/protocol.txt (modified) (4 diffs)
- trunk/server/memcached.c (modified) (4 diffs)
- trunk/server/memcached.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/server/ChangeLog
r619 r620 15 15 * Switch to unsigned 64-bit increment/decrement counters 16 16 from Evan Miller and Dusgtin Sallings. 17 18 * Add append command support written by Filipe Laborde. 19 Tests/protocol doc updates by myself. 17 20 18 21 2007-08-21 Paul Lindner <lindner@inuus.com> trunk/server/doc/protocol.txt
r619 r620 54 54 There are three types of commands. 55 55 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. 56 Storage commands (there are five: "set", "add", "replace", "append" 57 and "cas") ask the server to store some data identified by a key. The 58 client sends a command line, and then a data block; after that the 59 client expects one line of response, which will indicate success or 60 faulure. 60 61 61 62 Retrieval commands (there are two: "get" and "gets") ask the server to … … 128 129 <command name> <key> <flags> <exptime> <bytes> [<unqiue>]\r\n 129 130 130 - <command name> is "set", "add", "replace", or "cas"131 - <command name> is "set", "add", "replace", "append", or "cas" 131 132 132 133 "set" means "store this data". … … 137 138 "replace" means "store this data, but only if the server *does* 138 139 already hold data for this key". 140 141 "append" means "add this data to an existing key". 139 142 140 143 "cas" is a check and set operation which means "store this data but … … 183 186 - "EXISTS\r\n" to indicate that the item you are trying to store with 184 187 a "cas" command has been modified since you last fetched it. 188 185 189 186 190 Retrieval command: trunk/server/memcached.c
r619 r620 1160 1160 int flags; 1161 1161 time_t exptime; 1162 int vlen ;1162 int vlen, old_vlen; 1163 1163 uint32_t req_memory_ptr, in_memory_ptr; 1164 1165 item *it; 1164 item *it, *old_it; 1166 1165 1167 1166 assert(c != NULL); … … 1207 1206 } 1208 1207 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 1209 1220 it = item_alloc(key, nkey, flags, realtime(exptime), vlen+2); 1210 1221 1211 1222 /* HANDLE_CAS VALIDATION */ 1212 if (handle_cas == true)1223 if (handle_cas == true) 1213 1224 { 1214 1225 item *itmp=item_get(key, it->nkey); … … 1252 1263 } 1253 1264 1254 c->item_comm = comm;1255 1265 c->item = it; 1256 1266 c->ritem = ITEM_data(it); 1257 1267 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; 1258 1281 conn_set_state(c, conn_nread); 1259 1282 } … … 1488 1511 ((strcmp(tokens[COMMAND_TOKEN].value, "add") == 0 && (comm = NREAD_ADD)) || 1489 1512 (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)) )) { 1491 1515 1492 1516 process_update_command(c, tokens, ntokens, comm, false); trunk/server/memcached.h
r619 r620 138 138 #define NREAD_SET 2 139 139 #define NREAD_REPLACE 3 140 #define NREAD_APPEND 4 140 141 141 142 typedef struct {
