fix bugs and add asynchronous interface

pull/1/head
deffpuzzl 2018-04-30 22:48:49 +08:00
parent 4b2fe7b7c7
commit 5c3b628914
7 changed files with 383 additions and 92 deletions

View File

@ -60,6 +60,11 @@ stvm DOM 进入域的维护
>* 2、新增热点数据点击量api >* 2、新增热点数据点击量api
====***更新日期:20180430***====
>* 1、修复create脚本sizeof算法问题。
>* 2、新增异步操作(网络插入、删除、更新)异步接口支持。
**下本版本:** **下本版本:**
* 1、新增多机资源共享方式。 * 1、新增多机资源共享方式。

View File

@ -53,6 +53,12 @@ typedef struct __SOCK_CONNECT
int m_lCltPort; int m_lCltPort;
BSock m_skSock; BSock m_skSock;
int m_isListen; int m_isListen;
void *pvData;
void *pstFace;
void *pstVoid;
int m_lBuffer;
BOOL m_bHead;
int m_lRead;
BOOL m_bWork; BOOL m_bWork;
ulong m_uWorker; ulong m_uWorker;
CMList *m_pstWork; 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 lTvmRebuildIndex(SATvm *pstSavm, TABLE t);
extern long lTvmResetLock(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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -65,6 +65,11 @@ typedef long CREATE;
#define OPERATE_DELETE 2 #define OPERATE_DELETE 2
#define OPERATE_UPDATE 4 #define OPERATE_UPDATE 4
#define OPERATE_SELECT 8 #define OPERATE_SELECT 8
#define OPERAYS_INSERT 1025
#define OPERAYS_DELETE 1026
#define OPERAYS_UPDATE 1027
#define OPERATE_TRCATE 14 #define OPERATE_TRCATE 14
#define OPERATE_COUNT 15 #define OPERATE_COUNT 15
#define OPERATE_GROUP 16 #define OPERATE_GROUP 16
@ -109,7 +114,7 @@ typedef long CREATE;
#define MAX_FIELD_LEN 32 // maxinum length of Field name #define MAX_FIELD_LEN 32 // maxinum length of Field name
#ifndef MAX_FILED_NUM #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 #endif
#define MAX_REMOTE_IP 20 #define MAX_REMOTE_IP 20
@ -614,6 +619,8 @@ extern char* sGetLog();
extern char* sGetNode(); extern char* sGetNode();
extern void* pGetBoot(); extern void* pGetBoot();
extern void* pGetSATvm(); extern void* pGetSATvm();
extern void* pCloneSATvm();
extern void vCloneFree(SATvm *pstSavm);
extern long lDefaultBoot(); extern long lDefaultBoot();
extern TBoot* pBootInitial(); extern TBoot* pBootInitial();
extern size_t lGetTblRow(TABLE t); extern size_t lGetTblRow(TABLE t);

View File

@ -4,7 +4,7 @@ AR=ar
LD=ld LD=ld
LN=ln LN=ln
CC=cc -fPIC 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 LDFLAG=-shared -g
OUTLIB=../lib OUTLIB=../lib
OUTBIN=../bin OUTBIN=../bin

View File

@ -197,6 +197,12 @@ int sizecn(TblKey *pstKey, long lfld)
for(i = 0, k = 0; i < lfld; i ++) for(i = 0, k = 0; i < lfld; i ++)
{ {
pv = &pstKey[i]; pv = &pstKey[i];
if(FIELD_CHAR == pv->m_lAttr)
{
k = sizeof(char);
continue;
}
if(FIELD_CHAR != pv->m_lAttr && pv->m_lLen > k) if(FIELD_CHAR != pv->m_lAttr && pv->m_lLen > k)
k = pv->m_lLen; k = pv->m_lLen;
} }
@ -322,7 +328,7 @@ long lAnalysTable(char *s, long len, TblDef *pstTde)
{ {
long i, n, k; long i, n, k;
TblKey *pv = NULL; 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)); memset(szField, 0, sizeof(szField));
if(len > sizeof(szField) || len < 1) if(len > sizeof(szField) || len < 1)
@ -2179,9 +2185,6 @@ long _lExeExtreme(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, void *pv
if(RC_SUCC != lRet) if(RC_SUCC != lRet)
{ {
TFree(pvResult); TFree(pvResult);
vDestroyFiled(pstRoot);
fprintf(stderr, "extreme table (%s) failure, %s\n", pstIndex->m_szTable,
sGetTError(pstSavm->m_lErrno));
return RC_FAIL; return RC_FAIL;
} }
@ -2236,7 +2239,6 @@ long _lExeExtreme(SATvm *pstSavm, TIndex *pstIndex, SQLFld *pstRoot, void *pv
TFree(pvResult); TFree(pvResult);
fprintf(stdout, "---(%ld)records selected -ep(%d)--\n", pstSavm->m_lEffect, pstSavm->m_lEType); fprintf(stdout, "---(%ld)records selected -ep(%d)--\n", pstSavm->m_lEffect, pstSavm->m_lEType);
vDestroyFiled(pstRoot);
return RC_SUCC; 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)) if(RC_SUCC != _lExeExtreme(pstSavm, &stIndex, pstRoot, pvWhere, bRmt))
goto ERR_SELECT; goto ERR_SELECT;
vDestroyFiled(pstRoot);
pstRoot = NULL;
TFree(pstField); TFree(pstField);
TFree(pvWhere); TFree(pvWhere);
return RC_SUCC; return RC_SUCC;
@ -2348,12 +2352,14 @@ long _lParseSelect(SATvm *pstSavm, char *pszTable, char *pszField, char *pszW
TFree(pvWhere); TFree(pvWhere);
vDestroyFiled(pstRoot); vDestroyFiled(pstRoot);
pstRoot = NULL;
return RC_SUCC; return RC_SUCC;
ERR_SELECT: ERR_SELECT:
TFree(pvWhere); TFree(pvWhere);
TFree(pstField); TFree(pstField);
vDestroyFiled(pstRoot); vDestroyFiled(pstRoot);
pstRoot = NULL;
return RC_FAIL; return RC_FAIL;
} }

