Merge branch '1.2.4'

pull/1/head
deffpuzzl 2018-06-21 23:24:26 +08:00
commit 7dffc83838
7 changed files with 215 additions and 27 deletions

View File

@ -39,11 +39,11 @@ typedef long (*FUNCEXEC)(SATvm *pstSavm, void *arg);
#define MAX_CON_EVENTS 65535 #define MAX_CON_EVENTS 65535
#define TVM_PORT_LISTEN 1801 #define TVM_PORT_LISTEN 1801
#define TVM_PORT_DOMAIN 1800 #define TVM_PORT_DOMAIN 1800
#define MAX_LOCK_TIME 600
#define TVM_LOCAL_SERV "LIS.tvm" #define TVM_LOCAL_SERV "LIS.tvm"
#define TVM_REMOTE_DOM "RDS.tvm" #define TVM_REMOTE_DOM "RDS.tvm"
#define LOCAL_HOST_IP "127.0.0.1" #define LOCAL_HOST_IP "127.0.0.1"
/************************************************************************************************* /*************************************************************************************************
& &
*************************************************************************************************/ *************************************************************************************************/
@ -77,6 +77,7 @@ typedef struct __TVM_INTERFACE
/************************************************************************************************* /*************************************************************************************************
macro macro
*************************************************************************************************/ *************************************************************************************************/
#define Tlog(...) vTraceLog(__FILE__, __LINE__, __VA_ARGS__)
/************************************************************************************************* /*************************************************************************************************
function function
@ -84,6 +85,7 @@ typedef struct __TVM_INTERFACE
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern void vTraceLog(const char *pszFile, int nLine, const char *fmt, ...);
extern void lInitTitle(int argc, char **argv, char **envp); extern void lInitTitle(int argc, char **argv, char **envp);
extern void vSetTitile(const char *name); extern void vSetTitile(const char *name);

106
src/func.c Normal file
View File

@ -0,0 +1,106 @@
/*
* Copyright (c) 2018 Savens Liu
*
* The original has been patented, Open source is not equal to open rights.
* Anyone can clone, download, learn and discuss for free. Without the permission
* of the copyright owner or author, it shall not be merged, published, licensed or sold.
* The copyright owner or author has the right to pursue his responsibility.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "tvm.h"
/************************************************************************************************
function
************************************************************************************************/
extern void vCondInsInit(FdCond *pstCond, TABLE t);
/*************************************************************************************************
descriptiondump the unused
parameters:
pstSavm --stvm handle
t --table
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lUnuseDump(SATvm *pstSavm, TABLE t)
{
FILE *fp = NULL;
char szFile[512];
RunTime *pstRun = NULL;
SHTruck *pstTruck = NULL;
size_t lRow = 0, lOffset, lDump = 0;
if(!pstSavm)
{
pstSavm->m_lErrno = CONDIT_IS_NIL;
return RC_FAIL;
}
memset(szFile, 0, sizeof(szFile));
if(RC_SUCC != lInitSATvm(pstSavm, t))
return RC_FAIL;
vHoldConnect(pstSavm);
if(NULL == (pstRun = (RunTime *)pInitHitTest(pstSavm, t)))
return RC_FAIL;
if(RES_REMOT_SID == pstRun->m_lLocal)
{
pstSavm->m_lErrno = RMT_NOT_SUPPT;
return RC_FAIL;
}
snprintf(szFile, sizeof(szFile), "%s/%d.udb", getenv("TVMDBD"), t);
if(NULL == (fp = fopen(szFile, "ab")))
{
pstSavm->m_lErrno = FILE_NOT_RSET;
return RC_FAIL;
}
lOffset = lGetTblData(t);
pstRun->m_lCurLine = 0;
pstSavm->lSize = lGetRowSize(t);
pstTruck = (PSHTruck)pGetNode(pstRun->m_pvAddr, lOffset);
for(lRow = 0; (lRow < ((TblDef *)pstRun->m_pvAddr)->m_lValid) && (lOffset < lGetTableSize(t));
pstTruck = (PSHTruck)pGetNode(pstRun->m_pvAddr, lOffset))
{
if(IS_TRUCK_NULL(pstTruck) || pstTruck->m_lTimes == 0)
{
lOffset += lGetRowTruck(t);
continue;
}
fwrite(pstTruck->m_pvData, lGetRowSize(t), 1, fp);
pstSavm->pstVoid = pstTruck->m_pvData;
vCondInsInit(&pstSavm->stCond, t);
lDelete(pstSavm);
lDump ++;
lOffset += lGetRowTruck(t);
}
fclose(fp);
vForceDisconnect(pstSavm, t);
pstSavm->m_lEffect = lDump;
fprintf(stdout, "export table:%s valid:%ld, completed successfully !!\n", sGetTableName(t),
pstSavm->m_lEffect);
return RC_SUCC;
}
/****************************************************************************************
code end
****************************************************************************************/

