Error moving temp DB file on the final destination: Invalid cross-device link

Error moving temp DB file on the final destination: Invalid cross-device link

 

dbfilename /data1/redisdata/dump.rdb 路径需要同文件系统,否则无法写入dump.rdb文件

/** Save the DB on disk. Return REDIS_ERR on error, REDIS_OK on success */
0405	int rdbSave(char *filename) {
0406	    dictIterator *di = NULL;
0407	    dictEntry *de;
0408	    FILE *fp;
0409	    char tmpfile[256];
0410	    int j;
0411	    time_t now = time(NULL);
0412	 
0413	    /** Wait for I/O therads to terminate, just in case this is a
0414	     * foreground-saving, to avoid seeking the swap file descriptor at the
0415	     * same time. */
0416	    if (server.vm_enabled)
0417	        waitEmptyIOJobsQueue();
0418	 
0419	    snprintf(tmpfile,256,"temp-%d.rdb", (int) getpid());
0420	    fp = fopen(tmpfile,"w");
0421	    if (!fp) {
0422	        redisLog(REDIS_WARNING, "Failed saving the DB: %s", strerror(errno));
0423	        return REDIS_ERR;
0424	    }
0425	    if (fwrite("REDIS0001",9,1,fp) == 0) goto werr;
0426	    for (j = 0; j < server.dbnum; j++) {
0427	        redisDb *db = server.db+j;
0428	        dict *d = db->dict;
0429	        if (dictSize(d) == 0) continue;
0430	        di = dictGetIterator(d);
0431	        if (!di) {
0432	            fclose(fp);
0433	            return REDIS_ERR;
0434	        }
0435	 
0436	        /** Write the SELECT DB opcode */
0437	        if (rdbSaveType(fp,REDIS_SELECTDB) == -1) goto werr;
0438	        if (rdbSaveLen(fp,j) == -1) goto werr;
0439	 
0440	        /** Iterate this DB writing every entry */
0441	        while((de = dictNext(di)) != NULL) {
0442	            sds keystr = dictGetEntryKey(de);
0443	            robj key, *o = dictGetEntryVal(de);
0444	            time_t expiretime;
0445	             
0446	            initStaticStringObject(key,keystr);
0447	            expiretime = getExpire(db,&key);
0448	 
0449	            /** Save the expire time */
0450	            if (expiretime != -1) {
0451	                /** If this key is already expired skip it */
0452	                if (expiretime < now) continue;
0453	                if (rdbSaveType(fp,REDIS_EXPIRETIME) == -1) goto werr;
0454	                if (rdbSaveTime(fp,expiretime) == -1) goto werr;
0455	            }
0456	            /** Save the key and associated value. This requires special
0457	             * handling if the value is swapped out. */
0458	            if (!server.vm_enabled || o->storage == REDIS_VM_MEMORY ||
0459	                                      o->storage == REDIS_VM_SWAPPING) {
0460	                /** Save type, key, value */
0461	                if (rdbSaveType(fp,o->type) == -1) goto werr;
0462	                if (rdbSaveStringObject(fp,&key) == -1) goto werr;
0463	                if (rdbSaveObject(fp,o) == -1) goto werr;
0464	            } else {
0465	                /** REDIS_VM_SWAPPED or REDIS_VM_LOADING */
0466	                robj *po;
0467	                /** Get a preview of the object in memory */
0468	                po = vmPreviewObject(o);
0469	                /** Save type, key, value */
0470	                if (rdbSaveType(fp,po->type) == -1) goto werr;
0471	                if (rdbSaveStringObject(fp,&key) == -1) goto werr;
0472	                if (rdbSaveObject(fp,po) == -1) goto werr;
0473	                /** Remove the loaded object from memory */
0474	                decrRefCount(po);
0475	            }
0476	        }
0477	        dictReleaseIterator(di);
0478	    }
0479	    /** EOF opcode */
0480	    if (rdbSaveType(fp,REDIS_EOF) == -1) goto werr;
0481	 
0482	    /** Make sure data will not remain on the OS's output buffers */
0483	    fflush(fp);
0484	    fsync(fileno(fp));
0485	    fclose(fp);
0486	 
0487	   

 /** Use RENAME to make sure the DB file is changed atomically only
0488	     * if the generate DB file is ok. */
0489	    if (rename(tmpfile,filename) == -1) {
0490	        redisLog(REDIS_WARNING,"Error moving temp DB file on the final destination: %s", strerror(errno));
0491	        unlink(tmpfile);
0492	        return REDIS_ERR;
0493	    }


0494	    redisLog(REDIS_NOTICE,"DB saved on disk");
0495	    server.dirty = 0;
0496	    server.lastsave = time(NULL);
0497	    return REDIS_OK;
0498	 
0499	werr:
0500	    fclose(fp);
0501	    unlink(tmpfile);
0502	    redisLog(REDIS_WARNING,"Write error saving DB on disk: %s", strerror(errno));
0503	    if (di) dictReleaseIterator(di);
0504	    return REDIS_ERR;
0505	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值