2 We use this to dump all keys.
4 At this point we only support a callback method. This could be optimized by first
5 calling items and finding active slabs. For the moment though we just loop through
6 all slabs on servers and "grab" the keys.
10 static memcached_return
ascii_dump(memcached_st
*ptr
, memcached_dump_func
*callback
, void *context
, uint32_t number_of_callbacks
)
12 memcached_return rc
= 0;
13 char buffer
[MEMCACHED_DEFAULT_COMMAND_SIZE
];
18 unlikely (ptr
->number_of_hosts
== 0)
19 return MEMCACHED_NO_SERVERS
;
21 for (server_key
= 0; server_key
< ptr
->number_of_hosts
; server_key
++)
23 /* 256 I BELIEVE is the upper limit of slabs */
24 for (x
= 0; x
< 256; x
++)
26 send_length
= (size_t) snprintf(buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
,
27 "stats cachedump %u 0 0\r\n", x
);
29 rc
= memcached_do(&ptr
->hosts
[server_key
], buffer
, send_length
, 1);
31 unlikely (rc
!= MEMCACHED_SUCCESS
)
36 uint32_t callback_counter
;
37 rc
= memcached_response(&ptr
->hosts
[server_key
], buffer
, MEMCACHED_DEFAULT_COMMAND_SIZE
, NULL
);
39 if (rc
== MEMCACHED_ITEM
)
41 char *string_ptr
, *end_ptr
;
45 string_ptr
+= 5; /* Move past ITEM */
46 for (end_ptr
= string_ptr
; isgraph(*end_ptr
); end_ptr
++);
48 key
[(size_t)(end_ptr
-string_ptr
)]= 0;
49 for (callback_counter
= 0; callback_counter
< number_of_callbacks
; callback_counter
++)
51 rc
= (*callback
[callback_counter
])(ptr
, key
, (size_t)(end_ptr
-string_ptr
), context
);
52 if (rc
!= MEMCACHED_SUCCESS
)
56 else if (rc
== MEMCACHED_END
)
58 else if (rc
== MEMCACHED_SERVER_ERROR
|| rc
== MEMCACHED_CLIENT_ERROR
)
60 /* If we try to request stats cachedump for a slab class that is too big
61 * the server will return an incorrect error message:
62 * "MEMCACHED_SERVER_ERROR failed to allocate memory"
63 * This isn't really a fatal error, so let's just skip it. I want to
64 * fix the return value from the memcached server to a CLIENT_ERROR,
65 * so let's add support for that as well right now.
77 if (rc
== MEMCACHED_END
)
78 return MEMCACHED_SUCCESS
;
83 memcached_return
memcached_dump(memcached_st
*ptr
, memcached_dump_func
*callback
, void *context
, uint32_t number_of_callbacks
)
85 /* No support for Binary protocol yet */
86 if (ptr
->flags
& MEM_BINARY_PROTOCOL
)
87 return MEMCACHED_FAILURE
;
89 return ascii_dump(ptr
, callback
, context
, number_of_callbacks
);