Permalink
Browse files

optionally take a list of slabs to run against.

lru_crawler crawl 1,2,3,10,20 will kick crawlers off for all of those slabs in
parallel.
  • Loading branch information...
1 parent 2846242 commit e8711e1b6e774f5981403697f25ae8cec3f3b07e @dormando dormando committed Apr 16, 2014
Showing with 34 additions and 23 deletions.
  1. +31 −15 items.c
  2. +1 −1 items.h
  3. +2 −7 memcached.c
View
46 items.c
@@ -872,25 +872,41 @@ int start_item_crawler_thread(void) {
return 0;
}
-enum crawler_result_type lru_crawler_crawl(int sid) {
+enum crawler_result_type lru_crawler_crawl(char *slabs) {
+ char *b = NULL;
+ uint32_t sid = 0;
+ uint8_t tocrawl[POWER_LARGEST];
if (pthread_mutex_trylock(&lru_crawler_lock) != 0) {
return CRAWLER_RUNNING;
}
- if (sid < POWER_SMALLEST || sid > POWER_LARGEST) {
- return CRAWLER_BADCLASS;
- }
pthread_mutex_lock(&cache_lock);
- if (tails[sid] != NULL) {
- if (settings.verbose > 2)
- fprintf(stderr, "Kicking LRU crawler off for slab %d\n", sid);
- crawlers[sid].nbytes = 0;
- crawlers[sid].nkey = 0;
- crawlers[sid].it_flags = 1; /* For a crawler, this means enabled. */
- crawlers[sid].next = 0;
- crawlers[sid].prev = 0;
- crawlers[sid].slabs_clsid = sid;
- crawler_link_q((item *)&crawlers[sid]);
- crawler_count++;
+
+ for (char *p = strtok_r(slabs, ",", &b);
+ p != NULL;
+ p = strtok_r(NULL, ",", &b)) {
+
+ if (!safe_strtoul(p, &sid) || sid < POWER_SMALLEST
+ || sid > POWER_LARGEST) {
+ pthread_mutex_unlock(&cache_lock);
+ pthread_mutex_unlock(&lru_crawler_lock);
+ return CRAWLER_BADCLASS;
+ }
+ tocrawl[sid] = 1;
+ }
+
+ for (sid = 0; sid < LARGEST_ID; sid++) {
+ if (tocrawl[sid] != 0 && tails[sid] != NULL) {
+ if (settings.verbose > 2)
+ fprintf(stderr, "Kicking LRU crawler off for slab %d\n", sid);
+ crawlers[sid].nbytes = 0;
+ crawlers[sid].nkey = 0;
+ crawlers[sid].it_flags = 1; /* For a crawler, this means enabled. */
+ crawlers[sid].next = 0;
+ crawlers[sid].prev = 0;
+ crawlers[sid].slabs_clsid = sid;
+ crawler_link_q((item *)&crawlers[sid]);
+ crawler_count++;
+ }
}
pthread_mutex_unlock(&cache_lock);
pthread_cond_signal(&lru_crawler_cond);
View
@@ -34,4 +34,4 @@ enum crawler_result_type {
int start_item_crawler_thread(void);
int stop_item_crawler_thread(void);
int init_lru_crawler(void);
-enum crawler_result_type lru_crawler_crawl(int sid);
+enum crawler_result_type lru_crawler_crawl(char *slabs);
View
@@ -3563,18 +3563,13 @@ static void process_command(conn *c, char *command) {
}
} else if (ntokens > 1 && strcmp(tokens[COMMAND_TOKEN].value, "lru_crawler") == 0) {
if (ntokens == 4 && strcmp(tokens[COMMAND_TOKEN + 1].value, "crawl") == 0) {
- int sid, rv;
+ int rv;
if (settings.lru_crawler == false) {
out_string(c, "CLIENT_ERROR lru crawler disabled");
return;
}
- sid = strtol(tokens[2].value, NULL, 10);
- if (errno == ERANGE) {
- out_string(c, "CLIENT_ERROR bad command line format");
- return;
- }
- rv = lru_crawler_crawl(sid);
+ rv = lru_crawler_crawl(tokens[2].value);
switch(rv) {
case CRAWLER_OK:
out_string(c, "OK");

0 comments on commit e8711e1

Please sign in to comment.