提交 82ad9a91 编写于 作者: S Shengliang Guan

transaction object

上级 622cdc39
......@@ -23,8 +23,7 @@
extern "C" {
#endif
typedef struct {
} STrans;
typedef struct STrans STrans;
int32_t trnInit();
void trnCleanup();
......@@ -33,11 +32,11 @@ STrans *trnCreate();
int32_t trnCommit(STrans *);
void trnDrop(STrans *);
void trnAppendRedoLog(STrans *, SSdbRawData *);
void trnAppendUndoLog(STrans *, SSdbRawData *);
void trnAppendCommitLog(STrans *, SSdbRawData *);
void trnAppendRedoAction(STrans *, SEpSet *, void *pMsg);
void trnAppendUndoAction(STrans *, SEpSet *, void *pMsg);
int32_t trnAppendRedoLog(STrans *, SSdbRawData *);
int32_t trnAppendUndoLog(STrans *, SSdbRawData *);
int32_t trnAppendCommitLog(STrans *, SSdbRawData *);
int32_t trnAppendRedoAction(STrans *, SEpSet *, void *pMsg);
int32_t trnAppendUndoAction(STrans *, SEpSet *, void *pMsg);
#ifdef __cplusplus
}
......
......@@ -19,6 +19,7 @@
#include "os.h"
#include "trn.h"
#include "tglobal.h"
#include "tarray.h"
#include "tlog.h"
#ifdef __cplusplus
......@@ -32,6 +33,14 @@ extern "C" {
#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", mDebugFlag, __VA_ARGS__); }}
typedef struct STrans {
SArray *redoLogs;
SArray *undoLogs;
SArray *commitLogs;
SArray *redoActions;
SArray *undoActions;
} STrans;
#ifdef __cplusplus
}
#endif
......
......@@ -16,15 +16,78 @@
#define _DEFAULT_SOURCE
#include "trnInt.h"
#define TRN_DEFAULT_ARRAY_SIZE 8
int32_t trnInit() { return 0; }
void trnCleanup();
STrans *trnCreate() { return NULL; }
STrans *trnCreate() {
STrans *pTrans = calloc(1, sizeof(STrans));
if (pTrans == NULL) {
terrno = TSDB_CODE_MND_OUT_OF_MEMORY;
return NULL;
}
pTrans->redoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
pTrans->undoLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
pTrans->commitLogs = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
pTrans->redoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
pTrans->undoActions = taosArrayInit(TRN_DEFAULT_ARRAY_SIZE, sizeof(void *));
if (pTrans->redoLogs == NULL || pTrans->undoLogs == NULL || pTrans->commitLogs == NULL ||
pTrans->redoActions == NULL || pTrans->undoActions == NULL) {
taosArrayDestroy(pTrans->redoLogs);
taosArrayDestroy(pTrans->undoLogs);
taosArrayDestroy(pTrans->commitLogs);
taosArrayDestroy(pTrans->redoActions);
taosArrayDestroy(pTrans->undoActions);
free(pTrans);
terrno = TSDB_CODE_MND_OUT_OF_MEMORY;
return NULL;
}
return pTrans;
}
int32_t trnCommit(STrans *pTrans) { return 0; }
void trnDrop(STrans *pTrans) {}
void trnAppendRedoLog(STrans *pTrans, SSdbRawData *pRaw) {}
void trnAppendUndoLog(STrans *pTrans, SSdbRawData *pRaw) {}
void trnAppendCommitLog(STrans *pTrans, SSdbRawData *pRaw) {}
void trnAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {}
void trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {}
int32_t trnAppendRedoLog(STrans *pTrans, SSdbRawData *pRaw) {
void *ptr = taosArrayPush(pTrans->redoLogs, &pRaw);
if (ptr == NULL) {
return TSDB_CODE_MND_OUT_OF_MEMORY;
}
return 0;
}
int32_t trnAppendUndoLog(STrans *pTrans, SSdbRawData *pRaw) {
void *ptr = taosArrayPush(pTrans->undoLogs, &pRaw);
if (ptr == NULL) {
return TSDB_CODE_MND_OUT_OF_MEMORY;
}
return 0;
}
int32_t trnAppendCommitLog(STrans *pTrans, SSdbRawData *pRaw) {
void *ptr = taosArrayPush(pTrans->commitLogs, &pRaw);
if (ptr == NULL) {
return TSDB_CODE_MND_OUT_OF_MEMORY;
}
return 0;
}
int32_t trnAppendRedoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
void *ptr = taosArrayPush(pTrans->redoActions, &pMsg);
if (ptr == NULL) {
return TSDB_CODE_MND_OUT_OF_MEMORY;
}
return 0;
}
int32_t trnAppendUndoAction(STrans *pTrans, SEpSet *pEpSet, void *pMsg) {
void *ptr = taosArrayPush(pTrans->undoActions, &pMsg);
if (ptr == NULL) {
return TSDB_CODE_MND_OUT_OF_MEMORY;
}
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册