s3/evict: fetch atime from stat file
This commit is contained in:
parent
65d8af19ed
commit
fac7e521e9
|
@ -76,7 +76,7 @@ int32_t taosUnLockFile(TdFilePtr pFile);
|
||||||
|
|
||||||
int32_t taosUmaskFile(int32_t maskVal);
|
int32_t taosUmaskFile(int32_t maskVal);
|
||||||
|
|
||||||
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime);
|
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *atime);
|
||||||
int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno);
|
int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno);
|
||||||
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime);
|
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime);
|
||||||
bool taosCheckExistFile(const char *pathname);
|
bool taosCheckExistFile(const char *pathname);
|
||||||
|
|
|
@ -65,7 +65,7 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("mnode file:%s not exist", file);
|
dInfo("mnode file:%s not exist", file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
||||||
SWrapperCfg *pCfgs = NULL;
|
SWrapperCfg *pCfgs = NULL;
|
||||||
snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("vnode file:%s not exist", file);
|
dInfo("vnode file:%s not exist", file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("dnode file:%s not exist", file);
|
dInfo("dnode file:%s not exist", file);
|
||||||
code = 0;
|
code = 0;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
@ -469,7 +469,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dDebug("dnode file:%s not exist", file);
|
dDebug("dnode file:%s not exist", file);
|
||||||
code = 0;
|
code = 0;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
|
|
@ -38,7 +38,7 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("file:%s not exist", file);
|
dInfo("file:%s not exist", file);
|
||||||
code = 0;
|
code = 0;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
|
|
@ -30,8 +30,9 @@ void s3PutObjectFromFile(const char *file, const char *object);
|
||||||
void s3DeleteObjects(const char *object_name[], int nobject);
|
void s3DeleteObjects(const char *object_name[], int nobject);
|
||||||
bool s3Exists(const char *object_name);
|
bool s3Exists(const char *object_name);
|
||||||
bool s3Get(const char *object_name, const char *path);
|
bool s3Get(const char *object_name, const char *path);
|
||||||
void s3EvictCache();
|
void s3EvictCache(const char *path, long object_size);
|
||||||
long s3Size(const char *object_name);
|
long s3Size(const char *object_name);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -60,7 +60,7 @@ int32_t tqOffsetSnapRead(STqOffsetReader* pReader, uint8_t** ppData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t sz = 0;
|
int64_t sz = 0;
|
||||||
if (taosStatFile(fname, &sz, NULL) < 0) {
|
if (taosStatFile(fname, &sz, NULL, NULL) < 0) {
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
taosMemoryFree(fname);
|
taosMemoryFree(fname);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -176,7 +176,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
// SDelFile
|
// SDelFile
|
||||||
if (pTsdb->fs.pDelFile) {
|
if (pTsdb->fs.pDelFile) {
|
||||||
tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname);
|
tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname);
|
||||||
if (taosStatFile(fname, &size, NULL)) {
|
if (taosStatFile(fname, &size, NULL, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
@ -195,7 +195,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
|
|
||||||
// head =========
|
// head =========
|
||||||
tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname);
|
tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname);
|
||||||
if (taosStatFile(fname, &size, NULL)) {
|
if (taosStatFile(fname, &size, NULL, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
|
|
||||||
// data =========
|
// data =========
|
||||||
tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname);
|
tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname);
|
||||||
if (taosStatFile(fname, &size, NULL)) {
|
if (taosStatFile(fname, &size, NULL, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
@ -221,7 +221,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
|
|
||||||
// sma =============
|
// sma =============
|
||||||
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
|
tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname);
|
||||||
if (taosStatFile(fname, &size, NULL)) {
|
if (taosStatFile(fname, &size, NULL, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
@ -237,7 +237,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
// stt ===========
|
// stt ===========
|
||||||
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) {
|
||||||
tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
|
tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname);
|
||||||
if (taosStatFile(fname, &size, NULL)) {
|
if (taosStatFile(fname, &size, NULL, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **p
|
||||||
const char *object_name = taosDirEntryBaseName((char *)path);
|
const char *object_name = taosDirEntryBaseName((char *)path);
|
||||||
long s3_size = s3Size(object_name);
|
long s3_size = s3Size(object_name);
|
||||||
if (!strncmp(path + strlen(path) - 5, ".data", 5) && s3_size > 0) {
|
if (!strncmp(path + strlen(path) - 5, ".data", 5) && s3_size > 0) {
|
||||||
s3EvictCache();
|
s3EvictCache(path, s3_size);
|
||||||
s3Get(object_name, path);
|
s3Get(object_name, path);
|
||||||
|
|
||||||
pFD->pFD = taosOpenFile(path, flag);
|
pFD->pFD = taosOpenFile(path, flag);
|
||||||
|
@ -66,7 +66,7 @@ int32_t tsdbOpenFile(const char *path, int32_t szPage, int32_t flag, STsdbFD **p
|
||||||
|
|
||||||
// not check file size when reading data files.
|
// not check file size when reading data files.
|
||||||
if (flag != TD_FILE_READ) {
|
if (flag != TD_FILE_READ) {
|
||||||
if (taosStatFile(path, &pFD->szFile, NULL) < 0) {
|
if (taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosMemoryFree(pFD->pBuf);
|
taosMemoryFree(pFD->pBuf);
|
||||||
taosCloseFile(&pFD->pFD);
|
taosCloseFile(&pFD->pFD);
|
||||||
|
|
|
@ -190,7 +190,71 @@ bool s3Get(const char *object_name, const char *path) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void s3EvictCache() {}
|
typedef struct {
|
||||||
|
int64_t size;
|
||||||
|
int32_t atime;
|
||||||
|
char name[TSDB_FILENAME_LEN];
|
||||||
|
} SEvictFile;
|
||||||
|
|
||||||
|
static int32_t evictFileCompareAsce(const void *pLeft, const void *pRight) {
|
||||||
|
SEvictFile *lhs = (SEvictFile *)pLeft;
|
||||||
|
SEvictFile *rhs = (SEvictFile *)pRight;
|
||||||
|
return lhs->atime < rhs->atime ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void s3EvictCache(const char *path, long object_size) {
|
||||||
|
SDiskSize disk_size = {0};
|
||||||
|
if (taosGetDiskSize((char *)path, &disk_size) < 0) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
vError("failed to get disk:%s size since %s", path, terrstr());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (object_size >= disk_size.avail + 1 << 30) {
|
||||||
|
// evict too old files
|
||||||
|
// 1, list data files' atime under dir(path)
|
||||||
|
char dir_name[TSDB_FILENAME_LEN] = "\0";
|
||||||
|
tstrncpy(dir_name, path, TSDB_FILENAME_LEN);
|
||||||
|
taosDirName(dir_name);
|
||||||
|
|
||||||
|
tdbDirPtr pDir = taosOpenDir(dir_name);
|
||||||
|
if (pDir == NULL) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
vError("failed to open %s since %s", dir_name, terrstr());
|
||||||
|
}
|
||||||
|
SArray *evict_files = taosArrayInit(16, sizeof(SEvictFile));
|
||||||
|
tdbDirEntryPtr pDirEntry;
|
||||||
|
while ((pDirEntry = taosReadDir(pDir)) != NULL) {
|
||||||
|
char *name = taosGetDirEntryName(pDirEntry);
|
||||||
|
if (!strncmp(name + strlen(name) - 5, ".data", 5)) {
|
||||||
|
SEvictFile e_file = {0};
|
||||||
|
|
||||||
|
tstrncpy(e_file.name, name, TSDB_FILENAME_LEN);
|
||||||
|
taosStatFile(name, &e_file.size, NULL, &e_file.atime);
|
||||||
|
|
||||||
|
taosArrayPush(evict_files, &e_file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
taosCloseDir(&pDir);
|
||||||
|
|
||||||
|
// 2, sort by atime
|
||||||
|
taosArraySort(evict_files, evictFileCompareAsce);
|
||||||
|
|
||||||
|
// 3, remove files ascendingly until we get enough object_size space
|
||||||
|
long evict_size = 0;
|
||||||
|
size_t ef_size = TARRAY_SIZE(evict_files);
|
||||||
|
for (size_t i = 0; i < ef_size; ++i) {
|
||||||
|
SEvictFile *evict_file = taosArrayGet(evict_files, i);
|
||||||
|
taosRemoveFile(evict_file->name);
|
||||||
|
evict_size += evict_file->size;
|
||||||
|
if (evict_size >= object_size) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taosArrayDestroy(evict_files);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
long s3Size(const char *object_name) {
|
long s3Size(const char *object_name) {
|
||||||
long size = 0;
|
long size = 0;
|
||||||
|
|
|
@ -848,7 +848,7 @@ int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) {
|
||||||
|
|
||||||
char path[PATH_MAX] = {0};
|
char path[PATH_MAX] = {0};
|
||||||
udfdGetFuncBodyPath(udf, path);
|
udfdGetFuncBodyPath(udf, path);
|
||||||
bool fileExist = !(taosStatFile(path, NULL, NULL) < 0);
|
bool fileExist = !(taosStatFile(path, NULL, NULL, NULL) < 0);
|
||||||
if (fileExist) {
|
if (fileExist) {
|
||||||
strncpy(udf->path, path, PATH_MAX);
|
strncpy(udf->path, path, PATH_MAX);
|
||||||
fnInfo("udfd func body file. reuse existing file %s", path);
|
fnInfo("udfd func body file. reuse existing file %s", path);
|
||||||
|
|
|
@ -162,7 +162,7 @@ static FORCE_INLINE int idxFileCtxGetSize(IFileCtx* ctx) {
|
||||||
return ctx->offset;
|
return ctx->offset;
|
||||||
} else {
|
} else {
|
||||||
int64_t file_size = 0;
|
int64_t file_size = 0;
|
||||||
taosStatFile(ctx->file.buf, &file_size, NULL);
|
taosStatFile(ctx->file.buf, &file_size, NULL, NULL);
|
||||||
return (int)file_size;
|
return (int)file_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +199,7 @@ IFileCtx* idxFileCtxCreate(WriterType type, const char* path, bool readOnly, int
|
||||||
code = taosFtruncateFile(ctx->file.pFile, 0);
|
code = taosFtruncateFile(ctx->file.pFile, 0);
|
||||||
UNUSED(code);
|
UNUSED(code);
|
||||||
|
|
||||||
code = taosStatFile(path, &ctx->file.size, NULL);
|
code = taosStatFile(path, &ctx->file.size, NULL, NULL);
|
||||||
UNUSED(code);
|
UNUSED(code);
|
||||||
|
|
||||||
ctx->file.wBufOffset = 0;
|
ctx->file.wBufOffset = 0;
|
||||||
|
|
|
@ -278,7 +278,8 @@ static const SSysTableShowAdapter sysTableShowAdapter[] = {
|
||||||
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode);
|
static int32_t translateSubquery(STranslateContext* pCxt, SNode* pNode);
|
||||||
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode);
|
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode);
|
||||||
static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal);
|
static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal);
|
||||||
static int32_t createSimpleSelectStmtFromProjList(const char* pDb, const char* pTable, SNodeList* pProjectionList, SSelectStmt** pStmt);
|
static int32_t createSimpleSelectStmtFromProjList(const char* pDb, const char* pTable, SNodeList* pProjectionList,
|
||||||
|
SSelectStmt** pStmt);
|
||||||
static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta, SNode** pQuery);
|
static int32_t createLastTsSelectStmt(char* pDb, char* pTable, STableMeta* pMeta, SNode** pQuery);
|
||||||
static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery);
|
static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery);
|
||||||
static int32_t setRefreshMate(STranslateContext* pCxt, SQuery* pQuery);
|
static int32_t setRefreshMate(STranslateContext* pCxt, SQuery* pQuery);
|
||||||
|
@ -772,7 +773,8 @@ static SNodeList* getProjectList(const SNode* pNode) {
|
||||||
|
|
||||||
static bool isTimeLineQuery(SNode* pStmt) {
|
static bool isTimeLineQuery(SNode* pStmt) {
|
||||||
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
if (QUERY_NODE_SELECT_STMT == nodeType(pStmt)) {
|
||||||
return (TIME_LINE_MULTI == ((SSelectStmt*)pStmt)->timeLineResMode) || (TIME_LINE_GLOBAL == ((SSelectStmt*)pStmt)->timeLineResMode);
|
return (TIME_LINE_MULTI == ((SSelectStmt*)pStmt)->timeLineResMode) ||
|
||||||
|
(TIME_LINE_GLOBAL == ((SSelectStmt*)pStmt)->timeLineResMode);
|
||||||
} else if (QUERY_NODE_SET_OPERATOR == nodeType(pStmt)) {
|
} else if (QUERY_NODE_SET_OPERATOR == nodeType(pStmt)) {
|
||||||
return TIME_LINE_GLOBAL == ((SSetOperator*)pStmt)->timeLineResMode;
|
return TIME_LINE_GLOBAL == ((SSetOperator*)pStmt)->timeLineResMode;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1596,9 +1598,11 @@ static int32_t translateInterpFunc(STranslateContext* pCxt, SFunctionNode* pFunc
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSelect->hasInterpFunc && (FUNC_RETURN_ROWS_INDEFINITE == pSelect->returnRows || pSelect->returnRows != fmGetFuncReturnRows(pFunc))) {
|
if (pSelect->hasInterpFunc &&
|
||||||
|
(FUNC_RETURN_ROWS_INDEFINITE == pSelect->returnRows || pSelect->returnRows != fmGetFuncReturnRows(pFunc))) {
|
||||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
||||||
"%s ignoring null value options cannot be used when applying to multiple columns", pFunc->functionName);
|
"%s ignoring null value options cannot be used when applying to multiple columns",
|
||||||
|
pFunc->functionName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != pSelect->pWindow || NULL != pSelect->pGroupByList) {
|
if (NULL != pSelect->pWindow || NULL != pSelect->pGroupByList) {
|
||||||
|
@ -1636,7 +1640,8 @@ static int32_t translateTimelineFunc(STranslateContext* pCxt, SFunctionNode* pFu
|
||||||
}
|
}
|
||||||
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
SSelectStmt* pSelect = (SSelectStmt*)pCxt->pCurrStmt;
|
||||||
if (NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
if (NULL != pSelect->pFromTable && QUERY_NODE_TEMP_TABLE == nodeType(pSelect->pFromTable) &&
|
||||||
!isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) && !isTimeLineAlignedQuery(pCxt->pCurrStmt)) {
|
!isGlobalTimeLineQuery(((STempTableNode*)pSelect->pFromTable)->pSubquery) &&
|
||||||
|
!isTimeLineAlignedQuery(pCxt->pCurrStmt)) {
|
||||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_ALLOWED_FUNC,
|
||||||
"%s function requires valid time series input", pFunc->functionName);
|
"%s function requires valid time series input", pFunc->functionName);
|
||||||
}
|
}
|
||||||
|
@ -2296,7 +2301,8 @@ static EDealRes doCheckExprForGroupBy(SNode** pNode, void* pContext) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) {
|
if (isScanPseudoColumnFunc(*pNode) || QUERY_NODE_COLUMN == nodeType(*pNode)) {
|
||||||
if (pSelect->selectFuncNum > 1 || pSelect->hasOtherVectorFunc || !pSelect->hasSelectFunc || (isDistinctOrderBy(pCxt) && pCxt->currClause == SQL_CLAUSE_ORDER_BY)) {
|
if (pSelect->selectFuncNum > 1 || pSelect->hasOtherVectorFunc || !pSelect->hasSelectFunc ||
|
||||||
|
(isDistinctOrderBy(pCxt) && pCxt->currClause == SQL_CLAUSE_ORDER_BY)) {
|
||||||
return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt), ((SExprNode*)(*pNode))->userAlias);
|
return generateDealNodeErrMsg(pCxt, getGroupByErrorCode(pCxt), ((SExprNode*)(*pNode))->userAlias);
|
||||||
} else {
|
} else {
|
||||||
return rewriteColToSelectValFunc(pCxt, pNode);
|
return rewriteColToSelectValFunc(pCxt, pNode);
|
||||||
|
@ -2699,7 +2705,8 @@ static int32_t replaceTbName(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SRealTableNode* pTable = (SRealTableNode*)pSelect->pFromTable;
|
SRealTableNode* pTable = (SRealTableNode*)pSelect->pFromTable;
|
||||||
if (TSDB_CHILD_TABLE != pTable->pMeta->tableType && TSDB_NORMAL_TABLE != pTable->pMeta->tableType && TSDB_SYSTEM_TABLE != pTable->pMeta->tableType) {
|
if (TSDB_CHILD_TABLE != pTable->pMeta->tableType && TSDB_NORMAL_TABLE != pTable->pMeta->tableType &&
|
||||||
|
TSDB_SYSTEM_TABLE != pTable->pMeta->tableType) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3110,7 +3117,8 @@ static int32_t convertFillValue(STranslateContext* pCxt, SDataType dt, SNodeList
|
||||||
code = scalarCalculateConstants(pCastFunc, &pCell->pNode);
|
code = scalarCalculateConstants(pCastFunc, &pCell->pNode);
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE != nodeType(pCell->pNode)) {
|
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_VALUE != nodeType(pCell->pNode)) {
|
||||||
code = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Fill value can only accept constant");
|
code =
|
||||||
|
generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Fill value can only accept constant");
|
||||||
} else if (TSDB_CODE_SUCCESS != code) {
|
} else if (TSDB_CODE_SUCCESS != code) {
|
||||||
code = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Filled data type mismatch");
|
code = generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Filled data type mismatch");
|
||||||
}
|
}
|
||||||
|
@ -3576,7 +3584,6 @@ static int32_t createDefaultEveryNode(STranslateContext* pCxt, SNode** pOutput)
|
||||||
pEvery->isDuration = true;
|
pEvery->isDuration = true;
|
||||||
pEvery->literal = taosStrdup("1s");
|
pEvery->literal = taosStrdup("1s");
|
||||||
|
|
||||||
|
|
||||||
*pOutput = (SNode*)pEvery;
|
*pOutput = (SNode*)pEvery;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -3675,8 +3682,8 @@ static int32_t translatePartitionBy(STranslateContext* pCxt, SSelectStmt* pSelec
|
||||||
if (pSelect->pPartitionByList) {
|
if (pSelect->pPartitionByList) {
|
||||||
int8_t typeType = getTableTypeFromTableNode(pSelect->pFromTable);
|
int8_t typeType = getTableTypeFromTableNode(pSelect->pFromTable);
|
||||||
SNode* pPar = nodesListGetNode(pSelect->pPartitionByList, 0);
|
SNode* pPar = nodesListGetNode(pSelect->pPartitionByList, 0);
|
||||||
if (!((TSDB_NORMAL_TABLE == typeType || TSDB_CHILD_TABLE == typeType) &&
|
if (!((TSDB_NORMAL_TABLE == typeType || TSDB_CHILD_TABLE == typeType) && 1 == pSelect->pPartitionByList->length &&
|
||||||
1 == pSelect->pPartitionByList->length && (QUERY_NODE_FUNCTION == nodeType(pPar) && FUNCTION_TYPE_TBNAME == ((SFunctionNode*)pPar)->funcType))) {
|
(QUERY_NODE_FUNCTION == nodeType(pPar) && FUNCTION_TYPE_TBNAME == ((SFunctionNode*)pPar)->funcType))) {
|
||||||
pSelect->timeLineResMode = TIME_LINE_MULTI;
|
pSelect->timeLineResMode = TIME_LINE_MULTI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3943,9 +3950,9 @@ static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pS
|
||||||
}
|
}
|
||||||
snprintf(pRightExpr->aliasName, sizeof(pRightExpr->aliasName), "%s", pLeftExpr->aliasName);
|
snprintf(pRightExpr->aliasName, sizeof(pRightExpr->aliasName), "%s", pLeftExpr->aliasName);
|
||||||
SNode* pProj = createSetOperProject(pSetOperator->stmtName, pLeft);
|
SNode* pProj = createSetOperProject(pSetOperator->stmtName, pLeft);
|
||||||
if (QUERY_NODE_COLUMN == nodeType(pLeft) && QUERY_NODE_COLUMN == nodeType(pRight)
|
if (QUERY_NODE_COLUMN == nodeType(pLeft) && QUERY_NODE_COLUMN == nodeType(pRight) &&
|
||||||
&& ((SColumnNode*)pLeft)->colId == PRIMARYKEY_TIMESTAMP_COL_ID
|
((SColumnNode*)pLeft)->colId == PRIMARYKEY_TIMESTAMP_COL_ID &&
|
||||||
&& ((SColumnNode*)pRight)->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
((SColumnNode*)pRight)->colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||||
((SColumnNode*)pProj)->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
((SColumnNode*)pProj)->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||||
}
|
}
|
||||||
if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pSetOperator->pProjectionList, pProj)) {
|
if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pSetOperator->pProjectionList, pProj)) {
|
||||||
|
@ -5725,7 +5732,6 @@ static int32_t translateRestoreDnode(STranslateContext* pCxt, SRestoreComponentN
|
||||||
return buildCmdMsg(pCxt, TDMT_MND_RESTORE_DNODE, (FSerializeFunc)tSerializeSRestoreDnodeReq, &restoreReq);
|
return buildCmdMsg(pCxt, TDMT_MND_RESTORE_DNODE, (FSerializeFunc)tSerializeSRestoreDnodeReq, &restoreReq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, const char* pDbName, const char* pTableName,
|
static int32_t getSmaIndexDstVgId(STranslateContext* pCxt, const char* pDbName, const char* pTableName,
|
||||||
int32_t* pVgId) {
|
int32_t* pVgId) {
|
||||||
SVgroupInfo vg = {0};
|
SVgroupInfo vg = {0};
|
||||||
|
@ -5867,8 +5873,10 @@ int32_t createIntervalFromCreateSmaIndexStmt(SCreateIndexStmt* pStmt, SInterval*
|
||||||
pInterval->interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i;
|
pInterval->interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i;
|
||||||
pInterval->intervalUnit = ((SValueNode*)pStmt->pOptions->pInterval)->unit;
|
pInterval->intervalUnit = ((SValueNode*)pStmt->pOptions->pInterval)->unit;
|
||||||
pInterval->offset = NULL != pStmt->pOptions->pOffset ? ((SValueNode*)pStmt->pOptions->pOffset)->datum.i : 0;
|
pInterval->offset = NULL != pStmt->pOptions->pOffset ? ((SValueNode*)pStmt->pOptions->pOffset)->datum.i : 0;
|
||||||
pInterval->sliding = NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : pInterval->interval;
|
pInterval->sliding =
|
||||||
pInterval->slidingUnit = NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : pInterval->intervalUnit;
|
NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : pInterval->interval;
|
||||||
|
pInterval->slidingUnit =
|
||||||
|
NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->unit : pInterval->intervalUnit;
|
||||||
pInterval->precision = pStmt->pOptions->tsPrecision;
|
pInterval->precision = pStmt->pOptions->tsPrecision;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -6100,7 +6108,8 @@ static EDealRes checkColumnTagsInCond(SNode* pNode, void* pContext) {
|
||||||
return DEAL_RES_CONTINUE;
|
return DEAL_RES_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t checkCollectTopicTags(STranslateContext* pCxt, SCreateTopicStmt* pStmt, STableMeta* pMeta, SNodeList** ppProjection) {
|
static int32_t checkCollectTopicTags(STranslateContext* pCxt, SCreateTopicStmt* pStmt, STableMeta* pMeta,
|
||||||
|
SNodeList** ppProjection) {
|
||||||
SBuildTopicContext colCxt = {.colExists = false, .colNotFound = false, .pMeta = pMeta, .pTags = NULL};
|
SBuildTopicContext colCxt = {.colExists = false, .colNotFound = false, .pMeta = pMeta, .pTags = NULL};
|
||||||
nodesWalkExprPostOrder(pStmt->pWhere, checkColumnTagsInCond, &colCxt);
|
nodesWalkExprPostOrder(pStmt->pWhere, checkColumnTagsInCond, &colCxt);
|
||||||
if (colCxt.colNotFound) {
|
if (colCxt.colNotFound) {
|
||||||
|
@ -6542,7 +6551,8 @@ static int32_t checkStreamQuery(STranslateContext* pCxt, SCreateStreamStmt* pStm
|
||||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
||||||
"SUBTABLE expression must be of VARCHAR type");
|
"SUBTABLE expression must be of VARCHAR type");
|
||||||
}
|
}
|
||||||
if (NULL != pSelect->pSubtable && 0 == LIST_LENGTH(pSelect->pPartitionByList) && subtableExprHasColumnOrPseudoColumn(pSelect->pSubtable)) {
|
if (NULL != pSelect->pSubtable && 0 == LIST_LENGTH(pSelect->pPartitionByList) &&
|
||||||
|
subtableExprHasColumnOrPseudoColumn(pSelect->pSubtable)) {
|
||||||
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_STREAM_QUERY,
|
||||||
"SUBTABLE expression must not has column when no partition by clause");
|
"SUBTABLE expression must not has column when no partition by clause");
|
||||||
}
|
}
|
||||||
|
@ -7121,7 +7131,6 @@ int32_t translatePostCreateStream(SParseContext* pParseCxt, SQuery* pQuery, void
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t translateDropStream(STranslateContext* pCxt, SDropStreamStmt* pStmt) {
|
static int32_t translateDropStream(STranslateContext* pCxt, SDropStreamStmt* pStmt) {
|
||||||
SMDropStreamReq dropReq = {0};
|
SMDropStreamReq dropReq = {0};
|
||||||
SName name;
|
SName name;
|
||||||
|
@ -7152,7 +7161,7 @@ static int32_t translateResumeStream(STranslateContext* pCxt, SResumeStreamStmt*
|
||||||
|
|
||||||
static int32_t readFromFile(char* pName, int32_t* len, char** buf) {
|
static int32_t readFromFile(char* pName, int32_t* len, char** buf) {
|
||||||
int64_t filesize = 0;
|
int64_t filesize = 0;
|
||||||
if (taosStatFile(pName, &filesize, NULL) < 0) {
|
if (taosStatFile(pName, &filesize, NULL, NULL) < 0) {
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7806,7 +7815,8 @@ static SNodeList* createProjectCols(int32_t ncols, const char* const pCols[]) {
|
||||||
return pProjections;
|
return pProjections;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSimpleSelectStmtImpl(const char* pDb, const char* pTable, SNodeList* pProjectionList, SSelectStmt** pStmt) {
|
static int32_t createSimpleSelectStmtImpl(const char* pDb, const char* pTable, SNodeList* pProjectionList,
|
||||||
|
SSelectStmt** pStmt) {
|
||||||
SSelectStmt* pSelect = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
|
SSelectStmt* pSelect = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
|
||||||
if (NULL == pSelect) {
|
if (NULL == pSelect) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -7829,7 +7839,6 @@ static int32_t createSimpleSelectStmtImpl(const char* pDb, const char* pTable, S
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int32_t createSimpleSelectStmtFromCols(const char* pDb, const char* pTable, int32_t numOfProjs,
|
static int32_t createSimpleSelectStmtFromCols(const char* pDb, const char* pTable, int32_t numOfProjs,
|
||||||
const char* const pProjCol[], SSelectStmt** pStmt) {
|
const char* const pProjCol[], SSelectStmt** pStmt) {
|
||||||
SNodeList* pProjectionList = NULL;
|
SNodeList* pProjectionList = NULL;
|
||||||
|
@ -7843,13 +7852,15 @@ static int32_t createSimpleSelectStmtFromCols(const char* pDb, const char* pTabl
|
||||||
return createSimpleSelectStmtImpl(pDb, pTable, pProjectionList, pStmt);
|
return createSimpleSelectStmtImpl(pDb, pTable, pProjectionList, pStmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSimpleSelectStmtFromProjList(const char* pDb, const char* pTable, SNodeList* pProjectionList, SSelectStmt** pStmt) {
|
static int32_t createSimpleSelectStmtFromProjList(const char* pDb, const char* pTable, SNodeList* pProjectionList,
|
||||||
|
SSelectStmt** pStmt) {
|
||||||
return createSimpleSelectStmtImpl(pDb, pTable, pProjectionList, pStmt);
|
return createSimpleSelectStmtImpl(pDb, pTable, pProjectionList, pStmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt) {
|
static int32_t createSelectStmtForShow(ENodeType showType, SSelectStmt** pStmt) {
|
||||||
const SSysTableShowAdapter* pShow = &sysTableShowAdapter[showType - SYSTABLE_SHOW_TYPE_OFFSET];
|
const SSysTableShowAdapter* pShow = &sysTableShowAdapter[showType - SYSTABLE_SHOW_TYPE_OFFSET];
|
||||||
return createSimpleSelectStmtFromCols(pShow->pDbName, pShow->pTableName, pShow->numOfShowCols, pShow->pShowCols, pStmt);
|
return createSimpleSelectStmtFromCols(pShow->pDbName, pShow->pTableName, pShow->numOfShowCols, pShow->pShowCols,
|
||||||
|
pStmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t createSelectStmtForShowTableDist(SShowTableDistributedStmt* pStmt, SSelectStmt** pOutput) {
|
static int32_t createSelectStmtForShowTableDist(SShowTableDistributedStmt* pStmt, SSelectStmt** pOutput) {
|
||||||
|
@ -7987,8 +7998,8 @@ static int32_t createShowTableTagsProjections(SNodeList** pProjections, SNodeLis
|
||||||
static int32_t rewriteShowStableTags(STranslateContext* pCxt, SQuery* pQuery) {
|
static int32_t rewriteShowStableTags(STranslateContext* pCxt, SQuery* pQuery) {
|
||||||
SShowTableTagsStmt* pShow = (SShowTableTagsStmt*)pQuery->pRoot;
|
SShowTableTagsStmt* pShow = (SShowTableTagsStmt*)pQuery->pRoot;
|
||||||
SSelectStmt* pSelect = NULL;
|
SSelectStmt* pSelect = NULL;
|
||||||
int32_t code = createSimpleSelectStmtFromCols(((SValueNode*)pShow->pDbName)->literal, ((SValueNode*)pShow->pTbName)->literal,
|
int32_t code = createSimpleSelectStmtFromCols(((SValueNode*)pShow->pDbName)->literal,
|
||||||
-1, NULL, &pSelect);
|
((SValueNode*)pShow->pTbName)->literal, -1, NULL, &pSelect);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = createShowTableTagsProjections(&pSelect->pProjectionList, &pShow->pTags);
|
code = createShowTableTagsProjections(&pSelect->pProjectionList, &pShow->pTags);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ int32_t raftStoreReadFile(SSyncNode *pNode) {
|
||||||
const char *file = pNode->raftStorePath;
|
const char *file = pNode->raftStorePath;
|
||||||
SRaftStore *pStore = &pNode->raftStore;
|
SRaftStore *pStore = &pNode->raftStore;
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
sInfo("vgId:%d, raft store file:%s not exist, use default value", pNode->vgId, file);
|
sInfo("vgId:%d, raft store file:%s not exist, use default value", pNode->vgId, file);
|
||||||
pStore->currentTerm = 0;
|
pStore->currentTerm = 0;
|
||||||
pStore->voteFor.addr = 0;
|
pStore->voteFor.addr = 0;
|
||||||
|
|
|
@ -53,7 +53,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) {
|
||||||
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
|
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
|
||||||
|
|
||||||
int64_t fileSize = 0;
|
int64_t fileSize = 0;
|
||||||
taosStatFile(fnameStr, &fileSize, NULL);
|
taosStatFile(fnameStr, &fileSize, NULL, NULL);
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE);
|
TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
|
@ -304,7 +304,7 @@ int walRepairLogFileTs(SWal* pWal, bool* updateMeta) {
|
||||||
|
|
||||||
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
|
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
|
||||||
int32_t mtime = 0;
|
int32_t mtime = 0;
|
||||||
if (taosStatFile(fnameStr, NULL, &mtime) < 0) {
|
if (taosStatFile(fnameStr, NULL, &mtime, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
wError("vgId:%d, failed to stat file due to %s, file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
|
wError("vgId:%d, failed to stat file due to %s, file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -353,7 +353,7 @@ int walTrimIdxFile(SWal* pWal, int32_t fileIdx) {
|
||||||
walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr);
|
walBuildIdxName(pWal, pFileInfo->firstVer, fnameStr);
|
||||||
|
|
||||||
int64_t fileSize = 0;
|
int64_t fileSize = 0;
|
||||||
taosStatFile(fnameStr, &fileSize, NULL);
|
taosStatFile(fnameStr, &fileSize, NULL, NULL);
|
||||||
int64_t records = TMAX(0, pFileInfo->lastVer - pFileInfo->firstVer + 1);
|
int64_t records = TMAX(0, pFileInfo->lastVer - pFileInfo->firstVer + 1);
|
||||||
int64_t lastEndOffset = records * sizeof(SWalIdxEntry);
|
int64_t lastEndOffset = records * sizeof(SWalIdxEntry);
|
||||||
|
|
||||||
|
@ -436,7 +436,7 @@ int walCheckAndRepairMeta(SWal* pWal) {
|
||||||
SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);
|
SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);
|
||||||
|
|
||||||
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
|
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
|
||||||
int32_t code = taosStatFile(fnameStr, &fileSize, NULL);
|
int32_t code = taosStatFile(fnameStr, &fileSize, NULL, NULL);
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
wError("failed to stat file since %s. file:%s", terrstr(), fnameStr);
|
wError("failed to stat file since %s. file:%s", terrstr(), fnameStr);
|
||||||
|
@ -522,7 +522,7 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
|
||||||
walBuildLogName(pWal, pFileInfo->firstVer, fLogNameStr);
|
walBuildLogName(pWal, pFileInfo->firstVer, fLogNameStr);
|
||||||
int64_t fileSize = 0;
|
int64_t fileSize = 0;
|
||||||
|
|
||||||
if (taosStatFile(fnameStr, &fileSize, NULL) < 0 && errno != ENOENT) {
|
if (taosStatFile(fnameStr, &fileSize, NULL, NULL) < 0 && errno != ENOENT) {
|
||||||
wError("vgId:%d, failed to stat file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
|
wError("vgId:%d, failed to stat file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -935,7 +935,7 @@ int walLoadMeta(SWal* pWal) {
|
||||||
walBuildMetaName(pWal, metaVer, fnameStr);
|
walBuildMetaName(pWal, metaVer, fnameStr);
|
||||||
// read metafile
|
// read metafile
|
||||||
int64_t fileSize = 0;
|
int64_t fileSize = 0;
|
||||||
taosStatFile(fnameStr, &fileSize, NULL);
|
taosStatFile(fnameStr, &fileSize, NULL, NULL);
|
||||||
if (fileSize == 0) {
|
if (fileSize == 0) {
|
||||||
(void)taosRemoveFile(fnameStr);
|
(void)taosRemoveFile(fnameStr);
|
||||||
wDebug("vgId:%d, wal find empty meta ver %d", pWal->cfg.vgId, metaVer);
|
wDebug("vgId:%d, wal find empty meta ver %d", pWal->cfg.vgId, metaVer);
|
||||||
|
|
|
@ -191,7 +191,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
|
int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *atime) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
struct _stati64 fileStat;
|
struct _stati64 fileStat;
|
||||||
int32_t code = _stati64(path, &fileStat);
|
int32_t code = _stati64(path, &fileStat);
|
||||||
|
@ -211,6 +211,10 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime) {
|
||||||
*mtime = fileStat.st_mtime;
|
*mtime = fileStat.st_mtime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (atime != NULL) {
|
||||||
|
*atime = fileStat.st_mtime;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
|
int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
|
||||||
|
|
|
@ -17,8 +17,8 @@
|
||||||
#include "tlog.h"
|
#include "tlog.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tconfig.h"
|
#include "tconfig.h"
|
||||||
#include "tjson.h"
|
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
|
#include "tjson.h"
|
||||||
|
|
||||||
#define LOG_MAX_LINE_SIZE (10024)
|
#define LOG_MAX_LINE_SIZE (10024)
|
||||||
#define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 3)
|
#define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 3)
|
||||||
|
@ -403,13 +403,13 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) {
|
||||||
strcpy(name, fn);
|
strcpy(name, fn);
|
||||||
strcat(name, ".0");
|
strcat(name, ".0");
|
||||||
}
|
}
|
||||||
bool log0Exist = taosStatFile(name, NULL, &logstat0_mtime) >= 0;
|
bool log0Exist = taosStatFile(name, NULL, &logstat0_mtime, NULL) >= 0;
|
||||||
|
|
||||||
if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
|
if (strlen(fn) < LOG_FILE_NAME_LEN + 50 - 2) {
|
||||||
strcpy(name, fn);
|
strcpy(name, fn);
|
||||||
strcat(name, ".1");
|
strcat(name, ".1");
|
||||||
}
|
}
|
||||||
bool log1Exist = taosStatFile(name, NULL, &logstat1_mtime) >= 0;
|
bool log1Exist = taosStatFile(name, NULL, &logstat1_mtime, NULL) >= 0;
|
||||||
|
|
||||||
// if none of the log files exist, open 0, if both exists, open the old one
|
// if none of the log files exist, open 0, if both exists, open the old one
|
||||||
if (!log0Exist && !log1Exist) {
|
if (!log0Exist && !log1Exist) {
|
||||||
|
@ -902,7 +902,7 @@ void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr*
|
||||||
|
|
||||||
if (NULL == *pFd) {
|
if (NULL == *pFd) {
|
||||||
int64_t filesize = 0;
|
int64_t filesize = 0;
|
||||||
if (taosStatFile(filepath, &filesize, NULL) < 0) {
|
if (taosStatFile(filepath, &filesize, NULL, NULL) < 0) {
|
||||||
if (ENOENT == errno) {
|
if (ENOENT == errno) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -952,8 +952,8 @@ void taosReadCrashInfo(char* filepath, char** pMsg, int64_t* pMsgLen, TdFilePtr*
|
||||||
readSize = taosReadFile(pFile, buf, msgLen);
|
readSize = taosReadFile(pFile, buf, msgLen);
|
||||||
if (msgLen != readSize) {
|
if (msgLen != readSize) {
|
||||||
truncateFile = true;
|
truncateFile = true;
|
||||||
taosPrintLog(flags, level, dflag, "failed to read file:%s,%p wlen:%" PRId64 " tlen:%" PRId64 " since %s",
|
taosPrintLog(flags, level, dflag, "failed to read file:%s,%p wlen:%" PRId64 " tlen:%" PRId64 " since %s", filepath,
|
||||||
filepath, pFile, readSize, msgLen, terrstr());
|
pFile, readSize, msgLen, terrstr());
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#define _XOPEN_SOURCE
|
#define _XOPEN_SOURCE
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "shellInt.h"
|
|
||||||
#include "shellAuto.h"
|
|
||||||
#include "geosWrapper.h"
|
#include "geosWrapper.h"
|
||||||
|
#include "shellAuto.h"
|
||||||
|
#include "shellInt.h"
|
||||||
|
|
||||||
static bool shellIsEmptyCommand(const char *cmd);
|
static bool shellIsEmptyCommand(const char *cmd);
|
||||||
static int32_t shellRunSingleCommand(char *command);
|
static int32_t shellRunSingleCommand(char *command);
|
||||||
|
@ -387,8 +387,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_BINARY:
|
case TSDB_DATA_TYPE_BINARY:
|
||||||
case TSDB_DATA_TYPE_NCHAR:
|
case TSDB_DATA_TYPE_NCHAR:
|
||||||
case TSDB_DATA_TYPE_JSON:
|
case TSDB_DATA_TYPE_JSON: {
|
||||||
{
|
|
||||||
int32_t bufIndex = 0;
|
int32_t bufIndex = 0;
|
||||||
for (int32_t i = 0; i < length; i++) {
|
for (int32_t i = 0; i < length; i++) {
|
||||||
buf[bufIndex] = val[i];
|
buf[bufIndex] = val[i];
|
||||||
|
@ -401,8 +400,7 @@ void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, i
|
||||||
buf[bufIndex] = 0;
|
buf[bufIndex] = 0;
|
||||||
|
|
||||||
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
|
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
|
||||||
}
|
} break;
|
||||||
break;
|
|
||||||
case TSDB_DATA_TYPE_GEOMETRY:
|
case TSDB_DATA_TYPE_GEOMETRY:
|
||||||
shellDumpHexValue(buf, val, length);
|
shellDumpHexValue(buf, val, length);
|
||||||
taosFprintfFile(pFile, "%s", buf);
|
taosFprintfFile(pFile, "%s", buf);
|
||||||
|
@ -535,12 +533,10 @@ void shellPrintString(const char *str, int32_t width) {
|
||||||
|
|
||||||
if (width == 0) {
|
if (width == 0) {
|
||||||
printf("%s", str);
|
printf("%s", str);
|
||||||
}
|
} else if (len > width) {
|
||||||
else if (len > width) {
|
|
||||||
if (width <= 3) {
|
if (width <= 3) {
|
||||||
printf("%.*s.", width - 1, str);
|
printf("%.*s.", width - 1, str);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
printf("%.*s...", width - 3, str);
|
printf("%.*s...", width - 3, str);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -616,7 +612,6 @@ void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t
|
||||||
} else {
|
} else {
|
||||||
n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.7f", width, GET_FLOAT_VAL(val));
|
n = snprintf(buf, TSDB_MAX_BYTES_PER_ROW, "%*.7f", width, GET_FLOAT_VAL(val));
|
||||||
if (n > SHELL_FLOAT_WIDTH) {
|
if (n > SHELL_FLOAT_WIDTH) {
|
||||||
|
|
||||||
printf("%*.7e", width, GET_FLOAT_VAL(val));
|
printf("%*.7e", width, GET_FLOAT_VAL(val));
|
||||||
} else {
|
} else {
|
||||||
printf("%s", buf);
|
printf("%s", buf);
|
||||||
|
@ -922,7 +917,7 @@ void shellReadHistory() {
|
||||||
taosMemoryFreeClear(line);
|
taosMemoryFreeClear(line);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
int64_t file_size;
|
int64_t file_size;
|
||||||
if (taosStatFile(pHistory->file, &file_size, NULL) == 0 && file_size > SHELL_MAX_COMMAND_SIZE) {
|
if (taosStatFile(pHistory->file, &file_size, NULL, NULL) == 0 && file_size > SHELL_MAX_COMMAND_SIZE) {
|
||||||
TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_STREAM | TD_FILE_TRUNC);
|
TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_STREAM | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) return;
|
if (pFile == NULL) return;
|
||||||
int32_t endIndex = pHistory->hstart;
|
int32_t endIndex = pHistory->hstart;
|
||||||
|
@ -1044,7 +1039,8 @@ void shellGetGrantInfo() {
|
||||||
|
|
||||||
int32_t code = taos_errno(tres);
|
int32_t code = taos_errno(tres);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
if (code != TSDB_CODE_OPS_NOT_SUPPORT && code != TSDB_CODE_MND_NO_RIGHTS && code != TSDB_CODE_PAR_PERMISSION_DENIED) {
|
if (code != TSDB_CODE_OPS_NOT_SUPPORT && code != TSDB_CODE_MND_NO_RIGHTS &&
|
||||||
|
code != TSDB_CODE_PAR_PERMISSION_DENIED) {
|
||||||
fprintf(stderr, "Failed to check Server Edition, Reason:0x%04x:%s\r\n\r\n", code, taos_errstr(tres));
|
fprintf(stderr, "Failed to check Server Edition, Reason:0x%04x:%s\r\n\r\n", code, taos_errstr(tres));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -1080,7 +1076,8 @@ void shellGetGrantInfo() {
|
||||||
} else if (strcmp(expiretime, "unlimited") == 0) {
|
} else if (strcmp(expiretime, "unlimited") == 0) {
|
||||||
fprintf(stdout, "Server is Enterprise %s Edition, %s and will never expire.\r\n", serverVersion, sinfo);
|
fprintf(stdout, "Server is Enterprise %s Edition, %s and will never expire.\r\n", serverVersion, sinfo);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stdout, "Server is Enterprise %s Edition, %s and will expire at %s.\r\n", serverVersion, sinfo, expiretime);
|
fprintf(stdout, "Server is Enterprise %s Edition, %s and will expire at %s.\r\n", serverVersion, sinfo,
|
||||||
|
expiretime);
|
||||||
}
|
}
|
||||||
|
|
||||||
taos_free_result(tres);
|
taos_free_result(tres);
|
||||||
|
@ -1165,8 +1162,7 @@ void *shellThreadLoop(void *arg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t shellExecute() {
|
int32_t shellExecute() {
|
||||||
printf(shell.info.clientVersion, shell.info.cusName,
|
printf(shell.info.clientVersion, shell.info.cusName, taos_get_client_info(), shell.info.cusName);
|
||||||
taos_get_client_info(), shell.info.cusName);
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
SShellArgs *pArgs = &shell.args;
|
SShellArgs *pArgs = &shell.args;
|
||||||
|
|
|
@ -221,7 +221,7 @@ int64_t getDirectorySize(char* dir) {
|
||||||
totalSize += subDirSize;
|
totalSize += subDirSize;
|
||||||
} else if (0 == strcmp(strchr(fileName, '.'), ".log")) { // only calc .log file size, and not include .idx file
|
} else if (0 == strcmp(strchr(fileName, '.'), ".log")) { // only calc .log file size, and not include .idx file
|
||||||
int64_t file_size = 0;
|
int64_t file_size = 0;
|
||||||
taosStatFile(subdir, &file_size, NULL);
|
taosStatFile(subdir, &file_size, NULL, NULL);
|
||||||
totalSize += file_size;
|
totalSize += file_size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -702,4 +702,3 @@ int main(int32_t argc, char* argv[]) {
|
||||||
taosCloseFile(&g_fp);
|
taosCloseFile(&g_fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue