Repair multithreading exit bug

pull/1/head
deffpuzzl 2018-06-11 23:49:32 +08:00
parent 7e155af62c
commit ac3ec27fd5
9 changed files with 102 additions and 95 deletions

View File

@ -28,7 +28,7 @@ int main(int argc, char *argv[])
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量 conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
// stUser.acct_id = time(NULL); // 对结构体赋值 // stUser.acct_id = time(NULL); // 对结构体赋值
strcpy(stUser.user_no, "20180223"); // 对结构体赋值 strcpy(stUser.user_no, "20180224"); // 对结构体赋值
strcpy(stUser.user_type, "1"); // 对结构体赋值 strcpy(stUser.user_type, "1"); // 对结构体赋值
strcpy(stUser.user_nm, "Savens Liu"); // 对结构体赋值 strcpy(stUser.user_nm, "Savens Liu"); // 对结构体赋值
strcpy(stUser.user_addr, "China"); // 对结构体赋值 strcpy(stUser.user_addr, "China"); // 对结构体赋值

View File

@ -26,7 +26,7 @@ int main(int argc, char *argv[])
} }
queueinit(pstSavm, stUser, QUEUE_USER_INFO); queueinit(pstSavm, stUser, QUEUE_USER_INFO);
if(RC_SUCC != lTvmPop(pstSavm, (void *)&stUser, QUE_NORMAL)) // 插入记录 if(RC_SUCC != lTvmPop(pstSavm, (void *)&stUser, QUE_NORMAL))
{ {
fprintf(stderr, "Pop error:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno)); fprintf(stderr, "Pop error:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL; return RC_FAIL;

View File

@ -198,10 +198,11 @@ typedef long CREATE;
#define IS_TRUCK_NRML(p) ((p)->m_chTag == DATA_TRUCK_NRML) #define IS_TRUCK_NRML(p) ((p)->m_chTag == DATA_TRUCK_NRML)
#define IS_TRUCK_LOCK(p) ((p)->m_chTag == DATA_TRUCK_LOCK) #define IS_TRUCK_LOCK(p) ((p)->m_chTag == DATA_TRUCK_LOCK)
#define SET_DATA_TRUCK(p, type) ((p)->m_chTag = type) #define SET_DATA_TRUCK(p, type) ((p)->m_chTag = type)
#define TFree(p) if(p) { free(p); p = NULL; } #define TFree(p) if(p) { free(p); p = NULL; }
#define TFgrp(p) do{vDeleteRowgrp(p);p = NULL;}while(0); #define TFgrp(p) do{vDeleteRowgrp(p);p = NULL;}while(0);
#define TFlst(p) do{vDestroyList(p);p = NULL;}while(0); #define TFlst(p) do{vDestroyList(p);p = NULL;}while(0);
#define TClose(f) if(f) { fclose(f); f = NULL; } #define TClose(f) if(f) { fclose(f); f = NULL; }
#define Tdefstr(d,s,l) if(0 == *d) strncpy(d, s, l);
#define Futex(a,o,v,t) syscall(SYS_futex, a, o, v, t, NULL, 0) #define Futex(a,o,v,t) syscall(SYS_futex, a, o, v, t, NULL, 0)
#define Tremohold(p,r) if(p->m_bHold) r->m_lState = RESOURCE_ABLE; #define Tremohold(p,r) if(p->m_bHold) r->m_lState = RESOURCE_ABLE;
@ -677,6 +678,13 @@ typedef struct __TVM_BOOT_PARAM
char m_szLog[MAX_STRIG_LEN]; char m_szLog[MAX_STRIG_LEN];
}TBoot; }TBoot;
typedef struct __THREAD_RUN
{
BSock m_epfd;
pthread_t m_tPid;
bool m_bRun;
}TThread;
/************************************************************************************************* /*************************************************************************************************
STVM user define STVM user define
*************************************************************************************************/ *************************************************************************************************/

View File

@ -791,7 +791,7 @@ long lParseResouce(SATvm *pstSavm, char *pszFile, long *plCout, TDomain **pps
strncpy(pv->m_szIp, sgetvalue(szValue, ":", 1), sizeof(pv->m_szIp)); strncpy(pv->m_szIp, sgetvalue(szValue, ":", 1), sizeof(pv->m_szIp));
pv->m_lPort = atol(sgetvalue(szValue, ":", 2)); pv->m_lPort = atol(sgetvalue(szValue, ":", 2));
} }
else if(!strcasecmp(szTarg, "TIMTOUT")) else if(!strcasecmp(szTarg, "TIMEOUT"))
pv->m_lTimeOut = atol(szValue); pv->m_lTimeOut = atol(szValue);
else if(!strcasecmp(szTarg, "MAXTRY")) else if(!strcasecmp(szTarg, "MAXTRY"))
pv->m_lTryMax = atol(szValue); pv->m_lTryMax = atol(szValue);
@ -819,7 +819,7 @@ long lParseResouce(SATvm *pstSavm, char *pszFile, long *plCout, TDomain **pps
} }
pv->m_lGroup = pv->m_lGroup > 0 ? pv->m_lGroup : 1; pv->m_lGroup = pv->m_lGroup > 0 ? pv->m_lGroup : 1;
pv->m_lTimeOut = pv->m_lTimeOut > 0 ? pv->m_lTimeOut : 5; pv->m_lTimeOut = pv->m_lTimeOut > 0 ? pv->m_lTimeOut : 2;
pv->m_lTryMax = pv->m_lTryMax > 0 ? pv->m_lTryMax : 3; pv->m_lTryMax = pv->m_lTryMax > 0 ? pv->m_lTryMax : 3;
pv->m_lKeepLive= pv->m_lKeepLive > 0 ? pv->m_lKeepLive : 30; pv->m_lKeepLive= pv->m_lKeepLive > 0 ? pv->m_lKeepLive : 30;
} }
@ -925,20 +925,19 @@ long lParseDomain(char *pszBuffer, TIndex *pstIndex, TDomain *pstDom, long *p
} }
} }
pv->m_lTryMax = 0; pv->m_lTryMax = 0;
pv->m_lLastTime = 0; pv->m_lLastTime = 0;
pv->m_lStatus = RESOURCE_INIT; pv->m_lStatus = RESOURCE_INIT;
pv->m_table = pstIndex->m_table; pv->m_table = pstIndex->m_table;
pv->m_lPort = pstDom->m_lPort; pv->m_lPort = pstDom->m_lPort;
pv->m_lGroup = pstDom->m_lGroup; pv->m_lGroup = pstDom->m_lGroup;
pv->m_lKeepLive = pstDom->m_lKeepLive; pv->m_lKeepLive = pstDom->m_lKeepLive;
pv->m_lTimeOut = pstDom->m_lTimeOut; pv->m_lTimeOut = pstDom->m_lTimeOut;
pv->m_lTryMax = pstDom->m_lTryMax; pv->m_lTryMax = pstDom->m_lTryMax;
strcpy(pv->m_szIp, pstDom->m_szIp); strcpy(pv->m_szIp, pstDom->m_szIp);
strcpy(pv->m_szTable, pstIndex->m_szTable); strcpy(pv->m_szTable, pstIndex->m_szTable);
strcpy(pv->m_szOwner, pstDom->m_szOwner); strcpy(pv->m_szOwner, pstDom->m_szOwner);
if(!strlen(pv->m_szPart)) Tdefstr(pv->m_szPart, pstDom->m_szOwner, sizeof(pv->m_szPart));
strcpy(pv->m_szPart, pstDom->m_szOwner);
return RC_SUCC; return RC_SUCC;
} }
@ -1242,7 +1241,7 @@ long lUnmakeConfig(char *pszFile)
if(!bf) if(!bf)
{ {
bf = !bf; bf = !bf;
fprintf(fp, "GROUP=%ld TIMTOUT=%ld MAXTRY=%ld KEEPALIVE=%ld\n", fprintf(fp, "GROUP=%ld TIMEOUT=%ld MAXTRY=%ld KEEPALIVE=%ld\n",
pstDomain[j].m_lGroup, pstDomain[j].m_lTimeOut, pstDomain[j].m_lTryMax, pstDomain[j].m_lGroup, pstDomain[j].m_lTimeOut, pstDomain[j].m_lTryMax,
pstDomain[j].m_lKeepLive); pstDomain[j].m_lKeepLive);
} }

