Changeset 674
- Timestamp:
- 12/11/07 03:29:00 (1 year ago)
- Files:
-
- branches/binary/server/memcached.c (modified) (11 diffs)
- branches/binary/server/memcached.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/binary/server/memcached.c
r673 r674 1011 1011 1012 1012 static void complete_update_bin(conn *c) { 1013 int eno=-1, ret=0; 1013 1014 assert(c != NULL); 1014 1015 … … 1024 1025 *(ITEM_data(it) + it->nbytes - 1) = '\n'; 1025 1026 1026 if (store_item(it, c->item_comm)) { 1027 /* Stored */ 1028 write_bin_response(c, NULL, 0); 1029 } else { 1030 /* not Stored */ 1031 int eno=-1; 1032 if(c->item_comm == NREAD_ADD) { 1033 eno=ERR_EXISTS; 1034 } else if(c->item_comm == NREAD_REPLACE) { 1035 eno=ERR_NOT_FOUND; 1036 } else { 1037 eno=ERR_NOT_STORED; 1038 } 1039 write_bin_error(c, eno, 0); 1027 switch (store_item(it, c->item_comm)) { 1028 case 1: 1029 /* Stored */ 1030 write_bin_response(c, NULL, 0); 1031 break; 1032 case 2: 1033 write_bin_error(c, ERR_EXISTS, 0); 1034 break; 1035 case 3: 1036 write_bin_error(c, ERR_NOT_FOUND, 0); 1037 break; 1038 default: 1039 if(c->item_comm == NREAD_ADD) { 1040 eno=ERR_EXISTS; 1041 } else if(c->item_comm == NREAD_REPLACE) { 1042 eno=ERR_NOT_FOUND; 1043 } else { 1044 eno=ERR_NOT_STORED; 1045 } 1046 write_bin_error(c, eno, 0); 1040 1047 } 1041 1048 … … 1059 1066 1060 1067 /* the length has two unnecessary bytes, and then we write four more */ 1061 add_bin_header(c, 0, it->nbytes - 2 + 4 );1062 /* Flags and value*/1068 add_bin_header(c, 0, it->nbytes - 2 + 4 + (c->cmd == CMD_GETS?8:0)); 1069 /* Flags */ 1063 1070 add_iov(c, flags, 4); 1071 /* if it's a gets, add the identifier */ 1072 if(c->cmd == CMD_GETS) { 1073 uint64_t* identifier; 1074 identifier=(uint64_t*)(c->wbuf + MIN_BIN_PKT_LENGTH + 4); 1075 *identifier=swap64((uint32_t)it->cas_id); 1076 add_iov(c, identifier, 8); 1077 } 1064 1078 /* bytes minus the CRLF */ 1065 1079 add_iov(c, ITEM_data(it), it->nbytes - 2); … … 1106 1120 bin_read_key(c, bin_reading_set_header, BIN_SET_HDR_LEN); 1107 1121 break; 1122 case CMD_CAS: 1123 bin_read_key(c, bin_reading_cas_header, BIN_CAS_HDR_LEN); 1124 break; 1125 case CMD_GETS: 1108 1126 case CMD_GETQ: 1109 1127 case CMD_GET: … … 1121 1139 } 1122 1140 1123 static void process_bin_update(conn *c ) {1141 static void process_bin_update(conn *c, bool cas) { 1124 1142 char *key; 1125 1143 int nkey; … … 1129 1147 item *it; 1130 1148 int comm; 1149 int hdrlen=cas ? BIN_CAS_HDR_LEN : BIN_SET_HDR_LEN; 1131 1150 1132 1151 assert(c != NULL); 1133 1152 1134 key=c->rbuf + BIN_SET_HDR_LEN;1153 key=c->rbuf + hdrlen; 1135 1154 nkey=c->keylen; 1136 1155 key[nkey]=0x00; … … 1138 1157 flags = ntohl(*((int*)(c->rbuf))); 1139 1158 exptime = ntohl(*((int*)(c->rbuf + 4))); 1140 vlen = c->bin_header[2] - (nkey + BIN_SET_HDR_LEN); 1159 vlen = c->bin_header[2] - (nkey + hdrlen); 1160 1161 if(settings.verbose) { 1162 fprintf(stderr, "Value len is %d\n", vlen); 1163 } 1141 1164 1142 1165 if (settings.detail_enabled) { … … 1160 1183 1161 1184 it = item_alloc(key, nkey, flags, realtime(exptime), vlen+2); 1185 if(cas) { 1186 it->cas_id = (uint64_t)swap64(*((int64_t*)(c->rbuf + 8))); 1187 } 1162 1188 1163 1189 if (it == 0) { … … 1175 1201 case CMD_ADD: 1176 1202 c->item_comm = NREAD_ADD; 1203 break; 1204 case CMD_CAS: 1205 c->item_comm = NREAD_CAS; 1177 1206 break; 1178 1207 case CMD_SET: … … 1292 1321 switch(c->substate) { 1293 1322 case bin_reading_set_header: 1294 process_bin_update(c); 1323 process_bin_update(c, false); 1324 break; 1325 case bin_reading_cas_header: 1326 process_bin_update(c, true); 1295 1327 break; 1296 1328 case bin_read_set_value: … … 1364 1396 do_item_replace(old_it, it); 1365 1397 stored = 1; 1366 } 1367 else 1368 { 1398 } else { 1399 if(settings.verbose > 1) { 1400 fprintf(stderr, "CAS: failure: expected %llu, got %llu\n", 1401 old_it->cas_id, it->cas_id); 1402 } 1369 1403 stored = 2; 1370 1404 } branches/binary/server/memcached.h
r673 r674 43 43 /* flags:32, expiration:32 */ 44 44 #define BIN_SET_HDR_LEN 8 45 /* Same as set, but with another 64 bits for the CAS identifier */ 46 #define BIN_CAS_HDR_LEN (BIN_SET_HDR_LEN + 8) 45 47 /* incr:64, initial:64, expiration:32 */ 46 48 #define BIN_INCR_HDR_LEN 20 … … 63 65 #define CMD_NOOP 9 64 66 #define CMD_VERSION 10 67 68 #define CMD_GETS 50 69 #define CMD_CAS 51 65 70 66 71 #define ERR_UNKNOWN_CMD 0x81 … … 182 187 bin_no_state, 183 188 bin_reading_set_header, 189 bin_reading_cas_header, 184 190 bin_read_set_value, 185 191 bin_reading_get_key,
