Changeset 635
- Timestamp:
- 11/15/07 08:13:45 (1 year ago)
- Files:
-
- trunk/server/items.c (modified) (3 diffs)
- trunk/server/memcached.c (modified) (10 diffs)
- trunk/server/memcached.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/server/items.c
r618 r635 18 18 static void item_link_q(item *it); 19 19 static void item_unlink_q(item *it); 20 static uint64_t get_cas_id(); 20 21 21 22 /* … … 38 39 sizes[i] = 0; 39 40 } 41 } 42 43 /* Get the next CAS id for a new item. */ 44 uint64_t get_cas_id() { 45 static uint64_t cas_id; 46 if(cas_id >= MAX_CAS_ID) { 47 cas_id = 0; 48 } 49 return ++cas_id; 40 50 } 41 51 … … 130 140 it->nkey = nkey; 131 141 it->nbytes = nbytes; 142 it->cas_id = get_cas_id(); 132 143 strcpy(ITEM_key(it), key); 133 144 it->exptime = exptime; trunk/server/memcached.c
r633 r635 690 690 item *it = c->item; 691 691 int comm = c->item_comm; 692 int ret; 692 693 693 694 STATS_LOCK(); … … 698 699 out_string(c, "CLIENT_ERROR bad data chunk"); 699 700 } else { 700 if (store_item(it, comm)) { 701 out_string(c, "STORED"); 702 } else { 703 out_string(c, "NOT_STORED"); 704 } 701 ret = store_item(it, comm); 702 if (ret == 1) 703 out_string(c, "STORED"); 704 else if(ret == 2) 705 out_string(c, "EXISTS"); 706 else if(ret == 3) 707 out_string(c, "NOT FOUND"); 708 else 709 out_string(c, "NOT_STORED"); 705 710 } 706 711 … … 735 740 { 736 741 /* replace and add can't override delete locks; don't store */ 742 } else if (comm == NREAD_CAS) { 743 /* validate cas operation */ 744 if (delete_locked) 745 old_it = do_item_get_nocheck(key, it->nkey); 746 747 if(old_it == NULL) { 748 // LRU expired 749 stored = 3; 750 } 751 else if(it->cas_id == old_it->cas_id) { 752 // cas validates 753 do_item_replace(old_it, it); 754 stored = 1; 755 } 756 else 757 { 758 stored = 2; 759 } 737 760 } else { 738 739 761 /* 740 762 * Append - combine new and old record into single one. Here it's … … 1081 1103 token_t *key_token = &tokens[KEY_TOKEN]; 1082 1104 char suffix[255]; 1083 uint32_t in_memory_ptr;1084 1105 assert(c != NULL); 1085 1106 … … 1134 1155 if(return_key_ptr == true) 1135 1156 { 1136 in_memory_ptr = (uint32_t)item_get(key, nkey);1137 sprintf(suffix," %d %d %lu\r\n", atoi(ITEM_suffix(it) + 1), it->nbytes - 2, in_memory_ptr);1157 sprintf(suffix," %d %d %llu\r\n", atoi(ITEM_suffix(it) + 1), 1158 it->nbytes - 2, it->cas_id); 1138 1159 if (add_iov(c, "VALUE ", 6) != 0 || 1139 1160 add_iov(c, ITEM_key(it), it->nkey) != 0 || … … 1214 1235 time_t exptime; 1215 1236 int vlen, old_vlen; 1216 uint 32_t req_memory_ptr, in_memory_ptr;1237 uint64_t req_cas_id; 1217 1238 item *it, *old_it; 1218 1239 … … 1232 1253 1233 1254 // does cas value exist? 1234 if( tokens[5].value)1255 if(handle_cas) 1235 1256 { 1236 req_ memory_ptr= strtoull(tokens[5].value, NULL, 10);1257 req_cas_id = strtoull(tokens[5].value, NULL, 10); 1237 1258 } 1238 1259 … … 1260 1281 1261 1282 it = item_alloc(key, nkey, flags, realtime(exptime), vlen+2); 1262 1263 /* HANDLE_CAS VALIDATION */1264 if (handle_cas == true)1265 {1266 item *itmp=item_get(key, it->nkey);1267 /* Release the reference */1268 if(itmp) {1269 item_remove(itmp);1270 }1271 in_memory_ptr = (uint32_t)itmp;1272 if(in_memory_ptr == req_memory_ptr)1273 {1274 // validates allow the set1275 }1276 else if(in_memory_ptr)1277 {1278 out_string(c, "EXISTS");1279 1280 /* swallow the data line */1281 c->write_and_go = conn_swallow;1282 c->sbytes = vlen + 2;1283 return;1284 }1285 else1286 {1287 out_string(c, "NOT FOUND");1288 /* swallow the data line */1289 c->write_and_go = conn_swallow;1290 c->sbytes = vlen + 2;1291 return;1292 }1293 }1294 1283 1295 1284 if (it == 0) { … … 1303 1292 return; 1304 1293 } 1294 if(handle_cas) 1295 it->cas_id = req_cas_id; 1305 1296 1306 1297 c->item = it; … … 1546 1537 process_update_command(c, tokens, ntokens, comm, false); 1547 1538 1548 } else if (ntokens == 6 && (strcmp(tokens[COMMAND_TOKEN].value, "cas") == 0 )) {1539 } else if (ntokens == 6 && (strcmp(tokens[COMMAND_TOKEN].value, "cas") == 0 && (comm = NREAD_CAS))) { 1549 1540 1550 1541 process_update_command(c, tokens, ntokens, comm, true); trunk/server/memcached.h
r629 r635 32 32 #define IOV_LIST_HIGHWAT 600 33 33 #define MSG_LIST_HIGHWAT 100 34 35 #define MAX_CAS_ID 0x7ffffffffffffff0 34 36 35 37 /* Get a consistent bool type */ … … 113 115 uint8_t slabs_clsid;/* which slab class we're in */ 114 116 uint8_t nkey; /* key length, w/terminating null and padding */ 117 uint64_t cas_id; /* the CAS identifier */ 115 118 void * end[]; 116 119 /* then null-terminated key */ … … 141 144 #define NREAD_APPEND 4 142 145 #define NREAD_PREPEND 5 146 #define NREAD_CAS 6 143 147 144 148 typedef struct {
