From: antirez Date: Wed, 29 Dec 2010 22:00:00 +0000 (+0100) Subject: diskstore directory structure creation X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/ddbc81af33d6b3cda29cedf39e5587edf33b7ec1?ds=sidebyside diskstore directory structure creation --- diff --git a/src/diskstore.c b/src/diskstore.c index 0eece403..cfb8ae66 100644 --- a/src/diskstore.c +++ b/src/diskstore.c @@ -74,10 +74,26 @@ #include #include +int create256dir(char *prefix) { + char buf[1024]; + int j; + + for (j = 0; j < 256; j++) { + snprintf(buf,sizeof(buf),"%s%02x",prefix,j); + if (mkdir(buf,0755) == -1) { + redisLog(REDIS_WARNING,"Error creating dir %s for diskstore: %s", + buf,strerror(errno)); + return REDIS_ERR; + } + } + return REDIS_OK; +} + int dsOpen(void) { struct stat sb; - int retval; + int retval, j; char *path = server.ds_path; + char buf[1024]; if ((retval = stat(path,&sb) == -1) && errno != ENOENT) { redisLog(REDIS_WARNING, "Error opening disk store at %s: %s", @@ -97,11 +113,20 @@ int dsOpen(void) { /* New disk store, create the directory structure now, as creating * them in a lazy way is not a good idea, after very few insertions * we'll need most of the 65536 directories anyway. */ - if (mkdir(path,0644) == -1) { + if (mkdir(path,0755) == -1) { redisLog(REDIS_WARNING,"Disk store init failed creating dir %s: %s", path, strerror(errno)); return REDIS_ERR; } + /* Create the top level 256 directories */ + snprintf(buf,sizeof(buf),"%s/",path); + if (create256dir(buf) == REDIS_ERR) return REDIS_ERR; + + /* For every 256 top level dir, create 256 nested dirs */ + for (j = 0; j < 256; j++) { + snprintf(buf,sizeof(buf),"%s/%02x/",path,j); + if (create256dir(buf) == REDIS_ERR) return REDIS_ERR; + } return REDIS_OK; } diff --git a/src/dscache.c b/src/dscache.c index fca2cca9..24d485fb 100644 --- a/src/dscache.c +++ b/src/dscache.c @@ -457,6 +457,7 @@ void cacheScheduleForFlush(redisDb *db, robj *key) { val->storage = REDIS_DS_DIRTY; } + redisLog(REDIS_DEBUG,"Scheduling key %s for saving",key->ptr); dk = zmalloc(sizeof(*dk)); dk->db = db; dk->key = key; @@ -477,6 +478,8 @@ void cacheCron(void) { struct dictEntry *de; robj *val; + redisLog(REDIS_DEBUG,"Creating IO Job to save key %s",dk->key->ptr); + /* Lookup the key. We need to check if it's still here and * possibly access to the value. */ de = dictFind(dk->db->dict,dk->key->ptr); diff --git a/src/redis.c b/src/redis.c index 8680797a..652d18ca 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1493,7 +1493,9 @@ int main(int argc, char **argv) { linuxOvercommitMemoryWarning(); #endif start = time(NULL); - if (server.appendonly) { + if (server.ds_enabled) { + redisLog(REDIS_NOTICE,"Running with disk back end"); + } else if (server.appendonly) { if (loadAppendOnlyFile(server.appendfilename) == REDIS_OK) redisLog(REDIS_NOTICE,"DB loaded from append only file: %ld seconds",time(NULL)-start); } else {