Merge pull request #12015 from taosdata/feature/vnode_refact1
refactor: vnode
This commit is contained in:
commit
4e918d0f61
|
@ -1524,6 +1524,7 @@ typedef struct {
|
|||
int32_t tEncodeSRSmaParam(SCoder* pCoder, const SRSmaParam* pRSmaParam);
|
||||
int32_t tDecodeSRSmaParam(SCoder* pCoder, SRSmaParam* pRSmaParam);
|
||||
|
||||
// TDMT_VND_CREATE_STB ==============
|
||||
typedef struct SVCreateStbReq {
|
||||
const char* name;
|
||||
tb_uid_t suid;
|
||||
|
@ -1536,17 +1537,14 @@ typedef struct SVCreateStbReq {
|
|||
int tEncodeSVCreateStbReq(SCoder* pCoder, const SVCreateStbReq* pReq);
|
||||
int tDecodeSVCreateStbReq(SCoder* pCoder, SVCreateStbReq* pReq);
|
||||
|
||||
// TDMT_VND_DROP_STB ==============
|
||||
typedef struct SVDropStbReq {
|
||||
// data
|
||||
#ifdef WINDOWS
|
||||
size_t avoidCompilationErrors;
|
||||
#endif
|
||||
|
||||
const char* name;
|
||||
tb_uid_t suid;
|
||||
} SVDropStbReq;
|
||||
|
||||
typedef struct SVCreateStbRsp {
|
||||
int code;
|
||||
} SVCreateStbRsp;
|
||||
int32_t tEncodeSVDropStbReq(SCoder* pCoder, const SVDropStbReq* pReq);
|
||||
int32_t tDecodeSVDropStbReq(SCoder* pCoder, SVDropStbReq* pReq);
|
||||
|
||||
typedef struct SVCreateTbReq {
|
||||
tb_uid_t uid;
|
||||
|
@ -1603,19 +1601,37 @@ int tDecodeSVCreateTbBatchRsp(SCoder* pCoder, SVCreateTbBatchRsp* pRsp);
|
|||
int32_t tSerializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
|
||||
int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatchRsp* pRsp);
|
||||
|
||||
// TDMT_VND_DROP_TABLE =================
|
||||
typedef struct {
|
||||
int64_t ver;
|
||||
char* name;
|
||||
uint8_t type;
|
||||
tb_uid_t suid;
|
||||
const char* name;
|
||||
int8_t igNotExists;
|
||||
} SVDropTbReq;
|
||||
|
||||
typedef struct {
|
||||
int tmp; // TODO: to avoid compile error
|
||||
int32_t code;
|
||||
} SVDropTbRsp;
|
||||
|
||||
int32_t tSerializeSVDropTbReq(void** buf, SVDropTbReq* pReq);
|
||||
void* tDeserializeSVDropTbReq(void* buf, SVDropTbReq* pReq);
|
||||
typedef struct {
|
||||
int32_t nReqs;
|
||||
union {
|
||||
SVDropTbReq* pReqs;
|
||||
SArray* pArray;
|
||||
};
|
||||
} SVDropTbBatchReq;
|
||||
|
||||
int32_t tEncodeSVDropTbBatchReq(SCoder* pCoder, const SVDropTbBatchReq* pReq);
|
||||
int32_t tDecodeSVDropTbBatchReq(SCoder* pCoder, SVDropTbBatchReq* pReq);
|
||||
|
||||
typedef struct {
|
||||
int32_t nRsps;
|
||||
union {
|
||||
SVDropTbRsp* pRsps;
|
||||
SArray* pArray;
|
||||
};
|
||||
} SVDropTbBatchRsp;
|
||||
|
||||
int32_t tEncodeSVDropTbBatchRsp(SCoder* pCoder, const SVDropTbBatchRsp* pRsp);
|
||||
int32_t tDecodeSVDropTbBatchRsp(SCoder* pCoder, SVDropTbBatchRsp* pRsp);
|
||||
|
||||
typedef struct {
|
||||
SMsgHead head;
|
||||
|
|
|
@ -170,9 +170,9 @@ enum {
|
|||
TD_DEF_MSG_TYPE(TDMT_VND_UPDATE_TAG_VAL, "vnode-update-tag-val", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TABLE_META, "vnode-table-meta", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_TABLES_META, "vnode-tables-meta", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateTbReq, SVCreateTbRsp)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_CREATE_STB, "vnode-create-stb", SVCreateStbReq, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_ALTER_STB, "vnode-alter-stb", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_DROP_STB, "vnode-drop-stb", SVDropStbReq, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONSUME, "vnode-mq-consume", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_QUERY, "vnode-mq-query", NULL, NULL)
|
||||
TD_DEF_MSG_TYPE(TDMT_VND_MQ_CONNECT, "vnode-mq-connect", NULL, NULL)
|
||||
|
|
|
@ -318,6 +318,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_VND_TB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0515)
|
||||
#define TSDB_CODE_VND_SMA_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0516)
|
||||
#define TSDB_CODE_VND_HASH_MISMATCH TAOS_DEF_ERROR_CODE(0, 0x0517)
|
||||
#define TSDB_CODE_VND_TABLE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0518)
|
||||
|
||||
// tsdb
|
||||
#define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600)
|
||||
|
@ -616,6 +617,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_OFFSET_LESS_ZERO TAOS_DEF_ERROR_CODE(0, 0x2637)
|
||||
#define TSDB_CODE_PAR_SLIMIT_LEAK_PARTITION_BY TAOS_DEF_ERROR_CODE(0, 0x2638)
|
||||
#define TSDB_CODE_PAR_INVALID_TOPIC_QUERY TAOS_DEF_ERROR_CODE(0, 0x2639)
|
||||
#define TSDB_CODE_PAR_INVALID_DROP_STABLE TAOS_DEF_ERROR_CODE(0, 0x263A)
|
||||
|
||||
//planner
|
||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||
|
|
|
@ -79,17 +79,6 @@ typedef struct {
|
|||
#define TD_CODER_CURRENT(CODER) ((CODER)->data + (CODER)->pos)
|
||||
#define TD_CODER_MOVE_POS(CODER, MOVE) ((CODER)->pos += (MOVE))
|
||||
#define TD_CODER_CHECK_CAPACITY_FAILED(CODER, EXPSIZE) (((CODER)->size - (CODER)->pos) < (EXPSIZE))
|
||||
// #define TCODER_MALLOC(PCODER, SIZE) \
|
||||
// ({ \
|
||||
// void* ptr = NULL; \
|
||||
// SCoderMem* pMem = (SCoderMem*)taosMemoryMalloc(sizeof(*pMem) + (SIZE)); \
|
||||
// if (pMem) { \
|
||||
// pMem->next = (PCODER)->mList; \
|
||||
// (PCODER)->mList = pMem; \
|
||||
// ptr = (void*)&pMem[1]; \
|
||||
// } \
|
||||
// ptr; \
|
||||
// })
|
||||
static FORCE_INLINE void* tCoderMalloc(SCoder* pCoder, int32_t size) {
|
||||
void* ptr = NULL;
|
||||
SCoderMem* pMem = (SCoderMem*)taosMemoryMalloc(sizeof(SCoderMem*) + size);
|
||||
|
@ -104,6 +93,7 @@ static FORCE_INLINE void* tCoderMalloc(SCoder* pCoder, int32_t size) {
|
|||
#define tEncodeSize(E, S, SIZE, RET) \
|
||||
do { \
|
||||
SCoder coder = {0}; \
|
||||
RET = 0; \
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, NULL, 0, TD_ENCODER); \
|
||||
if ((E)(&coder, S) == 0) { \
|
||||
SIZE = coder.pos; \
|
||||
|
|
|
@ -52,54 +52,6 @@ typedef struct SSkipListNode {
|
|||
#define SL_NODE_GET_FORWARD_POINTER(n, l) (n)->forwards[(l)]
|
||||
#define SL_NODE_GET_BACKWARD_POINTER(n, l) (n)->forwards[(n)->level + (l)]
|
||||
|
||||
/*
|
||||
* @version 0.3
|
||||
* @date 2017/11/12
|
||||
* the simple version of skip list.
|
||||
*
|
||||
* for multi-thread safe purpose, we employ TdThreadRwlock to guarantee to generate
|
||||
* deterministic result. Later, we will remove the lock in SkipList to further enhance the performance.
|
||||
* In this case, one should use the concurrent skip list (by using michael-scott algorithm) instead of
|
||||
* this simple version in a multi-thread environment, to achieve higher performance of read/write operations.
|
||||
*
|
||||
* Note: Duplicated primary key situation.
|
||||
* In case of duplicated primary key, two ways can be employed to handle this situation:
|
||||
* 1. add as normal insertion without special process.
|
||||
* 2. add an overflow pointer at each list node, all nodes with the same key will be added in the overflow pointer.
|
||||
* In this case, the total steps of each search will be reduced significantly.
|
||||
* Currently, we implement the skip list in a line with the first means, maybe refactor it soon.
|
||||
*
|
||||
* Memory consumption: the memory alignment causes many memory wasted. So, employ a memory
|
||||
* pool will significantly reduce the total memory consumption, as well as the calloc/malloc operation costs.
|
||||
*
|
||||
*/
|
||||
|
||||
// state struct, record following information:
|
||||
// number of links in each level.
|
||||
// avg search steps, for latest 1000 queries
|
||||
// avg search rsp time, for latest 1000 queries
|
||||
// total memory size
|
||||
typedef struct tSkipListState {
|
||||
// in bytes, sizeof(SSkipList)+sizeof(SSkipListNode)*SSkipList->nSize
|
||||
uint64_t nTotalMemSize;
|
||||
uint64_t nLevelNodeCnt[MAX_SKIP_LIST_LEVEL];
|
||||
uint64_t queryCount; // total query count
|
||||
|
||||
/*
|
||||
* only record latest 1000 queries
|
||||
* when the value==1000, = 0,
|
||||
* nTotalStepsForQueries = 0,
|
||||
* nTotalElapsedTimeForQueries = 0
|
||||
*/
|
||||
uint64_t nRecQueries;
|
||||
uint16_t nTotalStepsForQueries;
|
||||
uint64_t nTotalElapsedTimeForQueries;
|
||||
|
||||
uint16_t nInsertObjs;
|
||||
uint16_t nTotalStepsForInsert;
|
||||
uint64_t nTotalElapsedTimeForInsert;
|
||||
} tSkipListState;
|
||||
|
||||
typedef enum { SSkipListPutSuccess = 0, SSkipListPutEarlyStop = 1, SSkipListPutSkipOne = 2 } SSkipListPutStatus;
|
||||
|
||||
typedef struct SSkipList {
|
||||
|
@ -115,9 +67,6 @@ typedef struct SSkipList {
|
|||
uint32_t size;
|
||||
SSkipListNode *pHead; // point to the first element
|
||||
SSkipListNode *pTail; // point to the last element
|
||||
#if SKIP_LIST_RECORD_PERFORMANCE
|
||||
tSkipListState state; // skiplist state
|
||||
#endif
|
||||
tGenericSavedFunc *insertHandleFn;
|
||||
} SSkipList;
|
||||
|
||||
|
|
|
@ -490,21 +490,6 @@ int32_t tDeserializeSClientHbBatchRsp(void *buf, int32_t bufLen, SClientHbBatchR
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tSerializeSVDropTbReq(void **buf, SVDropTbReq *pReq) {
|
||||
int32_t tlen = 0;
|
||||
tlen += taosEncodeFixedI64(buf, pReq->ver);
|
||||
tlen += taosEncodeString(buf, pReq->name);
|
||||
tlen += taosEncodeFixedU8(buf, pReq->type);
|
||||
return tlen;
|
||||
}
|
||||
|
||||
void *tDeserializeSVDropTbReq(void *buf, SVDropTbReq *pReq) {
|
||||
buf = taosDecodeFixedI64(buf, &pReq->ver);
|
||||
buf = taosDecodeString(buf, &pReq->name);
|
||||
buf = taosDecodeFixedU8(buf, &pReq->type);
|
||||
return buf;
|
||||
}
|
||||
|
||||
int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq) {
|
||||
SCoder encoder = {0};
|
||||
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
|
||||
|
@ -3811,3 +3796,119 @@ int tDecodeSVCreateTbRsp(SCoder *pCoder, SVCreateTbRsp *pRsp) {
|
|||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TDMT_VND_DROP_TABLE =================
|
||||
static int32_t tEncodeSVDropTbReq(SCoder *pCoder, const SVDropTbReq *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeCStr(pCoder, pReq->name) < 0) return -1;
|
||||
if (tEncodeI8(pCoder, pReq->igNotExists) < 0) return -1;
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tDecodeSVDropTbReq(SCoder *pCoder, SVDropTbReq *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1;
|
||||
if (tDecodeI8(pCoder, &pReq->igNotExists) < 0) return -1;
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tEncodeSVDropTbRsp(SCoder *pCoder, const SVDropTbRsp *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI32(pCoder, pReq->code) < 0) return -1;
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tDecodeSVDropTbRsp(SCoder *pCoder, SVDropTbRsp *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI32(pCoder, &pReq->code) < 0) return -1;
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVDropTbBatchReq(SCoder *pCoder, const SVDropTbBatchReq *pReq) {
|
||||
int32_t nReqs = taosArrayGetSize(pReq->pArray);
|
||||
SVDropTbReq *pDropTbReq;
|
||||
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI32v(pCoder, nReqs) < 0) return -1;
|
||||
for (int iReq = 0; iReq < nReqs; iReq++) {
|
||||
pDropTbReq = (SVDropTbReq *)taosArrayGet(pReq->pArray, iReq);
|
||||
if (tEncodeSVDropTbReq(pCoder, pDropTbReq) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVDropTbBatchReq(SCoder *pCoder, SVDropTbBatchReq *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI32v(pCoder, &pReq->nReqs) < 0) return -1;
|
||||
pReq->pReqs = (SVDropTbReq *)tCoderMalloc(pCoder, sizeof(SVDropTbReq) * pReq->nReqs);
|
||||
if (pReq->pReqs == NULL) return -1;
|
||||
for (int iReq = 0; iReq < pReq->nReqs; iReq++) {
|
||||
if (tDecodeSVDropTbReq(pCoder, pReq->pReqs + iReq) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVDropTbBatchRsp(SCoder *pCoder, const SVDropTbBatchRsp *pRsp) {
|
||||
int32_t nRsps = taosArrayGetSize(pRsp->pArray);
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI32v(pCoder, nRsps) < 0) return -1;
|
||||
for (int iRsp = 0; iRsp < nRsps; iRsp++) {
|
||||
if (tEncodeSVDropTbRsp(pCoder, (SVDropTbRsp *)taosArrayGet(pRsp->pArray, iRsp)) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVDropTbBatchRsp(SCoder *pCoder, SVDropTbBatchRsp *pRsp) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI32v(pCoder, &pRsp->nRsps) < 0) return -1;
|
||||
pRsp->pRsps = (SVDropTbRsp *)tCoderMalloc(pCoder, sizeof(SVDropTbRsp) * pRsp->nRsps);
|
||||
if (pRsp->pRsps == NULL) return -1;
|
||||
for (int iRsp = 0; iRsp < pRsp->nRsps; iRsp++) {
|
||||
if (tDecodeSVDropTbRsp(pCoder, pRsp->pRsps + iRsp) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVDropStbReq(SCoder *pCoder, const SVDropStbReq *pReq) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeCStr(pCoder, pReq->name) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pReq->suid) < 0) return -1;
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVDropStbReq(SCoder *pCoder, SVDropStbReq *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeCStr(pCoder, &pReq->name) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pReq->suid) < 0) return -1;
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -429,16 +429,22 @@ static void *mndBuildVCreateStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pSt
|
|||
|
||||
static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb, int32_t *pContLen) {
|
||||
SName name = {0};
|
||||
SVDropStbReq req = {0};
|
||||
int32_t contLen = 0;
|
||||
int32_t ret = 0;
|
||||
SMsgHead *pHead = NULL;
|
||||
SCoder coder = {0};
|
||||
|
||||
tNameFromString(&name, pStb->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
|
||||
SVDropTbReq req = {0};
|
||||
req.ver = 0;
|
||||
req.name = (char *)tNameGetTableName(&name);
|
||||
req.type = TD_SUPER_TABLE;
|
||||
req.suid = pStb->uid;
|
||||
|
||||
int32_t contLen = tSerializeSVDropTbReq(NULL, &req) + sizeof(SMsgHead);
|
||||
SMsgHead *pHead = taosMemoryMalloc(contLen);
|
||||
tEncodeSize(tEncodeSVDropStbReq, &req, contLen, ret);
|
||||
if (ret < 0) return NULL;
|
||||
|
||||
contLen += sizeof(SMsgHead);
|
||||
pHead = taosMemoryMalloc(contLen);
|
||||
if (pHead == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
|
@ -448,7 +454,10 @@ static void *mndBuildVDropStbReq(SMnode *pMnode, SVgObj *pVgroup, SStbObj *pStb,
|
|||
pHead->vgId = htonl(pVgroup->vgId);
|
||||
|
||||
void *pBuf = POINTER_SHIFT(pHead, sizeof(SMsgHead));
|
||||
tSerializeSVDropTbReq(&pBuf, &req);
|
||||
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pBuf, contLen - sizeof(SMsgHead), TD_ENCODER);
|
||||
tEncodeSVDropStbReq(&coder, &req);
|
||||
tCoderClear(&coder);
|
||||
|
||||
*pContLen = contLen;
|
||||
return pHead;
|
||||
|
|
|
@ -8,7 +8,6 @@ target_sources(
|
|||
"src/vnd/vnodeBufPool.c"
|
||||
"src/vnd/vnodeCfg.c"
|
||||
"src/vnd/vnodeCommit.c"
|
||||
"src/vnd/vnodeInt.c"
|
||||
"src/vnd/vnodeQuery.c"
|
||||
"src/vnd/vnodeStateMgr.c"
|
||||
"src/vnd/vnodeModule.c"
|
||||
|
@ -33,7 +32,6 @@ target_sources(
|
|||
"src/tsdb/tsdbMemTable.c"
|
||||
"src/tsdb/tsdbRead.c"
|
||||
"src/tsdb/tsdbReadImpl.c"
|
||||
"src/tsdb/tsdbScan.c"
|
||||
"src/tsdb/tsdbSma.c"
|
||||
"src/tsdb/tsdbWrite.c"
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "tmsg.h"
|
||||
#include "trow.h"
|
||||
|
||||
#include "tdbInt.h"
|
||||
#include "tdb.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -57,9 +57,6 @@ int vnodeProcessCMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
|||
int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg);
|
||||
int vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo);
|
||||
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg);
|
||||
int32_t vnodeCompact(SVnode *pVnode);
|
||||
int32_t vnodeSync(SVnode *pVnode);
|
||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad);
|
||||
int vnodeValidateTableHash(SVnode *pVnode, char *tableFName);
|
||||
|
||||
|
|
|
@ -43,7 +43,6 @@ int metaEncodeEntry(SCoder* pCoder, const SMetaEntry* pME);
|
|||
int metaDecodeEntry(SCoder* pCoder, SMetaEntry* pME);
|
||||
|
||||
// metaTable ==================
|
||||
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq);
|
||||
|
||||
// metaQuery ==================
|
||||
int metaGetTableEntryByVersion(SMetaReader* pReader, int64_t version, tb_uid_t uid);
|
||||
|
|
|
@ -73,7 +73,6 @@ struct STsdb {
|
|||
SVnode *pVnode;
|
||||
bool repoLocked;
|
||||
TdThreadMutex mutex;
|
||||
STsdbCfg config;
|
||||
STsdbMemTable *mem;
|
||||
STsdbMemTable *imem;
|
||||
SRtn rtn;
|
||||
|
@ -185,7 +184,7 @@ struct STsdbFS {
|
|||
};
|
||||
|
||||
#define REPO_ID(r) TD_VID((r)->pVnode)
|
||||
#define REPO_CFG(r) (&(r)->config)
|
||||
#define REPO_CFG(r) (&(r)->pVnode->config.tsdbCfg)
|
||||
#define REPO_FS(r) ((r)->fs)
|
||||
#define REPO_META(r) ((r)->pVnode->pMeta)
|
||||
#define REPO_TFS(r) ((r)->pVnode->pTfs)
|
||||
|
@ -534,23 +533,6 @@ static FORCE_INLINE int tsdbGetFidLevel(int fid, SRtn *pRtn) {
|
|||
}
|
||||
}
|
||||
|
||||
// tsdbDBDef
|
||||
// typedef struct SDBFile SDBFile;
|
||||
// typedef DB_ENV* TDBEnv;
|
||||
|
||||
// struct SDBFile {
|
||||
// int32_t fid;
|
||||
// DB* pDB;
|
||||
// char* path;
|
||||
// };
|
||||
|
||||
// int32_t tsdbOpenDBF(TDBEnv pEnv, SDBFile* pDBF);
|
||||
// void tsdbCloseDBF(SDBFile* pDBF);
|
||||
// int32_t tsdbOpenBDBEnv(DB_ENV** ppEnv, const char* path);
|
||||
// void tsdbCloseBDBEnv(DB_ENV* pEnv);
|
||||
// int32_t tsdbSaveSmaToDB(SDBFile* pDBF, void* key, uint32_t keySize, void* data, uint32_t dataSize);
|
||||
// void* tsdbGetSmaDataByKey(SDBFile* pDBF, void* key, uint32_t keySize, uint32_t* valueSize);
|
||||
|
||||
// tsdbFile
|
||||
#define TSDB_FILE_HEAD_SIZE 512
|
||||
#define TSDB_FILE_DELIMITER 0xF00AFA0F
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "tcompare.h"
|
||||
#include "tcompression.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tdbInt.h"
|
||||
#include "tdb.h"
|
||||
#include "tencode.h"
|
||||
#include "tfs.h"
|
||||
#include "tglobal.h"
|
||||
|
@ -72,6 +72,7 @@ int metaClose(SMeta* pMeta);
|
|||
int metaBegin(SMeta* pMeta);
|
||||
int metaCommit(SMeta* pMeta);
|
||||
int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
|
||||
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq);
|
||||
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq);
|
||||
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline);
|
||||
STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver);
|
||||
|
|
|
@ -23,7 +23,7 @@ void metaReaderInit(SMetaReader *pReader, SMeta *pMeta, int32_t flags) {
|
|||
|
||||
void metaReaderClear(SMetaReader *pReader) {
|
||||
tCoderClear(&pReader->coder);
|
||||
TDB_FREE(pReader->pBuf);
|
||||
tdbFree(pReader->pBuf);
|
||||
}
|
||||
|
||||
int metaGetTableEntryByVersion(SMetaReader *pReader, int64_t version, tb_uid_t uid) {
|
||||
|
@ -96,15 +96,17 @@ SMTbCursor *metaOpenTbCursor(SMeta *pMeta) {
|
|||
|
||||
metaReaderInit(&pTbCur->mr, pMeta, 0);
|
||||
|
||||
tdbDbcOpen(pMeta->pUidIdx, &pTbCur->pDbc);
|
||||
tdbDbcOpen(pMeta->pUidIdx, &pTbCur->pDbc, NULL);
|
||||
|
||||
tdbDbcMoveToFirst(pTbCur->pDbc);
|
||||
|
||||
return pTbCur;
|
||||
}
|
||||
|
||||
void metaCloseTbCursor(SMTbCursor *pTbCur) {
|
||||
if (pTbCur) {
|
||||
TDB_FREE(pTbCur->pKey);
|
||||
TDB_FREE(pTbCur->pVal);
|
||||
tdbFree(pTbCur->pKey);
|
||||
tdbFree(pTbCur->pVal);
|
||||
metaReaderClear(&pTbCur->mr);
|
||||
if (pTbCur->pDbc) {
|
||||
tdbDbcClose(pTbCur->pDbc);
|
||||
|
@ -119,7 +121,7 @@ int metaTbCursorNext(SMTbCursor *pTbCur) {
|
|||
STbCfg tbCfg;
|
||||
|
||||
for (;;) {
|
||||
ret = tdbDbNext(pTbCur->pDbc, &pTbCur->pKey, &pTbCur->kLen, &pTbCur->pVal, &pTbCur->vLen);
|
||||
ret = tdbDbcNext(pTbCur->pDbc, &pTbCur->pKey, &pTbCur->kLen, &pTbCur->pVal, &pTbCur->vLen);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -169,7 +171,7 @@ SSchemaWrapper *metaGetTableSchema(SMeta *pMeta, tb_uid_t uid, int32_t sver, boo
|
|||
|
||||
pSW->pSchema = pSchema;
|
||||
|
||||
TDB_FREE(pVal);
|
||||
tdbFree(pVal);
|
||||
|
||||
return pSW;
|
||||
}
|
||||
|
@ -185,7 +187,9 @@ struct SMCtbCursor {
|
|||
|
||||
SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) {
|
||||
SMCtbCursor *pCtbCur = NULL;
|
||||
SCtbIdxKey ctbIdxKey;
|
||||
int ret;
|
||||
int c;
|
||||
|
||||
pCtbCur = (SMCtbCursor *)taosMemoryCalloc(1, sizeof(*pCtbCur));
|
||||
if (pCtbCur == NULL) {
|
||||
|
@ -193,12 +197,20 @@ SMCtbCursor *metaOpenCtbCursor(SMeta *pMeta, tb_uid_t uid) {
|
|||
}
|
||||
|
||||
pCtbCur->suid = uid;
|
||||
ret = tdbDbcOpen(pMeta->pCtbIdx, &pCtbCur->pCur);
|
||||
ret = tdbDbcOpen(pMeta->pCtbIdx, &pCtbCur->pCur, NULL);
|
||||
if (ret < 0) {
|
||||
taosMemoryFree(pCtbCur);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// move to the suid
|
||||
ctbIdxKey.suid = uid;
|
||||
ctbIdxKey.uid = INT64_MIN;
|
||||
tdbDbcMoveTo(pCtbCur->pCur, &ctbIdxKey, sizeof(ctbIdxKey), &c);
|
||||
if (c > 0) {
|
||||
tdbDbcMoveToNext(pCtbCur->pCur);
|
||||
}
|
||||
|
||||
return pCtbCur;
|
||||
}
|
||||
|
||||
|
@ -207,8 +219,8 @@ void metaCloseCtbCurosr(SMCtbCursor *pCtbCur) {
|
|||
if (pCtbCur->pCur) {
|
||||
tdbDbcClose(pCtbCur->pCur);
|
||||
|
||||
TDB_FREE(pCtbCur->pKey);
|
||||
TDB_FREE(pCtbCur->pVal);
|
||||
tdbFree(pCtbCur->pKey);
|
||||
tdbFree(pCtbCur->pVal);
|
||||
}
|
||||
|
||||
taosMemoryFree(pCtbCur);
|
||||
|
@ -219,12 +231,15 @@ tb_uid_t metaCtbCursorNext(SMCtbCursor *pCtbCur) {
|
|||
int ret;
|
||||
SCtbIdxKey *pCtbIdxKey;
|
||||
|
||||
ret = tdbDbNext(pCtbCur->pCur, &pCtbCur->pKey, &pCtbCur->kLen, &pCtbCur->pVal, &pCtbCur->vLen);
|
||||
ret = tdbDbcNext(pCtbCur->pCur, &pCtbCur->pKey, &pCtbCur->kLen, &pCtbCur->pVal, &pCtbCur->vLen);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
pCtbIdxKey = pCtbCur->pKey;
|
||||
if (pCtbIdxKey->suid > pCtbCur->suid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return pCtbIdxKey->uid;
|
||||
}
|
||||
|
@ -283,7 +298,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
|||
|
||||
while (true) {
|
||||
// TODO: lock during iterate?
|
||||
if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) {
|
||||
if (tdbDbcNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) {
|
||||
pSmaIdxKey = pCur->pKey;
|
||||
ASSERT(pSmaIdxKey != NULL);
|
||||
|
||||
|
@ -297,7 +312,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
|||
++pSW->number;
|
||||
STSma *tptr = (STSma *)taosMemoryRealloc(pSW->tSma, pSW->number * sizeof(STSma));
|
||||
if (tptr == NULL) {
|
||||
TDB_FREE(pSmaVal);
|
||||
tdbFree(pSmaVal);
|
||||
metaCloseSmaCursor(pCur);
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
taosMemoryFreeClear(pSW);
|
||||
|
@ -306,13 +321,13 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
|||
pSW->tSma = tptr;
|
||||
pBuf = pSmaVal;
|
||||
if (tDecodeTSma(pBuf, pSW->tSma + pSW->number - 1) == NULL) {
|
||||
TDB_FREE(pSmaVal);
|
||||
tdbFree(pSmaVal);
|
||||
metaCloseSmaCursor(pCur);
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
taosMemoryFreeClear(pSW);
|
||||
return NULL;
|
||||
}
|
||||
TDB_FREE(pSmaVal);
|
||||
tdbFree(pSmaVal);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -354,7 +369,7 @@ SArray *metaGetSmaTbUids(SMeta *pMeta, bool isDup) {
|
|||
tb_uid_t uid = 0;
|
||||
while (true) {
|
||||
// TODO: lock during iterate?
|
||||
if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) {
|
||||
if (tdbDbcNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) {
|
||||
ASSERT(pSmaIdxKey != NULL);
|
||||
pSmaIdxKey = pCur->pKey;
|
||||
|
||||
|
@ -425,11 +440,11 @@ void *metaGetSmaInfoByIndex(SMeta *pMeta, int64_t indexUid, bool isDecode) {
|
|||
if (tDecodeTSma(pBuf, pCfg) == NULL) {
|
||||
tdDestroyTSma(pCfg);
|
||||
taosMemoryFree(pCfg);
|
||||
TDB_FREE(pVal);
|
||||
tdbFree(pVal);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TDB_FREE(pVal);
|
||||
tdbFree(pVal);
|
||||
return pCfg;
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -289,7 +289,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
pVal = pBuf = buf;
|
||||
metaEncodeTbInfo(&pBuf, pTbCfg);
|
||||
vLen = POINTER_DISTANCE(pBuf, buf);
|
||||
ret = tdbDbInsert(pMetaDb->pTbDB, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbPut(pMetaDb->pTbDB, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
pVal = pBuf = buf;
|
||||
metaEncodeSchemaEx(&pBuf, &schemaWrapper);
|
||||
vLen = POINTER_DISTANCE(pBuf, buf);
|
||||
ret = tdbDbInsert(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen, &pMeta->pDB->txn);
|
||||
ret = tdbDbPut(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen, &pMeta->pDB->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
kLen = nameLen + 1 + sizeof(uid);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbInsert(pMetaDb->pNameIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbPut(pMetaDb->pNameIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
kLen = sizeof(uid);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbInsert(pMetaDb->pStbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbPut(pMetaDb->pStbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
kLen = sizeof(ctbIdxKey);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbInsert(pMetaDb->pCtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbPut(pMetaDb->pCtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
kLen = sizeof(uid);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbInsert(pMetaDb->pNtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbPut(pMetaDb->pNtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ static SSchemaWrapper *metaGetTableSchemaImpl(SMeta *pMeta, tb_uid_t uid, int32_
|
|||
pSchemaWrapper = taosMemoryMalloc(sizeof(*pSchemaWrapper));
|
||||
metaDecodeSchemaEx(pBuf, pSchemaWrapper, isGetEx);
|
||||
|
||||
TDB_FREE(pVal);
|
||||
tdbFree(pVal);
|
||||
|
||||
return pSchemaWrapper;
|
||||
}
|
||||
|
@ -438,7 +438,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
|||
|
||||
while (true) {
|
||||
// TODO: lock during iterate?
|
||||
if (tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) {
|
||||
if (tdbDbcNext(pCur->pCur, &pCur->pKey, &pCur->kLen, NULL, &pCur->vLen) == 0) {
|
||||
pSmaIdxKey = pCur->pKey;
|
||||
ASSERT(pSmaIdxKey != NULL);
|
||||
|
||||
|
@ -450,7 +450,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
|||
}
|
||||
|
||||
if ((pSW == NULL) && ((pSW = taosMemoryCalloc(1, sizeof(*pSW))) == NULL)) {
|
||||
TDB_FREE(pSmaVal);
|
||||
tdbFree(pSmaVal);
|
||||
metaCloseSmaCursor(pCur);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -458,7 +458,7 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
|||
++pSW->number;
|
||||
STSma *tptr = (STSma *)taosMemoryRealloc(pSW->tSma, pSW->number * sizeof(STSma));
|
||||
if (tptr == NULL) {
|
||||
TDB_FREE(pSmaVal);
|
||||
tdbFree(pSmaVal);
|
||||
metaCloseSmaCursor(pCur);
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
taosMemoryFreeClear(pSW);
|
||||
|
@ -467,13 +467,13 @@ STSmaWrapper *metaGetSmaInfoByTable(SMeta *pMeta, tb_uid_t uid) {
|
|||
pSW->tSma = tptr;
|
||||
pBuf = pSmaVal;
|
||||
if (tDecodeTSma(pBuf, pSW->tSma + pSW->number - 1) == NULL) {
|
||||
TDB_FREE(pSmaVal);
|
||||
tdbFree(pSmaVal);
|
||||
metaCloseSmaCursor(pCur);
|
||||
tdDestroyTSmaWrapper(pSW);
|
||||
taosMemoryFreeClear(pSW);
|
||||
return NULL;
|
||||
}
|
||||
TDB_FREE(pSmaVal);
|
||||
tdbFree(pSmaVal);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -530,7 +530,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
|
|||
int32_t kLen = sizeof(pSmaCfg->indexUid);
|
||||
int32_t vLen = POINTER_DISTANCE(qBuf, pBuf);
|
||||
|
||||
ret = tdbDbInsert(pMeta->pDB->pSmaDB, key, kLen, val, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbPut(pMeta->pDB->pSmaDB, key, kLen, val, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
taosMemoryFreeClear(pBuf);
|
||||
return -1;
|
||||
|
@ -545,7 +545,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
|
|||
val = NULL;
|
||||
vLen = 0;
|
||||
|
||||
ret = tdbDbInsert(pMeta->pDB->pSmaIdx, key, kLen, val, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbPut(pMeta->pDB->pSmaIdx, key, kLen, val, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
taosMemoryFreeClear(pBuf);
|
||||
return -1;
|
||||
|
@ -613,7 +613,7 @@ int64_t metaSmaCursorNext(SMSmaCursor *pCur) {
|
|||
void *pBuf;
|
||||
SSmaIdxKey *smaIdxKey;
|
||||
|
||||
ret = tdbDbNext(pCur->pCur, &pCur->pKey, &pCur->kLen, &pCur->pVal, &pCur->vLen);
|
||||
ret = tdbDbcNext(pCur->pCur, &pCur->pKey, &pCur->kLen, &pCur->pVal, &pCur->vLen);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -72,8 +72,47 @@ _err:
|
|||
}
|
||||
|
||||
int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) {
|
||||
// TODO
|
||||
SMetaReader mr = {0};
|
||||
|
||||
// validate req
|
||||
metaReaderInit(&mr, pMeta, 0);
|
||||
if (metaGetTableEntryByUid(&mr, pReq->suid) < 0) {
|
||||
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// do drop
|
||||
// drop from pTbDb
|
||||
// drop from pSkmDb
|
||||
// drop from pUidIdx
|
||||
// drop from pNameIdx
|
||||
// {
|
||||
// TDBC *pDbc1 = NULL;
|
||||
// void *pKey = NULL;
|
||||
// void *pVal = NULL;
|
||||
// int kLen = 0;
|
||||
// int vLen = 0;
|
||||
// int ret = 0;
|
||||
|
||||
// // drop from pCtbIdx
|
||||
// ret = tdbDbcOpen(pMeta->pCtbIdx, &pDbc1);
|
||||
// tdbDbcMoveTo(pDbc1, &pReq->suid, sizeof(pReq->suid), NULL /*cmpr*/, 0 /*TDB_FORWARD_SEARCH*/);
|
||||
// tdbDbcGet(pDbc1, &pKey, &kLen, &pVal, vLen);
|
||||
// tdbDbcDrop(pDbc1);
|
||||
// // drop from pTagIdx
|
||||
// // drop from pTtlIdx
|
||||
// }
|
||||
|
||||
// clear and return
|
||||
metaReaderClear(&mr);
|
||||
metaError("vgId:%d super table %s uid:%" PRId64 " is dropped", TD_VID(pMeta->pVnode), pReq->name, pReq->suid);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
metaReaderClear(&mr);
|
||||
metaError("vgId:%d failed to drop super table %s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
|
||||
pReq->suid, tstrerror(terrno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) {
|
||||
|
@ -179,7 +218,7 @@ static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
tCoderClear(&coder);
|
||||
|
||||
// write to table.db
|
||||
if (tdbDbInsert(pMeta->pTbDb, pKey, kLen, pVal, vLen, &pMeta->txn) < 0) {
|
||||
if (tdbDbPut(pMeta->pTbDb, pKey, kLen, pVal, vLen, &pMeta->txn) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
|
@ -192,11 +231,11 @@ _err:
|
|||
}
|
||||
|
||||
static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
return tdbDbInsert(pMeta->pUidIdx, &pME->uid, sizeof(tb_uid_t), &pME->version, sizeof(int64_t), &pMeta->txn);
|
||||
return tdbDbPut(pMeta->pUidIdx, &pME->uid, sizeof(tb_uid_t), &pME->version, sizeof(int64_t), &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
return tdbDbInsert(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), &pMeta->txn);
|
||||
return tdbDbPut(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
|
@ -219,12 +258,12 @@ static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
ttlKey.dtime = ctime + ttlDays * 24 * 60 * 60;
|
||||
ttlKey.uid = pME->uid;
|
||||
|
||||
return tdbDbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn);
|
||||
return tdbDbPut(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SCtbIdxKey ctbIdxKey = {.suid = pME->ctbEntry.suid, .uid = pME->uid};
|
||||
return tdbDbInsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), NULL, 0, &pMeta->txn);
|
||||
return tdbDbPut(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), NULL, 0, &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
|
@ -265,7 +304,7 @@ static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pVal, vLen, TD_ENCODER);
|
||||
tEncodeSSchemaWrapper(&coder, pSW);
|
||||
|
||||
if (tdbDbInsert(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), pVal, vLen, &pMeta->txn) < 0) {
|
||||
if (tdbDbPut(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), pVal, vLen, &pMeta->txn) < 0) {
|
||||
rcode = -1;
|
||||
goto _exit;
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ typedef struct {
|
|||
#define TSDB_COMMIT_BUF(ch) TSDB_READ_BUF(&((ch)->readh))
|
||||
#define TSDB_COMMIT_COMP_BUF(ch) TSDB_READ_COMP_BUF(&((ch)->readh))
|
||||
#define TSDB_COMMIT_EXBUF(ch) TSDB_READ_EXBUF(&((ch)->readh))
|
||||
#define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->config.maxRows)
|
||||
#define TSDB_COMMIT_DEFAULT_ROWS(ch) TSDB_DEFAULT_BLOCK_ROWS(TSDB_COMMIT_REPO(ch)->pVnode->config.tsdbCfg.maxRows)
|
||||
#define TSDB_COMMIT_TXN_VERSION(ch) FS_TXN_VERSION(REPO_FS(TSDB_COMMIT_REPO(ch)))
|
||||
|
||||
static void tsdbStartCommit(STsdb *pRepo);
|
||||
|
|
|
@ -34,9 +34,8 @@ int tsdbOpen(SVnode *pVnode, STsdb **ppTsdb) {
|
|||
VNODE_TSDB_DIR);
|
||||
pTsdb->pVnode = pVnode;
|
||||
pTsdb->repoLocked = false;
|
||||
tdbMutexInit(&pTsdb->mutex, NULL);
|
||||
pTsdb->config = pVnode->config.tsdbCfg;
|
||||
pTsdb->fs = tsdbNewFS(&pTsdb->config);
|
||||
taosThreadMutexInit(&pTsdb->mutex, NULL);
|
||||
pTsdb->fs = tsdbNewFS(REPO_CFG(pTsdb));
|
||||
|
||||
// create dir (TODO: use tfsMkdir)
|
||||
taosMkDir(pTsdb->path);
|
||||
|
|
|
@ -311,7 +311,7 @@ static bool emptyQueryTimewindow(STsdbReadHandle* pTsdbReadHandle) {
|
|||
// Update the query time window according to the data time to live(TTL) information, in order to avoid to return
|
||||
// the expired data to client, even it is queried already.
|
||||
static int64_t getEarliestValidTimestamp(STsdb* pTsdb) {
|
||||
STsdbCfg* pCfg = &pTsdb->config;
|
||||
STsdbCfg* pCfg = REPO_CFG(pTsdb);
|
||||
|
||||
int64_t now = taosGetTimestamp(pCfg->precision);
|
||||
return now - (tsTickPerDay[pCfg->precision] * pCfg->keep2) + 1; // needs to add one tick
|
||||
|
@ -404,7 +404,7 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, SQueryTableDataCond* pC
|
|||
pReadHandle->defaultLoadColumn = getDefaultLoadColumns(pReadHandle, true);
|
||||
}
|
||||
|
||||
pReadHandle->pDataCols = tdNewDataCols(1000, pReadHandle->pTsdb->config.maxRows);
|
||||
pReadHandle->pDataCols = tdNewDataCols(1000, pReadHandle->pTsdb->pVnode->config.tsdbCfg.maxRows);
|
||||
if (pReadHandle->pDataCols == NULL) {
|
||||
tsdbError("%p failed to malloc buf for pDataCols, %s", pReadHandle, pReadHandle->idStr);
|
||||
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||
|
@ -889,7 +889,7 @@ static bool moveToNextRowInMem(STableCheckInfo* pCheckInfo) {
|
|||
}
|
||||
|
||||
static bool hasMoreDataInCache(STsdbReadHandle* pHandle) {
|
||||
STsdbCfg* pCfg = &pHandle->pTsdb->config;
|
||||
STsdbCfg* pCfg = REPO_CFG(pHandle->pTsdb);
|
||||
size_t size = taosArrayGetSize(pHandle->pTableCheckInfo);
|
||||
assert(pHandle->activeIndex < size && pHandle->activeIndex >= 0 && size >= 1);
|
||||
pHandle->cur.fid = INT32_MIN;
|
||||
|
@ -1169,7 +1169,7 @@ static void copyAllRemainRowsFromFileBlock(STsdbReadHandle* pTsdbReadHandle,
|
|||
|
||||
static int32_t handleDataMergeIfNeeded(STsdbReadHandle* pTsdbReadHandle, SBlock* pBlock, STableCheckInfo* pCheckInfo) {
|
||||
SQueryFilePos* cur = &pTsdbReadHandle->cur;
|
||||
STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config;
|
||||
STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb);
|
||||
SDataBlockInfo binfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock);
|
||||
TSKEY key;
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
@ -1756,7 +1756,7 @@ int32_t getEndPosInDataBlock(STsdbReadHandle* pTsdbReadHandle, SDataBlockInfo* p
|
|||
static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInfo* pCheckInfo, SBlock* pBlock) {
|
||||
SQueryFilePos* cur = &pTsdbReadHandle->cur;
|
||||
SDataBlockInfo blockInfo = GET_FILE_DATA_BLOCK_INFO(pCheckInfo, pBlock);
|
||||
STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config;
|
||||
STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb);
|
||||
|
||||
initTableMemIterator(pTsdbReadHandle, pCheckInfo);
|
||||
|
||||
|
@ -2200,7 +2200,7 @@ static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exi
|
|||
int32_t numOfBlocks = 0;
|
||||
int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo);
|
||||
|
||||
STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config;
|
||||
STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb);
|
||||
STimeWindow win = TSWINDOW_INITIALIZER;
|
||||
|
||||
while (true) {
|
||||
|
@ -2306,7 +2306,7 @@ int32_t tsdbGetFileBlocksDistInfo(tsdbReaderT* queryHandle, STableBlockDistInfo*
|
|||
|
||||
// find the start data block in file
|
||||
pTsdbReadHandle->locateStart = true;
|
||||
STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config;
|
||||
STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb);
|
||||
int32_t fid = getFileIdFromKey(pTsdbReadHandle->window.skey, pCfg->days, pCfg->precision);
|
||||
|
||||
tsdbRLockFS(pFileHandle);
|
||||
|
@ -2407,7 +2407,7 @@ static int32_t getDataBlocksInFiles(STsdbReadHandle* pTsdbReadHandle, bool* exis
|
|||
// find the start data block in file
|
||||
if (!pTsdbReadHandle->locateStart) {
|
||||
pTsdbReadHandle->locateStart = true;
|
||||
STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config;
|
||||
STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb);
|
||||
int32_t fid = getFileIdFromKey(pTsdbReadHandle->window.skey, pCfg->days, pCfg->precision);
|
||||
|
||||
tsdbRLockFS(pFileHandle);
|
||||
|
@ -2498,7 +2498,7 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
|||
STsdbReadHandle* pTsdbReadHandle) {
|
||||
int numOfRows = 0;
|
||||
int32_t numOfCols = (int32_t)taosArrayGetSize(pTsdbReadHandle->pColumns);
|
||||
STsdbCfg* pCfg = &pTsdbReadHandle->pTsdb->config;
|
||||
STsdbCfg* pCfg = REPO_CFG(pTsdbReadHandle->pTsdb);
|
||||
win->skey = TSKEY_INITIAL_VAL;
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
|
|
@ -248,7 +248,8 @@ int tsdbLoadBlockInfo(SReadH *pReadh, void *pTarget) {
|
|||
|
||||
int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) {
|
||||
ASSERT(pBlock->numOfSubBlocks > 0);
|
||||
int8_t update = pReadh->pRepo->config.update;
|
||||
STsdbCfg *pCfg = REPO_CFG(pReadh->pRepo);
|
||||
int8_t update = pCfg->update;
|
||||
|
||||
SBlock *iBlock = pBlock;
|
||||
if (pBlock->numOfSubBlocks > 1) {
|
||||
|
@ -279,7 +280,7 @@ int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) {
|
|||
int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo, const int16_t *colIds, int numOfColsIds,
|
||||
bool mergeBitmap) {
|
||||
ASSERT(pBlock->numOfSubBlocks > 0);
|
||||
int8_t update = pReadh->pRepo->config.update;
|
||||
int8_t update = pReadh->pRepo->pVnode->config.tsdbCfg.update;
|
||||
|
||||
SBlock *iBlock = pBlock;
|
||||
if (pBlock->numOfSubBlocks > 1) {
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#include "tsdb.h"
|
||||
#ifndef _TSDB_PLUGINS
|
||||
|
||||
int tsdbScanFGroup(STsdbScanHandle* pScanHandle, char* rootDir, int fid) { return 0; }
|
||||
|
||||
STsdbScanHandle* tsdbNewScanHandle() { return NULL; }
|
||||
|
||||
void tsdbSetScanLogStream(STsdbScanHandle* pScanHandle, FILE* fLogStream) {}
|
||||
|
||||
int tsdbSetAndOpenScanFile(STsdbScanHandle* pScanHandle, char* rootDir, int fid) { return 0; }
|
||||
|
||||
int tsdbScanSBlockIdx(STsdbScanHandle* pScanHandle) { return 0; }
|
||||
|
||||
int tsdbScanSBlock(STsdbScanHandle* pScanHandle, int idx) { return 0; }
|
||||
|
||||
int tsdbCloseScanFile(STsdbScanHandle* pScanHandle) { return 0; }
|
||||
|
||||
void tsdbFreeScanHandle(STsdbScanHandle* pScanHandle) {}
|
||||
|
||||
#endif
|
||||
#endif
|
|
@ -224,7 +224,7 @@ static FORCE_INLINE int32_t tsdbUnLockSma(SSmaEnv *pEnv) {
|
|||
}
|
||||
|
||||
static SPoolMem *openPool() {
|
||||
SPoolMem *pPool = (SPoolMem *)tdbOsMalloc(sizeof(*pPool));
|
||||
SPoolMem *pPool = (SPoolMem *)taosMemoryMalloc(sizeof(*pPool));
|
||||
|
||||
pPool->prev = pPool->next = pPool;
|
||||
pPool->size = 0;
|
||||
|
@ -246,7 +246,7 @@ static void clearPool(SPoolMem *pPool) {
|
|||
pMem->prev->next = pMem->next;
|
||||
pPool->size -= pMem->size;
|
||||
|
||||
tdbOsFree(pMem);
|
||||
taosMemoryFree(pMem);
|
||||
} while (1);
|
||||
|
||||
assert(pPool->size == 0);
|
||||
|
@ -255,7 +255,7 @@ static void clearPool(SPoolMem *pPool) {
|
|||
static void closePool(SPoolMem *pPool) {
|
||||
if (pPool) {
|
||||
clearPool(pPool);
|
||||
tdbOsFree(pPool);
|
||||
taosMemoryFree(pPool);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ static void *poolMalloc(void *arg, size_t size) {
|
|||
SPoolMem *pPool = (SPoolMem *)arg;
|
||||
SPoolMem *pMem;
|
||||
|
||||
pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size);
|
||||
pMem = (SPoolMem *)taosMemoryMalloc(sizeof(*pMem) + size);
|
||||
if (!pMem) {
|
||||
assert(0);
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ static void poolFree(void *arg, void *ptr) {
|
|||
pMem->prev->next = pMem->next;
|
||||
pPool->size -= pMem->size;
|
||||
|
||||
tdbOsFree(pMem);
|
||||
taosMemoryFree(pMem);
|
||||
}
|
||||
|
||||
int32_t tsdbInitSma(STsdb *pTsdb) {
|
||||
|
|
|
@ -56,11 +56,11 @@ static inline int tsdbSmaKeyCmpr(const void *arg1, int len1, const void *arg2, i
|
|||
|
||||
static int32_t tsdbOpenDBDb(TDB **ppDB, TENV *pEnv, const char *pFName) {
|
||||
int ret;
|
||||
FKeyComparator compFunc;
|
||||
tdb_cmpr_fn_t compFunc;
|
||||
|
||||
// Create a database
|
||||
compFunc = tsdbSmaKeyCmpr;
|
||||
ret = tdbDbOpen(pFName, TDB_VARIANT_LEN, TDB_VARIANT_LEN, compFunc, pEnv, ppDB);
|
||||
ret = tdbDbOpen(pFName, -1, -1, compFunc, pEnv, ppDB);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ int32_t tsdbCloseDBF(SDBFile *pDBF) {
|
|||
int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *pKey, int32_t keyLen, void *pVal, int32_t valLen, TXN *txn) {
|
||||
int32_t ret;
|
||||
|
||||
ret = tdbDbInsert(pDBF->pDB, pKey, keyLen, pVal, valLen, txn);
|
||||
ret = tdbDbPut(pDBF->pDB, pKey, keyLen, pVal, valLen, txn);
|
||||
if (ret < 0) {
|
||||
tsdbError("Failed to create insert sma data into db, ret = %d", ret);
|
||||
return -1;
|
||||
|
|
|
@ -60,9 +60,10 @@ static int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) {
|
|||
SSubmitBlk *pBlock = NULL;
|
||||
SSubmitBlkIter blkIter = {0};
|
||||
STSRow *row = NULL;
|
||||
TSKEY now = taosGetTimestamp(pTsdb->config.precision);
|
||||
TSKEY minKey = now - tsTickPerDay[pTsdb->config.precision] * pTsdb->config.keep2;
|
||||
TSKEY maxKey = now + tsTickPerDay[pTsdb->config.precision] * pTsdb->config.days;
|
||||
STsdbCfg *pCfg = REPO_CFG(pTsdb);
|
||||
TSKEY now = taosGetTimestamp(pCfg->precision);
|
||||
TSKEY minKey = now - tsTickPerDay[pCfg->precision] * pCfg->keep2;
|
||||
TSKEY maxKey = now + tsTickPerDay[pCfg->precision] * pCfg->days;
|
||||
|
||||
terrno = TSDB_CODE_SUCCESS;
|
||||
pMsg->length = htonl(pMsg->length);
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "vnd.h"
|
||||
// #include "vnodeInt.h"
|
||||
|
||||
int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; }
|
||||
|
||||
int32_t vnodeCompact(SVnode *pVnode) { return 0; }
|
||||
|
||||
int32_t vnodeSync(SVnode *pVnode) { return 0; }
|
|
@ -17,10 +17,10 @@
|
|||
|
||||
static int vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq, int len, SRpcMsg *pRsp);
|
||||
static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int vnodeProcessDropStbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int vnodeProcessDropStbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int vnodeProcessCreateTbReq(SVnode *pVnode, int64_t version, void *pReq, int len, SRpcMsg *pRsp);
|
||||
static int vnodeProcessAlterTbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int vnodeProcessDropTbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp);
|
||||
|
||||
int vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs, int64_t *version) {
|
||||
|
@ -116,7 +116,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
|
|||
if (vnodeProcessAlterStbReq(pVnode, pReq, len, pRsp) < 0) goto _err;
|
||||
break;
|
||||
case TDMT_VND_DROP_STB:
|
||||
if (vnodeProcessDropStbReq(pVnode, pReq, len, pRsp) < 0) goto _err;
|
||||
if (vnodeProcessDropStbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||
break;
|
||||
case TDMT_VND_CREATE_TABLE:
|
||||
if (vnodeProcessCreateTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||
|
@ -125,7 +125,7 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
|
|||
if (vnodeProcessAlterTbReq(pVnode, pReq, len, pRsp) < 0) goto _err;
|
||||
break;
|
||||
case TDMT_VND_DROP_TABLE:
|
||||
if (vnodeProcessDropTbReq(pVnode, pReq, len, pRsp) < 0) goto _err;
|
||||
if (vnodeProcessDropTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err;
|
||||
break;
|
||||
case TDMT_VND_CREATE_SMA: { // timeRangeSMA
|
||||
if (tsdbCreateTSma(pVnode->pTsdb, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead))) < 0) {
|
||||
|
@ -450,9 +450,32 @@ static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq, int32_t len, SRpc
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int vnodeProcessDropStbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
// TODO
|
||||
// ASSERT(0);
|
||||
static int vnodeProcessDropStbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SVDropStbReq req = {0};
|
||||
int rcode = TSDB_CODE_SUCCESS;
|
||||
SCoder coder = {0};
|
||||
|
||||
pRsp->msgType = TDMT_VND_CREATE_STB_RSP;
|
||||
pRsp->pCont = NULL;
|
||||
pRsp->contLen = 0;
|
||||
|
||||
// decode request
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pReq, len, TD_DECODER);
|
||||
if (tDecodeSVDropStbReq(&coder, &req) < 0) {
|
||||
rcode = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
// process request
|
||||
// if (metaDropSTable(pVnode->pMeta, version, &req) < 0) {
|
||||
// rcode = terrno;
|
||||
// goto _exit;
|
||||
// }
|
||||
|
||||
// return rsp
|
||||
_exit:
|
||||
pRsp->code = rcode;
|
||||
tCoderClear(&coder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -462,9 +485,15 @@ static int vnodeProcessAlterTbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcM
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int vnodeProcessDropTbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
static int vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SVDropTbReq req = {0};
|
||||
SVDropTbReq rsp = {0};
|
||||
|
||||
// decode req
|
||||
|
||||
// process req
|
||||
|
||||
// return rsp
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -3176,11 +3176,11 @@ static int32_t rewriteShow(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
return code;
|
||||
}
|
||||
|
||||
typedef struct SVgroupTablesBatch {
|
||||
typedef struct SVgroupCreateTableBatch {
|
||||
SVCreateTbBatchReq req;
|
||||
SVgroupInfo info;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
} SVgroupTablesBatch;
|
||||
} SVgroupCreateTableBatch;
|
||||
|
||||
static void destroyCreateTbReq(SVCreateTbReq* pReq) {
|
||||
taosMemoryFreeClear(pReq->name);
|
||||
|
@ -3188,7 +3188,7 @@ static void destroyCreateTbReq(SVCreateTbReq* pReq) {
|
|||
}
|
||||
|
||||
static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* pStmt, const SVgroupInfo* pVgroupInfo,
|
||||
SVgroupTablesBatch* pBatch) {
|
||||
SVgroupCreateTableBatch* pBatch) {
|
||||
char dbFName[TSDB_DB_FNAME_LEN] = {0};
|
||||
SName name = {.type = TSDB_DB_NAME_T, .acctId = acctId};
|
||||
strcpy(name.dbname, pStmt->dbName);
|
||||
|
@ -3222,13 +3222,13 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray* pBufArray) {
|
||||
static int32_t serializeVgroupCreateTableBatch(SVgroupCreateTableBatch* pTbBatch, SArray* pBufArray) {
|
||||
int tlen;
|
||||
SCoder coder = {0};
|
||||
|
||||
int32_t ret = 0;
|
||||
tEncodeSize(tEncodeSVCreateTbBatchReq, &pTbBatch->req, tlen, ret);
|
||||
tlen += sizeof(SMsgHead); //+ tSerializeSVCreateTbBatchReq(NULL, &(pTbBatch->req));
|
||||
tlen += sizeof(SMsgHead);
|
||||
void* buf = taosMemoryMalloc(tlen);
|
||||
if (NULL == buf) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -3254,7 +3254,7 @@ static int32_t serializeVgroupTablesBatch(SVgroupTablesBatch* pTbBatch, SArray*
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void destroyCreateTbReqBatch(SVgroupTablesBatch* pTbBatch) {
|
||||
static void destroyCreateTbReqBatch(SVgroupCreateTableBatch* pTbBatch) {
|
||||
size_t size = taosArrayGetSize(pTbBatch->req.pArray);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SVCreateTbReq* pTableReq = taosArrayGet(pTbBatch->req.pArray, i);
|
||||
|
@ -3299,10 +3299,10 @@ static int32_t buildCreateTableDataBlock(int32_t acctId, const SCreateTableStmt*
|
|||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SVgroupTablesBatch tbatch = {0};
|
||||
SVgroupCreateTableBatch tbatch = {0};
|
||||
int32_t code = buildNormalTableBatchReq(acctId, pStmt, pInfo, &tbatch);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = serializeVgroupTablesBatch(&tbatch, *pBufArray);
|
||||
code = serializeVgroupCreateTableBatch(&tbatch, *pBufArray);
|
||||
}
|
||||
|
||||
destroyCreateTbReqBatch(&tbatch);
|
||||
|
@ -3347,9 +3347,9 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, c
|
|||
req.ctb.suid = suid;
|
||||
req.ctb.pTag = row;
|
||||
|
||||
SVgroupTablesBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId));
|
||||
SVgroupCreateTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId));
|
||||
if (pTableBatch == NULL) {
|
||||
SVgroupTablesBatch tBatch = {0};
|
||||
SVgroupCreateTableBatch tBatch = {0};
|
||||
tBatch.info = *pVgInfo;
|
||||
strcpy(tBatch.dbName, pDbName);
|
||||
|
||||
|
@ -3522,21 +3522,21 @@ static int32_t rewriteCreateSubTable(STranslateContext* pCxt, SCreateSubTableCla
|
|||
return code;
|
||||
}
|
||||
|
||||
static SArray* serializeVgroupsTablesBatch(int32_t acctId, SHashObj* pVgroupHashmap) {
|
||||
static SArray* serializeVgroupsCreateTableBatch(int32_t acctId, SHashObj* pVgroupHashmap) {
|
||||
SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*));
|
||||
if (NULL == pBufArray) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SVgroupTablesBatch* pTbBatch = NULL;
|
||||
SVgroupCreateTableBatch* pTbBatch = NULL;
|
||||
do {
|
||||
pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch);
|
||||
if (pTbBatch == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
serializeVgroupTablesBatch(pTbBatch, pBufArray);
|
||||
serializeVgroupCreateTableBatch(pTbBatch, pBufArray);
|
||||
destroyCreateTbReqBatch(pTbBatch);
|
||||
} while (true);
|
||||
|
||||
|
@ -3561,7 +3561,143 @@ static int32_t rewriteCreateMultiTable(STranslateContext* pCxt, SQuery* pQuery)
|
|||
}
|
||||
}
|
||||
|
||||
SArray* pBufArray = serializeVgroupsTablesBatch(pCxt->pParseCxt->acctId, pVgroupHashmap);
|
||||
SArray* pBufArray = serializeVgroupsCreateTableBatch(pCxt->pParseCxt->acctId, pVgroupHashmap);
|
||||
taosHashCleanup(pVgroupHashmap);
|
||||
if (NULL == pBufArray) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return rewriteToVnodeModifOpStmt(pQuery, pBufArray);
|
||||
}
|
||||
|
||||
typedef struct SVgroupDropTableBatch {
|
||||
SVDropTbBatchReq req;
|
||||
SVgroupInfo info;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
} SVgroupDropTableBatch;
|
||||
|
||||
static void addDropTbReqIntoVgroup(SHashObj* pVgroupHashmap, SDropTableClause* pClause, SVgroupInfo* pVgInfo) {
|
||||
SVDropTbReq req = {.name = pClause->tableName, .igNotExists = pClause->ignoreNotExists};
|
||||
SVgroupDropTableBatch* pTableBatch = taosHashGet(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId));
|
||||
if (NULL == pTableBatch) {
|
||||
SVgroupDropTableBatch tBatch = {0};
|
||||
tBatch.info = *pVgInfo;
|
||||
tBatch.req.pArray = taosArrayInit(TARRAY_MIN_SIZE, sizeof(SVDropTbReq));
|
||||
taosArrayPush(tBatch.req.pArray, &req);
|
||||
|
||||
taosHashPut(pVgroupHashmap, &pVgInfo->vgId, sizeof(pVgInfo->vgId), &tBatch, sizeof(tBatch));
|
||||
} else { // add to the correct vgroup
|
||||
taosArrayPush(pTableBatch->req.pArray, &req);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t buildDropTableVgroupHashmap(STranslateContext* pCxt, SDropTableClause* pClause, bool* pIsSuperTable,
|
||||
SHashObj* pVgroupHashmap) {
|
||||
STableMeta* pTableMeta = NULL;
|
||||
int32_t code = getTableMeta(pCxt, pClause->dbName, pClause->tableName, &pTableMeta);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && TSDB_SUPER_TABLE == pTableMeta->tableType) {
|
||||
*pIsSuperTable = true;
|
||||
goto over;
|
||||
}
|
||||
|
||||
*pIsSuperTable = false;
|
||||
|
||||
SVgroupInfo info = {0};
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = getTableHashVgroup(pCxt, pClause->dbName, pClause->tableName, &info);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
addDropTbReqIntoVgroup(pVgroupHashmap, pClause, &info);
|
||||
}
|
||||
|
||||
over:
|
||||
taosMemoryFreeClear(pTableMeta);
|
||||
return code;
|
||||
}
|
||||
|
||||
static void destroyDropTbReqBatch(SVgroupDropTableBatch* pTbBatch) { taosArrayDestroy(pTbBatch->req.pArray); }
|
||||
|
||||
static int32_t serializeVgroupDropTableBatch(SVgroupDropTableBatch* pTbBatch, SArray* pBufArray) {
|
||||
int tlen;
|
||||
SCoder coder = {0};
|
||||
|
||||
int32_t ret = 0;
|
||||
tEncodeSize(tEncodeSVDropTbBatchReq, &pTbBatch->req, tlen, ret);
|
||||
tlen += sizeof(SMsgHead);
|
||||
void* buf = taosMemoryMalloc(tlen);
|
||||
if (NULL == buf) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
((SMsgHead*)buf)->vgId = htonl(pTbBatch->info.vgId);
|
||||
((SMsgHead*)buf)->contLen = htonl(tlen);
|
||||
void* pBuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
|
||||
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pBuf, tlen - sizeof(SMsgHead), TD_ENCODER);
|
||||
tEncodeSVDropTbBatchReq(&coder, &pTbBatch->req);
|
||||
tCoderClear(&coder);
|
||||
|
||||
SVgDataBlocks* pVgData = taosMemoryCalloc(1, sizeof(SVgDataBlocks));
|
||||
if (NULL == pVgData) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pVgData->vg = pTbBatch->info;
|
||||
pVgData->pData = buf;
|
||||
pVgData->size = tlen;
|
||||
pVgData->numOfTables = (int32_t)taosArrayGetSize(pTbBatch->req.pArray);
|
||||
taosArrayPush(pBufArray, &pVgData);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static SArray* serializeVgroupsDropTableBatch(int32_t acctId, SHashObj* pVgroupHashmap) {
|
||||
SArray* pBufArray = taosArrayInit(taosHashGetSize(pVgroupHashmap), sizeof(void*));
|
||||
if (NULL == pBufArray) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SVgroupDropTableBatch* pTbBatch = NULL;
|
||||
do {
|
||||
pTbBatch = taosHashIterate(pVgroupHashmap, pTbBatch);
|
||||
if (pTbBatch == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
serializeVgroupDropTableBatch(pTbBatch, pBufArray);
|
||||
destroyDropTbReqBatch(pTbBatch);
|
||||
} while (true);
|
||||
|
||||
return pBufArray;
|
||||
}
|
||||
|
||||
static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot;
|
||||
|
||||
SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
||||
if (NULL == pVgroupHashmap) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
bool isSuperTable = false;
|
||||
SNode* pNode;
|
||||
FOREACH(pNode, pStmt->pTables) {
|
||||
int32_t code = buildDropTableVgroupHashmap(pCxt, (SDropTableClause*)pNode, &isSuperTable, pVgroupHashmap);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosHashCleanup(pVgroupHashmap);
|
||||
return code;
|
||||
}
|
||||
if (isSuperTable && LIST_LENGTH(pStmt->pTables) > 1) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DROP_STABLE);
|
||||
}
|
||||
}
|
||||
|
||||
if (isSuperTable) {
|
||||
taosHashCleanup(pVgroupHashmap);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SArray* pBufArray = serializeVgroupsDropTableBatch(pCxt->pParseCxt->acctId, pVgroupHashmap);
|
||||
taosHashCleanup(pVgroupHashmap);
|
||||
if (NULL == pBufArray) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
@ -3607,6 +3743,9 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
||||
code = rewriteCreateMultiTable(pCxt, pQuery);
|
||||
break;
|
||||
case QUERY_NODE_DROP_TABLE_STMT:
|
||||
code = rewriteDropTable(pCxt, pQuery);
|
||||
break;
|
||||
case QUERY_NODE_ALTER_TABLE_STMT:
|
||||
if (TSDB_ALTER_TABLE_UPDATE_TAG_VAL == ((SAlterTableStmt*)pQuery->pRoot)->alterType) {
|
||||
code = rewriteAlterTable(pCxt, pQuery);
|
||||
|
|
|
@ -126,6 +126,8 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
return "slimit/soffset only available for PARTITION BY query";
|
||||
case TSDB_CODE_PAR_INVALID_TOPIC_QUERY:
|
||||
return "Invalid topic query";
|
||||
case TSDB_CODE_PAR_INVALID_DROP_STABLE:
|
||||
return "Cannot drop super table in batch";
|
||||
case TSDB_CODE_OUT_OF_MEMORY:
|
||||
return "Out of memory";
|
||||
default:
|
||||
|
|
|
@ -944,9 +944,16 @@ static int32_t createSetOperatorLogicNode(SLogicPlanContext* pCxt, SSetOperator*
|
|||
}
|
||||
|
||||
static int32_t getMsgType(ENodeType sqlType) {
|
||||
return (QUERY_NODE_CREATE_TABLE_STMT == sqlType || QUERY_NODE_CREATE_MULTI_TABLE_STMT == sqlType)
|
||||
? TDMT_VND_CREATE_TABLE
|
||||
: TDMT_VND_SUBMIT;
|
||||
switch (sqlType) {
|
||||
case QUERY_NODE_CREATE_TABLE_STMT:
|
||||
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
||||
return TDMT_VND_CREATE_TABLE;
|
||||
case QUERY_NODE_DROP_TABLE_STMT:
|
||||
return TDMT_VND_DROP_TABLE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TDMT_VND_SUBMIT;
|
||||
}
|
||||
|
||||
static int32_t createVnodeModifLogicNode(SLogicPlanContext* pCxt, SVnodeModifOpStmt* pStmt, SLogicNode** pLogicNode) {
|
||||
|
|
|
@ -254,6 +254,7 @@ int32_t schValidateTaskReceivedMsgType(SSchJob *pJob, SSchTask *pTask, int32_t m
|
|||
SCH_SET_TASK_LASTMSG_TYPE(pTask, -1);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
case TDMT_VND_CREATE_TABLE_RSP:
|
||||
case TDMT_VND_DROP_TABLE_RSP:
|
||||
case TDMT_VND_SUBMIT_RSP:
|
||||
break;
|
||||
default:
|
||||
|
@ -1103,6 +1104,30 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch
|
|||
SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask));
|
||||
break;
|
||||
}
|
||||
case TDMT_VND_DROP_TABLE_RSP: {
|
||||
SVDropTbBatchRsp batchRsp = {0};
|
||||
if (msg) {
|
||||
SCoder coder = {0};
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, msg, msgSize, TD_DECODER);
|
||||
code = tDecodeSVDropTbBatchRsp(&coder, &batchRsp);
|
||||
if (TSDB_CODE_SUCCESS == code && batchRsp.pArray) {
|
||||
int32_t num = taosArrayGetSize(batchRsp.pArray);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SVDropTbRsp *rsp = taosArrayGet(batchRsp.pArray, i);
|
||||
if (NEED_CLIENT_HANDLE_ERROR(rsp->code)) {
|
||||
tCoderClear(&coder);
|
||||
SCH_ERR_JRET(rsp->code);
|
||||
}
|
||||
}
|
||||
}
|
||||
tCoderClear(&coder);
|
||||
SCH_ERR_JRET(code);
|
||||
}
|
||||
|
||||
SCH_ERR_JRET(rspCode);
|
||||
SCH_ERR_RET(schProcessOnTaskSuccess(pJob, pTask));
|
||||
break;
|
||||
}
|
||||
case TDMT_VND_SUBMIT_RSP: {
|
||||
if (msg) {
|
||||
SSubmitRsp *rsp = (SSubmitRsp *)msg;
|
||||
|
@ -1325,6 +1350,10 @@ int32_t schHandleCreateTableCallback(void *param, const SDataBuf *pMsg, int32_t
|
|||
return schHandleCallback(param, pMsg, TDMT_VND_CREATE_TABLE_RSP, code);
|
||||
}
|
||||
|
||||
int32_t schHandleDropTableCallback(void *param, const SDataBuf *pMsg, int32_t code) {
|
||||
return schHandleCallback(param, pMsg, TDMT_VND_DROP_TABLE_RSP, code);
|
||||
}
|
||||
|
||||
int32_t schHandleQueryCallback(void *param, const SDataBuf *pMsg, int32_t code) {
|
||||
return schHandleCallback(param, pMsg, TDMT_VND_QUERY_RSP, code);
|
||||
}
|
||||
|
@ -1421,6 +1450,9 @@ int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp) {
|
|||
case TDMT_VND_CREATE_TABLE:
|
||||
*fp = schHandleCreateTableCallback;
|
||||
break;
|
||||
case TDMT_VND_DROP_TABLE:
|
||||
*fp = schHandleDropTableCallback;
|
||||
break;
|
||||
case TDMT_VND_SUBMIT:
|
||||
*fp = schHandleSubmitCallback;
|
||||
break;
|
||||
|
@ -1940,6 +1972,7 @@ int32_t schBuildAndSendMsg(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr,
|
|||
|
||||
switch (msgType) {
|
||||
case TDMT_VND_CREATE_TABLE:
|
||||
case TDMT_VND_DROP_TABLE:
|
||||
case TDMT_VND_SUBMIT: {
|
||||
msgSize = pTask->msgLen;
|
||||
msg = taosMemoryCalloc(1, msgSize);
|
||||
|
|
|
@ -22,6 +22,65 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int (*tdb_cmpr_fn_t)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
|
||||
// exposed types
|
||||
typedef struct STEnv TENV;
|
||||
typedef struct STDB TDB;
|
||||
typedef struct STDBC TDBC;
|
||||
typedef struct STxn TXN;
|
||||
|
||||
// TENV
|
||||
int tdbEnvOpen(const char *rootDir, int szPage, int pages, TENV **ppEnv);
|
||||
int tdbEnvClose(TENV *pEnv);
|
||||
int tdbBegin(TENV *pEnv, TXN *pTxn);
|
||||
int tdbCommit(TENV *pEnv, TXN *pTxn);
|
||||
|
||||
// TDB
|
||||
int tdbDbOpen(const char *fname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TENV *pEnv, TDB **ppDb);
|
||||
int tdbDbClose(TDB *pDb);
|
||||
int tdbDbDrop(TDB *pDb);
|
||||
int tdbDbPut(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn);
|
||||
int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen);
|
||||
int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);
|
||||
|
||||
// TDBC
|
||||
int tdbDbcOpen(TDB *pDb, TDBC **ppDbc, TXN *pTxn);
|
||||
int tdbDbcClose(TDBC *pDbc);
|
||||
int tdbDbcMoveTo(TDBC *pDbc, const void *pKey, int kLen, int *c);
|
||||
int tdbDbcMoveToFirst(TDBC *pDbc);
|
||||
int tdbDbcMoveToLast(TDBC *pDbc);
|
||||
int tdbDbcMoveToNext(TDBC *pDbc);
|
||||
int tdbDbcMoveToPrev(TDBC *pDbc);
|
||||
int tdbDbcGet(TDBC *pDbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen);
|
||||
|
||||
int tdbDbcPut(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen);
|
||||
int tdbDbcUpdate(TDBC *pDbc, const void *pKey, int kLen, const void *pVal, int vLen);
|
||||
int tdbDbcDrop(TDBC *pDbc);
|
||||
int tdbDbcNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||
|
||||
// TXN
|
||||
#define TDB_TXN_WRITE 0x1
|
||||
#define TDB_TXN_READ_UNCOMMITTED 0x2
|
||||
|
||||
int tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *), void *xArg,
|
||||
int flags);
|
||||
int tdbTxnClose(TXN *pTxn);
|
||||
|
||||
// other
|
||||
void tdbFree(void *);
|
||||
|
||||
struct STxn {
|
||||
int flags;
|
||||
int64_t txnId;
|
||||
void *(*xMalloc)(void *, size_t);
|
||||
void (*xFree)(void *, void *);
|
||||
void *xArg;
|
||||
};
|
||||
|
||||
// error code
|
||||
enum { TDB_CODE_SUCCESS = 0, TDB_CODE_MAX };
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,7 @@ struct SBTree {
|
|||
int keyLen;
|
||||
int valLen;
|
||||
SPager *pPager;
|
||||
FKeyComparator kcmpr;
|
||||
tdb_cmpr_fn_t kcmpr;
|
||||
int pageSize;
|
||||
int maxLocal;
|
||||
int minLocal;
|
||||
|
@ -58,16 +58,6 @@ typedef struct {
|
|||
SBTree *pBt;
|
||||
} SBtreeInitPageArg;
|
||||
|
||||
typedef struct {
|
||||
int kLen;
|
||||
const u8 *pKey;
|
||||
int vLen;
|
||||
const u8 *pVal;
|
||||
SPgno pgno;
|
||||
u8 *pBuf;
|
||||
} SCellDecoder;
|
||||
|
||||
static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst);
|
||||
static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2);
|
||||
static int tdbBtreeOpenImpl(SBTree *pBt);
|
||||
static int tdbBtreeInitPage(SPage *pPage, void *arg, int init);
|
||||
|
@ -76,11 +66,10 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
|
|||
static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder);
|
||||
static int tdbBtreeBalance(SBTC *pBtc);
|
||||
static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell);
|
||||
static int tdbBtcMoveToNext(SBTC *pBtc);
|
||||
static int tdbBtcMoveDownward(SBTC *pBtc);
|
||||
static int tdbBtcMoveUpward(SBTC *pBtc);
|
||||
|
||||
int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) {
|
||||
int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, tdb_cmpr_fn_t kcmpr, SBTree **ppBt) {
|
||||
SBTree *pBt;
|
||||
int ret;
|
||||
|
||||
|
@ -165,7 +154,7 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in
|
|||
|
||||
// make sure enough space to hold the cell
|
||||
szBuf = kLen + vLen + 14;
|
||||
pBuf = TDB_REALLOC(pBt->pBuf, pBt->pageSize > szBuf ? szBuf : pBt->pageSize);
|
||||
pBuf = tdbRealloc(pBt->pBuf, pBt->pageSize > szBuf ? szBuf : pBt->pageSize);
|
||||
if (pBuf == NULL) {
|
||||
tdbBtcClose(&btc);
|
||||
ASSERT(0);
|
||||
|
@ -243,7 +232,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
|
|||
tdbBtreeDecodeCell(btc.pPage, pCell, &cd);
|
||||
|
||||
if (ppKey) {
|
||||
pTKey = TDB_REALLOC(*ppKey, cd.kLen);
|
||||
pTKey = tdbRealloc(*ppKey, cd.kLen);
|
||||
if (pTKey == NULL) {
|
||||
tdbBtcClose(&btc);
|
||||
ASSERT(0);
|
||||
|
@ -255,7 +244,7 @@ int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkL
|
|||
}
|
||||
|
||||
if (ppVal) {
|
||||
pTVal = TDB_REALLOC(*ppVal, cd.vLen);
|
||||
pTVal = tdbRealloc(*ppVal, cd.vLen);
|
||||
if (pTVal == NULL) {
|
||||
tdbBtcClose(&btc);
|
||||
ASSERT(0);
|
||||
|
@ -1018,6 +1007,7 @@ int tdbBtcOpen(SBTC *pBtc, SBTree *pBt, TXN *pTxn) {
|
|||
pBtc->iPage = -1;
|
||||
pBtc->pPage = NULL;
|
||||
pBtc->idx = -1;
|
||||
memset(&pBtc->coder, 0, sizeof(SCellDecoder));
|
||||
|
||||
if (pTxn == NULL) {
|
||||
pBtc->pTxn = &pBtc->txn;
|
||||
|
@ -1060,6 +1050,8 @@ int tdbBtcMoveToFirst(SBTC *pBtc) {
|
|||
return 0;
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
#if 0
|
||||
// move from a position
|
||||
int iPage = 0;
|
||||
|
||||
|
@ -1077,6 +1069,7 @@ int tdbBtcMoveToFirst(SBTC *pBtc) {
|
|||
|
||||
tdbBtcMoveUpward(pBtc);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// move downward
|
||||
|
@ -1125,6 +1118,8 @@ int tdbBtcMoveToLast(SBTC *pBtc) {
|
|||
return 0;
|
||||
}
|
||||
} else {
|
||||
ASSERT(0);
|
||||
#if 0
|
||||
int iPage = 0;
|
||||
|
||||
// downward search
|
||||
|
@ -1147,6 +1142,7 @@ int tdbBtcMoveToLast(SBTC *pBtc) {
|
|||
|
||||
tdbBtcMoveUpward(pBtc);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// move downward
|
||||
|
@ -1185,7 +1181,7 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
|
||||
tdbBtreeDecodeCell(pBtc->pPage, pCell, &cd);
|
||||
|
||||
pKey = TDB_REALLOC(*ppKey, cd.kLen);
|
||||
pKey = tdbRealloc(*ppKey, cd.kLen);
|
||||
if (pKey == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -1196,9 +1192,9 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
|
||||
if (ppVal) {
|
||||
// TODO: vLen may be zero
|
||||
pVal = TDB_REALLOC(*ppVal, cd.vLen);
|
||||
pVal = tdbRealloc(*ppVal, cd.vLen);
|
||||
if (pVal == NULL) {
|
||||
TDB_FREE(pKey);
|
||||
tdbFree(pKey);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -1216,7 +1212,7 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tdbBtcMoveToNext(SBTC *pBtc) {
|
||||
int tdbBtcMoveToNext(SBTC *pBtc) {
|
||||
int nCells;
|
||||
int ret;
|
||||
SCell *pCell;
|
||||
|
@ -1262,6 +1258,43 @@ static int tdbBtcMoveToNext(SBTC *pBtc) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtcMoveToPrev(SBTC *pBtc) {
|
||||
if (pBtc->idx < 0) return -1;
|
||||
|
||||
pBtc->idx--;
|
||||
if (pBtc->idx >= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// move upward
|
||||
for (;;) {
|
||||
if (pBtc->iPage == 0) {
|
||||
pBtc->idx = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
tdbBtcMoveUpward(pBtc);
|
||||
pBtc->idx--;
|
||||
if (pBtc->idx >= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// move downward
|
||||
for (;;) {
|
||||
if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) break;
|
||||
|
||||
tdbBtcMoveDownward(pBtc);
|
||||
if (TDB_BTREE_PAGE_IS_LEAF(pBtc->pPage)) {
|
||||
pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage) - 1;
|
||||
} else {
|
||||
pBtc->idx = TDB_PAGE_TOTAL_CELLS(pBtc->pPage);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tdbBtcMoveDownward(SBTC *pBtc) {
|
||||
int ret;
|
||||
SPgno pgno;
|
||||
|
@ -1307,17 +1340,38 @@ static int tdbBtcMoveUpward(SBTC *pBtc) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
|
||||
int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen) {
|
||||
SCell *pCell;
|
||||
|
||||
if (pBtc->idx < 0 || pBtc->idx >= TDB_PAGE_TOTAL_CELLS(pBtc->pPage)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx);
|
||||
tdbBtreeDecodeCell(pBtc->pPage, pCell, &pBtc->coder);
|
||||
|
||||
if (ppKey) {
|
||||
*ppKey = (void *)pBtc->coder.pKey;
|
||||
*kLen = pBtc->coder.kLen;
|
||||
}
|
||||
|
||||
if (ppVal) {
|
||||
*ppVal = (void *)pBtc->coder.pVal;
|
||||
*kLen = pBtc->coder.vLen;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
|
||||
int ret;
|
||||
int nCells;
|
||||
int c;
|
||||
SBTree *pBt;
|
||||
SCell *pCell;
|
||||
SPager *pPager;
|
||||
SCellDecoder cd = {0};
|
||||
|
||||
pBt = pBtc->pBt;
|
||||
pPager = pBt->pPager;
|
||||
SBTree *pBt = pBtc->pBt;
|
||||
SPager *pPager = pBt->pPager;
|
||||
const void *pTKey;
|
||||
int tkLen;
|
||||
|
||||
if (pBtc->iPage < 0) {
|
||||
// move from a clear cursor
|
||||
|
@ -1334,6 +1388,8 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
|
|||
// for empty tree, just return with an invalid position
|
||||
if (TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0) return 0;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
#if 0
|
||||
SPage *pPage;
|
||||
int idx;
|
||||
int iPage = 0;
|
||||
|
@ -1368,11 +1424,12 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
|
|||
if (pBtc->iPage == iPage) break;
|
||||
tdbBtcMoveUpward(pBtc);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// search downward to the leaf
|
||||
for (;;) {
|
||||
int lidx, ridx, midx;
|
||||
int lidx, ridx;
|
||||
SPage *pPage;
|
||||
|
||||
pPage = pBtc->pPage;
|
||||
|
@ -1381,13 +1438,11 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
|
|||
ridx = nCells - 1;
|
||||
|
||||
ASSERT(nCells > 0);
|
||||
ASSERT(pBtc->idx == -1);
|
||||
|
||||
// compare first cell
|
||||
midx = lidx;
|
||||
pCell = tdbPageGetCell(pPage, midx);
|
||||
tdbBtreeDecodeCell(pPage, pCell, &cd);
|
||||
c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen);
|
||||
pBtc->idx = lidx;
|
||||
tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL);
|
||||
c = pBt->kcmpr(pKey, kLen, pTKey, tkLen);
|
||||
if (c <= 0) {
|
||||
ridx = lidx - 1;
|
||||
} else {
|
||||
|
@ -1396,10 +1451,9 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
|
|||
|
||||
// compare last cell
|
||||
if (lidx <= ridx) {
|
||||
midx = ridx;
|
||||
pCell = tdbPageGetCell(pPage, midx);
|
||||
tdbBtreeDecodeCell(pPage, pCell, &cd);
|
||||
c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen);
|
||||
pBtc->idx = ridx;
|
||||
tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL);
|
||||
c = pBt->kcmpr(pKey, kLen, pTKey, tkLen);
|
||||
if (c >= 0) {
|
||||
lidx = ridx + 1;
|
||||
} else {
|
||||
|
@ -1411,24 +1465,15 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
|
|||
for (;;) {
|
||||
if (lidx > ridx) break;
|
||||
|
||||
midx = (lidx + ridx) >> 1;
|
||||
|
||||
pCell = tdbPageGetCell(pPage, midx);
|
||||
ret = tdbBtreeDecodeCell(pPage, pCell, &cd);
|
||||
if (ret < 0) {
|
||||
// TODO: handle error
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Compare the key values
|
||||
c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen);
|
||||
pBtc->idx = (lidx + ridx) >> 1;
|
||||
tdbBtcGet(pBtc, &pTKey, &tkLen, NULL, NULL);
|
||||
c = pBt->kcmpr(pKey, kLen, pTKey, tkLen);
|
||||
if (c < 0) {
|
||||
// pKey < cd.pKey
|
||||
ridx = midx - 1;
|
||||
ridx = pBtc->idx - 1;
|
||||
} else if (c > 0) {
|
||||
// pKey > cd.pKey
|
||||
lidx = midx + 1;
|
||||
lidx = pBtc->idx + 1;
|
||||
} else {
|
||||
// pKey == cd.pKey
|
||||
break;
|
||||
|
@ -1437,14 +1482,11 @@ static int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst) {
|
|||
|
||||
// keep search downward or break
|
||||
if (TDB_BTREE_PAGE_IS_LEAF(pPage)) {
|
||||
pBtc->idx = midx;
|
||||
*pCRst = c;
|
||||
break;
|
||||
} else {
|
||||
if (c <= 0) {
|
||||
pBtc->idx = midx;
|
||||
} else {
|
||||
pBtc->idx = midx + 1;
|
||||
if (c > 0) {
|
||||
pBtc->idx += 1;
|
||||
}
|
||||
tdbBtcMoveDownward(pBtc);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ struct STDBC {
|
|||
SBTC btc;
|
||||
};
|
||||
|
||||
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TENV *pEnv, TDB **ppDb) {
|
||||
int tdbDbOpen(const char *fname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TENV *pEnv, TDB **ppDb) {
|
||||
TDB *pDb;
|
||||
SPager *pPager;
|
||||
int ret;
|
||||
|
@ -75,7 +75,7 @@ int tdbDbDrop(TDB *pDb) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn) {
|
||||
int tdbDbPut(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn) {
|
||||
return tdbBtreeInsert(pDb->pBt, pKey, keyLen, pVal, valLen, pTxn);
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, vo
|
|||
return tdbBtreePGet(pDb->pBt, pKey, kLen, ppKey, pkLen, ppVal, vLen);
|
||||
}
|
||||
|
||||
int tdbDbcOpen(TDB *pDb, TDBC **ppDbc) {
|
||||
int tdbDbcOpen(TDB *pDb, TDBC **ppDbc, TXN *pTxn) {
|
||||
int ret;
|
||||
TDBC *pDbc = NULL;
|
||||
|
||||
|
@ -97,34 +97,53 @@ int tdbDbcOpen(TDB *pDb, TDBC **ppDbc) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
tdbBtcOpen(&pDbc->btc, pDb->pBt, NULL);
|
||||
|
||||
// TODO: move to first now, we can move to any key-value
|
||||
// and in any direction, design new APIs.
|
||||
ret = tdbBtcMoveToFirst(&pDbc->btc);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
tdbBtcOpen(&pDbc->btc, pDb->pBt, pTxn);
|
||||
|
||||
*ppDbc = pDbc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
||||
int tdbDbcMoveTo(TDBC *pDbc, const void *pKey, int kLen, int *c) { return tdbBtcMoveTo(&pDbc->btc, pKey, kLen, c); }
|
||||
|
||||
int tdbDbcMoveToFirst(TDBC *pDbc) { return tdbBtcMoveToFirst(&pDbc->btc); }
|
||||
|
||||
int tdbDbcMoveToLast(TDBC *pDbc) { return tdbBtcMoveToLast(&pDbc->btc); }
|
||||
|
||||
int tdbDbcMoveToNext(TDBC *pDbc) { return tdbBtcMoveToNext(&pDbc->btc); }
|
||||
|
||||
int tdbDbcMoveToPrev(TDBC *pDbc) { return tdbBtcMoveToPrev(&pDbc->btc); }
|
||||
|
||||
int tdbDbcGet(TDBC *pDbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen) {
|
||||
return tdbBtcGet(&pDbc->btc, ppKey, pkLen, ppVal, pvLen);
|
||||
}
|
||||
|
||||
int tdbDbcPut(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbcUpdate(TDBC *pDbc, const void *pKey, int kLen, const void *pVal, int vLen) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbcDrop(TDBC *pDbc) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbcNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
||||
return tdbBtreeNext(&pDbc->btc, ppKey, kLen, ppVal, vLen);
|
||||
}
|
||||
|
||||
int tdbDbcClose(TDBC *pDbc) {
|
||||
if (pDbc) {
|
||||
tdbBtcClose(&pDbc->btc);
|
||||
tdbOsFree(pDbc);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbcInsert(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
#include "tdbInt.h"
|
||||
|
||||
int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv) {
|
||||
int tdbEnvOpen(const char *rootDir, int szPage, int pages, TENV **ppEnv) {
|
||||
TENV *pEnv;
|
||||
int dsize;
|
||||
int zsize;
|
||||
|
@ -49,14 +49,14 @@ int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv) {
|
|||
|
||||
pEnv->jfd = -1;
|
||||
|
||||
ret = tdbPCacheOpen(pageSize, cacheSize, &(pEnv->pCache));
|
||||
ret = tdbPCacheOpen(szPage, pages, &(pEnv->pCache));
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pEnv->nPgrHash = 8;
|
||||
tsize = sizeof(SPager *) * pEnv->nPgrHash;
|
||||
pEnv->pgrHash = TDB_REALLOC(pEnv->pgrHash, tsize);
|
||||
pEnv->pgrHash = tdbRealloc(pEnv->pgrHash, tsize);
|
||||
if (pEnv->pgrHash == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -103,11 +103,6 @@ int tdbCommit(TENV *pEnv, TXN *pTxn) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tdbRollback(TENV *pEnv, TXN *pTxn) {
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SPager *tdbEnvGetPager(TENV *pEnv, const char *fname) {
|
||||
u32 hash;
|
||||
SPager **ppPager;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tdbInt.h"
|
||||
#include "tdbOs.h"
|
||||
|
||||
#ifndef TDB_FOR_TDENGINE
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn)
|
|||
// 1. Search the hash table
|
||||
pPage = pCache->pgHash[tdbPCachePageHash(pPgid) % pCache->nHash];
|
||||
while (pPage) {
|
||||
if (TDB_IS_SAME_PAGE(&(pPage->pgid), pPgid)) break;
|
||||
if (memcmp(pPage->pgid.fileid, pPgid->fileid, TDB_FILE_ID_LEN) == 0 && pPage->pgid.pgno == pPgid->pgno) break;
|
||||
pPage = pPage->pHashNext;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,26 @@
|
|||
|
||||
#include "tdbInt.h"
|
||||
|
||||
void *tdbRealloc(void *ptr, size_t size) {
|
||||
void *nPtr;
|
||||
if ((ptr) == NULL || ((int *)(ptr))[-1] < (size)) {
|
||||
nPtr = tdbOsRealloc((ptr) ? (char *)(ptr) - sizeof(int) : NULL, (size) + sizeof(int));
|
||||
if (nPtr) {
|
||||
((int *)nPtr)[0] = (size);
|
||||
nPtr = (char *)nPtr + sizeof(int);
|
||||
}
|
||||
} else {
|
||||
nPtr = (ptr);
|
||||
}
|
||||
return nPtr;
|
||||
}
|
||||
|
||||
void tdbFree(void *p) {
|
||||
if (p) {
|
||||
tdbOsFree((char *)(p) - sizeof(int));
|
||||
}
|
||||
}
|
||||
|
||||
int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique) {
|
||||
int64_t stDev = 0, stIno = 0;
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_BTREE_H_
|
||||
#define _TD_BTREE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SBTree SBTree;
|
||||
typedef struct SBTC SBTC;
|
||||
typedef struct SBtInfo {
|
||||
SPgno root;
|
||||
int nLevel;
|
||||
int nData;
|
||||
} SBtInfo;
|
||||
|
||||
struct SBTC {
|
||||
SBTree *pBt;
|
||||
i8 iPage;
|
||||
SPage *pPage;
|
||||
int idx;
|
||||
int idxStack[BTREE_MAX_DEPTH + 1];
|
||||
SPage *pgStack[BTREE_MAX_DEPTH + 1];
|
||||
TXN *pTxn;
|
||||
TXN txn;
|
||||
};
|
||||
|
||||
// SBTree
|
||||
int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, FKeyComparator kcmpr, SBTree **ppBt);
|
||||
int tdbBtreeClose(SBTree *pBt);
|
||||
int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn);
|
||||
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen);
|
||||
int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);
|
||||
|
||||
// SBTC
|
||||
int tdbBtcOpen(SBTC *pBtc, SBTree *pBt, TXN *pTxn);
|
||||
int tdbBtcMoveToFirst(SBTC *pBtc);
|
||||
int tdbBtcMoveToLast(SBTC *pBtc);
|
||||
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||
int tdbBtcClose(SBTC *pBtc);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_BTREE_H_*/
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_TDB_DB_H_
|
||||
#define _TD_TDB_DB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct STDB TDB;
|
||||
typedef struct STDBC TDBC;
|
||||
|
||||
// TDB
|
||||
int tdbDbOpen(const char *fname, int keyLen, int valLen, FKeyComparator keyCmprFn, TENV *pEnv, TDB **ppDb);
|
||||
int tdbDbClose(TDB *pDb);
|
||||
int tdbDbDrop(TDB *pDb);
|
||||
int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn);
|
||||
int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen);
|
||||
int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);
|
||||
|
||||
// TDBC
|
||||
int tdbDbcOpen(TDB *pDb, TDBC **ppDbc);
|
||||
int tdbDbNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||
int tdbDbcClose(TDBC *pDbc);
|
||||
int tdbDbcInsert(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_TDB_DB_H_*/
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TDB_ENV_H_
|
||||
#define _TDB_ENV_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct STEnv {
|
||||
char *rootDir;
|
||||
char *jfname;
|
||||
int jfd;
|
||||
SPCache *pCache;
|
||||
SPager *pgrList;
|
||||
int nPager;
|
||||
int nPgrHash;
|
||||
SPager **pgrHash;
|
||||
} TENV;
|
||||
|
||||
int tdbEnvOpen(const char *rootDir, int pageSize, int cacheSize, TENV **ppEnv);
|
||||
int tdbEnvClose(TENV *pEnv);
|
||||
int tdbBegin(TENV *pEnv, TXN *pTxn);
|
||||
int tdbCommit(TENV *pEnv, TXN *pTxn);
|
||||
int tdbRollback(TENV *pEnv, TXN *pTxn);
|
||||
|
||||
void tdbEnvAddPager(TENV *pEnv, SPager *pPager);
|
||||
void tdbEnvRemovePager(TENV *pEnv, SPager *pPager);
|
||||
SPager *tdbEnvGetPager(TENV *pEnv, const char *fname);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TDB_ENV_H_*/
|
|
@ -31,6 +31,12 @@ typedef uint16_t u16;
|
|||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
// SPgno
|
||||
typedef u32 SPgno;
|
||||
|
||||
#include "tdbOs.h"
|
||||
#include "tdbUtil.h"
|
||||
|
||||
// p must be u8 *
|
||||
#define TDB_GET_U24(p) ((p)[0] * 65536 + *(u16 *)((p) + 1))
|
||||
#define TDB_PUT_U24(p, v) \
|
||||
|
@ -41,10 +47,6 @@ typedef uint64_t u64;
|
|||
(p)[0] = (tv >> 16) & 0xff; \
|
||||
} while (0)
|
||||
|
||||
// SPgno
|
||||
typedef u32 SPgno;
|
||||
#define TDB_IVLD_PGNO ((pgno_t)0)
|
||||
|
||||
// fileid
|
||||
#define TDB_FILE_ID_LEN 24
|
||||
|
||||
|
@ -54,51 +56,21 @@ typedef struct {
|
|||
SPgno pgno;
|
||||
} SPgid;
|
||||
|
||||
#define TDB_IVLD_PGID (SPgid){0, TDB_IVLD_PGNO};
|
||||
|
||||
static FORCE_INLINE int tdbCmprPgId(const void *p1, const void *p2) {
|
||||
SPgid *pgid1 = (SPgid *)p1;
|
||||
SPgid *pgid2 = (SPgid *)p2;
|
||||
int rcode;
|
||||
|
||||
rcode = memcmp(pgid1->fileid, pgid2->fileid, TDB_FILE_ID_LEN);
|
||||
if (rcode) {
|
||||
return rcode;
|
||||
} else {
|
||||
if (pgid1->pgno > pgid2->pgno) {
|
||||
return 1;
|
||||
} else if (pgid1->pgno < pgid2->pgno) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define TDB_IS_SAME_PAGE(pPgid1, pPgid2) (tdbCmprPgId(pPgid1, pPgid2) == 0)
|
||||
|
||||
// pgsz_t
|
||||
#define TDB_MIN_PGSIZE 512 // 512B
|
||||
#define TDB_MAX_PGSIZE 16777216 // 16M
|
||||
#define TDB_DEFAULT_PGSIZE 4096
|
||||
#define TDB_IS_PGSIZE_VLD(s) (((s) >= TDB_MIN_PGSIZE) && ((s) <= TDB_MAX_PGSIZE))
|
||||
|
||||
// cache
|
||||
#define TDB_DEFAULT_CACHE_SIZE (256 * 4096) // 1M
|
||||
|
||||
// dbname
|
||||
#define TDB_MAX_DBNAME_LEN 24
|
||||
|
||||
#define TDB_VARIANT_LEN ((int)-1)
|
||||
|
||||
typedef int (*FKeyComparator)(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||
|
||||
#define TDB_JOURNAL_NAME "tdb.journal"
|
||||
|
||||
#define TDB_FILENAME_LEN 128
|
||||
|
||||
#define TDB_DEFAULT_FANOUT 6
|
||||
|
||||
#define BTREE_MAX_DEPTH 20
|
||||
|
||||
#define TDB_FLAG_IS(flags, flag) ((flags) == (flag))
|
||||
|
@ -112,37 +84,253 @@ typedef struct SPCache SPCache;
|
|||
typedef struct SPage SPage;
|
||||
|
||||
// transaction
|
||||
#define TDB_TXN_WRITE 0x1
|
||||
#define TDB_TXN_READ_UNCOMMITTED 0x2
|
||||
typedef struct STxn {
|
||||
int flags;
|
||||
i64 txnId;
|
||||
void *(*xMalloc)(void *, size_t);
|
||||
void (*xFree)(void *, void *);
|
||||
void *xArg;
|
||||
} TXN;
|
||||
|
||||
#define TDB_TXN_IS_WRITE(PTXN) ((PTXN)->flags & TDB_TXN_WRITE)
|
||||
#define TDB_TXN_IS_READ(PTXN) (!TDB_TXN_IS_WRITE(PTXN))
|
||||
#define TDB_TXN_IS_READ_UNCOMMITTED(PTXN) ((PTXN)->flags & TDB_TXN_READ_UNCOMMITTED)
|
||||
|
||||
#include "tdbOs.h"
|
||||
// tdbEnv.c ====================================
|
||||
void tdbEnvAddPager(TENV *pEnv, SPager *pPager);
|
||||
void tdbEnvRemovePager(TENV *pEnv, SPager *pPager);
|
||||
SPager *tdbEnvGetPager(TENV *pEnv, const char *fname);
|
||||
|
||||
#include "tdbUtil.h"
|
||||
// tdbBtree.c ====================================
|
||||
typedef struct SBTree SBTree;
|
||||
typedef struct SBTC SBTC;
|
||||
typedef struct SBtInfo {
|
||||
SPgno root;
|
||||
int nLevel;
|
||||
int nData;
|
||||
} SBtInfo;
|
||||
|
||||
#include "tdbPCache.h"
|
||||
typedef struct {
|
||||
int kLen;
|
||||
const u8 *pKey;
|
||||
int vLen;
|
||||
const u8 *pVal;
|
||||
SPgno pgno;
|
||||
u8 *pBuf;
|
||||
} SCellDecoder;
|
||||
|
||||
#include "tdbPager.h"
|
||||
struct SBTC {
|
||||
SBTree *pBt;
|
||||
i8 iPage;
|
||||
SPage *pPage;
|
||||
int idx;
|
||||
int idxStack[BTREE_MAX_DEPTH + 1];
|
||||
SPage *pgStack[BTREE_MAX_DEPTH + 1];
|
||||
SCellDecoder coder;
|
||||
TXN *pTxn;
|
||||
TXN txn;
|
||||
};
|
||||
|
||||
#include "tdbBtree.h"
|
||||
// SBTree
|
||||
int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, tdb_cmpr_fn_t kcmpr, SBTree **ppBt);
|
||||
int tdbBtreeClose(SBTree *pBt);
|
||||
int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn);
|
||||
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen);
|
||||
int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);
|
||||
|
||||
#include "tdbEnv.h"
|
||||
// SBTC
|
||||
int tdbBtcOpen(SBTC *pBtc, SBTree *pBt, TXN *pTxn);
|
||||
int tdbBtcClose(SBTC *pBtc);
|
||||
int tdbBtcMoveTo(SBTC *pBtc, const void *pKey, int kLen, int *pCRst);
|
||||
int tdbBtcMoveToFirst(SBTC *pBtc);
|
||||
int tdbBtcMoveToLast(SBTC *pBtc);
|
||||
int tdbBtcMoveToNext(SBTC *pBtc);
|
||||
int tdbBtcMoveToPrev(SBTC *pBtc);
|
||||
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||
int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen);
|
||||
|
||||
#include "tdbDb.h"
|
||||
// tdbPager.c ====================================
|
||||
|
||||
#include "tdbPage.h"
|
||||
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager);
|
||||
int tdbPagerClose(SPager *pPager);
|
||||
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate);
|
||||
int tdbPagerWrite(SPager *pPager, SPage *pPage);
|
||||
int tdbPagerBegin(SPager *pPager, TXN *pTxn);
|
||||
int tdbPagerCommit(SPager *pPager, TXN *pTxn);
|
||||
int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *, int), void *arg,
|
||||
TXN *pTxn);
|
||||
void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn);
|
||||
int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno);
|
||||
|
||||
#include "tdbTxn.h"
|
||||
// tdbPCache.c ====================================
|
||||
#define TDB_PCACHE_PAGE \
|
||||
u8 isAnchor; \
|
||||
u8 isLocal; \
|
||||
u8 isDirty; \
|
||||
i32 nRef; \
|
||||
SPage *pCacheNext; \
|
||||
SPage *pFreeNext; \
|
||||
SPage *pHashNext; \
|
||||
SPage *pLruNext; \
|
||||
SPage *pLruPrev; \
|
||||
SPage *pDirtyNext; \
|
||||
SPager *pPager; \
|
||||
SPgid pgid;
|
||||
|
||||
// For page ref
|
||||
#define TDB_INIT_PAGE_REF(pPage) ((pPage)->nRef = 0)
|
||||
#define TDB_REF_PAGE(pPage) atomic_add_fetch_32(&((pPage)->nRef), 1)
|
||||
#define TDB_UNREF_PAGE(pPage) atomic_sub_fetch_32(&((pPage)->nRef), 1)
|
||||
#define TDB_GET_PAGE_REF(pPage) atomic_load_32(&((pPage)->nRef))
|
||||
|
||||
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache);
|
||||
int tdbPCacheClose(SPCache *pCache);
|
||||
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn);
|
||||
void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn);
|
||||
int tdbPCacheGetPageSize(SPCache *pCache);
|
||||
|
||||
// tdbPage.c ====================================
|
||||
typedef u8 SCell;
|
||||
|
||||
// PAGE APIS implemented
|
||||
typedef struct {
|
||||
int szOffset;
|
||||
int szPageHdr;
|
||||
int szFreeCell;
|
||||
// cell number
|
||||
int (*getCellNum)(SPage *);
|
||||
void (*setCellNum)(SPage *, int);
|
||||
// cell content offset
|
||||
int (*getCellBody)(SPage *);
|
||||
void (*setCellBody)(SPage *, int);
|
||||
// first free cell offset (0 means no free cells)
|
||||
int (*getCellFree)(SPage *);
|
||||
void (*setCellFree)(SPage *, int);
|
||||
// total free bytes
|
||||
int (*getFreeBytes)(SPage *);
|
||||
void (*setFreeBytes)(SPage *, int);
|
||||
// cell offset at idx
|
||||
int (*getCellOffset)(SPage *, int);
|
||||
void (*setCellOffset)(SPage *, int, int);
|
||||
// free cell info
|
||||
void (*getFreeCellInfo)(SCell *pCell, int *szCell, int *nxOffset);
|
||||
void (*setFreeCellInfo)(SCell *pCell, int szCell, int nxOffset);
|
||||
} SPageMethods;
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
// Page footer
|
||||
typedef struct {
|
||||
u8 cksm[4];
|
||||
} SPageFtr;
|
||||
#pragma pack(pop)
|
||||
|
||||
struct SPage {
|
||||
tdb_spinlock_t lock;
|
||||
int pageSize;
|
||||
u8 *pData;
|
||||
SPageMethods *pPageMethods;
|
||||
// Fields below used by pager and am
|
||||
u8 *pPageHdr;
|
||||
u8 *pCellIdx;
|
||||
u8 *pFreeStart;
|
||||
u8 *pFreeEnd;
|
||||
SPageFtr *pPageFtr;
|
||||
int nOverflow;
|
||||
SCell *apOvfl[4];
|
||||
int aiOvfl[4];
|
||||
int kLen; // key length of the page, -1 for unknown
|
||||
int vLen; // value length of the page, -1 for unknown
|
||||
int maxLocal;
|
||||
int minLocal;
|
||||
int (*xCellSize)(const SPage *, SCell *);
|
||||
// Fields used by SPCache
|
||||
TDB_PCACHE_PAGE
|
||||
};
|
||||
|
||||
// For page lock
|
||||
#define P_LOCK_SUCC 0
|
||||
#define P_LOCK_BUSY 1
|
||||
#define P_LOCK_FAIL -1
|
||||
|
||||
static inline int tdbTryLockPage(tdb_spinlock_t *pLock) {
|
||||
int ret;
|
||||
if (tdbSpinlockTrylock(pLock) == 0) {
|
||||
ret = P_LOCK_SUCC;
|
||||
} else if (errno == EBUSY) {
|
||||
ret = P_LOCK_BUSY;
|
||||
} else {
|
||||
ret = P_LOCK_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0)
|
||||
#define TDB_DESTROY_PAGE_LOCK(pPage) tdbSpinlockDestroy(&((pPage)->lock))
|
||||
#define TDB_LOCK_PAGE(pPage) tdbSpinlockLock(&((pPage)->lock))
|
||||
#define TDB_UNLOCK_PAGE(pPage) tdbSpinlockUnlock(&((pPage)->lock))
|
||||
#define TDB_TRY_LOCK_PAGE(pPage) tdbTryLockPage(&((pPage)->lock))
|
||||
|
||||
// APIs
|
||||
#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage))
|
||||
#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx)
|
||||
#define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage)
|
||||
#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno)
|
||||
#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset)
|
||||
#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset)
|
||||
|
||||
int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg);
|
||||
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg);
|
||||
void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *));
|
||||
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *));
|
||||
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl);
|
||||
int tdbPageDropCell(SPage *pPage, int idx);
|
||||
void tdbPageCopy(SPage *pFromPage, SPage *pToPage);
|
||||
int tdbPageCapacity(int pageSize, int amHdrSize);
|
||||
|
||||
static inline SCell *tdbPageGetCell(SPage *pPage, int idx) {
|
||||
SCell *pCell;
|
||||
int iOvfl;
|
||||
int lidx;
|
||||
|
||||
ASSERT(idx >= 0 && idx < TDB_PAGE_TOTAL_CELLS(pPage));
|
||||
|
||||
iOvfl = 0;
|
||||
for (; iOvfl < pPage->nOverflow; iOvfl++) {
|
||||
if (pPage->aiOvfl[iOvfl] == idx) {
|
||||
pCell = pPage->apOvfl[iOvfl];
|
||||
return pCell;
|
||||
} else if (pPage->aiOvfl[iOvfl] > idx) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lidx = idx - iOvfl;
|
||||
ASSERT(lidx >= 0 && lidx < pPage->pPageMethods->getCellNum(pPage));
|
||||
pCell = pPage->pData + pPage->pPageMethods->getCellOffset(pPage, lidx);
|
||||
|
||||
return pCell;
|
||||
}
|
||||
|
||||
struct STEnv {
|
||||
char *rootDir;
|
||||
char *jfname;
|
||||
int jfd;
|
||||
SPCache *pCache;
|
||||
SPager *pgrList;
|
||||
int nPager;
|
||||
int nPgrHash;
|
||||
SPager **pgrHash;
|
||||
};
|
||||
|
||||
struct SPager {
|
||||
char *dbFileName;
|
||||
char *jFileName;
|
||||
int pageSize;
|
||||
uint8_t fid[TDB_FILE_ID_LEN];
|
||||
tdb_fd_t fd;
|
||||
tdb_fd_t jfd;
|
||||
SPCache *pCache;
|
||||
SPgno dbFileSize;
|
||||
SPgno dbOrigSize;
|
||||
SPage *pDirty;
|
||||
u8 inTran;
|
||||
SPager *pNext; // used by TENV
|
||||
SPager *pHashNext; // used by TENV
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_PAGE_CACHE_H_
|
||||
#define _TD_PAGE_CACHE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define TDB_PCACHE_PAGE \
|
||||
u8 isAnchor; \
|
||||
u8 isLocal; \
|
||||
u8 isDirty; \
|
||||
i32 nRef; \
|
||||
SPage *pCacheNext; \
|
||||
SPage *pFreeNext; \
|
||||
SPage *pHashNext; \
|
||||
SPage *pLruNext; \
|
||||
SPage *pLruPrev; \
|
||||
SPage *pDirtyNext; \
|
||||
SPager *pPager; \
|
||||
SPgid pgid;
|
||||
|
||||
// For page ref
|
||||
#define TDB_INIT_PAGE_REF(pPage) ((pPage)->nRef = 0)
|
||||
#if 0
|
||||
#define TDB_REF_PAGE(pPage) (++(pPage)->nRef)
|
||||
#define TDB_UNREF_PAGE(pPage) (--(pPage)->nRef)
|
||||
#define TDB_GET_PAGE_REF(pPage) ((pPage)->nRef)
|
||||
#else
|
||||
#define TDB_REF_PAGE(pPage) atomic_add_fetch_32(&((pPage)->nRef), 1)
|
||||
#define TDB_UNREF_PAGE(pPage) atomic_sub_fetch_32(&((pPage)->nRef), 1)
|
||||
#define TDB_GET_PAGE_REF(pPage) atomic_load_32(&((pPage)->nRef))
|
||||
#endif
|
||||
|
||||
int tdbPCacheOpen(int pageSize, int cacheSize, SPCache **ppCache);
|
||||
int tdbPCacheClose(SPCache *pCache);
|
||||
SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn);
|
||||
void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn);
|
||||
int tdbPCacheGetPageSize(SPCache *pCache);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_PAGE_CACHE_H_*/
|
|
@ -1,149 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TDB_PAGE_H_
|
||||
#define _TDB_PAGE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef u8 SCell;
|
||||
|
||||
// PAGE APIS implemented
|
||||
typedef struct {
|
||||
int szOffset;
|
||||
int szPageHdr;
|
||||
int szFreeCell;
|
||||
// cell number
|
||||
int (*getCellNum)(SPage *);
|
||||
void (*setCellNum)(SPage *, int);
|
||||
// cell content offset
|
||||
int (*getCellBody)(SPage *);
|
||||
void (*setCellBody)(SPage *, int);
|
||||
// first free cell offset (0 means no free cells)
|
||||
int (*getCellFree)(SPage *);
|
||||
void (*setCellFree)(SPage *, int);
|
||||
// total free bytes
|
||||
int (*getFreeBytes)(SPage *);
|
||||
void (*setFreeBytes)(SPage *, int);
|
||||
// cell offset at idx
|
||||
int (*getCellOffset)(SPage *, int);
|
||||
void (*setCellOffset)(SPage *, int, int);
|
||||
// free cell info
|
||||
void (*getFreeCellInfo)(SCell *pCell, int *szCell, int *nxOffset);
|
||||
void (*setFreeCellInfo)(SCell *pCell, int szCell, int nxOffset);
|
||||
} SPageMethods;
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
||||
// Page footer
|
||||
typedef struct {
|
||||
u8 cksm[4];
|
||||
} SPageFtr;
|
||||
#pragma pack(pop)
|
||||
|
||||
struct SPage {
|
||||
tdb_spinlock_t lock;
|
||||
int pageSize;
|
||||
u8 *pData;
|
||||
SPageMethods *pPageMethods;
|
||||
// Fields below used by pager and am
|
||||
u8 *pPageHdr;
|
||||
u8 *pCellIdx;
|
||||
u8 *pFreeStart;
|
||||
u8 *pFreeEnd;
|
||||
SPageFtr *pPageFtr;
|
||||
int nOverflow;
|
||||
SCell *apOvfl[4];
|
||||
int aiOvfl[4];
|
||||
int kLen; // key length of the page, -1 for unknown
|
||||
int vLen; // value length of the page, -1 for unknown
|
||||
int maxLocal;
|
||||
int minLocal;
|
||||
int (*xCellSize)(const SPage *, SCell *);
|
||||
// Fields used by SPCache
|
||||
TDB_PCACHE_PAGE
|
||||
};
|
||||
|
||||
// For page lock
|
||||
#define P_LOCK_SUCC 0
|
||||
#define P_LOCK_BUSY 1
|
||||
#define P_LOCK_FAIL -1
|
||||
|
||||
static inline int tdbTryLockPage(tdb_spinlock_t *pLock) {
|
||||
int ret;
|
||||
if (tdbSpinlockTrylock(pLock) == 0) {
|
||||
ret = P_LOCK_SUCC;
|
||||
} else if (errno == EBUSY) {
|
||||
ret = P_LOCK_BUSY;
|
||||
} else {
|
||||
ret = P_LOCK_FAIL;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0)
|
||||
#define TDB_DESTROY_PAGE_LOCK(pPage) tdbSpinlockDestroy(&((pPage)->lock))
|
||||
#define TDB_LOCK_PAGE(pPage) tdbSpinlockLock(&((pPage)->lock))
|
||||
#define TDB_UNLOCK_PAGE(pPage) tdbSpinlockUnlock(&((pPage)->lock))
|
||||
#define TDB_TRY_LOCK_PAGE(pPage) tdbTryLockPage(&((pPage)->lock))
|
||||
|
||||
// APIs
|
||||
#define TDB_PAGE_TOTAL_CELLS(pPage) ((pPage)->nOverflow + (pPage)->pPageMethods->getCellNum(pPage))
|
||||
#define TDB_PAGE_USABLE_SIZE(pPage) ((u8 *)(pPage)->pPageFtr - (pPage)->pCellIdx)
|
||||
#define TDB_PAGE_FREE_SIZE(pPage) (*(pPage)->pPageMethods->getFreeBytes)(pPage)
|
||||
#define TDB_PAGE_PGNO(pPage) ((pPage)->pgid.pgno)
|
||||
#define TDB_BYTES_CELL_TAKEN(pPage, pCell) ((*(pPage)->xCellSize)(pPage, pCell) + (pPage)->pPageMethods->szOffset)
|
||||
#define TDB_PAGE_OFFSET_SIZE(pPage) ((pPage)->pPageMethods->szOffset)
|
||||
|
||||
int tdbPageCreate(int pageSize, SPage **ppPage, void *(*xMalloc)(void *, size_t), void *arg);
|
||||
int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg);
|
||||
void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *));
|
||||
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *));
|
||||
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl);
|
||||
int tdbPageDropCell(SPage *pPage, int idx);
|
||||
void tdbPageCopy(SPage *pFromPage, SPage *pToPage);
|
||||
int tdbPageCapacity(int pageSize, int amHdrSize);
|
||||
|
||||
static inline SCell *tdbPageGetCell(SPage *pPage, int idx) {
|
||||
SCell *pCell;
|
||||
int iOvfl;
|
||||
int lidx;
|
||||
|
||||
ASSERT(idx >= 0 && idx < TDB_PAGE_TOTAL_CELLS(pPage));
|
||||
|
||||
iOvfl = 0;
|
||||
for (; iOvfl < pPage->nOverflow; iOvfl++) {
|
||||
if (pPage->aiOvfl[iOvfl] == idx) {
|
||||
pCell = pPage->apOvfl[iOvfl];
|
||||
return pCell;
|
||||
} else if (pPage->aiOvfl[iOvfl] > idx) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
lidx = idx - iOvfl;
|
||||
ASSERT(lidx >= 0 && lidx < pPage->pPageMethods->getCellNum(pPage));
|
||||
pCell = pPage->pData + pPage->pPageMethods->getCellOffset(pPage, lidx);
|
||||
|
||||
return pCell;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TDB_PAGE_H_*/
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TDB_PAGER_H_
|
||||
#define _TDB_PAGER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct SPager {
|
||||
char *dbFileName;
|
||||
char *jFileName;
|
||||
int pageSize;
|
||||
uint8_t fid[TDB_FILE_ID_LEN];
|
||||
tdb_fd_t fd;
|
||||
tdb_fd_t jfd;
|
||||
SPCache *pCache;
|
||||
SPgno dbFileSize;
|
||||
SPgno dbOrigSize;
|
||||
SPage *pDirty;
|
||||
u8 inTran;
|
||||
SPager *pNext; // used by TENV
|
||||
SPager *pHashNext; // used by TENV
|
||||
};
|
||||
|
||||
int tdbPagerOpen(SPCache *pCache, const char *fileName, SPager **ppPager);
|
||||
int tdbPagerClose(SPager *pPager);
|
||||
int tdbPagerOpenDB(SPager *pPager, SPgno *ppgno, bool toCreate);
|
||||
int tdbPagerWrite(SPager *pPager, SPage *pPage);
|
||||
int tdbPagerBegin(SPager *pPager, TXN *pTxn);
|
||||
int tdbPagerCommit(SPager *pPager, TXN *pTxn);
|
||||
int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPage)(SPage *, void *, int), void *arg,
|
||||
TXN *pTxn);
|
||||
void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn);
|
||||
int tdbPagerAllocPage(SPager *pPager, SPgno *ppgno);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TDB_PAGER_H_*/
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TDB_TXN_H_
|
||||
#define _TDB_TXN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int tdbTxnOpen(TXN *pTxn, int64_t txnid, void *(*xMalloc)(void *, size_t), void (*xFree)(void *, void *), void *xArg,
|
||||
int flags);
|
||||
int tdbTxnClose(TXN *pTxn);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TDB_TXN_H_*/
|
|
@ -31,27 +31,7 @@ extern "C" {
|
|||
int tdbGnrtFileID(const char *fname, uint8_t *fileid, bool unique);
|
||||
int tdbGetFileSize(tdb_fd_t fd, int szPage, SPgno *size);
|
||||
|
||||
static inline void *tdbRealloc(void *ptr, size_t size) {
|
||||
void *nPtr;
|
||||
if ((ptr) == NULL || ((int *)(ptr))[-1] < (size)) {
|
||||
nPtr = tdbOsRealloc((ptr) ? (char *)(ptr) - sizeof(int) : NULL, (size) + sizeof(int));
|
||||
if (nPtr) {
|
||||
((int *)nPtr)[0] = (size);
|
||||
nPtr = (char *)nPtr + sizeof(int);
|
||||
}
|
||||
} else {
|
||||
nPtr = (ptr);
|
||||
}
|
||||
return nPtr;
|
||||
}
|
||||
#define TDB_REALLOC(PTR, SIZE) tdbRealloc(PTR, SIZE)
|
||||
|
||||
#define TDB_FREE(PTR) \
|
||||
do { \
|
||||
if (PTR) { \
|
||||
tdbOsFree((char *)(PTR) - sizeof(int)); \
|
||||
} \
|
||||
} while (0)
|
||||
void *tdbRealloc(void *ptr, size_t size);
|
||||
|
||||
static inline void *tdbDefaultMalloc(void *arg, size_t size) {
|
||||
void *ptr;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include "os.h"
|
||||
#include "tdbInt.h"
|
||||
#include "tdb.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
|
@ -12,7 +12,7 @@ typedef struct SPoolMem {
|
|||
} SPoolMem;
|
||||
|
||||
static SPoolMem *openPool() {
|
||||
SPoolMem *pPool = (SPoolMem *)tdbOsMalloc(sizeof(*pPool));
|
||||
SPoolMem *pPool = (SPoolMem *)taosMemoryMalloc(sizeof(*pPool));
|
||||
|
||||
pPool->prev = pPool->next = pPool;
|
||||
pPool->size = 0;
|
||||
|
@ -32,7 +32,7 @@ static void clearPool(SPoolMem *pPool) {
|
|||
pMem->prev->next = pMem->next;
|
||||
pPool->size -= pMem->size;
|
||||
|
||||
tdbOsFree(pMem);
|
||||
taosMemoryFree(pMem);
|
||||
} while (1);
|
||||
|
||||
assert(pPool->size == 0);
|
||||
|
@ -40,7 +40,7 @@ static void clearPool(SPoolMem *pPool) {
|
|||
|
||||
static void closePool(SPoolMem *pPool) {
|
||||
clearPool(pPool);
|
||||
tdbOsFree(pPool);
|
||||
taosMemoryFree(pPool);
|
||||
}
|
||||
|
||||
static void *poolMalloc(void *arg, size_t size) {
|
||||
|
@ -48,7 +48,7 @@ static void *poolMalloc(void *arg, size_t size) {
|
|||
SPoolMem *pPool = (SPoolMem *)arg;
|
||||
SPoolMem *pMem;
|
||||
|
||||
pMem = (SPoolMem *)tdbOsMalloc(sizeof(*pMem) + size);
|
||||
pMem = (SPoolMem *)taosMemoryMalloc(sizeof(*pMem) + size);
|
||||
if (pMem == NULL) {
|
||||
assert(0);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ static void poolFree(void *arg, void *ptr) {
|
|||
pMem->prev->next = pMem->next;
|
||||
pPool->size -= pMem->size;
|
||||
|
||||
tdbOsFree(pMem);
|
||||
taosMemoryFree(pMem);
|
||||
}
|
||||
|
||||
static int tKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||
|
@ -119,7 +119,7 @@ TEST(tdb_test, simple_test) {
|
|||
int ret;
|
||||
TENV *pEnv;
|
||||
TDB *pDb;
|
||||
FKeyComparator compFunc;
|
||||
tdb_cmpr_fn_t compFunc;
|
||||
int nData = 10000000;
|
||||
TXN txn;
|
||||
|
||||
|
@ -131,7 +131,7 @@ TEST(tdb_test, simple_test) {
|
|||
|
||||
// Create a database
|
||||
compFunc = tKeyCmpr;
|
||||
ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, compFunc, pEnv, &pDb);
|
||||
ret = tdbDbOpen("db.db", -1, -1, compFunc, pEnv, &pDb);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
{
|
||||
|
@ -152,7 +152,7 @@ TEST(tdb_test, simple_test) {
|
|||
for (int iData = 1; iData <= nData; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(val, "value%d", iData);
|
||||
ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val), &txn);
|
||||
ret = tdbDbPut(pDb, key, strlen(key), val, strlen(val), &txn);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
// if pool is full, commit the transaction and start a new one
|
||||
|
@ -189,7 +189,7 @@ TEST(tdb_test, simple_test) {
|
|||
GTEST_ASSERT_EQ(memcmp(val, pVal, vLen), 0);
|
||||
}
|
||||
|
||||
TDB_FREE(pVal);
|
||||
tdbFree(pVal);
|
||||
}
|
||||
|
||||
{ // Iterate to query the DB data
|
||||
|
@ -199,11 +199,11 @@ TEST(tdb_test, simple_test) {
|
|||
int vLen, kLen;
|
||||
int count = 0;
|
||||
|
||||
ret = tdbDbcOpen(pDb, &pDBC);
|
||||
ret = tdbDbcOpen(pDb, &pDBC, NULL);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
for (;;) {
|
||||
ret = tdbDbNext(pDBC, &pKey, &kLen, &pVal, &vLen);
|
||||
ret = tdbDbcNext(pDBC, &pKey, &kLen, &pVal, &vLen);
|
||||
if (ret < 0) break;
|
||||
|
||||
// std::cout.write((char *)pKey, kLen) /* << " " << kLen */ << " ";
|
||||
|
@ -217,8 +217,8 @@ TEST(tdb_test, simple_test) {
|
|||
|
||||
tdbDbcClose(pDBC);
|
||||
|
||||
TDB_FREE(pKey);
|
||||
TDB_FREE(pVal);
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -237,7 +237,7 @@ TEST(tdb_test, simple_test2) {
|
|||
int ret;
|
||||
TENV *pEnv;
|
||||
TDB *pDb;
|
||||
FKeyComparator compFunc;
|
||||
tdb_cmpr_fn_t compFunc;
|
||||
int nData = 1000000;
|
||||
TXN txn;
|
||||
|
||||
|
@ -249,7 +249,7 @@ TEST(tdb_test, simple_test2) {
|
|||
|
||||
// Create a database
|
||||
compFunc = tDefaultKeyCmpr;
|
||||
ret = tdbDbOpen("db.db", TDB_VARIANT_LEN, TDB_VARIANT_LEN, compFunc, pEnv, &pDb);
|
||||
ret = tdbDbOpen("db.db", -1, -1, compFunc, pEnv, &pDb);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
{
|
||||
|
@ -269,7 +269,7 @@ TEST(tdb_test, simple_test2) {
|
|||
for (int iData = 1; iData <= nData; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(val, "value%d", iData);
|
||||
ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val), &txn);
|
||||
ret = tdbDbPut(pDb, key, strlen(key), val, strlen(val), &txn);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
|
@ -280,11 +280,11 @@ TEST(tdb_test, simple_test2) {
|
|||
int vLen, kLen;
|
||||
int count = 0;
|
||||
|
||||
ret = tdbDbcOpen(pDb, &pDBC);
|
||||
ret = tdbDbcOpen(pDb, &pDBC, NULL);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
for (;;) {
|
||||
ret = tdbDbNext(pDBC, &pKey, &kLen, &pVal, &vLen);
|
||||
ret = tdbDbcNext(pDBC, &pKey, &kLen, &pVal, &vLen);
|
||||
if (ret < 0) break;
|
||||
|
||||
std::cout.write((char *)pKey, kLen) /* << " " << kLen */ << " ";
|
||||
|
@ -298,8 +298,8 @@ TEST(tdb_test, simple_test2) {
|
|||
|
||||
tdbDbcClose(pDBC);
|
||||
|
||||
TDB_FREE(pKey);
|
||||
TDB_FREE(pVal);
|
||||
tdbFree(pKey);
|
||||
tdbFree(pVal);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tdbInt.h"
|
||||
#include "tdb.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
TEST(tdb_util_test, simple_test) {
|
||||
int vEncode = 5000;
|
||||
int vDecode;
|
||||
int nEncode;
|
||||
int nDecode;
|
||||
u8 buffer[128];
|
||||
// int vEncode = 5000;
|
||||
// int vDecode;
|
||||
// int nEncode;
|
||||
// int nDecode;
|
||||
// uint8_t buffer[128];
|
||||
|
||||
nEncode = tdbPutVarInt(buffer, vEncode);
|
||||
// nEncode = tdbPutVarInt(buffer, vEncode);
|
||||
|
||||
nDecode = tdbGetVarInt(buffer, &vDecode);
|
||||
// nDecode = tdbGetVarInt(buffer, &vDecode);
|
||||
|
||||
GTEST_ASSERT_EQ(nEncode, nDecode);
|
||||
GTEST_ASSERT_EQ(vEncode, vDecode);
|
||||
// GTEST_ASSERT_EQ(nEncode, nDecode);
|
||||
// GTEST_ASSERT_EQ(vEncode, vDecode);
|
||||
}
|
|
@ -317,6 +317,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_TSDB_STATE, "Invalid tsdb state")
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_TB_NOT_EXIST, "Table not exists")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_SMA_NOT_EXIST, "SMA not exists")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_HASH_MISMATCH, "Hash value mismatch")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_VND_TABLE_NOT_EXIST, "Table does not exists")
|
||||
|
||||
// tsdb
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_TDB_INVALID_TABLE_ID, "Invalid table ID")
|
||||
|
|
Loading…
Reference in New Issue