stvm 1.2.2

1.2.3
DeffPuzzL 2018-03-12 15:01:29 +08:00
commit 45dedd3594
41 changed files with 24128 additions and 0 deletions

58
README Normal file
View File

@ -0,0 +1,58 @@
/*************************************************************************************************
STVM 高效缓存数据库
*************************************************************************************************/
启动环境变量
TVMDBD=/home/stvm/tvmdb 指向stvm工作目录
TVMCFG=/home/stvm/tvmdb/.tvm.run 启动参数
编译项目
cd stvm-1.2/src目录
./make
在../lib下生成
libstvm.a
libstvm.so
libstvm.so.1.2 -> ../lib/libstvm.so
在../bin下生成
stvm
detvm
使用方法:
如果不使用多机集群,无需配置域文件,直接 stvm -w 缺省启动单机模式。
stvm -s 停止系统
STVM也提供一个类型sqlpuls类型简单工具 输入:
stvm SQL 进入SQL界面该工具主要用来运维调试使用。
stvm DOM 进入域的维护
关于域的配置,请参见:
stvm.conf
配置域完成后可以stvm -c stvm.conf编译到$TVMCFG下
然后在stvm -w启动即可
目前本版本为测试版本不保证无bug建议以单机模式64位下运行将性能发挥在极致。
作者:Savens Liu
邮箱:deffpuzzl@qq.com
====更新日期:20180312====
1、支持动态创建表语句
2、新增对表结构导出功能
用法:
表创建语法示例: tbl_acct_base.def
在stvm SQL中利用 create $file来创建表
提交人:Savens Liu
下本版本:
1、新增多机资源共享方式。
2、JAVA接口开发
不定时更新

BIN
demo/count Executable file

Binary file not shown.

51
demo/count.c Normal file
View File