View File

@ -11,7 +11,7 @@ LDFLAG=-shared -g
OUTLIB=../lib OUTLIB=../lib
OUTBIN=../bin OUTBIN=../bin
OBJFILE=tree.o sem.o msg.o tcp.o str.o list.o conf.o queue.o OBJFILE=tree.o sem.o msg.o tcp.o str.o list.o conf.o queue.o func.o
TARGET=$(OUTLIB)/libstvm.a TARGET=$(OUTLIB)/libstvm.a
#TARDLL=$(OUTLIB)/libstvm.so #TARDLL=$(OUTLIB)/libstvm.so
TARVER=$(OUTLIB)/libstvm.so.1.2 TARVER=$(OUTLIB)/libstvm.so.1.2

View File

@ -404,8 +404,7 @@ long _lParseAlias(SATvm *pstSavm, char *pszTable, char *pszField, char *pszAl
strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart));
strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable));
supper(stIndex.m_szTable); supper(stIndex.m_szTable);
if(0x00 == stIndex.m_szPart[0]) Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart));
strcpy(stIndex.m_szPart, sGetNode());
if(RC_SUCC != lGetTblIndex(pstSavm, stIndex.m_szTable, stIndex.m_szPart, &stIndex)) if(RC_SUCC != lGetTblIndex(pstSavm, stIndex.m_szTable, stIndex.m_szPart, &stIndex))
return RC_FAIL; return RC_FAIL;
@ -1358,8 +1357,7 @@ long _lShowTableInfo(SATvm *pstSavm, char *pszTable, bool bRmt)
strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart));
strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable));
supper(stIndex.m_szTable); supper(stIndex.m_szTable);
if(0x00 == stIndex.m_szPart[0]) Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart));
strcpy(stIndex.m_szPart, sGetNode());
if(bRmt) if(bRmt)
{ {
@ -2013,11 +2011,8 @@ long _lExeUpdate(SATvm *pstSavm, TIndex *pstIndex, void *pvNew, char *pvData,
else else
lRet = lUpdate(pstSavm, (void *)pvNew); lRet = lUpdate(pstSavm, (void *)pvNew);
if(RC_SUCC != lRet) if(RC_SUCC != lRet)
{
fprintf(stderr, "update table (%s) failure, %s\n", pstIndex->m_szTable,
sGetTError(pstSavm->m_lErrno));
return RC_FAIL; return RC_FAIL;
}
lTime -= lGetTiskTime(); lTime -= lGetTiskTime();
fprintf(stdout, "---(%ld) records updated, ep(%d), %s---\n", pstSavm->m_lEffect, pstSavm->m_lEType, fprintf(stdout, "---(%ld) records updated, ep(%d), %s---\n", pstSavm->m_lEffect, pstSavm->m_lEType,
@ -2078,13 +2073,9 @@ long _lExeInsert(SATvm *pstSavm, TIndex *pstIndex, void *pvInsert, bool bRmt)
else else
lRet = lInsert(pstSavm); lRet = lInsert(pstSavm);
if(RC_SUCC != lRet) if(RC_SUCC != lRet)
{
fprintf(stderr, "insert table (%s) failure, %s\n", pstIndex->m_szTable,
sGetTError(pstSavm->m_lErrno));
return RC_FAIL; return RC_FAIL;
}
lTime -= lGetTiskTime();
lTime -= lGetTiskTime();
fprintf(stdout, "---(%ld) records inserted, %s---\n", pstSavm->m_lEffect, sGetCostTime(-1 * lTime)); fprintf(stdout, "---(%ld) records inserted, %s---\n", pstSavm->m_lEffect, sGetCostTime(-1 * lTime));
return RC_SUCC; return RC_SUCC;
} }
@ -2205,11 +2196,8 @@ long _lCountSelect(SATvm *pstSavm, TIndex *pstIndex, char *pvData, bool bRmt)
else else
lRet = lCount(pstSavm, &lSum); lRet = lCount(pstSavm, &lSum);
if(lRet != RC_SUCC) if(lRet != RC_SUCC)
{
fprintf(stderr, "count table (%s) failure, %s\n", pstIndex->m_szTable,
sGetTError(pstSavm->m_lErrno));
return RC_FAIL; return RC_FAIL;
}
lTime -= lGetTiskTime(); lTime -= lGetTiskTime();
fprintf(stdout, "COUNT(*)\n"); fprintf(stdout, "COUNT(*)\n");
@ -2241,13 +2229,9 @@ long _lExeClick(SATvm *pstSavm, TIndex *pstIndex, char *pvData, bool bRmt)
else else
lRet = lClick(pstSavm, &ulHits); lRet = lClick(pstSavm, &ulHits);
if(lRet != RC_SUCC) if(lRet != RC_SUCC)
{
fprintf(stderr, "count table (%s) failure, %s\n", pstIndex->m_szTable,
sGetTError(pstSavm->m_lErrno));
return RC_FAIL; return RC_FAIL;
}
lTime -= lGetTiskTime();
lTime -= lGetTiskTime();
fprintf(stdout, "HITSPOT\n"); fprintf(stdout, "HITSPOT\n");
fprintf(stdout, "%zu\n", ulHits); fprintf(stdout, "%zu\n", ulHits);
fflush(stdout); fflush(stdout);
@ -2822,8 +2806,7 @@ long _lParseSelect(SATvm *pstSavm, char *pszTable, char *pszField, char *pszW
strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart));
strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable));
supper(stIndex.m_szTable); supper(stIndex.m_szTable);
if(0x00 == stIndex.m_szPart[0]) Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart));
strcpy(stIndex.m_szPart, sGetNode());
if(!strcmp(stIndex.m_szTable, "SEQUENCE")) if(!strcmp(stIndex.m_szTable, "SEQUENCE"))
return lParseSequece(pstSavm, stIndex.m_szPart, pszField, bRmt); return lParseSequece(pstSavm, stIndex.m_szPart, pszField, bRmt);
@ -3034,8 +3017,7 @@ long _lParseUpdate(SATvm *pstSavm, char *pszTable, char *pszField, char *pszW
strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart));
strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable));
supper(stIndex.m_szTable); supper(stIndex.m_szTable);
if(0x00 == stIndex.m_szPart[0]) Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart));
strcpy(stIndex.m_szPart, sGetNode());
if(bRmt) if(bRmt)
{ {
@ -3178,8 +3160,7 @@ long _lParseDelete(SATvm *pstSavm, char *pszTable, char *pszWhere, bool bRmt
strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart));
strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable));
supper(stIndex.m_szTable); supper(stIndex.m_szTable);
if(0x00 == stIndex.m_szPart[0]) Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart));
strcpy(stIndex.m_szPart, sGetNode());
if(bRmt) if(bRmt)
{ {
@ -3439,8 +3420,7 @@ long _lParseInsert(SATvm *pstSavm, char *pszTable, char *pszField, char *pszV
strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szPart, sgetvalue(pszTable, "@", 2), sizeof(stIndex.m_szPart));
strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable)); strncpy(stIndex.m_szTable, sgetvalue(pszTable, "@", 1), sizeof(stIndex.m_szTable));
supper(stIndex.m_szTable); supper(stIndex.m_szTable);
if(0x00 == stIndex.m_szPart[0]) Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart));
strcpy(stIndex.m_szPart, sGetNode());
if(bRmt) if(bRmt)
{ {
@ -3597,8 +3577,7 @@ long _lTruncateSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt)
strncpy(stIndex.m_szPart, sgetvalue(szTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szPart, sgetvalue(szTable, "@", 2), sizeof(stIndex.m_szPart));
strncpy(stIndex.m_szTable, sgetvalue(szTable, "@", 1), sizeof(stIndex.m_szTable)); strncpy(stIndex.m_szTable, sgetvalue(szTable, "@", 1), sizeof(stIndex.m_szTable));
supper(stIndex.m_szTable); supper(stIndex.m_szTable);
if(0x00 == stIndex.m_szPart[0]) Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart));
strcpy(stIndex.m_szPart, sGetNode());
if(bRmt) if(bRmt)
{ {
@ -3654,8 +3633,7 @@ long _lDropSyntax(SATvm *pstSavm, char *pszSQL, bool bRmt)
strncpy(stIndex.m_szPart, sgetvalue(szTable, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szPart, sgetvalue(szTable, "@", 2), sizeof(stIndex.m_szPart));
strncpy(stIndex.m_szTable, sgetvalue(szTable, "@", 1), sizeof(stIndex.m_szTable)); strncpy(stIndex.m_szTable, sgetvalue(szTable, "@", 1), sizeof(stIndex.m_szTable));
supper(stIndex.m_szTable); supper(stIndex.m_szTable);
if(0x00 == stIndex.m_szPart[0]) Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart));
strcpy(stIndex.m_szPart, sGetNode());
if(bRmt) if(bRmt)
{ {
@ -3717,8 +3695,7 @@ long _lLoadSyntax(SATvm *pstSavm, char *pszSQL)
strncpy(stIndex.m_szPart, sgetvalue(szParam, "@", 2), sizeof(stIndex.m_szPart)); strncpy(stIndex.m_szPart, sgetvalue(szParam, "@", 2), sizeof(stIndex.m_szPart));
strncpy(stIndex.m_szTable, sgetvalue(szParam, "@", 1), sizeof(stIndex.m_szTable)); strncpy(stIndex.m_szTable, sgetvalue(szParam, "@", 1), sizeof(stIndex.m_szTable));
supper(stIndex.m_szTable); supper(stIndex.m_szTable);
if(0x00 == stIndex.m_szPart[0]) Tdefstr(stIndex.m_szPart, sGetNode(), sizeof(stIndex.m_szPart));
strcpy(stIndex.m_szPart, sGetNode());
if(RC_SUCC != lGetTblIndex(pstSavm, stIndex.m_szTable, stIndex.m_szPart, &stIndex)) if(RC_SUCC != lGetTblIndex(pstSavm, stIndex.m_szTable, stIndex.m_szPart, &stIndex))
return RC_FAIL; return RC_FAIL;
@ -4074,6 +4051,8 @@ long lStopSystem(TBoot *pstBoot, char *pszApp)
snprintf(szCmd, sizeof(szCmd), "ps -u %s|grep -E \"%s|%s\"|awk '{print $1}'", snprintf(szCmd, sizeof(szCmd), "ps -u %s|grep -E \"%s|%s\"|awk '{print $1}'",
getenv("LOGNAME"), TVM_LOCAL_SERV, TVM_REMOTE_DOM); getenv("LOGNAME"), TVM_LOCAL_SERV, TVM_REMOTE_DOM);
if(!bIsTvmBoot()) return RC_SUCC;
if(TVM_BOOT_CLUSTER == pstBoot->m_lBootType) if(TVM_BOOT_CLUSTER == pstBoot->m_lBootType)
lOfflineNotify(pstSavm, pstBoot->m_lBootPort); lOfflineNotify(pstSavm, pstBoot->m_lBootPort);
@ -4880,7 +4859,15 @@ int main(int argc, char *argv[])
TBoot *pstBoot = (TBoot *)pBootInitial(); TBoot *pstBoot = (TBoot *)pBootInitial();
if(3 == argc && !strcmp(argv[1], "-c")) if(3 == argc && !strcmp(argv[1], "-c"))
{
if(bIsTvmBoot() && TVM_BOOT_SIMPLE != pstBoot->m_lBootType)
{
fprintf(stderr, "build failure, please stop STVM and do this !\n");
return RC_FAIL;
}
return lMakeConfig(argv[2]); return lMakeConfig(argv[2]);
}
else if(3 == argc && !strcmp(argv[1], "-o")) else if(3 == argc && !strcmp(argv[1], "-o"))
return lUnmakeConfig(argv[2]); return lUnmakeConfig(argv[2]);
@ -4892,7 +4879,7 @@ int main(int argc, char *argv[])
vCheckTvmEnv(); vCheckTvmEnv();
memset(szCom, 0, sizeof(szCom)); memset(szCom, 0, sizeof(szCom));
while(-1 != (iChoose = getopt(argc, argv, "w::s::p::f::d:m:t:i:u:l:c:v?::"))) while(-1 != (iChoose = getopt(argc, argv, "w::s::p::f::d:m:t:i:u::l:c:v?::")))
{ {
switch(iChoose) switch(iChoose)
{ {
@ -4933,9 +4920,12 @@ int main(int argc, char *argv[])
if(0x59 != lRet && 0x79 != lRet) if(0x59 != lRet && 0x79 != lRet)
return RC_SUCC; return RC_SUCC;
if(RC_SUCC != lResetLock(pstSavm, atol(optarg))) if(RC_SUCC != lResetLock(pstSavm, atol(optarg)))
fprintf(stderr, "重置表(%ld)失败, %s\n", atol(optarg), sGetTError(pstSavm->m_lErrno)); {
fprintf(stderr, "reset table (%ld) lock failure, %s\n", atol(optarg),
sGetTError(pstSavm->m_lErrno));
}
else else
fprintf(stderr, "重置表(%ld)完成, completed successfully !!\n", atol(optarg)); fprintf(stderr, "reset table (%ld) success, completed successfully !!\n", atol(optarg));
return RC_SUCC; return RC_SUCC;
case 'v': case 'v':
fprintf(stdout, "%s\n", sGetTVMVers()); fprintf(stdout, "%s\n", sGetTVMVers());
@ -4949,14 +4939,11 @@ int main(int argc, char *argv[])
if(1 == lAction) if(1 == lAction)
{ {
vTableStruck(atol(optarg)); vTableStruck(table);
return RC_SUCC;
}
else if(2 == lAction)
{
// vTableStruck(atol(optarg));
return RC_SUCC; return RC_SUCC;
} }
else if(3 == lAction)
return lUnuseDump(pstSavm, table);
vPrintFunc(basename(argv[0])); vPrintFunc(basename(argv[0]));
return RC_SUCC; return RC_SUCC;

View File

@ -1836,18 +1836,24 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi
pstCon->m_lRead = 0; pstCon->m_lRead = 0;
pstCon->m_bHead = false; pstCon->m_bHead = false;
pstRun = (RunTime *)pGetRunTime(pstSovm, pstFace->m_table);
pstRun->m_bAttch = pstSovm->stRunTime[pstFace->m_table].m_bAttch; pstRun = (RunTime *)pGetRunTime(pstSavm, pstFace->m_table);
pstRun->m_pvAddr = pstSovm->stRunTime[pstFace->m_table].m_pvAddr;
if(!pstRun->m_bAttch || !pstRun->m_pvAddr) if(!pstRun->m_bAttch || !pstRun->m_pvAddr)
{ {
//Tlog("initial table:%d, %d, %d", pstFace->m_table, pstFace->m_enum, pstRun->m_bAttch); //Tlog("initial table:%d, %d, %d", pstFace->m_table, pstFace->m_enum, pstRun->m_bAttch);
if(RC_SUCC != lInitSATvm(pstSovm, pstFace->m_table)) if(RC_SUCC != lInitSATvm(pstSavm, pstFace->m_table))
{ {
pstFace->m_lRows = 0; pstFace->m_lRows = 0;
pstFace->m_lErrno = pstSovm->m_lErrno; pstFace->m_lErrno = pstSovm->m_lErrno;
return lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); return lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace));
} }
memcpy(&pstSovm->stRunTime[pstFace->m_table], pstRun, sizeof(RunTime));
}
else
{
pstSovm->stRunTime[pstFace->m_table].m_bAttch = pstRun->m_bAttch;
pstSovm->stRunTime[pstFace->m_table].m_pvAddr = pstRun->m_pvAddr;
} }
if(PROTOCAL_JAVA & pstFace->m_enum) if(PROTOCAL_JAVA & pstFace->m_enum)
@ -1865,10 +1871,8 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi
pstSovm->lFind = pstFace->m_lFind; pstSovm->lFind = pstFace->m_lFind;
pstSovm->tblName = pstFace->m_table; pstSovm->tblName = pstFace->m_table;
pstSovm->lSize = pstFace->m_lDLen; pstSovm->lSize = pstFace->m_lDLen;
lRet = lProcaOperate(pstSovm, pstCon, pstFace, pvData); if(RC_SUCC == lProcaOperate(pstSovm, pstCon, pstFace, pvData))
pstSavm->stRunTime[pstFace->m_table].m_bAttch = pstRun->m_bAttch; return RC_SUCC;
pstSavm->stRunTime[pstFace->m_table].m_pvAddr = pstRun->m_pvAddr;
if(RC_SUCC == lRet) return RC_SUCC;
return lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); return lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace));
} }
@ -1885,10 +1889,8 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi
pstSovm->lFind = pstFace->m_lFind; pstSovm->lFind = pstFace->m_lFind;
pstSovm->tblName = pstFace->m_table; pstSovm->tblName = pstFace->m_table;
pstSovm->lSize = pstFace->m_lDLen; pstSovm->lSize = pstFace->m_lDLen;
lRet = lEventOperate(pstSovm, pstCon, pstFace, pvData); if(RC_SUCC == lEventOperate(pstSovm, pstCon, pstFace, pvData))
pstSavm->stRunTime[pstFace->m_table].m_bAttch = pstRun->m_bAttch; return RC_SUCC;
pstSavm->stRunTime[pstFace->m_table].m_pvAddr = pstRun->m_pvAddr;
if(RC_SUCC == lRet) return RC_SUCC;
return lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace)); return lSendBuffer(pstCon->m_skSock, (void *)pstFace, sizeof(TFace));
} }
@ -1906,23 +1908,21 @@ void* vEpollListen(void *pvParam)
SKCon *pstCon = NULL; SKCon *pstCon = NULL;
TFace *pstFace = NULL; TFace *pstFace = NULL;
epollevt events[MAX_EVENTS]; epollevt events[MAX_EVENTS];
BSock epfd = *((long *)pvParam); TThread *pstTrd = (TThread *)pvParam;
SATvm *pstSavm = (SATvm *)calloc(1, sizeof(SATvm)); SATvm *pstSavm = (SATvm *)pCloneSATvm();
pthread_detach(pthread_self()); pthread_detach(pthread_self());
vHoldConnect(pstSavm);
if(RC_SUCC != lTvmBuffer(pstSavm)) if(RC_SUCC != lTvmBuffer(pstSavm))
return NULL; return NULL;
while(g_eRun) while(g_eRun)
{ {
nWait = epoll_wait(epfd, events, MAX_EVENTS, 500); nWait = epoll_wait(pstTrd->m_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;
if(pstCon->m_isListen) if(pstCon->m_isListen)
lEpollAccept(pstSavm, epfd, pstCon); lEpollAccept(pstSavm, pstTrd->m_epfd, pstCon);
else if(events[i].events & EPOLLIN) else if(events[i].events & EPOLLIN)
{ {
if(false == pstCon->m_bHead) if(false == pstCon->m_bHead)
@ -1938,7 +1938,7 @@ void* vEpollListen(void *pvParam)
pstCon->m_bWork = false; pstCon->m_bWork = false;
} }
pstCon->m_pstWork = NULL; pstCon->m_pstWork = NULL;
epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); epoll_ctl(pstTrd->m_epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]);
TFree(pstCon->pstFace); TFree(pstCon->pstFace);
TFree(pstCon->pstVoid); TFree(pstCon->pstVoid);
close(pstCon->m_skSock); close(pstCon->m_skSock);
@ -1973,7 +1973,7 @@ void* vEpollListen(void *pvParam)
pstCon->m_bWork = false; pstCon->m_bWork = false;
} }
pstCon->m_pstWork = NULL; pstCon->m_pstWork = NULL;
epoll_ctl(epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]); epoll_ctl(pstTrd->m_epfd, EPOLL_CTL_DEL, pstCon->m_skSock, &events[i]);
TFree(pstCon->pstFace); TFree(pstCon->pstFace);
TFree(pstCon->pstVoid); TFree(pstCon->pstVoid);
close(pstCon->m_skSock); close(pstCon->m_skSock);
@ -1987,9 +1987,11 @@ LISTEN_ERROR:
continue; continue;
} }
close(epfd); close(pstTrd->m_epfd);
pstSavm->pstVoid = NULL; pstSavm->pstVoid = NULL;
vTvmDisconnect(pstSavm); vTvmDisconnect(pstSavm);
pstTrd->m_bRun = false;
pthread_exit(NULL);
return NULL; return NULL;
} }
@ -2152,7 +2154,7 @@ void vDomainEvent(SATvm *pstSavm, long lPort)
while(g_eRun) while(g_eRun)
{ {
for(sleep(1), list = pGetDomgrp(); list; list = list->pstNext) for(usleep(5000), list = pGetDomgrp(); list && g_eRun; list = list->pstNext)
{ {
if(NULL == (pstDom = (TDomain *)list->psvData)) if(NULL == (pstDom = (TDomain *)list->psvData))
continue; continue;
@ -2407,8 +2409,8 @@ long lBootLocal(SATvm *pstSavm, TBoot *pstBoot, Benum eMode)
pid_t lPid; pid_t lPid;
epollevt event; epollevt event;
BSock epfd = -1; BSock epfd = -1;
pthread_t *tPid = NULL;
SKCon *pstCon = NULL; SKCon *pstCon = NULL;
TThread *pstTrd = NULL;
if(!pstBoot || pstBoot->m_lBootExec < 1) // 线程数量 if(!pstBoot || pstBoot->m_lBootExec < 1) // 线程数量
{ {
@ -2462,11 +2464,18 @@ long lBootLocal(SATvm *pstSavm, TBoot *pstBoot, Benum eMode)
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
signal(SIGTRAP, SIG_IGN); signal(SIGTRAP, SIG_IGN);
tPid = malloc(sizeof(pthread_t) * pstBoot->m_lBootExec);
vHoldConnect(pstSavm); vHoldConnect(pstSavm);
if(NULL == (pstTrd = (TThread *)calloc(pstBoot->m_lBootExec, sizeof(TThread))))
{
fprintf(stderr, "create pthread tid failed, %s\n", strerror(errno));
return RC_FAIL;
}
for(i = 0; i < pstBoot->m_lBootExec; i ++) for(i = 0; i < pstBoot->m_lBootExec; i ++)
{ {
if(0 != pthread_create(&tPid[i], NULL, vEpollListen, (void*)&epfd)) pstTrd[i].m_epfd = epfd;
pstTrd[i].m_bRun = true;
if(0 != pthread_create(&pstTrd[i].m_tPid, NULL, vEpollListen, (void*)&pstTrd[i]))
{ {
fprintf(stderr, "create thread error, %s\n", strerror(errno)); fprintf(stderr, "create thread error, %s\n", strerror(errno));
exit(-1); exit(-1);
@ -2479,13 +2488,18 @@ long lBootLocal(SATvm *pstSavm, TBoot *pstBoot, Benum eMode)
vRemoteResouce(pstSavm, eMode, pstBoot->m_lBootPort); vRemoteResouce(pstSavm, eMode, pstBoot->m_lBootPort);
vTvmDisconnect(pstSavm); vTvmDisconnect(pstSavm);
for(i = 0; i < pstBoot->m_lBootExec; i ++) for(i = 0; i < pstBoot->m_lBootExec; i ++)
{ {
for(usleep(1000);ESRCH != pthread_kill(tPid[i], 0); usleep(1000)); usleep(500);
if(!pstTrd[i].m_bRun)
continue;
for(;(pstTrd[i].m_bRun) && (ESRCH != pthread_kill(pstTrd[i].m_tPid, 0)); usleep(1000));
} }
vCloseDomain(); vCloseDomain();
TFree(tPid); TFree(pstTrd);
Tlog("Service thread exits"); Tlog("Service thread exits");
exit(-1); exit(-1);
} }

View File

@ -1103,8 +1103,7 @@ char* sGetTableName(TABLE t)
*************************************************************************************************/ *************************************************************************************************/
char* sGetTablePart(TABLE t, char *pszNode) char* sGetTablePart(TABLE t, char *pszNode)
{ {
if(0x00 == g_stTblDef[t].m_szPart[0]) Tdefstr(g_stTblDef[t].m_szPart, pszNode, MAX_FIELD_LEN);
strncpy(g_stTblDef[t].m_szPart, pszNode, MAX_FIELD_LEN);
return g_stTblDef[t].m_szPart; return g_stTblDef[t].m_szPart;
} }

View File

@ -15,8 +15,8 @@ LOGNAME="/home/stvm/log/stvm.log"
TABLE=15 PERMIT=15 TABLE=15 PERMIT=15
*REMOTE_DOMAIN *REMOTE_DOMAIN
GROUP=1 DOMAINID="DBS" WSADDR="192.168.5.20:5010" TIMETOUT=2 MAXTRY=3 KEEPALIVE=30 GROUP=1 DOMAINID="DBS" WSADDR="192.168.5.20:5010" TIMEOUT=2 MAXTRY=3 KEEPALIVE=30
GROUP=2 DOMAINID="CTS" WSADDR="192.168.5.20:5011" TIMETOUT=2 MAXTRY=3 KEEPALIVE=30 GROUP=2 DOMAINID="CTS" WSADDR="192.168.5.20:5011" TIMEOUT=2 MAXTRY=3 KEEPALIVE=30
*REMOTE_TABLE *REMOTE_TABLE
TABLE=8 TABLENAME="TBL_BRH_INFO" TABLE=8 TABLENAME="TBL_BRH_INFO"