featuring delete command (under testing)
@@ -12,6 +12,7 @@ | ||
12 | 12 | #include <string.h> |
13 | 13 | #include <time.h> |
14 | 14 | #include <assert.h> |
15 | +#include <syslog.h> | |
15 | 16 | |
16 | 17 | /* Forward Declarations */ |
17 | 18 | static void item_link_q(item *it); |
@@ -283,7 +284,14 @@ | ||
283 | 284 | sizes[it->slabs_clsid]--; |
284 | 285 | return; |
285 | 286 | } |
286 | - | |
287 | +void replication_error(memcached_st *memc, memcached_return rc, char *module) | |
288 | +{ | |
289 | + syslog(LOG_DAEMON|LOG_CRIT, "# of replica=%d[%s]",memcached_server_count(memc),settings.repdest); | |
290 | + syslog(LOG_DAEMON|LOG_CRIT, "pushed server [%p] at [%p]",(void *)memc, (void *)&memc); | |
291 | + syslog(LOG_DAEMON|LOG_CRIT, "memcache error %s[%s]", memcached_strerror(memc, rc),module); | |
292 | + if (memc->cached_errno) | |
293 | + syslog(LOG_DAEMON|LOG_CRIT, " system error %s\n", strerror(memc->cached_errno)); | |
294 | +} | |
287 | 295 | int do_item_link(item *it) { |
288 | 296 | MEMCACHED_ITEM_LINK(ITEM_key(it), it->nkey, it->nbytes); |
289 | 297 | assert((it->it_flags & (ITEM_LINKED|ITEM_SLABBED)) == 0); |
@@ -294,7 +302,8 @@ | ||
294 | 302 | { |
295 | 303 | memcached_return rc; |
296 | 304 | rc= memcached_set(memc, ITEM_key(it), it->nkey, ITEM_data(it), |
297 | - it->nbytes-2, it->exptime==0 ? 0 : it->exptime + process_started, it->it_flags); | |
305 | +/* it->nbytes-2, it->exptime==0 ? 0 : it->exptime + process_started, it->it_flags);*/ | |
306 | + it->nbytes-2, it->exptime==0 ? 0 : it->exptime + process_started, 32); /* for Java only */ | |
298 | 307 | if (rc == MEMCACHED_SUCCESS) |
299 | 308 | { |
300 | 309 | /* |
@@ -305,12 +314,7 @@ | ||
305 | 314 | */ |
306 | 315 | }else // Unknown Issue |
307 | 316 | { |
308 | - printf("# of replica=%d[%s]\n",memcached_server_count(memc),settings.repdest); | |
309 | - fprintf(stderr, "pushed server [%p] at [%p]\n",(void *)memc, (void *)&memc); | |
310 | - fprintf(stderr, "memcache error %s\n", | |
311 | - memcached_strerror(memc, rc)); | |
312 | - if (memc->cached_errno) | |
313 | - fprintf(stderr, " system error %s\n", strerror(memc->cached_errno)); | |
317 | + replication_error(memc, rc, "do_item_link (set, add...)"); | |
314 | 318 | } |
315 | 319 | } |
316 | 320 |
@@ -332,13 +336,30 @@ | ||
332 | 336 | MEMCACHED_ITEM_UNLINK(ITEM_key(it), it->nkey, it->nbytes); |
333 | 337 | if ((it->it_flags & ITEM_LINKED) != 0) { |
334 | 338 | it->it_flags &= ~ITEM_LINKED; |
335 | - STATS_LOCK(); | |
336 | - stats.curr_bytes -= ITEM_ntotal(it); | |
337 | - stats.curr_items -= 1; | |
338 | - STATS_UNLOCK(); | |
339 | - assoc_delete(ITEM_key(it), it->nkey); | |
340 | - item_unlink_q(it); | |
341 | - if (it->refcount == 0) item_free(it); | |
339 | + if(settings.repdest) | |
340 | + { | |
341 | + memcached_return rc; | |
342 | + rc = memcached_delete(memc, ITEM_key(it), it->nkey, 0); | |
343 | + if (rc == MEMCACHED_SUCCESS) | |
344 | + { | |
345 | +/* | |
346 | + printf("key===%s[%d] val===%s[%zd]",ITEM_key(it),it->nkey,ITEM_data(it), strlen(ITEM_data(it))-2); | |
347 | + printf("key===%s[%d] val===%s[%d]",ITEM_key(it),it->nkey,ITEM_data(it), it->nbytes-2); | |
348 | + printf("replicate to %s\n",settings.repdest); | |
349 | + fflush(stdout); | |
350 | +*/ | |
351 | + }else // Unknown Issue | |
352 | + { | |
353 | + replication_error(memc, rc, "do_item_unlink (delete...)"); | |
354 | + } | |
355 | + } | |
356 | + STATS_LOCK(); | |
357 | + stats.curr_bytes -= ITEM_ntotal(it); | |
358 | + stats.curr_items -= 1; | |
359 | + STATS_UNLOCK(); | |
360 | + assoc_delete(ITEM_key(it), it->nkey); | |
361 | + item_unlink_q(it); | |
362 | + if (it->refcount == 0) item_free(it); | |
342 | 363 | } |
343 | 364 | } |
344 | 365 |
@@ -6,6 +6,7 @@ | ||
6 | 6 | void item_free(item *it); |
7 | 7 | bool item_size_ok(const size_t nkey, const int flags, const int nbytes); |
8 | 8 | |
9 | +void replication_error(memcached_st *memc, memcached_return rc, char *module); /* error message output */ | |
9 | 10 | int do_item_link(item *it); /** may fail if transgresses limits */ |
10 | 11 | void do_item_unlink(item *it); |
11 | 12 | void do_item_remove(item *it); |