View File

@ -28,6 +28,47 @@ extern long _lPushByRt(SATvm *pstSavm);
extern long _lPopByRt(SATvm *pstSavm, void *psvOut); extern long _lPopByRt(SATvm *pstSavm, void *psvOut);
extern long _lPopupByRt(SATvm *pstSavm, size_t lExp, time_t lTime, size_t *plOut, void **pp); extern long _lPopupByRt(SATvm *pstSavm, size_t lExp, time_t lTime, size_t *plOut, void **pp);
/*************************************************************************************************
descriptionDelete the queue that matches conditions
parameters:
pstSavm --stvm handle
pvAddr --memory address
t --table
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long _lDeleteQueue(SATvm *pstSavm, void *pvAddr)
{
SHTruck *pstTruck = NULL;
TblDef *pv = (TblDef *)pvAddr;
size_t lRow, lOffset = pv->m_lListOfs;
for(pstSavm->m_lEffect = 0, lRow = 0; lRow < pv->m_lMaxRow; lOffset ++, lRow ++)
{
if(0 >= pv->m_lValid)
break;
pstTruck = (PSHTruck)pGetNode(pvAddr, pv->m_lData + pv->m_lTruck * (lOffset % pv->m_lMaxRow));
if(IS_TRUCK_NULL(pstTruck))
continue;
if(RC_MISMA == lFeildMatch(&pstSavm->stCond, pstTruck->m_pvData, pstSavm->pstVoid))
continue;
pstSavm->m_lEffect ++;
if(0 > (int)__sync_sub_and_fetch(&pv->m_lValid, 1))
{
__sync_fetch_and_add(&pv->m_lValid, 1);
break;
}
SET_DATA_TRUCK(pstTruck, DATA_TRUCK_NULL);
}
return RC_SUCC;
}
/************************************************************************************************* /*************************************************************************************************
descriptionpush data to queue descriptionpush data to queue
parameters: parameters:
@ -295,6 +336,50 @@ retrys:
return RC_SUCC; return RC_SUCC;
} }
/*************************************************************************************************
descriptionpop data from queue
parameters:
pstSavm --stvm handle
psvOut --out data
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lTimePop(SATvm *pstSavm, void *pvOut, Uenum eWait)
{
long lRet;
Timesp tm = {0, 1};
RunTime *pstRun = NULL;
if(!pstSavm)
{
pstSavm->m_lErrno = CONDIT_IS_NIL;
return RC_FAIL;
}
if(NULL == (pstRun = (RunTime *)pInitMemTable(pstSavm, pstSavm->tblName)))
return RC_FAIL;
if(TYPE_MQUEUE != pstRun->m_lType)
{
pstSavm->m_lErrno = NOT_SUPPT_OPT;
vTblDisconnect(pstSavm, pstSavm->tblName);
return RC_FAIL;
}
if(RES_REMOT_SID == pstRun->m_lLocal)
{
Tremohold(pstSavm, pstRun);
return _lPopByRt(pstSavm, pvOut);
}
if(QUE_NORMAL == eWait) tm.tv_sec = MAX_LOCK_TIME;
lRet = _lPop(pstSavm, pstRun->m_pvAddr, pvOut, &tm);
vTblDisconnect(pstSavm, pstSavm->tblName);
return lRet;
}
/************************************************************************************************* /*************************************************************************************************
descriptionpop data from queue descriptionpop data from queue
parameters: parameters:

View File

@ -1091,7 +1091,7 @@ long lCreateByFile(char *pszFile)
return RC_FAIL; return RC_FAIL;
} }
if(NULL == (pszCreate = (char *)calloc(stBuf.st_size, 1))) if(NULL == (pszCreate = (char *)calloc(stBuf.st_size + 1, 1)))
{ {
fprintf(stderr, "create memory error, %s\n", strerror(errno)); fprintf(stderr, "create memory error, %s\n", strerror(errno));
return RC_FAIL; return RC_FAIL;
@ -4387,7 +4387,8 @@ void vInitialCustom()
//select nextval from SEQUENCE@SEQ_TEST //select nextval from SEQUENCE@SEQ_TEST
snprintf(g_stCustom.m_pszWord, ALLOC_CMD_LEN, "SET,FROM,WHERE,COUNT(1),MAX,MIN,NEXTVAL," snprintf(g_stCustom.m_pszWord, ALLOC_CMD_LEN, "SET,FROM,WHERE,COUNT(1),MAX,MIN,NEXTVAL,"
"ORDER BY,GROUP BY,SEQUENCE@,SYS_TVM_FIELD,SYS_TVM_DOMAIN,SYS_TVM_SEQUE,TABLE,INTO," "ORDER BY,GROUP BY,SEQUENCE@,SYS_TVM_FIELD,SYS_TVM_DOMAIN,SYS_TVM_SEQUE,TABLE,INTO,"
"ON,INFO,INDEX,VALUES,DEBUG [ON|OFF],SHOWMODE [ROW|COLUMN],SHOWSIZE [NUM],CLICK,TO,"); "ON,INFO,INDEX,VALUES,DEBUG [ON|OFF],SHOWMODE [ROW|COLUMN],SHOWSIZE [NUM],CLICK,TO,"
"DELIMITER,");
g_stCustom.m_lWord = lgetstrnum(g_stCustom.m_pszWord, ","); g_stCustom.m_lWord = lgetstrnum(g_stCustom.m_pszWord, ",");
rl_attempted_completion_function = pMatchCompletion; rl_attempted_completion_function = pMatchCompletion;

View File

@ -33,14 +33,13 @@ Rowgrp *g_pstDomgrp = NULL, *g_pstTblgrp = NULL;
extern char* pGetLog(); extern char* pGetLog();
extern long lGetBootType(); extern long lGetBootType();
extern void vSetBootType(long lType); extern void vSetBootType(long lType);
extern long lTimePop(SATvm *pstSavm, void *pvOut, Uenum eWait);
void* pParsePacket(SATvm *pstSavm, void *pstVoid, TFace *pstFace, void *pvBuffer, long lLen); void* pParsePacket(SATvm *pstSavm, void *pstVoid, TFace *pstFace, void *pvBuffer, long lLen);
void* pProtocaJava(SATvm *pstSavm, void *pstVoid, TFace *pstFace, void *pvBuffer, long lLen); void* pProtocaJava(SATvm *pstSavm, void *pstVoid, TFace *pstFace, void *pvBuffer, long lLen);
/************************************************************************************************* /*************************************************************************************************
macro macro
*************************************************************************************************/ *************************************************************************************************/
#define Tlog(...) vTraceLog(__FILE__, __LINE__, __VA_ARGS__)
#define checkrequest(s,c,f) if(MAX(f->m_lRows, f->m_lDLen) > c->m_lBuffer) \ #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) \
@ -1448,7 +1447,7 @@ long lEventOperate(SATvm *pstSavm, SKCon *pstCon, TFace *pstFace, char *pvDat
TFree(pvOut); TFree(pvOut);
return RC_SUCC; return RC_SUCC;
case OPERATE_QUEPOP: case OPERATE_QUEPOP:
if(RC_SUCC != lPop(pstSavm, (void *)pvData, pstFace->m_lFind)) if(RC_SUCC != lTimePop(pstSavm, (void *)pvData, pstFace->m_lFind))
{ {
pstFace->m_lErrno = pstSavm->m_lErrno; pstFace->m_lErrno = pstSavm->m_lErrno;
lData = sizeof(TFace); lData = sizeof(TFace);
@ -1852,6 +1851,7 @@ long lPollRequest(SATvm *pstSovm, SKCon *pstCon, TFace *pstFace, void *pstVoi
} }
else else
{ {
pstSovm->stRunTime[pstFace->m_table].m_lType = pstRun->m_lType;
pstSovm->stRunTime[pstFace->m_table].m_bAttch = pstRun->m_bAttch; pstSovm->stRunTime[pstFace->m_table].m_bAttch = pstRun->m_bAttch;
pstSovm->stRunTime[pstFace->m_table].m_pvAddr = pstRun->m_pvAddr; pstSovm->stRunTime[pstFace->m_table].m_pvAddr = pstRun->m_pvAddr;
} }

View File

@ -43,6 +43,7 @@ extern long _lQueryByRt(SATvm *pstSavm, size_t *plOut, void **ppsvOut);
extern long _lExtremeByRt(SATvm *pstSavm, void *psvOut); extern long _lExtremeByRt(SATvm *pstSavm, void *psvOut);
extern void _vDropTableByRt(SATvm *pstSavm, TABLE t); extern void _vDropTableByRt(SATvm *pstSavm, TABLE t);
extern long _lRenameTableByRt(SATvm *pstSavm, TABLE to, TABLE tn); extern long _lRenameTableByRt(SATvm *pstSavm, TABLE to, TABLE tn);
extern long _lDeleteQueue(SATvm *pstSavm, void *pvAddr);
/************************************************************************************************* /*************************************************************************************************
macro macro
@ -4311,16 +4312,20 @@ long _lDeleteGroup(SATvm *pstSavm, void *pvAddr, TABLE t)
RC_SUCC --success RC_SUCC --success
RC_FAIL --failure RC_FAIL --failure
*************************************************************************************************/ *************************************************************************************************/
long _lDeleteTruck(SATvm *pstSavm, void *pvAddr, TABLE t) long _lDeleteTruck(SATvm *pstSavm, RunTime *pstRun, TABLE t)
{ {
bool bIsIdx = false; bool bIsIdx = false;
SHTree *pstRoot = NULL; SHTree *pstRoot = NULL;
SHTruck *pstTruck = NULL; SHTruck *pstTruck = NULL;
char szIdx[MAX_INDEX_LEN]; char szIdx[MAX_INDEX_LEN];
void *pvAddr = pstRun->m_pvAddr;
RWLock *prwLock = (RWLock *)pGetRWLock(pvAddr); RWLock *prwLock = (RWLock *)pGetRWLock(pvAddr);
size_t lData = 0, lOffset = lGetTblData(t), lIdx; size_t lData = 0, lOffset = lGetTblData(t), lIdx;
long lRow, lValid = ((TblDef *)pvAddr)->m_lValid; long lRow, lValid = ((TblDef *)pvAddr)->m_lValid;
if(TYPE_MQUEUE == pstRun->m_lType)
return _lDeleteQueue(pstSavm, pvAddr);
if(HAVE_INDEX(t)) bIsIdx = true; if(HAVE_INDEX(t)) bIsIdx = true;
if(RC_SUCC != pthread_rwlock_wrlock(prwLock)) if(RC_SUCC != pthread_rwlock_wrlock(prwLock))
@ -4476,13 +4481,6 @@ long lDelete(SATvm *pstSavm)
if(NULL == (pstRun = (RunTime *)pInitMemTable(pstSavm, pstSavm->tblName))) if(NULL == (pstRun = (RunTime *)pInitMemTable(pstSavm, pstSavm->tblName)))
return RC_FAIL; return RC_FAIL;
if(TYPE_MQUEUE == pstRun->m_lType)
{
pstSavm->m_lErrno = NOT_SUPPT_OPT;
vTblDisconnect(pstSavm, pstSavm->tblName);
return RC_FAIL;
}
if(RES_REMOT_SID == pstRun->m_lLocal) if(RES_REMOT_SID == pstRun->m_lLocal)
{ {
Tremohold(pstSavm, pstRun); Tremohold(pstSavm, pstRun);
@ -4498,7 +4496,7 @@ long lDelete(SATvm *pstSavm)
if(!pstSavm->pstVoid) if(!pstSavm->pstVoid)
{ {
lRet = _lDeleteTruck(pstSavm, pstRun->m_pvAddr, pstSavm->tblName); lRet = _lDeleteTruck(pstSavm, pstRun, pstSavm->tblName);
vTblDisconnect(pstSavm, pstSavm->tblName); vTblDisconnect(pstSavm, pstSavm->tblName);
return lRet; return lRet;
} }
@ -4532,7 +4530,7 @@ long lDelete(SATvm *pstSavm)
} }
} }
lRet = _lDeleteTruck(pstSavm, pstRun->m_pvAddr, pstSavm->tblName); lRet = _lDeleteTruck(pstSavm, pstRun, pstSavm->tblName);
vTblDisconnect(pstSavm, pstSavm->tblName); vTblDisconnect(pstSavm, pstSavm->tblName);
return lRet; return lRet;
} }
@ -9237,7 +9235,12 @@ long lImportFile(TABLE t, char *pszFile, char *pszFlag)
memset(pvData, 0, lGetRowSize(t)); memset(pvData, 0, lGetRowSize(t));
if(TYPE_MQUEUE == pstRun->m_lType) if(TYPE_MQUEUE == pstRun->m_lType)
memcpy(pvData, szLine, lGetRowSize(t)); {
if(lGetFldNum(t) > 0)
_lImportContext(szLine, lGetFldNum(t), pGetTblKey(t), pvData, pszFlag);
else
memcpy(pvData, szLine, lGetRowSize(t));
}
else else
_lImportContext(szLine, lGetFldNum(t), pGetTblKey(t), pvData, pszFlag); _lImportContext(szLine, lGetFldNum(t), pGetTblKey(t), pvData, pszFlag);
if(RC_SUCC != __lInsert(pstSavm, pstRun, pstSavm->tblName, 0)) if(RC_SUCC != __lInsert(pstSavm, pstRun, pstSavm->tblName, 0))

