Merge branch '3.0' into fix/3_liaohj
This commit is contained in:
commit
d013e02762
|
@ -2,7 +2,7 @@
|
||||||
# taosadapter
|
# taosadapter
|
||||||
ExternalProject_Add(taosadapter
|
ExternalProject_Add(taosadapter
|
||||||
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
|
GIT_REPOSITORY https://github.com/taosdata/taosadapter.git
|
||||||
GIT_TAG main
|
GIT_TAG 3.0
|
||||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
|
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taosadapter"
|
||||||
BINARY_DIR ""
|
BINARY_DIR ""
|
||||||
#BUILD_IN_SOURCE TRUE
|
#BUILD_IN_SOURCE TRUE
|
||||||
|
|
|
@ -110,6 +110,8 @@ typedef struct SFirstLastRes {
|
||||||
int32_t pkBytes;
|
int32_t pkBytes;
|
||||||
int8_t pkType;
|
int8_t pkType;
|
||||||
STuplePos pos;
|
STuplePos pos;
|
||||||
|
STuplePos nullTuplePos;
|
||||||
|
bool nullTupleSaved;
|
||||||
char buf[];
|
char buf[];
|
||||||
} SFirstLastRes;
|
} SFirstLastRes;
|
||||||
|
|
||||||
|
|
|
@ -29,5 +29,6 @@ int32_t qExecExplainBegin(SQueryPlan *pDag, SExplainCtx **pCtx, int64_t startTs)
|
||||||
int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp);
|
int32_t qExecExplainEnd(SExplainCtx *pCtx, SRetrieveTableRsp **pRsp);
|
||||||
int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp);
|
int32_t qExplainUpdateExecInfo(SExplainCtx *pCtx, SExplainRsp *pRspMsg, int32_t groupId, SRetrieveTableRsp **pRsp);
|
||||||
void qExplainFreeCtx(SExplainCtx *pCtx);
|
void qExplainFreeCtx(SExplainCtx *pCtx);
|
||||||
|
int32_t formatDurationOrKeep(char* buffer, int32_t timeInMinutes);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -143,7 +143,7 @@ int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
|
||||||
int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
|
int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
|
||||||
int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes);
|
int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes);
|
||||||
int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len);
|
int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len);
|
||||||
void taosWinSocketInit();
|
int32_t taosWinSocketInit();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* set timeout(ms)
|
* set timeout(ms)
|
||||||
|
|
|
@ -35,6 +35,8 @@ extern STaosError errors[];
|
||||||
#define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code))))
|
#define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code))))
|
||||||
|
|
||||||
#define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code))
|
#define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code))
|
||||||
|
#define TAOS_SYSTEM_WINAPI_ERROR(code) (0x81ff0000 | (code))
|
||||||
|
#define TAOS_SYSTEM_WINSOCKET_ERROR(code) (0x82ff0000 | (code))
|
||||||
#define TAOS_SUCCEEDED(err) ((err) >= 0)
|
#define TAOS_SUCCEEDED(err) ((err) >= 0)
|
||||||
#define TAOS_FAILED(err) ((err) < 0)
|
#define TAOS_FAILED(err) ((err) < 0)
|
||||||
|
|
||||||
|
@ -153,6 +155,7 @@ int32_t taosGetErrSize();
|
||||||
#define TSDB_CODE_MSG_PREPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0136) // internal
|
#define TSDB_CODE_MSG_PREPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0136) // internal
|
||||||
#define TSDB_CODE_OUT_OF_BUFFER TAOS_DEF_ERROR_CODE(0, 0x0137)
|
#define TSDB_CODE_OUT_OF_BUFFER TAOS_DEF_ERROR_CODE(0, 0x0137)
|
||||||
#define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138)
|
#define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138)
|
||||||
|
#define TSDB_CODE_SOCKET_ERROR TAOS_DEF_ERROR_CODE(0, 0x0139)
|
||||||
|
|
||||||
//client
|
//client
|
||||||
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)
|
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)
|
||||||
|
|
|
@ -55,7 +55,8 @@ Source: favicon.ico; DestDir: "{app}\include"; Flags: igNoreversion;
|
||||||
Source: {#MyAppSourceDir}{#MyAppDLLName}; DestDir: "{win}\System32"; Flags: igNoreversion recursesubdirs createallsubdirs 64bit;Check:IsWin64;
|
Source: {#MyAppSourceDir}{#MyAppDLLName}; DestDir: "{win}\System32"; Flags: igNoreversion recursesubdirs createallsubdirs 64bit;Check:IsWin64;
|
||||||
Source: {#MyAppSourceDir}{#MyAppCfgName}; DestDir: "{app}\cfg"; Flags: igNoreversion recursesubdirs createallsubdirs onlyifdoesntexist uninsneveruninstall
|
Source: {#MyAppSourceDir}{#MyAppCfgName}; DestDir: "{app}\cfg"; Flags: igNoreversion recursesubdirs createallsubdirs onlyifdoesntexist uninsneveruninstall
|
||||||
Source: {#MyAppSourceDir}{#MyAppDriverName}; DestDir: "{app}\driver"; Flags: igNoreversion recursesubdirs createallsubdirs
|
Source: {#MyAppSourceDir}{#MyAppDriverName}; DestDir: "{app}\driver"; Flags: igNoreversion recursesubdirs createallsubdirs
|
||||||
Source: {#MyAppSourceDir}\taos_odbc\*; DestDir: "{app}\taos_odbc\"; Flags: igNoreversion recursesubdirs createallsubdirs
|
Source: {#MyAppSourceDir}\taos_odbc\*; DestDir: "{app}\taos_odbc"; Flags: igNoreversion recursesubdirs createallsubdirs
|
||||||
|
Source: {#MyAppSourceDir}\*.dll; DestDir: "{app}"; Flags: igNoreversion recursesubdirs createallsubdirs
|
||||||
;Source: {#MyAppSourceDir}{#MyAppConnectorName}; DestDir: "{app}\connector"; Flags: igNoreversion recursesubdirs createallsubdirs
|
;Source: {#MyAppSourceDir}{#MyAppConnectorName}; DestDir: "{app}\connector"; Flags: igNoreversion recursesubdirs createallsubdirs
|
||||||
;Source: {#MyAppSourceDir}{#MyAppExamplesName}; DestDir: "{app}\examples"; Flags: igNoreversion recursesubdirs createallsubdirs
|
;Source: {#MyAppSourceDir}{#MyAppExamplesName}; DestDir: "{app}\examples"; Flags: igNoreversion recursesubdirs createallsubdirs
|
||||||
Source: {#MyAppSourceDir}{#MyAppIncludeName}; DestDir: "{app}\include"; Flags: igNoreversion recursesubdirs createallsubdirs
|
Source: {#MyAppSourceDir}{#MyAppIncludeName}; DestDir: "{app}\include"; Flags: igNoreversion recursesubdirs createallsubdirs
|
||||||
|
@ -69,7 +70,9 @@ Source: {#MyAppSourceDir}\taosdump.exe; DestDir: "{app}"; DestName: "{#CusPrompt
|
||||||
[run]
|
[run]
|
||||||
Filename: {sys}\sc.exe; Parameters: "create taosd start= DEMAND binPath= ""C:\\TDengine\\taosd.exe --win_service""" ; Flags: runhidden
|
Filename: {sys}\sc.exe; Parameters: "create taosd start= DEMAND binPath= ""C:\\TDengine\\taosd.exe --win_service""" ; Flags: runhidden
|
||||||
Filename: {sys}\sc.exe; Parameters: "create taosadapter start= DEMAND binPath= ""C:\\TDengine\\taosadapter.exe""" ; Flags: runhidden
|
Filename: {sys}\sc.exe; Parameters: "create taosadapter start= DEMAND binPath= ""C:\\TDengine\\taosadapter.exe""" ; Flags: runhidden
|
||||||
Filename: "{cmd}"; Parameters: "/c odbcconf /F ""C:\TDengine\taos_odbc\win_odbcinst.in"""; WorkingDir: "{app}"; Flags: runhidden; StatusMsg: "Configuring ODBC"
|
|
||||||
|
Filename: "C:\Windows\System32\odbcconf.exe"; Parameters: "/S /F win_odbcinst.ini"; WorkingDir: "{app}\taos_odbc\x64"; Flags: runhidden; StatusMsg: "Configuring ODBC x64"
|
||||||
|
Filename: "C:\Windows\SysWOW64\odbcconf.exe"; Parameters: "/S /F win_odbcinst.ini"; WorkingDir: "{app}\taos_odbc\x86"; Flags: runhidden; StatusMsg: "Configuring ODBC x86"
|
||||||
|
|
||||||
[UninstallRun]
|
[UninstallRun]
|
||||||
RunOnceId: "stoptaosd"; Filename: {sys}\sc.exe; Parameters: "stop taosd" ; Flags: runhidden
|
RunOnceId: "stoptaosd"; Filename: {sys}\sc.exe; Parameters: "stop taosd" ; Flags: runhidden
|
||||||
|
@ -100,32 +103,26 @@ begin
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function DeleteOdbcDsnRegistry: Boolean;
|
function DeleteOdbcDsnRegistry: Boolean;
|
||||||
var
|
|
||||||
Names: TArrayOfString;
|
|
||||||
I: Integer;
|
|
||||||
Value: String;
|
|
||||||
begin
|
begin
|
||||||
if RegGetValueNames(HKCU64, 'SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources', Names) then
|
RegDeleteKeyIncludingSubkeys(HKCU, 'SOFTWARE\ODBC\ODBC.INI\TAOS_ODBC_DSN');
|
||||||
begin
|
RegDeleteKeyIncludingSubkeys(HKCU, 'SOFTWARE\ODBC\ODBC.INI\TAOS_ODBC_WS_DSN')
|
||||||
for I := 0 to GetArrayLength(Names) - 1 do
|
|
||||||
begin
|
RegDeleteValue(HKCU, 'SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources', 'TAOS_ODBC_DSN');
|
||||||
if RegQueryStringValue(HKCU64, 'SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources', Names[I], Value) then
|
RegDeleteValue(HKCU, 'SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources', 'TAOS_ODBC_WS_DSN');
|
||||||
begin
|
|
||||||
if Value = 'TDengine' then
|
|
||||||
begin
|
|
||||||
RegDeleteKeyIncludingSubkeys(HKCU64, 'SOFTWARE\ODBC\ODBC.INI\' + Names[I]);
|
|
||||||
RegDeleteValue(HKCU64, 'SOFTWARE\ODBC\ODBC.INI\ODBC Data Sources\', Names[I]);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function DeleteOdbcDriverRegistry: Boolean;
|
function DeleteOdbcDriverRegistry: Boolean;
|
||||||
begin
|
begin
|
||||||
RegDeleteKeyIncludingSubkeys(HKLM64, 'SOFTWARE\ODBC\ODBCINST.INI\TDengine');
|
// Delete 64-bit ODBC driver registry
|
||||||
RegDeleteValue(HKLM64, 'SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers', 'TDengine');
|
RegDeleteKeyIncludingSubkeys(HKLM64, 'SOFTWARE\ODBC\ODBCINST.INI\TAOS_ODBC_DRIVER');
|
||||||
|
RegDeleteValue(HKLM64, 'SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers', 'TAOS_ODBC_DRIVER');
|
||||||
|
|
||||||
|
// Delete 32-bit ODBC driver registry
|
||||||
|
RegDeleteKeyIncludingSubkeys(HKLM64, 'SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\TAOS_ODBC_DRIVER');
|
||||||
|
RegDeleteValue(HKLM64, 'SOFTWARE\Wow6432Node\ODBC\ODBCINST.INI\ODBC Drivers', 'TAOS_ODBC_DRIVER');
|
||||||
|
|
||||||
Result := True;
|
Result := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,11 @@ static void processFileInTheEnd(TdFilePtr pFile, char* path) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (taosFtruncateFile(pFile, 0) != 0) {
|
if (taosFtruncateFile(pFile, 0) != 0) {
|
||||||
tscError("failed to truncate file:%s, errno:%d", path, errno);
|
tscError("failed to truncate file:%s, errno:%d", path, terrno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (taosUnLockFile(pFile) != 0) {
|
if (taosUnLockFile(pFile) != 0) {
|
||||||
tscError("failed to unlock file:%s, errno:%d", path, errno);
|
tscError("failed to unlock file:%s, errno:%d", path, terrno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (taosCloseFile(&(pFile)) != 0) {
|
if (taosCloseFile(&(pFile)) != 0) {
|
||||||
|
@ -367,7 +367,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP
|
||||||
tscInfo("[monitor] create slow log file:%s", path);
|
tscInfo("[monitor] create slow log file:%s", path);
|
||||||
pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC);
|
pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
tscError("failed to open file:%s since %d", path, errno);
|
tscError("failed to open file:%s since %d", path, terrno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosLSeekFile(pFile, 0, SEEK_END) < 0) {
|
if (taosLSeekFile(pFile, 0, SEEK_END) < 0) {
|
||||||
tscError("failed to seek file:%p code: %d", pFile, errno);
|
tscError("failed to seek file:%p code: %d", pFile, terrno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (taosWriteFile(pFile, slowLogData->data, strlen(slowLogData->data) + 1) < 0) {
|
if (taosWriteFile(pFile, slowLogData->data, strlen(slowLogData->data) + 1) < 0) {
|
||||||
|
@ -409,7 +409,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP
|
||||||
static char* readFile(TdFilePtr pFile, int64_t* offset, int64_t size) {
|
static char* readFile(TdFilePtr pFile, int64_t* offset, int64_t size) {
|
||||||
tscDebug("[monitor] readFile slow begin pFile:%p, offset:%" PRId64 ", size:%" PRId64, pFile, *offset, size);
|
tscDebug("[monitor] readFile slow begin pFile:%p, offset:%" PRId64 ", size:%" PRId64, pFile, *offset, size);
|
||||||
if (taosLSeekFile(pFile, *offset, SEEK_SET) < 0) {
|
if (taosLSeekFile(pFile, *offset, SEEK_SET) < 0) {
|
||||||
tscError("failed to seek file:%p code: %d", pFile, errno);
|
tscError("failed to seek file:%p code: %d", pFile, terrno);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -549,7 +549,7 @@ static void monitorSendSlowLogAtRunning(int64_t clusterId) {
|
||||||
int64_t size = getFileSize(pClient->path);
|
int64_t size = getFileSize(pClient->path);
|
||||||
if (size <= pClient->offset) {
|
if (size <= pClient->offset) {
|
||||||
if (taosFtruncateFile(pClient->pFile, 0) < 0) {
|
if (taosFtruncateFile(pClient->pFile, 0) < 0) {
|
||||||
tscError("failed to truncate file:%p code: %d", pClient->pFile, errno);
|
tscError("failed to truncate file:%p code: %d", pClient->pFile, terrno);
|
||||||
}
|
}
|
||||||
tscDebug("[monitor] monitorSendSlowLogAtRunning truncate file to 0 file:%p", pClient->pFile);
|
tscDebug("[monitor] monitorSendSlowLogAtRunning truncate file to 0 file:%p", pClient->pFile);
|
||||||
pClient->offset = 0;
|
pClient->offset = 0;
|
||||||
|
@ -606,7 +606,7 @@ static void monitorSendAllSlowLogAtQuit() {
|
||||||
|
|
||||||
static void processFileRemoved(SlowLogClient* pClient) {
|
static void processFileRemoved(SlowLogClient* pClient) {
|
||||||
if (taosUnLockFile(pClient->pFile) != 0) {
|
if (taosUnLockFile(pClient->pFile) != 0) {
|
||||||
tscError("failed to unlock file:%s since %d", pClient->path, errno);
|
tscError("failed to unlock file:%s since %d", pClient->path, terrno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
(void)taosCloseFile(&(pClient->pFile));
|
(void)taosCloseFile(&(pClient->pFile));
|
||||||
|
@ -614,7 +614,7 @@ static void processFileRemoved(SlowLogClient* pClient) {
|
||||||
TdFilePtr pFile =
|
TdFilePtr pFile =
|
||||||
taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC);
|
taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
tscError("failed to open file:%s since %d", pClient->path, errno);
|
tscError("failed to open file:%s since %d", pClient->path, terrno);
|
||||||
} else {
|
} else {
|
||||||
pClient->pFile = pFile;
|
pClient->pFile = pFile;
|
||||||
}
|
}
|
||||||
|
@ -821,9 +821,10 @@ int32_t monitorInit() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) {
|
code = taosMulModeMkDir(tmpSlowLogPath, 0777, true);
|
||||||
|
if (code != 0) {
|
||||||
tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr());
|
tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr());
|
||||||
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsem2_init(&monitorSem, 0, 0) != 0) {
|
if (tsem2_init(&monitorSem, 0, 0) != 0) {
|
||||||
|
|
|
@ -128,15 +128,15 @@ int32_t s3CheckCfg() {
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
(void)fprintf(stderr, "failed to open test file: %s.\n", path);
|
(void)fprintf(stderr, "failed to open test file: %s.\n", path);
|
||||||
// uError("ERROR: %s Failed to open %s", __func__, path);
|
// uError("ERROR: %s Failed to open %s", __func__, path);
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next);
|
TAOS_CHECK_GOTO(terrno, &lino, _next);
|
||||||
}
|
}
|
||||||
if (taosWriteFile(fp, testdata, strlen(testdata)) < 0) {
|
if (taosWriteFile(fp, testdata, strlen(testdata)) < 0) {
|
||||||
(void)fprintf(stderr, "failed to write test file: %s.\n", path);
|
(void)fprintf(stderr, "failed to write test file: %s.\n", path);
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next);
|
TAOS_CHECK_GOTO(terrno, &lino, _next);
|
||||||
}
|
}
|
||||||
if (taosFsyncFile(fp) < 0) {
|
if (taosFsyncFile(fp) < 0) {
|
||||||
(void)fprintf(stderr, "failed to fsync test file: %s.\n", path);
|
(void)fprintf(stderr, "failed to fsync test file: %s.\n", path);
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next);
|
TAOS_CHECK_GOTO(terrno, &lino, _next);
|
||||||
}
|
}
|
||||||
(void)taosCloseFile(&fp);
|
(void)taosCloseFile(&fp);
|
||||||
|
|
||||||
|
@ -872,7 +872,7 @@ upload:
|
||||||
|
|
||||||
if (i > 0 && cp.parts[i - 1].completed) {
|
if (i > 0 && cp.parts[i - 1].completed) {
|
||||||
if (taosLSeekFile(data->infileFD, cp.parts[i].offset, SEEK_SET) < 0) {
|
if (taosLSeekFile(data->infileFD, cp.parts[i].offset, SEEK_SET) < 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -988,12 +988,12 @@ int32_t s3PutObjectFromFile2ByEp(const char *file, const char *object_name, int8
|
||||||
|
|
||||||
if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) {
|
if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) {
|
||||||
uError("ERROR: %s Failed to stat file %s: ", __func__, file);
|
uError("ERROR: %s Failed to stat file %s: ", __func__, file);
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) {
|
if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) {
|
||||||
uError("ERROR: %s Failed to open file %s: ", __func__, file);
|
uError("ERROR: %s Failed to open file %s: ", __func__, file);
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength =
|
data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength =
|
||||||
|
@ -1065,18 +1065,18 @@ static int32_t s3PutObjectFromFileOffsetByEp(const char *file, const char *objec
|
||||||
|
|
||||||
if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) {
|
if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) {
|
||||||
uError("ERROR: %s Failed to stat file %s: ", __func__, file);
|
uError("ERROR: %s Failed to stat file %s: ", __func__, file);
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
contentLength = size;
|
contentLength = size;
|
||||||
|
|
||||||
if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) {
|
if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) {
|
||||||
uError("ERROR: %s Failed to open file %s: ", __func__, file);
|
uError("ERROR: %s Failed to open file %s: ", __func__, file);
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
if (taosLSeekFile(data.infileFD, offset, SEEK_SET) < 0) {
|
if (taosLSeekFile(data.infileFD, offset, SEEK_SET) < 0) {
|
||||||
(void)taosCloseFile(&data.infileFD);
|
(void)taosCloseFile(&data.infileFD);
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength =
|
data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength =
|
||||||
|
@ -1412,8 +1412,8 @@ static int32_t s3GetObjectToFileByEp(const char *object_name, const char *fileNa
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
TdFilePtr pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
uError("[s3] open file error, errno:%d, fileName:%s", TAOS_SYSTEM_ERROR(errno), fileName);
|
uError("[s3] open file error, errno:%d, fileName:%s", terrno, fileName);
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
TS3GetData cbd = {0};
|
TS3GetData cbd = {0};
|
||||||
|
@ -1881,7 +1881,6 @@ void s3EvictCache(const char *path, long object_size) {
|
||||||
// 1, list data files' atime under dir(path)
|
// 1, list data files' atime under dir(path)
|
||||||
tdbDirPtr pDir = taosOpenDir(dir_name);
|
tdbDirPtr pDir = taosOpenDir(dir_name);
|
||||||
if (pDir == NULL) {
|
if (pDir == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
vError("failed to open %s since %s", dir_name, terrstr());
|
vError("failed to open %s since %s", dir_name, terrstr());
|
||||||
}
|
}
|
||||||
SArray *evict_files = taosArrayInit(16, sizeof(SEvictFile));
|
SArray *evict_files = taosArrayInit(16, sizeof(SEvictFile));
|
||||||
|
|
|
@ -10,7 +10,7 @@ int32_t cos_cp_open(char const* cp_path, SCheckpoint* checkpoint) {
|
||||||
TdFilePtr fd = taosOpenFile(cp_path, TD_FILE_WRITE | TD_FILE_CREATE /* | TD_FILE_TRUNC*/ | TD_FILE_WRITE_THROUGH);
|
TdFilePtr fd = taosOpenFile(cp_path, TD_FILE_WRITE | TD_FILE_CREATE /* | TD_FILE_TRUNC*/ | TD_FILE_WRITE_THROUGH);
|
||||||
if (!fd) {
|
if (!fd) {
|
||||||
uError("%s Failed to open %s", __func__, cp_path);
|
uError("%s Failed to open %s", __func__, cp_path);
|
||||||
TAOS_CHECK_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_CHECK_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
checkpoint->thefile = fd;
|
checkpoint->thefile = fd;
|
||||||
|
@ -162,7 +162,7 @@ int32_t cos_cp_load(char const* filepath, SCheckpoint* checkpoint) {
|
||||||
|
|
||||||
TdFilePtr fd = taosOpenFile(filepath, TD_FILE_READ);
|
TdFilePtr fd = taosOpenFile(filepath, TD_FILE_READ);
|
||||||
if (!fd) {
|
if (!fd) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = -1;
|
int64_t size = -1;
|
||||||
|
@ -175,7 +175,7 @@ int32_t cos_cp_load(char const* filepath, SCheckpoint* checkpoint) {
|
||||||
|
|
||||||
int64_t n = taosReadFile(fd, cp_body, size);
|
int64_t n = taosReadFile(fd, cp_body, size);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
} else if (n != size) {
|
} else if (n != size) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_FILE_CORRUPTED, &lino, _exit);
|
TAOS_CHECK_GOTO(TSDB_CODE_FILE_CORRUPTED, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
@ -207,13 +207,13 @@ static int32_t cos_cp_save_json(cJSON const* json, SCheckpoint* checkpoint) {
|
||||||
|
|
||||||
TdFilePtr fp = checkpoint->thefile;
|
TdFilePtr fp = checkpoint->thefile;
|
||||||
if (taosFtruncateFile(fp, 0) < 0) {
|
if (taosFtruncateFile(fp, 0) < 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
if (taosLSeekFile(fp, 0, SEEK_SET) < 0) {
|
if (taosLSeekFile(fp, 0, SEEK_SET) < 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
if (taosWriteFile(fp, data, strlen(data)) < 0) {
|
if (taosWriteFile(fp, data, strlen(data)) < 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFsyncFile(fp) < 0) {
|
if (taosFsyncFile(fp) < 0) {
|
||||||
|
|
|
@ -58,7 +58,7 @@ static int32_t generateConfigFile(char* confDir) {
|
||||||
TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
uError("[rsync] open conf file error, dir:%s," ERRNO_ERR_FORMAT, confDir, ERRNO_ERR_DATA);
|
uError("[rsync] open conf file error, dir:%s," ERRNO_ERR_FORMAT, confDir, ERRNO_ERR_DATA);
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
@ -90,10 +90,10 @@ static int32_t generateConfigFile(char* confDir) {
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
uDebug("[rsync] conf:%s", confContent);
|
uDebug("[rsync] conf:%s", confContent);
|
||||||
if (taosWriteFile(pFile, confContent, strlen(confContent)) <= 0) {
|
if (taosWriteFile(pFile, confContent, strlen(confContent)) != TSDB_CODE_SUCCESS) {
|
||||||
uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA);
|
uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA);
|
||||||
(void)taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,20 +71,20 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(terrno));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to open mnode file:%s since %s", file, tstrerror(code));
|
dError("failed to open mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, pData, size) != size) {
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
|
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -197,17 +197,17 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (taosFsyncFile(pFile) < 0) {
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,10 +215,7 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);
|
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
||||||
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, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dInfo("vnode file:%s not exist, reason:%s", file, tstrerror(code));
|
dInfo("vnode file:%s not exist, reason:%s", file, tstrerror(code));
|
||||||
code = 0;
|
code = 0;
|
||||||
return code;
|
return code;
|
||||||
|
@ -114,14 +114,14 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to open vnode file:%s since %s", file, tstrerror(code));
|
dError("failed to open vnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, pData, size) != size) {
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
|
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -234,13 +234,13 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (taosFsyncFile(pFile) < 0) {
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
@ -253,12 +253,8 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = 0;
|
|
||||||
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
|
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
|
|
@ -203,14 +203,14 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -333,16 +333,15 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
if (pFile == NULL) TAOS_CHECK_GOTO(terrno, NULL, _OVER);
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(terrno, NULL, _OVER);
|
||||||
if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(terrno, NULL, _OVER);
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
|
||||||
|
|
||||||
code = 0;
|
|
||||||
pData->updateTime = taosGetTimestampMs();
|
pData->updateTime = taosGetTimestampMs();
|
||||||
dInfo("succeed to write dnode file:%s, num:%d ver:%" PRId64, realfile, (int32_t)taosArrayGetSize(pData->dnodeEps),
|
dInfo("succeed to write dnode file:%s, num:%d ver:%" PRId64, realfile, (int32_t)taosArrayGetSize(pData->dnodeEps),
|
||||||
pData->dnodeVer);
|
pData->dnodeVer);
|
||||||
|
@ -599,7 +598,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
||||||
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, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dDebug("dnode file:%s not exist, reason:%s", file, tstrerror(code));
|
dDebug("dnode file:%s not exist, reason:%s", file, tstrerror(code));
|
||||||
code = 0;
|
code = 0;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
@ -607,14 +606,14 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -626,7 +625,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = terrno;
|
||||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,14 +56,14 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to open file:%s since %s", file, tstrerror(code));
|
dError("failed to open file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
dError("failed to fstat file:%s since %s", file, tstrerror(code));
|
dError("failed to fstat file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to read file:%s since %s", file, tstrerror(code));
|
dError("failed to read file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -148,17 +148,17 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (taosFsyncFile(pFile) < 0) {
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,12 +166,8 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = 0;
|
|
||||||
dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
|
dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
@ -192,7 +188,7 @@ int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) {
|
||||||
|
|
||||||
*pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC);
|
*pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC);
|
||||||
if (*pFile == NULL) {
|
if (*pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to open file:%s since %s", filepath, tstrerror(code));
|
dError("failed to open file:%s since %s", filepath, tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -203,7 +199,7 @@ int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) {
|
||||||
ret = taosLockFile(*pFile);
|
ret = taosLockFile(*pFile);
|
||||||
if (ret == 0) break;
|
if (ret == 0) break;
|
||||||
|
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
taosMsleep(1000);
|
taosMsleep(1000);
|
||||||
retryTimes++;
|
retryTimes++;
|
||||||
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, tstrerror(code), retryTimes);
|
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, tstrerror(code), retryTimes);
|
||||||
|
@ -243,12 +239,12 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosWriteFile(pFile, opts.result, len) <= 0) {
|
if (taosWriteFile(pFile, opts.result, len) <= 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,10 +258,7 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
encryptDebug("succeed to write checkCode file:%s", realfile);
|
encryptDebug("succeed to write checkCode file:%s", realfile);
|
||||||
|
|
||||||
|
@ -283,17 +276,17 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t len = strlen(encryptCode);
|
int32_t len = strlen(encryptCode);
|
||||||
if (taosWriteFile(pFile, encryptCode, len) <= 0) {
|
if (taosWriteFile(pFile, encryptCode, len) <= 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (taosFsyncFile(pFile) < 0) {
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,10 +295,7 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _OVER;
|
|
||||||
}
|
|
||||||
|
|
||||||
encryptDebug("succeed to write encryptCode file:%s", realfile);
|
encryptDebug("succeed to write encryptCode file:%s", realfile);
|
||||||
|
|
||||||
|
@ -325,25 +315,25 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
encryptError("failed to open dnode file:%s since %s", file, tstrerror(code));
|
encryptError("failed to open dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
encryptError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
|
encryptError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size);
|
content = taosMemoryMalloc(size);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
encryptError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
encryptError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -465,14 +455,14 @@ static int32_t dmReadEncryptCodeFile(char *file, char **output) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to open dnode file:%s since %s", file, tstrerror(code));
|
dError("failed to open dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
dError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
|
dError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -484,7 +474,7 @@ static int32_t dmReadEncryptCodeFile(char *file, char **output) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "systable.h"
|
#include "systable.h"
|
||||||
#include "thttp.h"
|
#include "thttp.h"
|
||||||
#include "tjson.h"
|
#include "tjson.h"
|
||||||
|
#include "command.h"
|
||||||
|
|
||||||
#define DB_VER_NUMBER 1
|
#define DB_VER_NUMBER 1
|
||||||
#define DB_RESERVE_SIZE 27
|
#define DB_RESERVE_SIZE 27
|
||||||
|
@ -2321,18 +2322,25 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb,
|
||||||
(void)colDataSetVal(pColInfo, rows, (const char *)strictVstr, false);
|
(void)colDataSetVal(pColInfo, rows, (const char *)strictVstr, false);
|
||||||
|
|
||||||
char durationVstr[128] = {0};
|
char durationVstr[128] = {0};
|
||||||
int32_t len = sprintf(&durationVstr[VARSTR_HEADER_SIZE], "%dm", pDb->cfg.daysPerFile);
|
int32_t len = formatDurationOrKeep(&durationVstr[VARSTR_HEADER_SIZE], pDb->cfg.daysPerFile);
|
||||||
|
|
||||||
varDataSetLen(durationVstr, len);
|
varDataSetLen(durationVstr, len);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
(void)colDataSetVal(pColInfo, rows, (const char *)durationVstr, false);
|
(void)colDataSetVal(pColInfo, rows, (const char *)durationVstr, false);
|
||||||
|
|
||||||
char keepVstr[128] = {0};
|
char keepVstr[512] = {0};
|
||||||
|
char keep0Str[128] = {0};
|
||||||
|
char keep1Str[128] = {0};
|
||||||
|
char keep2Str[128] = {0};
|
||||||
|
|
||||||
|
int32_t lenKeep0 = formatDurationOrKeep(keep0Str, pDb->cfg.daysToKeep0);
|
||||||
|
int32_t lenKeep1 = formatDurationOrKeep(keep1Str, pDb->cfg.daysToKeep1);
|
||||||
|
int32_t lenKeep2 = formatDurationOrKeep(keep2Str, pDb->cfg.daysToKeep2);
|
||||||
|
|
||||||
if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) {
|
if (pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep1 || pDb->cfg.daysToKeep0 > pDb->cfg.daysToKeep2) {
|
||||||
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep1, pDb->cfg.daysToKeep2,
|
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep1Str, keep2Str, keep0Str);
|
||||||
pDb->cfg.daysToKeep0);
|
|
||||||
} else {
|
} else {
|
||||||
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%dm,%dm,%dm", pDb->cfg.daysToKeep0, pDb->cfg.daysToKeep1,
|
len = sprintf(&keepVstr[VARSTR_HEADER_SIZE], "%s,%s,%s", keep0Str, keep1Str, keep2Str);
|
||||||
pDb->cfg.daysToKeep2);
|
|
||||||
}
|
}
|
||||||
varDataSetLen(keepVstr, len);
|
varDataSetLen(keepVstr, len);
|
||||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||||
|
|
|
@ -616,7 +616,7 @@ void mndDumpSdb() {
|
||||||
char file[] = "sdb.json";
|
char file[] = "sdb.json";
|
||||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = terrno;
|
||||||
mError("failed to write %s since %s", file, terrstr());
|
mError("failed to write %s since %s", file, terrstr());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,6 +64,8 @@ static int32_t mndProcessKillTransReq(SRpcMsg *pReq);
|
||||||
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
static int32_t mndRetrieveTrans(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||||
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter);
|
static void mndCancelGetNextTrans(SMnode *pMnode, void *pIter);
|
||||||
|
|
||||||
|
static int32_t tsMaxTransId = 0;
|
||||||
|
|
||||||
int32_t mndInitTrans(SMnode *pMnode) {
|
int32_t mndInitTrans(SMnode *pMnode) {
|
||||||
SSdbTable table = {
|
SSdbTable table = {
|
||||||
.sdbType = SDB_TRANS,
|
.sdbType = SDB_TRANS,
|
||||||
|
@ -602,7 +604,10 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnConflct conflict,
|
||||||
tstrncpy(pTrans->opername, opername, TSDB_TRANS_OPER_LEN);
|
tstrncpy(pTrans->opername, opername, TSDB_TRANS_OPER_LEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
pTrans->id = sdbGetMaxId(pMnode->pSdb, SDB_TRANS);
|
int32_t sdbMaxId = sdbGetMaxId(pMnode->pSdb, SDB_TRANS);
|
||||||
|
sdbReadLock(pMnode->pSdb, SDB_TRANS);
|
||||||
|
pTrans->id = TMAX(sdbMaxId, tsMaxTransId + 1);
|
||||||
|
sdbUnLock(pMnode->pSdb, SDB_TRANS);
|
||||||
pTrans->stage = TRN_STAGE_PREPARE;
|
pTrans->stage = TRN_STAGE_PREPARE;
|
||||||
pTrans->policy = policy;
|
pTrans->policy = policy;
|
||||||
pTrans->conflict = conflict;
|
pTrans->conflict = conflict;
|
||||||
|
@ -1027,6 +1032,9 @@ int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans) {
|
||||||
mInfo("trans:%d, prepare transaction", pTrans->id);
|
mInfo("trans:%d, prepare transaction", pTrans->id);
|
||||||
if ((code = mndTransSync(pMnode, pTrans)) != 0) {
|
if ((code = mndTransSync(pMnode, pTrans)) != 0) {
|
||||||
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
mError("trans:%d, failed to prepare since %s", pTrans->id, tstrerror(code));
|
||||||
|
sdbWriteLock(pMnode->pSdb, SDB_TRANS);
|
||||||
|
tsMaxTransId = TMAX(pTrans->id, tsMaxTransId);
|
||||||
|
sdbUnLock(pMnode->pSdb, SDB_TRANS);
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
mInfo("trans:%d, prepare finished", pTrans->id);
|
mInfo("trans:%d, prepare finished", pTrans->id);
|
||||||
|
|
|
@ -86,8 +86,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
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) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
|
@ -100,8 +99,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
|
|
||||||
ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t));
|
ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
|
@ -110,8 +108,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
|
|
||||||
ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t));
|
ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
|
@ -120,8 +117,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
|
|
||||||
ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t));
|
ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t));
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
|
@ -132,8 +128,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
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) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
|
@ -148,8 +143,7 @@ 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) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
if (ret != sizeof(int64_t)) {
|
if (ret != sizeof(int64_t)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
|
@ -163,8 +157,7 @@ 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) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
if (ret != sizeof(reserve)) {
|
if (ret != sizeof(reserve)) {
|
||||||
code = TSDB_CODE_FILE_CORRUPTED;
|
code = TSDB_CODE_FILE_CORRUPTED;
|
||||||
|
@ -175,26 +168,21 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
|
||||||
}
|
}
|
||||||
|
|
||||||
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)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
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)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
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)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
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)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) {
|
||||||
|
@ -203,8 +191,7 @@ 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)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,15 +201,13 @@ 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)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
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)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
TAOS_RETURN(code);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -249,7 +234,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
||||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
taosMemoryFree(pRaw);
|
taosMemoryFree(pRaw);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
mInfo("read sdb file:%s finished since %s", file, tstrerror(code));
|
mInfo("read sdb file:%s finished since %s", file, tstrerror(code));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -274,7 +259,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
||||||
if (ret == 0) break;
|
if (ret == 0) break;
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
mError("failed to read sdb file:%s since %s", file, tstrerror(code));
|
mError("failed to read sdb file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -305,7 +290,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
|
||||||
|
|
||||||
ret = taosReadFile(pFile, pRaw->pData, readLen);
|
ret = taosReadFile(pFile, pRaw->pData, readLen);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
mError("failed to read sdb file:%s since %s, ret:%" PRId64 " readLen:%d", file, tstrerror(code), ret, readLen);
|
mError("failed to read sdb file:%s since %s, ret:%" PRId64 " readLen:%d", file, tstrerror(code), ret, readLen);
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -401,7 +386,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
|
||||||
|
|
||||||
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) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code));
|
mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code));
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
@ -447,7 +432,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
|
||||||
pRaw->status = pRow->status;
|
pRaw->status = pRow->status;
|
||||||
|
|
||||||
if (taosWriteFile(pFile, pRaw, sizeof(SSdbRaw)) != sizeof(SSdbRaw)) {
|
if (taosWriteFile(pFile, pRaw, sizeof(SSdbRaw)) != sizeof(SSdbRaw)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
taosHashCancelIterate(hash, ppRow);
|
taosHashCancelIterate(hash, ppRow);
|
||||||
sdbFreeRaw(pRaw);
|
sdbFreeRaw(pRaw);
|
||||||
break;
|
break;
|
||||||
|
@ -479,7 +464,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosWriteFile(pFile, newData, newDataLen) != newDataLen) {
|
if (taosWriteFile(pFile, newData, newDataLen) != newDataLen) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
taosHashCancelIterate(hash, ppRow);
|
taosHashCancelIterate(hash, ppRow);
|
||||||
sdbFreeRaw(pRaw);
|
sdbFreeRaw(pRaw);
|
||||||
break;
|
break;
|
||||||
|
@ -491,7 +476,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
|
||||||
|
|
||||||
int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen);
|
int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen);
|
||||||
if (taosWriteFile(pFile, &cksum, sizeof(int32_t)) != sizeof(int32_t)) {
|
if (taosWriteFile(pFile, &cksum, sizeof(int32_t)) != sizeof(int32_t)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = errno;
|
||||||
taosHashCancelIterate(hash, ppRow);
|
taosHashCancelIterate(hash, ppRow);
|
||||||
sdbFreeRaw(pRaw);
|
sdbFreeRaw(pRaw);
|
||||||
break;
|
break;
|
||||||
|
@ -523,7 +508,6 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
code = taosRenameFile(tmpfile, curfile);
|
code = taosRenameFile(tmpfile, curfile);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
mError("failed to write sdb file:%s since %s", curfile, tstrerror(code));
|
mError("failed to write sdb file:%s since %s", curfile, tstrerror(code));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -654,8 +638,8 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
|
||||||
int64_t commitTerm = pSdb->commitTerm;
|
int64_t commitTerm = pSdb->commitTerm;
|
||||||
int64_t commitConfig = pSdb->commitConfig;
|
int64_t commitConfig = pSdb->commitConfig;
|
||||||
if (taosCopyFile(datafile, pIter->name) < 0) {
|
if (taosCopyFile(datafile, pIter->name) < 0) {
|
||||||
|
code = terrno;
|
||||||
(void)taosThreadMutexUnlock(&pSdb->filelock);
|
(void)taosThreadMutexUnlock(&pSdb->filelock);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code));
|
mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code));
|
||||||
sdbCloseIter(pIter);
|
sdbCloseIter(pIter);
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
|
@ -664,7 +648,7 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter
|
||||||
|
|
||||||
pIter->file = taosOpenFile(pIter->name, TD_FILE_READ);
|
pIter->file = taosOpenFile(pIter->name, TD_FILE_READ);
|
||||||
if (pIter->file == NULL) {
|
if (pIter->file == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code));
|
mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code));
|
||||||
sdbCloseIter(pIter);
|
sdbCloseIter(pIter);
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
|
@ -693,7 +677,7 @@ int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
|
||||||
|
|
||||||
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) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, tstrerror(code), 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;
|
||||||
|
@ -724,7 +708,7 @@ int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) {
|
||||||
|
|
||||||
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) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
mError("failed to open %s since %s", pIter->name, tstrerror(code));
|
mError("failed to open %s since %s", pIter->name, tstrerror(code));
|
||||||
sdbCloseIter(pIter);
|
sdbCloseIter(pIter);
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
|
@ -758,8 +742,8 @@ 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) {
|
code = taosRenameFile(pIter->name, datafile);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code));
|
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -792,7 +776,7 @@ int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) {
|
||||||
int32_t code = 0;
|
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) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total);
|
mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total);
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
|
|
@ -292,7 +292,7 @@ int32_t tsdbReadDelData(SDelFReader *pReader, SDelIdx *pDelIdx, SArray *aDelData
|
||||||
int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx);
|
int32_t tsdbReadDelIdx(SDelFReader *pReader, SArray *aDelIdx);
|
||||||
|
|
||||||
// tsdbRead.c ==============================================================================================
|
// tsdbRead.c ==============================================================================================
|
||||||
int32_t tsdbTakeReadSnap2(STsdbReader *pReader, _query_reseek_func_t reseek, STsdbReadSnap **ppSnap);
|
int32_t tsdbTakeReadSnap2(STsdbReader *pReader, _query_reseek_func_t reseek, STsdbReadSnap **ppSnap, const char* id);
|
||||||
void tsdbUntakeReadSnap2(STsdbReader *pReader, STsdbReadSnap *pSnap, bool proactive);
|
void tsdbUntakeReadSnap2(STsdbReader *pReader, STsdbReadSnap *pSnap, bool proactive);
|
||||||
int32_t tsdbGetTableSchema(SMeta *pMeta, int64_t uid, STSchema **pSchema, int64_t *suid);
|
int32_t tsdbGetTableSchema(SMeta *pMeta, int64_t uid, STSchema **pSchema, int64_t *suid);
|
||||||
|
|
||||||
|
@ -342,7 +342,6 @@ typedef struct {
|
||||||
rocksdb_writeoptions_t *writeoptions;
|
rocksdb_writeoptions_t *writeoptions;
|
||||||
rocksdb_readoptions_t *readoptions;
|
rocksdb_readoptions_t *readoptions;
|
||||||
rocksdb_writebatch_t *writebatch;
|
rocksdb_writebatch_t *writebatch;
|
||||||
rocksdb_writebatch_t *rwritebatch;
|
|
||||||
STSchema *pTSchema;
|
STSchema *pTSchema;
|
||||||
} SRocksCache;
|
} SRocksCache;
|
||||||
|
|
||||||
|
@ -363,7 +362,6 @@ struct STsdb {
|
||||||
SMemTable *imem;
|
SMemTable *imem;
|
||||||
STsdbFS fs; // old
|
STsdbFS fs; // old
|
||||||
SLRUCache *lruCache;
|
SLRUCache *lruCache;
|
||||||
SCacheFlushState flushState;
|
|
||||||
TdThreadMutex lruMutex;
|
TdThreadMutex lruMutex;
|
||||||
SLRUCache *biCache;
|
SLRUCache *biCache;
|
||||||
TdThreadMutex biMutex;
|
TdThreadMutex biMutex;
|
||||||
|
|
|
@ -214,10 +214,8 @@ static int32_t tsdbOpenRocksCache(STsdb *pTsdb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
rocksdb_writebatch_t *writebatch = rocksdb_writebatch_create();
|
rocksdb_writebatch_t *writebatch = rocksdb_writebatch_create();
|
||||||
rocksdb_writebatch_t *rwritebatch = rocksdb_writebatch_create();
|
|
||||||
|
|
||||||
pTsdb->rCache.writebatch = writebatch;
|
pTsdb->rCache.writebatch = writebatch;
|
||||||
pTsdb->rCache.rwritebatch = rwritebatch;
|
|
||||||
pTsdb->rCache.my_comparator = cmp;
|
pTsdb->rCache.my_comparator = cmp;
|
||||||
pTsdb->rCache.options = options;
|
pTsdb->rCache.options = options;
|
||||||
pTsdb->rCache.writeoptions = writeoptions;
|
pTsdb->rCache.writeoptions = writeoptions;
|
||||||
|
@ -248,7 +246,6 @@ static void tsdbCloseRocksCache(STsdb *pTsdb) {
|
||||||
rocksdb_close(pTsdb->rCache.db);
|
rocksdb_close(pTsdb->rCache.db);
|
||||||
rocksdb_flushoptions_destroy(pTsdb->rCache.flushoptions);
|
rocksdb_flushoptions_destroy(pTsdb->rCache.flushoptions);
|
||||||
rocksdb_writebatch_destroy(pTsdb->rCache.writebatch);
|
rocksdb_writebatch_destroy(pTsdb->rCache.writebatch);
|
||||||
rocksdb_writebatch_destroy(pTsdb->rCache.rwritebatch);
|
|
||||||
rocksdb_readoptions_destroy(pTsdb->rCache.readoptions);
|
rocksdb_readoptions_destroy(pTsdb->rCache.readoptions);
|
||||||
rocksdb_writeoptions_destroy(pTsdb->rCache.writeoptions);
|
rocksdb_writeoptions_destroy(pTsdb->rCache.writeoptions);
|
||||||
rocksdb_options_destroy(pTsdb->rCache.options);
|
rocksdb_options_destroy(pTsdb->rCache.options);
|
||||||
|
@ -258,8 +255,8 @@ static void tsdbCloseRocksCache(STsdb *pTsdb) {
|
||||||
taosMemoryFree(pTsdb->rCache.pTSchema);
|
taosMemoryFree(pTsdb->rCache.pTSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rocksMayWrite(STsdb *pTsdb, bool force, bool read) {
|
static void rocksMayWrite(STsdb *pTsdb, bool force) {
|
||||||
rocksdb_writebatch_t *wb = read ? pTsdb->rCache.rwritebatch : pTsdb->rCache.writebatch;
|
rocksdb_writebatch_t *wb = pTsdb->rCache.writebatch;
|
||||||
|
|
||||||
int count = rocksdb_writebatch_count(wb);
|
int count = rocksdb_writebatch_count(wb);
|
||||||
if ((force && count > 0) || count >= ROCKS_BATCH_SIZE) {
|
if ((force && count > 0) || count >= ROCKS_BATCH_SIZE) {
|
||||||
|
@ -270,7 +267,6 @@ static void rocksMayWrite(STsdb *pTsdb, bool force, bool read) {
|
||||||
tsdbError("vgId:%d, %s failed at line %d, count: %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, count,
|
tsdbError("vgId:%d, %s failed at line %d, count: %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__, count,
|
||||||
err);
|
err);
|
||||||
rocksdb_free(err);
|
rocksdb_free(err);
|
||||||
// pTsdb->flushState.flush_count = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rocksdb_writebatch_clear(wb);
|
rocksdb_writebatch_clear(wb);
|
||||||
|
@ -459,47 +455,23 @@ static int32_t tsdbCacheSerialize(SLastCol *pLastCol, char **value, size_t *size
|
||||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tsdbCachePutBatch(SLastCol *pLastCol, const void *key, size_t klen, SCacheFlushState *state) {
|
static int32_t tsdbCachePutToRocksdb(STsdb *pTsdb, SLastKey *pLastKey, SLastCol *pLastCol);
|
||||||
int32_t code = 0;
|
|
||||||
STsdb *pTsdb = state->pTsdb;
|
|
||||||
SRocksCache *rCache = &pTsdb->rCache;
|
|
||||||
rocksdb_writebatch_t *wb = rCache->writebatch;
|
|
||||||
char *rocks_value = NULL;
|
|
||||||
size_t vlen = 0;
|
|
||||||
|
|
||||||
code = tsdbCacheSerialize(pLastCol, &rocks_value, &vlen);
|
|
||||||
if (code) {
|
|
||||||
tsdbError("tsdb/cache: vgId:%d, serialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
rocksdb_writebatch_put(wb, (char *)key, klen, rocks_value, vlen);
|
|
||||||
|
|
||||||
taosMemoryFree(rocks_value);
|
|
||||||
|
|
||||||
if (++state->flush_count >= ROCKS_BATCH_SIZE) {
|
|
||||||
char *err = NULL;
|
|
||||||
|
|
||||||
rocksdb_write(rCache->db, rCache->writeoptions, wb, &err);
|
|
||||||
if (NULL != err) {
|
|
||||||
tsdbError("vgId:%d, %s failed at line %d, count: %d since %s", TD_VID(pTsdb->pVnode), __func__, __LINE__,
|
|
||||||
state->flush_count, err);
|
|
||||||
rocksdb_free(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
rocksdb_writebatch_clear(wb);
|
|
||||||
|
|
||||||
state->flush_count = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int tsdbCacheFlushDirty(const void *key, size_t klen, void *value, void *ud) {
|
int tsdbCacheFlushDirty(const void *key, size_t klen, void *value, void *ud) {
|
||||||
SLastCol *pLastCol = (SLastCol *)value;
|
SLastCol *pLastCol = (SLastCol *)value;
|
||||||
|
|
||||||
if (pLastCol->dirty) {
|
if (pLastCol->dirty) {
|
||||||
tsdbCachePutBatch(pLastCol, key, klen, (SCacheFlushState *)ud);
|
STsdb *pTsdb = (STsdb *)ud;
|
||||||
|
|
||||||
|
int32_t code = tsdbCachePutToRocksdb(pTsdb, (SLastKey *)key, pLastCol);
|
||||||
|
if (code) {
|
||||||
|
tsdbError("tsdb/cache: vgId:%d, flush dirty lru failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
pLastCol->dirty = 0;
|
pLastCol->dirty = 0;
|
||||||
|
|
||||||
|
rocksMayWrite(pTsdb, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -514,10 +486,9 @@ int32_t tsdbCacheCommit(STsdb *pTsdb) {
|
||||||
|
|
||||||
(void)taosThreadMutexLock(&pTsdb->lruMutex);
|
(void)taosThreadMutexLock(&pTsdb->lruMutex);
|
||||||
|
|
||||||
taosLRUCacheApply(pCache, tsdbCacheFlushDirty, &pTsdb->flushState);
|
taosLRUCacheApply(pCache, tsdbCacheFlushDirty, pTsdb);
|
||||||
|
|
||||||
rocksMayWrite(pTsdb, true, false);
|
rocksMayWrite(pTsdb, true);
|
||||||
rocksMayWrite(pTsdb, true, true);
|
|
||||||
rocksdb_flush(pTsdb->rCache.db, pTsdb->rCache.flushoptions, &err);
|
rocksdb_flush(pTsdb->rCache.db, pTsdb->rCache.flushoptions, &err);
|
||||||
|
|
||||||
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
|
@ -606,7 +577,7 @@ static void tsdbCacheDeleter(const void *key, size_t klen, void *value, void *ud
|
||||||
SLastCol *pLastCol = (SLastCol *)value;
|
SLastCol *pLastCol = (SLastCol *)value;
|
||||||
|
|
||||||
if (pLastCol->dirty) {
|
if (pLastCol->dirty) {
|
||||||
tsdbCachePutBatch(pLastCol, key, klen, (SCacheFlushState *)ud);
|
(void)tsdbCacheFlushDirty(key, klen, pLastCol, ud);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < pLastCol->rowKey.numOfPKs; ++i) {
|
for (uint8_t i = 0; i < pLastCol->rowKey.numOfPKs; ++i) {
|
||||||
|
@ -643,11 +614,11 @@ static int32_t tsdbCacheNewTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, i
|
||||||
|
|
||||||
SLastKey *pLastKey = &(SLastKey){.lflag = lflag, .uid = uid, .cid = cid};
|
SLastKey *pLastKey = &(SLastKey){.lflag = lflag, .uid = uid, .cid = cid};
|
||||||
LRUStatus status = taosLRUCacheInsert(pCache, pLastKey, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, NULL,
|
LRUStatus status = taosLRUCacheInsert(pCache, pLastKey, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, NULL,
|
||||||
TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState);
|
TAOS_LRU_PRIORITY_LOW, pTsdb);
|
||||||
if (status != TAOS_LRU_STATUS_OK) {
|
if (status != TAOS_LRU_STATUS_OK) {
|
||||||
tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
|
tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
|
||||||
tsdbCacheFreeSLastColItem(pLastCol);
|
|
||||||
code = TSDB_CODE_FAILED;
|
code = TSDB_CODE_FAILED;
|
||||||
|
pLastCol = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -665,10 +636,9 @@ int32_t tsdbCacheCommitNoLock(STsdb *pTsdb) {
|
||||||
SLRUCache *pCache = pTsdb->lruCache;
|
SLRUCache *pCache = pTsdb->lruCache;
|
||||||
rocksdb_writebatch_t *wb = pTsdb->rCache.writebatch;
|
rocksdb_writebatch_t *wb = pTsdb->rCache.writebatch;
|
||||||
|
|
||||||
taosLRUCacheApply(pCache, tsdbCacheFlushDirty, &pTsdb->flushState);
|
taosLRUCacheApply(pCache, tsdbCacheFlushDirty, pTsdb);
|
||||||
|
|
||||||
rocksMayWrite(pTsdb, true, false);
|
rocksMayWrite(pTsdb, true);
|
||||||
rocksMayWrite(pTsdb, true, true);
|
|
||||||
rocksdb_flush(pTsdb->rCache.db, pTsdb->rCache.flushoptions, &err);
|
rocksdb_flush(pTsdb->rCache.db, pTsdb->rCache.flushoptions, &err);
|
||||||
|
|
||||||
if (NULL != err) {
|
if (NULL != err) {
|
||||||
|
@ -738,6 +708,10 @@ static int32_t tsdbCacheDropTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid,
|
||||||
|
|
||||||
char **values_list = NULL;
|
char **values_list = NULL;
|
||||||
size_t *values_list_sizes = NULL;
|
size_t *values_list_sizes = NULL;
|
||||||
|
|
||||||
|
// was written by caller
|
||||||
|
// rocksMayWrite(pTsdb, true); // flush writebatch cache
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(tsdbCacheGetValuesFromRocks(pTsdb, 2, (const char *const *)keys_list, keys_list_sizes, &values_list,
|
TAOS_CHECK_GOTO(tsdbCacheGetValuesFromRocks(pTsdb, 2, (const char *const *)keys_list, keys_list_sizes, &values_list,
|
||||||
&values_list_sizes),
|
&values_list_sizes),
|
||||||
NULL, _exit);
|
NULL, _exit);
|
||||||
|
@ -862,7 +836,7 @@ int32_t tsdbCacheDropTable(STsdb *pTsdb, tb_uid_t uid, tb_uid_t suid, SSchemaWra
|
||||||
taosMemoryFree(pTSchema);
|
taosMemoryFree(pTSchema);
|
||||||
}
|
}
|
||||||
|
|
||||||
rocksMayWrite(pTsdb, true, false);
|
rocksMayWrite(pTsdb, false);
|
||||||
|
|
||||||
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
|
|
||||||
|
@ -903,7 +877,7 @@ int32_t tsdbCacheDropSubTables(STsdb *pTsdb, SArray *uids, tb_uid_t suid) {
|
||||||
|
|
||||||
taosMemoryFree(pTSchema);
|
taosMemoryFree(pTSchema);
|
||||||
|
|
||||||
rocksMayWrite(pTsdb, true, false);
|
rocksMayWrite(pTsdb, false);
|
||||||
|
|
||||||
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
|
|
||||||
|
@ -934,7 +908,7 @@ int32_t tsdbCacheDropNTableColumn(STsdb *pTsdb, int64_t uid, int16_t cid, bool h
|
||||||
|
|
||||||
(void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey);
|
(void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey);
|
||||||
|
|
||||||
rocksMayWrite(pTsdb, true, false);
|
rocksMayWrite(pTsdb, false);
|
||||||
|
|
||||||
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
|
|
||||||
|
@ -973,7 +947,7 @@ int32_t tsdbCacheDropSTableColumn(STsdb *pTsdb, SArray *uids, int16_t cid, bool
|
||||||
(void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey);
|
(void)tsdbCacheDropTableColumn(pTsdb, uid, cid, hasPrimayKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
rocksMayWrite(pTsdb, true, false);
|
rocksMayWrite(pTsdb, false);
|
||||||
|
|
||||||
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
|
|
||||||
|
@ -1083,11 +1057,11 @@ static int32_t tsdbCachePutToLRU(STsdb *pTsdb, SLastKey *pLastKey, SLastCol *pLa
|
||||||
TAOS_CHECK_EXIT(tsdbCacheReallocSLastCol(pLRULastCol, &charge));
|
TAOS_CHECK_EXIT(tsdbCacheReallocSLastCol(pLRULastCol, &charge));
|
||||||
|
|
||||||
LRUStatus status = taosLRUCacheInsert(pTsdb->lruCache, pLastKey, ROCKS_KEY_LEN, pLRULastCol, charge, tsdbCacheDeleter,
|
LRUStatus status = taosLRUCacheInsert(pTsdb->lruCache, pLastKey, ROCKS_KEY_LEN, pLRULastCol, charge, tsdbCacheDeleter,
|
||||||
NULL, TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState);
|
NULL, TAOS_LRU_PRIORITY_LOW, pTsdb);
|
||||||
if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) {
|
if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) {
|
||||||
tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
|
tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
|
||||||
tsdbCacheFreeSLastColItem(pLRULastCol);
|
|
||||||
code = TSDB_CODE_FAILED;
|
code = TSDB_CODE_FAILED;
|
||||||
|
pLRULastCol = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -1177,6 +1151,8 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray
|
||||||
keys_list_sizes[i] = ROCKS_KEY_LEN;
|
keys_list_sizes[i] = ROCKS_KEY_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rocksMayWrite(pTsdb, true); // flush writebatch cache
|
||||||
|
|
||||||
code = tsdbCacheGetValuesFromRocks(pTsdb, num_keys, (const char *const *)keys_list, keys_list_sizes, &values_list,
|
code = tsdbCacheGetValuesFromRocks(pTsdb, num_keys, (const char *const *)keys_list, keys_list_sizes, &values_list,
|
||||||
&values_list_sizes);
|
&values_list_sizes);
|
||||||
if (code) {
|
if (code) {
|
||||||
|
@ -1243,7 +1219,7 @@ static int32_t tsdbCacheUpdate(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, SArray
|
||||||
taosMemoryFreeClear(pToFree);
|
taosMemoryFreeClear(pToFree);
|
||||||
}
|
}
|
||||||
|
|
||||||
rocksMayWrite(pTsdb, true, false);
|
rocksMayWrite(pTsdb, false);
|
||||||
|
|
||||||
taosMemoryFree(keys_list);
|
taosMemoryFree(keys_list);
|
||||||
taosMemoryFree(keys_list_sizes);
|
taosMemoryFree(keys_list_sizes);
|
||||||
|
@ -1573,32 +1549,22 @@ static int32_t tsdbCacheLoadFromRaw(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArr
|
||||||
}
|
}
|
||||||
|
|
||||||
LRUStatus status = taosLRUCacheInsert(pCache, &idxKey->key, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, NULL,
|
LRUStatus status = taosLRUCacheInsert(pCache, &idxKey->key, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter, NULL,
|
||||||
TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState);
|
TAOS_LRU_PRIORITY_LOW, pTsdb);
|
||||||
if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) {
|
if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) {
|
||||||
tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
|
tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
|
||||||
tsdbCacheFreeSLastColItem(pLastCol);
|
pLastCol = NULL;
|
||||||
taosMemoryFree(pLastCol);
|
|
||||||
TAOS_CHECK_EXIT(TSDB_CODE_FAILED);
|
TAOS_CHECK_EXIT(TSDB_CODE_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// store result back to rocks cache
|
// store result back to rocks cache
|
||||||
wb = pTsdb->rCache.rwritebatch;
|
code = tsdbCachePutToRocksdb(pTsdb, &idxKey->key, pLastCol);
|
||||||
char *value = NULL;
|
|
||||||
size_t vlen = 0;
|
|
||||||
code = tsdbCacheSerialize(pLastCol, &value, &vlen);
|
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("tsdb/cache: vgId:%d, serialize failed since %s.", TD_VID(pTsdb->pVnode), tstrerror(code));
|
tsdbError("vgId:%d, %s failed at line %d since %s.", TD_VID(pTsdb->pVnode), __func__, __LINE__, tstrerror(code));
|
||||||
} else {
|
TAOS_CHECK_EXIT(code);
|
||||||
SLastKey *key = &idxKey->key;
|
|
||||||
size_t klen = ROCKS_KEY_LEN;
|
|
||||||
rocksdb_writebatch_put(wb, (char *)key, klen, value, vlen);
|
|
||||||
taosMemoryFree(value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wb) {
|
rocksMayWrite(pTsdb, false);
|
||||||
rocksMayWrite(pTsdb, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
taosArrayDestroy(lastrowTmpIndexArray);
|
taosArrayDestroy(lastrowTmpIndexArray);
|
||||||
|
@ -1638,6 +1604,8 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA
|
||||||
keys_list_sizes[i] = ROCKS_KEY_LEN;
|
keys_list_sizes[i] = ROCKS_KEY_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rocksMayWrite(pTsdb, true); // flush writebatch cache
|
||||||
|
|
||||||
code = tsdbCacheGetValuesFromRocks(pTsdb, num_keys, (const char *const *)keys_list, keys_list_sizes, &values_list,
|
code = tsdbCacheGetValuesFromRocks(pTsdb, num_keys, (const char *const *)keys_list, keys_list_sizes, &values_list,
|
||||||
&values_list_sizes);
|
&values_list_sizes);
|
||||||
if (code) {
|
if (code) {
|
||||||
|
@ -1686,11 +1654,9 @@ static int32_t tsdbCacheLoadFromRocks(STsdb *pTsdb, tb_uid_t uid, SArray *pLastA
|
||||||
}
|
}
|
||||||
|
|
||||||
LRUStatus status = taosLRUCacheInsert(pCache, &idxKey->key, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter,
|
LRUStatus status = taosLRUCacheInsert(pCache, &idxKey->key, ROCKS_KEY_LEN, pLastCol, charge, tsdbCacheDeleter,
|
||||||
NULL, TAOS_LRU_PRIORITY_LOW, &pTsdb->flushState);
|
NULL, TAOS_LRU_PRIORITY_LOW, pTsdb);
|
||||||
if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) {
|
if (TAOS_LRU_STATUS_OK != status && TAOS_LRU_STATUS_OK_OVERWRITTEN != status) {
|
||||||
tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
|
tsdbError("vgId:%d, %s failed at line %d status %d.", TD_VID(pTsdb->pVnode), __func__, __LINE__, status);
|
||||||
tsdbCacheFreeSLastColItem(pLastCol);
|
|
||||||
taosMemoryFreeClear(pLastCol);
|
|
||||||
taosMemoryFreeClear(pToFree);
|
taosMemoryFreeClear(pToFree);
|
||||||
TAOS_CHECK_EXIT(TSDB_CODE_FAILED);
|
TAOS_CHECK_EXIT(TSDB_CODE_FAILED);
|
||||||
}
|
}
|
||||||
|
@ -1797,6 +1763,7 @@ int32_t tsdbCacheGetBatch(STsdb *pTsdb, tb_uid_t uid, SArray *pLastArray, SCache
|
||||||
|
|
||||||
if (remainCols && TARRAY_SIZE(remainCols) > 0) {
|
if (remainCols && TARRAY_SIZE(remainCols) > 0) {
|
||||||
(void)taosThreadMutexLock(&pTsdb->lruMutex);
|
(void)taosThreadMutexLock(&pTsdb->lruMutex);
|
||||||
|
|
||||||
for (int i = 0; i < TARRAY_SIZE(remainCols);) {
|
for (int i = 0; i < TARRAY_SIZE(remainCols);) {
|
||||||
SIdxKey *idxKey = &((SIdxKey *)TARRAY_DATA(remainCols))[i];
|
SIdxKey *idxKey = &((SIdxKey *)TARRAY_DATA(remainCols))[i];
|
||||||
LRUHandle *h = taosLRUCacheLookup(pCache, &idxKey->key, ROCKS_KEY_LEN);
|
LRUHandle *h = taosLRUCacheLookup(pCache, &idxKey->key, ROCKS_KEY_LEN);
|
||||||
|
@ -1910,6 +1877,8 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE
|
||||||
keys_list_sizes[i] = klen;
|
keys_list_sizes[i] = klen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rocksMayWrite(pTsdb, true); // flush writebatch cache
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(tsdbCacheGetValuesFromRocks(pTsdb, numKeys, (const char *const *)keys_list, keys_list_sizes,
|
TAOS_CHECK_GOTO(tsdbCacheGetValuesFromRocks(pTsdb, numKeys, (const char *const *)keys_list, keys_list_sizes,
|
||||||
&values_list, &values_list_sizes),
|
&values_list, &values_list_sizes),
|
||||||
NULL, _exit);
|
NULL, _exit);
|
||||||
|
@ -1944,7 +1913,7 @@ int32_t tsdbCacheDel(STsdb *pTsdb, tb_uid_t suid, tb_uid_t uid, TSKEY sKey, TSKE
|
||||||
taosMemoryFreeClear(pLastCol);
|
taosMemoryFreeClear(pLastCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
rocksMayWrite(pTsdb, true, false);
|
rocksMayWrite(pTsdb, false);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
(void)taosThreadMutexUnlock(&pTsdb->lruMutex);
|
||||||
|
@ -1986,9 +1955,6 @@ int32_t tsdbOpenCache(STsdb *pTsdb) {
|
||||||
|
|
||||||
(void)taosThreadMutexInit(&pTsdb->lruMutex, NULL);
|
(void)taosThreadMutexInit(&pTsdb->lruMutex, NULL);
|
||||||
|
|
||||||
pTsdb->flushState.pTsdb = pTsdb;
|
|
||||||
pTsdb->flushState.flush_count = 0;
|
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
if (code) {
|
if (code) {
|
||||||
tsdbError("tsdb/cache: vgId:%d, open failed at line %d since %s.", TD_VID(pTsdb->pVnode), lino, tstrerror(code));
|
tsdbError("tsdb/cache: vgId:%d, open failed at line %d since %s.", TD_VID(pTsdb->pVnode), lino, tstrerror(code));
|
||||||
|
|
|
@ -473,7 +473,7 @@ int32_t tsdbRetrieveCacheRows(void* pReader, SSDataBlock* pResBlock, const int32
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosThreadMutexLock(&pr->readerMutex);
|
(void)taosThreadMutexLock(&pr->readerMutex);
|
||||||
code = tsdbTakeReadSnap2((STsdbReader*)pr, tsdbCacheQueryReseek, &pr->pReadSnap);
|
code = tsdbTakeReadSnap2((STsdbReader*)pr, tsdbCacheQueryReseek, &pr->pReadSnap, pr->idstr);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,12 +113,12 @@ static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) {
|
||||||
// save to file
|
// save to file
|
||||||
pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFD == NULL) {
|
if (pFD == NULL) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t n = taosWriteFile(pFD, pData, size);
|
int64_t n = taosWriteFile(pFD, pData, size);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFsyncFile(pFD) < 0) {
|
if (taosFsyncFile(pFD) < 0) {
|
||||||
|
@ -178,7 +178,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
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, NULL)) {
|
if (taosStatFile(fname, &size, NULL, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,7 +192,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, NULL)) {
|
if (taosStatFile(fname, &size, NULL, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
// if (size != tsdbLogicToFileSize(pSet->pHeadF->size, pTsdb->pVnode->config.tsdbPageSize)) {
|
// if (size != tsdbLogicToFileSize(pSet->pHeadF->size, pTsdb->pVnode->config.tsdbPageSize)) {
|
||||||
|
@ -203,7 +203,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, NULL)) {
|
if (taosStatFile(fname, &size, NULL, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
// if (size < tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) {
|
// if (size < tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) {
|
||||||
|
@ -218,7 +218,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, NULL)) {
|
if (taosStatFile(fname, &size, NULL, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
// if (size < tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) {
|
// if (size < tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) {
|
||||||
|
@ -234,7 +234,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) {
|
||||||
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, NULL)) {
|
if (taosStatFile(fname, &size, NULL, NULL)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
// if (size != tsdbLogicToFileSize(pSet->aSttF[iStt]->size, pTsdb->pVnode->config.tsdbPageSize)) {
|
// if (size != tsdbLogicToFileSize(pSet->aSttF[iStt]->size, pTsdb->pVnode->config.tsdbPageSize)) {
|
||||||
|
@ -293,13 +293,13 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) {
|
||||||
// load binary
|
// load binary
|
||||||
TdFilePtr pFD = taosOpenFile(fname, TD_FILE_READ);
|
TdFilePtr pFD = taosOpenFile(fname, TD_FILE_READ);
|
||||||
if (pFD == NULL) {
|
if (pFD == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size;
|
int64_t size;
|
||||||
if (taosFStatFile(pFD, &size, NULL) < 0) {
|
code = taosFStatFile(pFD, &size, NULL);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
(void)taosCloseFile(&pFD);
|
(void)taosCloseFile(&pFD);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFD, pData, size) < 0) {
|
if (taosReadFile(pFD, pData, size) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
(void)taosCloseFile(&pFD);
|
(void)taosCloseFile(&pFD);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
@ -713,10 +713,7 @@ static int32_t tsdbFSCommit(STsdb *pTsdb) {
|
||||||
if (!taosCheckExistFile(current_t)) goto _exit;
|
if (!taosCheckExistFile(current_t)) goto _exit;
|
||||||
|
|
||||||
// rename the file
|
// rename the file
|
||||||
if (taosRenameFile(current_t, current) < 0) {
|
TSDB_CHECK_CODE(taosRenameFile(current_t, current), lino, _exit);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load the new FS
|
// Load the new FS
|
||||||
code = tsdbFSCreate(&fs);
|
code = tsdbFSCreate(&fs);
|
||||||
|
|
|
@ -84,15 +84,15 @@ static int32_t save_json(const cJSON *json, const char *fname) {
|
||||||
|
|
||||||
fp = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
fp = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosWriteFile(fp, data, strlen(data)) < 0) {
|
if (taosWriteFile(fp, data, strlen(data)) < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFsyncFile(fp) < 0) {
|
if (taosFsyncFile(fp) < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -111,12 +111,13 @@ static int32_t load_json(const char *fname, cJSON **json) {
|
||||||
|
|
||||||
TdFilePtr fp = taosOpenFile(fname, TD_FILE_READ);
|
TdFilePtr fp = taosOpenFile(fname, TD_FILE_READ);
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size;
|
int64_t size;
|
||||||
if (taosFStatFile(fp, &size, NULL) < 0) {
|
code = taosFStatFile(fp, &size, NULL);
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
|
if (code != 0) {
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
data = taosMemoryMalloc(size + 1);
|
data = taosMemoryMalloc(size + 1);
|
||||||
|
@ -125,7 +126,7 @@ static int32_t load_json(const char *fname, cJSON **json) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(fp, data, size) < 0) {
|
if (taosReadFile(fp, data, size) < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
data[size] = '\0';
|
data[size] = '\0';
|
||||||
|
|
||||||
|
@ -304,10 +305,7 @@ static int32_t commit_edit(STFileSystem *fs) {
|
||||||
|
|
||||||
int32_t code;
|
int32_t code;
|
||||||
int32_t lino;
|
int32_t lino;
|
||||||
if ((code = taosRenameFile(current_t, current))) {
|
TSDB_CHECK_CODE(taosRenameFile(current_t, current), lino, _exit);
|
||||||
code = TAOS_SYSTEM_ERROR(code);
|
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
|
||||||
}
|
|
||||||
|
|
||||||
code = apply_commit(fs);
|
code = apply_commit(fs);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
|
@ -5016,7 +5016,7 @@ int32_t tsdbReaderResume2(STsdbReader* pReader) {
|
||||||
int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
|
int32_t numOfTables = tSimpleHashGetSize(pReader->status.pTableMap);
|
||||||
if (numOfTables > 0) {
|
if (numOfTables > 0) {
|
||||||
tsdbTrace("tsdb/reader: %p, take snapshot", pReader);
|
tsdbTrace("tsdb/reader: %p, take snapshot", pReader);
|
||||||
code = tsdbTakeReadSnap2(pReader, tsdbSetQueryReseek, &pReader->pReadSnap);
|
code = tsdbTakeReadSnap2(pReader, tsdbSetQueryReseek, &pReader->pReadSnap, pReader->idStr);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
@ -5862,7 +5862,7 @@ int32_t tsdbGetTableSchema(SMeta* pMeta, int64_t uid, STSchema** pSchema, int64_
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STsdbReadSnap** ppSnap) {
|
int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STsdbReadSnap** ppSnap, const char* id) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
STsdb* pTsdb = pReader->pTsdb;
|
STsdb* pTsdb = pReader->pTsdb;
|
||||||
SVersionRange* pRange = &pReader->info.verRange;
|
SVersionRange* pRange = &pReader->info.verRange;
|
||||||
|
@ -5872,7 +5872,7 @@ int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STs
|
||||||
// lock
|
// lock
|
||||||
code = taosThreadMutexLock(&pTsdb->mutex);
|
code = taosThreadMutexLock(&pTsdb->mutex);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
tsdbError("failed to lock tsdb, code:%s", tstrerror(code));
|
tsdbError("%s failed to lock tsdb, code:%s", id, tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5932,18 +5932,19 @@ int32_t tsdbTakeReadSnap2(STsdbReader* pReader, _query_reseek_func_t reseek, STs
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) taosThreadMutexUnlock(&pTsdb->mutex);
|
(void) taosThreadMutexUnlock(&pTsdb->mutex);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);}
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
}
|
||||||
|
|
||||||
// unlock
|
// unlock
|
||||||
(void) taosThreadMutexUnlock(&pTsdb->mutex);
|
(void) taosThreadMutexUnlock(&pTsdb->mutex);
|
||||||
*ppSnap = pSnap;
|
*ppSnap = pSnap;
|
||||||
|
|
||||||
tsdbTrace("vgId:%d, take read snapshot", TD_VID(pTsdb->pVnode));
|
tsdbTrace("%s vgId:%d, take read snapshot", id, TD_VID(pTsdb->pVnode));
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
tsdbError("%s vgId:%d take read snapshot failed, line:%d code:%s", pReader->idStr, TD_VID(pTsdb->pVnode), lino,
|
tsdbError("%s vgId:%d take read snapshot failed, line:%d code:%s", id, TD_VID(pTsdb->pVnode), lino, tstrerror(code));
|
||||||
tstrerror(code));
|
|
||||||
if (pSnap) {
|
if (pSnap) {
|
||||||
if (pSnap->pNode) taosMemoryFree(pSnap->pNode);
|
if (pSnap->pNode) taosMemoryFree(pSnap->pNode);
|
||||||
if (pSnap->pINode) taosMemoryFree(pSnap->pINode);
|
if (pSnap->pINode) taosMemoryFree(pSnap->pINode);
|
||||||
|
|
|
@ -46,14 +46,14 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) {
|
||||||
|
|
||||||
pFD->pFD = taosOpenFile(lc_path, flag);
|
pFD->pFD = taosOpenFile(lc_path, flag);
|
||||||
if (pFD->pFD == NULL) {
|
if (pFD->pFD == NULL) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
if (taosStatFile(lc_path, &lc_size, NULL, NULL) < 0) {
|
if (taosStatFile(lc_path, &lc_size, NULL, NULL) < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tsdbInfo("no file: %s", path);
|
tsdbInfo("no file: %s", path);
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
pFD->s3File = 1;
|
pFD->s3File = 1;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) {
|
||||||
// not check file size when reading data files.
|
// not check file size when reading data files.
|
||||||
if (flag != TD_FILE_READ /* && !pFD->s3File*/) {
|
if (flag != TD_FILE_READ /* && !pFD->s3File*/) {
|
||||||
if (!lc_size && taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) {
|
if (!lc_size && taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e
|
||||||
|
|
||||||
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
|
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage);
|
code = taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage);
|
||||||
|
@ -187,7 +187,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e
|
||||||
|
|
||||||
n = taosWriteFile(pFD->pFD, pFD->pBuf, pFD->szPage);
|
n = taosWriteFile(pFD->pFD, pFD->pBuf, pFD->szPage);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pFD->szFile < pFD->pgno) {
|
if (pFD->szFile < pFD->pgno) {
|
||||||
|
@ -224,13 +224,13 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgor
|
||||||
// seek
|
// seek
|
||||||
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
|
int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
// read
|
// read
|
||||||
n = taosReadFile(pFD->pFD, pFD->pBuf, pFD->szPage);
|
n = taosReadFile(pFD->pFD, pFD->pBuf, pFD->szPage);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
} else if (n < pFD->szPage) {
|
} else if (n < pFD->szPage) {
|
||||||
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
|
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
|
||||||
}
|
}
|
||||||
|
@ -377,12 +377,12 @@ static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, boo
|
||||||
// read last chunk
|
// read last chunk
|
||||||
int64_t ret = taosLSeekFile(pFD->pFD, chunksize * (chunkno - pFD->lcn) + cOffset, SEEK_SET);
|
int64_t ret = taosLSeekFile(pFD->pFD, chunksize * (chunkno - pFD->lcn) + cOffset, SEEK_SET);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = taosReadFile(pFD->pFD, buf + n, nRead);
|
ret = taosReadFile(pFD->pFD, buf + n, nRead);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
} else if (ret < nRead) {
|
} else if (ret < nRead) {
|
||||||
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
|
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ static int32_t tsdbCopyFileWithLimitedSpeed(TdFilePtr from, TdFilePtr to, int64_
|
||||||
int64_t n;
|
int64_t n;
|
||||||
int64_t last = taosGetTimestampMs();
|
int64_t last = taosGetTimestampMs();
|
||||||
if ((n = taosFSendFile(to, from, &offset, TMIN(limit, remain))) < 0) {
|
if ((n = taosFSendFile(to, from, &offset, TMIN(limit, remain))) < 0) {
|
||||||
TAOS_CHECK_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_CHECK_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
remain -= n;
|
remain -= n;
|
||||||
|
@ -76,14 +76,14 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi
|
||||||
|
|
||||||
fdFrom = taosOpenFile(fname_from, TD_FILE_READ);
|
fdFrom = taosOpenFile(fname_from, TD_FILE_READ);
|
||||||
if (fdFrom == NULL) {
|
if (fdFrom == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname_to, from->f->size);
|
tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname_to, from->f->size);
|
||||||
|
|
||||||
fdTo = taosOpenFile(fname_to, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
|
fdTo = taosOpenFile(fname_to, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
|
||||||
if (fdTo == NULL) {
|
if (fdTo == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
SVnodeCfg *pCfg = &rtner->tsdb->pVnode->config;
|
SVnodeCfg *pCfg = &rtner->tsdb->pVnode->config;
|
||||||
|
@ -91,7 +91,7 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi
|
||||||
int64_t lc_size = tsdbLogicToFileSize(to->size, rtner->szPage) - chunksize * (to->lcn - 1);
|
int64_t lc_size = tsdbLogicToFileSize(to->size, rtner->szPage) - chunksize * (to->lcn - 1);
|
||||||
|
|
||||||
if (taosFSendFile(fdTo, fdFrom, 0, lc_size) < 0) {
|
if (taosFSendFile(fdTo, fdFrom, 0, lc_size) < 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -116,14 +116,14 @@ static int32_t tsdbDoCopyFile(SRTNer *rtner, const STFileObj *from, const STFile
|
||||||
|
|
||||||
fdFrom = taosOpenFile(from->fname, TD_FILE_READ);
|
fdFrom = taosOpenFile(from->fname, TD_FILE_READ);
|
||||||
if (fdFrom == NULL) {
|
if (fdFrom == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, from->f->size);
|
tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, from->f->size);
|
||||||
|
|
||||||
fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
|
fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
|
||||||
if (fdTo == NULL) {
|
if (fdTo == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
|
@ -430,7 +430,7 @@ static int32_t tsdbCopyFileS3(SRTNer *rtner, const STFileObj *from, const STFile
|
||||||
|
|
||||||
fdFrom = taosOpenFile(from->fname, TD_FILE_READ);
|
fdFrom = taosOpenFile(from->fname, TD_FILE_READ);
|
||||||
if (fdFrom == NULL) {
|
if (fdFrom == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *object_name = taosDirEntryBaseName(fname);
|
char *object_name = taosDirEntryBaseName(fname);
|
||||||
|
@ -520,7 +520,7 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int
|
||||||
|
|
||||||
fdFrom = taosOpenFile(fname, TD_FILE_READ);
|
fdFrom = taosOpenFile(fname, TD_FILE_READ);
|
||||||
if (fdFrom == NULL) {
|
if (fdFrom == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbInfo("vgId:%d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, lc_size);
|
tsdbInfo("vgId:%d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, lc_size);
|
||||||
|
@ -528,12 +528,12 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int
|
||||||
snprintf(dot2 + 1, TSDB_FQDN_LEN - (dot2 + 1 - object_name), "%d.data", lcn);
|
snprintf(dot2 + 1, TSDB_FQDN_LEN - (dot2 + 1 - object_name), "%d.data", lcn);
|
||||||
fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
|
fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
|
||||||
if (fdTo == NULL) {
|
if (fdTo == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size);
|
int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -619,19 +619,19 @@ static int32_t tsdbMigrateDataFileS3(SRTNer *rtner, const STFileObj *fobj, int64
|
||||||
|
|
||||||
fdFrom = taosOpenFile(fobj->fname, TD_FILE_READ);
|
fdFrom = taosOpenFile(fobj->fname, TD_FILE_READ);
|
||||||
if (fdFrom == NULL) {
|
if (fdFrom == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
tsdbInfo("vgId: %d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, fobj->f->size);
|
tsdbInfo("vgId: %d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, fobj->f->size);
|
||||||
|
|
||||||
fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
|
fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
|
||||||
if (fdTo == NULL) {
|
if (fdTo == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size);
|
int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
|
|
@ -181,15 +181,15 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) {
|
||||||
// save info to a vnode_tmp.json
|
// save info to a vnode_tmp.json
|
||||||
pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosWriteFile(pFile, data, strlen(data)) < 0) {
|
if (taosWriteFile(pFile, data, strlen(data)) < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFsyncFile(pFile) < 0) {
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
@ -211,8 +211,9 @@ int vnodeCommitInfo(const char *dir) {
|
||||||
snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME);
|
snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME);
|
||||||
snprintf(tfname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME_TMP);
|
snprintf(tfname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME_TMP);
|
||||||
|
|
||||||
if (taosRenameFile(tfname, fname) < 0) {
|
int32_t code = taosRenameFile(tfname, fname);
|
||||||
return terrno = TAOS_SYSTEM_ERROR(errno);
|
if (code < 0) {
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
vInfo("vnode info is committed, dir:%s", dir);
|
vInfo("vnode info is committed, dir:%s", dir);
|
||||||
|
@ -232,12 +233,11 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) {
|
||||||
// read info
|
// read info
|
||||||
pFile = taosOpenFile(fname, TD_FILE_READ);
|
pFile = taosOpenFile(fname, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
|
||||||
|
|
||||||
pData = taosMemoryMalloc(size + 1);
|
pData = taosMemoryMalloc(size + 1);
|
||||||
if (pData == NULL) {
|
if (pData == NULL) {
|
||||||
|
@ -245,7 +245,7 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, pData, size) < 0) {
|
if (taosReadFile(pFile, pData, size) < 0) {
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
pData[size] = '\0';
|
pData[size] = '\0';
|
||||||
|
|
|
@ -267,14 +267,15 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(fName, TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile(fName, TD_FILE_READ);
|
||||||
if (NULL == pFile) {
|
if (NULL == pFile) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size;
|
int64_t size;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
|
if (code != 0) {
|
||||||
(void)taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
*ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + size + 1);
|
*ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + size + 1);
|
||||||
|
@ -289,7 +290,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
|
||||||
if (taosReadFile(pFile, ((SSnapDataHdr *)(*ppData))->data, size) < 0) {
|
if (taosReadFile(pFile, ((SSnapDataHdr *)(*ppData))->data, size) < 0) {
|
||||||
taosMemoryFree(*ppData);
|
taosMemoryFree(*ppData);
|
||||||
(void)taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
|
TSDB_CHECK_CODE(code = terrno, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
|
|
|
@ -344,27 +344,18 @@ static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) {
|
||||||
return TSDB_CACHE_MODEL_NONE_STR;
|
return TSDB_CACHE_MODEL_NONE_STR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t formatDurationOrKeep(char** buffer, int32_t timeInMinutes) {
|
int32_t formatDurationOrKeep(char* buffer, int32_t timeInMinutes) {
|
||||||
int len = 0;
|
int32_t len = 0;
|
||||||
if (timeInMinutes % 1440 == 0) {
|
if (timeInMinutes % 1440 == 0) {
|
||||||
int days = timeInMinutes / 1440;
|
int32_t days = timeInMinutes / 1440;
|
||||||
len = snprintf(NULL, 0, "%dd", days);
|
len = sprintf(buffer, "%dd", days);
|
||||||
*buffer = (char*)taosMemoryCalloc(len + 1, sizeof(char));
|
|
||||||
if(*buffer == NULL) return terrno;
|
|
||||||
sprintf(*buffer, "%dd", days);
|
|
||||||
} else if (timeInMinutes % 60 == 0) {
|
} else if (timeInMinutes % 60 == 0) {
|
||||||
int hours = timeInMinutes / 60;
|
int32_t hours = timeInMinutes / 60;
|
||||||
len = snprintf(NULL, 0, "%dh", hours);
|
len = sprintf(buffer, "%dh", hours);
|
||||||
*buffer = (char*)taosMemoryCalloc(len + 1, sizeof(char));
|
|
||||||
if(*buffer == NULL) return terrno;
|
|
||||||
sprintf(*buffer, "%dh", hours);
|
|
||||||
} else {
|
} else {
|
||||||
len = snprintf(NULL, 0, "%dm", timeInMinutes);
|
len = sprintf(buffer, "%dm", timeInMinutes);
|
||||||
*buffer = (char*)taosMemoryCalloc(len + 1, sizeof(char));
|
|
||||||
if(*buffer == NULL) return terrno;
|
|
||||||
sprintf(*buffer, "%dm", timeInMinutes);
|
|
||||||
}
|
}
|
||||||
return TSDB_CODE_SUCCESS;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) {
|
static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) {
|
||||||
|
@ -404,25 +395,16 @@ static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName,
|
||||||
} else if (pCfg->hashPrefix < 0) {
|
} else if (pCfg->hashPrefix < 0) {
|
||||||
hashPrefix = pCfg->hashPrefix + dbFNameLen + 1;
|
hashPrefix = pCfg->hashPrefix + dbFNameLen + 1;
|
||||||
}
|
}
|
||||||
char* durationStr = NULL;
|
char durationStr[128] = {0};
|
||||||
char* keep0Str = NULL;
|
char keep0Str[128] = {0};
|
||||||
char* keep1Str = NULL;
|
char keep1Str[128] = {0};
|
||||||
char* keep2Str = NULL;
|
char keep2Str[128] = {0};
|
||||||
int32_t codeDuration = formatDurationOrKeep(&durationStr, pCfg->daysPerFile);
|
|
||||||
int32_t codeKeep0 = formatDurationOrKeep(&keep0Str, pCfg->daysToKeep0);
|
int32_t lenDuration = formatDurationOrKeep(durationStr, pCfg->daysPerFile);
|
||||||
int32_t codeKeep1 = formatDurationOrKeep(&keep1Str, pCfg->daysToKeep1);
|
int32_t lenKeep0 = formatDurationOrKeep(keep0Str, pCfg->daysToKeep0);
|
||||||
int32_t codeKeep2 = formatDurationOrKeep(&keep2Str, pCfg->daysToKeep2);
|
int32_t lenKeep1 = formatDurationOrKeep(keep1Str, pCfg->daysToKeep1);
|
||||||
if(codeDuration != TSDB_CODE_SUCCESS || codeKeep0 != TSDB_CODE_SUCCESS || codeKeep1 != TSDB_CODE_SUCCESS || codeKeep2 != TSDB_CODE_SUCCESS) {
|
int32_t lenKeep2 = formatDurationOrKeep(keep2Str, pCfg->daysToKeep2);
|
||||||
int32_t firstErrorCode = codeDuration != TSDB_CODE_SUCCESS ? codeDuration :
|
|
||||||
codeKeep0 != TSDB_CODE_SUCCESS ? codeKeep0 :
|
|
||||||
codeKeep1 != TSDB_CODE_SUCCESS ? codeKeep1 : codeKeep2;
|
|
||||||
taosMemoryFree(pRetentions);
|
|
||||||
taosMemoryFree(durationStr);
|
|
||||||
taosMemoryFree(keep0Str);
|
|
||||||
taosMemoryFree(keep1Str);
|
|
||||||
taosMemoryFree(keep2Str);
|
|
||||||
return firstErrorCode;
|
|
||||||
}
|
|
||||||
if (IS_SYS_DBNAME(dbName)) {
|
if (IS_SYS_DBNAME(dbName)) {
|
||||||
len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE DATABASE `%s`", dbName);
|
len += sprintf(buf2 + VARSTR_HEADER_SIZE, "CREATE DATABASE `%s`", dbName);
|
||||||
} else {
|
} else {
|
||||||
|
@ -449,10 +431,6 @@ static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName,
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(pRetentions);
|
taosMemoryFree(pRetentions);
|
||||||
taosMemoryFree(durationStr);
|
|
||||||
taosMemoryFree(keep0Str);
|
|
||||||
taosMemoryFree(keep1Str);
|
|
||||||
taosMemoryFree(keep2Str);
|
|
||||||
|
|
||||||
(varDataLen(buf2)) = len;
|
(varDataLen(buf2)) = len;
|
||||||
|
|
||||||
|
|
|
@ -1012,6 +1012,10 @@ static void destroySqlFunctionCtx(SqlFunctionCtx* pCtx, SExprInfo* pExpr, int32_
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||||
|
if (pCtx[i].fpSet.cleanup != NULL) {
|
||||||
|
pCtx[i].fpSet.cleanup(&pCtx[i]);
|
||||||
|
}
|
||||||
|
|
||||||
if (pExpr != NULL) {
|
if (pExpr != NULL) {
|
||||||
SExprInfo* pExprInfo = &pExpr[i];
|
SExprInfo* pExprInfo = &pExpr[i];
|
||||||
for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
|
for (int32_t j = 0; j < pExprInfo->base.numOfParams; ++j) {
|
||||||
|
|
|
@ -204,7 +204,7 @@ static FORCE_INLINE int32_t initOpenCacheFile(SGroupCacheFileFd* pFileFd, char*
|
||||||
TdFilePtr newFd = taosOpenFile(filename, TD_FILE_CREATE|TD_FILE_READ|TD_FILE_WRITE|TD_FILE_AUTO_DEL);
|
TdFilePtr newFd = taosOpenFile(filename, TD_FILE_CREATE|TD_FILE_READ|TD_FILE_WRITE|TD_FILE_AUTO_DEL);
|
||||||
//TdFilePtr newFd = taosOpenFile(filename, TD_FILE_CREATE|TD_FILE_READ|TD_FILE_WRITE);
|
//TdFilePtr newFd = taosOpenFile(filename, TD_FILE_CREATE|TD_FILE_READ|TD_FILE_WRITE);
|
||||||
if (NULL == newFd) {
|
if (NULL == newFd) {
|
||||||
QRY_ERR_RET(TAOS_SYSTEM_ERROR(errno));
|
QRY_ERR_RET(terrno);
|
||||||
}
|
}
|
||||||
pFileFd->fd = newFd;
|
pFileFd->fd = newFd;
|
||||||
int32_t code = taosThreadMutexInit(&pFileFd->mutex, NULL);
|
int32_t code = taosThreadMutexInit(&pFileFd->mutex, NULL);
|
||||||
|
@ -315,16 +315,16 @@ static int32_t saveBlocksToDisk(SGroupCacheOperatorInfo* pGCache, SGcDownstreamC
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ret = taosLSeekFile(pFd->fd, pHead->basic.offset, SEEK_SET);
|
int32_t ret = taosLSeekFile(pFd->fd, pHead->basic.offset, SEEK_SET);
|
||||||
if (ret == -1) {
|
if (ret < 0) {
|
||||||
releaseFdToFileCtx(pFd);
|
releaseFdToFileCtx(pFd);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = (int32_t)taosWriteFile(pFd->fd, pHead->pBuf, pHead->basic.bufSize);
|
ret = (int32_t)taosWriteFile(pFd->fd, pHead->pBuf, pHead->basic.bufSize);
|
||||||
if (ret != pHead->basic.bufSize) {
|
if (ret != pHead->basic.bufSize) {
|
||||||
releaseFdToFileCtx(pFd);
|
releaseFdToFileCtx(pFd);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,8 +548,8 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ret = taosLSeekFile(pFileFd->fd, pBasic->offset, SEEK_SET);
|
int32_t ret = taosLSeekFile(pFileFd->fd, pBasic->offset, SEEK_SET);
|
||||||
if (ret == -1) {
|
if (ret < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,7 +562,7 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa
|
||||||
ret = (int32_t)taosReadFile(pFileFd->fd, *ppBuf, pBasic->bufSize);
|
ret = (int32_t)taosReadFile(pFileFd->fd, *ppBuf, pBasic->bufSize);
|
||||||
if (ret != pBasic->bufSize) {
|
if (ret != pBasic->bufSize) {
|
||||||
taosMemoryFreeClear(*ppBuf);
|
taosMemoryFreeClear(*ppBuf);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -659,10 +659,6 @@ void destroyOperator(SOperatorInfo* pOperator) {
|
||||||
freeResetOperatorParams(pOperator, OP_GET_PARAM, true);
|
freeResetOperatorParams(pOperator, OP_GET_PARAM, true);
|
||||||
freeResetOperatorParams(pOperator, OP_NOTIFY_PARAM, true);
|
freeResetOperatorParams(pOperator, OP_NOTIFY_PARAM, true);
|
||||||
|
|
||||||
if (pOperator->fpSet.closeFn != NULL && pOperator->info != NULL) {
|
|
||||||
pOperator->fpSet.closeFn(pOperator->info);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pOperator->pDownstream != NULL) {
|
if (pOperator->pDownstream != NULL) {
|
||||||
for (int32_t i = 0; i < pOperator->numOfRealDownstream; ++i) {
|
for (int32_t i = 0; i < pOperator->numOfRealDownstream; ++i) {
|
||||||
destroyOperator(pOperator->pDownstream[i]);
|
destroyOperator(pOperator->pDownstream[i]);
|
||||||
|
@ -673,6 +669,12 @@ void destroyOperator(SOperatorInfo* pOperator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanupExprSupp(&pOperator->exprSupp);
|
cleanupExprSupp(&pOperator->exprSupp);
|
||||||
|
|
||||||
|
// close operator after cleanup exprSupp, since we need to call cleanup of sqlFunctionCtx first to avoid mem leak.
|
||||||
|
if (pOperator->fpSet.closeFn != NULL && pOperator->info != NULL) {
|
||||||
|
pOperator->fpSet.closeFn(pOperator->info);
|
||||||
|
}
|
||||||
|
|
||||||
taosMemoryFreeClear(pOperator);
|
taosMemoryFreeClear(pOperator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ static int32_t overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBloc
|
||||||
|
|
||||||
if (order == TSDB_ORDER_ASC) {
|
if (order == TSDB_ORDER_ASC) {
|
||||||
w = getAlignQueryTimeWindow(pInterval, pBlockInfo->window.skey);
|
w = getAlignQueryTimeWindow(pInterval, pBlockInfo->window.skey);
|
||||||
if(w.ekey < pBlockInfo->window.skey) {
|
if (w.ekey < pBlockInfo->window.skey) {
|
||||||
qError("w.ekey:%" PRId64 " < pBlockInfo->window.skey:%" PRId64, w.ekey, pBlockInfo->window.skey);
|
qError("w.ekey:%" PRId64 " < pBlockInfo->window.skey:%" PRId64, w.ekey, pBlockInfo->window.skey);
|
||||||
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -117,7 +117,7 @@ static int32_t overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBloc
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(w.ekey <= pBlockInfo->window.ekey) {
|
if (w.ekey <= pBlockInfo->window.ekey) {
|
||||||
qError("w.ekey:%" PRId64 " <= pBlockInfo->window.ekey:%" PRId64, w.ekey, pBlockInfo->window.ekey);
|
qError("w.ekey:%" PRId64 " <= pBlockInfo->window.ekey:%" PRId64, w.ekey, pBlockInfo->window.ekey);
|
||||||
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ static int32_t overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBloc
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
w = getAlignQueryTimeWindow(pInterval, pBlockInfo->window.ekey);
|
w = getAlignQueryTimeWindow(pInterval, pBlockInfo->window.ekey);
|
||||||
if(w.skey > pBlockInfo->window.ekey) {
|
if (w.skey > pBlockInfo->window.ekey) {
|
||||||
qError("w.skey:%" PRId64 " > pBlockInfo->window.skey:%" PRId64, w.skey, pBlockInfo->window.ekey);
|
qError("w.skey:%" PRId64 " > pBlockInfo->window.skey:%" PRId64, w.skey, pBlockInfo->window.ekey);
|
||||||
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ static int32_t overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBloc
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(w.skey >= pBlockInfo->window.skey){
|
if (w.skey >= pBlockInfo->window.skey) {
|
||||||
qError("w.skey:%" PRId64 " >= pBlockInfo->window.skey:%" PRId64, w.skey, pBlockInfo->window.skey);
|
qError("w.skey:%" PRId64 " >= pBlockInfo->window.skey:%" PRId64, w.skey, pBlockInfo->window.skey);
|
||||||
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -399,7 +399,7 @@ static int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanBase* pTableSca
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(*status != FUNC_DATA_REQUIRED_DATA_LOAD) {
|
if (*status != FUNC_DATA_REQUIRED_DATA_LOAD) {
|
||||||
pAPI->tsdReader.tsdReaderReleaseDataBlock(pTableScanInfo->dataReader);
|
pAPI->tsdReader.tsdReaderReleaseDataBlock(pTableScanInfo->dataReader);
|
||||||
qError("%s loadDataBlock invalid status:%d", GET_TASKID(pTaskInfo), *status);
|
qError("%s loadDataBlock invalid status:%d", GET_TASKID(pTaskInfo), *status);
|
||||||
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
||||||
|
@ -625,8 +625,7 @@ int32_t addTagPseudoColumnData(SReadHandle* pHandle, const SExprInfo* pExpr, int
|
||||||
// append null value before return to caller, since the caller will ignore this error code and proceed
|
// append null value before return to caller, since the caller will ignore this error code and proceed
|
||||||
doSetNullValue(pBlock, pExpr, numOfExpr);
|
doSetNullValue(pBlock, pExpr, numOfExpr);
|
||||||
} else {
|
} else {
|
||||||
qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", pBlock->info.id.uid, tstrerror(code),
|
qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", pBlock->info.id.uid, tstrerror(code), idStr);
|
||||||
idStr);
|
|
||||||
}
|
}
|
||||||
pHandle->api.metaReaderFn.clearReader(&mr);
|
pHandle->api.metaReaderFn.clearReader(&mr);
|
||||||
return code;
|
return code;
|
||||||
|
@ -1241,6 +1240,29 @@ _end:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t doInitReader(STableScanInfo* pInfo, SExecTaskInfo* pTaskInfo, SStorageAPI* pAPI, int32_t* pNum,
|
||||||
|
STableKeyInfo** pList) {
|
||||||
|
const char* idStr = GET_TASKID(pTaskInfo);
|
||||||
|
int32_t code = initNextGroupScan(pInfo, pList, pNum);
|
||||||
|
if (code) {
|
||||||
|
qError("%s failed to init groupScan Info, code:%s at line:%d", idStr, tstrerror(code), __LINE__);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pInfo->base.dataReader != NULL) {
|
||||||
|
qError("%s tsdb reader should be null", idStr);
|
||||||
|
return TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = pAPI->tsdReader.tsdReaderOpen(pInfo->base.readHandle.vnode, &pInfo->base.cond, *pList, *pNum, pInfo->pResBlock,
|
||||||
|
(void**)&pInfo->base.dataReader, idStr, &pInfo->pIgnoreTables);
|
||||||
|
if (code) {
|
||||||
|
qError("%s failed to open tsdbReader, code:%s at line:%d", idStr, tstrerror(code), __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlock) {
|
static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlock) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
@ -1250,6 +1272,7 @@ static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlo
|
||||||
int32_t num = 0;
|
int32_t num = 0;
|
||||||
STableKeyInfo* pList = NULL;
|
STableKeyInfo* pList = NULL;
|
||||||
SSDataBlock* pResult = NULL;
|
SSDataBlock* pResult = NULL;
|
||||||
|
const char* idStr = GET_TASKID(pTaskInfo);
|
||||||
|
|
||||||
QRY_PARAM_CHECK(pResBlock);
|
QRY_PARAM_CHECK(pResBlock);
|
||||||
|
|
||||||
|
@ -1260,17 +1283,10 @@ static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlo
|
||||||
}
|
}
|
||||||
|
|
||||||
taosRLockLatch(&pTaskInfo->lock);
|
taosRLockLatch(&pTaskInfo->lock);
|
||||||
code = initNextGroupScan(pInfo, &pList, &num);
|
code = doInitReader(pInfo, pTaskInfo, pAPI, &num, &pList);
|
||||||
|
|
||||||
taosRUnLockLatch(&pTaskInfo->lock);
|
taosRUnLockLatch(&pTaskInfo->lock);
|
||||||
QUERY_CHECK_CODE(code, lino, _end);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
QUERY_CHECK_CONDITION((pInfo->base.dataReader == NULL), code, lino, _end, TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
|
|
||||||
|
|
||||||
code = pAPI->tsdReader.tsdReaderOpen(pInfo->base.readHandle.vnode, &pInfo->base.cond, pList, num, pInfo->pResBlock,
|
|
||||||
(void**)&pInfo->base.dataReader, GET_TASKID(pTaskInfo), &pInfo->pIgnoreTables);
|
|
||||||
QUERY_CHECK_CODE(code, lino, _end);
|
|
||||||
|
|
||||||
if (pInfo->filesetDelimited) {
|
if (pInfo->filesetDelimited) {
|
||||||
pAPI->tsdReader.tsdSetFilesetDelimited(pInfo->base.dataReader);
|
pAPI->tsdReader.tsdSetFilesetDelimited(pInfo->base.dataReader);
|
||||||
}
|
}
|
||||||
|
@ -1280,7 +1296,6 @@ static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pResult = NULL;
|
|
||||||
code = doGroupedTableScan(pOperator, &pResult);
|
code = doGroupedTableScan(pOperator, &pResult);
|
||||||
QUERY_CHECK_CODE(code, lino, _end);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
|
||||||
|
@ -1305,7 +1320,7 @@ static int32_t groupSeqTableScan(SOperatorInfo* pOperator, SSDataBlock** pResBlo
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
|
qError("%s %s failed at line %d since %s", idStr, __func__, lino, tstrerror(code));
|
||||||
pTaskInfo->code = code;
|
pTaskInfo->code = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2804,8 +2819,8 @@ static int32_t setBlockIntoRes(SStreamScanInfo* pInfo, const SSDataBlock* pBlock
|
||||||
|
|
||||||
// currently only the tbname pseudo column
|
// currently only the tbname pseudo column
|
||||||
if (pInfo->numOfPseudoExpr > 0) {
|
if (pInfo->numOfPseudoExpr > 0) {
|
||||||
code = addTagPseudoColumnData(&pInfo->readHandle, pInfo->pPseudoExpr, pInfo->numOfPseudoExpr,
|
code = addTagPseudoColumnData(&pInfo->readHandle, pInfo->pPseudoExpr, pInfo->numOfPseudoExpr, pInfo->pRes,
|
||||||
pInfo->pRes, pBlockInfo->rows, pTaskInfo, &pTableScanInfo->base.metaCache);
|
pBlockInfo->rows, pTaskInfo, &pTableScanInfo->base.metaCache);
|
||||||
// ignore the table not exists error, since this table may have been dropped during the scan procedure.
|
// ignore the table not exists error, since this table may have been dropped during the scan procedure.
|
||||||
if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
|
if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST) {
|
||||||
code = 0;
|
code = 0;
|
||||||
|
@ -3471,7 +3486,8 @@ FETCH_NEXT_BLOCK:
|
||||||
(*ppRes) = pInfo->pDeleteDataRes;
|
(*ppRes) = pInfo->pDeleteDataRes;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
qError("%s===stream=== %s failed at line %d since pInfo->pUpdateRes is empty", GET_TASKID(pTaskInfo), __func__, lino);
|
qError("%s===stream=== %s failed at line %d since pInfo->pUpdateRes is empty", GET_TASKID(pTaskInfo), __func__,
|
||||||
|
lino);
|
||||||
blockDataCleanup(pInfo->pUpdateDataRes);
|
blockDataCleanup(pInfo->pUpdateDataRes);
|
||||||
pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE;
|
pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE;
|
||||||
} break;
|
} break;
|
||||||
|
@ -3484,7 +3500,8 @@ FETCH_NEXT_BLOCK:
|
||||||
(*ppRes) = pInfo->pUpdateRes;
|
(*ppRes) = pInfo->pUpdateRes;
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
qError("%s===stream=== %s failed at line %d since pInfo->pUpdateRes is empty", GET_TASKID(pTaskInfo), __func__, lino);
|
qError("%s===stream=== %s failed at line %d since pInfo->pUpdateRes is empty", GET_TASKID(pTaskInfo), __func__,
|
||||||
|
lino);
|
||||||
blockDataCleanup(pInfo->pUpdateDataRes);
|
blockDataCleanup(pInfo->pUpdateDataRes);
|
||||||
pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE;
|
pInfo->scanMode = STREAM_SCAN_FROM_READERHANDLE;
|
||||||
} break;
|
} break;
|
||||||
|
@ -4280,7 +4297,6 @@ static int32_t doTagScanOneTable(SOperatorInfo* pOperator, const SSDataBlock* pR
|
||||||
qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", item->uid, tstrerror(terrno),
|
qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", item->uid, tstrerror(terrno),
|
||||||
GET_TASKID(pTaskInfo));
|
GET_TASKID(pTaskInfo));
|
||||||
tDecoderClear(&(*mr).coder);
|
tDecoderClear(&(*mr).coder);
|
||||||
pAPI->metaReaderFn.clearReader(mr);
|
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4289,7 +4305,6 @@ static int32_t doTagScanOneTable(SOperatorInfo* pOperator, const SSDataBlock* pR
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", item->uid, tstrerror(terrno),
|
qError("failed to get table meta, uid:0x%" PRIx64 ", code:%s, %s", item->uid, tstrerror(terrno),
|
||||||
GET_TASKID(pTaskInfo));
|
GET_TASKID(pTaskInfo));
|
||||||
pAPI->metaReaderFn.clearReader(mr);
|
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4697,6 +4712,12 @@ static int32_t doTagScanFromMetaEntryNext(SOperatorInfo* pOperator, SSDataBlock*
|
||||||
|
|
||||||
while (pInfo->curPos < size && count < pOperator->resultInfo.capacity) {
|
while (pInfo->curPos < size && count < pOperator->resultInfo.capacity) {
|
||||||
code = doTagScanOneTable(pOperator, pRes, count, &mr, &pTaskInfo->storageAPI);
|
code = doTagScanOneTable(pOperator, pRes, count, &mr, &pTaskInfo->storageAPI);
|
||||||
|
if (code == TSDB_CODE_OUT_OF_MEMORY) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
// ignore other error
|
||||||
|
}
|
||||||
|
|
||||||
++count;
|
++count;
|
||||||
if (++pInfo->curPos >= size) {
|
if (++pInfo->curPos >= size) {
|
||||||
setOperatorCompleted(pOperator);
|
setOperatorCompleted(pOperator);
|
||||||
|
@ -4814,7 +4835,7 @@ int32_t createTagScanOperatorInfo(SReadHandle* pReadHandle, STagScanPhysiNode* p
|
||||||
nodesRewriteExprPostOrder(&pTagCond, tagScanRewriteTagColumn, (void*)&pInfo->filterCtx);
|
nodesRewriteExprPostOrder(&pTagCond, tagScanRewriteTagColumn, (void*)&pInfo->filterCtx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//TODO wjm check pInfo->filterCtx.code
|
// TODO wjm check pInfo->filterCtx.code
|
||||||
__optr_fn_t tagScanNextFn = (pTagScanNode->onlyMetaCtbIdx) ? doTagScanFromCtbIdxNext : doTagScanFromMetaEntryNext;
|
__optr_fn_t tagScanNextFn = (pTagScanNode->onlyMetaCtbIdx) ? doTagScanFromCtbIdxNext : doTagScanFromMetaEntryNext;
|
||||||
pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, tagScanNextFn, NULL, destroyTagScanOperatorInfo,
|
pOperator->fpSet = createOperatorFpSet(optrDummyOpenFn, tagScanNextFn, NULL, destroyTagScanOperatorInfo,
|
||||||
optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
|
optrDefaultBufFn, NULL, optrDefaultGetNextExtFn, NULL);
|
||||||
|
@ -5065,8 +5086,7 @@ static int32_t initSubTablesMergeInfo(STableMergeScanInfo* pInfo) {
|
||||||
}
|
}
|
||||||
int32_t bufPageSize = pInfo->bufPageSize;
|
int32_t bufPageSize = pInfo->bufPageSize;
|
||||||
int32_t inMemSize = (pSubTblsInfo->numSubTables - pSubTblsInfo->numTableBlocksInMem) * bufPageSize;
|
int32_t inMemSize = (pSubTblsInfo->numSubTables - pSubTblsInfo->numTableBlocksInMem) * bufPageSize;
|
||||||
code =
|
code = createDiskbasedBuf(&pSubTblsInfo->pBlocksBuf, pInfo->bufPageSize, inMemSize, "blocksExternalBuf", tsTempDir);
|
||||||
createDiskbasedBuf(&pSubTblsInfo->pBlocksBuf, pInfo->bufPageSize, inMemSize, "blocksExternalBuf", tsTempDir);
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
taosMemoryFree(pSubTblsInfo->aInputs);
|
taosMemoryFree(pSubTblsInfo->aInputs);
|
||||||
taosMemoryFree(pSubTblsInfo);
|
taosMemoryFree(pSubTblsInfo);
|
||||||
|
@ -5223,7 +5243,8 @@ _end:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t getSubTablesSortedBlock(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t capacity, SSDataBlock** pResBlock) {
|
static int32_t getSubTablesSortedBlock(SOperatorInfo* pOperator, SSDataBlock* pBlock, int32_t capacity,
|
||||||
|
SSDataBlock** pResBlock) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
STableMergeScanInfo* pInfo = pOperator->info;
|
STableMergeScanInfo* pInfo = pOperator->info;
|
||||||
|
|
|
@ -894,13 +894,7 @@ int64_t* extractTsCol(SSDataBlock* pBlock, const SIntervalAggOperatorInfo* pInfo
|
||||||
|
|
||||||
tsCols = (int64_t*)pColDataInfo->pData;
|
tsCols = (int64_t*)pColDataInfo->pData;
|
||||||
if(tsCols[0] == 0) {
|
if(tsCols[0] == 0) {
|
||||||
pTaskInfo->code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
|
qWarn("%s at line %d.block start ts:%" PRId64 ",end ts:%" PRId64, __func__, __LINE__, tsCols[0], tsCols[pBlock->info.rows - 1]);
|
||||||
T_LONG_JMP(pTaskInfo->env, terrno);
|
|
||||||
}
|
|
||||||
|
|
||||||
// no data in primary ts
|
|
||||||
if (tsCols[0] == 0 && tsCols[pBlock->info.rows - 1] == 0) {
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsCols[0] != 0 && (pBlock->info.window.skey == 0 && pBlock->info.window.ekey == 0)) {
|
if (tsCols[0] != 0 && (pBlock->info.window.skey == 0 && pBlock->info.window.ekey == 0)) {
|
||||||
|
|
|
@ -152,6 +152,7 @@ int32_t getIrateInfoSize(int32_t pkBytes);
|
||||||
int32_t cachedLastRowFunction(SqlFunctionCtx* pCtx);
|
int32_t cachedLastRowFunction(SqlFunctionCtx* pCtx);
|
||||||
|
|
||||||
bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
bool getFirstLastFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||||
|
int32_t firstLastFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo);
|
||||||
int32_t firstFunction(SqlFunctionCtx* pCtx);
|
int32_t firstFunction(SqlFunctionCtx* pCtx);
|
||||||
int32_t firstFunctionMerge(SqlFunctionCtx* pCtx);
|
int32_t firstFunctionMerge(SqlFunctionCtx* pCtx);
|
||||||
int32_t lastFunction(SqlFunctionCtx* pCtx);
|
int32_t lastFunction(SqlFunctionCtx* pCtx);
|
||||||
|
|
|
@ -3469,7 +3469,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.translateFunc = translateFirstLast,
|
.translateFunc = translateFirstLast,
|
||||||
.dynDataRequiredFunc = lastDynDataReq,
|
.dynDataRequiredFunc = lastDynDataReq,
|
||||||
.getEnvFunc = getFirstLastFuncEnv,
|
.getEnvFunc = getFirstLastFuncEnv,
|
||||||
.initFunc = functionSetup,
|
.initFunc = firstLastFunctionSetup,
|
||||||
.processFunc = lastFunction,
|
.processFunc = lastFunction,
|
||||||
.sprocessFunc = firstLastScalarFunction,
|
.sprocessFunc = firstLastScalarFunction,
|
||||||
.finalizeFunc = firstLastFinalize,
|
.finalizeFunc = firstLastFinalize,
|
||||||
|
|
|
@ -2617,6 +2617,22 @@ static FORCE_INLINE TSKEY getRowPTs(SColumnInfoData* pTsColInfo, int32_t rowInde
|
||||||
return *(TSKEY*)colDataGetData(pTsColInfo, rowIndex);
|
return *(TSKEY*)colDataGetData(pTsColInfo, rowIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t firstLastFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResInfo) {
|
||||||
|
if (pResInfo->initialized) {
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS != functionSetup(pCtx, pResInfo)) {
|
||||||
|
return TSDB_CODE_FUNC_SETUP_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
SFirstLastRes * pRes = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
|
SInputColumnInfoData* pInput = &pCtx->input;
|
||||||
|
|
||||||
|
pRes->nullTupleSaved = false;
|
||||||
|
pRes->nullTuplePos.pageId = -1;
|
||||||
|
return TSDB_CODE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t prepareBuf(SqlFunctionCtx* pCtx) {
|
static int32_t prepareBuf(SqlFunctionCtx* pCtx) {
|
||||||
if (pCtx->subsidiaries.rowLen == 0) {
|
if (pCtx->subsidiaries.rowLen == 0) {
|
||||||
int32_t rowLen = 0;
|
int32_t rowLen = 0;
|
||||||
|
@ -2635,7 +2651,7 @@ static int32_t prepareBuf(SqlFunctionCtx* pCtx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t firstlastSaveTupleData(const SSDataBlock* pSrcBlock, int32_t rowIndex, SqlFunctionCtx* pCtx,
|
static int32_t firstlastSaveTupleData(const SSDataBlock* pSrcBlock, int32_t rowIndex, SqlFunctionCtx* pCtx,
|
||||||
SFirstLastRes* pInfo) {
|
SFirstLastRes* pInfo, bool noElements) {
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
if (pCtx->subsidiaries.num <= 0) {
|
if (pCtx->subsidiaries.num <= 0) {
|
||||||
|
@ -2643,7 +2659,7 @@ static int32_t firstlastSaveTupleData(const SSDataBlock* pSrcBlock, int32_t rowI
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pInfo->hasResult) {
|
if (!pInfo->hasResult) {
|
||||||
code = saveTupleData(pCtx, rowIndex, pSrcBlock, &pInfo->pos);
|
code = saveTupleData(pCtx, rowIndex, pSrcBlock, noElements ? &pInfo->nullTuplePos : &pInfo->pos);
|
||||||
} else {
|
} else {
|
||||||
code = updateTupleData(pCtx, rowIndex, pSrcBlock, &pInfo->pos);
|
code = updateTupleData(pCtx, rowIndex, pSrcBlock, &pInfo->pos);
|
||||||
}
|
}
|
||||||
|
@ -2669,7 +2685,7 @@ static int32_t doSaveCurrentVal(SqlFunctionCtx* pCtx, int32_t rowIndex, int64_t
|
||||||
}
|
}
|
||||||
|
|
||||||
pInfo->ts = currentTs;
|
pInfo->ts = currentTs;
|
||||||
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pInfo);
|
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pInfo, false);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -2708,10 +2724,11 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (pInput->colDataSMAIsSet && (pInput->pColumnDataAgg[0]->numOfNull == pInput->totalRows) &&
|
if (pInput->colDataSMAIsSet && (pInput->pColumnDataAgg[0]->numOfNull == pInput->totalRows) &&
|
||||||
pInputCol->hasNull == true) {
|
pInputCol->hasNull == true) {
|
||||||
// save selectivity value for column consisted of all null values
|
// save selectivity value for column consisted of all null values
|
||||||
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo);
|
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo, !pInfo->nullTupleSaved);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
pInfo->nullTupleSaved = true;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2802,10 +2819,11 @@ int32_t firstFunction(SqlFunctionCtx* pCtx) {
|
||||||
|
|
||||||
if (numOfElems == 0) {
|
if (numOfElems == 0) {
|
||||||
// save selectivity value for column consisted of all null values
|
// save selectivity value for column consisted of all null values
|
||||||
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo);
|
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo, !pInfo->nullTupleSaved);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
pInfo->nullTupleSaved = true;
|
||||||
}
|
}
|
||||||
SET_VAL(pResInfo, numOfElems, 1);
|
SET_VAL(pResInfo, numOfElems, 1);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -2841,10 +2859,11 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
||||||
if (pInput->colDataSMAIsSet && (pInput->pColumnDataAgg[0]->numOfNull == pInput->totalRows) &&
|
if (pInput->colDataSMAIsSet && (pInput->pColumnDataAgg[0]->numOfNull == pInput->totalRows) &&
|
||||||
pInputCol->hasNull == true) {
|
pInputCol->hasNull == true) {
|
||||||
// save selectivity value for column consisted of all null values
|
// save selectivity value for column consisted of all null values
|
||||||
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo);
|
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo, !pInfo->nullTupleSaved);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
pInfo->nullTupleSaved = true;
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2983,10 +3002,11 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
||||||
|
|
||||||
// save selectivity value for column consisted of all null values
|
// save selectivity value for column consisted of all null values
|
||||||
if (numOfElems == 0) {
|
if (numOfElems == 0) {
|
||||||
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo);
|
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo, !pInfo->nullTupleSaved);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
pInfo->nullTupleSaved = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -3031,7 +3051,7 @@ static bool firstLastTransferInfoImpl(SFirstLastRes* pInput, SFirstLastRes* pOut
|
||||||
static int32_t firstLastTransferInfo(SqlFunctionCtx* pCtx, SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst,
|
static int32_t firstLastTransferInfo(SqlFunctionCtx* pCtx, SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst,
|
||||||
int32_t rowIndex) {
|
int32_t rowIndex) {
|
||||||
if (firstLastTransferInfoImpl(pInput, pOutput, isFirst)) {
|
if (firstLastTransferInfoImpl(pInput, pOutput, isFirst)) {
|
||||||
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pOutput);
|
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pOutput, pOutput->nullTupleSaved);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3079,6 +3099,14 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx* pCtx, bool isFirstQuer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (numOfElems == 0) {
|
||||||
|
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, pInput->startRowIndex, pCtx, pInfo, !pInfo->nullTupleSaved);
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
pInfo->nullTupleSaved = true;
|
||||||
|
}
|
||||||
|
|
||||||
SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1);
|
SET_VAL(GET_RES_INFO(pCtx), numOfElems, 1);
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -3099,6 +3127,11 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0;
|
pResInfo->isNullRes = (pResInfo->numOfRes == 0) ? 1 : 0;
|
||||||
|
|
||||||
SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(pResInfo);
|
SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
|
|
||||||
|
if (pResInfo->isNullRes) {
|
||||||
|
colDataSetNULL(pCol, pBlock->info.rows);
|
||||||
|
return setSelectivityValue(pCtx, pBlock, &pRes->nullTuplePos, pBlock->info.rows);
|
||||||
|
}
|
||||||
code = colDataSetVal(pCol, pBlock->info.rows, pRes->buf, pRes->isNull || pResInfo->isNullRes);
|
code = colDataSetVal(pCol, pBlock->info.rows, pRes->buf, pRes->isNull || pResInfo->isNullRes);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return code;
|
return code;
|
||||||
|
@ -3134,12 +3167,16 @@ int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
return TSDB_CODE_OUT_OF_RANGE;
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pEntryInfo->numOfRes == 0) {
|
||||||
|
colDataSetNULL(pCol, pBlock->info.rows);
|
||||||
|
code = setSelectivityValue(pCtx, pBlock, &pRes->nullTuplePos, pBlock->info.rows);
|
||||||
|
} else {
|
||||||
code = colDataSetVal(pCol, pBlock->info.rows, res, false);
|
code = colDataSetVal(pCol, pBlock->info.rows, res, false);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
code = setSelectivityValue(pCtx, pBlock, &pRes->pos, pBlock->info.rows);
|
code = setSelectivityValue(pCtx, pBlock, &pRes->pos, pBlock->info.rows);
|
||||||
|
}
|
||||||
taosMemoryFree(res);
|
taosMemoryFree(res);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3185,7 +3222,7 @@ static int32_t doSaveLastrow(SqlFunctionCtx* pCtx, char* pData, int32_t rowIndex
|
||||||
pInfo->pkData = pInfo->buf + pInfo->bytes;
|
pInfo->pkData = pInfo->buf + pInfo->bytes;
|
||||||
}
|
}
|
||||||
pInfo->ts = cts;
|
pInfo->ts = cts;
|
||||||
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pInfo);
|
int32_t code = firstlastSaveTupleData(pCtx->pSrcBlock, rowIndex, pCtx, pInfo, false);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -6036,9 +6073,10 @@ static void modeFunctionCleanup(SModeInfo * pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void modeFunctionCleanupExt(SqlFunctionCtx* pCtx) {
|
void modeFunctionCleanupExt(SqlFunctionCtx* pCtx) {
|
||||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
if (pCtx == NULL || GET_RES_INFO(pCtx) == NULL || GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)) == NULL) {
|
||||||
SModeInfo* pInfo = GET_ROWCELL_INTERBUF(pResInfo);
|
return;
|
||||||
modeFunctionCleanup(pInfo);
|
}
|
||||||
|
modeFunctionCleanup(GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t saveModeTupleData(SqlFunctionCtx* pCtx, char* data, SModeInfo *pInfo, STuplePos* pPos) {
|
static int32_t saveModeTupleData(SqlFunctionCtx* pCtx, char* data, SModeInfo *pInfo, STuplePos* pPos) {
|
||||||
|
|
|
@ -994,7 +994,7 @@ int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) {
|
||||||
|
|
||||||
TdFilePtr file = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC);
|
TdFilePtr file = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC);
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
fnError("udfd write udf shared library: %s failed, error: %d %s", path, errno, strerror(errno));
|
fnError("udfd write udf shared library: %s failed, error: %d %s", path, errno, strerror(terrno));
|
||||||
return TSDB_CODE_FILE_CORRUPTED;
|
return TSDB_CODE_FILE_CORRUPTED;
|
||||||
}
|
}
|
||||||
int64_t count = taosWriteFile(file, pFuncInfo->pCode, pFuncInfo->codeSize);
|
int64_t count = taosWriteFile(file, pFuncInfo->pCode, pFuncInfo->codeSize);
|
||||||
|
|
|
@ -1125,7 +1125,7 @@ static int32_t tfileGetFileList(const char* path, SArray** ppResult) {
|
||||||
|
|
||||||
TdDirPtr pDir = taosOpenDir(path);
|
TdDirPtr pDir = taosOpenDir(path);
|
||||||
if (NULL == pDir) {
|
if (NULL == pDir) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _exception);
|
TAOS_CHECK_GOTO(terrno, NULL, _exception);
|
||||||
}
|
}
|
||||||
TdDirEntryPtr pDirEntry;
|
TdDirEntryPtr pDirEntry;
|
||||||
while ((pDirEntry = taosReadDir(pDir)) != NULL) {
|
while ((pDirEntry = taosReadDir(pDir)) != NULL) {
|
||||||
|
|
|
@ -2268,7 +2268,7 @@ static int32_t parseDataFromFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt*
|
||||||
}
|
}
|
||||||
pStmt->fp = taosOpenFile(filePathStr, TD_FILE_READ | TD_FILE_STREAM);
|
pStmt->fp = taosOpenFile(filePathStr, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (NULL == pStmt->fp) {
|
if (NULL == pStmt->fp) {
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parseDataFromFileImpl(pCxt, pStmt, rowsDataCxt);
|
return parseDataFromFileImpl(pCxt, pStmt, rowsDataCxt);
|
||||||
|
|
|
@ -11384,7 +11384,7 @@ static int32_t translateDropView(STranslateContext* pCxt, SDropViewStmt* pStmt)
|
||||||
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, NULL) < 0) {
|
if (taosStatFile(pName, &filesize, NULL, NULL) < 0) {
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
*len = filesize;
|
*len = filesize;
|
||||||
|
@ -11401,7 +11401,7 @@ static int32_t readFromFile(char* pName, int32_t* len, char** buf) {
|
||||||
TdFilePtr tfile = taosOpenFile(pName, O_RDONLY | O_BINARY);
|
TdFilePtr tfile = taosOpenFile(pName, O_RDONLY | O_BINARY);
|
||||||
if (NULL == tfile) {
|
if (NULL == tfile) {
|
||||||
taosMemoryFreeClear(*buf);
|
taosMemoryFreeClear(*buf);
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t s = taosReadFile(tfile, *buf, *len);
|
int64_t s = taosReadFile(tfile, *buf, *len);
|
||||||
|
@ -14080,7 +14080,7 @@ static int32_t prepareReadCsvFile(STranslateContext* pCxt, SCreateSubTableFromFi
|
||||||
if (NULL == pModifyStmt->fp) {
|
if (NULL == pModifyStmt->fp) {
|
||||||
fp = taosOpenFile(pCreateStmt->filePath, TD_FILE_READ | TD_FILE_STREAM);
|
fp = taosOpenFile(pCreateStmt->filePath, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (NULL == fp) {
|
if (NULL == fp) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _ERR;
|
goto _ERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,13 +290,13 @@ int32_t remoteChkp_readMetaData(char* path, SSChkpMetaOnS3** pMeta) {
|
||||||
|
|
||||||
pFile = taosOpenFile(path, TD_FILE_READ);
|
pFile = taosOpenFile(path, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[256] = {0};
|
char buf[256] = {0};
|
||||||
if (taosReadFile(pFile, buf, sizeof(buf)) <= 0) {
|
if (taosReadFile(pFile, buf, sizeof(buf)) <= 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ int32_t remoteChkp_validAndCvtMeta(char* path, SSChkpMetaOnS3* pMeta, int64_t ch
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosStatFile(src, NULL, NULL, NULL) != 0) {
|
if (taosStatFile(src, NULL, NULL, NULL) != 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,8 +367,8 @@ int32_t remoteChkp_validAndCvtMeta(char* path, SSChkpMetaOnS3* pMeta, int64_t ch
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosRenameFile(src, dst) != 0) {
|
code = taosRenameFile(src, dst);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,7 +507,6 @@ int32_t rebuildFromRemoteChkp_s3(const char* key, char* chkpPath, int64_t chkpId
|
||||||
if (taosIsDir(defaultPath)) {
|
if (taosIsDir(defaultPath)) {
|
||||||
code = taosRenameFile(defaultPath, defaultTmp);
|
code = taosRenameFile(defaultPath, defaultTmp);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
} else {
|
} else {
|
||||||
rename = 1;
|
rename = 1;
|
||||||
|
@ -598,7 +597,7 @@ int32_t backendFileCopyFilesImpl(const char* src, const char* dst) {
|
||||||
// copy file to dst
|
// copy file to dst
|
||||||
TdDirPtr pDir = taosOpenDir(src);
|
TdDirPtr pDir = taosOpenDir(src);
|
||||||
if (pDir == NULL) {
|
if (pDir == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
goto _ERROR;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1427,7 +1426,7 @@ int32_t chkpPreBuildDir(char* path, int64_t chkpId, char** chkpDir, char** chkpI
|
||||||
|
|
||||||
code = taosMulModeMkDir(pChkpDir, 0755, true);
|
code = taosMulModeMkDir(pChkpDir, 0755, true);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("failed to prepare checkpoint dir, path:%s, reason:%s", path, tstrerror(code));
|
stError("failed to prepare checkpoint dir, path:%s, reason:%s", path, tstrerror(code));
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
}
|
}
|
||||||
|
@ -1603,12 +1602,12 @@ int32_t chkpLoadExtraInfo(char* pChkpIdDir, int64_t* chkpId, int64_t* processId)
|
||||||
// compatible with previous version
|
// compatible with previous version
|
||||||
*processId = -1;
|
*processId = -1;
|
||||||
code = 0;
|
code = 0;
|
||||||
stWarn("failed to open file to load extra info, file:%s, reason:%s", pDst, tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
stWarn("failed to open file to load extra info, file:%s, reason:%s", pDst, tstrerror(terrno));
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, buf, sizeof(buf)) <= 0) {
|
if (taosReadFile(pFile, buf, sizeof(buf)) <= 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("failed to read file to load extra info, file:%s, reason:%s", pDst, tstrerror(code));
|
stError("failed to read file to load extra info, file:%s, reason:%s", pDst, tstrerror(code));
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
}
|
}
|
||||||
|
@ -1656,7 +1655,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) {
|
||||||
|
|
||||||
pFile = taosOpenFile(pDst, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
pFile = taosOpenFile(pDst, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("failed to open file to add extra info, file:%s, reason:%s", pDst, tstrerror(code));
|
stError("failed to open file to add extra info, file:%s, reason:%s", pDst, tstrerror(code));
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
}
|
}
|
||||||
|
@ -1669,7 +1668,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nBytes != taosWriteFile(pFile, buf, nBytes)) {
|
if (nBytes != taosWriteFile(pFile, buf, nBytes)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("failed to write file to add extra info, file:%s, reason:%s", pDst, tstrerror(code));
|
stError("failed to write file to add extra info, file:%s, reason:%s", pDst, tstrerror(code));
|
||||||
goto _EXIT;
|
goto _EXIT;
|
||||||
}
|
}
|
||||||
|
@ -4665,7 +4664,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) {
|
||||||
TdDirPtr pDir = taosOpenDir(p->buf);
|
TdDirPtr pDir = taosOpenDir(p->buf);
|
||||||
if (pDir == NULL) {
|
if (pDir == NULL) {
|
||||||
(void)taosThreadRwlockUnlock(&p->rwLock);
|
(void)taosThreadRwlockUnlock(&p->rwLock);
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
TdDirEntryPtr de = NULL;
|
TdDirEntryPtr de = NULL;
|
||||||
|
@ -4973,7 +4972,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosCopyFile(srcBuf, dstBuf) < 0) {
|
if (taosCopyFile(srcBuf, dstBuf) < 0) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("failed to copy file from %s to %s, reason:%s", srcBuf, dstBuf, tstrerror(code));
|
stError("failed to copy file from %s to %s, reason:%s", srcBuf, dstBuf, tstrerror(code));
|
||||||
goto _ERROR;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
@ -4986,7 +4985,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) {
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(dstDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
TdFilePtr pFile = taosOpenFile(dstDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("chkp failed to create meta file: %s, reason:%s", dstDir, tstrerror(code));
|
stError("chkp failed to create meta file: %s, reason:%s", dstDir, tstrerror(code));
|
||||||
goto _ERROR;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
@ -5003,7 +5002,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) {
|
||||||
|
|
||||||
nBytes = taosWriteFile(pFile, content, strlen(content));
|
nBytes = taosWriteFile(pFile, content, strlen(content));
|
||||||
if (nBytes != strlen(content)) {
|
if (nBytes != strlen(content)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("chkp failed to write meta file: %s,reason:%s", dstDir, tstrerror(code));
|
stError("chkp failed to write meta file: %s,reason:%s", dstDir, tstrerror(code));
|
||||||
(void)taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
goto _ERROR;
|
goto _ERROR;
|
||||||
|
|
|
@ -1244,7 +1244,7 @@ static int32_t uploadCheckpointToS3(const char* id, const char* path) {
|
||||||
|
|
||||||
TdDirPtr pDir = taosOpenDir(path);
|
TdDirPtr pDir = taosOpenDir(path);
|
||||||
if (pDir == NULL) {
|
if (pDir == NULL) {
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
TdDirEntryPtr de = NULL;
|
TdDirEntryPtr de = NULL;
|
||||||
|
|
|
@ -271,7 +271,7 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
TdDirPtr pDir = taosOpenDir(pSnapFile->path);
|
TdDirPtr pDir = taosOpenDir(pSnapFile->path);
|
||||||
if (NULL == pDir) {
|
if (NULL == pDir) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("%s failed to open %s, reason:%s", STREAM_STATE_TRANSFER, pSnapFile->path, tstrerror(code));
|
stError("%s failed to open %s, reason:%s", STREAM_STATE_TRANSFER, pSnapFile->path, tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -556,9 +556,9 @@ _NEXT:
|
||||||
|
|
||||||
uint8_t* buf = taosMemoryCalloc(1, sizeof(SStreamSnapBlockHdr) + kBlockSize);
|
uint8_t* buf = taosMemoryCalloc(1, sizeof(SStreamSnapBlockHdr) + kBlockSize);
|
||||||
int64_t nread = taosPReadFile(pSnapFile->fd, buf + sizeof(SStreamSnapBlockHdr), kBlockSize, pSnapFile->offset);
|
int64_t nread = taosPReadFile(pSnapFile->fd, buf + sizeof(SStreamSnapBlockHdr), kBlockSize, pSnapFile->offset);
|
||||||
if (nread == -1) {
|
if (nread < 0) {
|
||||||
taosMemoryFree(buf);
|
taosMemoryFree(buf);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("%s snap failed to read snap, file name:%s, type:%d,reason:%s", STREAM_STATE_TRANSFER, item->name,
|
stError("%s snap failed to read snap, file name:%s, type:%d,reason:%s", STREAM_STATE_TRANSFER, item->name,
|
||||||
item->type, tstrerror(code));
|
item->type, tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
|
@ -696,7 +696,7 @@ int32_t streamSnapWriteImpl(SStreamSnapWriter* pWriter, uint8_t* pData, uint32_t
|
||||||
if (strlen(pHdr->name) == strlen(pItem->name) && strcmp(pHdr->name, pItem->name) == 0) {
|
if (strlen(pHdr->name) == strlen(pItem->name) && strcmp(pHdr->name, pItem->name) == 0) {
|
||||||
int64_t bytes = taosPWriteFile(pSnapFile->fd, pHdr->data, pHdr->size, pSnapFile->offset);
|
int64_t bytes = taosPWriteFile(pSnapFile->fd, pHdr->data, pHdr->size, pSnapFile->offset);
|
||||||
if (bytes != pHdr->size) {
|
if (bytes != pHdr->size) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("%s failed to write snap, file name:%s, reason:%s", STREAM_STATE_TRANSFER, pHdr->name, tstrerror(code));
|
stError("%s failed to write snap, file name:%s, reason:%s", STREAM_STATE_TRANSFER, pHdr->name, tstrerror(code));
|
||||||
goto _err;
|
goto _err;
|
||||||
} else {
|
} else {
|
||||||
|
@ -735,7 +735,7 @@ int32_t streamSnapWriteImpl(SStreamSnapWriter* pWriter, uint8_t* pData, uint32_t
|
||||||
|
|
||||||
// open fd again, let's close fd during handle errors.
|
// open fd again, let's close fd during handle errors.
|
||||||
if (taosPWriteFile(pSnapFile->fd, pHdr->data, pHdr->size, pSnapFile->offset) != pHdr->size) {
|
if (taosPWriteFile(pSnapFile->fd, pHdr->data, pHdr->size, pSnapFile->offset) != pHdr->size) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
stError("%s failed to write snap, file name:%s, reason:%s", STREAM_STATE_TRANSFER, pHdr->name, tstrerror(code));
|
stError("%s failed to write snap, file name:%s, reason:%s", STREAM_STATE_TRANSFER, pHdr->name, tstrerror(code));
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1279,7 +1279,7 @@ int32_t syncLogBufferCreate(SSyncLogBuffer** ppBuf) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SSyncLogBuffer* pBuf = taosMemoryCalloc(1, sizeof(SSyncLogBuffer));
|
SSyncLogBuffer* pBuf = taosMemoryCalloc(1, sizeof(SSyncLogBuffer));
|
||||||
if (pBuf == NULL) {
|
if (pBuf == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exit);
|
TAOS_CHECK_GOTO(terrno, NULL, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
pBuf->size = sizeof(pBuf->entries) / sizeof(pBuf->entries[0]);
|
pBuf->size = sizeof(pBuf->entries) / sizeof(pBuf->entries[0]);
|
||||||
|
|
|
@ -150,13 +150,13 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = terrno ? terrno : TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
TAOS_CHECK_EXIT(code);
|
TAOS_CHECK_EXIT(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||||
TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno));
|
TAOS_CHECK_EXIT(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFsyncFile(pFile) < 0) {
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
@ -164,9 +164,7 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
if (taosRenameFile(file, realfile) != 0) {
|
TAOS_CHECK_EXIT(taosRenameFile(file, realfile));
|
||||||
TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
sInfo("vgId:%d, succeed to write sync cfg file:%s, len:%d, lastConfigIndex:%" PRId64 ", changeVersion:%d",
|
sInfo("vgId:%d, succeed to write sync cfg file:%s, len:%d, lastConfigIndex:%" PRId64 ", changeVersion:%d",
|
||||||
pNode->vgId, realfile, len, pNode->raftCfg.lastConfigIndex, pNode->raftCfg.cfg.changeVersion);
|
pNode->vgId, realfile, len, pNode->raftCfg.lastConfigIndex, pNode->raftCfg.cfg.changeVersion);
|
||||||
|
@ -261,14 +259,14 @@ int32_t syncReadCfgFile(SSyncNode *pNode) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
sError("vgId:%d, failed to open sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code));
|
sError("vgId:%d, failed to open sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
if (code != 0) {
|
||||||
sError("vgId:%d, failed to fstat sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code));
|
sError("vgId:%d, failed to fstat sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -280,7 +278,7 @@ int32_t syncReadCfgFile(SSyncNode *pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, pData, size) != size) {
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
sError("vgId:%d, failed to read sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code));
|
sError("vgId:%d, failed to read sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,14 +54,14 @@ int32_t raftStoreReadFile(SSyncNode *pNode) {
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
sError("vgId:%d, failed to open raft store file:%s since %s", pNode->vgId, file, terrstr());
|
sError("vgId:%d, failed to open raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
TAOS_CHECK_GOTO(terrno, &lino, _OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
code = taosFStatFile(pFile, &size, NULL);
|
||||||
|
if (code != 0) {
|
||||||
sError("vgId:%d, failed to fstat raft store file:%s since %s", pNode->vgId, file, terrstr());
|
sError("vgId:%d, failed to fstat raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
|
TAOS_CHECK_GOTO(code, &lino, _OVER);
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pData = taosMemoryMalloc(size + 1);
|
pData = taosMemoryMalloc(size + 1);
|
||||||
|
@ -72,7 +72,7 @@ int32_t raftStoreReadFile(SSyncNode *pNode) {
|
||||||
if (taosReadFile(pFile, pData, size) != size) {
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
sError("vgId:%d, failed to read raft store file:%s since %s", pNode->vgId, file, terrstr());
|
sError("vgId:%d, failed to read raft store file:%s since %s", pNode->vgId, file, terrstr());
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
TAOS_CHECK_GOTO(terrno, &lino, _OVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
pData[size] = '\0';
|
pData[size] = '\0';
|
||||||
|
@ -127,15 +127,15 @@ int32_t raftStoreWriteFile(SSyncNode *pNode) {
|
||||||
if (buffer == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER);
|
if (buffer == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER);
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
if (pFile == NULL) TAOS_CHECK_GOTO(terrno, &lino, _OVER);
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER);
|
||||||
|
|
||||||
if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER);
|
||||||
|
|
||||||
(void)taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER);
|
if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER);
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
sInfo("vgId:%d, succeed to write raft store file:%s, term:%" PRId64, pNode->vgId, realfile, pStore->currentTerm);
|
sInfo("vgId:%d, succeed to write raft store file:%s, term:%" PRId64, pNode->vgId, realfile, pStore->currentTerm);
|
||||||
|
|
|
@ -25,7 +25,7 @@ int32_t syncRespMgrCreate(void *data, int64_t ttl, SSyncRespMgr **ppObj) {
|
||||||
*ppObj = NULL;
|
*ppObj = NULL;
|
||||||
|
|
||||||
if ((pObj = taosMemoryCalloc(1, sizeof(SSyncRespMgr))) == NULL) {
|
if ((pObj = taosMemoryCalloc(1, sizeof(SSyncRespMgr))) == NULL) {
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
pObj->pRespHash =
|
pObj->pRespHash =
|
||||||
|
|
|
@ -54,7 +54,7 @@ static int32_t syncSnapBufferCreate(SSyncSnapBuffer **ppBuf) {
|
||||||
SSyncSnapBuffer *pBuf = taosMemoryCalloc(1, sizeof(SSyncSnapBuffer));
|
SSyncSnapBuffer *pBuf = taosMemoryCalloc(1, sizeof(SSyncSnapBuffer));
|
||||||
if (pBuf == NULL) {
|
if (pBuf == NULL) {
|
||||||
*ppBuf = NULL;
|
*ppBuf = NULL;
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
pBuf->size = sizeof(pBuf->entries) / sizeof(void *);
|
pBuf->size = sizeof(pBuf->entries) / sizeof(void *);
|
||||||
if (pBuf->size != TSDB_SYNC_SNAP_BUFFER_SIZE) return TSDB_CODE_SYN_INTERNAL_ERROR;
|
if (pBuf->size != TSDB_SYNC_SNAP_BUFFER_SIZE) return TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
@ -74,7 +74,7 @@ int32_t snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaIndex, SSyncSn
|
||||||
|
|
||||||
SSyncSnapshotSender *pSender = taosMemoryCalloc(1, sizeof(SSyncSnapshotSender));
|
SSyncSnapshotSender *pSender = taosMemoryCalloc(1, sizeof(SSyncSnapshotSender));
|
||||||
if (pSender == NULL) {
|
if (pSender == NULL) {
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
pSender->start = false;
|
pSender->start = false;
|
||||||
|
@ -285,7 +285,7 @@ static int32_t snapshotSend(SSyncSnapshotSender *pSender) {
|
||||||
if (pSender->seq > SYNC_SNAPSHOT_SEQ_BEGIN) {
|
if (pSender->seq > SYNC_SNAPSHOT_SEQ_BEGIN) {
|
||||||
pBlk = taosMemoryCalloc(1, sizeof(SyncSnapBlock));
|
pBlk = taosMemoryCalloc(1, sizeof(SyncSnapBlock));
|
||||||
if (pBlk == NULL) {
|
if (pBlk == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
goto _OUT;
|
goto _OUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +422,7 @@ int32_t snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId, SSyncSnapsh
|
||||||
|
|
||||||
SSyncSnapshotReceiver *pReceiver = taosMemoryCalloc(1, sizeof(SSyncSnapshotReceiver));
|
SSyncSnapshotReceiver *pReceiver = taosMemoryCalloc(1, sizeof(SSyncSnapshotReceiver));
|
||||||
if (pReceiver == NULL) {
|
if (pReceiver == NULL) {
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
pReceiver->start = false;
|
pReceiver->start = false;
|
||||||
|
@ -697,7 +697,7 @@ static int32_t syncSnapReceiverExchgSnapInfo(SSyncNode *pSyncNode, SSyncSnapshot
|
||||||
// copy snap info from leader
|
// copy snap info from leader
|
||||||
void *data = taosMemoryCalloc(1, pMsg->dataLen);
|
void *data = taosMemoryCalloc(1, pMsg->dataLen);
|
||||||
if (data == NULL) {
|
if (data == NULL) {
|
||||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
TAOS_CHECK_EXIT(terrno);
|
||||||
}
|
}
|
||||||
pInfo->data = data;
|
pInfo->data = data;
|
||||||
data = NULL;
|
data = NULL;
|
||||||
|
|
|
@ -1136,7 +1136,7 @@ int tdbPagerRestoreJournals(SPager *pPager) {
|
||||||
tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName);
|
tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName);
|
||||||
if (pDir == NULL) {
|
if (pDir == NULL) {
|
||||||
tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno));
|
tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno));
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray *pTxnList = taosArrayInit(16, sizeof(int64_t));
|
SArray *pTxnList = taosArrayInit(16, sizeof(int64_t));
|
||||||
|
@ -1182,7 +1182,7 @@ int tdbPagerRollback(SPager *pPager) {
|
||||||
tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName);
|
tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName);
|
||||||
if (pDir == NULL) {
|
if (pDir == NULL) {
|
||||||
tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno));
|
tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno));
|
||||||
return terrno = TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((pDirEntry = tdbReadDir(pDir)) != NULL) {
|
while ((pDirEntry = tdbReadDir(pDir)) != NULL) {
|
||||||
|
|
|
@ -39,7 +39,9 @@ int tdbGnrtFileID(tdb_fd_t fd, uint8_t *fileid, bool unique) {
|
||||||
int64_t stDev = 0, stIno = 0;
|
int64_t stDev = 0, stIno = 0;
|
||||||
|
|
||||||
int32_t code = taosDevInoFile(fd, &stDev, &stIno);
|
int32_t code = taosDevInoFile(fd, &stDev, &stIno);
|
||||||
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return code;
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
memset(fileid, 0, TDB_FILE_ID_LEN);
|
memset(fileid, 0, TDB_FILE_ID_LEN);
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ int32_t tfsOpen(SDiskCfg *pCfg, int32_t ndisk, STfs **ppTfs) {
|
||||||
|
|
||||||
pTfs = taosMemoryCalloc(1, sizeof(STfs));
|
pTfs = taosMemoryCalloc(1, sizeof(STfs));
|
||||||
if (pTfs == NULL) {
|
if (pTfs == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosThreadSpinInit(&pTfs->lock, 0) != 0) {
|
if (taosThreadSpinInit(&pTfs->lock, 0) != 0) {
|
||||||
|
@ -429,7 +429,7 @@ int32_t tfsOpendir(STfs *pTfs, const char *rname, STfsDir **ppDir) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
STfsDir *pDir = taosMemoryCalloc(1, sizeof(STfsDir));
|
STfsDir *pDir = taosMemoryCalloc(1, sizeof(STfsDir));
|
||||||
if (pDir == NULL) {
|
if (pDir == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exit);
|
TAOS_CHECK_GOTO(terrno, NULL, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDiskID diskId = {.id = 0, .level = 0};
|
SDiskID diskId = {.id = 0, .level = 0};
|
||||||
|
|
|
@ -22,7 +22,7 @@ int32_t tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *path,
|
||||||
STfsDisk *pDisk = NULL;
|
STfsDisk *pDisk = NULL;
|
||||||
|
|
||||||
if ((pDisk = taosMemoryCalloc(1, sizeof(STfsDisk))) == NULL) {
|
if ((pDisk = taosMemoryCalloc(1, sizeof(STfsDisk))) == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pDisk->path = taosStrdup(path)) == NULL) {
|
if ((pDisk->path = taosStrdup(path)) == NULL) {
|
||||||
|
|
|
@ -446,7 +446,7 @@ static void clientConnCb(uv_connect_t* req, int32_t status) {
|
||||||
int32_t httpSendQuit(SHttpModule* http, int64_t chanId) {
|
int32_t httpSendQuit(SHttpModule* http, int64_t chanId) {
|
||||||
SHttpMsg* msg = taosMemoryCalloc(1, sizeof(SHttpMsg));
|
SHttpMsg* msg = taosMemoryCalloc(1, sizeof(SHttpMsg));
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
msg->seq = atomic_fetch_add_64(&httpSeqNum, 1);
|
msg->seq = atomic_fetch_add_64(&httpSeqNum, 1);
|
||||||
msg->quit = 1;
|
msg->quit = 1;
|
||||||
|
@ -744,7 +744,7 @@ int64_t transInitHttpChanImpl() {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SHttpModule* http = taosMemoryCalloc(1, sizeof(SHttpModule));
|
SHttpModule* http = taosMemoryCalloc(1, sizeof(SHttpModule));
|
||||||
if (http == NULL) {
|
if (http == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
goto _ERROR;
|
goto _ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,14 +124,20 @@ _end:
|
||||||
}
|
}
|
||||||
void rpcClose(void* arg) {
|
void rpcClose(void* arg) {
|
||||||
tInfo("start to close rpc");
|
tInfo("start to close rpc");
|
||||||
|
if (arg == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
(void)transRemoveExHandle(transGetInstMgt(), (int64_t)arg);
|
(void)transRemoveExHandle(transGetInstMgt(), (int64_t)arg);
|
||||||
(void)transReleaseExHandle(transGetInstMgt(), (int64_t)arg);
|
(void)transReleaseExHandle(transGetInstMgt(), (int64_t)arg);
|
||||||
tInfo("end to close rpc");
|
tInfo("end to close rpc");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void rpcCloseImpl(void* arg) {
|
void rpcCloseImpl(void* arg) {
|
||||||
|
if (arg == NULL) return;
|
||||||
SRpcInfo* pRpc = (SRpcInfo*)arg;
|
SRpcInfo* pRpc = (SRpcInfo*)arg;
|
||||||
|
if (pRpc->tcphandle != NULL) {
|
||||||
(*taosCloseHandle[pRpc->connType])(pRpc->tcphandle);
|
(*taosCloseHandle[pRpc->connType])(pRpc->tcphandle);
|
||||||
|
}
|
||||||
taosMemoryFree(pRpc);
|
taosMemoryFree(pRpc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,6 @@ typedef struct SCliThrd {
|
||||||
int64_t pid; // pid
|
int64_t pid; // pid
|
||||||
uv_loop_t* loop;
|
uv_loop_t* loop;
|
||||||
SAsyncPool* asyncPool;
|
SAsyncPool* asyncPool;
|
||||||
uv_prepare_t* prepare;
|
|
||||||
void* pool; // conn pool
|
void* pool; // conn pool
|
||||||
// timer handles
|
// timer handles
|
||||||
SArray* timerList;
|
SArray* timerList;
|
||||||
|
@ -167,7 +166,6 @@ static void cliSendCb(uv_write_t* req, int status);
|
||||||
static void cliConnCb(uv_connect_t* req, int status);
|
static void cliConnCb(uv_connect_t* req, int status);
|
||||||
static void cliAsyncCb(uv_async_t* handle);
|
static void cliAsyncCb(uv_async_t* handle);
|
||||||
static void cliIdleCb(uv_idle_t* handle);
|
static void cliIdleCb(uv_idle_t* handle);
|
||||||
static void cliPrepareCb(uv_prepare_t* handle);
|
|
||||||
|
|
||||||
static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd);
|
static void cliHandleBatchReq(SCliBatch* pBatch, SCliThrd* pThrd);
|
||||||
static void cliSendBatchCb(uv_write_t* req, int status);
|
static void cliSendBatchCb(uv_write_t* req, int status);
|
||||||
|
@ -231,6 +229,8 @@ static FORCE_INLINE void transDestroyConnCtx(STransConnCtx* ctx);
|
||||||
// thread obj
|
// thread obj
|
||||||
static int32_t createThrdObj(void* trans, SCliThrd** pThrd);
|
static int32_t createThrdObj(void* trans, SCliThrd** pThrd);
|
||||||
static void destroyThrdObj(SCliThrd* pThrd);
|
static void destroyThrdObj(SCliThrd* pThrd);
|
||||||
|
|
||||||
|
int32_t cliSendQuit(SCliThrd* thrd);
|
||||||
static void cliWalkCb(uv_handle_t* handle, void* arg);
|
static void cliWalkCb(uv_handle_t* handle, void* arg);
|
||||||
|
|
||||||
#define CLI_RELEASE_UV(loop) \
|
#define CLI_RELEASE_UV(loop) \
|
||||||
|
@ -620,6 +620,10 @@ void* createConnPool(int size) {
|
||||||
}
|
}
|
||||||
void* destroyConnPool(SCliThrd* pThrd) {
|
void* destroyConnPool(SCliThrd* pThrd) {
|
||||||
void* pool = pThrd->pool;
|
void* pool = pThrd->pool;
|
||||||
|
if (pool == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
SConnList* connList = taosHashIterate((SHashObj*)pool, NULL);
|
SConnList* connList = taosHashIterate((SHashObj*)pool, NULL);
|
||||||
while (connList != NULL) {
|
while (connList != NULL) {
|
||||||
while (!QUEUE_IS_EMPTY(&connList->conns)) {
|
while (!QUEUE_IS_EMPTY(&connList->conns)) {
|
||||||
|
@ -874,7 +878,7 @@ static int32_t allocConnRef(SCliConn* conn, bool update) {
|
||||||
|
|
||||||
SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle));
|
SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle));
|
||||||
if (exh == NULL) {
|
if (exh == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
exh->refId = transAddExHandle(transGetRefMgt(), exh);
|
exh->refId = transAddExHandle(transGetRefMgt(), exh);
|
||||||
|
@ -974,7 +978,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn));
|
SCliConn* conn = taosMemoryCalloc(1, sizeof(SCliConn));
|
||||||
if (conn == NULL) {
|
if (conn == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read/write stream handle
|
// read/write stream handle
|
||||||
|
@ -996,7 +1000,7 @@ static int32_t cliCreateConn(SCliThrd* pThrd, SCliConn** pCliConn) {
|
||||||
if (timer == NULL) {
|
if (timer == NULL) {
|
||||||
timer = taosMemoryCalloc(1, sizeof(uv_timer_t));
|
timer = taosMemoryCalloc(1, sizeof(uv_timer_t));
|
||||||
if (timer == NULL) {
|
if (timer == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _failed);
|
TAOS_CHECK_GOTO(terrno, NULL, _failed);
|
||||||
}
|
}
|
||||||
|
|
||||||
tDebug("no available timer, create a timer %p", timer);
|
tDebug("no available timer, create a timer %p", timer);
|
||||||
|
@ -1951,7 +1955,7 @@ static int32_t createBatchList(SCliBatchList** ppBatchList, char* key, char* ip,
|
||||||
SCliBatchList* pBatchList = taosMemoryCalloc(1, sizeof(SCliBatchList));
|
SCliBatchList* pBatchList = taosMemoryCalloc(1, sizeof(SCliBatchList));
|
||||||
if (pBatchList == NULL) {
|
if (pBatchList == NULL) {
|
||||||
tError("failed to create batch list, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
tError("failed to create batch list, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
QUEUE_INIT(&pBatchList->wq);
|
QUEUE_INIT(&pBatchList->wq);
|
||||||
pBatchList->port = port;
|
pBatchList->port = port;
|
||||||
|
@ -1991,7 +1995,7 @@ static int32_t createBatch(SCliBatch** ppBatch, SCliBatchList* pList, SCliMsg* p
|
||||||
SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch));
|
SCliBatch* pBatch = taosMemoryCalloc(1, sizeof(SCliBatch));
|
||||||
if (pBatch == NULL) {
|
if (pBatch == NULL) {
|
||||||
tError("failed to create batch, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
tError("failed to create batch, reason:%s", tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUEUE_INIT(&pBatch->wq);
|
QUEUE_INIT(&pBatch->wq);
|
||||||
|
@ -2119,33 +2123,6 @@ static void cliAsyncCb(uv_async_t* handle) {
|
||||||
|
|
||||||
if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd->stopMsg, pThrd);
|
if (pThrd->stopMsg != NULL) cliHandleQuit(pThrd->stopMsg, pThrd);
|
||||||
}
|
}
|
||||||
static void cliPrepareCb(uv_prepare_t* handle) {
|
|
||||||
SCliThrd* thrd = handle->data;
|
|
||||||
tTrace("prepare work start");
|
|
||||||
|
|
||||||
SAsyncPool* pool = thrd->asyncPool;
|
|
||||||
for (int i = 0; i < pool->nAsync; i++) {
|
|
||||||
uv_async_t* async = &(pool->asyncs[i]);
|
|
||||||
SAsyncItem* item = async->data;
|
|
||||||
|
|
||||||
queue wq;
|
|
||||||
(void)taosThreadMutexLock(&item->mtx);
|
|
||||||
QUEUE_MOVE(&item->qmsg, &wq);
|
|
||||||
(void)taosThreadMutexUnlock(&item->mtx);
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
while (!QUEUE_IS_EMPTY(&wq)) {
|
|
||||||
queue* h = QUEUE_HEAD(&wq);
|
|
||||||
QUEUE_REMOVE(h);
|
|
||||||
|
|
||||||
SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q);
|
|
||||||
(*cliAsyncHandle[pMsg->type])(pMsg, thrd);
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tTrace("prepare work end");
|
|
||||||
if (thrd->stopMsg != NULL) cliHandleQuit(thrd->stopMsg, thrd);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cliDestroyConnMsgs(SCliConn* conn, bool destroy) {
|
void cliDestroyConnMsgs(SCliConn* conn, bool destroy) {
|
||||||
transCtxCleanup(&conn->ctx);
|
transCtxCleanup(&conn->ctx);
|
||||||
|
@ -2260,6 +2237,12 @@ void* transInitClient(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
if (cli) {
|
if (cli) {
|
||||||
|
for (int i = 0; i < cli->numOfThreads; i++) {
|
||||||
|
if (cli->pThreadObj[i]) {
|
||||||
|
(void)cliSendQuit(cli->pThreadObj[i]);
|
||||||
|
destroyThrdObj(cli->pThreadObj[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
taosMemoryFree(cli->pThreadObj);
|
taosMemoryFree(cli->pThreadObj);
|
||||||
taosMemoryFree(cli);
|
taosMemoryFree(cli);
|
||||||
}
|
}
|
||||||
|
@ -2315,7 +2298,7 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) {
|
||||||
|
|
||||||
SCliThrd* pThrd = (SCliThrd*)taosMemoryCalloc(1, sizeof(SCliThrd));
|
SCliThrd* pThrd = (SCliThrd*)taosMemoryCalloc(1, sizeof(SCliThrd));
|
||||||
if (pThrd == NULL) {
|
if (pThrd == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end);
|
TAOS_CHECK_GOTO(terrno, NULL, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
QUEUE_INIT(&pThrd->msg);
|
QUEUE_INIT(&pThrd->msg);
|
||||||
|
@ -2323,7 +2306,7 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) {
|
||||||
|
|
||||||
pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t));
|
pThrd->loop = (uv_loop_t*)taosMemoryMalloc(sizeof(uv_loop_t));
|
||||||
if (pThrd->loop == NULL) {
|
if (pThrd->loop == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end);
|
TAOS_CHECK_GOTO(terrno, NULL, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = uv_loop_init(pThrd->loop);
|
code = uv_loop_init(pThrd->loop);
|
||||||
|
@ -2339,37 +2322,6 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) {
|
||||||
TAOS_CHECK_GOTO(code, NULL, _end);
|
TAOS_CHECK_GOTO(code, NULL, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
pThrd->prepare = taosMemoryCalloc(1, sizeof(uv_prepare_t));
|
|
||||||
if (pThrd->prepare == NULL) {
|
|
||||||
tError("failed to create prepre since:%s", tstrerror(code));
|
|
||||||
TAOS_CHECK_GOTO(code, NULL, _end);
|
|
||||||
}
|
|
||||||
|
|
||||||
code = uv_prepare_init(pThrd->loop, pThrd->prepare);
|
|
||||||
if (code != 0) {
|
|
||||||
tError("failed to create prepre since:%s", uv_err_name(code));
|
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_THIRDPARTY_ERROR, NULL, _end);
|
|
||||||
}
|
|
||||||
pThrd->prepare->data = pThrd;
|
|
||||||
|
|
||||||
int32_t timerSize = 64;
|
|
||||||
pThrd->timerList = taosArrayInit(timerSize, sizeof(void*));
|
|
||||||
if (pThrd->timerList == NULL) {
|
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < timerSize; i++) {
|
|
||||||
uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t));
|
|
||||||
if (timer == NULL) {
|
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end);
|
|
||||||
}
|
|
||||||
(void)uv_timer_init(pThrd->loop, timer);
|
|
||||||
if (taosArrayPush(pThrd->timerList, &timer) == NULL) {
|
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pThrd->pool = createConnPool(4);
|
pThrd->pool = createConnPool(4);
|
||||||
if (pThrd->pool == NULL) {
|
if (pThrd->pool == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
@ -2402,6 +2354,23 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end);
|
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t timerSize = 64;
|
||||||
|
pThrd->timerList = taosArrayInit(timerSize, sizeof(void*));
|
||||||
|
if (pThrd->timerList == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < timerSize; i++) {
|
||||||
|
uv_timer_t* timer = taosMemoryCalloc(1, sizeof(uv_timer_t));
|
||||||
|
if (timer == NULL) {
|
||||||
|
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end);
|
||||||
|
}
|
||||||
|
(void)uv_timer_init(pThrd->loop, timer);
|
||||||
|
if (taosArrayPush(pThrd->timerList, &timer) == NULL) {
|
||||||
|
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _end);
|
||||||
|
}
|
||||||
|
}
|
||||||
pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
pThrd->nextTimeout = taosGetTimestampMs() + CONN_PERSIST_TIME(pTransInst->idleTime);
|
||||||
pThrd->pTransInst = trans;
|
pThrd->pTransInst = trans;
|
||||||
pThrd->quit = false;
|
pThrd->quit = false;
|
||||||
|
@ -2411,17 +2380,22 @@ static int32_t createThrdObj(void* trans, SCliThrd** ppThrd) {
|
||||||
|
|
||||||
_end:
|
_end:
|
||||||
if (pThrd) {
|
if (pThrd) {
|
||||||
|
(void)taosThreadMutexDestroy(&pThrd->msgMtx);
|
||||||
|
|
||||||
(void)uv_loop_close(pThrd->loop);
|
(void)uv_loop_close(pThrd->loop);
|
||||||
taosMemoryFree(pThrd->loop);
|
taosMemoryFree(pThrd->loop);
|
||||||
taosMemoryFree(pThrd->prepare);
|
|
||||||
(void)taosThreadMutexDestroy(&pThrd->msgMtx);
|
|
||||||
transAsyncPoolDestroy(pThrd->asyncPool);
|
transAsyncPoolDestroy(pThrd->asyncPool);
|
||||||
for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) {
|
for (int i = 0; i < taosArrayGetSize(pThrd->timerList); i++) {
|
||||||
uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i);
|
uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i);
|
||||||
|
(void)uv_timer_stop(timer);
|
||||||
taosMemoryFree(timer);
|
taosMemoryFree(timer);
|
||||||
}
|
}
|
||||||
taosArrayDestroy(pThrd->timerList);
|
taosArrayDestroy(pThrd->timerList);
|
||||||
taosMemoryFree(pThrd->prepare);
|
|
||||||
|
(void)destroyConnPool(pThrd);
|
||||||
|
transDQDestroy(pThrd->delayQueue, NULL);
|
||||||
|
transDQDestroy(pThrd->timeoutQueue, NULL);
|
||||||
|
transDQDestroy(pThrd->waitConnQueue, NULL);
|
||||||
taosHashCleanup(pThrd->fqdn2ipCache);
|
taosHashCleanup(pThrd->fqdn2ipCache);
|
||||||
taosHashCleanup(pThrd->failFastCache);
|
taosHashCleanup(pThrd->failFastCache);
|
||||||
taosHashCleanup(pThrd->batchCache);
|
taosHashCleanup(pThrd->batchCache);
|
||||||
|
@ -2450,8 +2424,8 @@ static void destroyThrdObj(SCliThrd* pThrd) {
|
||||||
uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i);
|
uv_timer_t* timer = taosArrayGetP(pThrd->timerList, i);
|
||||||
taosMemoryFree(timer);
|
taosMemoryFree(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroy(pThrd->timerList);
|
taosArrayDestroy(pThrd->timerList);
|
||||||
taosMemoryFree(pThrd->prepare);
|
|
||||||
taosMemoryFree(pThrd->loop);
|
taosMemoryFree(pThrd->loop);
|
||||||
taosHashCleanup(pThrd->fqdn2ipCache);
|
taosHashCleanup(pThrd->fqdn2ipCache);
|
||||||
taosHashCleanup(pThrd->failFastCache);
|
taosHashCleanup(pThrd->failFastCache);
|
||||||
|
@ -2486,7 +2460,7 @@ int32_t cliSendQuit(SCliThrd* thrd) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
SCliMsg* msg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
SCliMsg* msg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
msg->type = Quit;
|
msg->type = Quit;
|
||||||
|
@ -2894,7 +2868,7 @@ int32_t transReleaseCliHandle(void* handle) {
|
||||||
|
|
||||||
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
||||||
if (pCtx == NULL) {
|
if (pCtx == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
pCtx->ahandle = tmsg.info.ahandle;
|
pCtx->ahandle = tmsg.info.ahandle;
|
||||||
|
@ -2902,7 +2876,7 @@ int32_t transReleaseCliHandle(void* handle) {
|
||||||
SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
SCliMsg* cmsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
if (cmsg == NULL) {
|
if (cmsg == NULL) {
|
||||||
taosMemoryFree(pCtx);
|
taosMemoryFree(pCtx);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
cmsg->msg = tmsg;
|
cmsg->msg = tmsg;
|
||||||
cmsg->st = taosGetTimestampUs();
|
cmsg->st = taosGetTimestampUs();
|
||||||
|
@ -2923,7 +2897,7 @@ static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq
|
||||||
if (pReq->info.traceId.msgId == 0) TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64());
|
if (pReq->info.traceId.msgId == 0) TRACE_SET_MSGID(&pReq->info.traceId, tGenIdPI64());
|
||||||
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
||||||
if (pCtx == NULL) {
|
if (pCtx == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
epsetAssign(&pCtx->epSet, pEpSet);
|
epsetAssign(&pCtx->epSet, pEpSet);
|
||||||
|
@ -2937,7 +2911,7 @@ static int32_t transInitMsg(void* shandle, const SEpSet* pEpSet, STransMsg* pReq
|
||||||
SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
if (cliMsg == NULL) {
|
if (cliMsg == NULL) {
|
||||||
taosMemoryFree(pCtx);
|
taosMemoryFree(pCtx);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
cliMsg->ctx = pCtx;
|
cliMsg->ctx = pCtx;
|
||||||
|
@ -3071,7 +3045,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra
|
||||||
|
|
||||||
STransMsg* pTransRsp = taosMemoryCalloc(1, sizeof(STransMsg));
|
STransMsg* pTransRsp = taosMemoryCalloc(1, sizeof(STransMsg));
|
||||||
if (pTransRsp == NULL) {
|
if (pTransRsp == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1);
|
TAOS_CHECK_GOTO(terrno, NULL, _RETURN1);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle);
|
SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle);
|
||||||
|
@ -3081,7 +3055,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra
|
||||||
|
|
||||||
tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t));
|
tsem_t* sem = taosMemoryCalloc(1, sizeof(tsem_t));
|
||||||
if (sem == NULL) {
|
if (sem == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1);
|
TAOS_CHECK_GOTO(terrno, NULL, _RETURN1);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = tsem_init(sem, 0, 0);
|
code = tsem_init(sem, 0, 0);
|
||||||
|
@ -3096,7 +3070,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra
|
||||||
if (pCtx == NULL) {
|
if (pCtx == NULL) {
|
||||||
(void)tsem_destroy(sem);
|
(void)tsem_destroy(sem);
|
||||||
taosMemoryFree(sem);
|
taosMemoryFree(sem);
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1);
|
TAOS_CHECK_GOTO(terrno, NULL, _RETURN1);
|
||||||
}
|
}
|
||||||
|
|
||||||
epsetAssign(&pCtx->epSet, pEpSet);
|
epsetAssign(&pCtx->epSet, pEpSet);
|
||||||
|
@ -3111,7 +3085,7 @@ int32_t transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pReq, STra
|
||||||
(void)tsem_destroy(sem);
|
(void)tsem_destroy(sem);
|
||||||
taosMemoryFree(sem);
|
taosMemoryFree(sem);
|
||||||
taosMemoryFree(pCtx);
|
taosMemoryFree(pCtx);
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN1);
|
TAOS_CHECK_GOTO(terrno, NULL, _RETURN1);
|
||||||
}
|
}
|
||||||
|
|
||||||
cliMsg->ctx = pCtx;
|
cliMsg->ctx = pCtx;
|
||||||
|
@ -3150,7 +3124,7 @@ int32_t transCreateSyncMsg(STransMsg* pTransMsg, int64_t* refId) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
tsem2_t* sem = taosMemoryCalloc(1, sizeof(tsem2_t));
|
tsem2_t* sem = taosMemoryCalloc(1, sizeof(tsem2_t));
|
||||||
if (sem == NULL) {
|
if (sem == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsem2_init(sem, 0, 0) != 0) {
|
if (tsem2_init(sem, 0, 0) != 0) {
|
||||||
|
@ -3159,7 +3133,7 @@ int32_t transCreateSyncMsg(STransMsg* pTransMsg, int64_t* refId) {
|
||||||
|
|
||||||
STransSyncMsg* pSyncMsg = taosMemoryCalloc(1, sizeof(STransSyncMsg));
|
STransSyncMsg* pSyncMsg = taosMemoryCalloc(1, sizeof(STransSyncMsg));
|
||||||
if (pSyncMsg == NULL) {
|
if (pSyncMsg == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _EXIT);
|
TAOS_CHECK_GOTO(terrno, NULL, _EXIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosInitRWLatch(&pSyncMsg->latch);
|
taosInitRWLatch(&pSyncMsg->latch);
|
||||||
|
@ -3194,7 +3168,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq,
|
||||||
|
|
||||||
STransMsg* pTransMsg = taosMemoryCalloc(1, sizeof(STransMsg));
|
STransMsg* pTransMsg = taosMemoryCalloc(1, sizeof(STransMsg));
|
||||||
if (pTransMsg == NULL) {
|
if (pTransMsg == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2);
|
TAOS_CHECK_GOTO(terrno, NULL, _RETURN2);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle);
|
SCliThrd* pThrd = transGetWorkThrd(pTransInst, (int64_t)pReq->info.handle);
|
||||||
|
@ -3206,7 +3180,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq,
|
||||||
|
|
||||||
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
||||||
if (pCtx == NULL) {
|
if (pCtx == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2);
|
TAOS_CHECK_GOTO(terrno, NULL, _RETURN2);
|
||||||
}
|
}
|
||||||
|
|
||||||
epsetAssign(&pCtx->epSet, pEpSet);
|
epsetAssign(&pCtx->epSet, pEpSet);
|
||||||
|
@ -3229,7 +3203,7 @@ int32_t transSendRecvWithTimeout(void* shandle, SEpSet* pEpSet, STransMsg* pReq,
|
||||||
SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
if (cliMsg == NULL) {
|
if (cliMsg == NULL) {
|
||||||
taosMemoryFree(pCtx);
|
taosMemoryFree(pCtx);
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _RETURN2);
|
TAOS_CHECK_GOTO(terrno, NULL, _RETURN2);
|
||||||
}
|
}
|
||||||
|
|
||||||
cliMsg->ctx = pCtx;
|
cliMsg->ctx = pCtx;
|
||||||
|
@ -3294,7 +3268,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) {
|
||||||
for (int8_t i = 0; i < pTransInst->numOfThreads; i++) {
|
for (int8_t i = 0; i < pTransInst->numOfThreads; i++) {
|
||||||
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
STransConnCtx* pCtx = taosMemoryCalloc(1, sizeof(STransConnCtx));
|
||||||
if (pCtx == NULL) {
|
if (pCtx == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3303,7 +3277,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) {
|
||||||
SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
SCliMsg* cliMsg = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
if (cliMsg == NULL) {
|
if (cliMsg == NULL) {
|
||||||
taosMemoryFree(pCtx);
|
taosMemoryFree(pCtx);
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3330,7 +3304,7 @@ int32_t transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn) {
|
||||||
int32_t transAllocHandle(int64_t* refId) {
|
int32_t transAllocHandle(int64_t* refId) {
|
||||||
SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle));
|
SExHandle* exh = taosMemoryCalloc(1, sizeof(SExHandle));
|
||||||
if (exh == NULL) {
|
if (exh == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
exh->refId = transAddExHandle(transGetRefMgt(), exh);
|
exh->refId = transAddExHandle(transGetRefMgt(), exh);
|
||||||
|
@ -3369,7 +3343,7 @@ int32_t transFreeConnById(void* shandle, int64_t transpointId) {
|
||||||
|
|
||||||
SCliMsg* pCli = taosMemoryCalloc(1, sizeof(SCliMsg));
|
SCliMsg* pCli = taosMemoryCalloc(1, sizeof(SCliMsg));
|
||||||
if (pCli == NULL) {
|
if (pCli == NULL) {
|
||||||
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception);
|
TAOS_CHECK_GOTO(terrno, NULL, _exception);
|
||||||
}
|
}
|
||||||
pCli->type = FreeById;
|
pCli->type = FreeById;
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@ int32_t transDecompressMsg(char** msg, int32_t len) {
|
||||||
|
|
||||||
char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead));
|
char* buf = taosMemoryCalloc(1, oriLen + sizeof(STransMsgHead));
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
STransMsgHead* pNewHead = (STransMsgHead*)buf;
|
STransMsgHead* pNewHead = (STransMsgHead*)buf;
|
||||||
|
@ -106,7 +106,7 @@ int transSockInfo2Str(struct sockaddr* sockname, char* dst) {
|
||||||
int32_t transInitBuffer(SConnBuffer* buf) {
|
int32_t transInitBuffer(SConnBuffer* buf) {
|
||||||
buf->buf = taosMemoryCalloc(1, BUFFER_CAP);
|
buf->buf = taosMemoryCalloc(1, BUFFER_CAP);
|
||||||
if (buf->buf == NULL) {
|
if (buf->buf == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf->cap = BUFFER_CAP;
|
buf->cap = BUFFER_CAP;
|
||||||
|
@ -149,7 +149,7 @@ int32_t transDumpFromBuffer(SConnBuffer* connBuf, char** buf, int8_t resetBuf) {
|
||||||
if (total >= HEADSIZE && !p->invalid) {
|
if (total >= HEADSIZE && !p->invalid) {
|
||||||
*buf = taosMemoryCalloc(1, total);
|
*buf = taosMemoryCalloc(1, total);
|
||||||
if (*buf == NULL) {
|
if (*buf == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
memcpy(*buf, p->buf, total);
|
memcpy(*buf, p->buf, total);
|
||||||
if ((code = transResetBuffer(connBuf, resetBuf)) < 0) {
|
if ((code = transResetBuffer(connBuf, resetBuf)) < 0) {
|
||||||
|
@ -249,7 +249,7 @@ int32_t transSetConnOption(uv_tcp_t* stream, int keepalive) {
|
||||||
int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAsyncPool** pPool) {
|
int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAsyncPool** pPool) {
|
||||||
SAsyncPool* pool = taosMemoryCalloc(1, sizeof(SAsyncPool));
|
SAsyncPool* pool = taosMemoryCalloc(1, sizeof(SAsyncPool));
|
||||||
if (pool == NULL) {
|
if (pool == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
// return NULL;
|
// return NULL;
|
||||||
}
|
}
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -258,7 +258,7 @@ int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAs
|
||||||
pool->asyncs = taosMemoryCalloc(1, sizeof(uv_async_t) * pool->nAsync);
|
pool->asyncs = taosMemoryCalloc(1, sizeof(uv_async_t) * pool->nAsync);
|
||||||
if (pool->asyncs == NULL) {
|
if (pool->asyncs == NULL) {
|
||||||
taosMemoryFree(pool);
|
taosMemoryFree(pool);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0, err = 0;
|
int i = 0, err = 0;
|
||||||
|
@ -267,7 +267,7 @@ int32_t transAsyncPoolCreate(uv_loop_t* loop, int sz, void* arg, AsyncCB cb, SAs
|
||||||
|
|
||||||
SAsyncItem* item = taosMemoryCalloc(1, sizeof(SAsyncItem));
|
SAsyncItem* item = taosMemoryCalloc(1, sizeof(SAsyncItem));
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
item->pThrd = arg;
|
item->pThrd = arg;
|
||||||
|
@ -560,7 +560,7 @@ int32_t transDQCreate(uv_loop_t* loop, SDelayQueue** queue) {
|
||||||
|
|
||||||
timer = taosMemoryCalloc(1, sizeof(uv_timer_t));
|
timer = taosMemoryCalloc(1, sizeof(uv_timer_t));
|
||||||
if (timer == NULL) {
|
if (timer == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
heap = heapCreate(timeCompare);
|
heap = heapCreate(timeCompare);
|
||||||
|
@ -852,7 +852,7 @@ int32_t transUtilSWhiteListToStr(SIpWhiteList* pList, char** ppBuf) {
|
||||||
int32_t len = 0;
|
int32_t len = 0;
|
||||||
char* pBuf = taosMemoryCalloc(1, pList->num * 36);
|
char* pBuf = taosMemoryCalloc(1, pList->num * 36);
|
||||||
if (pBuf == NULL) {
|
if (pBuf == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < pList->num; i++) {
|
for (int i = 0; i < pList->num; i++) {
|
||||||
|
|
|
@ -88,7 +88,6 @@ typedef struct SWorkThrd {
|
||||||
uv_os_fd_t fd;
|
uv_os_fd_t fd;
|
||||||
uv_loop_t* loop;
|
uv_loop_t* loop;
|
||||||
SAsyncPool* asyncPool;
|
SAsyncPool* asyncPool;
|
||||||
uv_prepare_t* prepare;
|
|
||||||
queue msg;
|
queue msg;
|
||||||
|
|
||||||
queue conn;
|
queue conn;
|
||||||
|
@ -98,6 +97,7 @@ typedef struct SWorkThrd {
|
||||||
SIpWhiteListTab* pWhiteList;
|
SIpWhiteListTab* pWhiteList;
|
||||||
int64_t whiteListVer;
|
int64_t whiteListVer;
|
||||||
int8_t enableIpWhiteList;
|
int8_t enableIpWhiteList;
|
||||||
|
int8_t inited;
|
||||||
} SWorkThrd;
|
} SWorkThrd;
|
||||||
|
|
||||||
typedef struct SServerObj {
|
typedef struct SServerObj {
|
||||||
|
@ -139,7 +139,6 @@ static void uvOnConnectionCb(uv_stream_t* q, ssize_t nread, const uv_buf_t* buf)
|
||||||
static void uvWorkerAsyncCb(uv_async_t* handle);
|
static void uvWorkerAsyncCb(uv_async_t* handle);
|
||||||
static void uvAcceptAsyncCb(uv_async_t* handle);
|
static void uvAcceptAsyncCb(uv_async_t* handle);
|
||||||
static void uvShutDownCb(uv_shutdown_t* req, int status);
|
static void uvShutDownCb(uv_shutdown_t* req, int status);
|
||||||
static void uvPrepareCb(uv_prepare_t* handle);
|
|
||||||
|
|
||||||
static bool uvRecvReleaseReq(SSvrConn* conn, STransMsgHead* pHead);
|
static bool uvRecvReleaseReq(SSvrConn* conn, STransMsgHead* pHead);
|
||||||
|
|
||||||
|
@ -180,6 +179,11 @@ static void uvDestroyConn(uv_handle_t* handle);
|
||||||
static void* transWorkerThread(void* arg);
|
static void* transWorkerThread(void* arg);
|
||||||
static void* transAcceptThread(void* arg);
|
static void* transAcceptThread(void* arg);
|
||||||
|
|
||||||
|
static void destroyWorkThrd(SWorkThrd* pThrd);
|
||||||
|
static void destroyWorkThrdObj(SWorkThrd* pThrd);
|
||||||
|
|
||||||
|
static void sendQuitToWorkThrd(SWorkThrd* pThrd);
|
||||||
|
|
||||||
// add handle loop
|
// add handle loop
|
||||||
static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName);
|
static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName);
|
||||||
static int32_t addHandleToAcceptloop(void* arg);
|
static int32_t addHandleToAcceptloop(void* arg);
|
||||||
|
@ -260,7 +264,7 @@ int32_t uvWhiteListToStr(SWhiteUserList* plist, char* user, char** ppBuf) {
|
||||||
|
|
||||||
char* pBuf = taosMemoryCalloc(1, tlen + 64);
|
char* pBuf = taosMemoryCalloc(1, tlen + 64);
|
||||||
if (pBuf == NULL) {
|
if (pBuf == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t len = sprintf(pBuf, "user: %s, ver: %" PRId64 ", ip: {%s}", user, plist->ver, tmp);
|
int32_t len = sprintf(pBuf, "user: %s, ver: %" PRId64 ", ip: {%s}", user, plist->ver, tmp);
|
||||||
|
@ -299,7 +303,7 @@ int32_t uvWhiteListAdd(SIpWhiteListTab* pWhite, char* user, SIpWhiteList* plist,
|
||||||
if (ppUserList == NULL || *ppUserList == NULL) {
|
if (ppUserList == NULL || *ppUserList == NULL) {
|
||||||
SWhiteUserList* pUserList = taosMemoryCalloc(1, sizeof(SWhiteUserList));
|
SWhiteUserList* pUserList = taosMemoryCalloc(1, sizeof(SWhiteUserList));
|
||||||
if (pUserList == NULL) {
|
if (pUserList == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
pUserList->ver = ver;
|
pUserList->ver = ver;
|
||||||
|
@ -849,52 +853,6 @@ static bool uvRecvReleaseReq(SSvrConn* pConn, STransMsgHead* pHead) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static void uvPrepareCb(uv_prepare_t* handle) {
|
|
||||||
// prepare callback
|
|
||||||
SWorkThrd* pThrd = handle->data;
|
|
||||||
SAsyncPool* pool = pThrd->asyncPool;
|
|
||||||
|
|
||||||
for (int i = 0; i < pool->nAsync; i++) {
|
|
||||||
uv_async_t* async = &(pool->asyncs[i]);
|
|
||||||
SAsyncItem* item = async->data;
|
|
||||||
|
|
||||||
queue wq;
|
|
||||||
(void)taosThreadMutexLock(&item->mtx);
|
|
||||||
QUEUE_MOVE(&item->qmsg, &wq);
|
|
||||||
(void)taosThreadMutexUnlock(&item->mtx);
|
|
||||||
|
|
||||||
while (!QUEUE_IS_EMPTY(&wq)) {
|
|
||||||
queue* head = QUEUE_HEAD(&wq);
|
|
||||||
QUEUE_REMOVE(head);
|
|
||||||
|
|
||||||
SSvrMsg* msg = QUEUE_DATA(head, SSvrMsg, q);
|
|
||||||
if (msg == NULL) {
|
|
||||||
tError("unexcept occurred, continue");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// release handle to rpc init
|
|
||||||
if (msg->type == Quit || msg->type == Update) {
|
|
||||||
(*transAsyncHandle[msg->type])(msg, pThrd);
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
STransMsg transMsg = msg->msg;
|
|
||||||
|
|
||||||
SExHandle* exh1 = transMsg.info.handle;
|
|
||||||
int64_t refId = transMsg.info.refId;
|
|
||||||
SExHandle* exh2 = transAcquireExHandle(transGetSvrRefMgt(), refId);
|
|
||||||
if (exh2 == NULL || exh1 != exh2) {
|
|
||||||
tTrace("handle except msg %p, ignore it", exh1);
|
|
||||||
(void)transReleaseExHandle(transGetSvrRefMgt(), refId);
|
|
||||||
destroySmsg(msg);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
msg->pConn = exh1->handle;
|
|
||||||
(void)transReleaseExHandle(transGetSvrRefMgt(), refId);
|
|
||||||
(*transAsyncHandle[msg->type])(msg, pThrd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uvWorkDoTask(uv_work_t* req) {
|
static void uvWorkDoTask(uv_work_t* req) {
|
||||||
// doing time-consumeing task
|
// doing time-consumeing task
|
||||||
|
@ -1101,25 +1059,6 @@ static int32_t addHandleToWorkloop(SWorkThrd* pThrd, char* pipeName) {
|
||||||
|
|
||||||
QUEUE_INIT(&pThrd->msg);
|
QUEUE_INIT(&pThrd->msg);
|
||||||
|
|
||||||
pThrd->prepare = taosMemoryCalloc(1, sizeof(uv_prepare_t));
|
|
||||||
if (pThrd->prepare == NULL) {
|
|
||||||
tError("failed to init prepare");
|
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = uv_prepare_init(pThrd->loop, pThrd->prepare);
|
|
||||||
if (code != 0) {
|
|
||||||
tError("failed to init prepare since %s", uv_err_name(code));
|
|
||||||
return TSDB_CODE_THIRDPARTY_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = uv_prepare_start(pThrd->prepare, uvPrepareCb);
|
|
||||||
if (code != 0) {
|
|
||||||
tError("failed to start prepare since %s", uv_err_name(code));
|
|
||||||
return TSDB_CODE_THIRDPARTY_ERROR;
|
|
||||||
}
|
|
||||||
pThrd->prepare->data = pThrd;
|
|
||||||
|
|
||||||
// conn set
|
// conn set
|
||||||
QUEUE_INIT(&pThrd->conn);
|
QUEUE_INIT(&pThrd->conn);
|
||||||
|
|
||||||
|
@ -1155,7 +1094,7 @@ static int32_t addHandleToAcceptloop(void* arg) {
|
||||||
srv->pAcceptAsync = taosMemoryCalloc(1, sizeof(uv_async_t));
|
srv->pAcceptAsync = taosMemoryCalloc(1, sizeof(uv_async_t));
|
||||||
if (srv->pAcceptAsync == NULL) {
|
if (srv->pAcceptAsync == NULL) {
|
||||||
tError("failed to create async since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
tError("failed to create async since %s", tstrerror(TSDB_CODE_OUT_OF_MEMORY));
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = uv_async_init(srv->loop, srv->pAcceptAsync, uvAcceptAsyncCb);
|
code = uv_async_init(srv->loop, srv->pAcceptAsync, uvAcceptAsyncCb);
|
||||||
|
@ -1459,10 +1398,21 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
thrd->quit = false;
|
thrd->quit = false;
|
||||||
thrd->pTransInst = shandle;
|
thrd->pTransInst = shandle;
|
||||||
thrd->pWhiteList = uvWhiteListCreate();
|
thrd->pWhiteList = uvWhiteListCreate();
|
||||||
|
if (thrd->pWhiteList == NULL) {
|
||||||
|
destroyWorkThrdObj(thrd);
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto End;
|
||||||
|
}
|
||||||
|
|
||||||
srv->pThreadObj[i] = thrd;
|
|
||||||
srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t));
|
srv->pipe[i] = (uv_pipe_t*)taosMemoryCalloc(2, sizeof(uv_pipe_t));
|
||||||
|
if (srv->pipe[i] == NULL) {
|
||||||
|
destroyWorkThrdObj(thrd);
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto End;
|
||||||
|
}
|
||||||
|
|
||||||
thrd->pipe = &(srv->pipe[i][1]); // init read
|
thrd->pipe = &(srv->pipe[i][1]); // init read
|
||||||
|
srv->pThreadObj[i] = thrd;
|
||||||
|
|
||||||
if ((code = addHandleToWorkloop(thrd, pipeName)) != 0) {
|
if ((code = addHandleToWorkloop(thrd, pipeName)) != 0) {
|
||||||
goto End;
|
goto End;
|
||||||
|
@ -1476,6 +1426,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
tError("failed to create worker-thread:%d", i);
|
tError("failed to create worker-thread:%d", i);
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
|
thrd->inited = 1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
@ -1485,12 +1436,14 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
|
srv->pThreadObj[i] = thrd;
|
||||||
|
|
||||||
thrd->pTransInst = shandle;
|
thrd->pTransInst = shandle;
|
||||||
thrd->quit = false;
|
thrd->quit = false;
|
||||||
thrd->pTransInst = shandle;
|
thrd->pTransInst = shandle;
|
||||||
thrd->pWhiteList = uvWhiteListCreate();
|
thrd->pWhiteList = uvWhiteListCreate();
|
||||||
if (thrd->pWhiteList == NULL) {
|
if (thrd->pWhiteList == NULL) {
|
||||||
|
destroyWorkThrdObj(thrd);
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
|
@ -1501,8 +1454,6 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
|
|
||||||
srv->pThreadObj[i] = thrd;
|
|
||||||
|
|
||||||
uv_os_sock_t fds[2];
|
uv_os_sock_t fds[2];
|
||||||
if ((code = uv_socketpair(SOCK_STREAM, 0, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE)) != 0) {
|
if ((code = uv_socketpair(SOCK_STREAM, 0, fds, UV_NONBLOCK_PIPE, UV_NONBLOCK_PIPE)) != 0) {
|
||||||
tError("failed to create pipe, errmsg: %s", uv_err_name(code));
|
tError("failed to create pipe, errmsg: %s", uv_err_name(code));
|
||||||
|
@ -1539,6 +1490,7 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
tError("failed to create worker-thread:%d", i);
|
tError("failed to create worker-thread:%d", i);
|
||||||
goto End;
|
goto End;
|
||||||
}
|
}
|
||||||
|
thrd->inited = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1560,6 +1512,12 @@ void* transInitServer(uint32_t ip, uint32_t port, char* label, int numOfThreads,
|
||||||
srv->inited = true;
|
srv->inited = true;
|
||||||
return srv;
|
return srv;
|
||||||
End:
|
End:
|
||||||
|
for (int i = 0; i < srv->numOfThreads; i++) {
|
||||||
|
if (srv->pThreadObj[i] != NULL) {
|
||||||
|
SWorkThrd* thrd = srv->pThreadObj[i];
|
||||||
|
destroyWorkThrd(thrd);
|
||||||
|
}
|
||||||
|
}
|
||||||
transCloseServer(srv);
|
transCloseServer(srv);
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1663,20 +1621,26 @@ void uvHandleUpdate(SSvrMsg* msg, SWorkThrd* thrd) {
|
||||||
taosMemoryFree(msg);
|
taosMemoryFree(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void destroyWorkThrdObj(SWorkThrd* pThrd) {
|
||||||
|
if (pThrd == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
transAsyncPoolDestroy(pThrd->asyncPool);
|
||||||
|
uvWhiteListDestroy(pThrd->pWhiteList);
|
||||||
|
taosMemoryFree(pThrd->loop);
|
||||||
|
taosMemoryFree(pThrd);
|
||||||
|
}
|
||||||
void destroyWorkThrd(SWorkThrd* pThrd) {
|
void destroyWorkThrd(SWorkThrd* pThrd) {
|
||||||
if (pThrd == NULL) {
|
if (pThrd == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (pThrd->inited) {
|
||||||
|
sendQuitToWorkThrd(pThrd);
|
||||||
(void)taosThreadJoin(pThrd->thread, NULL);
|
(void)taosThreadJoin(pThrd->thread, NULL);
|
||||||
SRV_RELEASE_UV(pThrd->loop);
|
SRV_RELEASE_UV(pThrd->loop);
|
||||||
TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrMsg, destroySmsgWrapper, NULL);
|
TRANS_DESTROY_ASYNC_POOL_MSG(pThrd->asyncPool, SSvrMsg, destroySmsgWrapper, NULL);
|
||||||
transAsyncPoolDestroy(pThrd->asyncPool);
|
}
|
||||||
|
destroyWorkThrdObj(pThrd);
|
||||||
uvWhiteListDestroy(pThrd->pWhiteList);
|
|
||||||
|
|
||||||
taosMemoryFree(pThrd->prepare);
|
|
||||||
taosMemoryFree(pThrd->loop);
|
|
||||||
taosMemoryFree(pThrd);
|
|
||||||
}
|
}
|
||||||
void sendQuitToWorkThrd(SWorkThrd* pThrd) {
|
void sendQuitToWorkThrd(SWorkThrd* pThrd) {
|
||||||
SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
||||||
|
@ -1693,14 +1657,13 @@ void transCloseServer(void* arg) {
|
||||||
tDebug("send quit msg to accept thread");
|
tDebug("send quit msg to accept thread");
|
||||||
(void)uv_async_send(srv->pAcceptAsync);
|
(void)uv_async_send(srv->pAcceptAsync);
|
||||||
(void)taosThreadJoin(srv->thread, NULL);
|
(void)taosThreadJoin(srv->thread, NULL);
|
||||||
SRV_RELEASE_UV(srv->loop);
|
|
||||||
|
|
||||||
|
SRV_RELEASE_UV(srv->loop);
|
||||||
for (int i = 0; i < srv->numOfThreads; i++) {
|
for (int i = 0; i < srv->numOfThreads; i++) {
|
||||||
sendQuitToWorkThrd(srv->pThreadObj[i]);
|
|
||||||
destroyWorkThrd(srv->pThreadObj[i]);
|
destroyWorkThrd(srv->pThreadObj[i]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
(void)uv_loop_close(srv->loop);
|
SRV_RELEASE_UV(srv->loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosMemoryFree(srv->pThreadObj);
|
taosMemoryFree(srv->pThreadObj);
|
||||||
|
@ -1708,8 +1671,10 @@ void transCloseServer(void* arg) {
|
||||||
taosMemoryFree(srv->loop);
|
taosMemoryFree(srv->loop);
|
||||||
|
|
||||||
for (int i = 0; i < srv->numOfThreads; i++) {
|
for (int i = 0; i < srv->numOfThreads; i++) {
|
||||||
|
if (srv->pipe[i] != NULL) {
|
||||||
taosMemoryFree(srv->pipe[i]);
|
taosMemoryFree(srv->pipe[i]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
taosMemoryFree(srv->pipe);
|
taosMemoryFree(srv->pipe);
|
||||||
|
|
||||||
taosMemoryFree(srv);
|
taosMemoryFree(srv);
|
||||||
|
@ -1749,7 +1714,7 @@ int32_t transReleaseSrvHandle(void* handle) {
|
||||||
|
|
||||||
SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
||||||
if (m == NULL) {
|
if (m == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
goto _return1;
|
goto _return1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1799,7 +1764,7 @@ int32_t transSendResponse(const STransMsg* msg) {
|
||||||
|
|
||||||
SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
||||||
if (m == NULL) {
|
if (m == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
goto _return1;
|
goto _return1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1844,7 +1809,7 @@ int32_t transRegisterMsg(const STransMsg* msg) {
|
||||||
|
|
||||||
SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
SSvrMsg* m = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
||||||
if (m == NULL) {
|
if (m == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
goto _return1;
|
goto _return1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1888,7 +1853,7 @@ int32_t transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) {
|
||||||
|
|
||||||
SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
||||||
if (msg == NULL) {
|
if (msg == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
|
wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
|
||||||
*lastVer = retVer;
|
*lastVer = retVer;
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure size as non-negative
|
// ensure size as non-negative
|
||||||
|
@ -106,13 +106,13 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in
|
||||||
int64_t ret = taosLSeekFile(pFile, offset, SEEK_SET);
|
int64_t ret = taosLSeekFile(pFile, offset, SEEK_SET);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(errno), offset);
|
wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(errno), offset);
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (readSize != taosReadFile(pFile, buf, readSize)) {
|
if (readSize != taosReadFile(pFile, buf, readSize)) {
|
||||||
wError("vgId:%d, failed to read file due to %s. readSize:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno),
|
wError("vgId:%d, failed to read file due to %s. readSize:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno),
|
||||||
readSize, fnameStr);
|
readSize, fnameStr);
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* candidate = NULL;
|
char* candidate = NULL;
|
||||||
|
@ -169,15 +169,15 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in
|
||||||
}
|
}
|
||||||
int64_t ret = taosLSeekFile(pFile, offset + readSize, SEEK_SET);
|
int64_t ret = taosLSeekFile(pFile, offset + readSize, SEEK_SET);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(errno),
|
wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(terrno),
|
||||||
offset);
|
offset);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (extraSize != taosReadFile(pFile, buf + readSize, extraSize)) {
|
if (extraSize != taosReadFile(pFile, buf + readSize, extraSize)) {
|
||||||
wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", extraSize:%" PRId64 ", file:%s",
|
wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", extraSize:%" PRId64 ", file:%s",
|
||||||
pWal->cfg.vgId, strerror(errno), offset + readSize, extraSize, fnameStr);
|
pWal->cfg.vgId, strerror(errno), offset + readSize, extraSize, fnameStr);
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,8 +223,8 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in
|
||||||
lastEntryEndOffset, fileSize);
|
lastEntryEndOffset, fileSize);
|
||||||
|
|
||||||
if (taosFtruncateFile(pFile, lastEntryEndOffset) < 0) {
|
if (taosFtruncateFile(pFile, lastEntryEndOffset) < 0) {
|
||||||
wError("failed to truncate file due to %s. file:%s", strerror(errno), fnameStr);
|
wError("failed to truncate file due to %s. file:%s", strerror(terrno), fnameStr);
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pFile) < 0) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pFile) < 0) {
|
||||||
|
@ -315,7 +315,7 @@ static int32_t walRepairLogFileTs(SWal* pWal, bool* updateMeta) {
|
||||||
if (taosStatFile(fnameStr, NULL, &mtime, NULL) < 0) {
|
if (taosStatFile(fnameStr, NULL, &mtime, NULL) < 0) {
|
||||||
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);
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateMeta != NULL) *updateMeta = true;
|
if (updateMeta != NULL) *updateMeta = true;
|
||||||
|
@ -375,7 +375,7 @@ static int32_t walTrimIdxFile(SWal* pWal, int32_t fileIdx) {
|
||||||
|
|
||||||
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) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
wInfo("vgId:%d, trim idx file. file: %s, size: %" PRId64 ", offset: %" PRId64, pWal->cfg.vgId, fnameStr, fileSize,
|
wInfo("vgId:%d, trim idx file. file: %s, size: %" PRId64 ", offset: %" PRId64, pWal->cfg.vgId, fnameStr, fileSize,
|
||||||
|
@ -403,7 +403,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
|
||||||
regfree(&logRegPattern);
|
regfree(&logRegPattern);
|
||||||
regfree(&idxRegPattern);
|
regfree(&idxRegPattern);
|
||||||
wError("vgId:%d, path:%s, failed to open since %s", pWal->cfg.vgId, pWal->path, strerror(errno));
|
wError("vgId:%d, path:%s, failed to open since %s", pWal->cfg.vgId, pWal->path, strerror(errno));
|
||||||
TAOS_RETURN(TSDB_CODE_FAILED);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray* actualLog = taosArrayInit(8, sizeof(SWalFileInfo));
|
SArray* actualLog = taosArrayInit(8, sizeof(SWalFileInfo));
|
||||||
|
@ -422,7 +422,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
|
||||||
regfree(&idxRegPattern);
|
regfree(&idxRegPattern);
|
||||||
(void)taosCloseDir(&pDir);
|
(void)taosCloseDir(&pDir);
|
||||||
|
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
return terrno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,7 +462,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
wError("failed to stat file since %s. file:%s", terrstr(), fnameStr);
|
wError("failed to stat file since %s. file:%s", terrstr(), fnameStr);
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pFileInfo->lastVer >= pFileInfo->firstVer && fileSize == pFileInfo->fileSize) {
|
if (pFileInfo->lastVer >= pFileInfo->firstVer && fileSize == pFileInfo->fileSize) {
|
||||||
|
@ -518,11 +518,11 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
|
||||||
|
|
||||||
static int32_t walReadLogHead(TdFilePtr pLogFile, int64_t offset, SWalCkHead* pCkHead) {
|
static int32_t walReadLogHead(TdFilePtr pLogFile, int64_t offset, SWalCkHead* pCkHead) {
|
||||||
if (taosLSeekFile(pLogFile, offset, SEEK_SET) < 0) {
|
if (taosLSeekFile(pLogFile, offset, SEEK_SET) < 0) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pLogFile, pCkHead, sizeof(SWalCkHead)) != sizeof(SWalCkHead)) {
|
if (taosReadFile(pLogFile, pCkHead, sizeof(SWalCkHead)) != sizeof(SWalCkHead)) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (walValidHeadCksum(pCkHead) != 0) {
|
if (walValidHeadCksum(pCkHead) != 0) {
|
||||||
|
@ -545,7 +545,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
|
||||||
if (taosStatFile(fnameStr, &fileSize, NULL, 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);
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fileSize == (pFileInfo->lastVer - pFileInfo->firstVer + 1) * sizeof(SWalIdxEntry)) {
|
if (fileSize == (pFileInfo->lastVer - pFileInfo->firstVer + 1) * sizeof(SWalIdxEntry)) {
|
||||||
|
@ -565,30 +565,30 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
|
||||||
if (pIdxFile == NULL) {
|
if (pIdxFile == NULL) {
|
||||||
wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
|
wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
pLogFile = taosOpenFile(fLogNameStr, TD_FILE_READ);
|
pLogFile = taosOpenFile(fLogNameStr, TD_FILE_READ);
|
||||||
if (pLogFile == NULL) {
|
if (pLogFile == NULL) {
|
||||||
wError("vgId:%d, cannot open file %s, since %s", pWal->cfg.vgId, fLogNameStr, terrstr());
|
wError("vgId:%d, cannot open file %s, since %s", pWal->cfg.vgId, fLogNameStr, terrstr());
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine the last valid entry end, i.e. offset
|
// determine the last valid entry end, i.e. offset
|
||||||
while ((offset -= sizeof(SWalIdxEntry)) >= 0) {
|
while ((offset -= sizeof(SWalIdxEntry)) >= 0) {
|
||||||
if (taosLSeekFile(pIdxFile, offset, SEEK_SET) < 0) {
|
if (taosLSeekFile(pIdxFile, offset, SEEK_SET) < 0) {
|
||||||
wError("vgId:%d, failed to seek file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno),
|
wError("vgId:%d, failed to seek file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(terrno),
|
||||||
offset, fnameStr);
|
offset, fnameStr);
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) {
|
if (taosReadFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) {
|
||||||
wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno),
|
wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(terrno),
|
||||||
offset, fnameStr);
|
offset, fnameStr);
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (idxEntry.ver > pFileInfo->lastVer) {
|
if (idxEntry.ver > pFileInfo->lastVer) {
|
||||||
|
@ -619,7 +619,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
|
||||||
wError("vgId:%d, failed to ftruncate file since %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, terrstr(),
|
wError("vgId:%d, failed to ftruncate file since %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, terrstr(),
|
||||||
offset, fnameStr);
|
offset, fnameStr);
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,7 +628,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
|
||||||
wError("vgId:%d, failed to seek file since %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, terrstr(), offset,
|
wError("vgId:%d, failed to seek file since %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, terrstr(), offset,
|
||||||
fnameStr);
|
fnameStr);
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t count = 0;
|
int64_t count = 0;
|
||||||
|
@ -654,7 +654,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && taosWriteFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) < 0) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && taosWriteFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) < 0) {
|
||||||
wError("vgId:%d, failed to append file since %s. file:%s", pWal->cfg.vgId, terrstr(), fnameStr);
|
wError("vgId:%d, failed to append file since %s. file:%s", pWal->cfg.vgId, terrstr(), fnameStr);
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
@ -941,7 +941,7 @@ int32_t walSaveMeta(SWal* pWal) {
|
||||||
if (pMetaFile == NULL) {
|
if (pMetaFile == NULL) {
|
||||||
wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
char* serialized = NULL;
|
char* serialized = NULL;
|
||||||
|
@ -950,7 +950,7 @@ int32_t walSaveMeta(SWal* pWal) {
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && len != taosWriteFile(pMetaFile, serialized, len)) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && len != taosWriteFile(pMetaFile, serialized, len)) {
|
||||||
wError("vgId:%d, failed to write file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
wError("vgId:%d, failed to write file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr);
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
|
TAOS_CHECK_GOTO(terrno, &lino, _err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pMetaFile) < 0) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pMetaFile) < 0) {
|
||||||
|
@ -1028,7 +1028,7 @@ int32_t walLoadMeta(SWal* pWal) {
|
||||||
(void)taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
taosMemoryFree(buf);
|
taosMemoryFree(buf);
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
// load into fileInfoSet
|
// load into fileInfoSet
|
||||||
code = walMetaDeserialize(pWal, buf);
|
code = walMetaDeserialize(pWal, buf);
|
||||||
|
|
|
@ -137,14 +137,14 @@ static int32_t walReadSeekFilePos(SWalReader *pReader, int64_t fileFirstVer, int
|
||||||
wError("vgId:%d, failed to seek idx file, index:%" PRId64 ", pos:%" PRId64 ", since %s", pReader->pWal->cfg.vgId,
|
wError("vgId:%d, failed to seek idx file, index:%" PRId64 ", pos:%" PRId64 ", since %s", pReader->pWal->cfg.vgId,
|
||||||
ver, offset, terrstr());
|
ver, offset, terrstr());
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
SWalIdxEntry entry = {0};
|
SWalIdxEntry entry = {0};
|
||||||
if ((ret = taosReadFile(pIdxTFile, &entry, sizeof(SWalIdxEntry))) != sizeof(SWalIdxEntry)) {
|
if ((ret = taosReadFile(pIdxTFile, &entry, sizeof(SWalIdxEntry))) != sizeof(SWalIdxEntry)) {
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
wError("vgId:%d, failed to read idx file, since %s", pReader->pWal->cfg.vgId, terrstr());
|
wError("vgId:%d, failed to read idx file, since %s", pReader->pWal->cfg.vgId, terrstr());
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
} else {
|
} else {
|
||||||
wError("vgId:%d, read idx file incompletely, read bytes %" PRId64 ", bytes should be %ld",
|
wError("vgId:%d, read idx file incompletely, read bytes %" PRId64 ", bytes should be %ld",
|
||||||
pReader->pWal->cfg.vgId, ret, sizeof(SWalIdxEntry));
|
pReader->pWal->cfg.vgId, ret, sizeof(SWalIdxEntry));
|
||||||
|
@ -158,7 +158,7 @@ static int32_t walReadSeekFilePos(SWalReader *pReader, int64_t fileFirstVer, int
|
||||||
wError("vgId:%d, failed to seek log file, index:%" PRId64 ", pos:%" PRId64 ", since %s", pReader->pWal->cfg.vgId,
|
wError("vgId:%d, failed to seek log file, index:%" PRId64 ", pos:%" PRId64 ", since %s", pReader->pWal->cfg.vgId,
|
||||||
ver, entry.offset, terrstr());
|
ver, entry.offset, terrstr());
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||||
|
@ -175,7 +175,7 @@ static int32_t walReadChangeFile(SWalReader *pReader, int64_t fileFirstVer) {
|
||||||
if (pLogFile == NULL) {
|
if (pLogFile == NULL) {
|
||||||
wError("vgId:%d, cannot open file %s, since %s", pReader->pWal->cfg.vgId, fnameStr, terrstr());
|
wError("vgId:%d, cannot open file %s, since %s", pReader->pWal->cfg.vgId, fnameStr, terrstr());
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
pReader->pLogFile = pLogFile;
|
pReader->pLogFile = pLogFile;
|
||||||
|
@ -185,7 +185,7 @@ static int32_t walReadChangeFile(SWalReader *pReader, int64_t fileFirstVer) {
|
||||||
if (pIdxFile == NULL) {
|
if (pIdxFile == NULL) {
|
||||||
wError("vgId:%d, cannot open file %s, since %s", pReader->pWal->cfg.vgId, fnameStr, terrstr());
|
wError("vgId:%d, cannot open file %s, since %s", pReader->pWal->cfg.vgId, fnameStr, terrstr());
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
pReader->pIdxFile = pIdxFile;
|
pReader->pIdxFile = pIdxFile;
|
||||||
|
@ -270,7 +270,7 @@ int32_t walFetchHead(SWalReader *pRead, int64_t ver) {
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
if (contLen < 0) {
|
if (contLen < 0) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
} else {
|
} else {
|
||||||
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
|
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ int32_t walSkipFetchBody(SWalReader *pRead) {
|
||||||
}
|
}
|
||||||
int64_t code = taosLSeekFile(pRead->pLogFile, cryptedBodyLen, SEEK_CUR);
|
int64_t code = taosLSeekFile(pRead->pLogFile, cryptedBodyLen, SEEK_CUR);
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
pRead->curVersion++;
|
pRead->curVersion++;
|
||||||
|
@ -345,7 +345,7 @@ int32_t walFetchBody(SWalReader *pRead) {
|
||||||
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since %s, 0x%" PRIx64, vgId,
|
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since %s, 0x%" PRIx64, vgId,
|
||||||
pReadHead->version, ver, tstrerror(terrno), id);
|
pReadHead->version, ver, tstrerror(terrno), id);
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
} else {
|
} else {
|
||||||
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64
|
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64
|
||||||
", since file corrupted, 0x%" PRIx64,
|
", since file corrupted, 0x%" PRIx64,
|
||||||
|
@ -426,7 +426,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
|
||||||
|
|
||||||
if (contLen < 0) {
|
if (contLen < 0) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
} else {
|
} else {
|
||||||
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
|
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
|
||||||
}
|
}
|
||||||
|
@ -467,7 +467,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
|
||||||
|
|
||||||
if (contLen < 0) {
|
if (contLen < 0) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
} else {
|
} else {
|
||||||
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
|
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) {
|
||||||
wError("vgId:%d, restore from snapshot, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr());
|
wError("vgId:%d, restore from snapshot, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr());
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
wInfo("vgId:%d, restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr);
|
wInfo("vgId:%d, restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr);
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) {
|
||||||
wError("vgId:%d, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr());
|
wError("vgId:%d, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr());
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
wInfo("vgId:%d, restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr);
|
wInfo("vgId:%d, restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr);
|
||||||
}
|
}
|
||||||
|
@ -111,20 +111,20 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) {
|
||||||
char fnameStr[WAL_FILE_LEN];
|
char fnameStr[WAL_FILE_LEN];
|
||||||
if (pWal->pLogFile != NULL) {
|
if (pWal->pLogFile != NULL) {
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pLogFile)) != 0) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pLogFile)) != 0) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
code = taosCloseFile(&pWal->pLogFile);
|
code = taosCloseFile(&pWal->pLogFile);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pWal->pIdxFile != NULL) {
|
if (pWal->pIdxFile != NULL) {
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pIdxFile)) != 0) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pIdxFile)) != 0) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
code = taosCloseFile(&pWal->pIdxFile);
|
code = taosCloseFile(&pWal->pIdxFile);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) {
|
||||||
if (pIdxTFile == NULL) {
|
if (pIdxTFile == NULL) {
|
||||||
pWal->pIdxFile = NULL;
|
pWal->pIdxFile = NULL;
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
walBuildLogName(pWal, fileFirstVer, fnameStr);
|
walBuildLogName(pWal, fileFirstVer, fnameStr);
|
||||||
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
|
@ -149,7 +149,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) {
|
||||||
TAOS_UNUSED(taosCloseFile(&pIdxTFile));
|
TAOS_UNUSED(taosCloseFile(&pIdxTFile));
|
||||||
pWal->pLogFile = NULL;
|
pWal->pLogFile = NULL;
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
pWal->pLogFile = pLogTFile;
|
pWal->pLogFile = pLogTFile;
|
||||||
|
@ -200,21 +200,21 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
||||||
if (pIdxFile == NULL) {
|
if (pIdxFile == NULL) {
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
int64_t idxOff = walGetVerIdxOffset(pWal, ver);
|
int64_t idxOff = walGetVerIdxOffset(pWal, ver);
|
||||||
code = taosLSeekFile(pIdxFile, idxOff, SEEK_SET);
|
code = taosLSeekFile(pIdxFile, idxOff, SEEK_SET);
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
// read idx file and get log file pos
|
// read idx file and get log file pos
|
||||||
SWalIdxEntry entry;
|
SWalIdxEntry entry;
|
||||||
if (taosReadFile(pIdxFile, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) {
|
if (taosReadFile(pIdxFile, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) {
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
|
walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
|
||||||
|
@ -225,14 +225,14 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
||||||
// TODO
|
// TODO
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
code = taosLSeekFile(pLogFile, entry.offset, SEEK_SET);
|
code = taosLSeekFile(pLogFile, entry.offset, SEEK_SET);
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
// TODO
|
// TODO
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
// validate offset
|
// validate offset
|
||||||
SWalCkHead head;
|
SWalCkHead head;
|
||||||
|
@ -240,7 +240,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
||||||
if (size != sizeof(SWalCkHead)) {
|
if (size != sizeof(SWalCkHead)) {
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
code = walValidHeadCksum(&head);
|
code = walValidHeadCksum(&head);
|
||||||
|
|
||||||
|
@ -260,13 +260,13 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
code = taosFtruncateFile(pIdxFile, idxOff);
|
code = taosFtruncateFile(pIdxFile, idxOff);
|
||||||
if (code < 0) {
|
if (code < 0) {
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
pWal->vers.lastVer = ver - 1;
|
pWal->vers.lastVer = ver - 1;
|
||||||
((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer = ver - 1;
|
((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer = ver - 1;
|
||||||
|
@ -294,21 +294,21 @@ static int32_t walRollImpl(SWal *pWal) {
|
||||||
|
|
||||||
if (pWal->pIdxFile != NULL) {
|
if (pWal->pIdxFile != NULL) {
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pIdxFile)) != 0) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pIdxFile)) != 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
code = taosCloseFile(&pWal->pIdxFile);
|
code = taosCloseFile(&pWal->pIdxFile);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWal->pLogFile != NULL) {
|
if (pWal->pLogFile != NULL) {
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pLogFile)) != 0) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pLogFile)) != 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
code = taosCloseFile(&pWal->pLogFile);
|
code = taosCloseFile(&pWal->pLogFile);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,13 +319,13 @@ static int32_t walRollImpl(SWal *pWal) {
|
||||||
walBuildIdxName(pWal, newFileFirstVer, fnameStr);
|
walBuildIdxName(pWal, newFileFirstVer, fnameStr);
|
||||||
pIdxFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
pIdxFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
if (pIdxFile == NULL) {
|
if (pIdxFile == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
walBuildLogName(pWal, newFileFirstVer, fnameStr);
|
walBuildLogName(pWal, newFileFirstVer, fnameStr);
|
||||||
pLogFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
pLogFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
wDebug("vgId:%d, wal create new file for write:%s", pWal->cfg.vgId, fnameStr);
|
wDebug("vgId:%d, wal create new file for write:%s", pWal->cfg.vgId, fnameStr);
|
||||||
if (pLogFile == NULL) {
|
if (pLogFile == NULL) {
|
||||||
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
|
TAOS_CHECK_GOTO(terrno, &lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
TAOS_CHECK_GOTO(walRollFileInfo(pWal), &lino, _exit);
|
TAOS_CHECK_GOTO(walRollFileInfo(pWal), &lino, _exit);
|
||||||
|
@ -536,13 +536,13 @@ static int32_t walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) {
|
||||||
pWal->stopDnode();
|
pWal->stopDnode();
|
||||||
}
|
}
|
||||||
|
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check alignment of idx entries
|
// check alignment of idx entries
|
||||||
int64_t endOffset = taosLSeekFile(pWal->pIdxFile, 0, SEEK_END);
|
int64_t endOffset = taosLSeekFile(pWal->pIdxFile, 0, SEEK_END);
|
||||||
if (endOffset < 0) {
|
if (endOffset < 0) {
|
||||||
wFatal("vgId:%d, failed to seek end of WAL idxfile due to %s. ver:%" PRId64 "", pWal->cfg.vgId, strerror(errno),
|
wFatal("vgId:%d, failed to seek end of WAL idxfile due to %s. ver:%" PRId64 "", pWal->cfg.vgId, strerror(terrno),
|
||||||
ver);
|
ver);
|
||||||
taosMsleep(100);
|
taosMsleep(100);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -578,7 +578,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
|
||||||
|
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP &&
|
if (pWal->cfg.level != TAOS_WAL_SKIP &&
|
||||||
taosWriteFile(pWal->pLogFile, &pWal->writeHead, sizeof(SWalCkHead)) != sizeof(SWalCkHead)) {
|
taosWriteFile(pWal->pLogFile, &pWal->writeHead, sizeof(SWalCkHead)) != sizeof(SWalCkHead)) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal),
|
wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
|
@ -634,7 +634,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWal->cfg.level != TAOS_WAL_SKIP && taosWriteFile(pWal->pLogFile, (char *)buf, cyptedBodyLen) != cyptedBodyLen) {
|
if (pWal->cfg.level != TAOS_WAL_SKIP && taosWriteFile(pWal->pLogFile, (char *)buf, cyptedBodyLen) != cyptedBodyLen) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal),
|
wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
||||||
|
@ -672,7 +672,6 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
|
||||||
_exit:
|
_exit:
|
||||||
// recover in a reverse order
|
// recover in a reverse order
|
||||||
if (taosFtruncateFile(pWal->pLogFile, offset) < 0) {
|
if (taosFtruncateFile(pWal->pLogFile, offset) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
wFatal("vgId:%d, failed to recover WAL logfile from write error since %s, offset:%" PRId64, pWal->cfg.vgId,
|
wFatal("vgId:%d, failed to recover WAL logfile from write error since %s, offset:%" PRId64, pWal->cfg.vgId,
|
||||||
terrstr(), offset);
|
terrstr(), offset);
|
||||||
taosMsleep(100);
|
taosMsleep(100);
|
||||||
|
@ -681,7 +680,6 @@ _exit:
|
||||||
|
|
||||||
int64_t idxOffset = (index - pFileInfo->firstVer) * sizeof(SWalIdxEntry);
|
int64_t idxOffset = (index - pFileInfo->firstVer) * sizeof(SWalIdxEntry);
|
||||||
if (taosFtruncateFile(pWal->pIdxFile, idxOffset) < 0) {
|
if (taosFtruncateFile(pWal->pIdxFile, idxOffset) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
wFatal("vgId:%d, failed to recover WAL idxfile from write error since %s, offset:%" PRId64, pWal->cfg.vgId,
|
wFatal("vgId:%d, failed to recover WAL idxfile from write error since %s, offset:%" PRId64, pWal->cfg.vgId,
|
||||||
terrstr(), idxOffset);
|
terrstr(), idxOffset);
|
||||||
taosMsleep(100);
|
taosMsleep(100);
|
||||||
|
@ -700,12 +698,12 @@ static int32_t walInitWriteFile(SWal *pWal) {
|
||||||
walBuildIdxName(pWal, fileFirstVer, fnameStr);
|
walBuildIdxName(pWal, fileFirstVer, fnameStr);
|
||||||
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
if (pIdxTFile == NULL) {
|
if (pIdxTFile == NULL) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
walBuildLogName(pWal, fileFirstVer, fnameStr);
|
walBuildLogName(pWal, fileFirstVer, fnameStr);
|
||||||
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
if (pLogTFile == NULL) {
|
if (pLogTFile == NULL) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
// switch file
|
// switch file
|
||||||
pWal->pIdxFile = pIdxTFile;
|
pWal->pIdxFile = pIdxTFile;
|
||||||
|
@ -755,7 +753,7 @@ int32_t walFsync(SWal *pWal, bool forceFsync) {
|
||||||
if (taosFsyncFile(pWal->pLogFile) < 0) {
|
if (taosFsyncFile(pWal->pLogFile) < 0) {
|
||||||
wError("vgId:%d, file:%" PRId64 ".log, fsync failed since %s", pWal->cfg.vgId, walGetCurFileFirstVer(pWal),
|
wError("vgId:%d, file:%" PRId64 ".log, fsync failed since %s", pWal->cfg.vgId, walGetCurFileFirstVer(pWal),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
|
||||||
|
|
|
@ -145,7 +145,10 @@ int32_t taosMulMkDir(const char *dirname) {
|
||||||
char *pos = temp;
|
char *pos = temp;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
taosRealPath(dirname, temp, sizeof(temp));
|
code = taosRealPath(dirname, temp, sizeof(temp));
|
||||||
|
if(code != 0) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
if (temp[1] == ':') pos += 3;
|
if (temp[1] == ':') pos += 3;
|
||||||
#else
|
#else
|
||||||
(void)strcpy(temp, dirname);
|
(void)strcpy(temp, dirname);
|
||||||
|
@ -207,7 +210,10 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
|
||||||
char *pos = temp;
|
char *pos = temp;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
taosRealPath(dirname, temp, sizeof(temp));
|
code = taosRealPath(dirname, temp, sizeof(temp));
|
||||||
|
if(code != 0) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
if (temp[1] == ':') pos += 3;
|
if (temp[1] == ':') pos += 3;
|
||||||
#else
|
#else
|
||||||
(void)strcpy(temp, dirname);
|
(void)strcpy(temp, dirname);
|
||||||
|
@ -430,6 +436,9 @@ TdDirPtr taosOpenDir(const char *dirname) {
|
||||||
HANDLE hFind;
|
HANDLE hFind;
|
||||||
|
|
||||||
TdDirPtr pDir = taosMemoryMalloc(sizeof(TdDir));
|
TdDirPtr pDir = taosMemoryMalloc(sizeof(TdDir));
|
||||||
|
if(pDir == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
strcpy(szFind, dirname);
|
strcpy(szFind, dirname);
|
||||||
strcat(szFind, "\\*.*"); //利用通配符找这个目录下的所以文件,包括目录
|
strcat(szFind, "\\*.*"); //利用通配符找这个目录下的所以文件,包括目录
|
||||||
|
@ -437,6 +446,8 @@ TdDirPtr taosOpenDir(const char *dirname) {
|
||||||
pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData));
|
pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData));
|
||||||
if (INVALID_HANDLE_VALUE == pDir->hFind) {
|
if (INVALID_HANDLE_VALUE == pDir->hFind) {
|
||||||
taosMemoryFree(pDir);
|
taosMemoryFree(pDir);
|
||||||
|
DWORD errorCode = GetLastError();
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(errorCode);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return pDir;
|
return pDir;
|
||||||
|
@ -444,6 +455,11 @@ TdDirPtr taosOpenDir(const char *dirname) {
|
||||||
DIR *pDir = opendir(dirname);
|
DIR *pDir = opendir(dirname);
|
||||||
if (pDir == NULL) return NULL;
|
if (pDir == NULL) return NULL;
|
||||||
TdDirPtr dirPtr = (TdDirPtr)taosMemoryMalloc(sizeof(TdDir));
|
TdDirPtr dirPtr = (TdDirPtr)taosMemoryMalloc(sizeof(TdDir));
|
||||||
|
if (dirPtr == NULL) {
|
||||||
|
(void)closedir(pDir);
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
dirPtr->dirEntryPtr = (TdDirEntryPtr) & (dirPtr->dirEntry1);
|
dirPtr->dirEntryPtr = (TdDirEntryPtr) & (dirPtr->dirEntry1);
|
||||||
dirPtr->pDir = pDir;
|
dirPtr->pDir = pDir;
|
||||||
return dirPtr;
|
return dirPtr;
|
||||||
|
@ -506,22 +522,30 @@ char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosCloseDir(TdDirPtr *ppDir) {
|
int32_t taosCloseDir(TdDirPtr *ppDir) {
|
||||||
|
int32_t code = 0;
|
||||||
if (ppDir == NULL || *ppDir == NULL) {
|
if (ppDir == NULL || *ppDir == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
FindClose((*ppDir)->hFind);
|
if(!FindClose((*ppDir)->hFind)) {
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
taosMemoryFree(*ppDir);
|
taosMemoryFree(*ppDir);
|
||||||
*ppDir = NULL;
|
*ppDir = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
#elif defined(DARWIN)
|
#elif defined(DARWIN)
|
||||||
closedir((*ppDir)->pDir);
|
code = closedir((*ppDir)->pDir);
|
||||||
|
if (-1 == code) {
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
taosMemoryFree(*ppDir);
|
taosMemoryFree(*ppDir);
|
||||||
*ppDir = NULL;
|
*ppDir = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
int32_t code = closedir((DIR *)*ppDir);
|
code = closedir((DIR *)*ppDir);
|
||||||
*ppDir = NULL;
|
*ppDir = NULL;
|
||||||
if (-1 == code) {
|
if (-1 == code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
|
|
@ -64,7 +64,10 @@ int32_t osDefaultInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
taosWinSocketInit();
|
code = taosWinSocketInit();
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
const char *tmpDir = getenv("tmp");
|
const char *tmpDir = getenv("tmp");
|
||||||
if (tmpDir == NULL) {
|
if (tmpDir == NULL) {
|
||||||
|
|
|
@ -132,6 +132,7 @@ int64_t taosCopyFile(const char *from, const char *to) {
|
||||||
if (CopyFile(from, to, 0)) {
|
if (CopyFile(from, to, 0)) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -231,8 +232,9 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
|
||||||
|
|
||||||
HANDLE transactionHandle = CreateTransaction(NULL, NULL, 0, 0, 0, INFINITE, NULL);
|
HANDLE transactionHandle = CreateTransaction(NULL, NULL, 0, 0, 0, INFINITE, NULL);
|
||||||
if (transactionHandle == INVALID_HANDLE_VALUE) {
|
if (transactionHandle == INVALID_HANDLE_VALUE) {
|
||||||
printf("failed to rename file %s to %s, reason: CreateTransaction failed.\n", oldName, newName);
|
DWORD error = GetLastError();
|
||||||
return -1;
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(error);
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL result = MoveFileTransacted(oldName, newName, NULL, NULL, MOVEFILE_REPLACE_EXISTING, transactionHandle);
|
BOOL result = MoveFileTransacted(oldName, newName, NULL, NULL, MOVEFILE_REPLACE_EXISTING, transactionHandle);
|
||||||
|
@ -241,18 +243,18 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
|
||||||
finished = CommitTransaction(transactionHandle);
|
finished = CommitTransaction(transactionHandle);
|
||||||
if (!finished) {
|
if (!finished) {
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
printf("failed to rename file %s to %s, reason: CommitTransaction errcode %d.\n", oldName, newName, error);
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(error);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RollbackTransaction(transactionHandle);
|
RollbackTransaction(transactionHandle);
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(error);
|
||||||
finished = false;
|
finished = false;
|
||||||
printf("failed to rename file %s to %s, reason: MoveFileTransacted errcode %d.\n", oldName, newName, error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseHandle(transactionHandle);
|
CloseHandle(transactionHandle);
|
||||||
|
|
||||||
return finished ? 0 : -1;
|
return finished ? 0 : terrno;
|
||||||
#else
|
#else
|
||||||
int32_t code = rename(oldName, newName);
|
int32_t code = rename(oldName, newName);
|
||||||
if (-1 == code) {
|
if (-1 == code) {
|
||||||
|
@ -260,7 +262,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return TSDB_CODE_SUCCESS;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,12 +296,14 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *a
|
||||||
int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
|
int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (pFile == NULL || pFile->hFile == NULL) {
|
if (pFile == NULL || pFile->hFile == NULL) {
|
||||||
return -1;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
BY_HANDLE_FILE_INFORMATION bhfi;
|
BY_HANDLE_FILE_INFORMATION bhfi;
|
||||||
if (GetFileInformationByHandle(pFile->hFile, &bhfi) == FALSE) {
|
if (GetFileInformationByHandle(pFile->hFile, &bhfi) == FALSE) {
|
||||||
printf("taosFStatFile get file info fail.");
|
DWORD error = GetLastError();
|
||||||
return -1;
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(error);
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stDev != NULL) {
|
if (stDev != NULL) {
|
||||||
|
@ -395,68 +399,75 @@ HANDLE taosOpenFileNotStream(const char *path, int32_t tdFileOptions) {
|
||||||
if (h != INVALID_HANDLE_VALUE && (tdFileOptions & TD_FILE_APPEND) && (tdFileOptions & TD_FILE_WRITE)) {
|
if (h != INVALID_HANDLE_VALUE && (tdFileOptions & TD_FILE_APPEND) && (tdFileOptions & TD_FILE_WRITE)) {
|
||||||
SetFilePointer(h, 0, NULL, FILE_END);
|
SetFilePointer(h, 0, NULL, FILE_END);
|
||||||
}
|
}
|
||||||
// if (h == INVALID_HANDLE_VALUE) {
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
// DWORD dwError = GetLastError();
|
DWORD dwError = GetLastError();
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(dwError);
|
||||||
// LPVOID lpMsgBuf;
|
// LPVOID lpMsgBuf;
|
||||||
// FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
|
// FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, (LPTSTR)&lpMsgBuf, 0,
|
||||||
// 0,
|
// NULL);
|
||||||
// (LPTSTR)&lpMsgBuf, 0, NULL);
|
// printf("CreateFile failed with error %d: %s", dwError, (char *)lpMsgBuf);
|
||||||
// printf("CreateFile failed with error %d: %s", dwError, (char*)lpMsgBuf);
|
|
||||||
// LocalFree(lpMsgBuf);
|
// LocalFree(lpMsgBuf);
|
||||||
// }
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
(void)taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
if (pFile->hFile == NULL) {
|
if (pFile->hFile == NULL) {
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
return -1;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD bytesRead;
|
DWORD bytesRead;
|
||||||
if (!ReadFile(pFile->hFile, buf, count, &bytesRead, NULL)) {
|
if (!ReadFile(pFile->hFile, buf, count, &bytesRead, NULL)) {
|
||||||
|
DWORD errCode = GetLastError();
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(errCode);
|
||||||
bytesRead = -1;
|
bytesRead = -1;
|
||||||
}
|
}
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
return bytesRead;
|
return bytesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
|
int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) {
|
||||||
if (pFile == NULL || pFile->hFile == NULL) {
|
if (pFile == NULL || pFile->hFile == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockWrlock(&(pFile->rwlock));
|
(void)taosThreadRwlockWrlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DWORD bytesWritten;
|
DWORD bytesWritten;
|
||||||
if (!WriteFile(pFile->hFile, buf, count, &bytesWritten, NULL)) {
|
if (!WriteFile(pFile->hFile, buf, count, &bytesWritten, NULL)) {
|
||||||
|
errno = GetLastError();
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(errno);
|
||||||
bytesWritten = -1;
|
bytesWritten = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
return bytesWritten;
|
return bytesWritten;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset) {
|
int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset) {
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockWrlock(&(pFile->rwlock));
|
(void)taosThreadRwlockWrlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
if (pFile->hFile == NULL) {
|
if (pFile->hFile == NULL) {
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -470,48 +481,57 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t
|
||||||
BOOL result = WriteFile(pFile->hFile, buf, count, &ret, &ol);
|
BOOL result = WriteFile(pFile->hFile, buf, count, &ret, &ol);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
errno = GetLastError();
|
errno = GetLastError();
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(errno);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
|
int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
|
||||||
if (pFile == NULL || pFile->hFile == NULL) {
|
if (pFile == NULL || pFile->hFile == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockRdlock(&(pFile->rwlock));
|
(void)taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LARGE_INTEGER liOffset;
|
LARGE_INTEGER liOffset;
|
||||||
liOffset.QuadPart = offset;
|
liOffset.QuadPart = offset;
|
||||||
if (!SetFilePointerEx(pFile->hFile, liOffset, NULL, whence)) {
|
if (!SetFilePointerEx(pFile->hFile, liOffset, NULL, whence)) {
|
||||||
|
errno = GetLastError();
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
liOffset.QuadPart = 0;
|
liOffset.QuadPart = 0;
|
||||||
if (!SetFilePointerEx(pFile->hFile, liOffset, &liOffset, FILE_CURRENT)) {
|
if (!SetFilePointerEx(pFile->hFile, liOffset, &liOffset, FILE_CURRENT)) {
|
||||||
|
errno = GetLastError();
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
return liOffset.QuadPart;
|
return liOffset.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
|
int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
|
||||||
if (pFile == NULL || pFile->hFile == NULL) {
|
if (pFile == NULL || pFile->hFile == NULL) {
|
||||||
return 0;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size != NULL) {
|
if (size != NULL) {
|
||||||
LARGE_INTEGER fileSize;
|
LARGE_INTEGER fileSize;
|
||||||
if (!GetFileSizeEx(pFile->hFile, &fileSize)) {
|
if (!GetFileSizeEx(pFile->hFile, &fileSize)) {
|
||||||
return -1; // Error getting file size
|
errno = GetLastError();
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(errno);
|
||||||
|
return terrno; // Error getting file size
|
||||||
}
|
}
|
||||||
*size = fileSize.QuadPart;
|
*size = fileSize.QuadPart;
|
||||||
}
|
}
|
||||||
|
@ -519,7 +539,9 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
|
||||||
if (mtime != NULL) {
|
if (mtime != NULL) {
|
||||||
FILETIME creationTime, lastAccessTime, lastWriteTime;
|
FILETIME creationTime, lastAccessTime, lastWriteTime;
|
||||||
if (!GetFileTime(pFile->hFile, &creationTime, &lastAccessTime, &lastWriteTime)) {
|
if (!GetFileTime(pFile->hFile, &creationTime, &lastAccessTime, &lastWriteTime)) {
|
||||||
return -1; // Error getting file time
|
errno = GetLastError();
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(errno);
|
||||||
|
return terrno; // Error getting file time
|
||||||
}
|
}
|
||||||
// Convert the FILETIME structure to a time_t value
|
// Convert the FILETIME structure to a time_t value
|
||||||
ULARGE_INTEGER ull;
|
ULARGE_INTEGER ull;
|
||||||
|
@ -532,7 +554,8 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
|
||||||
|
|
||||||
int32_t taosLockFile(TdFilePtr pFile) {
|
int32_t taosLockFile(TdFilePtr pFile) {
|
||||||
if (pFile == NULL || pFile->hFile == NULL) {
|
if (pFile == NULL || pFile->hFile == NULL) {
|
||||||
return -1;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL fSuccess = FALSE;
|
BOOL fSuccess = FALSE;
|
||||||
|
@ -546,7 +569,7 @@ int32_t taosLockFile(TdFilePtr pFile) {
|
||||||
&overlapped // overlapped structure
|
&overlapped // overlapped structure
|
||||||
);
|
);
|
||||||
if (!fSuccess) {
|
if (!fSuccess) {
|
||||||
return GetLastError();
|
return TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -560,18 +583,20 @@ int32_t taosUnLockFile(TdFilePtr pFile) {
|
||||||
|
|
||||||
fSuccess = UnlockFileEx(pFile->hFile, 0, ~0, ~0, &overlapped);
|
fSuccess = UnlockFileEx(pFile->hFile, 0, ~0, ~0, &overlapped);
|
||||||
if (!fSuccess) {
|
if (!fSuccess) {
|
||||||
return GetLastError();
|
return TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
return 0;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
if (pFile->hFile == NULL) {
|
if (pFile->hFile == NULL) {
|
||||||
printf("Ftruncate file error, hFile was null\n");
|
printf("Ftruncate file error, hFile was null\n");
|
||||||
return -1;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
LARGE_INTEGER li_0;
|
LARGE_INTEGER li_0;
|
||||||
|
@ -579,7 +604,8 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||||
BOOL cur = SetFilePointerEx(pFile->hFile, li_0, NULL, FILE_CURRENT);
|
BOOL cur = SetFilePointerEx(pFile->hFile, li_0, NULL, FILE_CURRENT);
|
||||||
if (!cur) {
|
if (!cur) {
|
||||||
printf("SetFilePointerEx Error getting current position in file.\n");
|
printf("SetFilePointerEx Error getting current position in file.\n");
|
||||||
return -1;
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
LARGE_INTEGER li_size;
|
LARGE_INTEGER li_size;
|
||||||
|
@ -587,7 +613,6 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||||
BOOL cur2 = SetFilePointerEx(pFile->hFile, li_size, NULL, FILE_BEGIN);
|
BOOL cur2 = SetFilePointerEx(pFile->hFile, li_size, NULL, FILE_BEGIN);
|
||||||
if (cur2 == 0) {
|
if (cur2 == 0) {
|
||||||
int error = GetLastError();
|
int error = GetLastError();
|
||||||
printf("SetFilePointerEx GetLastError is: %d\n", error);
|
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case ERROR_INVALID_HANDLE:
|
case ERROR_INVALID_HANDLE:
|
||||||
errno = EBADF;
|
errno = EBADF;
|
||||||
|
@ -596,7 +621,8 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return -1;
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SetEndOfFile(pFile->hFile)) {
|
if (!SetEndOfFile(pFile->hFile)) {
|
||||||
|
@ -610,23 +636,27 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||||
errno = EIO;
|
errno = EIO;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return -1;
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
return terrno;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) {
|
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) {
|
||||||
if (pFileOut == NULL || pFileIn == NULL) {
|
if (pFileOut == NULL || pFileIn == NULL) {
|
||||||
return 0;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
if (pFileIn->hFile == NULL || pFileOut->hFile == NULL) {
|
if (pFileIn->hFile == NULL || pFileOut->hFile == NULL) {
|
||||||
return 0;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
LARGE_INTEGER fileOffset;
|
LARGE_INTEGER fileOffset;
|
||||||
fileOffset.QuadPart = *offset;
|
fileOffset.QuadPart = *offset;
|
||||||
|
|
||||||
if (!SetFilePointerEx(pFileIn->hFile, fileOffset, &fileOffset, FILE_BEGIN)) {
|
if (!SetFilePointerEx(pFileIn->hFile, fileOffset, &fileOffset, FILE_BEGIN)) {
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,6 +667,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
||||||
DWORD bytesWritten;
|
DWORD bytesWritten;
|
||||||
for (int64_t len = 0; len < (size - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) {
|
for (int64_t len = 0; len < (size - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) {
|
||||||
if (!ReadFile(pFileIn->hFile, buffer, _SEND_FILE_STEP_, &bytesRead, NULL)) {
|
if (!ReadFile(pFileIn->hFile, buffer, _SEND_FILE_STEP_, &bytesRead, NULL)) {
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
return writeLen;
|
return writeLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,12 +675,14 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
||||||
return writeLen;
|
return writeLen;
|
||||||
} else if (bytesRead < _SEND_FILE_STEP_) {
|
} else if (bytesRead < _SEND_FILE_STEP_) {
|
||||||
if (!WriteFile(pFileOut->hFile, buffer, bytesRead, &bytesWritten, NULL)) {
|
if (!WriteFile(pFileOut->hFile, buffer, bytesRead, &bytesWritten, NULL)) {
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return (int64_t)(writeLen + bytesRead);
|
return (int64_t)(writeLen + bytesRead);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!WriteFile(pFileOut->hFile, buffer, _SEND_FILE_STEP_, &bytesWritten, NULL)) {
|
if (!WriteFile(pFileOut->hFile, buffer, _SEND_FILE_STEP_, &bytesWritten, NULL)) {
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
writeLen += _SEND_FILE_STEP_;
|
writeLen += _SEND_FILE_STEP_;
|
||||||
|
@ -661,6 +694,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
||||||
if (remain > 0) {
|
if (remain > 0) {
|
||||||
DWORD bytesRead;
|
DWORD bytesRead;
|
||||||
if (!ReadFile(pFileIn->hFile, buffer, (DWORD)remain, &bytesRead, NULL)) {
|
if (!ReadFile(pFileIn->hFile, buffer, (DWORD)remain, &bytesRead, NULL)) {
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,6 +703,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
||||||
} else {
|
} else {
|
||||||
DWORD bytesWritten;
|
DWORD bytesWritten;
|
||||||
if (!WriteFile(pFileOut->hFile, buffer, bytesRead, &bytesWritten, NULL)) {
|
if (!WriteFile(pFileOut->hFile, buffer, bytesRead, &bytesWritten, NULL)) {
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
writeLen += bytesWritten;
|
writeLen += bytesWritten;
|
||||||
|
@ -718,7 +753,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
||||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t leftbytes = count;
|
int64_t leftbytes = count;
|
||||||
|
@ -741,7 +776,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
|
||||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return terrno;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (readbytes == 0) {
|
} else if (readbytes == 0) {
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
|
@ -826,25 +861,11 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef WINDOWS
|
|
||||||
DWORD ret = 0;
|
|
||||||
OVERLAPPED ol = {0};
|
|
||||||
ol.OffsetHigh = (uint32_t)((offset & 0xFFFFFFFF00000000LL) >> 0x20);
|
|
||||||
ol.Offset = (uint32_t)(offset & 0xFFFFFFFFLL);
|
|
||||||
|
|
||||||
HANDLE handle = (HANDLE)_get_osfhandle(pFile->fd);
|
|
||||||
SetLastError(0);
|
|
||||||
BOOL result = WriteFile(handle, buf, count, &ret, &ol);
|
|
||||||
if (!result) {
|
|
||||||
errno = GetLastError();
|
|
||||||
ret = -1;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
int64_t ret = pwrite(pFile->fd, buf, count, offset);
|
int64_t ret = pwrite(pFile->fd, buf, count, offset);
|
||||||
if (-1 == ret) {
|
if (-1 == ret) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
|
@ -859,7 +880,7 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t
|
||||||
int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
|
int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
|
||||||
if (pFile == NULL || pFile->fd < 0) {
|
if (pFile == NULL || pFile->fd < 0) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return -1;
|
||||||
}
|
}
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
(void)taosThreadRwlockRdlock(&(pFile->rwlock));
|
(void)taosThreadRwlockRdlock(&(pFile->rwlock));
|
||||||
|
@ -867,14 +888,10 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
#ifdef WINDOWS
|
|
||||||
int64_t ret = _lseeki64(pFile->fd, offset, whence);
|
|
||||||
#else
|
|
||||||
int64_t ret = lseek(pFile->fd, offset, whence);
|
int64_t ret = lseek(pFile->fd, offset, whence);
|
||||||
if (-1 == ret) {
|
if (-1 == ret) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#if FILE_WITH_LOCK
|
#if FILE_WITH_LOCK
|
||||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
|
@ -882,7 +899,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return terrno;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -899,16 +916,11 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) {
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
|
||||||
struct __stat64 fileStat;
|
|
||||||
int32_t code = _fstat64(pFile->fd, &fileStat);
|
|
||||||
#else
|
|
||||||
struct stat fileStat;
|
struct stat fileStat;
|
||||||
int32_t code = fstat(pFile->fd, &fileStat);
|
int32_t code = fstat(pFile->fd, &fileStat);
|
||||||
#endif
|
|
||||||
if (-1 == code) {
|
if (-1 == code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return code;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size != NULL) {
|
if (size != NULL) {
|
||||||
|
@ -927,32 +939,12 @@ int32_t taosLockFile(TdFilePtr pFile) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
|
||||||
BOOL fSuccess = FALSE;
|
|
||||||
LARGE_INTEGER fileSize;
|
|
||||||
OVERLAPPED overlapped = {0};
|
|
||||||
|
|
||||||
HANDLE hFile = (HANDLE)_get_osfhandle(pFile->fd);
|
|
||||||
|
|
||||||
fSuccess = LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY,
|
|
||||||
0, // reserved
|
|
||||||
~0, // number of bytes to lock low
|
|
||||||
~0, // number of bytes to lock high
|
|
||||||
&overlapped // overlapped structure
|
|
||||||
);
|
|
||||||
if (!fSuccess) {
|
|
||||||
return GetLastError();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
#else
|
|
||||||
int32_t code = (int32_t)flock(pFile->fd, LOCK_EX | LOCK_NB);
|
int32_t code = (int32_t)flock(pFile->fd, LOCK_EX | LOCK_NB);
|
||||||
if (-1 == code) {
|
if (-1 == code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
return code;
|
return 0;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosUnLockFile(TdFilePtr pFile) {
|
int32_t taosUnLockFile(TdFilePtr pFile) {
|
||||||
|
@ -960,25 +952,12 @@ int32_t taosUnLockFile(TdFilePtr pFile) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
|
||||||
BOOL fSuccess = FALSE;
|
|
||||||
OVERLAPPED overlapped = {0};
|
|
||||||
HANDLE hFile = (HANDLE)_get_osfhandle(pFile->fd);
|
|
||||||
|
|
||||||
fSuccess = UnlockFileEx(hFile, 0, ~0, ~0, &overlapped);
|
|
||||||
if (!fSuccess) {
|
|
||||||
return GetLastError();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
#else
|
|
||||||
int32_t code = (int32_t)flock(pFile->fd, LOCK_UN | LOCK_NB);
|
int32_t code = (int32_t)flock(pFile->fd, LOCK_UN | LOCK_NB);
|
||||||
if (-1 == code) {
|
if (-1 == code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
return code;
|
return 0;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||||
|
@ -987,104 +966,29 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) {
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
|
||||||
|
|
||||||
HANDLE h = (HANDLE)_get_osfhandle(pFile->fd);
|
|
||||||
|
|
||||||
LARGE_INTEGER li_0;
|
|
||||||
li_0.QuadPart = (int64_t)0;
|
|
||||||
BOOL cur = SetFilePointerEx(h, li_0, NULL, FILE_CURRENT);
|
|
||||||
if (!cur) {
|
|
||||||
printf("SetFilePointerEx Error getting current position in file.\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
LARGE_INTEGER li_size;
|
|
||||||
li_size.QuadPart = l_size;
|
|
||||||
BOOL cur2 = SetFilePointerEx(h, li_size, NULL, FILE_BEGIN);
|
|
||||||
if (cur2 == 0) {
|
|
||||||
int error = GetLastError();
|
|
||||||
printf("SetFilePointerEx GetLastError is: %d\n", error);
|
|
||||||
switch (error) {
|
|
||||||
case ERROR_INVALID_HANDLE:
|
|
||||||
errno = EBADF;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
errno = EIO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!SetEndOfFile(h)) {
|
|
||||||
int error = GetLastError();
|
|
||||||
printf("SetEndOfFile GetLastError is:%d", error);
|
|
||||||
switch (error) {
|
|
||||||
case ERROR_INVALID_HANDLE:
|
|
||||||
errno = EBADF;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
errno = EIO;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
#else
|
|
||||||
int32_t code = ftruncate(pFile->fd, l_size);
|
int32_t code = ftruncate(pFile->fd, l_size);
|
||||||
if (-1 == code) {
|
if (-1 == code) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
return code;
|
return 0;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) {
|
int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) {
|
||||||
if (pFileOut == NULL || pFileIn == NULL) {
|
if (pFileOut == NULL || pFileIn == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return -1;
|
||||||
}
|
}
|
||||||
if (pFileIn->fd < 0 || pFileOut->fd < 0) {
|
if (pFileIn->fd < 0 || pFileOut->fd < 0) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef _TD_DARWIN_64
|
||||||
|
if(lseek(pFileIn->fd, (int32_t)(*offset), 0) < 0) {
|
||||||
_lseeki64(pFileIn->fd, *offset, 0);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
int64_t writeLen = 0;
|
return -1;
|
||||||
uint8_t buffer[_SEND_FILE_STEP_] = {0};
|
|
||||||
|
|
||||||
for (int64_t len = 0; len < (size - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) {
|
|
||||||
size_t rlen = _read(pFileIn->fd, (void *)buffer, _SEND_FILE_STEP_);
|
|
||||||
if (rlen <= 0) {
|
|
||||||
return writeLen;
|
|
||||||
} else if (rlen < _SEND_FILE_STEP_) {
|
|
||||||
write(pFileOut->fd, (void *)buffer, (uint32_t)rlen);
|
|
||||||
return (int64_t)(writeLen + rlen);
|
|
||||||
} else {
|
|
||||||
write(pFileOut->fd, (void *)buffer, _SEND_FILE_STEP_);
|
|
||||||
writeLen += _SEND_FILE_STEP_;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int64_t remain = size - writeLen;
|
|
||||||
if (remain > 0) {
|
|
||||||
size_t rlen = _read(pFileIn->fd, (void *)buffer, (size_t)remain);
|
|
||||||
if (rlen <= 0) {
|
|
||||||
return writeLen;
|
|
||||||
} else {
|
|
||||||
write(pFileOut->fd, (void *)buffer, (uint32_t)remain);
|
|
||||||
writeLen += remain;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return writeLen;
|
|
||||||
|
|
||||||
#elif defined(_TD_DARWIN_64)
|
|
||||||
|
|
||||||
lseek(pFileIn->fd, (int32_t)(*offset), 0);
|
|
||||||
int64_t writeLen = 0;
|
int64_t writeLen = 0;
|
||||||
uint8_t buffer[_SEND_FILE_STEP_] = {0};
|
uint8_t buffer[_SEND_FILE_STEP_] = {0};
|
||||||
|
|
||||||
|
@ -1113,7 +1017,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
||||||
}
|
}
|
||||||
return writeLen;
|
return writeLen;
|
||||||
|
|
||||||
#else
|
#else // for linux
|
||||||
|
|
||||||
int64_t leftbytes = size;
|
int64_t leftbytes = size;
|
||||||
int64_t sentbytes;
|
int64_t sentbytes;
|
||||||
|
@ -1129,7 +1033,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return terrno;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (sentbytes == 0) {
|
} else if (sentbytes == 0) {
|
||||||
return (int64_t)(size - leftbytes);
|
return (int64_t)(size - leftbytes);
|
||||||
|
@ -1224,6 +1128,7 @@ int32_t taosCloseFile(TdFilePtr *ppFile) {
|
||||||
if ((*ppFile)->hFile != NULL) {
|
if ((*ppFile)->hFile != NULL) {
|
||||||
// FlushFileBuffers((*ppFile)->hFile);
|
// FlushFileBuffers((*ppFile)->hFile);
|
||||||
if (!CloseHandle((*ppFile)->hFile)) {
|
if (!CloseHandle((*ppFile)->hFile)) {
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
code = -1;
|
code = -1;
|
||||||
}
|
}
|
||||||
(*ppFile)->hFile = NULL;
|
(*ppFile)->hFile = NULL;
|
||||||
|
@ -1252,7 +1157,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
||||||
STUB_RAND_IO_ERR(terrno)
|
STUB_RAND_IO_ERR(terrno)
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -1268,7 +1173,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
DWORD ret = 0;
|
DWORD ret = 0;
|
||||||
|
@ -1279,7 +1184,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
||||||
SetLastError(0);
|
SetLastError(0);
|
||||||
BOOL result = ReadFile(pFile->hFile, buf, count, &ret, &ol);
|
BOOL result = ReadFile(pFile->hFile, buf, count, &ret, &ol);
|
||||||
if (!result && GetLastError() != ERROR_HANDLE_EOF) {
|
if (!result && GetLastError() != ERROR_HANDLE_EOF) {
|
||||||
errno = GetLastError();
|
code = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -1292,7 +1197,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
||||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
return terrno;
|
return -1;
|
||||||
}
|
}
|
||||||
int64_t ret = pread(pFile->fd, buf, count, offset);
|
int64_t ret = pread(pFile->fd, buf, count, offset);
|
||||||
if (-1 == ret) {
|
if (-1 == ret) {
|
||||||
|
@ -1305,7 +1210,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
|
||||||
|
|
||||||
if (code) {
|
if (code) {
|
||||||
terrno = code;
|
terrno = code;
|
||||||
return code;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1334,7 +1239,12 @@ int32_t taosFsyncFile(TdFilePtr pFile) {
|
||||||
if (pFile->tdFileOptions & TD_FILE_WRITE_THROUGH) {
|
if (pFile->tdFileOptions & TD_FILE_WRITE_THROUGH) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return !FlushFileBuffers(pFile->hFile);
|
bool ret = FlushFileBuffers(pFile->hFile);
|
||||||
|
if (!ret) {
|
||||||
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (pFile->fd >= 0) {
|
if (pFile->fd >= 0) {
|
||||||
|
@ -1398,7 +1308,9 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
size_t bufferSize = 512;
|
size_t bufferSize = 512;
|
||||||
*ptrBuf = taosMemoryMalloc(bufferSize);
|
*ptrBuf = taosMemoryMalloc(bufferSize);
|
||||||
if (*ptrBuf == NULL) goto END;
|
if (*ptrBuf == NULL) {
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
|
||||||
size_t bytesRead = 0;
|
size_t bytesRead = 0;
|
||||||
size_t totalBytesRead = 0;
|
size_t totalBytesRead = 0;
|
||||||
|
@ -1406,9 +1318,15 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) {
|
||||||
while (1) {
|
while (1) {
|
||||||
char *result = fgets(*ptrBuf + totalBytesRead, bufferSize - totalBytesRead, pFile->fp);
|
char *result = fgets(*ptrBuf + totalBytesRead, bufferSize - totalBytesRead, pFile->fp);
|
||||||
if (result == NULL) {
|
if (result == NULL) {
|
||||||
|
if (feof(pFile->fp)) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
ret = -1;
|
||||||
|
terrno = TAOS_SYSTEM_ERROR(ferror(pFile->fp));
|
||||||
taosMemoryFreeClear(*ptrBuf);
|
taosMemoryFreeClear(*ptrBuf);
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
bytesRead = strlen(*ptrBuf + totalBytesRead);
|
bytesRead = strlen(*ptrBuf + totalBytesRead);
|
||||||
totalBytesRead += bytesRead;
|
totalBytesRead += bytesRead;
|
||||||
|
|
||||||
|
@ -1432,7 +1350,7 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) {
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
ret = getline(ptrBuf, &len, pFile->fp);
|
ret = getline(ptrBuf, &len, pFile->fp);
|
||||||
if (-1 == ret) {
|
if (-1 == ret) {
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1442,10 +1360,6 @@ END:
|
||||||
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (code) {
|
|
||||||
terrno = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1637,8 +1551,7 @@ int taosSetAutoDelFile(char *path) {
|
||||||
if (succ) {
|
if (succ) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
DWORD error = GetLastError();
|
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
|
||||||
terrno = TAOS_SYSTEM_ERROR(error);
|
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -1170,19 +1170,23 @@ int32_t taosCreateSocketWithTimeout(uint32_t timeout) {
|
||||||
return (int)fd;
|
return (int)fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosWinSocketInit() {
|
int32_t taosWinSocketInit() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
static char flag = 0;
|
static int8_t flag = 0;
|
||||||
if (flag == 0) {
|
if (atomic_val_compare_exchange_8(&flag, 0, 1) == 0) {
|
||||||
WORD wVersionRequested;
|
WORD wVersionRequested;
|
||||||
WSADATA wsaData;
|
WSADATA wsaData;
|
||||||
wVersionRequested = MAKEWORD(1, 1);
|
wVersionRequested = MAKEWORD(1, 1);
|
||||||
if (WSAStartup(wVersionRequested, &wsaData) == 0) {
|
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
|
||||||
flag = 1;
|
atomic_store_8(&flag, 0);
|
||||||
|
int errorCode = WSAGetLastError();
|
||||||
|
return terrno = TAOS_SYSTEM_WINSOCKET_ERROR(errorCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t taosHton64(uint64_t val) {
|
uint64_t taosHton64(uint64_t val) {
|
||||||
|
|
|
@ -300,7 +300,7 @@ int32_t taosGetEmail(char *email, int32_t maxLen) {
|
||||||
|
|
||||||
if (taosReadFile(pFile, (void *)email, maxLen) < 0) {
|
if (taosReadFile(pFile, (void *)email, maxLen) < 0) {
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
return -1;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
|
|
|
@ -148,7 +148,7 @@ static void tqsortImpl(void *src, int32_t start, int32_t end, int64_t size, cons
|
||||||
int32_t taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ext_compar_fn_t comparFn) {
|
int32_t taosqsort(void *src, int64_t numOfElem, int64_t size, const void *param, __ext_compar_fn_t comparFn) {
|
||||||
char *buf = taosMemoryCalloc(1, size); // prepare the swap buffer
|
char *buf = taosMemoryCalloc(1, size); // prepare the swap buffer
|
||||||
if (NULL == buf) {
|
if (NULL == buf) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
tqsortImpl(src, 0, (int32_t)numOfElem - 1, (int32_t)size, param, comparFn, buf);
|
tqsortImpl(src, 0, (int32_t)numOfElem - 1, (int32_t)size, param, comparFn, buf);
|
||||||
taosMemoryFreeClear(buf);
|
taosMemoryFreeClear(buf);
|
||||||
|
@ -393,7 +393,7 @@ int32_t taosheapsort(void *base, int32_t size, int32_t len, const void *parcompa
|
||||||
|
|
||||||
char *buf = taosMemoryCalloc(1, size);
|
char *buf = taosMemoryCalloc(1, size);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base && size > 0) {
|
if (base && size > 0) {
|
||||||
|
@ -454,7 +454,7 @@ static int32_t taosMergeSortHelper(void *src, int64_t numOfElem, int64_t size, c
|
||||||
const int32_t THRESHOLD_SIZE = 6;
|
const int32_t THRESHOLD_SIZE = 6;
|
||||||
char *buf = taosMemoryCalloc(1, size); // prepare the swap buffer
|
char *buf = taosMemoryCalloc(1, size); // prepare the swap buffer
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t start = 0; start < numOfElem - 1; start += THRESHOLD_SIZE) {
|
for (int32_t start = 0; start < numOfElem - 1; start += THRESHOLD_SIZE) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ int32_t base58_encode(const uint8_t *value, int32_t vlen, char **result) {
|
||||||
size = (pe - pb) * 69 / 50 + 1;
|
size = (pe - pb) * 69 / 50 + 1;
|
||||||
if (size > TBASE_BUF_SIZE) {
|
if (size > TBASE_BUF_SIZE) {
|
||||||
if (!(pbuf = taosMemoryCalloc(1, size))) {
|
if (!(pbuf = taosMemoryCalloc(1, size))) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
bfree = true;
|
bfree = true;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ int32_t base58_encode(const uint8_t *value, int32_t vlen, char **result) {
|
||||||
uint8_t *pResult = taosMemoryCalloc(1, nz + (pbuf + size - pi) + 1);
|
uint8_t *pResult = taosMemoryCalloc(1, nz + (pbuf + size - pi) + 1);
|
||||||
if (!pResult) {
|
if (!pResult) {
|
||||||
if (bfree) taosMemoryFree(pbuf);
|
if (bfree) taosMemoryFree(pbuf);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
(void)memset(pResult, '1', nz);
|
(void)memset(pResult, '1', nz);
|
||||||
while (pi != pbuf + size) pResult[nz++] = basis_58[*pi++];
|
while (pi != pbuf + size) pResult[nz++] = basis_58[*pi++];
|
||||||
|
@ -117,7 +117,7 @@ int32_t base58_decode(const char *value, size_t inlen, int32_t *outlen, uint8_t
|
||||||
size = (int32_t)(pe - pb) * 733 / 1000 + 1;
|
size = (int32_t)(pe - pb) * 733 / 1000 + 1;
|
||||||
if (size > TBASE_BUF_SIZE) {
|
if (size > TBASE_BUF_SIZE) {
|
||||||
if (!(pbuf = taosMemoryCalloc(1, size))) {
|
if (!(pbuf = taosMemoryCalloc(1, size))) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
bfree = true;
|
bfree = true;
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ int32_t base58_decode(const char *value, size_t inlen, int32_t *outlen, uint8_t
|
||||||
uint8_t *pResult = taosMemoryCalloc(1, nz + (pbuf + size - it) + 1);
|
uint8_t *pResult = taosMemoryCalloc(1, nz + (pbuf + size - it) + 1);
|
||||||
if (!pResult) {
|
if (!pResult) {
|
||||||
if (bfree) taosMemoryFree(pbuf);
|
if (bfree) taosMemoryFree(pbuf);
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)memset(pResult, 0, nz);
|
(void)memset(pResult, 0, nz);
|
||||||
|
|
|
@ -44,7 +44,7 @@ int32_t tBloomFilterInit(uint64_t expectedEntries, double errorRate, SBloomFilte
|
||||||
}
|
}
|
||||||
SBloomFilter* pBF = taosMemoryCalloc(1, sizeof(SBloomFilter));
|
SBloomFilter* pBF = taosMemoryCalloc(1, sizeof(SBloomFilter));
|
||||||
if (pBF == NULL) {
|
if (pBF == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
QUERY_CHECK_CODE(code, lino, _error);
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
}
|
}
|
||||||
pBF->expectedEntries = expectedEntries;
|
pBF->expectedEntries = expectedEntries;
|
||||||
|
@ -65,7 +65,7 @@ int32_t tBloomFilterInit(uint64_t expectedEntries, double errorRate, SBloomFilte
|
||||||
pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t));
|
pBF->buffer = taosMemoryCalloc(pBF->numUnits, sizeof(uint64_t));
|
||||||
if (pBF->buffer == NULL) {
|
if (pBF->buffer == NULL) {
|
||||||
tBloomFilterDestroy(pBF);
|
tBloomFilterDestroy(pBF);
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
QUERY_CHECK_CODE(code, lino, _error);
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
}
|
}
|
||||||
(*ppBF) = pBF;
|
(*ppBF) = pBF;
|
||||||
|
@ -152,7 +152,7 @@ int32_t tBloomFilterDecode(SDecoder* pDecoder, SBloomFilter** ppBF) {
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
SBloomFilter* pBF = taosMemoryCalloc(1, sizeof(SBloomFilter));
|
SBloomFilter* pBF = taosMemoryCalloc(1, sizeof(SBloomFilter));
|
||||||
if (!pBF) {
|
if (!pBF) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
QUERY_CHECK_CODE(code, lino, _error);
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
}
|
}
|
||||||
pBF->buffer = NULL;
|
pBF->buffer = NULL;
|
||||||
|
|
|
@ -1227,8 +1227,8 @@ static void checkRegexCache(void* param, void* tmrId) {
|
||||||
if(sRegexCache.exit) {
|
if(sRegexCache.exit) {
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
bool ret = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
|
bool stopped = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
|
||||||
if (!ret) {
|
if (stopped) {
|
||||||
uError("failed to reset regex cache timer");
|
uError("failed to reset regex cache timer");
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ extern char **environ;
|
||||||
int32_t cfgInit(SConfig **ppCfg) {
|
int32_t cfgInit(SConfig **ppCfg) {
|
||||||
SConfig *pCfg = taosMemoryCalloc(1, sizeof(SConfig));
|
SConfig *pCfg = taosMemoryCalloc(1, sizeof(SConfig));
|
||||||
if (pCfg == NULL) {
|
if (pCfg == NULL) {
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
pCfg->array = taosArrayInit(32, sizeof(SConfigItem));
|
pCfg->array = taosArrayInit(32, sizeof(SConfigItem));
|
||||||
|
@ -136,7 +136,7 @@ static int32_t cfgCheckAndSetConf(SConfigItem *pItem, const char *conf) {
|
||||||
static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
|
static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) {
|
||||||
char fullDir[PATH_MAX] = {0};
|
char fullDir[PATH_MAX] = {0};
|
||||||
if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) {
|
if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) {
|
||||||
int32_t code = TAOS_SYSTEM_ERROR(errno);
|
int32_t code = terrno;
|
||||||
uError("failed to expand dir:%s since %s", inputDir, tstrerror(code));
|
uError("failed to expand dir:%s since %s", inputDir, tstrerror(code));
|
||||||
TAOS_RETURN(code);
|
TAOS_RETURN(code);
|
||||||
}
|
}
|
||||||
|
@ -1009,7 +1009,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) {
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!taosEOFFile(pFile)) {
|
while (!taosEOFFile(pFile)) {
|
||||||
|
@ -1066,7 +1066,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) {
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
// success when the file does not exist
|
// success when the file does not exist
|
||||||
code = TAOS_SYSTEM_ERROR(errno);
|
code = terrno;
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
uInfo("failed to load from cfg file %s since %s, use default parameters", filepath, tstrerror(code));
|
uInfo("failed to load from cfg file %s since %s, use default parameters", filepath, tstrerror(code));
|
||||||
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
TAOS_RETURN(TSDB_CODE_SUCCESS);
|
||||||
|
@ -1252,14 +1252,19 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) {
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
|
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno));
|
TAOS_CHECK_EXIT(terrno);
|
||||||
}
|
}
|
||||||
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
|
size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END);
|
||||||
|
if(fileSize <= 0) {
|
||||||
|
(void)taosCloseFile(&pFile);
|
||||||
|
(void)printf("load json file error: %s\n", filepath);
|
||||||
|
TAOS_CHECK_EXIT(terrno);
|
||||||
|
}
|
||||||
char *buf = taosMemoryMalloc(fileSize + 1);
|
char *buf = taosMemoryMalloc(fileSize + 1);
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
(void)taosCloseFile(&pFile);
|
(void)taosCloseFile(&pFile);
|
||||||
(void)printf("load json file error: %s, failed to alloc memory\n", filepath);
|
(void)printf("load json file error: %s, failed to alloc memory\n", filepath);
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
buf[fileSize] = 0;
|
buf[fileSize] = 0;
|
||||||
|
@ -1453,7 +1458,7 @@ struct SConfigIter {
|
||||||
int32_t cfgCreateIter(SConfig *pConf, SConfigIter **ppIter) {
|
int32_t cfgCreateIter(SConfig *pConf, SConfigIter **ppIter) {
|
||||||
SConfigIter *pIter = taosMemoryCalloc(1, sizeof(SConfigIter));
|
SConfigIter *pIter = taosMemoryCalloc(1, sizeof(SConfigIter));
|
||||||
if (pIter == NULL) {
|
if (pIter == NULL) {
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
pIter->pConf = pConf;
|
pIter->pConf = pConf;
|
||||||
|
|
|
@ -850,6 +850,7 @@ static void tsSortError(void) {
|
||||||
taosSort(errors, sizeof(errors) / sizeof(errors[0]), sizeof(errors[0]), taosCompareTaosError);
|
taosSort(errors, sizeof(errors) / sizeof(errors[0]), sizeof(errors[0]), taosCompareTaosError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char WinAPIErrDesc[256] = {0};
|
||||||
const char* tstrerror(int32_t err) {
|
const char* tstrerror(int32_t err) {
|
||||||
(void)taosThreadOnce(&tsErrorInit, tsSortError);
|
(void)taosThreadOnce(&tsErrorInit, tsSortError);
|
||||||
|
|
||||||
|
@ -860,6 +861,15 @@ const char* tstrerror(int32_t err) {
|
||||||
// invalid code return Unknown error
|
// invalid code return Unknown error
|
||||||
return strerror(code);
|
return strerror(code);
|
||||||
}
|
}
|
||||||
|
#ifdef WINDOWS
|
||||||
|
if ((err & 0x01ff0000) == 0x01ff0000) {
|
||||||
|
snprintf(WinAPIErrDesc, 256, "windows api error, code: 0x%08x", err & 0x0000ffff);
|
||||||
|
return WinAPIErrDesc;
|
||||||
|
} else if ((err & 0x02ff0000) == 0x02ff0000) {
|
||||||
|
snprintf(WinAPIErrDesc, 256, "windows socket error, code: 0x%08x", err & 0x0000ffff);
|
||||||
|
return WinAPIErrDesc;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
int32_t s = 0;
|
int32_t s = 0;
|
||||||
int32_t e = sizeof(errors) / sizeof(errors[0]);
|
int32_t e = sizeof(errors) / sizeof(errors[0]);
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ int32_t getThreadLocalGeosCtx(SGeosContext **ppCtx) {
|
||||||
|
|
||||||
SGeosContext *tlGeosCtxObj = (SGeosContext *)taosMemoryCalloc(1, sizeof(SGeosContext));
|
SGeosContext *tlGeosCtxObj = (SGeosContext *)taosMemoryCalloc(1, sizeof(SGeosContext));
|
||||||
if (!tlGeosCtxObj) {
|
if (!tlGeosCtxObj) {
|
||||||
TAOS_CHECK_EXIT(TSDB_CODE_OUT_OF_MEMORY);
|
TAOS_CHECK_EXIT(terrno);
|
||||||
}
|
}
|
||||||
if ((taosThreadSetSpecific(tlGeosCtxKey, (const void *)tlGeosCtxObj)) != 0) {
|
if ((taosThreadSetSpecific(tlGeosCtxKey, (const void *)tlGeosCtxObj)) != 0) {
|
||||||
taosMemoryFreeClear(tlGeosCtxObj);
|
taosMemoryFreeClear(tlGeosCtxObj);
|
||||||
|
|
|
@ -320,7 +320,7 @@ int32_t tjsonMakeObject(const SJson* pJson, const char* pName, FToObject func, v
|
||||||
}
|
}
|
||||||
*pObj = taosMemoryCalloc(1, objSize);
|
*pObj = taosMemoryCalloc(1, objSize);
|
||||||
if (NULL == *pObj) {
|
if (NULL == *pObj) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
return func(pJsonObj, *pObj);
|
return func(pJsonObj, *pObj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ int32_t tdListPrepend(SList *list, void *data) {
|
||||||
int32_t tdListAppend(SList *list, const void *data) {
|
int32_t tdListAppend(SList *list, const void *data) {
|
||||||
SListNode *node = (SListNode *)taosMemoryCalloc(1, sizeof(SListNode) + list->eleSize);
|
SListNode *node = (SListNode *)taosMemoryCalloc(1, sizeof(SListNode) + list->eleSize);
|
||||||
if (node == NULL) {
|
if (node == NULL) {
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy((void *)(node->data), data, list->eleSize);
|
memcpy((void *)(node->data), data, list->eleSize);
|
||||||
|
|
|
@ -207,7 +207,7 @@ int32_t taosInitSlowLog() {
|
||||||
tsLogObj.slowHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
tsLogObj.slowHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
if (tsLogObj.slowHandle->pFile == NULL) {
|
if (tsLogObj.slowHandle->pFile == NULL) {
|
||||||
(void)printf("\nfailed to open slow log file:%s, reason:%s\n", name, strerror(errno));
|
(void)printf("\nfailed to open slow log file:%s, reason:%s\n", name, strerror(errno));
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -539,15 +539,15 @@ static int32_t taosInitNormalLog(const char *logName, int32_t maxFileNum) {
|
||||||
tsLogObj.logHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE);
|
tsLogObj.logHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE);
|
||||||
if (tsLogObj.logHandle->pFile == NULL) {
|
if (tsLogObj.logHandle->pFile == NULL) {
|
||||||
(void)printf("\nfailed to open log file:%s, reason:%s\n", name, strerror(errno));
|
(void)printf("\nfailed to open log file:%s, reason:%s\n", name, strerror(errno));
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
(void)taosLockLogFile(tsLogObj.logHandle->pFile);
|
(void)taosLockLogFile(tsLogObj.logHandle->pFile);
|
||||||
|
|
||||||
// only an estimate for number of lines
|
// only an estimate for number of lines
|
||||||
int64_t filesize = 0;
|
int64_t filesize = 0;
|
||||||
if (taosFStatFile(tsLogObj.logHandle->pFile, &filesize, NULL) < 0) {
|
if (taosFStatFile(tsLogObj.logHandle->pFile, &filesize, NULL) != 0) {
|
||||||
(void)printf("\nfailed to fstat log file:%s, reason:%s\n", name, strerror(errno));
|
(void)printf("\nfailed to fstat log file:%s, reason:%s\n", name, strerror(errno));
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
tsLogObj.lines = (int32_t)(filesize / 60);
|
tsLogObj.lines = (int32_t)(filesize / 60);
|
||||||
|
|
||||||
|
@ -973,7 +973,6 @@ void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, vo
|
||||||
|
|
||||||
pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
taosPrintLog(flags, level, dflag, "failed to open file:%s since %s", filepath, terrstr());
|
taosPrintLog(flags, level, dflag, "failed to open file:%s since %s", filepath, terrstr());
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
@ -1003,7 +1002,6 @@ _return:
|
||||||
|
|
||||||
if (pFile) (void)taosCloseFile(&pFile);
|
if (pFile) (void)taosCloseFile(&pFile);
|
||||||
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
taosPrintLog(flags, level, dflag, "crash signal is %d", signum);
|
taosPrintLog(flags, level, dflag, "crash signal is %d", signum);
|
||||||
|
|
||||||
#ifdef _TD_DARWIN_64
|
#ifdef _TD_DARWIN_64
|
||||||
|
@ -1030,11 +1028,10 @@ 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, NULL) < 0) {
|
if (taosStatFile(filepath, &filesize, NULL, NULL) < 0) {
|
||||||
if (ENOENT == errno) {
|
if (TAOS_SYSTEM_ERROR(ENOENT) == terrno) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
taosPrintLog(flags, level, dflag, "failed to stat file:%s since %s", filepath, terrstr());
|
taosPrintLog(flags, level, dflag, "failed to stat file:%s since %s", filepath, terrstr());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1049,7 +1046,6 @@ void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
taosPrintLog(flags, level, dflag, "failed to open file:%s since %s", filepath, terrstr());
|
taosPrintLog(flags, level, dflag, "failed to open file:%s since %s", filepath, terrstr());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,7 @@ static int taosLRUEntryTableInit(SLRUEntryTable *table, int maxUpperHashBits) {
|
||||||
table->lengthBits = 4;
|
table->lengthBits = 4;
|
||||||
table->list = taosMemoryCalloc(1 << table->lengthBits, sizeof(SLRUEntry *));
|
table->list = taosMemoryCalloc(1 << table->lengthBits, sizeof(SLRUEntry *));
|
||||||
if (!table->list) {
|
if (!table->list) {
|
||||||
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
|
TAOS_RETURN(terrno);
|
||||||
}
|
}
|
||||||
|
|
||||||
table->elems = 0;
|
table->elems = 0;
|
||||||
|
|
|
@ -64,7 +64,7 @@ static int32_t createDiskFile(SDiskbasedBuf* pBuf) {
|
||||||
pBuf->pFile =
|
pBuf->pFile =
|
||||||
taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL);
|
taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL);
|
||||||
if (pBuf->pFile == NULL) {
|
if (pBuf->pFile == NULL) {
|
||||||
return TAOS_SYSTEM_ERROR(errno);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
|
@ -136,13 +136,12 @@ static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) { return pageSize
|
||||||
static int32_t doFlushBufPageImpl(SDiskbasedBuf* pBuf, int64_t offset, const char* pData, int32_t size) {
|
static int32_t doFlushBufPageImpl(SDiskbasedBuf* pBuf, int64_t offset, const char* pData, int32_t size) {
|
||||||
int32_t ret = taosLSeekFile(pBuf->pFile, offset, SEEK_SET);
|
int32_t ret = taosLSeekFile(pBuf->pFile, offset, SEEK_SET);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = terrno;
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = (int32_t)taosWriteFile(pBuf->pFile, pData, size);
|
ret = (int32_t)taosWriteFile(pBuf->pFile, pData, size);
|
||||||
if (ret != size) {
|
if (ret != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
return terrno;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,14 +248,14 @@ static int32_t loadPageFromDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) {
|
||||||
|
|
||||||
int32_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET);
|
int32_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET);
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
ret = TAOS_SYSTEM_ERROR(errno);
|
ret = terrno;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* pPage = (void*)GET_PAYLOAD_DATA(pg);
|
void* pPage = (void*)GET_PAYLOAD_DATA(pg);
|
||||||
ret = (int32_t)taosReadFile(pBuf->pFile, pPage, pg->length);
|
ret = (int32_t)taosReadFile(pBuf->pFile, pPage, pg->length);
|
||||||
if (ret != pg->length) {
|
if (ret != pg->length) {
|
||||||
ret = TAOS_SYSTEM_ERROR(errno);
|
ret = terrno;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ void taosSetQueueCapacity(STaosQueue *queue, int64_t size) { queue->itemLimit =
|
||||||
int32_t taosOpenQueue(STaosQueue **queue) {
|
int32_t taosOpenQueue(STaosQueue **queue) {
|
||||||
*queue = taosMemoryCalloc(1, sizeof(STaosQueue));
|
*queue = taosMemoryCalloc(1, sizeof(STaosQueue));
|
||||||
if (*queue == NULL) {
|
if (*queue == NULL) {
|
||||||
return (terrno = TSDB_CODE_OUT_OF_MEMORY);
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code = taosThreadMutexInit(&(*queue)->mutex, NULL);
|
int32_t code = taosThreadMutexInit(&(*queue)->mutex, NULL);
|
||||||
|
@ -162,7 +162,7 @@ int32_t taosAllocateQitem(int32_t size, EQItype itype, int64_t dataSize, void **
|
||||||
STaosQnode *pNode = taosMemoryCalloc(1, sizeof(STaosQnode) + size);
|
STaosQnode *pNode = taosMemoryCalloc(1, sizeof(STaosQnode) + size);
|
||||||
if (pNode == NULL) {
|
if (pNode == NULL) {
|
||||||
(void)atomic_sub_fetch_64(&tsQueueMemoryUsed, size + dataSize);
|
(void)atomic_sub_fetch_64(&tsQueueMemoryUsed, size + dataSize);
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
pNode->dataSize = dataSize;
|
pNode->dataSize = dataSize;
|
||||||
|
@ -260,7 +260,7 @@ int32_t taosReadQitem(STaosQueue *queue, void **ppItem) {
|
||||||
int32_t taosAllocateQall(STaosQall **qall) {
|
int32_t taosAllocateQall(STaosQall **qall) {
|
||||||
*qall = taosMemoryCalloc(1, sizeof(STaosQall));
|
*qall = taosMemoryCalloc(1, sizeof(STaosQall));
|
||||||
if (*qall == NULL) {
|
if (*qall == NULL) {
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -333,7 +333,7 @@ int32_t taosGetQitem(STaosQall *qall, void **ppItem) {
|
||||||
int32_t taosOpenQset(STaosQset **qset) {
|
int32_t taosOpenQset(STaosQset **qset) {
|
||||||
*qset = taosMemoryCalloc(sizeof(STaosQset), 1);
|
*qset = taosMemoryCalloc(sizeof(STaosQset), 1);
|
||||||
if (*qset == NULL) {
|
if (*qset == NULL) {
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosThreadMutexInit(&(*qset)->mutex, NULL);
|
(void)taosThreadMutexInit(&(*qset)->mutex, NULL);
|
||||||
|
|
|
@ -67,13 +67,13 @@ int32_t taosOpenRef(int32_t max, RefFp fp) {
|
||||||
|
|
||||||
nodeList = taosMemoryCalloc(sizeof(SRefNode *), (size_t)max);
|
nodeList = taosMemoryCalloc(sizeof(SRefNode *), (size_t)max);
|
||||||
if (nodeList == NULL) {
|
if (nodeList == NULL) {
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
lockedBy = taosMemoryCalloc(sizeof(int64_t), (size_t)max);
|
lockedBy = taosMemoryCalloc(sizeof(int64_t), (size_t)max);
|
||||||
if (lockedBy == NULL) {
|
if (lockedBy == NULL) {
|
||||||
taosMemoryFree(nodeList);
|
taosMemoryFree(nodeList);
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosThreadMutexLock(&tsRefMutex);
|
(void)taosThreadMutexLock(&tsRefMutex);
|
||||||
|
@ -157,7 +157,7 @@ int64_t taosAddRef(int32_t rsetId, void *p) {
|
||||||
|
|
||||||
pNode = taosMemoryCalloc(sizeof(SRefNode), 1);
|
pNode = taosMemoryCalloc(sizeof(SRefNode), 1);
|
||||||
if (pNode == NULL) {
|
if (pNode == NULL) {
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
rid = atomic_add_fetch_64(&pSet->rid, 1);
|
rid = atomic_add_fetch_64(&pSet->rid, 1);
|
||||||
|
|
|
@ -38,7 +38,7 @@ int32_t tScalableBfInit(uint64_t expectedEntries, double errorRate, SScalableBf*
|
||||||
}
|
}
|
||||||
SScalableBf* pSBf = taosMemoryCalloc(1, sizeof(SScalableBf));
|
SScalableBf* pSBf = taosMemoryCalloc(1, sizeof(SScalableBf));
|
||||||
if (pSBf == NULL) {
|
if (pSBf == NULL) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
QUERY_CHECK_CODE(code, lino, _error);
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
}
|
}
|
||||||
pSBf->maxBloomFilters = DEFAULT_MAX_BLOOMFILTERS;
|
pSBf->maxBloomFilters = DEFAULT_MAX_BLOOMFILTERS;
|
||||||
|
@ -218,7 +218,7 @@ int32_t tScalableBfDecode(SDecoder* pDecoder, SScalableBf** ppSBf) {
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
SScalableBf* pSBf = taosMemoryCalloc(1, sizeof(SScalableBf));
|
SScalableBf* pSBf = taosMemoryCalloc(1, sizeof(SScalableBf));
|
||||||
if (!pSBf) {
|
if (!pSBf) {
|
||||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
code = terrno;
|
||||||
QUERY_CHECK_CODE(code, lino, _error);
|
QUERY_CHECK_CODE(code, lino, _error);
|
||||||
}
|
}
|
||||||
pSBf->hashFn1 = HASH_FUNCTION_1;
|
pSBf->hashFn1 = HASH_FUNCTION_1;
|
||||||
|
|
|
@ -31,7 +31,7 @@ int32_t tQWorkerInit(SQWorkerPool *pool) {
|
||||||
pool->workers = taosMemoryCalloc(pool->max, sizeof(SQueueWorker));
|
pool->workers = taosMemoryCalloc(pool->max, sizeof(SQueueWorker));
|
||||||
if (pool->workers == NULL) {
|
if (pool->workers == NULL) {
|
||||||
taosCloseQset(pool->qset);
|
taosCloseQset(pool->qset);
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosThreadMutexInit(&pool->mutex, NULL);
|
(void)taosThreadMutexInit(&pool->mutex, NULL);
|
||||||
|
@ -310,7 +310,7 @@ int32_t tWWorkerInit(SWWorkerPool *pool) {
|
||||||
pool->nextId = 0;
|
pool->nextId = 0;
|
||||||
pool->workers = taosMemoryCalloc(pool->max, sizeof(SWWorker));
|
pool->workers = taosMemoryCalloc(pool->max, sizeof(SWWorker));
|
||||||
if (pool->workers == NULL) {
|
if (pool->workers == NULL) {
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)taosThreadMutexInit(&pool->mutex, NULL);
|
(void)taosThreadMutexInit(&pool->mutex, NULL);
|
||||||
|
@ -459,7 +459,7 @@ int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg)
|
||||||
case QWORKER_POOL: {
|
case QWORKER_POOL: {
|
||||||
SQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQWorkerPool));
|
SQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQWorkerPool));
|
||||||
if (!pPool) {
|
if (!pPool) {
|
||||||
return terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return terrno;
|
||||||
}
|
}
|
||||||
pPool->name = pCfg->name;
|
pPool->name = pCfg->name;
|
||||||
pPool->min = pCfg->min;
|
pPool->min = pCfg->min;
|
||||||
|
@ -477,7 +477,7 @@ int32_t tSingleWorkerInit(SSingleWorker *pWorker, const SSingleWorkerCfg *pCfg)
|
||||||
case QUERY_AUTO_QWORKER_POOL: {
|
case QUERY_AUTO_QWORKER_POOL: {
|
||||||
SQueryAutoQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQueryAutoQWorkerPool));
|
SQueryAutoQWorkerPool *pPool = taosMemoryCalloc(1, sizeof(SQueryAutoQWorkerPool));
|
||||||
if (!pPool) {
|
if (!pPool) {
|
||||||
return (terrno = TSDB_CODE_OUT_OF_MEMORY);
|
return terrno;
|
||||||
}
|
}
|
||||||
pPool->name = pCfg->name;
|
pPool->name = pCfg->name;
|
||||||
pPool->min = pCfg->min;
|
pPool->min = pCfg->min;
|
||||||
|
@ -812,7 +812,7 @@ int32_t tQueryAutoQWorkerInit(SQueryAutoQWorkerPool *pool) {
|
||||||
|
|
||||||
if (!pool->pCb) {
|
if (!pool->pCb) {
|
||||||
pool->pCb = taosMemoryCalloc(1, sizeof(SQueryAutoQWorkerPoolCB));
|
pool->pCb = taosMemoryCalloc(1, sizeof(SQueryAutoQWorkerPoolCB));
|
||||||
if (!pool->pCb) return TSDB_CODE_OUT_OF_MEMORY;
|
if (!pool->pCb) return terrno;
|
||||||
pool->pCb->pPool = pool;
|
pool->pCb->pPool = pool;
|
||||||
pool->pCb->beforeBlocking = tQueryAutoQWorkerBeforeBlocking;
|
pool->pCb->beforeBlocking = tQueryAutoQWorkerBeforeBlocking;
|
||||||
pool->pCb->afterRecoverFromBlocking = tQueryAutoQWorkerRecoverFromBlocking;
|
pool->pCb->afterRecoverFromBlocking = tQueryAutoQWorkerRecoverFromBlocking;
|
||||||
|
|
|
@ -1453,6 +1453,7 @@
|
||||||
,,y,script,./test.sh -f tsim/compute/diff2.sim
|
,,y,script,./test.sh -f tsim/compute/diff2.sim
|
||||||
,,y,script,./test.sh -f tsim/compute/first.sim
|
,,y,script,./test.sh -f tsim/compute/first.sim
|
||||||
,,y,script,./test.sh -f tsim/compute/interval.sim
|
,,y,script,./test.sh -f tsim/compute/interval.sim
|
||||||
|
,,y,script,./test.sh -f tsim/compute/interval1.sim
|
||||||
,,y,script,./test.sh -f tsim/compute/last_row.sim
|
,,y,script,./test.sh -f tsim/compute/last_row.sim
|
||||||
,,y,script,./test.sh -f tsim/compute/last.sim
|
,,y,script,./test.sh -f tsim/compute/last.sim
|
||||||
,,y,script,./test.sh -f tsim/compute/leastsquare.sim
|
,,y,script,./test.sh -f tsim/compute/leastsquare.sim
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/cfg.sh -n dnode1 -c timezone -v UTC
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
|
||||||
|
sql CREATE DATABASE `alphacloud_alphaess` BUFFER 512 CACHESIZE 1024 CACHEMODEL 'both' COMP 2 DURATION 10d WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 KEEP 365000d;
|
||||||
|
|
||||||
|
sql use alphacloud_alphaess;
|
||||||
|
|
||||||
|
sql create stable st(ts TIMESTAMP ENCODE 'delta-i' COMPRESS 'lz4' LEVEL 'medium', `uk` VARCHAR(64) ENCODE 'disabled' COMPRESS 'lz4' LEVEL 'medium' PRIMARY KEY ) tags(ta int,tb int,tc int);
|
||||||
|
|
||||||
|
sql create table t1 using st tags(1,1,1);
|
||||||
|
|
||||||
|
sql insert into t1 values ("1970-01-29 05:04:53.000"," 22:: ");
|
||||||
|
|
||||||
|
sql select _wstart, count(*) from st interval(1y);
|
||||||
|
|
||||||
|
if $rows != 1 then
|
||||||
|
print =====rows=$rows
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
print $data00 $data01 $data02 $data03
|
||||||
|
print $data10 $data11 $data12 $data13
|
||||||
|
|
||||||
|
if $data01 != 1 then
|
||||||
|
print =====data00=$data00
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
|
@ -72,10 +72,10 @@ endi
|
||||||
if $data5_db != on then # strict
|
if $data5_db != on then # strict
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data6_db != 345600m then # duration
|
if $data6_db != 240d then # duration
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data7_db != 1440000m,1440000m,1440000m then # keep
|
if $data7_db != 1000d,1000d,1000d then # keep
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data8_db != 256 then # buffer
|
if $data8_db != 256 then # buffer
|
||||||
|
@ -220,7 +220,7 @@ print ============== modify keep
|
||||||
sql alter database db keep 2400
|
sql alter database db keep 2400
|
||||||
sql select * from information_schema.ins_databases
|
sql select * from information_schema.ins_databases
|
||||||
print keep $data7_db
|
print keep $data7_db
|
||||||
if $data7_db != 3456000m,3456000m,3456000m then
|
if $data7_db != 2400d,2400d,2400d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,10 @@ endi
|
||||||
if $data24 != 1 then
|
if $data24 != 1 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data26 != 2880m then
|
if $data26 != 2d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 14400m,14400m,14400m then
|
if $data27 != 10d,10d,10d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
#if $data28 != 32 then
|
#if $data28 != 32 then
|
||||||
|
@ -78,7 +78,7 @@ endi
|
||||||
if $data24 != 1 then
|
if $data24 != 1 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data26 != 21600m then
|
if $data26 != 15d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
|
@ -92,10 +92,10 @@ endi
|
||||||
if $data5_db != on then # strict
|
if $data5_db != on then # strict
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data6_db != 14400m then # duration
|
if $data6_db != 10d then # duration
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data7_db != 5256000m,5256000m,5256000m then # keep
|
if $data7_db != 3650d,3650d,3650d then # keep
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data8_db != 256 then # buffer
|
if $data8_db != 256 then # buffer
|
||||||
|
|
|
@ -45,7 +45,7 @@ print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07
|
||||||
if $data22 != 2 then
|
if $data22 != 2 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 86400m,86400m,86400m then
|
if $data27 != 60d,60d,60d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $data22 != 2 then
|
if $data22 != 2 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 43200m,43200m,43200m then
|
if $data27 != 30d,30d,30d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 30240m,30240m,30240m then
|
if $data27 != 21d,21d,21d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql alter database $db keep 11,12
|
sql alter database $db keep 11,12
|
||||||
|
@ -48,7 +48,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 15840m,17280m,17280m then
|
if $data27 != 11d,12d,12d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql alter database $db keep 20,20,20
|
sql alter database $db keep 20,20,20
|
||||||
|
@ -56,7 +56,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 28800m,28800m,28800m then
|
if $data27 != 20d,20d,20d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql alter database $db keep 10,10,10
|
sql alter database $db keep 10,10,10
|
||||||
|
@ -64,7 +64,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 14400m,14400m,14400m then
|
if $data27 != 10d,10d,10d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql alter database $db keep 10,10,11
|
sql alter database $db keep 10,10,11
|
||||||
|
@ -72,7 +72,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 14400m,14400m,15840m then
|
if $data27 != 10d,10d,11d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql alter database $db keep 11,12,13
|
sql alter database $db keep 11,12,13
|
||||||
|
@ -80,7 +80,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 15840m,17280m,18720m then
|
if $data27 != 11d,12d,13d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql alter database $db keep 365000,365000,365000
|
sql alter database $db keep 365000,365000,365000
|
||||||
|
@ -88,7 +88,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 525600000m,525600000m,525600000m then
|
if $data27 != 365000d,365000d,365000d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 28800m,28800m,28800m then
|
if $data27 != 20d,20d,20d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 28800m,28800m,28800m then
|
if $data27 != 20d,20d,20d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql alter database $db keep 10
|
sql alter database $db keep 10
|
||||||
|
@ -57,7 +57,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 14400m,14400m,14400m then
|
if $data27 != 10d,10d,10d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql alter database $db keep 11
|
sql alter database $db keep 11
|
||||||
|
@ -65,7 +65,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 15840m,15840m,15840m then
|
if $data27 != 11d,11d,11d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql alter database $db keep 13
|
sql alter database $db keep 13
|
||||||
|
@ -73,7 +73,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 18720m,18720m,18720m then
|
if $data27 != 13d,13d,13d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql alter database $db keep 365000
|
sql alter database $db keep 365000
|
||||||
|
@ -81,7 +81,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 525600000m,525600000m,525600000m then
|
if $data27 != 365000d,365000d,365000d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
|
@ -118,10 +118,10 @@ endi
|
||||||
if $data24 != $replica then
|
if $data24 != $replica then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data26 != 14400m then
|
if $data26 != 10d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 525600m,525600m,525600m then
|
if $data27 != 365d,365d,365d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 56160m,56160m,56160m then
|
if $data27 != 39d,39d,39d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql drop database dbk0
|
sql drop database dbk0
|
||||||
|
@ -164,7 +164,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 56160m,57600m,57600m then
|
if $data27 != 39d,40d,40d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql drop database dbka
|
sql drop database dbka
|
||||||
|
@ -174,7 +174,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 15840m,15840m,15840m then
|
if $data27 != 11d,11d,11d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql drop database dbk1
|
sql drop database dbk1
|
||||||
|
@ -183,7 +183,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 15840m,17280m,18720m then
|
if $data27 != 11d,12d,13d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql drop database dbk2
|
sql drop database dbk2
|
||||||
|
@ -192,7 +192,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 15840m,15840m,18720m then
|
if $data27 != 11d,11d,13d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql drop database dbk3
|
sql drop database dbk3
|
||||||
|
@ -201,7 +201,7 @@ sql select * from information_schema.ins_databases
|
||||||
if $rows != 3 then
|
if $rows != 3 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
if $data27 != 15840m,18720m,18720m then
|
if $data27 != 11d,13d,13d then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql drop database dbk4
|
sql drop database dbk4
|
||||||
|
|
|
@ -89,7 +89,7 @@ if $data10 != @ -> Merge (columns=3 width=24 input_order=unknown output_order=
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql explain select count(*), last_row(f1), min(f1) from sta interval(1s);
|
sql explain select count(*), last_row(f1), min(f1) from sta interval(1s);
|
||||||
if $data10 != @ -> Merge (columns=4 width=82 input_order=asc output_order=asc mode=sort)@ then
|
if $data10 != @ -> Merge (columns=4 width=106 input_order=asc output_order=asc mode=sort)@ then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql explain select distinct count(*), last_row(f1), min(f1) from tba1;
|
sql explain select distinct count(*), last_row(f1), min(f1) from tba1;
|
||||||
|
|
Loading…
Reference in New Issue