@ -0,0 +1,51 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lCountUserInfo()
{
dbUser stUser;
size_t lRow = 0;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
stringset(pstSavm, stUser, user_type, "1"); // 查询条件赋值
stringset(pstSavm, stUser, user_no, "20180224"); // 查询条件赋值
if(RC_SUCC != lCount(pstSavm, (void *)&lRow))
{
fprintf(stderr, "Count error: (%d) (%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
fprintf(stdout, "Count:%ld\n\n", lRow);
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lCountUserInfo())
return RC_FAIL;
return RC_SUCC;
}

BIN
demo/create Executable file

Binary file not shown.

52
demo/create.c Normal file
View File

@ -0,0 +1,52 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
CREATE lCreateUserInfo()
{
DEFINE(TBL_USER_INFO, "TBL_USER_INFO", "", dbUser)
FIELD(dbUser, acct_id, "acct_id", FIELD_LONG)
FIELD(dbUser, user_no, "user_no", FIELD_CHAR)
FIELD(dbUser, user_type, "user_type", FIELD_CHAR)
FIELD(dbUser, user_nm, "user_nm", FIELD_CHAR)
FIELD(dbUser, user_addr, "user_addr", FIELD_CHAR)
FIELD(dbUser, user_phone, "user_phone", FIELD_CHAR)
CREATE_IDX(NORMAL) // 创建查询索引
IDX_FIELD(dbUser, acct_id, FIELD_LONG)
CREATE_IDX(UNQIUE) // 创建唯一索引
IDX_FIELD(dbUser, user_no, FIELD_CHAR)
IDX_FIELD(dbUser, user_type, FIELD_CHAR)
FINISH
}
int main(int argc, char *argv[])
{
SATvm *pstSavm = (SATvm *)pGetSATvm();
if(RC_SUCC != lCreateTable(pstSavm, TBL_USER_INFO, 1000, lCreateUserInfo))
{
fprintf(stderr, "create table %d failed, err: %s\n", TBL_USER_INFO, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
fprintf(stdout, "初始化表成功, completed successfully!!!\n");
fflush(stderr);
return RC_SUCC;
}

BIN
demo/delete Executable file

Binary file not shown.

50
demo/delete.c Normal file
View File

@ -0,0 +1,50 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lDeleteUserInfo()
{
dbUser stUser;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
stringset(pstSavm, stUser, user_type, "1"); // 查询条件赋值
stringset(pstSavm, stUser, user_no, "20180223"); // 查询条件赋值
if(RC_SUCC != lDelete(pstSavm))
{
fprintf(stderr, "Delete error: (%d) (%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lDeleteUserInfo())
return RC_FAIL;
return RC_SUCC;
}

BIN
demo/drop Executable file

Binary file not shown.

46
demo/drop.c Normal file
View File

@ -0,0 +1,46 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lDropUserInfo()
{
dbUser stUser;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
if(RC_SUCC != lDropTable(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "drop table error:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lDropUserInfo())
return RC_FAIL;
return RC_SUCC;
}

BIN
demo/extreme Executable file

Binary file not shown.

52
demo/extreme.c Normal file
View File

@ -0,0 +1,52 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lExtremeUserInfo()
{
dbUser stUser;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
stringset(pstSavm, stUser, user_type, "1"); // 查询条件赋值
decorate(pstSavm, dbUser, user_nm, MATCH_MIN);
decorate(pstSavm, dbUser, user_phone, MATCH_MAX);
if(RC_SUCC != lExtreme(pstSavm, (void *)&stUser))
{
fprintf(stderr, "Extreme error: (%d) (%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
fprintf(stdout, "user_nm:%s, user_phone:%s\n", stUser.user_nm, stUser.user_phone);
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lExtremeUserInfo())
return RC_FAIL;
return RC_SUCC;
}

BIN
demo/group Executable file

Binary file not shown.

56
demo/group.c Normal file
View File

@ -0,0 +1,56 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lGroupUserInfo()
{
size_t i, lRow = 0;
dbUser stUser, *pstUser = NULL;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
stringset(pstSavm, stUser, user_type, "1"); // 查询条件赋值
decorate(pstSavm, dbUser, user_nm, GROUP_BY | ORDER_ASC);
decorate(pstSavm, dbUser, user_phone, GROUP_BY | ORDER_DESC);
if(RC_SUCC != lGroup(pstSavm, &lRow, (void **)&pstUser))
{
fprintf(stderr, "Group error: (%d) (%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
for(i = 0; i < lRow; i ++)
fprintf(stdout, "user_nm:%s, user_phone:%s\n", pstUser[i].user_nm, pstUser[i].user_phone);
TFree(pstUser);
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lGroupUserInfo())
return RC_FAIL;
return RC_SUCC;
}

BIN
demo/insert Executable file

Binary file not shown.

58
demo/insert.c Normal file
View File

@ -0,0 +1,58 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lInsertUserInfo()
{
dbUser stUser;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
memset(&stUser, 0, sizeof(dbUser));
stUser.acct_id = 10021; // 对结构体赋值
strcpy(stUser.user_no, "20180223"); // 对结构体赋值
strcpy(stUser.user_type, "1"); // 对结构体赋值
strcpy(stUser.user_nm, "Savens Liu"); // 对结构体赋值
strcpy(stUser.user_addr, "China"); // 对结构体赋值
strcpy(stUser.user_phone, "18672911111"); // 对结构体赋值
insertinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
if(RC_SUCC != lInsert(pstSavm)) // 插入记录
{
fprintf(stderr, "Insert error:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lInsertUserInfo())
return RC_FAIL;
fprintf(stdout, "新增记录成功, completed successfully!!!\n");
fflush(stderr);
return RC_SUCC;
}

57
demo/makefile Executable file
View File

@ -0,0 +1,57 @@
INCDIR= -I/usr/include -I$(HOME)/include -I./ -I./include -I../include
LIBDIR= -L$(HOME)/lib -L../lib -lstvm -lm -lc -ldl -lpthread
CC=cc -fPIC
CO=-c -g
OUTLIB=../lib
OUTBIN=../bin
OBJFILE=tree.o sem.o msg.o tcp.o str.o list.o conf.o
CREATE=create
INSERT=insert
SELECT=select
QUERY=query
DELETE=delete
UPDATE=update
COUNT=count
GROUP=group
EXTREME=extreme
TRUNCATE=truncate
DROP=drop
PRESSURE=press_demo
all: $(CREATE) $(INSERT) $(SELECT) $(QUERY) $(DELETE) $(UPDATE) $(COUNT) $(GROUP) $(EXTREME) $(TRUNCATE) $(DROP) $(PRESSURE) clean
$(CREATE): create.o
$(CC) -o $@ $< $(LIBDIR)
$(INSERT): insert.o
$(CC) -o $@ $< $(LIBDIR)
$(SELECT): select.o
$(CC) -o $@ $< $(LIBDIR)
$(QUERY): query.o
$(CC) -o $@ $< $(LIBDIR)
$(DELETE): delete.o
$(CC) -o $@ $< $(LIBDIR)
$(UPDATE): update.o
$(CC) -o $@ $< $(LIBDIR)
$(COUNT): count.o
$(CC) -o $@ $< $(LIBDIR)
$(GROUP): group.o
$(CC) -o $@ $< $(LIBDIR)
$(EXTREME): extreme.o
$(CC) -o $@ $< $(LIBDIR)
$(TRUNCATE): truncate.o
$(CC) -o $@ $< $(LIBDIR)
$(DROP): drop.o
$(CC) -o $@ $< $(LIBDIR)
$(PRESSURE): press_demo.o
$(CC) -o $@ $< $(LIBDIR)
.SUFFIXES: .c .o
.c.o:
$(CC) $(CO) $*.c $(INCDIR) $(LIBDIR)
fall:
@touch *c
@make all
clean:
rm -f *.o

BIN
demo/press_demo Executable file

Binary file not shown.

59
demo/press_demo.c Normal file
View File

@ -0,0 +1,59 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lSelectUserInfo()
{
dbUser stUser;
int i = 0;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
vHoldConnect(pstSavm); // 让进程始终与STVM 保持链接,可以大大提高效率
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
stringset(pstSavm, stUser, user_type, "1"); // 查询条件赋值
stringset(pstSavm, stUser, user_no, "20180223"); // 查询条件赋值
for(i = 0; i < 2000000; i ++)
{
if(RC_SUCC != lSelect(pstSavm, (void *)&stUser))
{
fprintf(stderr, "Select error: (%d) (%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
}
fprintf(stdout, "acct_id:%ld, user_no:%s, user_type:%s, user_nm:%s, user_addr:%s, user_phone:%s\n",
stUser.acct_id, stUser.user_no, stUser.user_type, stUser.user_nm, stUser.user_addr, stUser.user_phone);
vHoldRelease(pstSavm); // 在进程退出时,断开链接
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lSelectUserInfo())
return RC_FAIL;
return RC_SUCC;
}

BIN
demo/query Executable file

Binary file not shown.

59
demo/query.c Normal file
View File

@ -0,0 +1,59 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lQueryUserInfo()
{
size_t i, lRow = 0;
dbUser stUser, *pstUser = NULL;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
stringset(pstSavm, stUser, user_type, "1"); // 查询条件赋值
stringset(pstSavm, stUser, user_no, "20180223"); // 查询条件赋值
if(RC_SUCC != lQuery(pstSavm, &lRow, (void **)&pstUser))
{
fprintf(stderr, "Query error:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
for(i = 0; i < lRow; i ++)
{
fprintf(stdout, "acct_id:%ld, user_no:%s, user_type:%s, user_nm:%s, user_addr:%s, user_phone:%s\n",
pstUser[i].acct_id, pstUser[i].user_no, pstUser[i].user_type, pstUser[i].user_nm, pstUser[i].user_addr,
pstUser[i].user_phone);
}
TFree(pstUser);
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lQueryUserInfo())
return RC_FAIL;
return RC_SUCC;
}

BIN
demo/select Executable file

Binary file not shown.

53
demo/select.c Normal file
View File

@ -0,0 +1,53 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lSelectUserInfo()
{
dbUser stUser;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
stringset(pstSavm, stUser, user_type, "1"); // 查询条件赋值
stringset(pstSavm, stUser, user_no, "20180223"); // 查询条件赋值
if(RC_SUCC != lSelect(pstSavm, (void *)&stUser))
{
fprintf(stderr, "Select error: (%d) (%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
fprintf(stdout, "acct_id:%ld, user_no:%s, user_type:%s, user_nm:%s, user_addr:%s, user_phone:%s\n",
stUser.acct_id, stUser.user_no, stUser.user_type, stUser.user_nm, stUser.user_addr, stUser.user_phone);
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lSelectUserInfo())
return RC_FAIL;
return RC_SUCC;
}

BIN
demo/truncate Executable file

Binary file not shown.

47
demo/truncate.c Normal file
View File

@ -0,0 +1,47 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lTruncateUserInfo()
{
dbUser stUser;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
if(RC_SUCC != lTruncate(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "Truncate error: (%d)(%s)\n", pstSavm->m_lEType, pstSavm->m_lErrno,
sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lTruncateUserInfo())
return RC_FAIL;
return RC_SUCC;
}

BIN
demo/update Executable file

Binary file not shown.

52
demo/update.c Normal file
View File

@ -0,0 +1,52 @@
#include "tvm.h"
#include "tmain.h"
#define TBL_USER_INFO 20
typedef struct __TBL_USER_INFO
{
long acct_id;
char user_no[21];
char user_type[2];
char user_nm[81];
char user_addr[161];
char user_phone[31];
}dbUser;
long lUpdateUserInfo()
{
dbUser stUser, stUpd;
SATvm *pstSavm = (SATvm *)pGetSATvm();
/* 初始化TBL_USER_INFO表每张表都需要初始化一次, 对于表重建后,需要重新初始化一次。*/
if(RC_SUCC != lInitSATvm(pstSavm, TBL_USER_INFO))
{
fprintf(stderr, "init failed, err:(%d)(%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
updateinit(stUpd);
conditinit(pstSavm, stUser, TBL_USER_INFO); // 绑定变量
stringset(pstSavm, stUser, user_type, "1"); // 查询条件赋值
stringset(pstSavm, stUser, user_no, "20180224"); // 查询条件赋值
stringupd(pstSavm, stUpd, user_phone, "1869112XXXX");
if(RC_SUCC != lUpdate(pstSavm, (void *)&stUpd))
{
fprintf(stderr, "Update error: (%d) (%s)\n", pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return RC_FAIL;
}
return RC_SUCC;
}
int main(int argc, char *argv[])
{
if(RC_SUCC != lUpdateUserInfo())
return RC_FAIL;
return RC_SUCC;
}

135
include/tmain.h Normal file
View File

@ -0,0 +1,135 @@
/*
* 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.
*/
#ifndef _HHH_TVM_DOMAIN_HHH__
#define _HHH_TVM_DOMAIN_HHH__
#include "tvm.h"
typedef struct epoll_event epollevt;
typedef long (*FUNCEXEC)(SATvm *pstSavm, void *arg);
/*************************************************************************************************
*************************************************************************************************/
#define SET_BLOCK 0
#define SET_UNBLOCK 1
#define READ_BUFFER 4096
#define MAX_EVENTS 5000
#define READ_MAX_LEN 1024 * 10
#define DATA_MAX_LEN 1048576 // 1024*1024 Maximum self-protection single record 1M
#define MAX_CON_EVENTS 65535
#define TVM_PORT_LISTEN 1801
#define TVM_PORT_DOMAIN 1800
#define TVM_LOCAL_SERV "LIS.tvm"
#define TVM_REMOTE_DOM "RDS.tvm"
#define LOCAL_HOST_IP "127.0.0.1"
/*************************************************************************************************
&
*************************************************************************************************/
typedef struct __SOCK_CONNECT
{
char m_szCltIp[16];
int m_lCltPort;
BSock m_skSock;
int m_isListen;
BOOL m_bWork;
ulong m_uWorker;
CMList *m_pstWork;
}SKCon;
typedef struct __TVM_INTERFACE
{
Benum m_enum;
Uenum m_lFind;
TABLE m_table;
uint m_lDLen;
uint m_lErrno;
size_t m_lRows;
}TFace;
/*************************************************************************************************
macro
*************************************************************************************************/
/*************************************************************************************************
function
*************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
extern void lInitTitle(int argc, char **argv, char **envp);
extern void vSetTitile(const char *name);
extern void vDeleteRowgrp(Rowgrp *pstNode);
extern Rowgrp* pFindRowList(Rowgrp *root, long idx);
extern void vSortRowgrp(Rowgrp **pproot, TblKey *pstKey, Benum em);
extern long lCountRowgrp(Rowgrp *pstRoot, void *psvData, long lLen, size_t lCount);
extern long lSortRowList(SATvm *, size_t lRow, void *pvData, size_t lTruck);
extern long lConvRowList(SATvm *pstSavm, Rowgrp *root, size_t *plOut, void **ppsvOut);
extern long lParsRowList(SATvm *pstSavm, void *pszBuffer, long lData, Rowgrp **root);
extern Rowgrp* pInsertRowgrp(SATvm *, Rowgrp *, Rowgrp *, Rowgrp *, void *, long , size_t );
extern bool bRepeatLstgrp(FdCond *pstRrp, void *pvData, TABLE t, size_t lOut, void *psvOut);
extern long lInsertLstgrp(SATvm *, FdCond *, void *, TABLE , size_t *, void **ppsvOut);
extern bool bExistProcess(long lPid);
extern void vInitTitle(int argc, char **argv, char **envp);
extern long lBootLocal(SATvm *pstSavm, TBoot *pstBoot, Benum eMode);
extern long lBootDomain(SATvm *pstSavm, TBoot *pstBoot, long lMode);
extern long lMultListen(SATvm *pstSavm, long lPort, long , FUNCEXEC , void *arg, FUNCEXEC );
extern long lOfflineNotify(SATvm *pstSavm, long lPort);
extern long lRefreshNotify(SATvm *pstSavm, long lPort);
extern long lPullNotify(SATvm *pstSavm, TDomain *pstDom, size_t lCount);
extern long lConnectNotify(SATvm *pstSavm, TDomain *pstDom, long lPort);
extern long lTvmGetTblIndex(SATvm *pstSavm, char *pszTable, char *pszPart, TIndex *pstIndex);
extern long lTvmGetTblField(SATvm *pstSavm, TABLE t, size_t *plOut, TField **ppstField);
extern long lTvmBeginWork(SATvm *pstSavm);
extern long lTvmRollbackWork(SATvm *pstSavm);
extern long lTvmCommitWork(SATvm *pstSavm);
extern long lTvmEndWork(SATvm *pstSavm);
extern void vTvmDisconnect(SATvm *pstSavm);
extern long lTvmConnect(SATvm *pstSavm, char *pszIp, long lPort, int times);
extern long lTvmTruncate(SATvm *pstSavm, TABLE t);
extern long lTvmGroup(SATvm *pstSavm, size_t *plOut, void **ppvOut);
extern long lTvmCount(SATvm *pstSavm, size_t *plCount);
extern long lTvmInsert(SATvm *pstSavm);
extern long lTvmSelect(SATvm *pstSavm, void *pvOut);
extern long lTvmQuery(SATvm *pstSavm, size_t *plOut, void **ppvOut);
extern long lTvmUpdate(SATvm *pstSavm, void *pvData);
extern long lTvmDelete(SATvm *pstSavm);
extern long lTvmExtreme(SATvm *pstSavm, void *pvOut);
extern long lTvmDropTable(SATvm *pstSavm, TABLE t);
extern long lTvmRenameTable(SATvm *pstSavm, TABLE to, TABLE tn);
extern long lTvmSelectSeque(SATvm *pstSavm, char *pszSQName, ulong *pulNumber);
extern long lTvmSetSequence(SATvm *pstSavm, char *pszSQName, ulong uStart);
extern long lTvmRebuildIndex(SATvm *pstSavm, TABLE t);
extern long lTvmResetLock(SATvm *pstSavm, TABLE t);
#ifdef __cplusplus
}
#endif
#endif // _HHH_TVM_DOMAIN_HHH__

174
include/tstr.h Normal file
View File

@ -0,0 +1,174 @@
/*
* 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.
*/
#ifndef _HHH_TVM_BASE_STR_HHH__
#define _HHH_TVM_BASE_STR_HHH__
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <signal.h>
#include <stdarg.h>
#include <getopt.h>
#include <unistd.h>
#include <math.h>
#include <sys/prctl.h>
#include <sys/types.h>
#include <semaphore.h>
#include <sys/syscall.h>
#include <sys/sysinfo.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/timeb.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/msg.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/utsname.h>
#include <netinet/tcp.h>
#include <sys/epoll.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/inotify.h>
#include <strings.h>
#include <iconv.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <dlfcn.h>
#include <libgen.h>
typedef short int sint;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef long long llong;
typedef unsigned char ushar;
typedef unsigned short ushort;
typedef unsigned char Byte;
typedef long int Benum;
typedef unsigned int Uenum;
typedef int BSock;
#ifndef BOOL
typedef unsigned int BOOL;
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef __cplusplus
#ifndef bool
typedef unsigned char bool;
#endif
#ifndef true
#define true 1
#endif
#ifndef false
#define false 0
#endif
#endif // __cplusplus
#define RC_NOTFOUND 24
#define RC_MATCH 2
#define RC_MISMA 1
#define RC_SUCC 0
#define RC_FAIL -1
#define RC_CONTU -5
#define RC_CLOSE -9
#define LOG_DEFU_SIZE 20480000
#define LOG_DEFU_NAME "tvm.log"
typedef pthread_mutex_t pmutex;
/*************************************************************************************************
function
*************************************************************************************************/
typedef struct __COMLIST
{
long m_lSize;
void *m_psvData;
struct __COMLIST *pstNext;
struct __COMLIST *pstLast;
}CMList;
typedef struct __ROWGROUP
{
long lIdx;
long lLen;
size_t lCount;
pmutex lock;
void *psvData;
struct __ROWGROUP *pstSSet;
struct __ROWGROUP *pstFset;
struct __ROWGROUP *pstNext;
struct __ROWGROUP *pstLast;
}Rowgrp;
#ifdef __cplusplus
extern "C" {
#endif
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define bool(x) (x == 0 ? false : true)
#define BOOL(x) (x == 0 ? false : true)
extern CMList* pGetCMTail(CMList *pstRoot);
extern CMList* pSearchNode(CMList *pstRoot, void *psvData, long lSize);
extern CMList* pInsertList(CMList *pstRoot, void *pszData, long lSize);
extern CMList* pDeleteNode(CMList *pstRoot, void *psvData, long lSize);
extern void vDestroyList(CMList *pstRoot);
extern char* supper(char *s);
extern char* slower(char *s);
extern char* strimcrlf(char *p);
extern char* sltrim(char *p);
extern char* srtrim(char *p);
extern char* strimall(char *p);
extern char* strimfield(char *s);
extern char* strimcpy(char *d, char *s, int l);
extern char* strimabout(char *s, char *o, char *d);
extern long lfieldnum(char *p, char *k);
extern char* sfieldvalue(char *p, char *k, int id);
extern long lgetstrnum(char *p, char *s);
extern char* sgetvalue(char *p, char *s, int id);
extern char* sfieldreplace(char *p, char o, char d);
#ifdef __cplusplus
}
#endif
#endif // _HHH_TVM_BASE_STR_HHH__

747
include/tvm.h Normal file
View File

@ -0,0 +1,747 @@
/*
* 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.
*/
#ifndef __TVM_DEFIND_HHHH___
#define __TVM_DEFIND_HHHH___
#include "tstr.h"
typedef pthread_rwlock_t RWLock;
typedef pthread_rwlockattr_t RWAttr;
typedef unsigned int TABLE;
typedef long long llSEQ;
typedef long (*TCREATE)(TABLE t);
typedef long CREATE;
//#pragma pack(4)
#define TVM_VKERNEL "1.2.0.0"
#define TVM_VERSION "1.2.2.0"
/*************************************************************************************************
custom macro
*************************************************************************************************/
#define PROT_JAVA 512
#define FIRST_ROW 256
#define ORDER_DESC 128
#define ORDER_ASC 64
#define ORDER_BY 64
#define GROUP_BY 32
#define MATCH_MAX 16
#define MATCH_MIN 8
#define FIELD_DOUB 4
#define FIELD_LONG 2
#define FIELD_CHAR 1
// execution plan
#define EXE_PLAN_ALL 0
#define EXE_PLAN_IDX 1
#define EXE_PLAN_GRP 2
#define CHK_SELECT 0
#define IDX_SELECT 1
#define RCD_SELECT 2
#define NIL_IGNORE 8
#define OPERATE_NULL 0
#define OPERATE_INSERT 1
#define OPERATE_DELETE 2
#define OPERATE_UPDATE 4
#define OPERATE_SELECT 8
#define OPERATE_TRCATE 14
#define OPERATE_COUNT 15
#define OPERATE_GROUP 16
#define OPERATE_QUERY 17
#define OPERATE_EXTREM 18
#define OPERATE_TBDROP 19
#define OPERATE_RENAME 20
#define OPERATE_SELSEQ 21
#define OPERATE_SETSEQ 22
#define OPERATE_RBDIDX 23
#define OPERATE_RETLOK 24
#define OPERATE_DMKEEP 25
#define OPERATE_DOMPUL 26
#define OPERATE_DOMPSH 27
#define OPERATE_DMRECN 28
#define OPERATE_REFRESH 29
#define OPERATE_DOMLOFF 30
#define OPERATE_DOMROFF 31
#define OPERATE_PULTBL 32
#define OPERATE_BEGWORK 33
#define OPERATE_ROLWORK 34
#define OPERATE_CMTWORK 35
#define OPERATE_ENDWORK 36
#define OPERATE_EXEEXIT 99
#define OPERATE_DEFAULT (OPERATE_SELECT | OPERATE_UPDATE | OPERATE_DELETE | OPERATE_INSERT)
/*************************************************************************************************
Internal definition
*************************************************************************************************/
#define SYS_TVM_INDEX 0x01
#define SYS_TVM_FIELD 0x02 // field table
#define SYS_TVM_DOMAIN 0x03 // domain table
#define SYS_TVM_SEQUE 0x04
#define TVM_MAX_TABLE 0xFF // maximum number of creation of the system
#define MAX_STRIG_LEN 256
#ifndef MAX_INDEX_LEN
#define MAX_INDEX_LEN 64
#endif
#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
#endif
#define MAX_REMOTE_IP 20
#define MAX_TIMESTAMP 20
#define MAX_FILED_IDX 8
// resource flag
#define RES_LOCAL_SID 1
#define RES_REMOT_SID 2
#define RESOURCE_ROFF 5
#define RESOURCE_AUTH 4
#define RESOURCE_EXCP 3
#define RESOURCE_ABLE 2
#define RESOURCE_STOP 1
#define RESOURCE_INIT 0
#define IPC_MSG 0x01
#define IPC_SEM 0x02
#define IPC_SHM 0x03
#define SEM_INIT 1
#define SEM_O_V 1 // Semaphore V operation
#define SEM_O_P -1 // Semaphore P operation
#define SEM_RD 0
#define SEM_WD 1
#define UNQIUE 1
#define NORMAL 16
#define HASHID 32
#define TYPE_SYSTEM 0x01
#define TYPE_INCORE 0x02
#define TYPE_CLIENT 0x03 // custom
#define TYPE_KEYVAL 0x04
#define TVM_NODE_INFO "localhost"
#define TVM_RUNCFG_TAG "\x01\x33\xC8\x48"
#define TVM_BOOT_CLUSTER 2
#define TVM_BOOT_LOCAL 1
#define TVM_BOOT_SIMPLE 0
#define HAVE_INDEX(t) (((TblDef *)pGetTblDef(t))->m_lIType != 0)
#define HAVE_UNIQ_IDX(t) (((TblDef *)pGetTblDef(t))->m_lIType & UNQIUE)
#define HAVE_NORL_IDX(t) (((TblDef *)pGetTblDef(t))->m_lIType & NORMAL)
#define HAVE_HASH_IDX(t) (((TblDef *)pGetTblDef(t))->m_lIType & HASHID)
#define IS_RED(x) (x->m_eColor == COLOR_RED)
#define FPOS(t, f) ((size_t)&((t *)0)->f)
#define FLEN(t, f) (sizeof(((t *)0)->f))
#define NODE_NULL g_lNilOfs
#define ReField(t, f) (FPOS(t, f) << 16 | FLEN(t, f))
#define REFrom(t) (t >> 16)
#define REFLen(t) (t & 0xffff)
#define WORK_ERROR_LOG "work.err"
#define STVM_SQL_LINE ".stvmrc"
#define COLOR_BLK 0
#define COLOR_RED 1
#define SELF_POS_UNUSE 0
#define DATA_TRUCK_NULL 0x00
#define DATA_TRUCK_NRML 0x01
#define DATA_TRUCK_LOCK 0x02
#define TABLE_LOCK_READ 1
#define TABLE_LOCK_WRITE 2
#define IS_TRUCK_NULL(p) ((p)->m_chTag == DATA_TRUCK_NULL)
#define IS_TRUCK_NRML(p) ((p)->m_chTag == DATA_TRUCK_NRML)
#define IS_TRUCK_LOCK(p) ((p)->m_chTag == DATA_TRUCK_LOCK)
#define SET_DATA_TRUCK(p, type) ((p)->m_chTag = type)
#define TFree(p) if(p) { free(p); p = NULL; }
#define TFgrp(p) do{vDeleteRowgrp(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 TVM_DONE_SUCC 0 // completed successfully
#define SVR_EXCEPTION 1 // sever exception
#define IDX_FIELD_NIL 2 // index field values is null
#define CONDIT_IS_NIL 3 // condition is null
#define DATA_SPC_FULL 4 // no space for create data
#define GENER_KEY_ERR 5 // generate shm key failure
#define SHM_ERR_INVAL 6 // Invalid parameter or shm has disappeared
#define SHM_ERR_EXIST 7 // shared memory already exists
#define SHM_ERR_EIDRM 8 // shared memory has been deleted
#define SHM_ERR_ACCES 9 // Permission denied
#define SHM_ERR_NOMEM 10 // Insufficient(shm) core memory
#define VER_NOT_MATCH 11 // data truck version mismatch
#define BLCK_SIZE_ERR 12 // size is error to creat data block
#define IDX_DEF_SPILL 13 // unique Index definition overflow
#define IDX_LEN_SPILL 14 // unique Index length overflow
#define GRP_DEF_SPILL 15 // normal Index definition overflow
#define GRP_LEN_SPILL 16 // normal Index length overflow
#define IDX_TYP_NODEF 17 // index type not define
#define FLD_DEF_SPILL 18 // field define overflow
#define IDX_DATA_MISM 19 // index data mismatch
#define FTYPE_NOT_DEF 20 // field type not define
#define SHMT_NOT_INIT 21 // memory has not been initialized
#define UNIQ_IDX_REPT 22 // unique index repeat
#define IDX_SPC_SPILL 23 // no space for create index
#define NO_DATA_FOUND 24 // no data be found
#define MORE_ROWS_SEL 25 // more then one records be selected
#define MALLC_MEM_ERR 26 // malloc memory error
#define CURS_IS_INVAL 27 // cursor invalid
#define TABLE_NOT_DEF 28 // table not define
#define FIL_NOT_EXIST 29 // file not exist
#define SEM_CDIT_NULL 30 // semget condition is null
#define SEM_ERR_INVAL 31 // Invalid parameter or sem has disappeared
#define SEM_ERR_EXIST 32 // semaphore already exists
#define SEM_ERR_EIDRM 33 // semaphore has been deleted
#define SEM_ERR_ACCES 34 // Permission denied(sem)
#define SEM_ERR_NOMEM 35 // Insufficient(sem) core memory
#define SEM_ERR_LIMIT 36 // Semaphore value out of limit
#define SQL_SYNTX_ERR 37 // SQL syntax is error
#define SQL_NOT_SUPPT 38 // SQL operation not be supported
#define SQL_TABLE_NIL 39 // SQL no table name be inputted
#define SQL_FIELD_NIL 40 // SQL field is not selected
#define SQL_WHERE_NIL 41 // SQL conditional syntax error
#define SQL_ERR_FIELD 42 // SQL field syntax error
#define SQL_ERR_WHERE 43 // SQL where syntax error
#define TBL_NOT_FOUND 44 // table not found
#define SQL_FAV_MATCH 45 // SQL fields does not match the value
#define LOCK_DORD_ERR 46 // set the read lock failure
#define LOCK_UNRD_ERR 47 // unlock read lock failure
#define LOCK_DOWR_ERR 48 // set the write lock failure
#define LOCK_UNWR_ERR 49 // unlock write lock failure
#define SOCK_CONN_ERR 50 // socket connect failure
#define SOCK_CONN_TMO 51 // socket connect timeout
#define SOCK_ERR_CRTE 52 // create socket failure
#define SOCK_READ_ERR 53 // socket recv failure
#define SOCK_SEND_ERR 54 // socket send failure
#define SOCK_BIND_ERR 55 // socket bind failure
#define SOCK_LSEN_ERR 56 // socket listen failure
#define SOCK_SEND_TMO 57 // socket send timeout
#define SOCK_READ_TMO 58 // socket read timeout
#define SOCK_IO_RESET 59 // socket reset
#define SOCK_COM_EXCP 60 // Socket communication anomaly
#define EPOLL_ADD_ERR 61 // epoll add fd error
#define EPOLL_CRT_ERR 62 // create epoll fd failure
#define EPOLL_DEL_ERR 63 // delete epoll fd failure
#define SOCK_ACPT_ERR 64 // socket accept failure
#define RMT_NOT_SUPPT 65 // SQL remote does not support
#define FILE_NOTFOUND 66 // file not found
#define BOOT_PARM_ERR 67 // boot parameters error
#define BOOT_RELA_ERR 68 // parameters table related error
#define BOOT_VER_ICMP 69 // Incompatible version
#define DOM_NOT_REGST 70 // domain not register
#define DMWORK_NOTSUP 71 // domain work does not support
#define SEQ_NOT_FOUND 72 // sequence does not exist
#define FILE_NOT_RSET 73 // file is not set
#define RECD_TOO_LONG 74 // record data too long
#define RESOU_DISABLE 75 // Resource unavailable
#define MSG_ERR_EXIST 76 // message queue already exists
#define MSG_ERR_ACCES 77 // Permission denied .msg
#define MSG_ERR_NOMEM 78 // Insufficient(msg) core memory
#define MSG_ERR_INVAL 79 // Invalid parameter or msg has disappeared
#define MSG_ERR_FAULT 80 // msg Invalid address
#define MSG_ERR_EIDRM 81 // message queue has been deleted
#define MSG_ERR_E2BIG 82 // message text length is greater than msgsz
#define MSG_ERR_EINTR 83 // Interrupted by signal
#define MSG_ERR_SNDEG 84 // msgsnd queue overrun
#define INI_ERR_CHLDP 85 // initial child process failed
#define FLD_NOT_EXIST 86 // field not exist
#define TBL_ARD_EXIST 87 // table already exist
#define WORK_NOT_OPEN 88 // The transaction has not been opened yet
#define WORK_NOT_REGT 89 // The transaction has not been register
#define DOM_NOT_INITL 90 // domain not initail
#define FIELD_NOT_DEF 91 // table field not define
#define FIELD_NOT_SET 92 // field not set
#define UPDFD_NOT_SET 93 // update field not set
#define EXTRE_SET_ERR 94 // extreme set decorate error
#define GROUP_SET_ERR 95 // group set decorate error
/*************************************************************************************************
*************************************************************************************************/
#define DEFINE(t, n, p, s) TABLE tbl = t; long type = 0; \
((TblDef *)pGetTblDef(t))->m_table = t; \
((TblDef *)pGetTblDef(t))->m_lReSize = sizeof(s); \
strncpy(((TblDef *)pGetTblDef(t))->m_szPart, p, MAX_FIELD_LEN); \
strncpy(((TblDef *)pGetTblDef(t))->m_szTable, n, MAX_FIELD_LEN); \
((TblDef *)pGetTblDef(t))->m_lTruck = sizeof(s) + sizeof(SHTruck);
#define CREATE_IDX(t) type = t;
#define IDX_FIELD(t, f, a) if(RC_SUCC != lAddIdxField(tbl, type, FPOS(t, f), FLEN(t, f), a)) \
return RC_FAIL;
#define FIELD(t, f, d, a) if(RC_SUCC != lSetTableIdx(tbl, FPOS(t, f), FLEN(t, f), d, a, CHK_SELECT)) \
return RC_FAIL;
#define FIELU(t, f, d, a) if(RC_SUCC != lSetTableIdx(tbl, FPOS(t, f), FLEN(t, f), d, a, IDX_SELECT)) \
return RC_FAIL;
#define FIELR(t, f, d, a) if(RC_SUCC != lSetTableIdx(tbl, FPOS(t, f), FLEN(t, f), d, a, RCD_SELECT)) \
return RC_FAIL;
#define FINISH return RC_SUCC;
/*************************************************************************************************
Field assignment
*************************************************************************************************/
#define defineinit(p,s,t) do{ \
p->stCond.uFldcmp = 0; \
p->stUpdt.uFldcmp = 0; \
p->lSize = sizeof(s); \
p->tblName = t; \
p->pstVoid = (void *)&(s); \
}while(0);
#define insertinit(p,s,t) do{ \
p->lSize = sizeof(s); \
p->tblName = t; \
p->pstVoid = (void *)&(s); \
}while(0);
#define conditinit(p,s,t) do{ \
p->stCond.uFldcmp = 0; \
p->stUpdt.uFldcmp = 0; \
p->lSize = sizeof(s); \
p->tblName = t; \
p->lFind = 0; \
memset(&(s), 0, p->lSize); \
p->pstVoid = (void *)&(s); \
}while(0);
#define conditnull(p,d,t) do{ \
p->stCond.uFldcmp = 0; \
p->stUpdt.uFldcmp = 0; \
p->lFind = 0; \
p->lSize = sizeof(d); \
p->tblName = t; \
p->pstVoid = NULL; \
}while(0);
#define stringsetv(p,s,f,...) vSetCodField(&p->stCond, sizeof((s).f), (void *)(s).f - (void *)&(s)); \
snprintf((s).f, sizeof((s).f), __VA_ARGS__);
#define stringset(p,s,f,v) vSetCodField(&p->stCond, sizeof((s).f), (void *)(s).f - (void *)&(s)); \
strncpy((s).f, v, sizeof((s).f));
#define stringcpy(p,s,f,v) vSetCodField(&p->stCond, sizeof((s).f), (void *)(s).f - (void *)&(s)); \
memcpy(&(s) + ((void *)(s).f - (void *)&(s)), (void *)v, sizeof((s).f));
#define numberset(p,s,f,v) vSetCodField(&p->stCond, sizeof((s).f), (void *)&(s).f - (void *)&(s)); \
(s).f = v;
#define decorate(p,d,f,v) vSetDecorate(&p->stUpdt, FLEN(d, f), FPOS(d, f), v); \
p->lFind = (v) & FIRST_ROW;
#define stringreset(s,f,v) strncpy((s).f, v, sizeof((s).f));
#define stringresetv(s,f,...) snprintf((s).f, sizeof((s).f), __VA_ARGS__);
#define stringrecpy(s,f,v) memcpy((s).f, v, sizeof((s).f));
#define numberreset(s,f,v) (s).f = v;
// UPDATE Field assignment
#define updateinit(s) memset(&(s), 0, sizeof(s));
#define stringupd(p,s,f,v) vSetCodField(&p->stUpdt, sizeof((s).f), (void *)(s).f - (void *)&(s)); \
strncpy((s).f, v, sizeof((s).f));
#define stringupy(p,s,f,v) vSetCodField(&p->stUpdt, sizeof((s).f), (void *)(s).f - (void *)&(s)); \
memcpy(&(s) + ((void *)(s).f - (void *)&(s)), (void *)v, sizeof((s).f));
#define numberupd(p,s,f,v) vSetCodField(&p->stUpdt, sizeof((s).f), (void *)&(s).f - (void *)&(s)); \
(s).f = v;
/*************************************************************************************************
Table structure & index definition area
*************************************************************************************************/
typedef struct __SH_DATA_TRUCK
{
ulong m_lTimes;
char m_chTag;
char m_pvData[0];
}SHTruck, *PSHTruck;
typedef struct __SH_RBTREE
{
size_t m_lSePos;
char m_szIdx[MAX_INDEX_LEN];
long m_lIdx;
size_t m_lData;
long m_eColor;
size_t m_lParent;
size_t m_lLeft;
size_t m_lRight;
}SHTree;
typedef struct __SH_LIST
{
size_t m_lPos;
size_t m_lNode;
size_t m_lData;
size_t m_lNext;
size_t m_lLast;
}SHList;
typedef struct __TBL_COM_KEY
{
long m_lFrom;
long m_lLen;
long m_lAttr;
long m_lIsPk;
char m_szField[MAX_FIELD_LEN];
}TblKey;
typedef struct __TBL_HEAD_DEF
{
RWLock m_rwlock; // rwlock
long m_lGroup; // index group
size_t m_lMaxRow; // maximum support
size_t m_lValid; // number of valid
long m_lIdxLen; // unique index length
size_t m_lNodeNil; // NIL
size_t m_lTreePos; // unique tree position
size_t m_lTreeRoot; // unique tree root
long m_lGrpLen; // index length
size_t m_lGroupPos; // index position
size_t m_lGroupRoot; // index root
size_t m_lListPos; // list position
size_t m_lListOfs; // list offset
size_t m_lData; // data offset
uint m_lIType; // index type
uint m_lIdxUp; // unique index field
TblKey m_stIdxUp[MAX_FILED_IDX]; // unique index
uint m_lGrpUp; // index field
TblKey m_stGrpUp[MAX_FILED_IDX]; // index
size_t m_lTable; // table size
long m_lReSize; // row size
size_t m_lTruck; // truck size
llSEQ m_lExSeQ; // extern sequence
long m_lExtern; // extern table space(standby)
long m_lIdxNum; // Number of fields
TblKey m_stKey[MAX_FILED_NUM]; // fields
TABLE m_table; // table
char m_szTable[MAX_FIELD_LEN]; // table name
char m_szPart[MAX_FIELD_LEN]; //
SHTree m_stNil;
}TblDef;
static long g_lNilOfs = FPOS(TblDef, m_stNil);
typedef struct __SQL_FIELD
{
TblKey m_stKey;
struct __SQL_FIELD *pstNext;
}SQLFld;
/*************************************************************************************************
TVM engine starts the required table (do not move)
*************************************************************************************************/
typedef struct __SYS_TVM_INDEX
{
TABLE m_table; // table
long m_lType; // table type
char m_szTable[MAX_FIELD_LEN]; // table name
char m_szPart[MAX_FIELD_LEN]; // partition name
char m_szOwner[MAX_FIELD_LEN]; // owner
key_t m_yKey;
long m_shmID; // Memory Key
long m_semID; // semaphore key
long m_lPid; // pid
long m_lValid; // valid
long m_lMaxRows; // Table maximum support record number.
long m_lRowSize; // truck size
long m_lLocal; // Local/remote
uint m_lState; // available
long m_lPers; // permissions
char m_szTime[MAX_TIMESTAMP]; // create time
}TIndex;
typedef struct __SYS_TVM_FIELD
{
TABLE m_table; // table
long m_lSeq; // filed seq
char m_szOwner[MAX_FIELD_LEN]; // owner
char m_szTable[MAX_FIELD_LEN]; // table name
char m_szField[MAX_FIELD_LEN]; // field name
long m_lAttr; // attr
long m_lFrom; // field from
long m_lLen; // field length
long m_lIsPk;
}TField;
typedef struct __SYS_TVM_DOMAIN
{
BSock m_skSock;
TABLE m_table;
TABLE m_mtable;
long m_lLock;
long m_lGroup;
long m_lKeepLive;
long m_lLastTime;
long m_lTimeOut;
long m_lTryMax;
long m_lTryTimes;
long m_lRowSize;
long m_lStatus; // remote domain state
long m_lPers; // perms
long m_lPort;
long m_lRelia;
char m_szIp[MAX_REMOTE_IP];
char m_szTable[MAX_FIELD_LEN];
char m_szPart[MAX_FIELD_LEN];
char m_szOwner[MAX_FIELD_LEN];
}TDomain;
typedef struct __SYS_TVM_SEQUE
{
char m_szSQName[MAX_INDEX_LEN]; // Name of sequence
uint m_uIncrement;
}TSeque;
/*************************************************************************************************
Operating handle
*************************************************************************************************/
typedef struct __TBL_FILED_KEY
{
Uenum uDecorate;
uint uFldpos;
uint uFldlen;
}FdKey;
typedef struct __TBL_CONDIT_FLD
{
uint uFldcmp;
FdKey stFdKey[MAX_FILED_NUM];
}FdCond;
typedef struct __TVM_WORK
{
TABLE m_table;
long m_lRowSize;
long m_lOperate;
FdCond m_stCond;
FdCond m_stUpdt;
void *m_pvData;
void *m_pvNew;
}TWork;
typedef struct __TVM_RUNTIME
{
void *pstVoid;
uint m_lState;
uint m_lLocal;
long m_shmID; // Memory Key
long m_semID; // semaphore key
long m_lRowSize; // Record block size
bool m_bAttch; // Does it initialize
void *m_pvAddr;
long m_lCurLine; // cursor line
long m_lCurType; // cursor type
void *m_pvCurAddr; // cursor address
}RunTime;
typedef struct __TVM_OPERATE
{
size_t lSize; // struck size
Uenum lFind; // find type
Uenum bSearch; // find table type
TABLE tblName; // table
void *pstVoid; // condition
FdCond stCond;
FdCond stUpdt;
bool m_bWork; // work
bool m_bPrew; // work on or off
bool m_bHold; // memory hold
bool m_bCreat;
CMList *m_pstWork; // work list
uint m_lTimes;
BSock m_skSock;
Uenum m_lEType;
key_t m_yKey;
key_t m_ySey;
key_t m_yMey;
Uenum m_lErrno;
size_t m_lEffect; // effect record line
bool m_bCache;
char m_szMsg[256]; // Custom message
char m_szNode[MAX_FIELD_LEN];
RunTime stRunTime[TVM_MAX_TABLE]; // table handle
}SATvm;
typedef struct __TVM_BOOT_PARAM
{
long m_lMaxTable;
long m_lMaxField;
long m_lMaxDomain;
long m_lMaxSeque;
long m_lBootExec;
long m_lBootPort;
long m_lBootType;
char m_szNode[MAX_FIELD_LEN];
char m_szLog[MAX_STRIG_LEN];
}TBoot;
/*************************************************************************************************
*************************************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
extern char* sGetLog();
extern char* sGetNode();
extern void* pGetBoot();
extern void* pGetSATvm();
extern long lDefaultBoot();
extern TBoot* pBootInitial();
extern size_t lGetTblRow(TABLE t);
extern long lGetPermit(TABLE t);
extern long lGetRowSize(TABLE t);
extern TblDef* pGetTblDef(TABLE t);
extern TblKey* pGetTblIdx(TABLE t);
extern uint lGetIdxNum(TABLE t);
extern uint lGetGrpNum(TABLE t);
extern size_t lGetTblData(TABLE t);
extern size_t lGetListOfs(TABLE t);
extern size_t lGetRowTruck(TABLE t);
extern size_t lGetIdxPos(TABLE t);
extern size_t lGetGrpPos(TABLE t);
extern long lGetFldNum(TABLE t);
extern size_t lGetIdxRoot(TABLE t);
extern long lGetTblGroup(TABLE t);
extern size_t lGetTblValid(TABLE t);
extern TblKey* pGetTblGrp(TABLE t);
extern TblKey* pGetTblKey(TABLE t);
extern RWLock* pGetRWLock(char* pvAddr);
extern void vRedeError(long err, char *s);
extern void* pGetAddr(SATvm *pstSavm, TABLE t);
extern RunTime* pGetRunTime(SATvm *pstSavm, TABLE t);
extern void* pGetNode(void *pvData, size_t lOfs);
extern void* pInitMemTable(SATvm *pstSavm, TABLE t);
extern void* pInitHitTest(SATvm *pstSavm, TABLE t);
extern long lTableMaxRow(SATvm *pstSavm, TABLE t);
extern key_t yGetIPCPath(SATvm *pstSavm, Benum em);
extern long lGetBootConfig(SATvm *pstSavm, TBoot *pstBoot);
extern long lAddIdxField(TABLE, long, long, long, long);
extern long lSetTableIdx(TABLE, long, long, char*, long, long);
extern long lUpdIndexPart(SATvm *pstSavm, TABLE t, char *pszPart);
extern TblKey* pFindField(TblKey *pstIdx, long lNum, char *pszField);
extern long lGetTblField(TABLE t, size_t *plOut, TField **ppstField);
extern void vSetCodField(FdCond *pstCond, uint ulen, uint uPos);
extern bool bSetCondAttr(FdCond *pstCond, TABLE t, Uenum eCheck);
extern void vSetDecorate(FdCond *pstCond, uint ulen, uint uPos, Uenum em);
extern long lGetDomainIndex(SATvm *pstSavm, long *plOut, TIndex **ppstIndex);
extern long lGetDomainTable(SATvm *pstSavm, long *plOut, TDomain **ppstDomain);
extern long lGetLocalIndex(SATvm *pstSavm, long *plOut, TIndex **ppstIndex);
extern long lGetTblIndex(SATvm *pstSavm, char *pszTable, char *pszPart, TIndex *pstIndex);
/*************************************************************************************************
config make&unmake
*************************************************************************************************/
extern long lUnmakeConfig(char *pszFile);
extern long lMakeConfig(char *pszFile);
/*************************************************************************************************
IPC Message and semaphore
*************************************************************************************************/
extern long lGetQueueNum(SATvm *pstSavm, long lQid);
extern long lQueueMaxByte(SATvm *pstSavm, long lQid);
extern long lQueueRcvTime(SATvm *pstSavm, long lQid);
extern long lCreateQueue(SATvm *pstSavm, bool bCreate);
extern long lOperateSems(SATvm *pstSavm, long semID, long lSems, Benum evp);
extern long lEventWrite(SATvm *pstSavm, long lQid, void *psvData, long lSize);
extern long lCreateSems(SATvm *pstSavm, RunTime *pstRun, long lSems, long lValue);
extern long lEventRead(SATvm *pstSavm, long lQid, void *pstVoid, long lSize, long lMType);
extern long lReadNoWait(SATvm *pstSavm, long lQid, void *psvVoid, long lSize, long lMType);
/*************************************************************************************************
api
*************************************************************************************************/
extern long lShutdownTvm();
extern long lStartupTvm(TBoot *pstBoot);
extern char* sGetUpdTime();
extern long lGetTErrno();
extern void vSetTvmMsg(SATvm *pstSavm, char *fmt, ...);
extern char* sGetTvmMsg(SATvm *pstSavm);
extern void vSetTErrno(long err);
extern char* sGetTError(long err);
extern size_t lGetEffect();
extern bool bIsTvmBoot();
extern void* pInitSATvm(TABLE t);
extern long lInitSvCache(SATvm *pstSavm);
extern void vInitSATvm(SATvm *pstSavm);
extern bool bTableIsExist(TABLE t);
extern bool bPartIsExist(char *pszTable, char *pszPart);
extern long lInitSATvm(SATvm *pstSavm, TABLE t);
extern void* pPartSatvm(SATvm *pstSavm, char *pszTable, char *pszPart);
extern long lResetLock(SATvm *pstSavm, TABLE t);
extern long lRebuildIndex(SATvm *pstSavm, TABLE t);
extern void vHoldConnect(SATvm *pstSavm);
extern void vHoldRelease(SATvm *pstSavm);
extern void vTblDisconnect(SATvm *pstSamo, TABLE t);
extern void vForceDisconnect(SATvm *pstSamo, TABLE t);
extern void vBeginWork(SATvm *pstSavm);
extern void vEndWork(SATvm *pstSavm);
extern long lCommitWork(SATvm *pstSavm);
extern long lRollbackWork(SATvm *pstSavm);
extern long lDropTable(SATvm *pstSavm, TABLE t);
extern long lImportFile(TABLE t, char *pszFile, char *pszFlag);
extern long lExportFile(TABLE t, char *pszFile, char *pszFlag);
extern long lImportTable(TABLE t, size_t lCount, void *psvOut);
extern long lExportTable(TABLE t, size_t *plOut, void **ppsvOut);
extern long lRenameTable(SATvm *pstSavm, TABLE to, TABLE tn);
extern long lCreateSeque(SATvm *pstSavm, char *pszSQName, uint uIncre);
extern long lSelectSeque(SATvm *pstSavm, char *pszSQName, ulong *pulNumber);
extern long lSetSequence(SATvm *pstSavm, char *pszSQName, ulong uStart);
extern long lCustomTable(SATvm *pstSavm, TABLE t, size_t lRow, TblDef *pstDef);
extern long lCreateTable(SATvm *pstSavm, TABLE t, size_t lRow, TCREATE pfCreateFunc);
extern long lInsertTrans(SATvm *pstSavm, size_t *plOffset, llSEQ *pllSeq);
extern long lDelete(SATvm *pstSavm);
extern long lInsert(SATvm *pstSavm);
extern long lTruncate(SATvm *pstSavm, TABLE t);
extern long lSelect(SATvm *pstSavm, void *psvOut);
extern long lUpdate(SATvm *pstSavm, void *psvUpd);
extern long lCount(SATvm *pstSavm, size_t *plCount);
extern long lExtreme(SATvm *pstSavm, void *psvOut);
extern long lGroup(SATvm *pstSavm, size_t *plOut, void **ppsvOut);
extern long lQuery(SATvm *pstSavm, size_t *plOut, void **ppsvOut);
extern long lTableDeclare(SATvm *pstSavm);
extern long lTableFetch(SATvm *pstSavm, void *psvOut);
extern long lNextFetch(SATvm *pstSavm, void **ppvOAddr);
extern void vTableClose(SATvm *pstSavm);
#ifdef __cplusplus
}
#endif
/*************************************************************************************************
code end
*************************************************************************************************/
#endif // __TVM_DEFIND_HHHH___

1271
src/conf.c Normal file

File diff suppressed because it is too large Load Diff

404
src/detvm.c Normal file
View File

@ -0,0 +1,404 @@
/*
* 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"
/*************************************************************************************************
macro
*************************************************************************************************/
#define DEBUG_HEAD_INFO 1
#define DEBUG_UNIQ_IDEX 2
#define DEBUG_GROP_IDEX 4
#define DEBUG_GROP_LIST 8
#define DEBUG_DATA_LIST 16
#define DEBUG_IDEX_TREE 32
#define DEBUG_IDEX_DATA 64
#define DEBUG_IDEX_DALL 128
#define DEBUG_ALLD_INFO (DEBUG_HEAD_INFO|DEBUG_UNIQ_IDEX|DEBUG_GROP_IDEX|DEBUG_GROP_LIST|DEBUG_DATA_LIST)
/*************************************************************************************************
function
*************************************************************************************************/
extern void vPrintHex(char *s, long lIdx, bool bf);
/*************************************************************************************************
descriptiondebug tree node
parameters:
pvData --memory address
pstTree --tree node
return:
*************************************************************************************************/
void vDebugTree(void *pvData, SHTree *pstTree)
{
if(!pvData || !pstTree) return ;
fprintf(stderr, "DugTree:%p-SePos:[%8ld], Idx(%ld):[%15s](%2ld), Color[%ld], lSePos:[%4ld], "
"lParent[%4ld], left[%4ld], right[%4ld]\n" , (char *)pstTree, (void *)pstTree - pvData,
pstTree->m_lIdx, pstTree->m_szIdx, pstTree->m_lData, pstTree->m_eColor, pstTree->m_lSePos,
pstTree->m_lParent, pstTree->m_lLeft, pstTree->m_lRight);
if(SELF_POS_UNUSE == pstTree->m_lSePos || NODE_NULL == pstTree->m_lSePos)
return ;
if(NODE_NULL != pstTree->m_lLeft)
vDebugTree(pvData, (SHTree *)pGetNode(pvData, pstTree->m_lLeft));
if(NODE_NULL != pstTree->m_lRight)
vDebugTree(pvData, (SHTree *)pGetNode(pvData, pstTree->m_lRight));
}
/*************************************************************************************************
descriptiondebug table
parameters:
pvData --memory address
pstTree --tree node
return:
*************************************************************************************************/
void vDebugTable(TABLE t, long eType)
{
long i = 0, j = 0;
RunTime *pstRun = NULL;
TblKey *pstKey = NULL;
SHTree *pstTree = NULL;
SHList *pstList = NULL;
SHTruck *pstTruck = NULL;
TIndex *pstIndex = NULL;
SATvm *pstSavm = (SATvm *)pGetSATvm();
if(NULL == (pstSavm = (SATvm *)pInitSATvm(t)))
{
fprintf(stderr, "initial table (%d) failed\n", t);
return ;
}
if(NULL == (pstRun = pInitHitTest(pstSavm, pstSavm->tblName)))
{
fprintf(stderr, "hit test table (%d) failed, err:(%d)(%s)\n", t,pstSavm->m_lErrno,
sGetTError(pstSavm->m_lErrno));
return ;
}
if(eType & DEBUG_HEAD_INFO)
{
fprintf(stdout, "\n==========================================TABLE HEAND INFO============="
"============================\n");
fprintf(stdout, "TABLE:%d, NAME:%s\tSHTree(%ld),SHList(%ld),TblDef(%ld)\n"
"extern:%ld, Group:%ld, MaxRow:%ld, Valid:%ld, lNodeNil:%ld, lIType:%d, "
"Table:%ld\nIdxLen:%ld, TreePos:%ld, TreeRoot:%ld, GrpLen:%ld, GroupPos:%ld, "
"GroupRoot:%ld\nListPos:%ld, ListOfs:%ld, Data:%ld, ReSize:%ld, Truck:%ld\n",
((TblDef *)pGetTblDef(t))->m_table, ((TblDef *)pGetTblDef(t))->m_szTable,
sizeof(SHTree), sizeof(SHList), sizeof(TblDef), ((TblDef *)pGetTblDef(t))->m_lExtern,
((TblDef *)pGetTblDef(t))->m_lGroup, ((TblDef *)pGetTblDef(t))->m_lMaxRow,
((TblDef *)pGetTblDef(t))->m_lValid, ((TblDef *)pGetTblDef(t))->m_lNodeNil,
((TblDef *)pGetTblDef(t))->m_lIType,
((TblDef *)pGetTblDef(t))->m_lTable, ((TblDef *)pGetTblDef(t))->m_lIdxLen,
((TblDef *)pGetTblDef(t))->m_lTreePos, ((TblDef *)pGetTblDef(t))->m_lTreeRoot,
((TblDef *)pGetTblDef(t))->m_lGrpLen, ((TblDef *)pGetTblDef(t))->m_lGroupPos,
((TblDef *)pGetTblDef(t))->m_lGroupRoot, ((TblDef *)pGetTblDef(t))->m_lListPos,
((TblDef *)pGetTblDef(t))->m_lListOfs, ((TblDef *)pGetTblDef(t))->m_lData,
((TblDef *)pGetTblDef(t))->m_lReSize, ((TblDef *)pGetTblDef(t))->m_lTruck);
pstTree = &((TblDef *)pGetTblDef(t))->m_stNil;
fprintf(stdout, ">>NODE_NULL POS:[%8ld], Idx:[%s](%ld)(%ld), Color[%ld], lSePos:[%4ld], lParent[%4ld]"
", left[%4ld], right[%4ld]\n" , (void *)pstTree - (void *)pGetTblDef(t), pstTree->m_szIdx,
pstTree->m_lIdx, pstTree->m_lData, pstTree->m_eColor, pstTree->m_lSePos, pstTree->m_lParent,
pstTree->m_lLeft, pstTree->m_lRight);
fprintf(stdout, "==========UNIQ INDEX FIELD=========\n");
for(i = 0, pstKey = pGetTblIdx(t); i < lGetIdxNum(t); i ++)
{
fprintf(stdout, "From:%4ld, len:%3ld, attr:%ld, IsPk:%ld, field:%s\n", pstKey[i].m_lFrom,
pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_lIsPk, pstKey[i].m_szField);
}
fprintf(stdout, "==========GROUP INDEX FIELD========\n");
for(i = 0, pstKey = pGetTblGrp(t); i < lGetGrpNum(t); i ++)
{
fprintf(stdout, "From:%4ld, len:%3ld, attr:%ld, IsPk:%ld, field:%s\n", pstKey[i].m_lFrom,
pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_lIsPk, pstKey[i].m_szField);
}
fprintf(stdout, "==================== TABLE FIELD ====================\n");
for(i = 0, pstKey = pGetTblKey(t); i < lGetFldNum(t); i ++)
{
fprintf(stdout, "From:%4ld, len:%3ld, attr:%ld, IsPk:%ld, field:%s\n", pstKey[i].m_lFrom,
pstKey[i].m_lLen, pstKey[i].m_lAttr, pstKey[i].m_lIsPk, pstKey[i].m_szField);
}
}
if(eType & DEBUG_UNIQ_IDEX)
{
fprintf(stdout, "\n===================================UNIQUE_INDEX====================="
"==============lValid(%ld)=========================\n", lGetTblValid(t));
if(eType & DEBUG_IDEX_DALL)
{
for(i = 0; i < lGetTblRow(t); i ++)
{
pstTree = (SHTree *)(pstRun->m_pvAddr + lGetIdxPos(t) + i * sizeof(SHTree));
vPrintHex(pstTree->m_szIdx, pstTree->m_lIdx, 0);
fprintf(stdout, "NODE:[%ld](%02ld), Idx:[%4s](%ld)(%2ld), Color[%ld], lSePos:[%4ld], "
"lParent[%4ld], left[%4ld], right[%4ld]\n" , (void *)pstTree - pstRun->m_pvAddr,
i, pstTree->m_szIdx, pstTree->m_lIdx, pstTree->m_lData, pstTree->m_eColor,
pstTree->m_lSePos, pstTree->m_lParent, pstTree->m_lLeft, pstTree->m_lRight);
}
}
else
{
for(i = 0; i < lGetTblValid(t); i ++)
{
pstTree = (SHTree *)(pstRun->m_pvAddr + lGetIdxPos(t) + i * sizeof(SHTree));
if(SELF_POS_UNUSE == pstTree->m_lSePos || NODE_NULL == pstTree->m_lSePos)
continue;
vPrintHex(pstTree->m_szIdx, pstTree->m_lIdx, 0);
fprintf(stdout, "NODE:[%6ld]->(%02ld), Idx:[%15s](%6ld), Color[%ld], lSePos:[%4ld], "
"lParent[%4ld], left[%4ld], right[%4ld]\n" , (void *)pstTree - pstRun->m_pvAddr, i,
pstTree->m_szIdx, pstTree->m_lData, pstTree->m_eColor, pstTree->m_lSePos,
pstTree->m_lParent, pstTree->m_lLeft, pstTree->m_lRight);
}
}
}
if(eType & DEBUG_GROP_IDEX)
{
fprintf(stdout, "\n===================================INDEX_GROUP====================="
"==============Valid:%ld, Group:%ld================\n", lGetTblValid(t), lGetTblGroup(t));
if(eType & DEBUG_IDEX_DALL)
{
for(i = 0; i < lGetTblRow(t); i ++)
{
pstTree = (SHTree *)(pstRun->m_pvAddr + lGetGrpPos(t) + i * sizeof(SHTree));
vPrintHex(pstTree->m_szIdx, pstTree->m_lIdx, 0);
fprintf(stdout, "NODE:[%ld](%02ld), Idx:[%4s](%ld)(%2ld), Color[%ld], lSePos:[%4ld],"
" lParent[%4ld], left[%4ld], right[%4ld]\n" , (void *)pstTree - pstRun->m_pvAddr,
i, pstTree->m_szIdx, pstTree->m_lIdx, pstTree->m_lData, pstTree->m_eColor,
pstTree->m_lSePos, pstTree->m_lParent, pstTree->m_lLeft, pstTree->m_lRight);
}
}
else
{
for(i = 0; i < lGetTblValid(t); i ++)
{
pstTree = (SHTree *)(pstRun->m_pvAddr + lGetGrpPos(t) + i * sizeof(SHTree));
if(SELF_POS_UNUSE == pstTree->m_lSePos || NODE_NULL == pstTree->m_lSePos)
continue;
vPrintHex(pstTree->m_szIdx, pstTree->m_lIdx, 0);
fprintf(stdout, "NODE:[%ld](%02ld), Idx:[%4s](%ld)(%2ld), Color[%ld], lSePos:[%4ld],"
" lParent[%4ld], left[%4ld], right[%4ld]\n" , (void *)pstTree - pstRun->m_pvAddr,
i, pstTree->m_szIdx, pstTree->m_lIdx, pstTree->m_lData, pstTree->m_eColor,
pstTree->m_lSePos, pstTree->m_lParent, pstTree->m_lLeft, pstTree->m_lRight);
}
}
}
if(eType & DEBUG_GROP_LIST)
{
fprintf(stdout, "\n=================================INDEX_LIST========================"
"==============Valid(%ld)=============\n", lGetTblValid(t));
if(eType & DEBUG_IDEX_DALL)
{
for(i = 0, j = lGetListOfs(t); i < lGetTblRow(t); i ++)
{
pstList = (SHList *)(pstRun->m_pvAddr + j + i * sizeof(SHList));
fprintf(stdout, "LIST:[%8ld][%02ld], lSePos:[%4ld], lData[%8ld], Node[%8ld], "
"Next[%8ld], Last[%8ld]\n" , (void *)pstList - pstRun->m_pvAddr, i,
pstList->m_lPos, pstList->m_lData, pstList->m_lNode, pstList->m_lNext,
pstList->m_lLast);
}
}
else
{
for(i = 0, j = lGetListOfs(t); i < lGetTblValid(t); i ++)
{
pstList = (SHList *)(pstRun->m_pvAddr + j + i * sizeof(SHList));
if(SELF_POS_UNUSE == pstList->m_lPos)
continue;
fprintf(stdout, "LIST:[%8ld][%02ld], lSePos:[%4ld], lData[%8ld], Node[%8ld], "
"Next[%8ld], Last[%8ld]\n" , (void *)pstList - pstRun->m_pvAddr, i,
pstList->m_lPos, pstList->m_lData, pstList->m_lNode,
pstList->m_lNext, pstList->m_lLast);
}
}
}
if(eType & DEBUG_IDEX_TREE)
{
fprintf(stdout, "\n=================================TREE DEUBG========================"
"==============Valid(%ld)=============\n", lGetTblValid(t));
vDebugTree(pstRun->m_pvAddr, pGetNode(pstRun->m_pvAddr, lGetIdxRoot(t)));
}
if(eType & DEBUG_IDEX_DATA)
{
fprintf(stdout, "\n===================================UNIQUE_INDEX====================="
"==============lValid(%ld)=========================\n", lGetTblValid(t));
for(i = 0; i < lGetTblRow(t); i ++)
{
pstTruck = (void *)(pstRun->m_pvAddr + lGetTblData(t) + i * lGetRowTruck(t));
fprintf(stdout, "SePos[%ld]\n", (void *)pstTruck - pstRun->m_pvAddr);
vPrintHex(pstTruck->m_pvData, lGetRowSize(t), 0);
}
}
vTblDisconnect(pstSavm, pstSavm->tblName);
fprintf(stdout, "=========================================================================="
"===================================\n");
}
/*************************************************************************************************
descriptionget action
parameters:
return:
*************************************************************************************************/
void vGetAction(char *s, long *plAction)
{
int i, nLen;
if(!s) return ;
for(i = 0, nLen = strlen(s); i < nLen; i ++)
{
switch(s[i])
{
case 'h':
*plAction |= DEBUG_HEAD_INFO;
break;
case 'u':
*plAction |= DEBUG_UNIQ_IDEX;
break;
case 'g':
*plAction |= DEBUG_GROP_IDEX;
break;
case 'l':
*plAction |= DEBUG_GROP_LIST;
break;
case 'd':
*plAction |= DEBUG_DATA_LIST;
break;
case 't':
*plAction |= DEBUG_IDEX_TREE;
break;
case 'e':
*plAction |= DEBUG_IDEX_DALL;
break;
case 'a':
*plAction |= DEBUG_IDEX_DATA;
break;
default:
break;
}
}
}
/*************************************************************************************************
descriptionprint func
parameters:
return:
*************************************************************************************************/
void vPrintFunc(char *s)
{
fprintf(stdout, "\nUsage:\t%s -[tpu][hugldtui]\n", s);
fprintf(stdout, "\t-t\t\t--table\n");
fprintf(stdout, "\t-p[hugldta]\t--debug\n");
fprintf(stdout, "\t-u(ui)\t\t--reset lock\n");
fprintf(stdout, "\n");
}
/*************************************************************************************************
descriptiondebug action
parameters:
return:
*************************************************************************************************/
void vDebugAction(TABLE t, int iAction, char *pszApp, char *pszParam)
{
long lRet, lDebug = 0;
SATvm *pstSavm = (SATvm *)pGetSATvm();
if(3 == iAction)
{
if(RC_SUCC != lResetLock((SATvm *)pGetSATvm(), t))
{
fprintf(stderr, "reset the table lock (%d) failed, err:(%d)(%s)\n", t,
pstSavm->m_lErrno, sGetTError(pstSavm->m_lErrno));
return ;
}
}
else if(5 == iAction)
{
vGetAction(pszParam, &lDebug);
vDebugTable(t, lDebug);
}
else
vPrintFunc(pszApp);
return ;
}
/*************************************************************************************************
descriptionmain
parameters:
return:
*************************************************************************************************/
int main(int argc, char *argv[])
{
TABLE t;
char szCom[256];
int iChoose = 0, iAction = 0;
memset(szCom, 0, sizeof(szCom));
while(-1 != (iChoose = getopt(argc, argv, "t:p:u::v?::")))
{
switch(iChoose)
{
case 't':
iAction |= 1;
t = atol(optarg);
break;
case 'u':
if(!optarg)
strcpy(szCom, "u");
else
strcpy(szCom, optarg);
iAction |= 2;
break;
case 'p':
iAction |= 4;
strcpy(szCom, optarg);
break;
case 'v':
case '?':
default:
vPrintFunc(basename(argv[0]));
return RC_FAIL;
}
}
vDebugAction(t, iAction, basename(argv[0]), szCom);
return RC_SUCC;
}
/*************************************************************************************************
code end
*************************************************************************************************/

1099
src/list.c Normal file

File diff suppressed because it is too large Load Diff

44
src/makefile Executable file
View File

@ -0,0 +1,44 @@
INCDIR= -I/usr/include -I$(HOME)/include -I./ -I./include -I../include
LIBDIR= -L$(HOME)/lib -L../lib -lstvm -lreadline -lm -lc -ldl -lpthread
AR=ar
LD=ld
LN=ln
CC=cc -fPIC
CO=-c -g
LDFLAG=-shared -g
OUTLIB=../lib
OUTBIN=../bin
OBJFILE=tree.o sem.o msg.o tcp.o str.o list.o conf.o
TARGET=$(OUTLIB)/libstvm.a
TARDLL=$(OUTLIB)/libstvm.so
TARVER=$(OUTLIB)/libstvm.so.1.2
STVM=$(OUTBIN)/stvm
DETVM=$(OUTBIN)/detvm
all: $(TARGET) $(TARDLL) $(STVM) $(DETVM) clean
$(TARGET): $(OBJFILE)
rm -f $@
$(AR) -cr $@ $(OBJFILE)
$(TARDLL): $(OBJFILE)
$(LD) $(LDFLAG) -o $@ $(OBJFILE)
rm -f $(TARVER)
$(LN) -s $@ $(TARVER)
$(STVM): stvm.o
$(CC) -o $@ $< $(LIBDIR)
$(DETVM): detvm.o
$(CC) -o $@ $< $(LIBDIR)
.SUFFIXES: .c .o
.c.o:
$(CC) $(CO) $*.c $(INCDIR) $(LIBDIR)
fall:
@touch *c
@make all
clean:
rm -f *.o

313
src/msg.c Normal file
View File

@ -0,0 +1,313 @@
/*
* 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"
/************************************************************************************************
ipc msg function
************************************************************************************************/
/*************************************************************************************************
descriptioncreate message queue
parameters:
pstSavm --stvm handle
bCreate --create type
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lCreateQueue(SATvm *pstSavm, bool bCreate)
{
long lQid;
if(bCreate)
{
pstSavm->m_yMey = yGetIPCPath(pstSavm, IPC_MSG);
if(pstSavm->m_yMey <= RC_FAIL)
return RC_FAIL;
lQid = msgget(pstSavm->m_yMey, IPC_CREAT|0600);
}
else
lQid = msgget(IPC_PRIVATE, IPC_CREAT|0600);
if(RC_FAIL >= lQid)
{
switch(errno)
{
case EEXIST:
pstSavm->m_lErrno = MSG_ERR_EXIST;
break;
case EACCES:
pstSavm->m_lErrno = MSG_ERR_ACCES;
break;
case ENOMEM:
pstSavm->m_lErrno = MSG_ERR_NOMEM;
break;
default:
pstSavm->m_lErrno = MSG_ERR_INVAL;
break;
}
return RC_FAIL;
}
return lQid;
}
/*************************************************************************************************
descriptionGet the number of message queues
parameters:
pstSavm --stvm handle
lQid --msg id
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lGetQueueNum(SATvm *pstSavm, long lQid)
{
struct msqid_ds stQueue;
if(msgctl(lQid, IPC_STAT, &stQueue) <= -1)
{
switch(errno)
{
case EFAULT:
pstSavm->m_lErrno = MSG_ERR_FAULT;
break;
case EIDRM:
pstSavm->m_lErrno = MSG_ERR_EIDRM;
break;
default:
pstSavm->m_lErrno = MSG_ERR_INVAL;
break;
}
return RC_FAIL;
}
return stQueue.msg_qnum;
}
/*************************************************************************************************
descriptionGet the maximum queue support byte
parameters:
pstSavm --stvm handle
lQid --msg id
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lQueueMaxByte(SATvm *pstSavm, long lQid)
{
struct msqid_ds stQueue;
if(msgctl(lQid, IPC_STAT, &stQueue) <= -1)
{
switch(errno)
{
case EFAULT:
pstSavm->m_lErrno = MSG_ERR_FAULT;
break;
case EIDRM:
pstSavm->m_lErrno = MSG_ERR_EIDRM;
break;
default:
pstSavm->m_lErrno = MSG_ERR_INVAL;
break;
}
return RC_FAIL;
}
return stQueue.msg_qbytes;
}
/*************************************************************************************************
descriptionGets the final processing time in the queue
parameters:
pstSavm --stvm handle
lQid --msg id
return:
long --success
RC_FAIL --failure
*************************************************************************************************/
long lQueueRcvTime(SATvm *pstSavm, long lQid)
{
struct msqid_ds stQueue;
if(msgctl(lQid, IPC_STAT, &stQueue) <= -1)
{
switch(errno)
{
case EFAULT:
pstSavm->m_lErrno = MSG_ERR_FAULT;
break;
case EIDRM:
pstSavm->m_lErrno = MSG_ERR_EIDRM;
break;
default:
pstSavm->m_lErrno = MSG_ERR_INVAL;
break;
}
return RC_FAIL;
}
// return (long)time(&stQueue.msg_rtime);
return (long)stQueue.msg_rtime > 0 ? (long)stQueue.msg_rtime : (long)stQueue.msg_ctime;
}
/*************************************************************************************************
descriptionread from message queue
parameters:
pstSavm --stvm handle
lQid --msg id
pstVoid --create type
lSize --create type
lMType --msg type
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lEventRead(SATvm *pstSavm, long lQid, void *pstVoid, long lSize, long lMType)
{
if(RC_SUCC > msgrcv(lQid, pstVoid, lSize - sizeof(long), lMType, 0))
{
switch(errno)
{
case E2BIG:
pstSavm->m_lErrno = MSG_ERR_E2BIG;
break;
case EACCES:
pstSavm->m_lErrno = MSG_ERR_ACCES;
break;
case EFAULT:
pstSavm->m_lErrno = MSG_ERR_FAULT;
break;
case EIDRM:
pstSavm->m_lErrno = MSG_ERR_EIDRM;
break;
case EINTR:
pstSavm->m_lErrno = MSG_ERR_EINTR;
break;
default:
pstSavm->m_lErrno = MSG_ERR_INVAL;
break;
}
return RC_FAIL;
}
return RC_SUCC;
}
/*************************************************************************************************
descriptionnon-blocking read from message queue
parameters:
pstSavm --stvm handle
lQid --msg id
pstVoid --create type
lSize --create type
lMType --msg type
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lReadNoWait(SATvm *pstSavm, long lQid, void *psvVoid, long lSize, long lMType)
{
errno = 0;
if(RC_SUCC > msgrcv(lQid, psvVoid, lSize - sizeof(long), lMType, IPC_NOWAIT))
{
switch(errno)
{
case EAGAIN:
case ENOMSG:
return RC_SUCC;
case E2BIG:
pstSavm->m_lErrno = MSG_ERR_E2BIG;
break;
case EACCES:
pstSavm->m_lErrno = MSG_ERR_ACCES;
break;
case EFAULT:
pstSavm->m_lErrno = MSG_ERR_FAULT;
break;
case EIDRM:
pstSavm->m_lErrno = MSG_ERR_EIDRM;
break;
case EINTR:
pstSavm->m_lErrno = MSG_ERR_EINTR;
return RC_FAIL;
default:
pstSavm->m_lErrno = MSG_ERR_INVAL;
break;
}
return RC_FAIL;
}
return RC_SUCC;
}
/*************************************************************************************************
descriptionwrite to message queue
parameters:
pstSavm --stvm handle
lQid --msg id
pstVoid --create type
lSize --create type
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lEventWrite(SATvm *pstSavm, long lQid, void *psvData, long lSize)
{
if(msgsnd(lQid, psvData, lSize - sizeof(long), 0) < RC_SUCC)
{
switch(errno)
{
case EACCES:
pstSavm->m_lErrno = MSG_ERR_ACCES;
break;
case EAGAIN:
pstSavm->m_lErrno = MSG_ERR_SNDEG;
break;
case EFAULT:
pstSavm->m_lErrno = MSG_ERR_FAULT;
break;
case EIDRM:
pstSavm->m_lErrno = MSG_ERR_EIDRM;
break;
case EINTR:
pstSavm->m_lErrno = MSG_ERR_EINTR;
break;
default:
pstSavm->m_lErrno = MSG_ERR_INVAL;
break;
}
return RC_FAIL;
}
return RC_SUCC;
}
/****************************************************************************************
code end
****************************************************************************************/

144
src/sem.c Normal file
View File

@ -0,0 +1,144 @@
/*
* 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"
/****************************************************************************************
senum union
****************************************************************************************/
union semun {
int val;
struct semid_ds *buf;
struct seminfo *__buf;
};
/************************************************************************************************
sems function
************************************************************************************************/
/*************************************************************************************************
descriptioncreate semaphore
parameters:
pstSavm --stvm handle
pstRun --table handle
lSems --the number of semaphores
lValue --The index of the semaphores
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lCreateSems(SATvm *pstSavm, RunTime *pstRun, long lSems, long lValue)
{
long i = 0;
union semun uSem;
if(lSems <= 0)
{
pstSavm->m_lErrno = SEM_CDIT_NULL;
return RC_FAIL;
}
if(RC_FAIL == (pstRun->m_semID = semget(pstSavm->m_ySey, lSems, IPC_CREAT|0600)))
{
switch(errno)
{
case EEXIST:
pstSavm->m_lErrno = SEM_ERR_EXIST;
break;
case EIDRM:
pstSavm->m_lErrno = SEM_ERR_EIDRM;
break;
case EACCES:
pstSavm->m_lErrno = SEM_ERR_ACCES;
break;
case ENOMEM:
pstSavm->m_lErrno = SEM_ERR_NOMEM;
break;
default:
pstSavm->m_lErrno = SEM_ERR_INVAL;
break;
}
return RC_FAIL;
}
for(i = 0, uSem.val = lValue; i < lSems; i ++)
semctl(pstRun->m_semID, i, SETVAL, uSem);
return RC_SUCC;
}
/*************************************************************************************************
descriptioncreate semaphore
parameters:
pstSavm --stvm handle
semID --the idx of semaphores
lSems --the number of semaphores
evp --opereate of P-V
return:
RC_SUCC --success
RC_FAIL --failure
*************************************************************************************************/
long lOperateSems(SATvm *pstSavm, long semID, long lSems, Benum evp)
{
struct sembuf se;
se.sem_num = lSems;
se.sem_op = evp;
se.sem_flg = SEM_UNDO;
if(RC_SUCC != semop(semID, &se, 1))
{
switch(errno)
{
case EINTR:
return RC_SUCC;
case EEXIST:
pstSavm->m_lErrno = SEM_ERR_EXIST;
break;
case EIDRM:
pstSavm->m_lErrno = SEM_ERR_EIDRM;
break;
case EACCES:
pstSavm->m_lErrno = SEM_ERR_ACCES;
break;
case ENOMEM:
pstSavm->m_lErrno = SEM_ERR_NOMEM;
break;
case E2BIG:
case ERANGE:
pstSavm->m_lErrno = SEM_ERR_INVAL;
break;
default:
pstSavm->m_lErrno = SEM_ERR_INVAL;
break;
}
return RC_FAIL;
}
return RC_SUCC;
}
/****************************************************************************************
code end
****************************************************************************************/

480
src/str.c Normal file
View File

@ -0,0 +1,480 @@
/*
* 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 "tstr.h"
/************************************************************************************************
strs function
************************************************************************************************/
/*************************************************************************************************
descriptionuppercase string
parameters:
s --string
return:
s
*************************************************************************************************/
char *supper(char *s)
{
long i, l = strlen(s), fg = 0;
for(i=0; i < l; i++)
s[i] = toupper(s[i]);
return s;
}
/*************************************************************************************************
descriptionlowercas string
parameters:
s --string
return:
s
*************************************************************************************************/
char *slower(char *s)
{
long i, l = strlen(s), fg = 0;
for(i = 0; i < l; i++)
s[i] = tolower(s[i]);
return s;
}
/*************************************************************************************************
descriptiondrop CRLF from string
parameters:
p --string
return:
p
*************************************************************************************************/
char* strimcrlf(char *p)
{
int i = 0, j = 0, m = 0;
char *s = NULL;
if(!p) return p;
if(!strlen(p)) return p;
s = p;
m = strlen(p);
for(i = 0; i < m; i ++)
{
if(p[i] == 10 || p[i] == 13)
continue;
s[j] = p[i];
j ++;
}
s[j] = 0x00;
return s;
}
/*************************************************************************************************
descriptiontrim the left space from string
parameters:
p --string
return:
p
*************************************************************************************************/
char* sltrim(char *p)
{
char *s = p;
long i, k = 0, l;
if(!p || (0 == (l = strlen(p))))
return p;
for(i = 0; i < l; i ++, k ++)
{
if(p[i] != ' ' && '\t' != p[i])
break;
}
if(0 == k) return p;
for(i = 0; i < l - k; i ++)
p[i] = s[i + k];
p[i] = 0x00;
return p;
}
/*************************************************************************************************
descriptiontrim the right space from string
parameters:
p --string
return:
p
*************************************************************************************************/
char* srtrim(char *p)
{
long i, k = 0, l = 0;
if(!p || 0 == (l = strlen(p)))
return p;
for(i = l - 1; i >= 0; i --)
{
if(p[i] == ' ' || '\t' == p[i])
continue;
break;
}
// p[i + 1] = '\0';
memset(p + i + 1, 0, l - i - 1);
return p;
}
/*************************************************************************************************
descriptiontrimall space from string
parameters:
p --string
return:
p
*************************************************************************************************/
char* strimall(char *p)
{
long i, k = 0, l = 0;
char *q = p;
if(!p || !strlen(p))
return p;
l = strlen(p);
for(i = 0; i < l; i ++)
{
if(p[i] == ' ')
continue;
q[k ++] = p[i];
}
memset(q + k, 0, l - k);
p = q;
return q;
}
/*************************************************************************************************
descriptiontrim the left space from field string
parameters:
p --string
return:
p
*************************************************************************************************/
char* strimfield(char *s)
{
register int i, n, m;
BOOL bf = false;
if(!s || 0 == (n = strlen(s)))
return s;
for(i = 0, m = 0; i < n; i ++)
{
if(s[i] == '\"')
bf = !bf;
if(bf) s[m ++] = s[i];
else if(s[i] != ' ' && s[i] != '\t')
s[m ++] = s[i];
}
s[m] = 0x00;
return s;
}
/*************************************************************************************************
descriptioncalcute the number of field string
parameters:
p --string
k --string
return:
p
*************************************************************************************************/
long lfieldnum(char *p, char *k)
{
char *y = p;
BOOL bf = false;
long idx, i, m, n;
if(!p || !k) return 0;
for(i = 0, idx = 0, m = strlen(p), n = strlen(k); i < m; i ++)
{
if(p[i] == '\\')
{
i ++;
continue;
}
if(p[i] == '\"' || p[i] == '\'')
bf = !bf;
if(bf) continue;
if(!memcmp(p + i, k, n))
{
++ idx;
for(i += n; i < m; i ++)
{
if(p[i] != ' ' && p[i] != '\t' && memcmp(p + i, k, n))
break;
}
y = p + i;
i --;
}
}
for(i = y - p ; i < m; i ++)
{
if(y[i] != ' ' && y[i] != '\t')
return ++ idx;
}
return idx;
}
/*************************************************************************************************
descriptionis or not gbk-Character set
parameters:
s --string
return:
1 --yes
0 --no
*************************************************************************************************/
int bIsgbk(const char *s)
{
if((ushar)s[0] > 0x80 && (ushar)s[1] >= 0x40)
return 1;
return 0;
}
/*************************************************************************************************
descriptionGets the field value of the specified character position
parameters:
p --string
s --characters
id --position
return:
char --values
*************************************************************************************************/
char* sfieldvalue(char *p, char *k, int id)
{
char *y = p;
BOOL bf = false;
long idx, i = 0, m = 0, n = 0;
static char szOut[1024];
memset(szOut, 0, sizeof(szOut));
if(!p || !k || id <= 0) return szOut;
for(i = 0, idx = 0, m = strlen(p), n = strlen(k); i < m; i ++)
{
if(p[i] == '\\')
{
i ++;
continue;
}
if(p[i] == '\"' || p[i] == '\'')
{
bf = !bf;
continue;
}
if(bf) continue;
if(!memcmp(p + i, k, n))
{
if(++idx == id)
break;
for(i += n; i < m; i ++)
{
if(p[i] != ' ' && p[i] != '\t' && memcmp(p + i, k, n))
break;
}
y = p + i;
i --;
}
}
if(idx + 1 < id) return szOut;
memcpy(szOut, y, i - (long )(y - p));
return szOut;
}
/*************************************************************************************************
descriptionGets the number of specified characters
parameters:
p --string
s --characters
return:
long --number
*************************************************************************************************/
long lgetstrnum(char *p, char *s)
{
char *q = p;
long i, m, n, k;
if(!p || 0 == (n = strlen(s)) || 0 == (m = strlen(p)))
return 0;
for(i = 0, k = 0; i < m; i += n, q += n)
{
if(0 == memcmp(q, s, n))
k ++;
}
return k;
}
/*************************************************************************************************
descriptionGets the value of the specified character position
parameters:
p --string
s --characters
id --position
return:
char --values
*************************************************************************************************/
char* sgetvalue(char *p, char *s, int id)
{
char *y = p;
long i, m, n, idx = 0;
static char szOut[1024];
memset(szOut, 0, sizeof(szOut));
if(!p || !s || id <= 0 || (n = strlen(s)) <= 0)
return szOut;
for(i = 0, idx = 0, m = strlen(p); i < m; i ++)
{
if(!memcmp(p + i, s, n))
{
if(i > 0 && bIsgbk(p + i - 1))
continue;
if(++ idx == id)
break;
y = p + i + n;
}
}
if(idx + 1 < id) return szOut;
memcpy(szOut, y, i - (int)(y - p));
return szOut;
}
/*************************************************************************************************
descriptionCharacters to replace
parameters:
p --The original string
o --key characters
d --target character
return:
char --values
*************************************************************************************************/
char* sfieldreplace(char *p, char o, char d)
{
char *s = p;
bool bf = false;
long idx, i, j = 0, m = 0;
if(!p) return p;
for(i = 0, idx = 0, m = strlen(p); i < m; i ++)
{
if(p[i] == '\"' || p[i] == '\'')
bf = !bf;
if(bf)
{
s[j ++] = p[i];
continue;
}
if(o == p[i])
{
if(i > 0 && bIsgbk(p + i - 1))
continue;
p[i] = d;
}
if((j == 0 && ' ' == p[i]) || (j > 0 && ' ' == s[j - 1] && p[i] == ' '))
continue;
s[j ++] = p[i];
}
s[j] = 0x00;
return s;
}
/*************************************************************************************************
descriptionGet the value between o-d
parameters:
p --The original string
o --key characters
d --target character
return:
char* --values
*************************************************************************************************/
char* strimabout(char *s, char *o, char *d)
{
long l = 0;
char *p = NULL, *q = NULL, *m = NULL;
if(!s || !o || !d) return NULL;
if(0 == (l = strlen(s))) return NULL;
if(NULL == (p = strstr(s, o))) return NULL;
for(l; l > 0; l --)
{
if(NULL != (q = strstr(s + l, d)))
break;
}
if(!q) return NULL;
l = strlen(o);
if((p - q) >= 0) return NULL;
if(((p - q + l) == 0))
{
s[0] = 0x00;
return NULL;
}
for(m = s, p += l; p != q; *p ++, *m ++)
*m = *p;
*m = 0x00;
return s;
}
/****************************************************************************************
code end
****************************************************************************************/

4139
src/stvm.c Normal file

File diff suppressed because it is too large Load Diff

4874
src/tcp.c Normal file

File diff suppressed because it is too large Load Diff

9511
src/tree.c Normal file

File diff suppressed because it is too large Load Diff

27
stvm.conf Normal file
View File

@ -0,0 +1,27 @@
*GLOBLE
MACHINE="TVM"
MAXTABLE=255
MAXFILED=3000
MAXDOMAIN=1024
MAXSEQUE=1024
#SERVER_EXEC=4
SERVER_EXEC=1
DEPLOY=cluster
#DEPLOY=local
SERVER_PORT=5050
LOGNAME="/home/stvm/log/stvm.log"
*LOCAL_RESOURCE
TABLE=15 PERMIT=15
*REMOTE_DOMAIN
GROUP=1 DOMAINID="DBS" WSADDR="192.168.5.20:5010" TIMETOUT=2 MAXTRY=3 KEEPALIVE=30
GROUP=2 DOMAINID="CTS" WSADDR="192.168.5.20:5011" TIMETOUT=2 MAXTRY=3 KEEPALIVE=30
*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"

16
tbl_user_info.def Normal file
View File

@ -0,0 +1,16 @@
set TABLE=20
set TABLESPACE=10000
create table TBL_USER_INFO
(
acct_id long,
user_no char(21),
user_type char[2],
user_nm char[81],
user_addr char[161],
user_phone char[31]
);
-- Create indexes
create unique index (user_no, user_type);
create index (acct_id);