diff --git a/README.MD b/README.MD index bdfce13..79d0655 100644 --- a/README.MD +++ b/README.MD @@ -60,6 +60,11 @@ stvm DOM 进入域的维护 >* 2、新增热点数据点击量api +====***更新日期:20180430***==== + +>* 1、修复create脚本sizeof算法问题。 +>* 2、新增异步操作(网络插入、删除、更新)异步接口支持。 + **下本版本:** * 1、新增多机资源共享方式。 diff --git a/include/tmain.h b/include/tmain.h index 5057813..06f72ee 100644 --- a/include/tmain.h +++ b/include/tmain.h @@ -53,6 +53,12 @@ typedef struct __SOCK_CONNECT int m_lCltPort; BSock m_skSock; int m_isListen; + void *pvData; + void *pstFace; + void *pstVoid; + int m_lBuffer; + BOOL m_bHead; + int m_lRead; BOOL m_bWork; ulong m_uWorker; CMList *m_pstWork; @@ -128,6 +134,10 @@ extern long lTvmSetSequence(SATvm *pstSavm, char *pszSQName, ulong uStart) extern long lTvmRebuildIndex(SATvm *pstSavm, TABLE t); extern long lTvmResetLock(SATvm *pstSavm, TABLE t); +// asynchronous interface +extern long lAsyInsert(SATvm *pstSavm); +extern long lAsyDelete(SATvm *pstSavm); +extern long lAsyUpdate(SATvm *pstSavm, void *pvData); #ifdef __cplusplus } #endif diff --git a/include/tvm.h b/include/tvm.h index a4c6415..5352909 100644 --- a/include/tvm.h +++ b/include/tvm.h @@ -65,6 +65,11 @@ typedef long CREATE; #define OPERATE_DELETE 2 #define OPERATE_UPDATE 4 #define OPERATE_SELECT 8 + +#define OPERAYS_INSERT 1025 +#define OPERAYS_DELETE 1026 +#define OPERAYS_UPDATE 1027 + #define OPERATE_TRCATE 14 #define OPERATE_COUNT 15 #define OPERATE_GROUP 16 @@ -109,7 +114,7 @@ typedef long CREATE; #define MAX_FIELD_LEN 32 // maxinum length of Field name #ifndef MAX_FILED_NUM -#define MAX_FILED_NUM 32 // maximum number of fields in a table +#define MAX_FILED_NUM 64 // maximum number of fields in a table #endif #define MAX_REMOTE_IP 20 @@ -614,6 +619,8 @@ extern char* sGetLog(); extern char* sGetNode(); extern void* pGetBoot(); extern void* pGetSATvm(); +extern void* pCloneSATvm(); +extern void vCloneFree(SATvm *pstSavm); extern long lDefaultBoot(); extern TBoot* pBootInitial(); extern size_t lGetTblRow(TABLE t); diff --git a/src/makefile b/src/makefile index 7eac74f..df4902f 100755 --- a/src/makefile +++ b/src/makefile @@ -4,7 +4,7 @@ AR=ar LD=ld LN=ln CC=cc -fPIC -CO=-c -g -DMAX_INDEX_LEN=64 -DMAX_FILED_NUM=32 +CO=-c -g -DMAX_INDEX_LEN=64 -DMAX_FILED_NUM=64 LDFLAG=-shared -g OUTLIB=../lib OUTBIN=../bin diff --git a/src/stvm.c b/src/stvm.c index 9b59a13..7293030 100644 --- a/src/stvm.c +++ b/src/stvm.c @@ -197,6 +197,12 @@ int sizecn(TblKey *pstKey, long lfld) for(i = 0, k = 0; i < lfld; i ++) { pv = &pstKey[i]; + if(FIELD_CHAR == pv->m_lAttr) + { + k = sizeof(char); + continue; + } + if(FIELD_CHAR != pv->m_lAttr && pv->m_lLen > k) k = pv->m_lLen; } @@ -322,7 +328,7 @@ long lAnalysTable(char *s, long len, TblDef *pstTde) { long i, n, k; TblKey *pv = NULL; - char szTemp[512], szField[1024], szTar[128], *p = NULL; + char szTemp[512], szField[5120], szTar[128], *p = NULL; memset(szField, 0, sizeof(szField)); if(len > sizeof(szField) || len < 1) @@ -2179,9 +2185,6 @@ long _lExeExtreme(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, void *pv if(RC_SUCC != lRet) { TFree(pvResult); - vDestroyFiled(pstRoot); - fprintf(stderr, "extreme table (%s) failure, %s\n", pstIndex->m_szTable, - sGetTError(pstSavm->m_lErrno)); return RC_FAIL; } @@ -2236,7 +2239,6 @@ long _lExeExtreme(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, void *pv TFree(pvResult); fprintf(stdout, "---(%ld)records selected -ep(%d)--\n", pstSavm->m_lEffect, pstSavm->m_lEType); - vDestroyFiled(pstRoot); return RC_SUCC; } @@ -2327,6 +2329,8 @@ long _lParseSelect(SATvm *pstSavm, char *pszTable, char *pszField, char *pszW if(RC_SUCC != _lExeExtreme(pstSavm, &stIndex, pstRoot, pvWhere, bRmt)) goto ERR_SELECT; + vDestroyFiled(pstRoot); + pstRoot = NULL; TFree(pstField); TFree(pvWhere); return RC_SUCC; @@ -2348,12 +2352,14 @@ long _lParseSelect(SATvm *pstSavm, char *pszTable, char *pszField, char *pszW TFree(pvWhere); vDestroyFiled(pstRoot); + pstRoot = NULL; return RC_SUCC; ERR_SELECT: TFree(pvWhere); TFree(pstField); vDestroyFiled(pstRoot); + pstRoot = NULL; return RC_FAIL; } diff --git a/src/tcp.c b/src/tcp.c index eb5fdd8..be77387 100644 --- a/src/tcp.c +++ b/src/tcp.c @@ -39,29 +39,29 @@ void* pProtocaJava(SATvm *pstSavm, void *pstVoid, TFace *pstFace, void *pvBuff /************************************************************************************************* macro *************************************************************************************************/ -#define Tlog(...) vTraceLog(__FILE__, __LINE__, __VA_ARGS__) +#define Tlog(...) vTraceLog(__FILE__, __LINE__, __VA_ARGS__) -#define checkrequest(f,c,v,d,l) if(MAX(f->m_lRows, f->m_lDLen) > l) \ - { \ - if(MAX(f->m_lRows, f->m_lDLen) > DATA_MAX_LEN) \ - { \ - f->m_lErrno = RECD_TOO_LONG; \ - goto LISTEN_ERROR; \ - } \ - l = MAX(f->m_lRows, f->m_lDLen); \ - if(NULL == (c = (void *)realloc(c, l + sizeof(TFace)))) \ - { \ - f->m_lErrno = MALLC_MEM_ERR; \ - goto LISTEN_ERROR; \ - } \ - f = (TFace *)c; \ - d = c + sizeof(TFace); \ - if(NULL == (v = (void *)realloc(v, l + sizeof(TFace)))) \ - { \ - f->m_lErrno = MALLC_MEM_ERR; \ - goto LISTEN_ERROR; \ - } \ - } +#define checkrequest(s,c,f) if(MAX(f->m_lRows, f->m_lDLen) > c->m_lBuffer) \ + { \ + if(MAX(f->m_lRows, f->m_lDLen) > DATA_MAX_LEN) \ + { \ + s->m_lErrno = RECD_TOO_LONG; \ + goto LISTEN_ERROR; \ + } \ + c->m_lBuffer = MAX(f->m_lRows, f->m_lDLen); \ + if(NULL == (c->pstFace = (void *)realloc(c->pstFace, c->m_lBuffer + sizeof(TFace)))) \ + { \ + s->m_lErrno = MALLC_MEM_ERR; \ + goto LISTEN_ERROR; \ + } \ + f = (TFace *)c->pstFace; \ + c->pvData = c->pstFace + sizeof(TFace); \ + if(NULL == (c->pstVoid = (void *)realloc(c->pstVoid, c->m_lBuffer + sizeof(TFace)))) \ + { \ + s->m_lErrno = MALLC_MEM_ERR; \ + goto LISTEN_ERROR; \ + } \ + } #define checkbuffer(p, r, n) if((p->lSize * n + r->m_lCurLine) > r->m_lRowSize) \ { \ @@ -1377,6 +1377,25 @@ long lEventOperate(SATvm *pstSavm, SKCon *pstCon, TFace *pstFace, char *pvDat pstFace->m_lRows = pstSavm->m_lEffect; lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); return RC_SUCC; + + case OPERAYS_UPDATE: + pstSavm->m_bWork = pstCon->m_bWork; + pstSavm->m_pstWork = pstCon->m_pstWork; + if(RC_SUCC == lUpdate(pstSavm, pvData)) + pstCon->m_pstWork = pstSavm->m_pstWork; + return RC_SUCC; + case OPERAYS_DELETE: + pstSavm->m_bWork = pstCon->m_bWork; + pstSavm->m_pstWork = pstCon->m_pstWork; + if(RC_SUCC == lDelete(pstSavm)) + pstCon->m_pstWork = pstSavm->m_pstWork; + return RC_SUCC; + case OPERAYS_INSERT: + pstSavm->m_bWork = pstCon->m_bWork; + pstSavm->m_pstWork = pstCon->m_pstWork; + if(RC_SUCC == lInsert(pstSavm)) + pstCon->m_pstWork = pstSavm->m_pstWork; + return RC_SUCC; case OPERATE_INSERT: pstSavm->m_bWork = pstCon->m_bWork; pstSavm->m_pstWork = pstCon->m_pstWork; @@ -1623,13 +1642,27 @@ long lEpollAccept(SATvm *pstSavm, BSock epfd, SKCon *pc) return RC_FAIL; } + pstCon->m_lBuffer = READ_MAX_LEN; + pstCon->pstFace = (void *)calloc(1, pstCon->m_lBuffer + sizeof(TFace)); + pstCon->pstVoid = (void *)calloc(1, pstCon->m_lBuffer + sizeof(TFace)); + if(NULL == pstCon->pstVoid || NULL == pstCon->pstFace) + { + close(skAccept); + fprintf(stderr, "Create memory, err:(%d)(%s)", errno, strerror(errno)); + return RC_FAIL; + } + + pstCon->m_lRead = 0; + pstCon->m_bHead = FALSE; pstCon->m_skSock = skAccept; pstCon->m_lCltPort = ntohs(cAddr.sin_port); + pstCon->pvData = pstCon->pstFace + sizeof(TFace); strncpy(pstCon->m_szCltIp, inet_ntoa(cAddr.sin_addr), sizeof(pstCon->m_szCltIp)); memset(&event, 0, sizeof(event)); event.data.ptr = pstCon; - event.events = EPOLLIN | EPOLLET; +// event.events = EPOLLIN | EPOLLET; + event.events = EPOLLIN; if(0 != epoll_ctl(epfd, EPOLL_CTL_ADD, skAccept, &event)) { close(skAccept); @@ -1695,15 +1728,21 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi { lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); vResetRemote(pstSovm, pstCon->m_szCltIp, pstFace->m_lFind, pstCon->m_skSock); + pstCon->m_lRead = 0; + pstCon->m_bHead = FALSE; return RC_SUCC; } - if(pstFace->m_lRows != lRecvBuffer(pstCon->m_skSock, pvData, pstFace->m_lRows)) - { - Tlog("recv %d byte, err:%s", lRet, strerror(errno)); + if(0 > (lRet = lRecvBuffer(pstCon->m_skSock, pvData + pstCon->m_lRead, + pstFace->m_lRows - pstCon->m_lRead))) return RC_FAIL; - } - + + pstCon->m_lRead += lRet; + if(pstFace->m_lRows != pstCon->m_lRead) // more data wait to read + return RC_SUCC; + + pstCon->m_lRead = 0; + pstCon->m_bHead = FALSE; pstRun = (RunTime *)pGetRunTime(pstSovm, pstFace->m_table); pstRun->m_bAttch = pstSovm->stRunTime[pstFace->m_table].m_bAttch; pstRun->m_pvAddr = pstSovm->stRunTime[pstFace->m_table].m_pvAddr; @@ -1770,33 +1809,22 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi *************************************************************************************************/ void* vEpollListen(void *pvParam) { + long lRet, i, nWait; SKCon *pstCon = NULL; TFace *pstFace = NULL; epollevt events[MAX_EVENTS]; BSock epfd = *((long *)pvParam); - long i, nWait, lBuffer = READ_MAX_LEN; - char *pvData, *pvFace = NULL, *pstVoid = NULL; SATvm *pstSavm = (SATvm *)calloc(1, sizeof(SATvm)); pthread_detach(pthread_self()); + vHoldConnect(pstSavm); - if(!pstSavm || NULL == (pvFace = calloc(1, lBuffer + sizeof(TFace)))) - { - fprintf(stderr, "create process(%s) memory failed, (%s)", TVM_LOCAL_SERV, strerror(errno)); - return NULL; - } - - if(NULL == (pstVoid = (void *)calloc(1, lBuffer + sizeof(TFace)))) - return NULL; - if(RC_SUCC != lTvmBuffer(pstSavm)) return NULL; - pstFace = (TFace *)pvFace; - pvData = pvFace + sizeof(TFace); while(g_eRun) { - nWait = epoll_wait(epfd, events, MAX_EVENTS, 1000); + nWait = epoll_wait(epfd, events, MAX_EVENTS, 500); for(i = 0; i < nWait; i++) { pstCon = (SKCon *)events[i].data.ptr; @@ -1804,29 +1832,45 @@ void* vEpollListen(void *pvParam) lEpollAccept(pstSavm, epfd, pstCon); else if(events[i].events & EPOLLIN) { - if(sizeof(TFace) != lRecvBuffer(pstCon->m_skSock, pvFace, sizeof(TFace))) - { - if(pstCon->m_bWork) - { - pstSavm->m_bWork = pstCon->m_bWork; - pstSavm->m_pstWork = pstCon->m_pstWork; - lRollbackWork(pstSavm); - pstCon->m_bWork = false; - } - pstCon->m_pstWork = NULL; - epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); - close(pstCon->m_skSock); - continue; - } - - if(TVM_MAX_TABLE <= pstFace->m_table) - { - pstFace->m_lErrno = RESOU_DISABLE; - goto LISTEN_ERROR; - } - - checkrequest(pstFace, pvFace, pstVoid, pvData, lBuffer); - if(RC_FAIL == lPollRequest(pstSavm, pstCon, pstFace, pstVoid, pvData)) + if(FALSE == pstCon->m_bHead) + { + if(0 > (lRet = lRecvBuffer(pstCon->m_skSock, pstCon->pstFace + pstCon->m_lRead, + sizeof(TFace) - pstCon->m_lRead))) + { + if(pstCon->m_bWork) + { + pstSavm->m_bWork = pstCon->m_bWork; + pstSavm->m_pstWork = pstCon->m_pstWork; + lRollbackWork(pstSavm); + pstCon->m_bWork = false; + } + pstCon->m_pstWork = NULL; + epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); + TFree(pstCon->pstFace); + TFree(pstCon->pstVoid); + close(pstCon->m_skSock); + continue; + } + + pstCon->m_lRead += lRet; + if(sizeof(TFace) != pstCon->m_lRead) // more data wait to read + continue; + + pstFace = (TFace *)pstCon->pstFace; + if(TVM_MAX_TABLE <= pstFace->m_table) + { + pstCon->m_lRead = 0; + pstFace->m_lErrno = RESOU_DISABLE; + goto LISTEN_ERROR; + } + + checkrequest(pstSavm, pstCon, pstFace); + pstCon->m_lRead = 0; + pstCon->m_bHead = TRUE; + } + + if(RC_FAIL == lPollRequest(pstSavm, pstCon, pstFace, pstCon->pstVoid, + pstCon->pvData)) { if(pstCon->m_bWork) { @@ -1837,6 +1881,8 @@ void* vEpollListen(void *pvParam) } pstCon->m_pstWork = NULL; epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); + TFree(pstCon->pstFace); + TFree(pstCon->pstVoid); close(pstCon->m_skSock); } } @@ -1844,13 +1890,11 @@ void* vEpollListen(void *pvParam) continue; LISTEN_ERROR: - lSendBuffer(pstCon->m_skSock, pvFace, sizeof(TFace)); + lSendBuffer(pstCon->m_skSock, pstCon->pstFace, sizeof(TFace)); continue; } close(epfd); - TFree(pvFace); - TFree(pstVoid); pstSavm->pstVoid = NULL; vTvmDisconnect(pstSavm); return NULL; @@ -2313,7 +2357,9 @@ long lBootLocal(SATvm *pstSavm, TBoot *pstBoot, Benum eMode) memset(&event, 0, sizeof(event)); event.data.ptr = pstCon; - event.events = EPOLLIN | EPOLLET; +// event.events = EPOLLIN | EPOLLET; + event.events = EPOLLIN; + if(0 != epoll_ctl(epfd, EPOLL_CTL_ADD, pstCon->m_skSock, &event)) { fprintf(stderr, "add socket (%d) error, err:(%d)(%s)", pstCon->m_skSock, @@ -3680,8 +3726,10 @@ void* pParsePacket(SATvm *pstSavm, void *pstVoid, TFace *pstFace, void *pvBuf switch(pstFace->m_enum) { + case OPERAYS_INSERT: case OPERATE_INSERT: return memcpy(pstVoid, pvData, pstFace->m_lDLen); + case OPERAYS_UPDATE: case OPERATE_UPDATE: memcpy(&pstCond->uFldcmp, pvData, sizeof(uint)); for(i = 0, pvData += sizeof(uint); i < pstCond->uFldcmp; i ++) @@ -3710,6 +3758,7 @@ void* pParsePacket(SATvm *pstSavm, void *pstVoid, TFace *pstFace, void *pvBuf case OPERATE_SELECT: case OPERATE_QUERY: case OPERATE_DELETE: + case OPERAYS_DELETE: case OPERATE_TRCATE: case OPERATE_GROUP: case OPERATE_COUNT: @@ -3944,6 +3993,159 @@ long lTvmQuery(SATvm *pstSavm, size_t *plOut, void **ppvOut) return RC_SUCC; } +/************************************************************************************************* + description:API - delete by asynch + parameters: + pstSavm --stvm handle + return: + RC_SUCC --success + RC_FAIL --failure + *************************************************************************************************/ +long lAsyDelete(SATvm *pstSavm) +{ + RunTime *pstRun; + TFace *pstFace; + uint lWrite = sizeof(TFace); + + if(!pstSavm) + { + pstSavm->m_lErrno = CONDIT_IS_NIL; + return RC_FAIL; + } + + pstRun = (RunTime *)pGetRunTime(pstSavm, 0); + if(!pstRun->pstVoid) + { + pstSavm->m_lErrno = DOM_NOT_INITL; + return RC_FAIL; + } + + pstFace = (TFace *)pstRun->pstVoid; + pstFace->m_lFind = pstSavm->lFind; + pstFace->m_lDLen = pstSavm->lSize; + pstFace->m_lErrno = TVM_DONE_SUCC; + pstFace->m_enum = OPERAYS_DELETE; + pstFace->m_table = pstSavm->tblName; + + checkbuffer(pstSavm, pstRun, 1); + vBuildPacket(pstRun->pstVoid, pstSavm->pstVoid, &pstSavm->stCond, &lWrite); + vAppendCond(pstRun->pstVoid, &pstSavm->stUpdt, &lWrite); + pstFace->m_lRows = lWrite - sizeof(TFace); + + if(lWrite != lSendBuffer(pstSavm->m_skSock, (void *)pstRun->pstVoid, lWrite)) + { + pstSavm->m_lErrno = SOCK_COM_EXCP; + return RC_FAIL; + } + + return RC_SUCC; +} + +/************************************************************************************************* + description:API - update by asynch + parameters: + pstSavm --stvm handle + pvData --update data + return: + RC_SUCC --success + RC_FAIL --failure + *************************************************************************************************/ +long lAsyUpdate(SATvm *pstSavm, void *pvData) +{ + RunTime *pstRun; + FdCond *pstCond; + TFace *pstFace; + uint lWrite = sizeof(TFace); + + if(!pstSavm || !pvData) + { + pstSavm->m_lErrno = CONDIT_IS_NIL; + return RC_FAIL; + } + + pstRun = (RunTime *)pGetRunTime(pstSavm, 0); + if(!pstRun->pstVoid) + { + pstSavm->m_lErrno = DOM_NOT_INITL; + return RC_FAIL; + } + + pstFace = (TFace *)pstRun->pstVoid; + pstFace->m_lFind = pstSavm->lFind; + pstFace->m_lDLen = pstSavm->lSize; + pstFace->m_lErrno = TVM_DONE_SUCC; + pstFace->m_enum = OPERAYS_UPDATE; + pstFace->m_table = pstSavm->tblName; + + checkbuffer(pstSavm, pstRun, 2); + pstCond = &pstSavm->stUpdt; + if(0 == pstCond->uFldcmp) + { + pstSavm->m_lErrno = UPDFD_NOT_SET; + return RC_FAIL; + } + + vBuildPacket(pstRun->pstVoid, pstSavm->pstVoid, &pstSavm->stCond, &lWrite); + vBuildPacket(pstRun->pstVoid, pvData, pstCond, &lWrite); + pstFace->m_lRows = lWrite - sizeof(TFace); + + if(lWrite != lSendBuffer(pstSavm->m_skSock, (void *)pstRun->pstVoid, lWrite)) + { + pstSavm->m_lErrno = SOCK_COM_EXCP; + return RC_FAIL; + } + + return RC_SUCC; +} + +/************************************************************************************************* + description:API - insert by asynch + parameters: + pstSavm --stvm handle + return: + RC_SUCC --success + RC_FAIL --failure + *************************************************************************************************/ +long lAsyInsert(SATvm *pstSavm) +{ + uint lWrite; + RunTime *pstRun; + TFace *pstFace; + + if(!pstSavm || !pstSavm->pstVoid) + { + pstSavm->m_lErrno = CONDIT_IS_NIL; + return RC_FAIL; + } + + pstRun = (RunTime *)pGetRunTime(pstSavm, 0); + if(!pstRun->pstVoid) + { + pstSavm->m_lErrno = DOM_NOT_INITL; + return RC_FAIL; + } + + pstFace = (TFace *)pstRun->pstVoid; + pstFace->m_lFind = pstSavm->lFind; + pstFace->m_lDLen = pstSavm->lSize; + pstFace->m_lErrno = TVM_DONE_SUCC; + pstFace->m_enum = OPERAYS_INSERT; + pstFace->m_table = pstSavm->tblName; + + pstFace->m_lRows = pstSavm->lSize; + lWrite = pstFace->m_lRows + sizeof(TFace); + + checkbuffer(pstSavm, pstRun, 1); + memcpy(pstRun->pstVoid + sizeof(TFace), pstSavm->pstVoid, pstSavm->lSize); + if(lWrite != lSendBuffer(pstSavm->m_skSock, (void *)pstRun->pstVoid, lWrite)) + { + pstSavm->m_lErrno = SOCK_COM_EXCP; + return RC_FAIL; + } + + return RC_SUCC; +} + /************************************************************************************************* description:API - insert parameters: diff --git a/src/tree.c b/src/tree.c index 3d6070e..d8ef080 100644 --- a/src/tree.c +++ b/src/tree.c @@ -461,6 +461,60 @@ void* pGetSATvm() return &g_stSavm; } +/************************************************************************************************* + description:clone stvm handle by thread + parameters: + return: + void* + *************************************************************************************************/ +void* pCloneSATvm() +{ + SATvm *pstSovm = (SATvm *)malloc(sizeof(SATvm)); + + if(!pstSovm) return NULL; + + memcpy(pstSovm, (SATvm *)pGetSATvm(), sizeof(SATvm)); + return pstSovm; +} + +/************************************************************************************************* + description:free the clone handle by thread + parameters: + return: + void* + *************************************************************************************************/ +void vCloneFree(SATvm *pstSovm) +{ + TFree(pstSovm); +} + +/************************************************************************************************* + description:initial stvm handle + parameters: + return: + *************************************************************************************************/ +long lAttchTable(SATvm *pstSovm, TABLE t) +{ + RunTime *pstRun = (RunTime *)pGetRunTime(pGetSATvm(), t); + + if(!pstSovm) return RC_FAIL; + + if(pstRun->m_bAttch && pstRun->m_pvAddr) + { + memcpy((RunTime *)pGetRunTime(pstSovm, t), pstRun, sizeof(RunTime)); + return RC_SUCC; + } + + if(RC_SUCC != lInitSATvm(pGetSATvm(), t)) + return RC_FAIL; + + if(NULL == (pstRun = (RunTime *)pInitHitTest(pGetSATvm(), t))) + return RC_FAIL; + + memcpy((RunTime *)pGetRunTime(pstSovm, t), pstRun, sizeof(RunTime)); + return RC_SUCC; +} + /************************************************************************************************* description:initial stvm handle parameters: @@ -584,7 +638,7 @@ TblDef* pGetTblDef(TABLE t) *************************************************************************************************/ RWLock* pGetRWLock(char* pvAddr) { - return &((TblDef *)pvAddr)->m_rwlock; + return (RWLock *)&((TblDef *)pvAddr)->m_rwlock; } /************************************************************************************************* @@ -1019,7 +1073,13 @@ void vHoldConnect(SATvm *pstSavm) void vHoldRelease(SATvm *pstSavm) { TABLE t; - RunTime *pstRun = NULL; + RunTime *pstRun = NULL; + + if(pstSavm != (SATvm *)pGetSATvm()) + { + TFree(pstSavm); + return; + } pstSavm->m_bHold = FALSE; for(t = 0; t < TVM_MAX_TABLE; t ++) @@ -6351,13 +6411,6 @@ long lInsert(SATvm *pstSavm) return _lInsertByRt(pstSavm); } - if(lGetTblRow(pstSavm->tblName) <= ((TblDef *)pstRun->m_pvAddr)->m_lValid) - { - pstSavm->m_lErrno = DATA_SPC_FULL; - vTblDisconnect(pstSavm, pstSavm->tblName); - return RC_FAIL; - } - prwLock = (RWLock *)pGetRWLock(pstRun->m_pvAddr); if(RC_SUCC != pthread_rwlock_wrlock(prwLock)) { @@ -6366,6 +6419,14 @@ long lInsert(SATvm *pstSavm) return RC_FAIL; } + if(lGetTblRow(pstSavm->tblName) <= ((TblDef *)pstRun->m_pvAddr)->m_lValid) + { + pthread_rwlock_unlock(prwLock); + pstSavm->m_lErrno = DATA_SPC_FULL; + vTblDisconnect(pstSavm, pstSavm->tblName); + return RC_FAIL; + } + lRet = __lInsert(pstSavm, pstRun->m_pvAddr, pstSavm->tblName, 0); pthread_rwlock_unlock(prwLock); vTblDisconnect(pstSavm, pstSavm->tblName); @@ -9806,7 +9867,7 @@ long lClick(SATvm *pstSavm, ulong *puHits) if(RES_REMOT_SID == pstRun->m_lLocal) { pstSavm->m_lErrno = RMT_NOT_SUPPT; - return RC_FAIL; + return RC_FAIL; // Tremohold(pstSavm, pstRun); // return _lSelectByRt(pstSavm, psvOut); } @@ -9899,7 +9960,7 @@ long lDumpTable(SATvm *pstSavm, TABLE t) fclose(fp); vTableClose(pstSavm); - fprintf(stdout, "导出表:%s 有效记录:%ld, completed successfully !!\n", sGetTableName(t), + fprintf(stdout, "导出表:%s 有效记录:%ld, completed successfully !!\n", sGetTableName(t), pstSavm->m_lEffect); return RC_SUCC; } @@ -9961,14 +10022,14 @@ long lMountTable(SATvm *pstSavm, char *pszFile) prwLock = (RWLock *)pGetRWLock(pstRun->m_pvAddr); if(RC_SUCC != pthread_rwlock_wrlock(prwLock)) { - vTblDisconnect(pstSavm, pstSavm->tblName); + vTblDisconnect(pstSavm, pstSavm->tblName); pstSavm->m_lErrno = LOCK_DOWR_ERR; goto MOUNT_ERROR; } while(1 == fread(pvData, stTde.m_lReSize, 1, fp)) { - fread((void *)&uTimes, sizeof(ulong), 1, fp); + fread((void *)&uTimes, sizeof(ulong), 1, fp); if(lGetTblRow(stTde.m_table) <= ((TblDef *)pstRun->m_pvAddr)->m_lValid) { pthread_rwlock_unlock(prwLock); @@ -9977,10 +10038,10 @@ long lMountTable(SATvm *pstSavm, char *pszFile) goto MOUNT_ERROR; } - lEffect ++; + lEffect ++; if(RC_SUCC != __lInsert(pstSavm, pstRun->m_pvAddr, pstSavm->tblName, uTimes)) { - fprintf(stderr, "=>警告, 导入表:%s 第(%ld)条记录错误, %s, 跳过..\n", + fprintf(stderr, "=>警告, 导入表:%s 第(%ld)条记录错误, %s, 跳过..\n", sGetTableName(stTde.m_table), lEffect, sGetTError(pstSavm->m_lErrno)); continue; } @@ -9992,7 +10053,7 @@ long lMountTable(SATvm *pstSavm, char *pszFile) pthread_rwlock_unlock(prwLock); vTblDisconnect(pstSavm, pstSavm->tblName); - fprintf(stdout, "导入表:%s 有效记录:%ld, completed successfully !!\n", + fprintf(stdout, "导入表:%s 有效记录:%ld, completed successfully !!\n", sGetTableName(stTde.m_table), lEffect); return RC_SUCC;