View File

@ -4,7 +4,7 @@ MAXTABLE=255
MAXFILED=3000 MAXFILED=3000
MAXDOMAIN=1024 MAXDOMAIN=1024
MAXSEQUE=1024 MAXSEQUE=1024
SERVER_EXEC=4 SERVER_EXEC=2
#SERVER_EXEC=1 #SERVER_EXEC=1
DEPLOY=cluster DEPLOY=cluster
#DEPLOY=local #DEPLOY=local
@ -12,16 +12,7 @@ SERVER_PORT=5050
LOGNAME="/home/stvm/log/stvm.log" LOGNAME="/home/stvm/log/stvm.log"
*LOCAL_RESOURCE *LOCAL_RESOURCE
TABLE=15 PERMIT=15
*REMOTE_DOMAIN *REMOTE_DOMAIN
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" TIMEOUT=2 MAXTRY=3 KEEPALIVE=30
*REMOTE_TABLE *REMOTE_TABLE
TABLE=8 TABLENAME="TBL_BRH_INFO"
MTABLE=17 DOMAINID="DBS"
MTABLE=17 DOMAINID="CTS"
TABLE=9 TABLENAME="TBL_ACCT_INFO"
MTABLE=16 DOMAINID="DBS"
MTABLE=16 DOMAINID="CTS"