Stop using /dev/null to find out the serialized object length
Now the rdbSave* functions return the number of bytes written (or required to write) in serializing a Redis object, writing to /dev/null and using ftell (which doesn't work on FreeBSD) isn't needed anymore.
This commit is contained in:
parent
47ddeec2dd
commit
e127bd9c53
@ -216,7 +216,7 @@ void debugCommand(redisClient *c) {
|
|||||||
"encoding:%s serializedlength:%lld "
|
"encoding:%s serializedlength:%lld "
|
||||||
"lru:%d lru_seconds_idle:%lu",
|
"lru:%d lru_seconds_idle:%lu",
|
||||||
(void*)val, val->refcount,
|
(void*)val, val->refcount,
|
||||||
strenc, (long long) rdbSavedObjectLen(val,NULL),
|
strenc, (long long) rdbSavedObjectLen(val),
|
||||||
val->lru, estimateObjectIdleTime(val));
|
val->lru, estimateObjectIdleTime(val));
|
||||||
} else {
|
} else {
|
||||||
vmpointer *vp = (vmpointer*) val;
|
vmpointer *vp = (vmpointer*) val;
|
||||||
|
17
src/rdb.c
17
src/rdb.c
@ -389,20 +389,15 @@ int rdbSaveObject(FILE *fp, robj *o) {
|
|||||||
* the rdbSaveObject() function. Currently we use a trick to get
|
* the rdbSaveObject() function. Currently we use a trick to get
|
||||||
* this length with very little changes to the code. In the future
|
* this length with very little changes to the code. In the future
|
||||||
* we could switch to a faster solution. */
|
* we could switch to a faster solution. */
|
||||||
off_t rdbSavedObjectLen(robj *o, FILE *fp) {
|
off_t rdbSavedObjectLen(robj *o) {
|
||||||
int nwritten;
|
int len = rdbSaveObject(NULL,o);
|
||||||
if (fp == NULL) fp = server.devnull;
|
redisAssert(len != -1);
|
||||||
rewind(fp);
|
return len;
|
||||||
|
|
||||||
/* Determining the saved length of an object should never return -1 */
|
|
||||||
redisAssert((nwritten = rdbSaveObject(fp,o)) != -1);
|
|
||||||
return nwritten;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the number of pages required to save this object in the swap file */
|
/* Return the number of pages required to save this object in the swap file */
|
||||||
off_t rdbSavedObjectPages(robj *o, FILE *fp) {
|
off_t rdbSavedObjectPages(robj *o) {
|
||||||
off_t bytes = rdbSavedObjectLen(o,fp);
|
off_t bytes = rdbSavedObjectLen(o);
|
||||||
|
|
||||||
return (bytes+(server.vm_page_size-1))/server.vm_page_size;
|
return (bytes+(server.vm_page_size-1))/server.vm_page_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -814,11 +814,6 @@ void initServer() {
|
|||||||
setupSigSegvAction();
|
setupSigSegvAction();
|
||||||
|
|
||||||
server.mainthread = pthread_self();
|
server.mainthread = pthread_self();
|
||||||
server.devnull = fopen("/dev/null","w");
|
|
||||||
if (server.devnull == NULL) {
|
|
||||||
redisLog(REDIS_WARNING, "Can't open /dev/null: %s", server.neterr);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
server.clients = listCreate();
|
server.clients = listCreate();
|
||||||
server.slaves = listCreate();
|
server.slaves = listCreate();
|
||||||
server.monitors = listCreate();
|
server.monitors = listCreate();
|
||||||
|
@ -481,7 +481,6 @@ struct redisServer {
|
|||||||
dict *pubsub_channels; /* Map channels to list of subscribed clients */
|
dict *pubsub_channels; /* Map channels to list of subscribed clients */
|
||||||
list *pubsub_patterns; /* A list of pubsub_patterns */
|
list *pubsub_patterns; /* A list of pubsub_patterns */
|
||||||
/* Misc */
|
/* Misc */
|
||||||
FILE *devnull;
|
|
||||||
unsigned lruclock:22; /* clock incrementing every minute, for LRU */
|
unsigned lruclock:22; /* clock incrementing every minute, for LRU */
|
||||||
unsigned lruclock_padding:10;
|
unsigned lruclock_padding:10;
|
||||||
};
|
};
|
||||||
@ -743,8 +742,8 @@ int rdbSaveBackground(char *filename);
|
|||||||
void rdbRemoveTempFile(pid_t childpid);
|
void rdbRemoveTempFile(pid_t childpid);
|
||||||
int rdbSave(char *filename);
|
int rdbSave(char *filename);
|
||||||
int rdbSaveObject(FILE *fp, robj *o);
|
int rdbSaveObject(FILE *fp, robj *o);
|
||||||
off_t rdbSavedObjectPages(robj *o, FILE *fp);
|
off_t rdbSavedObjectLen(robj *o);
|
||||||
off_t rdbSavedObjectLen(robj *o, FILE *fp);
|
off_t rdbSavedObjectPages(robj *o);
|
||||||
robj *rdbLoadObject(int type, FILE *fp);
|
robj *rdbLoadObject(int type, FILE *fp);
|
||||||
void backgroundSaveDoneHandler(int statloc);
|
void backgroundSaveDoneHandler(int statloc);
|
||||||
|
|
||||||
|
6
src/vm.c
6
src/vm.c
@ -263,7 +263,7 @@ int vmWriteObjectOnSwap(robj *o, off_t page) {
|
|||||||
* If we can't find enough contiguous empty pages to swap the object on disk
|
* If we can't find enough contiguous empty pages to swap the object on disk
|
||||||
* NULL is returned. */
|
* NULL is returned. */
|
||||||
vmpointer *vmSwapObjectBlocking(robj *val) {
|
vmpointer *vmSwapObjectBlocking(robj *val) {
|
||||||
off_t pages = rdbSavedObjectPages(val,NULL);
|
off_t pages = rdbSavedObjectPages(val);
|
||||||
off_t page;
|
off_t page;
|
||||||
vmpointer *vp;
|
vmpointer *vp;
|
||||||
|
|
||||||
@ -821,9 +821,7 @@ void *IOThreadEntryPoint(void *arg) {
|
|||||||
vmpointer *vp = (vmpointer*)j->id;
|
vmpointer *vp = (vmpointer*)j->id;
|
||||||
j->val = vmReadObjectFromSwap(j->page,vp->vtype);
|
j->val = vmReadObjectFromSwap(j->page,vp->vtype);
|
||||||
} else if (j->type == REDIS_IOJOB_PREPARE_SWAP) {
|
} else if (j->type == REDIS_IOJOB_PREPARE_SWAP) {
|
||||||
FILE *fp = fopen("/dev/null","w+");
|
j->pages = rdbSavedObjectPages(j->val);
|
||||||
j->pages = rdbSavedObjectPages(j->val,fp);
|
|
||||||
fclose(fp);
|
|
||||||
} else if (j->type == REDIS_IOJOB_DO_SWAP) {
|
} else if (j->type == REDIS_IOJOB_DO_SWAP) {
|
||||||
if (vmWriteObjectOnSwap(j->val,j->page) == REDIS_ERR)
|
if (vmWriteObjectOnSwap(j->val,j->page) == REDIS_ERR)
|
||||||
j->canceled = 1;
|
j->canceled = 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user