mirror of https://github.com/redis/redis.git
				
				
				
			diskstore directory structure creation
This commit is contained in:
		
							parent
							
								
									f63f0928c3
								
							
						
					
					
						commit
						ddbc81af33
					
				| 
						 | 
					@ -74,10 +74,26 @@
 | 
				
			||||||
#include <fcntl.h>
 | 
					#include <fcntl.h>
 | 
				
			||||||
#include <sys/stat.h>
 | 
					#include <sys/stat.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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) {
 | 
					int dsOpen(void) {
 | 
				
			||||||
    struct stat sb;
 | 
					    struct stat sb;
 | 
				
			||||||
    int retval;
 | 
					    int retval, j;
 | 
				
			||||||
    char *path = server.ds_path;
 | 
					    char *path = server.ds_path;
 | 
				
			||||||
 | 
					    char buf[1024];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if ((retval = stat(path,&sb) == -1) && errno != ENOENT) {
 | 
					    if ((retval = stat(path,&sb) == -1) && errno != ENOENT) {
 | 
				
			||||||
        redisLog(REDIS_WARNING, "Error opening disk store at %s: %s",
 | 
					        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
 | 
					    /* New disk store, create the directory structure now, as creating
 | 
				
			||||||
     * them in a lazy way is not a good idea, after very few insertions
 | 
					     * them in a lazy way is not a good idea, after very few insertions
 | 
				
			||||||
     * we'll need most of the 65536 directories anyway. */
 | 
					     * 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",
 | 
					        redisLog(REDIS_WARNING,"Disk store init failed creating dir %s: %s",
 | 
				
			||||||
            path, strerror(errno));
 | 
					            path, strerror(errno));
 | 
				
			||||||
        return REDIS_ERR;
 | 
					        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;
 | 
					    return REDIS_OK;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -457,6 +457,7 @@ void cacheScheduleForFlush(redisDb *db, robj *key) {
 | 
				
			||||||
            val->storage = REDIS_DS_DIRTY;
 | 
					            val->storage = REDIS_DS_DIRTY;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    redisLog(REDIS_DEBUG,"Scheduling key %s for saving",key->ptr);
 | 
				
			||||||
    dk = zmalloc(sizeof(*dk));
 | 
					    dk = zmalloc(sizeof(*dk));
 | 
				
			||||||
    dk->db = db;
 | 
					    dk->db = db;
 | 
				
			||||||
    dk->key = key;
 | 
					    dk->key = key;
 | 
				
			||||||
| 
						 | 
					@ -477,6 +478,8 @@ void cacheCron(void) {
 | 
				
			||||||
            struct dictEntry *de;
 | 
					            struct dictEntry *de;
 | 
				
			||||||
            robj *val;
 | 
					            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
 | 
					            /* Lookup the key. We need to check if it's still here and
 | 
				
			||||||
             * possibly access to the value. */
 | 
					             * possibly access to the value. */
 | 
				
			||||||
            de = dictFind(dk->db->dict,dk->key->ptr);
 | 
					            de = dictFind(dk->db->dict,dk->key->ptr);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1493,7 +1493,9 @@ int main(int argc, char **argv) {
 | 
				
			||||||
    linuxOvercommitMemoryWarning();
 | 
					    linuxOvercommitMemoryWarning();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
    start = time(NULL);
 | 
					    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)
 | 
					        if (loadAppendOnlyFile(server.appendfilename) == REDIS_OK)
 | 
				
			||||||
            redisLog(REDIS_NOTICE,"DB loaded from append only file: %ld seconds",time(NULL)-start);
 | 
					            redisLog(REDIS_NOTICE,"DB loaded from append only file: %ld seconds",time(NULL)-start);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue