Redis VM and RedisVM

Source: Internet
Author: User

Redis VM and RedisVM

This article is original freas_1990, reprint please indicate the source: http://blog.csdn.net/freas_1990/article/details/42052813



When the value of a key of Redis is swap to a file, the RedisObject to which the value of the key points will be changed to VMPointer, which stores the information of the value on the disk file, including the offset of the start page and the number of consecutive pages.


typedef struct redisObject {    unsigned type:4;    unsigned storage:2;     /* REDIS_VM_MEMORY or REDIS_VM_SWAPPING */    unsigned encoding:4;    unsigned lru:22;        /* lru time (relative to server.lruclock) */    int refcount;    void *ptr;    /* VM fields are only allocated if VM is active, otherwise the     * object allocation function will just allocate     * sizeof(redisObjct) minus sizeof(redisObjectVM), so using     * Redis without VM active will not have any overhead. */} robj;


typedef struct vmPointer {    unsigned type:4;    unsigned storage:2; /* REDIS_VM_SWAPPED or REDIS_VM_LOADING */    unsigned notused:26;    unsigned int vtype; /* type of the object stored in the swap file */    off_t page;         /* the page at witch the object is stored on disk */    off_t usedpages;    /* number of pages used on disk */} vmpointer;

The logic for importing the value of this key into the memory is as follows:

robj *vmReadObjectFromSwap(off_t page, int type) {    robj *o;    if (server.vm_enabled) pthread_mutex_lock(&server.io_swapfile_mutex);    if (fseeko(server.vm_fp,page*server.vm_page_size,SEEK_SET) == -1) {        redisLog(REDIS_WARNING,            "Unrecoverable VM problem in vmReadObjectFromSwap(): can't seek: %s",            strerror(errno));        _exit(1);    }    o = rdbLoadObject(type,server.vm_fp);    if (o == NULL) {        redisLog(REDIS_WARNING, "Unrecoverable VM problem in vmReadObjectFromSwap(): can't load object from swap file: %s", strerror(errno));        _exit(1);    }    if (server.vm_enabled) pthread_mutex_unlock(&server.io_swapfile_mutex);    return o;}

By now, the essence of redis VM has been broken. Do you understand?


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.