fix/TD-30989
This commit is contained in:
parent
c819ac1abe
commit
cfe7c552bc
|
@ -112,6 +112,8 @@ void sdbCleanup(SSdb *pSdb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
ESdbType sdbType = table.sdbType;
|
ESdbType sdbType = table.sdbType;
|
||||||
EKeyType keyType = table.keyType;
|
EKeyType keyType = table.keyType;
|
||||||
pSdb->keyTypes[sdbType] = table.keyType;
|
pSdb->keyTypes[sdbType] = table.keyType;
|
||||||
|
@ -134,8 +136,8 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
||||||
|
|
||||||
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_ENTRY_LOCK);
|
SHashObj *hash = taosHashInit(64, taosGetDefaultHashFunction(hashType), true, HASH_ENTRY_LOCK);
|
||||||
if (hash == NULL) {
|
if (hash == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
pSdb->maxId[sdbType] = 0;
|
pSdb->maxId[sdbType] = 0;
|
||||||
|
@ -146,16 +148,17 @@ int32_t sdbSetTable(SSdb *pSdb, SSdbTable table) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbCreateDir(SSdb *pSdb) {
|
static int32_t sdbCreateDir(SSdb *pSdb) {
|
||||||
|
int32_t code = 0;
|
||||||
if (taosMulMkDir(pSdb->currDir) != 0) {
|
if (taosMulMkDir(pSdb->currDir) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("failed to create dir:%s since %s", pSdb->currDir, terrstr());
|
mError("failed to create dir:%s since %s", pSdb->currDir, tstrerror(code));
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosMkDir(pSdb->tmpDir) != 0) {
|
if (taosMkDir(pSdb->tmpDir) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("failed to create dir:%s since %s", pSdb->tmpDir, terrstr());
|
mError("failed to create dir:%s since %s", pSdb->tmpDir, tstrerror(code));
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#define SDB_FILE_VER 1
|
#define SDB_FILE_VER 1
|
||||||
|
|
||||||
static int32_t sdbDeployData(SSdb *pSdb) {
|
static int32_t sdbDeployData(SSdb *pSdb) {
|
||||||
|
int32_t code = 0;
|
||||||
mInfo("start to deploy sdb");
|
mInfo("start to deploy sdb");
|
||||||
|
|
||||||
for (int32_t i = SDB_MAX - 1; i >= 0; --i) {
|
for (int32_t i = SDB_MAX - 1; i >= 0; --i) {
|
||||||
|
@ -33,8 +34,9 @@ static int32_t sdbDeployData(SSdb *pSdb) {
|
||||||
if (fp == NULL) continue;
|
if (fp == NULL) continue;
|
||||||
|
|
||||||
mInfo("start to deploy sdb:%s", sdbTableName(i));
|
mInfo("start to deploy sdb:%s", sdbTableName(i));
|
||||||
if ((*fp)(pSdb->pMnode) != 0) {
|
code = (*fp)(pSdb->pMnode);
|
||||||
mError("failed to deploy sdb:%s since %s", sdbTableName(i), terrstr());
|
if (code != 0) {
|
||||||
|
mError("failed to deploy sdb:%s since %s", sdbTableName(i), tstrerror(code));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,61 +82,62 @@ static void sdbResetData(SSdb *pSdb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
|
int32_t code = 0;
|
||||||
int64_t sver = 0;
|
int64_t sver = 0;
|
||||||
int32_t ret = taosReadFile(pFile, &sver, sizeof(int64_t));
|
int32_t ret = taosReadFile(pFile, &sver, sizeof(int64_t));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (sver != SDB_FILE_VER) {
|
if (sver != SDB_FILE_VER) {
|
||||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t));
|
ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t));
|
ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t));
|
ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
||||||
int64_t maxId = 0;
|
int64_t maxId = 0;
|
||||||
ret = taosReadFile(pFile, &maxId, sizeof(int64_t));
|
ret = taosReadFile(pFile, &maxId, sizeof(int64_t));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (i < SDB_MAX) {
|
if (i < SDB_MAX) {
|
||||||
pSdb->maxId[i] = maxId;
|
pSdb->maxId[i] = maxId;
|
||||||
|
@ -145,12 +148,12 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
int64_t ver = 0;
|
int64_t ver = 0;
|
||||||
ret = taosReadFile(pFile, &ver, sizeof(int64_t));
|
ret = taosReadFile(pFile, &ver, sizeof(int64_t));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (i < SDB_MAX) {
|
if (i < SDB_MAX) {
|
||||||
pSdb->tableVer[i] = ver;
|
pSdb->tableVer[i] = ver;
|
||||||
|
@ -160,37 +163,38 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
char reserve[SDB_RESERVE_SIZE] = {0};
|
char reserve[SDB_RESERVE_SIZE] = {0};
|
||||||
ret = taosReadFile(pFile, reserve, sizeof(reserve));
|
ret = taosReadFile(pFile, reserve, sizeof(reserve));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (ret != sizeof(reserve)) {
|
if (ret != sizeof(reserve)) {
|
||||||
terrno = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
|
int32_t code = 0;
|
||||||
int64_t sver = SDB_FILE_VER;
|
int64_t sver = SDB_FILE_VER;
|
||||||
if (taosWriteFile(pFile, &sver, sizeof(int64_t)) != sizeof(int64_t)) {
|
if (taosWriteFile(pFile, &sver, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosWriteFile(pFile, &pSdb->applyIndex, sizeof(int64_t)) != sizeof(int64_t)) {
|
if (taosWriteFile(pFile, &pSdb->applyIndex, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosWriteFile(pFile, &pSdb->applyTerm, sizeof(int64_t)) != sizeof(int64_t)) {
|
if (taosWriteFile(pFile, &pSdb->applyTerm, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosWriteFile(pFile, &pSdb->applyConfig, sizeof(int64_t)) != sizeof(int64_t)) {
|
if (taosWriteFile(pFile, &pSdb->applyConfig, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
||||||
|
@ -199,8 +203,8 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
maxId = pSdb->maxId[i];
|
maxId = pSdb->maxId[i];
|
||||||
}
|
}
|
||||||
if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) {
|
if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,15 +214,15 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
ver = pSdb->tableVer[i];
|
ver = pSdb->tableVer[i];
|
||||||
}
|
}
|
||||||
if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) {
|
if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char reserve[SDB_RESERVE_SIZE] = {0};
|
char reserve[SDB_RESERVE_SIZE] = {0};
|
||||||
if (taosWriteFile(pFile, reserve, sizeof(reserve)) != sizeof(reserve)) {
|
if (taosWriteFile(pFile, reserve, sizeof(reserve)) != sizeof(reserve)) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -237,21 +241,22 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
||||||
|
|
||||||
SSdbRaw *pRaw = taosMemoryMalloc(bufLen + 100);
|
SSdbRaw *pRaw = taosMemoryMalloc(bufLen + 100);
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
mError("failed read sdb file since %s", terrstr());
|
mError("failed read sdb file since %s", tstrerror(code));
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
taosMemoryFree(pRaw);
|
taosMemoryFree(pRaw);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mInfo("read sdb file:%s finished since %s", file, terrstr());
|
mInfo("read sdb file:%s finished since %s", file, tstrerror(code));
|
||||||
return 0;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdbReadFileHead(pSdb, pFile) != 0) {
|
code = sdbReadFileHead(pSdb, pFile);
|
||||||
mError("failed to read sdb file:%s head since %s", file, terrstr());
|
if (code != 0) {
|
||||||
|
mError("failed to read sdb file:%s head since %s", file, tstrerror(code));
|
||||||
taosMemoryFree(pRaw);
|
taosMemoryFree(pRaw);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -365,7 +370,7 @@ int32_t sdbReadFile(SSdb *pSdb) {
|
||||||
sdbResetData(pSdb);
|
sdbResetData(pSdb);
|
||||||
int32_t code = sdbReadFileImp(pSdb);
|
int32_t code = sdbReadFileImp(pSdb);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("failed to read sdb file since %s", terrstr());
|
mError("failed to read sdb file since %s", tstrerror(code));
|
||||||
sdbResetData(pSdb);
|
sdbResetData(pSdb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,13 +393,14 @@ static int32_t sdbWriteFileImp(SSdb *pSdb) {
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("failed to open sdb file:%s for write since %s", tmpfile, terrstr());
|
mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code));
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdbWriteFileHead(pSdb, pFile) != 0) {
|
code = sdbWriteFileHead(pSdb, pFile);
|
||||||
mError("failed to write sdb file:%s head since %s", tmpfile, terrstr());
|
if (code != 0) {
|
||||||
|
mError("failed to write sdb file:%s head since %s", tmpfile, tstrerror(code));
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -549,19 +555,22 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("failed to write sdb file since %s", terrstr());
|
mError("failed to write sdb file since %s", tstrerror(code));
|
||||||
}
|
}
|
||||||
taosThreadMutexUnlock(&pSdb->filelock);
|
taosThreadMutexUnlock(&pSdb->filelock);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbDeploy(SSdb *pSdb) {
|
int32_t sdbDeploy(SSdb *pSdb) {
|
||||||
if (sdbDeployData(pSdb) != 0) {
|
int32_t code = 0;
|
||||||
return -1;
|
code = sdbDeployData(pSdb);
|
||||||
|
if (code != 0) {
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdbWriteFile(pSdb, 0) != 0) {
|
code = sdbWriteFile(pSdb, 0);
|
||||||
return -1;
|
if (code != 0) {
|
||||||
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -605,6 +614,7 @@ static void sdbCloseIter(SSdbIter *pIter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *term, int64_t *config) {
|
int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *term, int64_t *config) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbIter *pIter = sdbCreateIter(pSdb);
|
SSdbIter *pIter = sdbCreateIter(pSdb);
|
||||||
if (pIter == NULL) return -1;
|
if (pIter == NULL) return -1;
|
||||||
|
|
||||||
|
@ -617,19 +627,19 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
|
||||||
int64_t commitConfig = pSdb->commitConfig;
|
int64_t commitConfig = pSdb->commitConfig;
|
||||||
if (taosCopyFile(datafile, pIter->name) < 0) {
|
if (taosCopyFile(datafile, pIter->name) < 0) {
|
||||||
taosThreadMutexUnlock(&pSdb->filelock);
|
taosThreadMutexUnlock(&pSdb->filelock);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, terrstr());
|
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code));
|
||||||
sdbCloseIter(pIter);
|
sdbCloseIter(pIter);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
taosThreadMutexUnlock(&pSdb->filelock);
|
taosThreadMutexUnlock(&pSdb->filelock);
|
||||||
|
|
||||||
pIter->file = taosOpenFile(pIter->name, TD_FILE_READ);
|
pIter->file = taosOpenFile(pIter->name, TD_FILE_READ);
|
||||||
if (pIter->file == NULL) {
|
if (pIter->file == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("failed to open sdb file:%s since %s", pIter->name, terrstr());
|
mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code));
|
||||||
sdbCloseIter(pIter);
|
sdbCloseIter(pIter);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppIter = pIter;
|
*ppIter = pIter;
|
||||||
|
@ -645,21 +655,22 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
|
||||||
void sdbStopRead(SSdb *pSdb, SSdbIter *pIter) { sdbCloseIter(pIter); }
|
void sdbStopRead(SSdb *pSdb, SSdbIter *pIter) { sdbCloseIter(pIter); }
|
||||||
|
|
||||||
int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
|
int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t maxlen = 4096;
|
int32_t maxlen = 4096;
|
||||||
void *pBuf = taosMemoryCalloc(1, maxlen);
|
void *pBuf = taosMemoryCalloc(1, maxlen);
|
||||||
if (pBuf == NULL) {
|
if (pBuf == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t readlen = taosReadFile(pIter->file, pBuf, maxlen);
|
int32_t readlen = taosReadFile(pIter->file, pBuf, maxlen);
|
||||||
if (readlen < 0 || readlen > maxlen) {
|
if (readlen < 0 || readlen > maxlen) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, terrstr(), pIter->total);
|
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, tstrerror(code), pIter->total);
|
||||||
*ppBuf = NULL;
|
*ppBuf = NULL;
|
||||||
*len = 0;
|
*len = 0;
|
||||||
taosMemoryFree(pBuf);
|
taosMemoryFree(pBuf);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
} else if (readlen == 0) {
|
} else if (readlen == 0) {
|
||||||
mInfo("sdbiter:%p, read snapshot to the end, total:%" PRId64, pIter, pIter->total);
|
mInfo("sdbiter:%p, read snapshot to the end, total:%" PRId64, pIter, pIter->total);
|
||||||
*ppBuf = NULL;
|
*ppBuf = NULL;
|
||||||
|
@ -676,15 +687,19 @@ int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) {
|
int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) {
|
||||||
|
int32_t code = 0;
|
||||||
SSdbIter *pIter = sdbCreateIter(pSdb);
|
SSdbIter *pIter = sdbCreateIter(pSdb);
|
||||||
if (pIter == NULL) return -1;
|
if (pIter == NULL) {
|
||||||
|
code = terrno;
|
||||||
|
TAOS_RETURN(code);
|
||||||
|
}
|
||||||
|
|
||||||
pIter->file = taosOpenFile(pIter->name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
pIter->file = taosOpenFile(pIter->name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pIter->file == NULL) {
|
if (pIter->file == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("failed to open %s since %s", pIter->name, terrstr());
|
mError("failed to open %s since %s", pIter->name, tstrerror(code));
|
||||||
sdbCloseIter(pIter);
|
sdbCloseIter(pIter);
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppIter = pIter;
|
*ppIter = pIter;
|
||||||
|
@ -702,8 +717,8 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFsyncFile(pIter->file) != 0) {
|
if (taosFsyncFile(pIter->file) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("sdbiter:%p, failed to fasync file %s since %s", pIter, pIter->name, terrstr());
|
mError("sdbiter:%p, failed to fasync file %s since %s", pIter, pIter->name, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,13 +728,14 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
|
||||||
char datafile[PATH_MAX] = {0};
|
char datafile[PATH_MAX] = {0};
|
||||||
snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
|
snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
|
||||||
if (taosRenameFile(pIter->name, datafile) != 0) {
|
if (taosRenameFile(pIter->name, datafile) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, terrstr());
|
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sdbReadFile(pSdb) != 0) {
|
code = sdbReadFile(pSdb);
|
||||||
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, terrstr());
|
if (code != 0) {
|
||||||
|
mError("sdbiter:%p, failed to read from %s since %s", pIter, datafile, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -742,10 +758,11 @@ _OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
|
int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t writelen = taosWriteFile(pIter->file, pBuf, len);
|
int32_t writelen = taosWriteFile(pIter->file, pBuf, len);
|
||||||
if (writelen != len) {
|
if (writelen != len) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
mError("failed to write len:%d since %s, total:%" PRId64, len, terrstr(), pIter->total);
|
mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,14 +53,15 @@ void sdbFreeRaw(SSdbRaw *pRaw) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*(int8_t *)(pRaw->pData + dataPos) = val;
|
*(int8_t *)(pRaw->pData + dataPos) = val;
|
||||||
|
@ -68,14 +69,15 @@ int32_t sdbSetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbSetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t val) {
|
int32_t sdbSetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t val) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*(uint8_t *)(pRaw->pData + dataPos) = val;
|
*(uint8_t *)(pRaw->pData + dataPos) = val;
|
||||||
|
@ -83,14 +85,15 @@ int32_t sdbSetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*(int32_t *)(pRaw->pData + dataPos) = val;
|
*(int32_t *)(pRaw->pData + dataPos) = val;
|
||||||
|
@ -98,14 +101,15 @@ int32_t sdbSetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
|
int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*(int16_t *)(pRaw->pData + dataPos) = val;
|
*(int16_t *)(pRaw->pData + dataPos) = val;
|
||||||
|
@ -113,14 +117,15 @@ int32_t sdbSetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*(int64_t *)(pRaw->pData + dataPos) = val;
|
*(int64_t *)(pRaw->pData + dataPos) = val;
|
||||||
|
@ -128,14 +133,15 @@ int32_t sdbSetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_t valLen) {
|
int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_t valLen) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + valLen > pRaw->dataLen) {
|
if (dataPos + valLen > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pVal != NULL) {
|
if (pVal != NULL) {
|
||||||
|
@ -145,14 +151,15 @@ int32_t sdbSetRawBinary(SSdbRaw *pRaw, int32_t dataPos, const char *pVal, int32_
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataLen > pRaw->dataLen) {
|
if (dataLen > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
pRaw->dataLen = dataLen;
|
pRaw->dataLen = dataLen;
|
||||||
|
@ -160,14 +167,15 @@ int32_t sdbSetRawDataLen(SSdbRaw *pRaw, int32_t dataLen) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == SDB_STATUS_INIT) {
|
if (status == SDB_STATUS_INIT) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
pRaw->status = status;
|
pRaw->status = status;
|
||||||
|
@ -175,14 +183,15 @@ int32_t sdbSetRawStatus(SSdbRaw *pRaw, ESdbStatus status) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
if (dataPos + sizeof(int8_t) > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*val = *(int8_t *)(pRaw->pData + dataPos);
|
*val = *(int8_t *)(pRaw->pData + dataPos);
|
||||||
|
@ -190,14 +199,15 @@ int32_t sdbGetRawInt8(SSdbRaw *pRaw, int32_t dataPos, int8_t *val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbGetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t *val) {
|
int32_t sdbGetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t *val) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
if (dataPos + sizeof(uint8_t) > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*val = *(uint8_t *)(pRaw->pData + dataPos);
|
*val = *(uint8_t *)(pRaw->pData + dataPos);
|
||||||
|
@ -205,14 +215,15 @@ int32_t sdbGetRawUInt8(SSdbRaw *pRaw, int32_t dataPos, uint8_t *val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
if (dataPos + sizeof(int32_t) > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*val = *(int32_t *)(pRaw->pData + dataPos);
|
*val = *(int32_t *)(pRaw->pData + dataPos);
|
||||||
|
@ -220,14 +231,15 @@ int32_t sdbGetRawInt32(SSdbRaw *pRaw, int32_t dataPos, int32_t *val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
|
int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
if (dataPos + sizeof(int16_t) > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*val = *(int16_t *)(pRaw->pData + dataPos);
|
*val = *(int16_t *)(pRaw->pData + dataPos);
|
||||||
|
@ -235,14 +247,15 @@ int32_t sdbGetRawInt16(SSdbRaw *pRaw, int32_t dataPos, int16_t *val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
if (dataPos + sizeof(int64_t) > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*val = *(int64_t *)(pRaw->pData + dataPos);
|
*val = *(int64_t *)(pRaw->pData + dataPos);
|
||||||
|
@ -250,14 +263,15 @@ int32_t sdbGetRawInt64(SSdbRaw *pRaw, int32_t dataPos, int64_t *val) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valLen) {
|
int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valLen) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dataPos + valLen > pRaw->dataLen) {
|
if (dataPos + valLen > pRaw->dataLen) {
|
||||||
terrno = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
code = TSDB_CODE_SDB_INVALID_DATA_LEN;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
if (pVal != NULL) {
|
if (pVal != NULL) {
|
||||||
memcpy(pVal, pRaw->pData + dataPos, valLen);
|
memcpy(pVal, pRaw->pData + dataPos, valLen);
|
||||||
|
@ -266,9 +280,10 @@ int32_t sdbGetRawBinary(SSdbRaw *pRaw, int32_t dataPos, char *pVal, int32_t valL
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver) {
|
int32_t sdbGetRawSoftVer(SSdbRaw *pRaw, int8_t *sver) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pRaw == NULL) {
|
if (pRaw == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PTR;
|
code = TSDB_CODE_INVALID_PTR;
|
||||||
return -1;
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
*sver = pRaw->sver;
|
*sver = pRaw->sver;
|
||||||
|
|
Loading…
Reference in New Issue