spx_private void idcreatorServerContextClear(struct IdcreatorServerContext *isc){/*{{{*/
    if(NULL != isc->client_ip){
        SpxStringFree(isc->client_ip);
    }

    isc->err = 0;
    isc->moore = SpxNioMooreNormal;
    isc->loop = NULL;
    memset(isc->inbuf,0,SpxMsgHeaderSize + sizeof(i32_t));
    memset(isc->outbuf,0,SpxMsgHeaderSize + sizeof(u64_t));
    memset(&(isc->inheader),0,sizeof(isc->inheader));
    memset(&(isc->outheader),0,sizeof(isc->outheader));
    isc->offset = 0;
    if(0 < isc->fd){
        SpxClose(isc->fd);
    }
}/*}}}*/
Пример #2
0
err_t ydb_storage_dio_delete_context_from_chunkfile(
        struct ydb_storage_configurtion *c,
        string_t fname,
        u64_t cbegin,
        u64_t ctotalsize,
        u32_t copver,
        u32_t cver,
        u64_t clastmodifytime,
        u64_t crealsize,
        u64_t lastmodifytime){/*{{{*/
    err_t err = 0;
    struct spx_msg *ioctx = NULL;
    int fd = 0;
    char *mptr = NULL;
    string_t io_suffix = NULL;
    string_t io_hashcode = NULL;

    bool_t io_isdelete = false;
    u32_t io_opver = 0;
    u32_t io_ver = 0;
    u64_t io_createtime = 0;
    u64_t io_lastmodifytime = 0;
    u64_t io_totalsize = 0;
    u64_t io_realsize = 0;


    u32_t unit = (int) cbegin / c->pagesize;
    u64_t begin = unit * c->pagesize;
    u64_t offset = cbegin - begin;
    u64_t len = offset + ctotalsize;

    fd = open(fname,O_RDWR,SpxFileMode);
    if(0 == fd){
        err = errno;
        SpxLogFmt2(c->log,SpxLogError,err,\
                "open chunkfile:%s is fail.",
                fname);
        goto r1;
    }

    mptr = mmap(NULL,\
            len,PROT_READ | PROT_WRITE ,\
            MAP_SHARED,fd,begin);
    if(MAP_FAILED == mptr){
        err = errno;
        SpxLogFmt2(c->log,SpxLogError,err,\
                "mmap chunkfile:%s with begin:%lld,length:%lld is fail.",
                fname,begin,len);
        goto r1;
    }

    ioctx = spx_msg_new(YDB_CHUNKFILE_MEMADATA_SIZE,&err);
    if(NULL == ioctx){
        SpxLog2(c->log,SpxLogError,err,\
                "alloc metedata ioctx is fail.");
        goto r1;
    }

    if(0 != (err = spx_msg_pack_ubytes(ioctx,
                    ((ubyte_t *) (mptr+ offset)),
                    YDB_CHUNKFILE_MEMADATA_SIZE))){
        SpxLog2(c->log,SpxLogError,err,\
                "read metedata to ioctx is fail.");
        goto r1;
    }

    spx_msg_seek(ioctx,0,SpxMsgSeekSet);

    err = ydb_storage_dio_parser_metadata(c->log,ioctx,
            &io_isdelete,&io_opver,
            &io_ver,&io_createtime,
            &io_lastmodifytime,&io_totalsize,&io_realsize,
            &io_suffix,&io_hashcode);
    if(0 != err){
        SpxLog2(c->log,SpxLogError,err,\
                "unpack metedate ioctx is fail.");
        goto r1;
    }

    if(io_isdelete){
        SpxLogFmt1(c->log,SpxLogError,
                "the file in the chunkfile:%s "
                "with begin:%lld totalsize:%lld is deleted.",
                fname,cbegin,ctotalsize);
        err = ENOENT;
        goto r1;
    }
    if(copver != io_opver || cver != io_ver
            || clastmodifytime != io_lastmodifytime
            || ctotalsize != io_totalsize
            || crealsize != io_realsize){
        SpxLogFmt1(c->log,SpxLogError,
                "the file in the chunkfile:%s "
                "with begin:%lld totalsize:%lld is not the deleting-file.",
                fname,cbegin,ctotalsize);
        err = ENOENT;
        goto r1;
    }

    spx_msg_seek(ioctx,0,SpxMsgSeekSet);
    spx_msg_pack_true(ioctx);//isdelete
    spx_msg_pack_u32(ioctx,copver + 1);
    spx_msg_pack_u32(ioctx,YDB_VERSION);
    spx_msg_seek(ioctx,sizeof(u64_t),SpxMsgSeekCurrent);//jump createtime
    spx_msg_pack_u64(ioctx,lastmodifytime);

    memcpy(mptr + offset,ioctx->buf,YDB_CHUNKFILE_MEMADATA_SIZE);

r1:
    if(NULL != ioctx){
        SpxMsgFree(ioctx);
    }
    if(NULL != mptr){
        munmap(mptr,len);
    }
    if(0 < fd){
        SpxClose(fd);
    }
    if(NULL != io_hashcode){
        SpxStringFree(io_hashcode);
    }
    if(NULL != io_suffix){
        SpxStringFree(io_suffix);
    }
    return err;
}/*}}}*/