338
src/tcp.c
View File

@ -39,29 +39,29 @@ void* pProtocaJava(SATvm *pstSavm, void *pstVoid, TFace *pstFace, void *pvBuff
/************************************************************************************************* /*************************************************************************************************
macro 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) \ #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) \ if(MAX(f->m_lRows, f->m_lDLen) > DATA_MAX_LEN) \
{ \ { \
f->m_lErrno = RECD_TOO_LONG; \ s->m_lErrno = RECD_TOO_LONG; \
goto LISTEN_ERROR; \ goto LISTEN_ERROR; \
} \ } \
l = MAX(f->m_lRows, f->m_lDLen); \ c->m_lBuffer = MAX(f->m_lRows, f->m_lDLen); \
if(NULL == (c = (void *)realloc(c, l + sizeof(TFace)))) \ if(NULL == (c->pstFace = (void *)realloc(c->pstFace, c->m_lBuffer + sizeof(TFace)))) \
{ \ { \
f->m_lErrno = MALLC_MEM_ERR; \ s->m_lErrno = MALLC_MEM_ERR; \
goto LISTEN_ERROR; \ goto LISTEN_ERROR; \
} \ } \
f = (TFace *)c; \ f = (TFace *)c->pstFace; \
d = c + sizeof(TFace); \ c->pvData = c->pstFace + sizeof(TFace); \
if(NULL == (v = (void *)realloc(v, l + sizeof(TFace)))) \ if(NULL == (c->pstVoid = (void *)realloc(c->pstVoid, c->m_lBuffer + sizeof(TFace)))) \
{ \ { \
f->m_lErrno = MALLC_MEM_ERR; \ s->m_lErrno = MALLC_MEM_ERR; \
goto LISTEN_ERROR; \ goto LISTEN_ERROR; \
} \ } \
} }
#define checkbuffer(p, r, n) if((p->lSize * n + r->m_lCurLine) > r->m_lRowSize) \ #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; pstFace->m_lRows = pstSavm->m_lEffect;
lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace));
return RC_SUCC; 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: case OPERATE_INSERT:
pstSavm->m_bWork = pstCon->m_bWork; pstSavm->m_bWork = pstCon->m_bWork;
pstSavm->m_pstWork = pstCon->m_pstWork; pstSavm->m_pstWork = pstCon->m_pstWork;
@ -1623,13 +1642,27 @@ long lEpollAccept(SATvm *pstSavm, BSock epfd, SKCon *pc)
return RC_FAIL; 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_skSock = skAccept;
pstCon->m_lCltPort = ntohs(cAddr.sin_port); 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)); strncpy(pstCon->m_szCltIp, inet_ntoa(cAddr.sin_addr), sizeof(pstCon->m_szCltIp));
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
event.data.ptr = pstCon; 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)) if(0 != epoll_ctl(epfd, EPOLL_CTL_ADD, skAccept, &event))
{ {
close(skAccept); close(skAccept);
@ -1695,15 +1728,21 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi
{ {
lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace));
vResetRemote(pstSovm, pstCon->m_szCltIp, pstFace->m_lFind, pstCon->m_skSock); vResetRemote(pstSovm, pstCon->m_szCltIp, pstFace->m_lFind, pstCon->m_skSock);
pstCon->m_lRead = 0;
pstCon->m_bHead = FALSE;
return RC_SUCC; return RC_SUCC;
} }
if(pstFace->m_lRows != lRecvBuffer(pstCon->m_skSock, pvData, pstFace->m_lRows)) if(0 > (lRet = lRecvBuffer(pstCon->m_skSock, pvData + pstCon->m_lRead,
{ pstFace->m_lRows - pstCon->m_lRead)))
Tlog("recv %d byte, err:%s", lRet, strerror(errno));
return RC_FAIL; 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 = (RunTime *)pGetRunTime(pstSovm, pstFace->m_table);
pstRun->m_bAttch = pstSovm->stRunTime[pstFace->m_table].m_bAttch; pstRun->m_bAttch = pstSovm->stRunTime[pstFace->m_table].m_bAttch;
pstRun->m_pvAddr = pstSovm->stRunTime[pstFace->m_table].m_pvAddr; 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) void* vEpollListen(void *pvParam)
{ {
long lRet, i, nWait;
SKCon *pstCon = NULL; SKCon *pstCon = NULL;
TFace *pstFace = NULL; TFace *pstFace = NULL;
epollevt events[MAX_EVENTS]; epollevt events[MAX_EVENTS];
BSock epfd = *((long *)pvParam); BSock epfd = *((long *)pvParam);
long i, nWait, lBuffer = READ_MAX_LEN;
char *pvData, *pvFace = NULL, *pstVoid = NULL;
SATvm *pstSavm = (SATvm *)calloc(1, sizeof(SATvm)); SATvm *pstSavm = (SATvm *)calloc(1, sizeof(SATvm));
pthread_detach(pthread_self()); pthread_detach(pthread_self());
vHoldConnect(pstSavm); 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)) if(RC_SUCC != lTvmBuffer(pstSavm))
return NULL; return NULL;
pstFace = (TFace *)pvFace;
pvData = pvFace + sizeof(TFace);
while(g_eRun) 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++) for(i = 0; i < nWait; i++)
{ {
pstCon = (SKCon *)events[i].data.ptr; pstCon = (SKCon *)events[i].data.ptr;
@ -1804,29 +1832,45 @@ void* vEpollListen(void *pvParam)
lEpollAccept(pstSavm, epfd, pstCon); lEpollAccept(pstSavm, epfd, pstCon);
else if(events[i].events & EPOLLIN) else if(events[i].events & EPOLLIN)
{ {
if(sizeof(TFace) != lRecvBuffer(pstCon->m_skSock, pvFace, sizeof(TFace))) if(FALSE == pstCon->m_bHead)
{ {
if(pstCon->m_bWork) if(0 > (lRet = lRecvBuffer(pstCon->m_skSock, pstCon->pstFace + pstCon->m_lRead,
{ sizeof(TFace) - pstCon->m_lRead)))
pstSavm->m_bWork = pstCon->m_bWork; {
pstSavm->m_pstWork = pstCon->m_pstWork; if(pstCon->m_bWork)
lRollbackWork(pstSavm); {
pstCon->m_bWork = false; pstSavm->m_bWork = pstCon->m_bWork;
} pstSavm->m_pstWork = pstCon->m_pstWork;
pstCon->m_pstWork = NULL; lRollbackWork(pstSavm);
epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); pstCon->m_bWork = false;
close(pstCon->m_skSock); }
continue; pstCon->m_pstWork = NULL;
} epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]);
TFree(pstCon->pstFace);
if(TVM_MAX_TABLE <= pstFace->m_table) TFree(pstCon->pstVoid);
{ close(pstCon->m_skSock);
pstFace->m_lErrno = RESOU_DISABLE; continue;
goto LISTEN_ERROR; }
}
pstCon->m_lRead += lRet;
checkrequest(pstFace, pvFace, pstVoid, pvData, lBuffer); if(sizeof(TFace) != pstCon->m_lRead) // more data wait to read
if(RC_FAIL == lPollRequest(pstSavm, pstCon, pstFace, pstVoid, pvData)) 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) if(pstCon->m_bWork)
{ {
@ -1837,6 +1881,8 @@ void* vEpollListen(void *pvParam)
} }
pstCon->m_pstWork = NULL; pstCon->m_pstWork = NULL;
epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]);
TFree(pstCon->pstFace);
TFree(pstCon->pstVoid);
close(pstCon->m_skSock); close(pstCon->m_skSock);
} }
} }
@ -1844,13 +1890,11 @@ void* vEpollListen(void *pvParam)
continue; continue;
LISTEN_ERROR: LISTEN_ERROR:
lSendBuffer(pstCon->m_skSock, pvFace, sizeof(TFace)); lSendBuffer(pstCon->m_skSock, pstCon->pstFace, sizeof(TFace));
continue; continue;
} }
close(epfd); close(epfd);
TFree(pvFace);
TFree(pstVoid);
pstSavm->pstVoid = NULL; pstSavm->pstVoid = NULL;
vTvmDisconnect(pstSavm); vTvmDisconnect(pstSavm);
return NULL; return NULL;
@ -2313,7 +2357,9 @@ long lBootLocal(SATvm *pstSavm, TBoot *pstBoot, Benum eMode)
memset(&event, 0, sizeof(event)); memset(&event, 0, sizeof(event));
event.data.ptr = pstCon; 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)) if(0 != epoll_ctl(epfd, EPOLL_CTL_ADD, pstCon->m_skSock, &event))
{ {
fprintf(stderr, "add socket (%d) error, err:(%d)(%s)", pstCon->m_skSock, 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) switch(pstFace->m_enum)
{ {
case OPERAYS_INSERT:
case OPERATE_INSERT: case OPERATE_INSERT:
return memcpy(pstVoid, pvData, pstFace->m_lDLen); return memcpy(pstVoid, pvData, pstFace->m_lDLen);
case OPERAYS_UPDATE:
case OPERATE_UPDATE: case OPERATE_UPDATE:
memcpy(&pstCond->uFldcmp, pvData, sizeof(uint)); memcpy(&pstCond->uFldcmp, pvData, sizeof(uint));
for(i = 0, pvData += sizeof(uint); i < pstCond->uFldcmp; i ++) 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_SELECT:
case OPERATE_QUERY: case OPERATE_QUERY:
case OPERATE_DELETE: case OPERATE_DELETE:
case OPERAYS_DELETE:
case OPERATE_TRCATE: case OPERATE_TRCATE:
case OPERATE_GROUP: case OPERATE_GROUP:
case OPERATE_COUNT: case OPERATE_COUNT:
@ -3944,6 +3993,159 @@ long lTvmQuery(SATvm *pstSavm, size_t *plOut, void **ppvOut)
return RC_SUCC; return RC_SUCC;
} }
/*************************************************************************************************
descriptionAPI - 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;
}
/*************************************************************************************************
descriptionAPI - 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;
}
/*************************************************************************************************
descriptionAPI - 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;
}
/************************************************************************************************* /*************************************************************************************************
descriptionAPI - insert descriptionAPI - insert
parameters: parameters:

View File

@ -461,6 +461,60 @@ void* pGetSATvm()
return &g_stSavm; return &g_stSavm;
} }
/*************************************************************************************************
descriptionclone 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;
}
/*************************************************************************************************
descriptionfree the clone handle by thread
parameters:
return:
void*
*************************************************************************************************/
void vCloneFree(SATvm *pstSovm)
{
TFree(pstSovm);
}
/*************************************************************************************************
descriptioninitial 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;
}
/************************************************************************************************* /*************************************************************************************************
descriptioninitial stvm handle descriptioninitial stvm handle
parameters: parameters:
@ -584,7 +638,7 @@ TblDef* pGetTblDef(TABLE t)
*************************************************************************************************/ *************************************************************************************************/
RWLock* pGetRWLock(char* pvAddr) 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) void vHoldRelease(SATvm *pstSavm)
{ {
TABLE t; TABLE t;
RunTime *pstRun = NULL; RunTime *pstRun = NULL;
if(pstSavm != (SATvm *)pGetSATvm())
{
TFree(pstSavm);
return;
}
pstSavm->m_bHold = FALSE; pstSavm->m_bHold = FALSE;
for(t = 0; t < TVM_MAX_TABLE; t ++) for(t = 0; t < TVM_MAX_TABLE; t ++)
@ -6351,13 +6411,6 @@ long lInsert(SATvm *pstSavm)
return _lInsertByRt(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); prwLock = (RWLock *)pGetRWLock(pstRun->m_pvAddr);
if(RC_SUCC != pthread_rwlock_wrlock(prwLock)) if(RC_SUCC != pthread_rwlock_wrlock(prwLock))
{ {
@ -6366,6 +6419,14 @@ long lInsert(SATvm *pstSavm)
return RC_FAIL; 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); lRet = __lInsert(pstSavm, pstRun->m_pvAddr, pstSavm->tblName, 0);
pthread_rwlock_unlock(prwLock); pthread_rwlock_unlock(prwLock);
vTblDisconnect(pstSavm, pstSavm->tblName); vTblDisconnect(pstSavm, pstSavm->tblName);
@ -9806,7 +9867,7 @@ long lClick(SATvm *pstSavm, ulong *puHits)
if(RES_REMOT_SID == pstRun->m_lLocal) if(RES_REMOT_SID == pstRun->m_lLocal)
{ {
pstSavm->m_lErrno = RMT_NOT_SUPPT; pstSavm->m_lErrno = RMT_NOT_SUPPT;
return RC_FAIL; return RC_FAIL;
// Tremohold(pstSavm, pstRun); // Tremohold(pstSavm, pstRun);
// return _lSelectByRt(pstSavm, psvOut); // return _lSelectByRt(pstSavm, psvOut);
} }
@ -9899,7 +9960,7 @@ long lDumpTable(SATvm *pstSavm, TABLE t)
fclose(fp); fclose(fp);
vTableClose(pstSavm); vTableClose(pstSavm);
fprintf(stdout, "导出表:%s 有效记录:%ld, completed successfully !!\n", sGetTableName(t), fprintf(stdout, "导出表:%s 有效记录:%ld, completed successfully !!\n", sGetTableName(t),
pstSavm->m_lEffect); pstSavm->m_lEffect);
return RC_SUCC; return RC_SUCC;
} }
@ -9961,14 +10022,14 @@ long lMountTable(SATvm *pstSavm, char *pszFile)
prwLock = (RWLock *)pGetRWLock(pstRun->m_pvAddr); prwLock = (RWLock *)pGetRWLock(pstRun->m_pvAddr);
if(RC_SUCC != pthread_rwlock_wrlock(prwLock)) if(RC_SUCC != pthread_rwlock_wrlock(prwLock))
{ {
vTblDisconnect(pstSavm, pstSavm->tblName); vTblDisconnect(pstSavm, pstSavm->tblName);
pstSavm->m_lErrno = LOCK_DOWR_ERR; pstSavm->m_lErrno = LOCK_DOWR_ERR;
goto MOUNT_ERROR; goto MOUNT_ERROR;
} }
while(1 == fread(pvData, stTde.m_lReSize, 1, fp)) 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) if(lGetTblRow(stTde.m_table) <= ((TblDef *)pstRun->m_pvAddr)->m_lValid)
{ {
pthread_rwlock_unlock(prwLock); pthread_rwlock_unlock(prwLock);
@ -9977,10 +10038,10 @@ long lMountTable(SATvm *pstSavm, char *pszFile)
goto MOUNT_ERROR; goto MOUNT_ERROR;
} }
lEffect ++; lEffect ++;
if(RC_SUCC != __lInsert(pstSavm, pstRun->m_pvAddr, pstSavm->tblName, uTimes)) 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)); sGetTableName(stTde.m_table), lEffect, sGetTError(pstSavm->m_lErrno));
continue; continue;
} }
@ -9992,7 +10053,7 @@ long lMountTable(SATvm *pstSavm, char *pszFile)
pthread_rwlock_unlock(prwLock); pthread_rwlock_unlock(prwLock);
vTblDisconnect(pstSavm, pstSavm->tblName); vTblDisconnect(pstSavm, pstSavm->tblName);
fprintf(stdout, "导入表:%s 有效记录:%ld, completed successfully !!\n", fprintf(stdout, "导入表:%s 有效记录:%ld, completed successfully !!\n",
sGetTableName(stTde.m_table), lEffect); sGetTableName(stTde.m_table), lEffect);
return RC_SUCC; return RC_SUCC;