Merge remote-tracking branch 'origin/3.0' into fix/mnode
This commit is contained in:
commit
8bfbc0f315
|
@ -46,7 +46,7 @@ ENDIF ()
|
|||
|
||||
IF (TD_WINDOWS)
|
||||
MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}")
|
||||
SET(COMMON_FLAGS "/w /D_WIN32")
|
||||
SET(COMMON_FLAGS "/w /D_WIN32 /Zi")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
|
||||
# IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900))
|
||||
# SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18")
|
||||
|
|
|
@ -146,5 +146,6 @@ option(
|
|||
option(
|
||||
BUILD_WITH_INVERTEDINDEX
|
||||
"If use invertedIndex"
|
||||
ON
|
||||
OFF
|
||||
)
|
||||
|
||||
|
|
|
@ -100,8 +100,10 @@ endif(${BUILD_WITH_NURAFT})
|
|||
|
||||
# addr2line
|
||||
if(${BUILD_ADDR2LINE})
|
||||
if(NOT ${TD_WINDOWS})
|
||||
cat("${TD_SUPPORT_DIR}/libdwarf_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
cat("${TD_SUPPORT_DIR}/addr2line_CMakeLists.txt.in" ${CONTRIB_TMP_FILE})
|
||||
endif(NOT ${TD_WINDOWS})
|
||||
endif(${BUILD_ADDR2LINE})
|
||||
|
||||
# download dependencies
|
||||
|
@ -335,6 +337,7 @@ endif(${BUILD_WITH_SQLITE})
|
|||
|
||||
# addr2line
|
||||
if(${BUILD_ADDR2LINE})
|
||||
if(NOT ${TD_WINDOWS})
|
||||
check_include_file( "sys/types.h" HAVE_SYS_TYPES_H)
|
||||
check_include_file( "sys/stat.h" HAVE_SYS_STAT_H )
|
||||
check_include_file( "inttypes.h" HAVE_INTTYPES_H )
|
||||
|
@ -374,6 +377,7 @@ if(${BUILD_ADDR2LINE})
|
|||
add_library(addr2line STATIC "addr2line/addr2line.c")
|
||||
target_link_libraries(addr2line PUBLIC libdwarf dl z)
|
||||
target_include_directories(addr2line PUBLIC "libdwarf/src/lib/libdwarf" )
|
||||
endif(NOT ${TD_WINDOWS})
|
||||
endif(${BUILD_ADDR2LINE})
|
||||
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ TDengine 提供了丰富的应用程序开发接口,为了便于用户快速
|
|||
关键不同点在于:
|
||||
|
||||
1. 使用 REST 连接,用户无需安装客户端驱动程序 taosc,具有跨平台易用的优势,但性能要下降 30%左右。
|
||||
2. 使用原生连接可以体验 TDengine 的全部功能,如[参数绑定接口](/reference/connector/cpp#参数绑定-api)、[订阅](reference/connector/cpp#数据订阅接口)等等。
|
||||
2. 使用原生连接可以体验 TDengine 的全部功能,如[参数绑定接口](/reference/connector/cpp#参数绑定-api)、[订阅](/reference/connector/cpp#订阅和消费-api)等等。
|
||||
|
||||
## 安装客户端驱动 taosc
|
||||
|
||||
|
|
|
@ -20,21 +20,21 @@ CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep] [DAYS days] [UPDATE 1];
|
|||
3. 数据库名最大长度为 33;
|
||||
4. 一条 SQL 语句的最大长度为 65480 个字符;
|
||||
5. 创建数据库时可用的参数有:
|
||||
- cache: [Description](/reference/config/#cache)
|
||||
- blocks: [Description](/reference/config/#blocks)
|
||||
- days: [Description](/reference/config/#days)
|
||||
- keep: [Description](/reference/config/#keep)
|
||||
- minRows: [Description](/reference/config/#minrows)
|
||||
- maxRows: [Description](/reference/config/#maxrows)
|
||||
- wal: [Description](/reference/config/#wallevel)
|
||||
- fsync: [Description](/reference/config/#fsync)
|
||||
- update: [Description](/reference/config/#update)
|
||||
- cacheLast: [Description](/reference/config/#cachelast)
|
||||
- replica: [Description](/reference/config/#replica)
|
||||
- quorum: [Description](/reference/config/#quorum)
|
||||
- maxVgroupsPerDb: [Description](/reference/config/#maxvgroupsperdb)
|
||||
- comp: [Description](/reference/config/#comp)
|
||||
- precision: [Description](/reference/config/#precision)
|
||||
- cache: [详细说明](/reference/config/#cache)
|
||||
- blocks: [详细说明](/reference/config/#blocks)
|
||||
- days: [详细说明](/reference/config/#days)
|
||||
- keep: [详细说明](/reference/config/#keep)
|
||||
- minRows: [详细说明](/reference/config/#minrows)
|
||||
- maxRows: [详细说明](/reference/config/#maxrows)
|
||||
- wal: [详细说明](/reference/config/#wallevel)
|
||||
- fsync: [详细说明](/reference/config/#fsync)
|
||||
- update: [详细说明](/reference/config/#update)
|
||||
- cacheLast: [详细说明](/reference/config/#cachelast)
|
||||
- replica: [详细说明](/reference/config/#replica)
|
||||
- quorum: [详细说明](/reference/config/#quorum)
|
||||
- maxVgroupsPerDb: [详细说明](/reference/config/#maxvgroupsperdb)
|
||||
- comp: [详细说明](/reference/config/#comp)
|
||||
- precision: [详细说明](/reference/config/#precision)
|
||||
6. 请注意上面列出的所有参数都可以配置在配置文件 `taosd.cfg` 中作为创建数据库时使用的默认配置, `create database` 的参数中明确指定的会覆盖配置文件中的设置。
|
||||
|
||||
:::
|
||||
|
|
|
@ -18,7 +18,7 @@ import CSAsyncQuery from "../../07-develop/04-query-data/_cs_async.mdx"
|
|||
|
||||
`TDengine.Connector` 是 TDengine 提供的 C# 语言连接器。C# 开发人员可以通过它开发存取 TDengine 集群数据的 C# 应用软件。
|
||||
|
||||
`TDengine.Connector` 连接器支持通过 TDengine 客户端驱动(taosc)建立与 TDengine 运行实例的连接,提供数据写入、查询、订阅、schemaless 数据写入、参数绑定接口数据写入等功能 `TDengine.Connector` 目前暂未提供 REST 连接方式,用户可以参考 [RESTful APIs](https://docs.taosdata.com//reference/restful-api/) 文档自行编写。
|
||||
`TDengine.Connector` 连接器支持通过 TDengine 客户端驱动(taosc)建立与 TDengine 运行实例的连接,提供数据写入、查询、订阅、schemaless 数据写入、参数绑定接口数据写入等功能 `TDengine.Connector` 目前暂未提供 REST 连接方式,用户可以参考 [REST API](/reference/rest-api/) 文档自行编写。
|
||||
|
||||
本文介绍如何在 Linux 或 Windows 环境中安装 `TDengine.Connector`,并通过 `TDengine.Connector` 连接 TDengine 集群,进行数据写入、查询等基本操作。
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ Either way, same or similar APIs are provided by connectors to access database o
|
|||
Key differences:
|
||||
|
||||
1. With REST connection, it's not necessary to install TDengine client driver (taosc), it's more friendly for cross-platform with the cost of 30% performance downgrade. When taosc has an upgrade, application does not need to make changes.
|
||||
2. With native connection, full compatibility of TDengine can be utilized, like [Parameter Binding](/reference/connector/cpp#Parameter Binding-api), [Subscription](reference/connector/cpp#Subscription), etc. But taosc has to be installed, some platforms may not be supported.
|
||||
2. With native connection, full compatibility of TDengine can be utilized, like [Parameter Binding](/reference/connector/cpp#parameter-binding-api), [Subscription](/reference/connector/cpp#subscription-and-consumption-api), etc. But taosc has to be installed, some platforms may not be supported.
|
||||
|
||||
## Install Client Driver taosc
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ CREATE DATABASE [IF NOT EXISTS] db_name [KEEP keep] [DAYS days] [UPDATE 1];
|
|||
- quorum: [Description](/reference/config/#quorum)
|
||||
- maxVgroupsPerDb: [Description](/reference/config/#maxvgroupsperdb)
|
||||
- comp: [Description](/reference/config/#comp)
|
||||
- precision: [Description](reference/config/#precision)
|
||||
- precision: [Description](/reference/config/#precision)
|
||||
6. Please be noted that all of the parameters mentioned in this section can be configured in configuration file `taosd.cfg` at server side and used by default, can be override if they are specified in `create database` statement.
|
||||
|
||||
:::
|
||||
|
|
|
@ -19,7 +19,7 @@ import CSAsyncQuery from "../../07-develop/04-query-data/_cs_async.mdx"
|
|||
|
||||
`TDengine.Connector` is a C# language connector provided by TDengine that allows C# developers to develop C# applications that access TDengine cluster data.
|
||||
|
||||
The `TDengine.Connector` connector supports connect to TDengine instances via the TDengine client driver (taosc), providing data writing, querying, subscription, schemaless writing, bind interface, etc. The `TDengine.Connector` currently does not provide a REST connection interface. Developers can write their RESTful application by referring to the [RESTful APIs](https://docs.taosdata.com//reference/restful-api/) documentation.
|
||||
The `TDengine.Connector` connector supports connect to TDengine instances via the TDengine client driver (taosc), providing data writing, querying, subscription, schemaless writing, bind interface, etc. The `TDengine.Connector` currently does not provide a REST connection interface. Developers can write their RESTful application by referring to the [REST API](/reference/rest-api/) documentation.
|
||||
|
||||
This article describes how to install `TDengine.Connector` in a Linux or Windows environment and connect to TDengine clusters via `TDengine.Connector` to perform basic operations such as data writing and querying.
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ We will explain how to migrate OpenTSDB applications to TDengine quickly, secure
|
|||
The following figure (Figure 1) shows the system's overall architecture for a typical DevOps application scenario.
|
||||
|
||||
**Figure 1. Typical architecture in a DevOps scenario**
|
||||
Figure 1. [IT-DevOps-Solutions-Immigrate-OpenTSDB-Arch](/img/IT-DevOps-Solutions-Immigrate-OpenTSDB-Arch.jpg "Figure 1. Typical architecture in a DevOps scenario")
|
||||

|
||||
|
||||
In this application scenario, there are Agent tools deployed in the application environment to collect machine metrics, network metrics, and application metrics. Data collectors to aggregate information collected by agents, systems for persistent data storage and management, and tools for monitoring data visualization (e.g., Grafana, etc.).
|
||||
|
||||
|
@ -96,7 +96,7 @@ Suppose your application is particularly complex, or the application domain is n
|
|||
|
||||
This chapter describes the differences between OpenTSDB and TDengine at the system functionality level. After reading this chapter, you can fully evaluate whether you can migrate some complex OpenTSDB-based applications to TDengine, and what you should pay attention to after migration.
|
||||
|
||||
TDengine currently only supports Grafana for visual kanban rendering, so if your application uses front-end kanban boards other than Grafana (e.g., [TSDash](https://github.com/facebook/tsdash), [Status Wolf](https://github) .com/box/StatusWolf), etc.). You cannot directly migrate those front-end kanbans to TDengine, and the front-end kanban will need to be ported to Grafana to work correctly.
|
||||
TDengine currently only supports Grafana for visual kanban rendering, so if your application uses front-end kanban boards other than Grafana (e.g., [TSDash](https://github.com/facebook/tsdash), [Status Wolf](https://github.com/box/StatusWolf), etc.). You cannot directly migrate those front-end kanbans to TDengine, and the front-end kanban will need to be ported to Grafana to work correctly.
|
||||
|
||||
TDengine version 2.3.0.x only supports collectd and StatsD as data collection aggregation software but will provide more data collection aggregation software in the future. If you use other data aggregators on the collection side, your application needs to be ported to these two data aggregation systems to write data correctly.
|
||||
In addition to the two data aggregator software protocols mentioned above, TDengine also supports writing data directly via InfluxDB's line protocol and OpenTSDB's data writing protocol, JSON format. You can rewrite the logic on the data push side to write data using the line protocols supported by TDengine.
|
||||
|
|
|
@ -86,6 +86,11 @@ typedef enum {
|
|||
TSDB_RETENTION_MAX = 3
|
||||
} ERetentionLevel;
|
||||
|
||||
typedef enum {
|
||||
TSDB_BITMODE_DEFAULT = 0, // 2 bits
|
||||
TSDB_BITMODE_ONE_BIT = 1, // 1 bit
|
||||
} EBitmapMode;
|
||||
|
||||
extern char *qtypeStr[];
|
||||
|
||||
#define TSDB_PORT_HTTP 11
|
||||
|
|
|
@ -313,8 +313,9 @@ typedef struct {
|
|||
SDataCol *cols;
|
||||
} SDataCols;
|
||||
|
||||
static FORCE_INLINE bool tdDataColsIsBitmapI(SDataCols *pCols) { return pCols->bitmapMode != 0; }
|
||||
static FORCE_INLINE void tdDataColsSetBitmapI(SDataCols *pCols) { pCols->bitmapMode = 1; }
|
||||
static FORCE_INLINE bool tdDataColsIsBitmapI(SDataCols *pCols) { return pCols->bitmapMode != TSDB_BITMODE_DEFAULT; }
|
||||
static FORCE_INLINE void tdDataColsSetBitmapI(SDataCols *pCols) { pCols->bitmapMode = TSDB_BITMODE_ONE_BIT; }
|
||||
static FORCE_INLINE bool tdIsBitmapModeI(int8_t bitmapMode) { return bitmapMode != TSDB_BITMODE_DEFAULT; }
|
||||
|
||||
#define keyCol(pCols) (&((pCols)->cols[0])) // Key column
|
||||
#define dataColsTKeyAt(pCols, idx) ((TKEY *)(keyCol(pCols)->pData))[(idx)] // the idx row of column-wised data
|
||||
|
|
|
@ -1697,7 +1697,7 @@ int32_t tDecodeSRSmaParam(SDecoder* pCoder, SRSmaParam* pRSmaParam);
|
|||
|
||||
// TDMT_VND_CREATE_STB ==============
|
||||
typedef struct SVCreateStbReq {
|
||||
const char* name;
|
||||
char* name;
|
||||
tb_uid_t suid;
|
||||
int8_t rollup;
|
||||
SSchemaWrapper schema;
|
||||
|
@ -1710,7 +1710,7 @@ int tDecodeSVCreateStbReq(SDecoder* pCoder, SVCreateStbReq* pReq);
|
|||
|
||||
// TDMT_VND_DROP_STB ==============
|
||||
typedef struct SVDropStbReq {
|
||||
const char* name;
|
||||
char* name;
|
||||
tb_uid_t suid;
|
||||
} SVDropStbReq;
|
||||
|
||||
|
@ -1723,13 +1723,13 @@ typedef struct SVCreateTbReq {
|
|||
int32_t flags;
|
||||
tb_uid_t uid;
|
||||
int64_t ctime;
|
||||
const char* name;
|
||||
char* name;
|
||||
int32_t ttl;
|
||||
int8_t type;
|
||||
union {
|
||||
struct {
|
||||
tb_uid_t suid;
|
||||
const uint8_t* pTag;
|
||||
uint8_t* pTag;
|
||||
} ctb;
|
||||
struct {
|
||||
SSchemaWrapper schema;
|
||||
|
@ -1777,7 +1777,7 @@ int32_t tDeserializeSVCreateTbBatchRsp(void* buf, int32_t bufLen, SVCreateTbBatc
|
|||
|
||||
// TDMT_VND_DROP_TABLE =================
|
||||
typedef struct {
|
||||
const char* name;
|
||||
char* name;
|
||||
int8_t igNotExists;
|
||||
} SVDropTbReq;
|
||||
|
||||
|
@ -1809,9 +1809,9 @@ int32_t tDecodeSVDropTbBatchRsp(SDecoder* pCoder, SVDropTbBatchRsp* pRsp);
|
|||
|
||||
// TDMT_VND_ALTER_TABLE =====================
|
||||
typedef struct {
|
||||
const char* tbName;
|
||||
char* tbName;
|
||||
int8_t action;
|
||||
const char* colName;
|
||||
char* colName;
|
||||
// TSDB_ALTER_TABLE_ADD_COLUMN
|
||||
int8_t type;
|
||||
int8_t flags;
|
||||
|
@ -1820,17 +1820,17 @@ typedef struct {
|
|||
// TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES
|
||||
int32_t colModBytes;
|
||||
// TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME
|
||||
const char* colNewName;
|
||||
char* colNewName;
|
||||
// TSDB_ALTER_TABLE_UPDATE_TAG_VAL
|
||||
const char* tagName;
|
||||
char* tagName;
|
||||
int8_t isNull;
|
||||
uint32_t nTagVal;
|
||||
const uint8_t* pTagVal;
|
||||
uint8_t* pTagVal;
|
||||
// TSDB_ALTER_TABLE_UPDATE_OPTIONS
|
||||
int8_t updateTTL;
|
||||
int32_t newTTL;
|
||||
int8_t updateComment;
|
||||
const char* newComment;
|
||||
char* newComment;
|
||||
} SVAlterTbReq;
|
||||
|
||||
int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq);
|
||||
|
@ -2267,8 +2267,8 @@ typedef struct {
|
|||
int64_t interval;
|
||||
int64_t offset; // use unit by precision of DB
|
||||
int64_t sliding;
|
||||
const char* expr; // sma expression
|
||||
const char* tagsFilter;
|
||||
char* expr; // sma expression
|
||||
char* tagsFilter;
|
||||
} STSma; // Time-range-wise SMA
|
||||
|
||||
typedef STSma SVCreateTSmaReq;
|
||||
|
@ -2600,7 +2600,7 @@ typedef struct {
|
|||
int64_t uid;
|
||||
int32_t sver;
|
||||
uint32_t nData;
|
||||
const uint8_t* pData;
|
||||
uint8_t* pData;
|
||||
SVCreateTbReq cTbReq;
|
||||
} SVSubmitBlk;
|
||||
|
||||
|
|
|
@ -46,24 +46,34 @@ typedef enum {
|
|||
AUTH_TYPE_OTHER,
|
||||
} AUTH_TYPE;
|
||||
|
||||
typedef struct SUserAuthInfo {
|
||||
char user[TSDB_USER_LEN];
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
AUTH_TYPE type;
|
||||
} SUserAuthInfo;
|
||||
|
||||
typedef struct SCatalogReq {
|
||||
SArray *pTableName; // element is SNAME
|
||||
SArray *pUdf; // udf name
|
||||
SArray *pTableMeta; // element is SNAME
|
||||
SArray *pDbVgroup; // element is db full name
|
||||
SArray *pTableHash; // element is SNAME
|
||||
SArray *pUdf; // element is udf name
|
||||
SArray *pDbCfg; // element is db full name
|
||||
SArray *pIndex; // element is index name
|
||||
SArray *pUser; // element is SUserAuthInfo
|
||||
bool qNodeRequired; // valid qnode
|
||||
} SCatalogReq;
|
||||
|
||||
typedef struct SMetaData {
|
||||
SArray *pTableMeta; // STableMeta array
|
||||
SArray *pVgroupInfo; // SVgroupInfo list
|
||||
SArray *pUdfList; // udf info list
|
||||
SArray *pQnodeList; // qnode list, SArray<SQueryNodeAddr>
|
||||
SArray *pTableMeta; // SArray<STableMeta>
|
||||
SArray *pDbVgroup; // SArray<SArray<SVgroupInfo>*>
|
||||
SArray *pTableHash; // SArray<SVgroupInfo>
|
||||
SArray *pUdfList; // SArray<SFuncInfo>
|
||||
SArray *pDbCfg; // SArray<SDbCfgInfo>
|
||||
SArray *pIndex; // SArray<SIndexInfo>
|
||||
SArray *pUser; // SArray<bool>
|
||||
SArray *pQnodeList; // SArray<SQueryNodeAddr>
|
||||
} SMetaData;
|
||||
|
||||
typedef struct STbSVersion {
|
||||
char* tbFName;
|
||||
int32_t sver;
|
||||
} STbSVersion;
|
||||
|
||||
typedef struct SCatalogCfg {
|
||||
uint32_t maxTblCacheNum;
|
||||
uint32_t maxDBCacheNum;
|
||||
|
@ -88,6 +98,11 @@ typedef struct SDbVgVersion {
|
|||
int32_t numOfTable; // unit is TSDB_TABLE_NUM_UNIT
|
||||
} SDbVgVersion;
|
||||
|
||||
typedef struct STbSVersion {
|
||||
char* tbFName;
|
||||
int32_t sver;
|
||||
} STbSVersion;
|
||||
|
||||
typedef struct SUserAuthVersion {
|
||||
char user[TSDB_USER_LEN];
|
||||
int32_t version;
|
||||
|
@ -96,6 +111,8 @@ typedef struct SUserAuthVersion {
|
|||
typedef SDbCfgRsp SDbCfgInfo;
|
||||
typedef SUserIndexRsp SIndexInfo;
|
||||
|
||||
typedef void (*catalogCallback)(SMetaData* pResult, void* param, int32_t code);
|
||||
|
||||
int32_t catalogInit(SCatalogCfg *cfg);
|
||||
|
||||
/**
|
||||
|
@ -131,7 +148,7 @@ int32_t catalogUpdateDBVgInfo(SCatalog* pCatalog, const char* dbName, uint64_t d
|
|||
|
||||
int32_t catalogRemoveDB(SCatalog* pCatalog, const char* dbName, uint64_t dbId);
|
||||
|
||||
int32_t catalogRemoveTableMeta(SCatalog* pCtg, const SName* pTableName);
|
||||
int32_t catalogRemoveTableMeta(SCatalog* pCtg, SName* pTableName);
|
||||
|
||||
int32_t catalogRemoveStbMeta(SCatalog* pCtg, const char* dbFName, uint64_t dbId, const char* stbName, uint64_t suid);
|
||||
|
||||
|
@ -241,9 +258,9 @@ int32_t catalogGetExpiredUsers(SCatalog* pCtg, SUserAuthVersion **users, uint32_
|
|||
|
||||
int32_t catalogGetDBCfg(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* dbFName, SDbCfgInfo* pDbCfg);
|
||||
|
||||
int32_t catalogGetIndexInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* indexName, SIndexInfo* pInfo);
|
||||
int32_t catalogGetIndexMeta(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* indexName, SIndexInfo* pInfo);
|
||||
|
||||
int32_t catalogGetUdfInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* funcName, SFuncInfo** pInfo);
|
||||
int32_t catalogGetUdfInfo(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* funcName, SFuncInfo* pInfo);
|
||||
|
||||
int32_t catalogChkAuth(SCatalog* pCtg, void *pRpc, const SEpSet* pMgmtEps, const char* user, const char* dbFName, AUTH_TYPE type, bool *pass);
|
||||
|
||||
|
|
|
@ -31,6 +31,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS
|
||||
#define TD_TMP_DIR_PATH "C:\\Windows\\Temp\\"
|
||||
#else
|
||||
#define TD_TMP_DIR_PATH "/tmp/"
|
||||
#endif
|
||||
|
||||
typedef struct TdDir *TdDirPtr;
|
||||
typedef struct TdDirEntry *TdDirEntryPtr;
|
||||
|
||||
|
|
|
@ -419,6 +419,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_TQ_META_KEY_NOT_IN_TXN TAOS_DEF_ERROR_CODE(0, 0x0A09)
|
||||
#define TSDB_CODE_TQ_META_KEY_DUP_IN_TXN TAOS_DEF_ERROR_CODE(0, 0x0A0A)
|
||||
#define TSDB_CODE_TQ_GROUP_NOT_SET TAOS_DEF_ERROR_CODE(0, 0x0A0B)
|
||||
#define TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0A0B)
|
||||
|
||||
// wal
|
||||
#define TSDB_CODE_WAL_APP_ERROR TAOS_DEF_ERROR_CODE(0, 0x1000)
|
||||
|
@ -636,6 +637,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_COMMENT_TOO_LONG TAOS_DEF_ERROR_CODE(0, 0x264E)
|
||||
#define TSDB_CODE_PAR_NOT_ALLOWED_FUNC TAOS_DEF_ERROR_CODE(0, 0x264F)
|
||||
#define TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY TAOS_DEF_ERROR_CODE(0, 0x2650)
|
||||
#define TSDB_CODE_PAR_INVALID_DROP_COL TAOS_DEF_ERROR_CODE(0, 0x2651)
|
||||
|
||||
//planner
|
||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||
|
|
|
@ -39,7 +39,7 @@ typedef struct {
|
|||
} SEncoder;
|
||||
|
||||
typedef struct {
|
||||
const uint8_t* data;
|
||||
uint8_t* data;
|
||||
uint32_t size;
|
||||
uint32_t pos;
|
||||
SCoderMem* mList;
|
||||
|
@ -120,7 +120,7 @@ static int32_t tEncodeCStrWithLen(SEncoder* pCoder, const char* val, uint32_t le
|
|||
static int32_t tEncodeCStr(SEncoder* pCoder, const char* val);
|
||||
|
||||
/* ------------------------ DECODE ------------------------ */
|
||||
void tDecoderInit(SDecoder* pCoder, const uint8_t* data, uint32_t size);
|
||||
void tDecoderInit(SDecoder* pCoder, uint8_t* data, uint32_t size);
|
||||
void tDecoderClear(SDecoder* SDecoder);
|
||||
int32_t tStartDecode(SDecoder* pCoder);
|
||||
void tEndDecode(SDecoder* pCoder);
|
||||
|
@ -141,9 +141,9 @@ static int32_t tDecodeU64v(SDecoder* pCoder, uint64_t* val);
|
|||
static int32_t tDecodeI64v(SDecoder* pCoder, int64_t* val);
|
||||
static int32_t tDecodeFloat(SDecoder* pCoder, float* val);
|
||||
static int32_t tDecodeDouble(SDecoder* pCoder, double* val);
|
||||
static int32_t tDecodeBinary(SDecoder* pCoder, const uint8_t** val, uint32_t* len);
|
||||
static int32_t tDecodeCStrAndLen(SDecoder* pCoder, const char** val, uint32_t* len);
|
||||
static int32_t tDecodeCStr(SDecoder* pCoder, const char** val);
|
||||
static int32_t tDecodeBinary(SDecoder* pCoder, uint8_t** val, uint32_t* len);
|
||||
static int32_t tDecodeCStrAndLen(SDecoder* pCoder, char** val, uint32_t* len);
|
||||
static int32_t tDecodeCStr(SDecoder* pCoder, char** val);
|
||||
static int32_t tDecodeCStrTo(SDecoder* pCoder, char* val);
|
||||
|
||||
/* ------------------------ IMPL ------------------------ */
|
||||
|
@ -377,7 +377,7 @@ static FORCE_INLINE int32_t tDecodeDouble(SDecoder* pCoder, double* val) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeBinary(SDecoder* pCoder, const uint8_t** val, uint32_t* len) {
|
||||
static FORCE_INLINE int32_t tDecodeBinary(SDecoder* pCoder, uint8_t** val, uint32_t* len) {
|
||||
if (tDecodeU32v(pCoder, len) < 0) return -1;
|
||||
|
||||
if (TD_CODER_CHECK_CAPACITY_FAILED(pCoder, *len)) return -1;
|
||||
|
@ -389,19 +389,19 @@ static FORCE_INLINE int32_t tDecodeBinary(SDecoder* pCoder, const uint8_t** val,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeCStrAndLen(SDecoder* pCoder, const char** val, uint32_t* len) {
|
||||
if (tDecodeBinary(pCoder, (const uint8_t**)val, len) < 0) return -1;
|
||||
static FORCE_INLINE int32_t tDecodeCStrAndLen(SDecoder* pCoder, char** val, uint32_t* len) {
|
||||
if (tDecodeBinary(pCoder, (uint8_t**)val, len) < 0) return -1;
|
||||
(*len) -= 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tDecodeCStr(SDecoder* pCoder, const char** val) {
|
||||
static FORCE_INLINE int32_t tDecodeCStr(SDecoder* pCoder, char** val) {
|
||||
uint32_t len;
|
||||
return tDecodeCStrAndLen(pCoder, val, &len);
|
||||
}
|
||||
|
||||
static int32_t tDecodeCStrTo(SDecoder* pCoder, char* val) {
|
||||
const char* pStr;
|
||||
char* pStr;
|
||||
uint32_t len;
|
||||
if (tDecodeCStrAndLen(pCoder, &pStr, &len) < 0) return -1;
|
||||
|
||||
|
|
|
@ -6,16 +6,36 @@
|
|||
set -e
|
||||
#set -x
|
||||
|
||||
verMode=edge
|
||||
pagMode=full
|
||||
|
||||
iplist=""
|
||||
serverFqdn=""
|
||||
|
||||
# -----------------------Variables definition---------------------
|
||||
script_dir=$(dirname $(readlink -f "$0"))
|
||||
# Dynamic directory
|
||||
data_dir="/var/lib/taos"
|
||||
log_dir="/var/log/taos"
|
||||
|
||||
data_link_dir="/usr/local/taos/data"
|
||||
log_link_dir="/usr/local/taos/log"
|
||||
clientName="taos"
|
||||
serverName="taosd"
|
||||
configFile="taos.cfg"
|
||||
productName="TDengine"
|
||||
emailName="taosdata.com"
|
||||
uninstallScript="rmtaos"
|
||||
historyFile="taos_history"
|
||||
tarName="taos.tar.gz"
|
||||
dataDir="/var/lib/taos"
|
||||
logDir="/var/log/taos"
|
||||
configDir="/etc/taos"
|
||||
installDir="/usr/local/taos"
|
||||
adapterName="taosadapter"
|
||||
benchmarkName="taosBenchmark"
|
||||
dumpName="taosdump"
|
||||
demoName="taosdemo"
|
||||
|
||||
cfg_install_dir="/etc/taos"
|
||||
data_dir=${dataDir}
|
||||
log_dir=${logDir}
|
||||
cfg_install_dir=${configDir}
|
||||
|
||||
bin_link_dir="/usr/bin"
|
||||
lib_link_dir="/usr/lib"
|
||||
|
@ -23,21 +43,13 @@ lib64_link_dir="/usr/lib64"
|
|||
inc_link_dir="/usr/include"
|
||||
|
||||
#install main path
|
||||
install_main_dir="/usr/local/taos"
|
||||
|
||||
install_main_dir=${installDir}
|
||||
# old bin dir
|
||||
bin_dir="/usr/local/taos/bin"
|
||||
bin_dir="${installDir}/bin"
|
||||
|
||||
service_config_dir="/etc/systemd/system"
|
||||
|
||||
#taos-tools para
|
||||
demoName="taosdemo"
|
||||
benchmarkName="taosBenchmark"
|
||||
dumpName="taosdump"
|
||||
emailName="taosdata.com"
|
||||
taosName="taos"
|
||||
toolsName="taostools"
|
||||
|
||||
nginx_port=6060
|
||||
nginx_dir="/usr/local/nginxd"
|
||||
|
||||
# Color setting
|
||||
RED='\033[0;31m'
|
||||
|
@ -74,7 +86,6 @@ else
|
|||
service_mod=2
|
||||
fi
|
||||
|
||||
|
||||
# get the operating system type for using the corresponding init file
|
||||
# ubuntu/debian(deb), centos/fedora(rpm), others: opensuse, redhat, ..., no verification
|
||||
#osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
|
||||
|
@ -110,11 +121,10 @@ else
|
|||
echo " osinfo: ${osinfo}"
|
||||
echo " This is an officially unverified linux system,"
|
||||
echo " if there are any problems with the installation and operation, "
|
||||
echo " please feel free to contact taosdata.com for support."
|
||||
echo " please feel free to contact ${emailName} for support."
|
||||
os_type=1
|
||||
fi
|
||||
|
||||
|
||||
# ============================= get input parameters =================================================
|
||||
|
||||
# install.sh -v [server | client] -e [yes | no] -i [systemd | service | ...]
|
||||
|
@ -124,8 +134,7 @@ interactiveFqdn=yes # [yes | no]
|
|||
verType=server # [server | client]
|
||||
initType=systemd # [systemd | service | ...]
|
||||
|
||||
while getopts "hv:e:i:" arg
|
||||
do
|
||||
while getopts "hv:e:i:" arg; do
|
||||
case $arg in
|
||||
e)
|
||||
#echo "interactiveFqdn=$OPTARG"
|
||||
|
@ -140,7 +149,7 @@ do
|
|||
initType=$(echo $OPTARG)
|
||||
;;
|
||||
h)
|
||||
echo "Usage: `basename $0` -v [server | client] -e [yes | no]"
|
||||
echo "Usage: $(basename $0) -v [server | client] -e [yes | no]"
|
||||
exit 0
|
||||
;;
|
||||
?) #unknow option
|
||||
|
@ -165,11 +174,11 @@ function install_main_path() {
|
|||
${csudo}mkdir -p ${install_main_dir}
|
||||
${csudo}mkdir -p ${install_main_dir}/cfg
|
||||
${csudo}mkdir -p ${install_main_dir}/bin
|
||||
${csudo} mkdir -p ${install_main_dir}/connector
|
||||
${csudo} mkdir -p ${install_main_dir}/lib
|
||||
# ${csudo}mkdir -p ${install_main_dir}/connector
|
||||
${csudo}mkdir -p ${install_main_dir}/driver
|
||||
${csudo}mkdir -p ${install_main_dir}/examples
|
||||
${csudo}mkdir -p ${install_main_dir}/include
|
||||
${csudo} mkdir -p ${install_main_dir}/init.d
|
||||
# ${csudo}mkdir -p ${install_main_dir}/init.d
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
${csudo}mkdir -p ${nginx_dir}
|
||||
fi
|
||||
|
@ -181,74 +190,139 @@ function install_main_path() {
|
|||
|
||||
function install_bin() {
|
||||
# Remove links
|
||||
${csudo} rm -f ${bin_link_dir}/taos || :
|
||||
${csudo} rm -f ${bin_link_dir}/taosd || :
|
||||
${csudo} rm -f ${bin_link_dir}/taosadapter || :
|
||||
${csudo} rm -f ${bin_link_dir}/create_table || :
|
||||
${csudo} rm -f ${bin_link_dir}/tmq_sim || :
|
||||
${csudo} rm -f ${bin_link_dir}/taosdump || :
|
||||
${csudo} rm -f ${bin_link_dir}/rmtaos || :
|
||||
#${csudo} rm -f ${bin_link_dir}/set_core || :
|
||||
${csudo}rm -f ${bin_link_dir}/${clientName} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${serverName} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${adapterName} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${uninstallScript} || :
|
||||
${csudo}rm -f ${bin_link_dir}/tarbitrator || :
|
||||
${csudo}rm -f ${bin_link_dir}/set_core || :
|
||||
${csudo}rm -f ${bin_link_dir}/run_${serverName}_and_${adapterName}.sh || :
|
||||
${csudo}rm -f ${bin_link_dir}/TDinsight.sh || :
|
||||
|
||||
${csudo}cp -r ${script_dir}/bin/* ${install_main_dir}/bin && ${csudo}chmod 0555 ${install_main_dir}/bin/*
|
||||
|
||||
#Make link
|
||||
[ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || :
|
||||
[ -x ${install_main_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || :
|
||||
[ -x ${install_main_dir}/bin/create_table ] && ${csudo} ln -s ${install_main_dir}/bin/create_table ${bin_link_dir}/create_table || :
|
||||
[ -x ${install_main_dir}/bin/tmq_sim ] && ${csudo} ln -s ${install_main_dir}/bin/tmq_sim ${bin_link_dir}/tmq_sim || :
|
||||
# [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || :
|
||||
# [ -x ${install_main_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || :
|
||||
[ -x ${install_main_dir}/bin/remove.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || :
|
||||
# [ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
|
||||
[ -x ${install_main_dir}/bin/${clientName} ] && ${csudo}ln -s ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName} || :
|
||||
[ -x ${install_main_dir}/bin/${serverName} ] && ${csudo}ln -s ${install_main_dir}/bin/${serverName} ${bin_link_dir}/${serverName} || :
|
||||
[ -x ${install_main_dir}/bin/${adapterName} ] && ${csudo}ln -s ${install_main_dir}/bin/${adapterName} ${bin_link_dir}/${adapterName} || :
|
||||
[ -x ${install_main_dir}/bin/${benchmarkName} ] && ${csudo}ln -s ${install_main_dir}/bin/${benchmarkName} ${bin_link_dir}/${demoName} || :
|
||||
[ -x ${install_main_dir}/bin/${benchmarkName} ] && ${csudo}ln -s ${install_main_dir}/bin/${benchmarkName} ${bin_link_dir}/${benchmarkName} || :
|
||||
[ -x ${install_main_dir}/bin/${dumpName} ] && ${csudo}ln -s ${install_main_dir}/bin/${dumpName} ${bin_link_dir}/${dumpName} || :
|
||||
[ -x ${install_main_dir}/bin/TDinsight.sh ] && ${csudo}ln -s ${install_main_dir}/bin/TDinsight.sh ${bin_link_dir}/TDinsight.sh || :
|
||||
[ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/${uninstallScript} || :
|
||||
[ -x ${install_main_dir}/bin/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
|
||||
[ -x ${install_main_dir}/bin/run_${serverName}_and_${adapterName}.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_${serverName}_and_${adapterName}.sh ${bin_link_dir}/run_${serverName}_and_${adapterName}.sh || :
|
||||
[ -x ${install_main_dir}/bin/tarbitrator ] && ${csudo}ln -s ${install_main_dir}/bin/tarbitrator ${bin_link_dir}/tarbitrator || :
|
||||
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
${csudo}cp -r ${script_dir}/nginxd/* ${nginx_dir} && ${csudo}chmod 0555 ${nginx_dir}/*
|
||||
${csudo}mkdir -p ${nginx_dir}/logs
|
||||
${csudo}chmod 777 ${nginx_dir}/sbin/nginx
|
||||
fi
|
||||
}
|
||||
|
||||
function install_lib() {
|
||||
# Remove links
|
||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
||||
${csudo} rm -f ${lib_link_dir}/libtdb.* || :
|
||||
${csudo} rm -f ${lib64_link_dir}/libtdb.* || :
|
||||
#${csudo}rm -rf ${v15_java_app_dir} || :
|
||||
${csudo}cp -rf ${script_dir}/driver/* ${install_main_dir}/driver && ${csudo}chmod 777 ${install_main_dir}/driver/*
|
||||
|
||||
${csudo} cp -rf ${script_dir}/lib/* ${install_main_dir}/lib && ${csudo} chmod 777 ${install_main_dir}/lib/*
|
||||
|
||||
${csudo} ln -s ${install_main_dir}/lib/libtaos.* ${lib_link_dir}/libtaos.so.1
|
||||
${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1
|
||||
${csudo}ln -s ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so
|
||||
|
||||
if [[ -d ${lib64_link_dir} && ! -e ${lib64_link_dir}/libtaos.so ]]; then
|
||||
${csudo} ln -s ${install_main_dir}/lib/libtaos.* ${lib64_link_dir}/libtaos.so.1 || :
|
||||
${csudo}ln -s ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 || :
|
||||
${csudo}ln -s ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so || :
|
||||
fi
|
||||
|
||||
${csudo}ldconfig
|
||||
}
|
||||
|
||||
function install_avro() {
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
avro_dir=${script_dir}/avro
|
||||
if [ -f "${avro_dir}/lib/libavro.so.23.0.0" ] && [ -d /usr/local/$1 ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/$1
|
||||
${csudo}/usr/bin/install -c -m 755 ${avro_dir}/lib/libavro.so.23.0.0 /usr/local/$1
|
||||
${csudo}ln -sf /usr/local/$1/libavro.so.23.0.0 /usr/local/$1/libavro.so.23
|
||||
${csudo}ln -sf /usr/local/$1/libavro.so.23 /usr/local/$1/libavro.so
|
||||
|
||||
${csudo}/usr/bin/install -c -d /usr/local/$1
|
||||
[ -f ${avro_dir}/lib/libavro.a ] &&
|
||||
${csudo}/usr/bin/install -c -m 755 ${avro_dir}/lib/libavro.a /usr/local/$1
|
||||
|
||||
if [ -d /etc/ld.so.conf.d ]; then
|
||||
echo "/usr/local/$1" | ${csudo}tee /etc/ld.so.conf.d/libavro.conf >/dev/null || echo -e "failed to write /etc/ld.so.conf.d/libavro.conf"
|
||||
${csudo}ldconfig
|
||||
else
|
||||
echo "/etc/ld.so.conf.d not found!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function install_jemalloc() {
|
||||
jemalloc_dir=${script_dir}/jemalloc
|
||||
|
||||
if [ -d ${jemalloc_dir} ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/bin
|
||||
|
||||
if [ -f ${jemalloc_dir}/bin/jemalloc-config ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc-config /usr/local/bin
|
||||
fi
|
||||
if [ -f ${jemalloc_dir}/bin/jemalloc.sh ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jemalloc.sh /usr/local/bin
|
||||
fi
|
||||
if [ -f ${jemalloc_dir}/bin/jeprof ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/bin/jeprof /usr/local/bin
|
||||
fi
|
||||
if [ -f ${jemalloc_dir}/include/jemalloc/jemalloc.h ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc
|
||||
${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/include/jemalloc/jemalloc.h /usr/local/include/jemalloc
|
||||
fi
|
||||
if [ -f ${jemalloc_dir}/lib/libjemalloc.so.2 ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/lib
|
||||
${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.so.2 /usr/local/lib
|
||||
${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so
|
||||
${csudo}/usr/bin/install -c -d /usr/local/lib
|
||||
if [ -f ${jemalloc_dir}/lib/libjemalloc.a ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc.a /usr/local/lib
|
||||
fi
|
||||
if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${jemalloc_dir}/lib/libjemalloc_pic.a /usr/local/lib
|
||||
fi
|
||||
if [ -f ${jemalloc_dir}/lib/libjemalloc_pic.a ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig
|
||||
${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig
|
||||
fi
|
||||
fi
|
||||
if [ -f ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc
|
||||
${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc
|
||||
fi
|
||||
if [ -f ${jemalloc_dir}/share/man/man3/jemalloc.3 ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/share/man/man3
|
||||
${csudo}/usr/bin/install -c -m 644 ${jemalloc_dir}/share/man/man3/jemalloc.3 /usr/local/share/man/man3
|
||||
fi
|
||||
|
||||
if [ -d /etc/ld.so.conf.d ]; then
|
||||
echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf >/dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf"
|
||||
${csudo}ldconfig
|
||||
else
|
||||
echo "/etc/ld.so.conf.d not found!"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function install_header() {
|
||||
${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || :
|
||||
${csudo}cp -f ${script_dir}/inc/* ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/*
|
||||
${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h
|
||||
# ${csudo} ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h
|
||||
${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h
|
||||
${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
|
||||
}
|
||||
|
||||
# temp install taosBenchmark
|
||||
function install_taosTools() {
|
||||
${csudo} rm -f ${bin_link_dir}/${benchmarkName} || :
|
||||
${csudo} rm -f ${bin_link_dir}/${dumpName} || :
|
||||
${csudo} rm -f ${bin_link_dir}/rm${toolsName} || :
|
||||
|
||||
${csudo} /usr/bin/install -c -m 755 ${script_dir}/bin/${dumpName} ${install_main_dir}/bin/${dumpName}
|
||||
${csudo} /usr/bin/install -c -m 755 ${script_dir}/bin/${benchmarkName} ${install_main_dir}/bin/${benchmarkName}
|
||||
${csudo} ln -sf ${install_main_dir}/bin/${benchmarkName} ${install_main_dir}/bin/${demoName}
|
||||
#Make link
|
||||
[[ -x ${install_main_dir}/bin/${benchmarkName} ]] && \
|
||||
${csudo} ln -s ${install_main_dir}/bin/${benchmarkName} ${bin_link_dir}/${benchmarkName} || :
|
||||
[[ -x ${install_main_dir}/bin/${demoName} ]] && \
|
||||
${csudo} ln -s ${install_main_dir}/bin/${demoName} ${bin_link_dir}/${demoName} || :
|
||||
[[ -x ${install_main_dir}/bin/${dumpName} ]] && \
|
||||
${csudo} ln -s ${install_main_dir}/bin/${dumpName} ${bin_link_dir}/${dumpName} || :
|
||||
}
|
||||
|
||||
function add_newHostname_to_hosts() {
|
||||
localIp="127.0.0.1"
|
||||
OLD_IFS="$IFS"
|
||||
|
@ -256,8 +330,7 @@ function add_newHostname_to_hosts() {
|
|||
iphost=$(cat /etc/hosts | grep $1 | awk '{print $1}')
|
||||
arr=($iphost)
|
||||
IFS="$OLD_IFS"
|
||||
for s in "${arr[@]}"
|
||||
do
|
||||
for s in "${arr[@]}"; do
|
||||
if [[ "$s" == "$localIp" ]]; then
|
||||
return
|
||||
fi
|
||||
|
@ -277,15 +350,12 @@ function set_hostname() {
|
|||
done
|
||||
|
||||
${csudo}hostname $newHostname || :
|
||||
retval=`echo $?`
|
||||
retval=$(echo $?)
|
||||
if [[ $retval != 0 ]]; then
|
||||
echo
|
||||
echo "set hostname fail!"
|
||||
return
|
||||
fi
|
||||
#echo -e -n "$(hostnamectl status --static)"
|
||||
#echo -e -n "$(hostnamectl status --transient)"
|
||||
#echo -e -n "$(hostnamectl status --pretty)"
|
||||
|
||||
#ubuntu/centos /etc/hostname
|
||||
if [[ -e /etc/hostname ]]; then
|
||||
|
@ -297,7 +367,7 @@ function set_hostname() {
|
|||
${csudo}sed -i -r "s/#*\s*(HOSTNAME=\s*).*/\1$newHostname/" /etc/sysconfig/network || :
|
||||
fi
|
||||
|
||||
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/taos.cfg
|
||||
${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$newHostname/" ${cfg_install_dir}/${configFile}
|
||||
serverFqdn=$newHostname
|
||||
|
||||
if [[ -e /etc/hosts ]]; then
|
||||
|
@ -311,8 +381,7 @@ function is_correct_ipaddr() {
|
|||
IFS=" "
|
||||
arr=($iplist)
|
||||
IFS="$OLD_IFS"
|
||||
for s in "${arr[@]}"
|
||||
do
|
||||
for s in "${arr[@]}"; do
|
||||
if [[ "$s" == "$newIp" ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
@ -332,7 +401,7 @@ function set_ipAsFqdn() {
|
|||
echo -e -n "${GREEN}Unable to get local ip, use 127.0.0.1${NC}"
|
||||
localFqdn="127.0.0.1"
|
||||
# Write the local FQDN to configuration file
|
||||
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg
|
||||
${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/${configFile}
|
||||
serverFqdn=$localFqdn
|
||||
echo
|
||||
return
|
||||
|
@ -349,12 +418,12 @@ function set_ipAsFqdn() {
|
|||
if [ ! -z "$localFqdn" ]; then
|
||||
# Check if correct ip address
|
||||
is_correct_ipaddr $localFqdn
|
||||
retval=`echo $?`
|
||||
retval=$(echo $?)
|
||||
if [[ $retval != 0 ]]; then
|
||||
read -p "Please choose an IP from local IP list:" localFqdn
|
||||
else
|
||||
# Write the local FQDN to configuration file
|
||||
${csudo} sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/taos.cfg
|
||||
${csudo}sed -i -r "s/#*\s*(fqdn\s*).*/\1$localFqdn/" ${cfg_install_dir}/${configFile}
|
||||
serverFqdn=$localFqdn
|
||||
break
|
||||
fi
|
||||
|
@ -373,8 +442,7 @@ function local_fqdn_check() {
|
|||
echo -e -n "${GREEN}It is strongly recommended to configure a hostname for this machine ${NC}"
|
||||
echo
|
||||
|
||||
while true
|
||||
do
|
||||
while true; do
|
||||
read -r -p "Set hostname now? [Y/n] " input
|
||||
if [ ! -n "$input" ]; then
|
||||
set_hostname
|
||||
|
@ -400,6 +468,74 @@ function local_fqdn_check() {
|
|||
fi
|
||||
}
|
||||
|
||||
function install_adapter_config() {
|
||||
if [ ! -f "${cfg_install_dir}/${adapterName}.toml" ]; then
|
||||
${csudo}mkdir -p ${cfg_install_dir}
|
||||
[ -f ${script_dir}/cfg/${adapterName}.toml ] && ${csudo}cp ${script_dir}/cfg/${adapterName}.toml ${cfg_install_dir}
|
||||
[ -f ${cfg_install_dir}/${adapterName}.toml ] && ${csudo}chmod 644 ${cfg_install_dir}/${adapterName}.toml
|
||||
fi
|
||||
|
||||
[ -f ${script_dir}/cfg/${adapterName}.toml ] &&
|
||||
${csudo}cp -f ${script_dir}/cfg/${adapterName}.toml ${cfg_install_dir}/${adapterName}.toml.new
|
||||
|
||||
[ -f ${cfg_install_dir}/${adapterName}.toml ] &&
|
||||
${csudo}ln -s ${cfg_install_dir}/${adapterName}.toml ${install_main_dir}/cfg/${adapterName}.toml
|
||||
|
||||
[ ! -z $1 ] && return 0 || : # only install client
|
||||
|
||||
}
|
||||
|
||||
function install_config() {
|
||||
|
||||
if [ ! -f "${cfg_install_dir}/${configFile}" ]; then
|
||||
${csudo}mkdir -p ${cfg_install_dir}
|
||||
[ -f ${script_dir}/cfg/${configFile} ] && ${csudo}cp ${script_dir}/cfg/${configFile} ${cfg_install_dir}
|
||||
${csudo}chmod 644 ${cfg_install_dir}/*
|
||||
fi
|
||||
|
||||
${csudo}cp -f ${script_dir}/cfg/${configFile} ${cfg_install_dir}/${configFile}.new
|
||||
${csudo}ln -s ${cfg_install_dir}/${configFile} ${install_main_dir}/cfg
|
||||
|
||||
[ ! -z $1 ] && return 0 || : # only install client
|
||||
|
||||
if ((${update_flag} == 1)); then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ "$interactiveFqdn" == "no" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local_fqdn_check
|
||||
|
||||
echo
|
||||
echo -e -n "${GREEN}Enter FQDN:port (like h1.${emailName}:6030) of an existing ${productName} cluster node to join${NC}"
|
||||
echo
|
||||
echo -e -n "${GREEN}OR leave it blank to build one${NC}:"
|
||||
read firstEp
|
||||
while true; do
|
||||
if [ ! -z "$firstEp" ]; then
|
||||
${csudo}sed -i -r "s/#*\s*(firstEp\s*).*/\1$firstEp/" ${cfg_install_dir}/${configFile}
|
||||
break
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
echo -e -n "${GREEN}Enter your email address for priority support or enter empty to skip${NC}: "
|
||||
read emailAddr
|
||||
while true; do
|
||||
if [ ! -z "$emailAddr" ]; then
|
||||
email_file="${install_main_dir}/email"
|
||||
${csudo}bash -c "echo $emailAddr > ${email_file}"
|
||||
break
|
||||
else
|
||||
break
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
function install_log() {
|
||||
${csudo}rm -rf ${log_dir} || :
|
||||
${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
|
||||
|
@ -413,13 +549,96 @@ function install_data() {
|
|||
${csudo}ln -s ${data_dir} ${install_main_dir}/data
|
||||
}
|
||||
|
||||
function clean_service_on_systemd() {
|
||||
taosd_service_config="${service_config_dir}/taosd.service"
|
||||
if systemctl is-active --quiet taosd; then
|
||||
echo "TDengine is running, stopping it..."
|
||||
${csudo} systemctl stop taosd &> /dev/null || echo &> /dev/null
|
||||
function install_connector() {
|
||||
[ -d "${script_dir}/connector/" ] && ${csudo}cp -rf ${script_dir}/connector/ ${install_main_dir}/
|
||||
}
|
||||
|
||||
function install_examples() {
|
||||
if [ -d ${script_dir}/examples ]; then
|
||||
${csudo}cp -rf ${script_dir}/examples/* ${install_main_dir}/examples
|
||||
fi
|
||||
${csudo} systemctl disable taosd &> /dev/null || echo &> /dev/null
|
||||
}
|
||||
|
||||
function clean_service_on_sysvinit() {
|
||||
if pidof ${serverName} &>/dev/null; then
|
||||
${csudo}service ${serverName} stop || :
|
||||
fi
|
||||
|
||||
if pidof tarbitrator &>/dev/null; then
|
||||
${csudo}service tarbitratord stop || :
|
||||
fi
|
||||
|
||||
if ((${initd_mod} == 1)); then
|
||||
if [ -e ${service_config_dir}/${serverName} ]; then
|
||||
${csudo}chkconfig --del ${serverName} || :
|
||||
fi
|
||||
|
||||
if [ -e ${service_config_dir}/tarbitratord ]; then
|
||||
${csudo}chkconfig --del tarbitratord || :
|
||||
fi
|
||||
elif ((${initd_mod} == 2)); then
|
||||
if [ -e ${service_config_dir}/${serverName} ]; then
|
||||
${csudo}insserv -r ${serverName} || :
|
||||
fi
|
||||
if [ -e ${service_config_dir}/tarbitratord ]; then
|
||||
${csudo}insserv -r tarbitratord || :
|
||||
fi
|
||||
elif ((${initd_mod} == 3)); then
|
||||
if [ -e ${service_config_dir}/${serverName} ]; then
|
||||
${csudo}update-rc.d -f ${serverName} remove || :
|
||||
fi
|
||||
if [ -e ${service_config_dir}/tarbitratord ]; then
|
||||
${csudo}update-rc.d -f tarbitratord remove || :
|
||||
fi
|
||||
fi
|
||||
|
||||
${csudo}rm -f ${service_config_dir}/${serverName} || :
|
||||
${csudo}rm -f ${service_config_dir}/tarbitratord || :
|
||||
|
||||
if $(which init &>/dev/null); then
|
||||
${csudo}init q || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_service_on_sysvinit() {
|
||||
clean_service_on_sysvinit
|
||||
sleep 1
|
||||
|
||||
if ((${os_type} == 1)); then
|
||||
# ${csudo}cp -f ${script_dir}/init.d/${serverName}.deb ${install_main_dir}/init.d/${serverName}
|
||||
${csudo}cp ${script_dir}/init.d/${serverName}.deb ${service_config_dir}/${serverName} && ${csudo}chmod a+x ${service_config_dir}/${serverName}
|
||||
# ${csudo}cp -f ${script_dir}/init.d/tarbitratord.deb ${install_main_dir}/init.d/tarbitratord
|
||||
${csudo}cp ${script_dir}/init.d/tarbitratord.deb ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord
|
||||
elif ((${os_type} == 2)); then
|
||||
# ${csudo}cp -f ${script_dir}/init.d/${serverName}.rpm ${install_main_dir}/init.d/${serverName}
|
||||
${csudo}cp ${script_dir}/init.d/${serverName}.rpm ${service_config_dir}/${serverName} && ${csudo}chmod a+x ${service_config_dir}/${serverName}
|
||||
# ${csudo}cp -f ${script_dir}/init.d/tarbitratord.rpm ${install_main_dir}/init.d/tarbitratord
|
||||
${csudo}cp ${script_dir}/init.d/tarbitratord.rpm ${service_config_dir}/tarbitratord && ${csudo}chmod a+x ${service_config_dir}/tarbitratord
|
||||
fi
|
||||
|
||||
if ((${initd_mod} == 1)); then
|
||||
${csudo}chkconfig --add ${serverName} || :
|
||||
${csudo}chkconfig --level 2345 ${serverName} on || :
|
||||
${csudo}chkconfig --add tarbitratord || :
|
||||
${csudo}chkconfig --level 2345 tarbitratord on || :
|
||||
elif ((${initd_mod} == 2)); then
|
||||
${csudo}insserv ${serverName} || :
|
||||
${csudo}insserv -d ${serverName} || :
|
||||
${csudo}insserv tarbitratord || :
|
||||
${csudo}insserv -d tarbitratord || :
|
||||
elif ((${initd_mod} == 3)); then
|
||||
${csudo}update-rc.d ${serverName} defaults || :
|
||||
${csudo}update-rc.d tarbitratord defaults || :
|
||||
fi
|
||||
}
|
||||
|
||||
function clean_service_on_systemd() {
|
||||
taosd_service_config="${service_config_dir}/${serverName}.service"
|
||||
if systemctl is-active --quiet ${serverName}; then
|
||||
echo "${productName} is running, stopping it..."
|
||||
${csudo}systemctl stop ${serverName} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${serverName} &>/dev/null || echo &>/dev/null
|
||||
${csudo}rm -f ${taosd_service_config}
|
||||
|
||||
tarbitratord_service_config="${service_config_dir}/tarbitratord.service"
|
||||
|
@ -433,7 +652,7 @@ function clean_service_on_systemd() {
|
|||
if [ "$verMode" == "cluster" ]; then
|
||||
nginx_service_config="${service_config_dir}/nginxd.service"
|
||||
if systemctl is-active --quiet nginxd; then
|
||||
echo "Nginx for TDengine is running, stopping it..."
|
||||
echo "Nginx for ${productName} is running, stopping it..."
|
||||
${csudo}systemctl stop nginxd &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable nginxd &>/dev/null || echo &>/dev/null
|
||||
|
@ -441,89 +660,277 @@ function clean_service_on_systemd() {
|
|||
fi
|
||||
}
|
||||
|
||||
# taos:2345:respawn:/etc/init.d/taosd start
|
||||
|
||||
function install_service_on_systemd() {
|
||||
clean_service_on_systemd
|
||||
|
||||
taosd_service_config="${service_config_dir}/taosd.service"
|
||||
${csudo} bash -c "echo '[Unit]' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'After=network-online.target taosadapter.service' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'Wants=network-online.target taosadapter.service' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'Restart=always' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}"
|
||||
#${csudo} bash -c "echo 'StartLimitIntervalSec=60s' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo '[Install]' >> ${taosd_service_config}"
|
||||
${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}"
|
||||
${csudo} systemctl enable taosd
|
||||
|
||||
[ -f ${script_dir}/cfg/${serverName}.service ] &&
|
||||
${csudo}cp ${script_dir}/cfg/${serverName}.service \
|
||||
${service_config_dir}/ || :
|
||||
${csudo}systemctl daemon-reload
|
||||
|
||||
${csudo}systemctl enable ${serverName}
|
||||
|
||||
[ -f ${script_dir}/cfg/tarbitratord.service ] &&
|
||||
${csudo}cp ${script_dir}/cfg/tarbitratord.service \
|
||||
${service_config_dir}/ || :
|
||||
${csudo}systemctl daemon-reload
|
||||
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
[ -f ${script_dir}/cfg/nginxd.service ] &&
|
||||
${csudo}cp ${script_dir}/cfg/nginxd.service \
|
||||
${service_config_dir}/ || :
|
||||
${csudo}systemctl daemon-reload
|
||||
|
||||
if ! ${csudo}systemctl enable nginxd &>/dev/null; then
|
||||
${csudo}systemctl daemon-reexec
|
||||
${csudo}systemctl enable nginxd
|
||||
fi
|
||||
${csudo}systemctl start nginxd
|
||||
fi
|
||||
}
|
||||
|
||||
function install_adapter_service() {
|
||||
if ((${service_mod} == 0)); then
|
||||
[ -f ${script_dir}/cfg/${adapterName}.service ] &&
|
||||
${csudo}cp ${script_dir}/cfg/${adapterName}.service \
|
||||
${service_config_dir}/ || :
|
||||
${csudo}systemctl daemon-reload
|
||||
fi
|
||||
}
|
||||
|
||||
function install_service() {
|
||||
# if ((${service_mod}==0)); then
|
||||
# install_service_on_systemd
|
||||
# elif ((${service_mod}==1)); then
|
||||
# install_service_on_sysvinit
|
||||
# else
|
||||
# # must manual stop taosd
|
||||
kill_process taosd
|
||||
# fi
|
||||
if ((${service_mod} == 0)); then
|
||||
install_service_on_systemd
|
||||
elif ((${service_mod} == 1)); then
|
||||
install_service_on_sysvinit
|
||||
else
|
||||
kill_process ${serverName}
|
||||
fi
|
||||
}
|
||||
|
||||
function install_config() {
|
||||
if [ ! -f ${cfg_install_dir}/${configFile} ]; then
|
||||
${csudo}mkdir -p ${cfg_install_dir}
|
||||
[ -f ${script_dir}/cfg/${configFile} ] && ${csudo}cp ${script_dir}/cfg/${configFile} ${cfg_install_dir}
|
||||
${csudo}chmod 644 ${cfg_install_dir}/*
|
||||
vercomp() {
|
||||
if [[ $1 == $2 ]]; then
|
||||
return 0
|
||||
fi
|
||||
local IFS=.
|
||||
local i ver1=($1) ver2=($2)
|
||||
# fill empty fields in ver1 with zeros
|
||||
for ((i = ${#ver1[@]}; i < ${#ver2[@]}; i++)); do
|
||||
ver1[i]=0
|
||||
done
|
||||
|
||||
for ((i = 0; i < ${#ver1[@]}; i++)); do
|
||||
if [[ -z ${ver2[i]} ]]; then
|
||||
# fill empty fields in ver2 with zeros
|
||||
ver2[i]=0
|
||||
fi
|
||||
if ((10#${ver1[i]} > 10#${ver2[i]})); then
|
||||
return 1
|
||||
fi
|
||||
if ((10#${ver1[i]} < 10#${ver2[i]})); then
|
||||
return 2
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
function is_version_compatible() {
|
||||
|
||||
curr_version=$(ls ${script_dir}/driver/libtaos.so* | awk -F 'libtaos.so.' '{print $2}')
|
||||
|
||||
if [ -f ${script_dir}/driver/vercomp.txt ]; then
|
||||
min_compatible_version=$(cat ${script_dir}/driver/vercomp.txt)
|
||||
else
|
||||
min_compatible_version=$(${script_dir}/bin/${serverName} -V | head -1 | cut -d ' ' -f 5)
|
||||
fi
|
||||
|
||||
${csudo}cp -f ${script_dir}/cfg/${configFile} ${install_main_dir}/cfg/${configFile}.org
|
||||
${csudo}ln -s ${cfg_install_dir}/${configFile} ${install_main_dir}/cfg
|
||||
exist_version=$(${installDir}/bin/${serverName} -V | head -1 | cut -d ' ' -f 3)
|
||||
vercomp $exist_version "2.0.16.0"
|
||||
case $? in
|
||||
2)
|
||||
prompt_force=1
|
||||
;;
|
||||
esac
|
||||
|
||||
vercomp $curr_version $min_compatible_version
|
||||
echo "" # avoid $? value not update
|
||||
|
||||
case $? in
|
||||
0) return 0 ;;
|
||||
1) return 0 ;;
|
||||
2) return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
function install_TDengine() {
|
||||
# Start to install
|
||||
echo -e "${GREEN}Start to install TDengine...${NC}"
|
||||
function updateProduct() {
|
||||
# Check if version compatible
|
||||
if ! is_version_compatible; then
|
||||
echo -e "${RED}Version incompatible${NC}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Start to update
|
||||
if [ ! -e ${tarName} ]; then
|
||||
echo "File ${tarName} does not exist"
|
||||
exit 1
|
||||
fi
|
||||
tar -zxf ${tarName}
|
||||
install_jemalloc
|
||||
|
||||
echo -e "${GREEN}Start to update ${productName}...${NC}"
|
||||
# Stop the service if running
|
||||
if pidof ${serverName} &>/dev/null; then
|
||||
if ((${service_mod} == 0)); then
|
||||
${csudo}systemctl stop ${serverName} || :
|
||||
elif ((${service_mod} == 1)); then
|
||||
${csudo}service ${serverName} stop || :
|
||||
else
|
||||
kill_process ${serverName}
|
||||
fi
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
if pidof nginx &>/dev/null; then
|
||||
if ((${service_mod} == 0)); then
|
||||
${csudo}systemctl stop nginxd || :
|
||||
elif ((${service_mod} == 1)); then
|
||||
${csudo}service nginxd stop || :
|
||||
else
|
||||
kill_process nginx
|
||||
fi
|
||||
sleep 1
|
||||
fi
|
||||
fi
|
||||
|
||||
install_main_path
|
||||
install_data
|
||||
|
||||
install_log
|
||||
install_header
|
||||
install_lib
|
||||
install_taosTools
|
||||
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
install_connector
|
||||
fi
|
||||
|
||||
install_examples
|
||||
if [ -z $1 ]; then
|
||||
install_bin
|
||||
install_service
|
||||
install_adapter_service
|
||||
install_config
|
||||
install_adapter_config
|
||||
|
||||
openresty_work=false
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
# Check if openresty is installed
|
||||
# Check if nginx is installed successfully
|
||||
if type curl &>/dev/null; then
|
||||
if curl -sSf http://127.0.0.1:${nginx_port} &>/dev/null; then
|
||||
echo -e "\033[44;32;1mNginx for ${productName} is updated successfully!${NC}"
|
||||
openresty_work=true
|
||||
else
|
||||
echo -e "\033[44;31;5mNginx for ${productName} does not work! Please try again!\033[0m"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
echo
|
||||
echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${cfg_install_dir}/${configFile}"
|
||||
echo -e "${GREEN_DARK}To configure Adapter (if has) ${NC}: edit ${cfg_install_dir}/${adapterName}.toml"
|
||||
if ((${service_mod} == 0)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
|
||||
elif ((${service_mod} == 1)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To start Adapter (if has)${NC}: ${adapterName} &${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ./${serverName}${NC}"
|
||||
fi
|
||||
|
||||
if [ ${openresty_work} = 'true' ]; then
|
||||
echo -e "${GREEN_DARK}To access ${productName} ${NC}: use ${GREEN_UNDERLINE}${clientName} -h $serverFqdn${NC} in shell OR from ${GREEN_UNDERLINE}http://127.0.0.1:${nginx_port}${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To access ${productName} ${NC}: use ${GREEN_UNDERLINE}${clientName} -h $serverFqdn${NC} in shell${NC}"
|
||||
fi
|
||||
|
||||
if ((${prompt_force} == 1)); then
|
||||
echo ""
|
||||
echo -e "${RED}Please run '${serverName} --force-keep-file' at first time for the exist ${productName} $exist_version!${NC}"
|
||||
fi
|
||||
echo
|
||||
echo -e "\033[44;32;1m${productName} is updated successfully!${NC}"
|
||||
else
|
||||
install_bin
|
||||
install_config
|
||||
|
||||
echo
|
||||
echo -e "\033[44;32;1m${productName} client is updated successfully!${NC}"
|
||||
fi
|
||||
|
||||
rm -rf $(tar -tf ${tarName} | grep -v "^\./$")
|
||||
}
|
||||
|
||||
function installProduct() {
|
||||
# Start to install
|
||||
if [ ! -e ${tarName} ]; then
|
||||
echo "File ${tarName} does not exist"
|
||||
exit 1
|
||||
fi
|
||||
tar -zxf ${tarName}
|
||||
|
||||
echo -e "${GREEN}Start to install ${productName}...${NC}"
|
||||
|
||||
install_main_path
|
||||
|
||||
if [ -z $1 ]; then
|
||||
install_data
|
||||
fi
|
||||
|
||||
install_log
|
||||
install_header
|
||||
install_lib
|
||||
install_jemalloc
|
||||
#install_avro lib
|
||||
#install_avro lib64
|
||||
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
install_connector
|
||||
fi
|
||||
install_examples
|
||||
|
||||
if [ -z $1 ]; then # install service and client
|
||||
# For installing new
|
||||
install_bin
|
||||
install_service
|
||||
install_adapter_service
|
||||
install_adapter_config
|
||||
|
||||
openresty_work=false
|
||||
if [ "$verMode" == "cluster" ]; then
|
||||
# Check if nginx is installed successfully
|
||||
if type curl &>/dev/null; then
|
||||
if curl -sSf http://127.0.0.1:${nginx_port} &>/dev/null; then
|
||||
echo -e "\033[44;32;1mNginx for ${productName} is installed successfully!${NC}"
|
||||
openresty_work=true
|
||||
else
|
||||
echo -e "\033[44;31;5mNginx for ${productName} does not work! Please try again!\033[0m"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
install_config
|
||||
|
||||
# Ask if to start the service
|
||||
#echo
|
||||
#echo -e "\033[44;32;1mTDengine is installed successfully!${NC}"
|
||||
echo
|
||||
echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg"
|
||||
echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${cfg_install_dir}/${configFile}"
|
||||
echo -e "${GREEN_DARK}To configure ${adapterName} (if has) ${NC}: edit ${cfg_install_dir}/${adapterName}.toml"
|
||||
if ((${service_mod} == 0)); then
|
||||
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
|
||||
elif ((${service_mod} == 1)); then
|
||||
echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To start TDengine ${NC}: taosd${NC}"
|
||||
echo -e "${GREEN_DARK}To start Adapter (if has)${NC}: ${adapterName} &${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${serverName}${NC}"
|
||||
fi
|
||||
|
||||
if [ ! -z "$firstEp" ]; then
|
||||
|
@ -535,39 +942,49 @@ function install_TDengine() {
|
|||
tmpPort=""
|
||||
fi
|
||||
if [[ "$tmpPort" != "" ]]; then
|
||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn -P $tmpPort${GREEN_DARK} to login into cluster, then${NC}"
|
||||
echo -e "${GREEN_DARK}To access ${productName} ${NC}: ${clientName} -h $tmpFqdn -P $tmpPort${GREEN_DARK} to login into cluster, then${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $tmpFqdn${GREEN_DARK} to login into cluster, then${NC}"
|
||||
echo -e "${GREEN_DARK}To access ${productName} ${NC}: ${clientName} -h $tmpFqdn${GREEN_DARK} to login into cluster, then${NC}"
|
||||
fi
|
||||
echo -e "${GREEN_DARK}execute ${NC}: create dnode 'newDnodeFQDN:port'; ${GREEN_DARK}to add this new node${NC}"
|
||||
echo
|
||||
elif [ ! -z "$serverFqdn" ]; then
|
||||
echo -e "${GREEN_DARK}To access TDengine ${NC}: taos -h $serverFqdn${GREEN_DARK} to login into TDengine server${NC}"
|
||||
echo -e "${GREEN_DARK}To access ${productName} ${NC}: ${clientName} -h $serverFqdn${GREEN_DARK} to login into ${productName} server${NC}"
|
||||
echo
|
||||
fi
|
||||
|
||||
echo -e "\033[44;32;1mTDengine is installed successfully!${NC}"
|
||||
echo -e "\033[44;32;1m${productName} is installed successfully!${NC}"
|
||||
echo
|
||||
else # Only install client
|
||||
install_bin
|
||||
install_config
|
||||
echo
|
||||
echo -e "\033[44;32;1mTDengine client is installed successfully!${NC}"
|
||||
echo -e "\033[44;32;1m${productName} client is installed successfully!${NC}"
|
||||
fi
|
||||
|
||||
touch ~/.taos_history
|
||||
touch ~/.${historyFile}
|
||||
rm -rf $(tar -tf ${tarName} | grep -v "^\./$")
|
||||
}
|
||||
|
||||
|
||||
## ==============================Main program starts from here============================
|
||||
serverFqdn=$(hostname)
|
||||
if [ "$verType" == "server" ]; then
|
||||
# Install server and client
|
||||
install_TDengine
|
||||
if [ -x ${bin_dir}/${serverName} ]; then
|
||||
update_flag=1
|
||||
updateProduct
|
||||
else
|
||||
installProduct
|
||||
fi
|
||||
elif [ "$verType" == "client" ]; then
|
||||
interactiveFqdn=no
|
||||
# Only install client
|
||||
install_TDengine client
|
||||
if [ -x ${bin_dir}/${clientName} ]; then
|
||||
update_flag=1
|
||||
updateProduct client
|
||||
else
|
||||
installProduct client
|
||||
fi
|
||||
else
|
||||
echo "please input correct verType"
|
||||
fi
|
||||
|
|
|
@ -121,7 +121,7 @@ struct SAppInstInfo {
|
|||
SCorEpSet mgmtEp;
|
||||
SInstanceSummary summary;
|
||||
SList* pConnList; // STscObj linked list
|
||||
int64_t clusterId;
|
||||
uint64_t clusterId;
|
||||
void* pTransporter;
|
||||
SAppHbMgr* pAppHbMgr;
|
||||
};
|
||||
|
@ -286,6 +286,8 @@ void initMsgHandleFp();
|
|||
TAOS* taos_connect_internal(const char* ip, const char* user, const char* pass, const char* auth, const char* db,
|
||||
uint16_t port, int connType);
|
||||
|
||||
SRequestObj* launchQuery(STscObj* pTscObj, const char* sql, int sqlLen);
|
||||
|
||||
int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtCallback* pStmtCb);
|
||||
|
||||
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList);
|
||||
|
|
|
@ -310,6 +310,8 @@ int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
|
|||
taosArrayDestroy(desc.subDesc);
|
||||
desc.subDesc = NULL;
|
||||
}
|
||||
} else {
|
||||
desc.subDesc = NULL;
|
||||
}
|
||||
|
||||
releaseRequest(*rid);
|
||||
|
|
|
@ -565,10 +565,32 @@ const char *taos_get_server_info(TAOS *taos) {
|
|||
|
||||
void taos_query_a(TAOS *taos, const char *sql, __taos_async_fn_t fp, void *param) {
|
||||
if (taos == NULL || sql == NULL) {
|
||||
// todo directly call fp
|
||||
fp(param, NULL, TSDB_CODE_INVALID_PARA);
|
||||
return;
|
||||
}
|
||||
|
||||
taos_query_l(taos, sql, (int32_t)strlen(sql));
|
||||
SRequestObj* pRequest = NULL;
|
||||
int32_t retryNum = 0;
|
||||
int32_t code = 0;
|
||||
|
||||
size_t sqlLen = strlen(sql);
|
||||
|
||||
while (retryNum++ < REQUEST_MAX_TRY_TIMES) {
|
||||
pRequest = launchQuery(taos, sql, sqlLen);
|
||||
if (pRequest == NULL || TSDB_CODE_SUCCESS == pRequest->code || !NEED_CLIENT_HANDLE_ERROR(pRequest->code)) {
|
||||
break;
|
||||
}
|
||||
|
||||
code = refreshMeta(taos, pRequest);
|
||||
if (code) {
|
||||
pRequest->code = code;
|
||||
break;
|
||||
}
|
||||
|
||||
destroyRequest(pRequest);
|
||||
}
|
||||
|
||||
fp(param, pRequest, code);
|
||||
}
|
||||
|
||||
void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
|
||||
|
|
|
@ -125,10 +125,10 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
struct SCatalog* pCatalog = NULL;
|
||||
|
||||
if (usedbRsp.vgVersion >= 0) {
|
||||
int32_t code1 = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||
uint64_t clusterId = pRequest->pTscObj->pAppInfo->clusterId;
|
||||
int32_t code1 = catalogGetHandle(clusterId, &pCatalog);
|
||||
if (code1 != TSDB_CODE_SUCCESS) {
|
||||
tscWarn("catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->pTscObj->pAppInfo->clusterId,
|
||||
tstrerror(code1));
|
||||
tscWarn("0x%" PRIx64 "catalogGetHandle failed, clusterId:%" PRIx64 ", error:%s", pRequest->requestId, clusterId, tstrerror(code1));
|
||||
} else {
|
||||
catalogRemoveDB(pCatalog, usedbRsp.db, usedbRsp.uid);
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ int32_t processUseDbRsp(void* param, const SDataBuf* pMsg, int32_t code) {
|
|||
if (output.dbVgroup) taosHashCleanup(output.dbVgroup->vgHash);
|
||||
taosMemoryFreeClear(output.dbVgroup);
|
||||
|
||||
tscError("failed to build use db output since %s", terrstr());
|
||||
tscError("0x%" PRIx64" failed to build use db output since %s", pRequest->requestId, terrstr());
|
||||
} else if (output.dbVgroup) {
|
||||
struct SCatalog* pCatalog = NULL;
|
||||
|
||||
|
|
|
@ -855,7 +855,7 @@ SDataCols *tdNewDataCols(int maxCols, int maxRows) {
|
|||
pCols->maxCols = maxCols;
|
||||
pCols->numOfRows = 0;
|
||||
pCols->numOfCols = 0;
|
||||
// pCols->bitmapMode = 0; // calloc already set 0
|
||||
pCols->bitmapMode = TSDB_BITMODE_DEFAULT;
|
||||
|
||||
if (maxCols > 0) {
|
||||
pCols->cols = (SDataCol *)taosMemoryCalloc(maxCols, sizeof(SDataCol));
|
||||
|
@ -899,7 +899,7 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
|
|||
#endif
|
||||
|
||||
pCols->numOfRows = 0;
|
||||
pCols->bitmapMode = 0;
|
||||
pCols->bitmapMode = TSDB_BITMODE_DEFAULT;
|
||||
pCols->numOfCols = schemaNCols(pSchema);
|
||||
|
||||
for (i = 0; i < schemaNCols(pSchema); ++i) {
|
||||
|
|
|
@ -341,18 +341,19 @@ int32_t tdSetBitmapValTypeN(void *pBitmap, int16_t nEle, TDRowValT valType, int8
|
|||
bool tdIsBitmapBlkNorm(const void *pBitmap, int32_t numOfBits, int8_t bitmapMode) {
|
||||
int32_t nBytes = (bitmapMode == 0 ? numOfBits / TD_VTYPE_PARTS : numOfBits / TD_VTYPE_PARTS_I);
|
||||
uint8_t vTypeByte = tdVTypeByte[bitmapMode][TD_VTYPE_NORM];
|
||||
uint8_t *qBitmap = (uint8_t*)pBitmap;
|
||||
for (int i = 0; i < nBytes; ++i) {
|
||||
if (*((uint8_t *)pBitmap) != vTypeByte) {
|
||||
if (*qBitmap != vTypeByte) {
|
||||
return false;
|
||||
}
|
||||
pBitmap = POINTER_SHIFT(pBitmap, i);
|
||||
qBitmap = (uint8_t *)POINTER_SHIFT(pBitmap, i);
|
||||
}
|
||||
|
||||
int32_t nLeft = numOfBits - nBytes * (bitmapMode == 0 ? TD_VTYPE_BITS : TD_VTYPE_BITS_I);
|
||||
|
||||
for (int j = 0; j < nLeft; ++j) {
|
||||
uint8_t vType;
|
||||
tdGetBitmapValType(pBitmap, j, &vType, bitmapMode);
|
||||
tdGetBitmapValType(qBitmap, j, &vType, bitmapMode);
|
||||
if (vType != TD_VTYPE_NORM) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
class DndTestBnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dbnodeTest", 9112);
|
||||
test.Init(TD_TMP_DIR_PATH "dbnodeTest", 9112);
|
||||
taosMsleep(1100);
|
||||
}
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class DndTestMnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dmnodeTest", 9114); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "dmnodeTest", 9114); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class DndTestQnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dqnodeTest", 9111); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "dqnodeTest", 9111); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class DndTestSnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dsnodeTest", 9113); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "dsnodeTest", 9113); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -48,7 +48,7 @@ void Testbase::Init(const char* path, int16_t port) {
|
|||
strcpy(tsDataDir, path);
|
||||
taosRemoveDir(path);
|
||||
taosMkDir(path);
|
||||
InitLog("/tmp/td");
|
||||
InitLog(TD_TMP_DIR_PATH "td");
|
||||
|
||||
server.Start();
|
||||
client.Init("root", "taosdata");
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class DndTestVnode : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/dvnodeTest", 9115); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "dvnodeTest", 9115); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class MndTestAcct : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/acctTest", 9012); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "acctTest", 9012); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -18,11 +18,11 @@ class MndTestBnode : public ::testing::Test {
|
|||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/mnode_test_bnode1", 9018);
|
||||
test.Init(TD_TMP_DIR_PATH "mnode_test_bnode1", 9018);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9018";
|
||||
|
||||
server2.Start("/tmp/mnode_test_bnode2", 9019);
|
||||
server2.Start(TD_TMP_DIR_PATH "mnode_test_bnode2", 9019);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class MndTestDb : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_db", 9030); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "mnode_test_db", 9030); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -18,14 +18,14 @@ class MndTestDnode : public ::testing::Test {
|
|||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/dnode_test_dnode1", 9023);
|
||||
test.Init(TD_TMP_DIR_PATH "dnode_test_dnode1", 9023);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9023";
|
||||
|
||||
// server2.Start("/tmp/dnode_test_dnode2", fqdn, 9024, firstEp);
|
||||
// server3.Start("/tmp/dnode_test_dnode3", fqdn, 9025, firstEp);
|
||||
// server4.Start("/tmp/dnode_test_dnode4", fqdn, 9026, firstEp);
|
||||
// server5.Start("/tmp/dnode_test_dnode5", fqdn, 9027, firstEp);
|
||||
// server2.Start(TD_TMP_DIR_PATH "dnode_test_dnode2", fqdn, 9024, firstEp);
|
||||
// server3.Start(TD_TMP_DIR_PATH "dnode_test_dnode3", fqdn, 9025, firstEp);
|
||||
// server4.Start(TD_TMP_DIR_PATH "dnode_test_dnode4", fqdn, 9026, firstEp);
|
||||
// server5.Start(TD_TMP_DIR_PATH "dnode_test_dnode5", fqdn, 9027, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class MndTestFunc : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_func", 9038); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "mnode_test_func", 9038); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -18,11 +18,11 @@ class MndTestMnode : public ::testing::Test {
|
|||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/mnode_test_mnode1", 9028);
|
||||
test.Init(TD_TMP_DIR_PATH "mnode_test_mnode1", 9028);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9028";
|
||||
|
||||
// server2.Start("/tmp/mnode_test_mnode2", fqdn, 9029, firstEp);
|
||||
// server2.Start(TD_TMP_DIR_PATH "mnode_test_mnode2", fqdn, 9029, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class MndTestProfile : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_profile", 9031); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "mnode_test_profile", 9031); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -18,11 +18,11 @@ class MndTestQnode : public ::testing::Test {
|
|||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/mnode_test_qnode1", 9014);
|
||||
test.Init(TD_TMP_DIR_PATH "mnode_test_qnode1", 9014);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9014";
|
||||
|
||||
// server2.Start("/tmp/mnode_test_qnode2", fqdn, 9015, firstEp);
|
||||
// server2.Start(TD_TMP_DIR_PATH "mnode_test_qnode2", fqdn, 9015, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ class MndTestSdb : public ::testing::Test {
|
|||
tsLogEmbedded = 1;
|
||||
tsAsyncLog = 0;
|
||||
|
||||
const char *path = "/tmp/td";
|
||||
const char *path = TD_TMP_DIR_PATH "td";
|
||||
taosRemoveDir(path);
|
||||
taosMkDir(path);
|
||||
tstrncpy(tsLogDir, path, PATH_MAX);
|
||||
|
@ -385,7 +385,7 @@ TEST_F(MndTestSdb, 01_Write_Str) {
|
|||
mnode.v100 = 100;
|
||||
mnode.v200 = 200;
|
||||
opt.pMnode = &mnode;
|
||||
opt.path = "/tmp/mnode_test_sdb";
|
||||
opt.path = TD_TMP_DIR_PATH "mnode_test_sdb";
|
||||
taosRemoveDir(opt.path);
|
||||
|
||||
SSdbTable strTable1;
|
||||
|
@ -727,7 +727,7 @@ TEST_F(MndTestSdb, 01_Read_Str) {
|
|||
mnode.v100 = 100;
|
||||
mnode.v200 = 200;
|
||||
opt.pMnode = &mnode;
|
||||
opt.path = "/tmp/mnode_test_sdb";
|
||||
opt.path = TD_TMP_DIR_PATH "mnode_test_sdb";
|
||||
|
||||
SSdbTable strTable1;
|
||||
memset(&strTable1, 0, sizeof(SSdbTable));
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class MndTestShow : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_show", 9021); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "mnode_test_show", 9021); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class MndTestSma : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_sma", 9035); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "mnode_test_sma", 9035); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -18,11 +18,11 @@ class MndTestSnode : public ::testing::Test {
|
|||
|
||||
public:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/mnode_test_snode1", 9016);
|
||||
test.Init(TD_TMP_DIR_PATH "mnode_test_snode1", 9016);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9016";
|
||||
|
||||
// server2.Start("/tmp/mnode_test_snode2", fqdn, 9017, firstEp);
|
||||
// server2.Start(TD_TMP_DIR_PATH "mnode_test_snode2", fqdn, 9017, firstEp);
|
||||
taosMsleep(300);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class MndTestStb : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_stb", 9034); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "mnode_test_stb", 9034); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class MndTestTopic : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_topic", 9039); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "mnode_test_topic", 9039); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
class MndTestTrans1 : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
test.Init("/tmp/mnode_test_trans1", 9013);
|
||||
test.Init(TD_TMP_DIR_PATH "mnode_test_trans1", 9013);
|
||||
const char* fqdn = "localhost";
|
||||
const char* firstEp = "localhost:9013";
|
||||
// server2.Start("/tmp/mnode_test_trans2", fqdn, 9020, firstEp);
|
||||
// server2.Start(TD_TMP_DIR_PATH "mnode_test_trans2", fqdn, 9020, firstEp);
|
||||
}
|
||||
|
||||
static void TearDownTestSuite() {
|
||||
|
@ -26,7 +26,7 @@ class MndTestTrans1 : public ::testing::Test {
|
|||
}
|
||||
|
||||
static void KillThenRestartServer() {
|
||||
char file[PATH_MAX] = "/tmp/mnode_test_trans1/mnode/data/sdb.data";
|
||||
char file[PATH_MAX] = TD_TMP_DIR_PATH "mnode_test_trans1/mnode/data/sdb.data";
|
||||
TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
int32_t size = 3 * 1024 * 1024;
|
||||
void* buffer = taosMemoryMalloc(size);
|
||||
|
|
|
@ -46,7 +46,7 @@ class MndTestTrans2 : public ::testing::Test {
|
|||
tsLogEmbedded = 1;
|
||||
tsAsyncLog = 0;
|
||||
|
||||
const char *logpath = "/tmp/td";
|
||||
const char *logpath = TD_TMP_DIR_PATH "td";
|
||||
taosRemoveDir(logpath);
|
||||
taosMkDir(logpath);
|
||||
tstrncpy(tsLogDir, logpath, PATH_MAX);
|
||||
|
@ -76,7 +76,7 @@ class MndTestTrans2 : public ::testing::Test {
|
|||
|
||||
tsTransPullupInterval = 1;
|
||||
|
||||
const char *mnodepath = "/tmp/mnode_test_trans";
|
||||
const char *mnodepath = TD_TMP_DIR_PATH "mnode_test_trans";
|
||||
taosRemoveDir(mnodepath);
|
||||
pMnode = mndOpen(mnodepath, &opt);
|
||||
mndStart(pMnode);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
class MndTestUser : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9011); }
|
||||
static void SetUpTestSuite() { test.Init(TD_TMP_DIR_PATH "mnode_test_user", 9011); }
|
||||
static void TearDownTestSuite() { test.Cleanup(); }
|
||||
|
||||
static Testbase test;
|
||||
|
|
|
@ -76,9 +76,14 @@ target_link_libraries(
|
|||
#PUBLIC scalar
|
||||
PUBLIC transport
|
||||
PUBLIC stream
|
||||
PUBLIC index
|
||||
)
|
||||
target_compile_definitions(vnode PUBLIC -DMETA_REFACT)
|
||||
|
||||
if (${BUILD_WITH_INVERTEDINDEX})
|
||||
add_definitions(-DUSE_INVERTED_INDEX)
|
||||
endif(${BUILD_WITH_INVERTEDINDEX})
|
||||
if(${BUILD_TEST})
|
||||
add_subdirectory(test)
|
||||
endif(${BUILD_TEST})
|
||||
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ struct SMetaEntry {
|
|||
int64_t version;
|
||||
int8_t type;
|
||||
tb_uid_t uid;
|
||||
const char *name;
|
||||
char *name;
|
||||
union {
|
||||
struct {
|
||||
SSchemaWrapper schema;
|
||||
|
@ -187,7 +187,7 @@ struct SMetaEntry {
|
|||
int64_t ctime;
|
||||
int32_t ttlDays;
|
||||
tb_uid_t suid;
|
||||
const uint8_t *pTags;
|
||||
uint8_t *pTags;
|
||||
} ctbEntry;
|
||||
struct {
|
||||
int64_t ctime;
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define _TD_VNODE_META_H_
|
||||
|
||||
#include "vnodeInt.h"
|
||||
#include "index.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -70,7 +71,11 @@ struct SMeta {
|
|||
TTB* pUidIdx;
|
||||
TTB* pNameIdx;
|
||||
TTB* pCtbIdx;
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
void* pTagIvtIdx;
|
||||
#else
|
||||
TTB* pTagIdx;
|
||||
#endif
|
||||
TTB* pTtlIdx;
|
||||
TTB* pSmaIdx;
|
||||
SMetaIdx* pIdx;
|
||||
|
|
|
@ -53,10 +53,10 @@ int metaOpenIdx(SMeta *pMeta) {
|
|||
#endif
|
||||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
SIndexOpts opts;
|
||||
if (indexOpen(&opts, pMeta->path, &pMeta->pIdx->pIdx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
// SIndexOpts opts;
|
||||
// if (indexOpen(&opts, pMeta->path, &pMeta->pIdx->pIdx) != 0) {
|
||||
// return -1;
|
||||
//}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
@ -71,36 +71,37 @@ void metaCloseIdx(SMeta *pMeta) { /* TODO */
|
|||
#endif
|
||||
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
SIndexOpts opts;
|
||||
if (indexClose(pMeta->pIdx->pIdx) != 0) {
|
||||
return -1;
|
||||
}
|
||||
// SIndexOpts opts;
|
||||
// if (indexClose(pMeta->pIdx->pIdx) != 0) {
|
||||
// return -1;
|
||||
//}
|
||||
// return 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
int metaSaveTableToIdx(SMeta *pMeta, const STbCfg *pTbCfg) {
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
if (pTbCfgs->type == META_CHILD_TABLE) {
|
||||
char buf[8] = {0};
|
||||
int16_t colId = (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId;
|
||||
sprintf(buf, "%d", colId); // colname
|
||||
// if (pTbCfgs->type == META_CHILD_TABLE) {
|
||||
// char buf[8] = {0};
|
||||
// int16_t colId = (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId;
|
||||
// sprintf(buf, "%d", colId); // colname
|
||||
|
||||
char *pTagVal = (char *)tdGetKVRowValOfCol(pTbCfg->ctbCfg.pTag, (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId);
|
||||
// char *pTagVal = (char *)tdGetKVRowValOfCol(pTbCfg->ctbCfg.pTag, (kvRowColIdx(pTbCfg->ctbCfg.pTag))[0].colId);
|
||||
|
||||
tb_uid_t suid = pTbCfg->ctbCfg.suid; // super id
|
||||
tb_uid_t tuid = 0; // child table uid
|
||||
SIndexMultiTerm *terms = indexMultiTermCreate();
|
||||
SIndexTerm *term =
|
||||
indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BINARY, buf, strlen(buf), pTagVal, strlen(pTagVal), tuid);
|
||||
indexMultiTermAdd(terms, term);
|
||||
// tb_uid_t suid = pTbCfg->ctbCfg.suid; // super id
|
||||
// tb_uid_t tuid = 0; // child table uid
|
||||
// SIndexMultiTerm *terms = indexMultiTermCreate();
|
||||
// SIndexTerm *term =
|
||||
// indexTermCreate(suid, ADD_VALUE, TSDB_DATA_TYPE_BINARY, buf, strlen(buf), pTagVal, strlen(pTagVal), tuid);
|
||||
// indexMultiTermAdd(terms, term);
|
||||
|
||||
int ret = indexPut(pMeta->pIdx->pIdx, terms);
|
||||
indexMultiTermDestroy(terms);
|
||||
return ret;
|
||||
} else {
|
||||
return DB_DONOTINDEX;
|
||||
}
|
||||
// int ret = indexPut(pMeta->pIdx->pIdx, terms);
|
||||
// indexMultiTermDestroy(terms);
|
||||
// return ret;
|
||||
//} else {
|
||||
// return DB_DONOTINDEX;
|
||||
//}
|
||||
#endif
|
||||
// TODO
|
||||
return 0;
|
||||
|
|
|
@ -93,11 +93,24 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
|
|||
}
|
||||
|
||||
// open pTagIdx
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
// TODO(yihaoDeng), refactor later
|
||||
char indexFullPath[128] = {0};
|
||||
sprintf(indexFullPath, "%s/%s", pMeta->path, "invert");
|
||||
taosMkDir(indexFullPath);
|
||||
ret = indexOpen(indexOptsCreate(), indexFullPath, (SIndex **)&pMeta->pTagIvtIdx);
|
||||
if (ret < 0) {
|
||||
metaError("vgId:%d failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
#else
|
||||
ret = tdbTbOpen("tag.idx", -1, 0, tagIdxKeyCmpr, pMeta->pEnv, &pMeta->pTagIdx);
|
||||
if (ret < 0) {
|
||||
metaError("vgId:%d failed to open meta tag index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
#endif
|
||||
|
||||
// open pTtlIdx
|
||||
ret = tdbTbOpen("ttl.idx", sizeof(STtlIdxKey), 0, ttlIdxKeyCmpr, pMeta->pEnv, &pMeta->pTtlIdx);
|
||||
|
@ -128,7 +141,11 @@ _err:
|
|||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||
if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
|
||||
if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx);
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
|
||||
#else
|
||||
if (pMeta->pTagIdx) tdbTbClose(pMeta->pTagIdx);
|
||||
#endif
|
||||
if (pMeta->pCtbIdx) tdbTbClose(pMeta->pCtbIdx);
|
||||
if (pMeta->pNameIdx) tdbTbClose(pMeta->pNameIdx);
|
||||
if (pMeta->pUidIdx) tdbTbClose(pMeta->pUidIdx);
|
||||
|
@ -145,7 +162,11 @@ int metaClose(SMeta *pMeta) {
|
|||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||
if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
|
||||
if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx);
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
|
||||
#else
|
||||
if (pMeta->pTagIdx) tdbTbClose(pMeta->pTagIdx);
|
||||
#endif
|
||||
if (pMeta->pCtbIdx) tdbTbClose(pMeta->pCtbIdx);
|
||||
if (pMeta->pNameIdx) tdbTbClose(pMeta->pNameIdx);
|
||||
if (pMeta->pUidIdx) tdbTbClose(pMeta->pUidIdx);
|
||||
|
|
|
@ -165,7 +165,9 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
ret = tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
tDecoderInit(&dc, pData, nData);
|
||||
oStbEntry.pBuf = taosMemoryMalloc(nData);
|
||||
memcpy(oStbEntry.pBuf, pData, nData);
|
||||
tDecoderInit(&dc, oStbEntry.pBuf, nData);
|
||||
metaDecodeEntry(&dc, &oStbEntry);
|
||||
|
||||
nStbEntry.version = version;
|
||||
|
@ -193,6 +195,7 @@ int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) {
|
|||
// update uid index
|
||||
tdbTbcUpsert(pUidIdxc, &pReq->suid, sizeof(tb_uid_t), &version, sizeof(version), 0);
|
||||
|
||||
if (oStbEntry.pBuf) taosMemoryFree(oStbEntry.pBuf);
|
||||
metaULock(pMeta);
|
||||
tDecoderClear(&dc);
|
||||
tdbTbcClose(pTbDbc);
|
||||
|
@ -420,7 +423,9 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
|||
|
||||
// get table entry
|
||||
SDecoder dc = {0};
|
||||
tDecoderInit(&dc, pData, nData);
|
||||
entry.pBuf = taosMemoryMalloc(nData);
|
||||
memcpy(entry.pBuf, pData, nData);
|
||||
tDecoderInit(&dc, entry.pBuf, nData);
|
||||
ret = metaDecodeEntry(&dc, &entry);
|
||||
ASSERT(ret == 0);
|
||||
|
||||
|
@ -820,16 +825,27 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
|
|||
pTagData = tdGetKVRowValOfCol((const SKVRow)pCtbEntry->ctbEntry.pTags, pTagColumn->colId);
|
||||
|
||||
// update tag index
|
||||
#ifdef USE_INVERTED_INDEX
|
||||
tb_uid_t suid = pCtbEntry->ctbEntry.suid;
|
||||
tb_uid_t tuid = pCtbEntry->uid;
|
||||
|
||||
SIndexMultiTerm *tmGroup = indexMultiTermCreate();
|
||||
|
||||
SIndexTerm *tm = indexTermCreate(suid, ADD_VALUE, pTagColumn->type, pTagColumn->name, sizeof(pTagColumn->name),
|
||||
pTagData, pTagData == NULL ? 0 : strlen(pTagData));
|
||||
indexMultiTermAdd(tmGroup, tm);
|
||||
int ret = indexPut((SIndex *)pMeta->pTagIvtIdx, tmGroup, tuid);
|
||||
indexMultiTermDestroy(tmGroup);
|
||||
#else
|
||||
if (metaCreateTagIdxKey(pCtbEntry->ctbEntry.suid, pTagColumn->colId, pTagData, pTagColumn->type, pCtbEntry->uid,
|
||||
&pTagIdxKey, &nTagIdxKey) < 0) {
|
||||
return -1;
|
||||
}
|
||||
tdbTbInsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, &pMeta->txn);
|
||||
metaDestroyTagIdxKey(pTagIdxKey);
|
||||
|
||||
#endif
|
||||
tDecoderClear(&dc);
|
||||
tdbFree(pData);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -600,6 +600,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
SSDataBlock block = {0};
|
||||
if (tqRetrieveDataBlock(&block.pDataBlock, pReader, &block.info.groupId, &block.info.uid, &block.info.rows,
|
||||
&block.info.numOfCols) < 0) {
|
||||
if (terrno == TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND) continue;
|
||||
ASSERT(0);
|
||||
}
|
||||
int32_t dataStrLen = sizeof(SRetrieveTableRsp) + blockGetEncodeSize(&block);
|
||||
|
|
|
@ -91,12 +91,22 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
|
|||
if (pHandle->sver != sversion || pHandle->cachedSchemaUid != pHandle->msgIter.suid) {
|
||||
pHandle->pSchema = metaGetTbTSchema(pHandle->pVnodeMeta, pHandle->msgIter.uid, sversion);
|
||||
if (pHandle->pSchema == NULL) {
|
||||
tqError("cannot found schema for table: %ld, version %d", pHandle->msgIter.suid, pHandle->sver);
|
||||
tqWarn("cannot found tsschema for table: uid: %ld (suid: %ld), version %d, possibly dropped table",
|
||||
pHandle->msgIter.uid, pHandle->msgIter.suid, pHandle->sver);
|
||||
/*ASSERT(0);*/
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// this interface use suid instead of uid
|
||||
pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, pHandle->msgIter.suid, sversion, true);
|
||||
if (pHandle->pSchemaWrapper == NULL) {
|
||||
tqWarn("cannot found schema wrapper for table: suid: %ld, version %d, possibly dropped table",
|
||||
pHandle->msgIter.suid, pHandle->sver);
|
||||
/*ASSERT(0);*/
|
||||
terrno = TSDB_CODE_TQ_TABLE_SCHEMA_NOT_FOUND;
|
||||
return -1;
|
||||
}
|
||||
pHandle->sver = sversion;
|
||||
pHandle->cachedSchemaUid = pHandle->msgIter.suid;
|
||||
}
|
||||
|
|
|
@ -1138,6 +1138,9 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF
|
|||
memcpy(tptr, pDataCol->pData, flen);
|
||||
if (tBitmaps > 0) {
|
||||
bptr = POINTER_SHIFT(pBlockData, lsize + flen);
|
||||
if (isSuper && !tdDataColsIsBitmapI(pDataCols)) {
|
||||
tdMergeBitmap((uint8_t *)pDataCol->pBitmap, rowsToWrite, (uint8_t *)pDataCol->pBitmap);
|
||||
}
|
||||
memcpy(bptr, pDataCol->pBitmap, tBitmaps);
|
||||
tBitmapsLen = tBitmaps;
|
||||
flen += tBitmapsLen;
|
||||
|
@ -1503,13 +1506,16 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
tSkipListIterNext(pCommitIter->pIter);
|
||||
} else {
|
||||
if (lastKey != key1) {
|
||||
lastKey = key1;
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++pTarget->numOfRows;
|
||||
}
|
||||
lastKey = key1;
|
||||
}
|
||||
|
||||
// copy disk data
|
||||
for (int i = 0; i < pDataCols->numOfCols; ++i) {
|
||||
SCellVal sVal = {0};
|
||||
// no duplicated TS keys in pDataCols from file
|
||||
if (tdGetColDataOfRow(&sVal, pDataCols->cols + i, *iter, pDataCols->bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p
|
|||
if (tDecodeIsEnd(&dc)) break;
|
||||
|
||||
// decode row
|
||||
if (tDecodeBinary(&dc, (const uint8_t **)&tRow.pRow, &tRow.szRow) < 0) {
|
||||
if (tDecodeBinary(&dc, (uint8_t **)&tRow.pRow, &tRow.szRow) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ static FORCE_INLINE int32_t tsdbEncodeRow(SEncoder *pEncoder, const STsdbRow *pR
|
|||
|
||||
static FORCE_INLINE int32_t tsdbDecodeRow(SDecoder *pDecoder, STsdbRow *pRow) {
|
||||
if (tDecodeI64(pDecoder, &pRow->version) < 0) return -1;
|
||||
if (tDecodeBinary(pDecoder, (const uint8_t **)&pRow->pRow, &pRow->szRow) < 0) return -1;
|
||||
if (tDecodeBinary(pDecoder, (uint8_t **)&pRow->pRow, &pRow->szRow) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1732,6 +1732,7 @@ static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capa
|
|||
if (*lastRowKey != TSKEY_INITIAL_VAL) {
|
||||
++(*curRow);
|
||||
}
|
||||
*lastRowKey = rowKey;
|
||||
++nResult;
|
||||
} else if (update) {
|
||||
mergeOption = 2;
|
||||
|
@ -1739,8 +1740,6 @@ static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capa
|
|||
mergeOption = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
*lastRowKey = rowKey;
|
||||
}
|
||||
} else {
|
||||
// TODO: use STSRowIter
|
||||
|
@ -1753,6 +1752,7 @@ static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capa
|
|||
if (*lastRowKey != TSKEY_INITIAL_VAL) {
|
||||
++(*curRow);
|
||||
}
|
||||
*lastRowKey = rowKey;
|
||||
++nResult;
|
||||
} else if (update) {
|
||||
mergeOption = 2;
|
||||
|
@ -1760,7 +1760,6 @@ static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capa
|
|||
mergeOption = 0;
|
||||
break;
|
||||
}
|
||||
*lastRowKey = rowKey;
|
||||
} else {
|
||||
SKvRowIdx* pColIdx = tdKvRowColIdxAt(row, chosen_itr - 1);
|
||||
colId = pColIdx->colId;
|
||||
|
@ -1965,7 +1964,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
SDataCols* pCols = pTsdbReadHandle->rhelper.pDCols[0];
|
||||
assert(pCols->cols[0].type == TSDB_DATA_TYPE_TIMESTAMP && pCols->cols[0].colId == PRIMARYKEY_TIMESTAMP_COL_ID &&
|
||||
cur->pos >= 0 && cur->pos < pBlock->numOfRows);
|
||||
|
||||
// Even Multi-Version supported, the records with duplicated TSKEY would be merged inside of tsdbLoadData interface.
|
||||
TSKEY* tsArray = pCols->cols[0].pData;
|
||||
assert(pCols->numOfRows == pBlock->numOfRows && tsArray[0] == pBlock->keyFirst &&
|
||||
tsArray[pBlock->numOfRows - 1] == pBlock->keyLast);
|
||||
|
@ -1995,6 +1994,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
|
||||
int32_t pos = cur->pos;
|
||||
cur->win = TSWINDOW_INITIALIZER;
|
||||
bool adjustPos = false;
|
||||
|
||||
// no data in buffer, load data from file directly
|
||||
if (pCheckInfo->iiter == NULL && pCheckInfo->iter == NULL) {
|
||||
|
@ -2016,6 +2016,13 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
break;
|
||||
}
|
||||
|
||||
if (adjustPos) {
|
||||
if (key == lastKeyAppend) {
|
||||
pos -= step;
|
||||
}
|
||||
adjustPos = false;
|
||||
}
|
||||
|
||||
if (((pos > endPos || tsArray[pos] > pTsdbReadHandle->window.ekey) && ascScan) ||
|
||||
((pos < endPos || tsArray[pos] < pTsdbReadHandle->window.ekey) && !ascScan)) {
|
||||
break;
|
||||
|
@ -2107,7 +2114,9 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
moveToNextRowInMem(pCheckInfo);
|
||||
|
||||
pos += step;
|
||||
adjustPos = true;
|
||||
} else {
|
||||
// discard the memory record
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
}
|
||||
} else if ((key > tsArray[pos] && ascScan) || (key < tsArray[pos] && !ascScan)) {
|
||||
|
|
|
@ -20,11 +20,11 @@
|
|||
static void tsdbResetReadTable(SReadH *pReadh);
|
||||
static void tsdbResetReadFile(SReadH *pReadh);
|
||||
static int tsdbLoadBlockOffset(SReadH *pReadh, SBlock *pBlock);
|
||||
static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols);
|
||||
static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols, int8_t bitmapMode);
|
||||
static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, void *content, int32_t len, int32_t bitmapLen, int8_t comp,
|
||||
int numOfRows, int numOfBitmaps, int maxPoints, char *buffer, int bufferSize);
|
||||
static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols, const int16_t *colIds,
|
||||
int numOfColIds);
|
||||
int numOfColIds, int8_t bitmapMode);
|
||||
static int tsdbLoadColData(SReadH *pReadh, SDFile *pDFile, SBlock *pBlock, SBlockCol *pBlockCol, SDataCol *pDataCol);
|
||||
|
||||
int tsdbInitReadH(SReadH *pReadh, STsdb *pRepo) {
|
||||
|
@ -266,10 +266,11 @@ int tsdbLoadBlockData(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo) {
|
|||
}
|
||||
}
|
||||
|
||||
if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[0]) < 0) return -1;
|
||||
|
||||
if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[0], TSDB_BITMODE_ONE_BIT) < 0) return -1;
|
||||
for (int i = 1; i < pBlock->numOfSubBlocks; i++) {
|
||||
iBlock++;
|
||||
if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[1]) < 0) return -1;
|
||||
if (tsdbLoadBlockDataImpl(pReadh, iBlock, pReadh->pDCols[1], TSDB_BITMODE_DEFAULT) < 0) return -1;
|
||||
// TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version
|
||||
if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL,
|
||||
TD_SUPPORT_UPDATE(update), TD_VER_MAX) < 0)
|
||||
|
@ -309,10 +310,10 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo,
|
|||
}
|
||||
}
|
||||
|
||||
if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[0], colIds, numOfColsIds) < 0) return -1;
|
||||
if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[0], colIds, numOfColsIds, TSDB_BITMODE_ONE_BIT) < 0) return -1;
|
||||
for (int i = 1; i < pBlock->numOfSubBlocks; i++) {
|
||||
iBlock++;
|
||||
if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[1], colIds, numOfColsIds) < 0) return -1;
|
||||
if (tsdbLoadBlockDataColsImpl(pReadh, iBlock, pReadh->pDCols[1], colIds, numOfColsIds, TSDB_BITMODE_DEFAULT) < 0) return -1;
|
||||
// TODO: use the real maxVersion to replace the UINT64_MAX to support Multi-Version
|
||||
if (tdMergeDataCols(pReadh->pDCols[0], pReadh->pDCols[1], pReadh->pDCols[1]->numOfRows, NULL,
|
||||
TD_SUPPORT_UPDATE(update), TD_VER_MAX) < 0)
|
||||
|
@ -543,14 +544,14 @@ static void tsdbResetReadFile(SReadH *pReadh) {
|
|||
tsdbCloseDFileSet(TSDB_READ_FSET(pReadh));
|
||||
}
|
||||
|
||||
static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols) {
|
||||
static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols, int8_t bitmapMode) {
|
||||
ASSERT(pBlock->numOfSubBlocks == 0 || pBlock->numOfSubBlocks == 1);
|
||||
|
||||
SDFile *pDFile = (pBlock->last) ? TSDB_READ_LAST_FILE(pReadh) : TSDB_READ_DATA_FILE(pReadh);
|
||||
|
||||
tdResetDataCols(pDataCols);
|
||||
|
||||
if (tsdbIsSupBlock(pBlock)) {
|
||||
if (tdIsBitmapModeI(bitmapMode)) {
|
||||
tdDataColsSetBitmapI(pDataCols);
|
||||
}
|
||||
|
||||
|
@ -730,7 +731,7 @@ static int tsdbCheckAndDecodeColumnData(SDataCol *pDataCol, void *content, int32
|
|||
}
|
||||
|
||||
static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDataCols, const int16_t *colIds,
|
||||
int numOfColIds) {
|
||||
int numOfColIds, int8_t bitmapMode) {
|
||||
ASSERT(pBlock->numOfSubBlocks == 0 || pBlock->numOfSubBlocks == 1);
|
||||
ASSERT(colIds[0] == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
|
||||
|
@ -739,7 +740,7 @@ static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *
|
|||
|
||||
tdResetDataCols(pDataCols);
|
||||
|
||||
if (tsdbIsSupBlock(pBlock)) {
|
||||
if (tdIsBitmapModeI(bitmapMode)) {
|
||||
tdDataColsSetBitmapI(pDataCols);
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class TqMetaUpdateAppendTest : public ::testing::Test {
|
|||
void TearDown() override { tqStoreClose(pMeta); }
|
||||
|
||||
STqMetaStore* pMeta;
|
||||
const char* pathName = "/tmp/tq_test";
|
||||
const char* pathName = TD_TMP_DIR_PATH "tq_test";
|
||||
};
|
||||
|
||||
TEST_F(TqMetaUpdateAppendTest, copyPutTest) {
|
||||
|
|
|
@ -58,6 +58,17 @@ enum {
|
|||
CTG_ACT_MAX
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
CTG_TASK_GET_QNODE = 0,
|
||||
CTG_TASK_GET_DB_VGROUP,
|
||||
CTG_TASK_GET_DB_CFG,
|
||||
CTG_TASK_GET_TB_META,
|
||||
CTG_TASK_GET_TB_HASH,
|
||||
CTG_TASK_GET_INDEX,
|
||||
CTG_TASK_GET_UDF,
|
||||
CTG_TASK_GET_USER,
|
||||
} CTG_TASK_TYPE;
|
||||
|
||||
typedef struct SCtgDebug {
|
||||
bool lockEnable;
|
||||
bool cacheEnable;
|
||||
|
@ -66,6 +77,43 @@ typedef struct SCtgDebug {
|
|||
uint32_t showCachePeriodSec;
|
||||
} SCtgDebug;
|
||||
|
||||
typedef struct SCtgTbCacheInfo {
|
||||
bool inCache;
|
||||
uint64_t dbId;
|
||||
uint64_t suid;
|
||||
int32_t tbType;
|
||||
} SCtgTbCacheInfo;
|
||||
|
||||
typedef struct SCtgTbMetaCtx {
|
||||
SCtgTbCacheInfo tbInfo;
|
||||
SName* pName;
|
||||
int32_t flag;
|
||||
} SCtgTbMetaCtx;
|
||||
|
||||
typedef struct SCtgDbVgCtx {
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
} SCtgDbVgCtx;
|
||||
|
||||
typedef struct SCtgDbCfgCtx {
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
} SCtgDbCfgCtx;
|
||||
|
||||
typedef struct SCtgTbHashCtx {
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
SName* pName;
|
||||
} SCtgTbHashCtx;
|
||||
|
||||
typedef struct SCtgIndexCtx {
|
||||
char indexFName[TSDB_INDEX_FNAME_LEN];
|
||||
} SCtgIndexCtx;
|
||||
|
||||
typedef struct SCtgUdfCtx {
|
||||
char udfName[TSDB_FUNC_NAME_LEN];
|
||||
} SCtgUdfCtx;
|
||||
|
||||
typedef struct SCtgUserCtx {
|
||||
SUserAuthInfo user;
|
||||
} SCtgUserCtx;
|
||||
|
||||
typedef struct SCtgTbMetaCache {
|
||||
SRWLatch stbLock;
|
||||
|
@ -113,6 +161,55 @@ typedef struct SCatalog {
|
|||
SCtgRentMgmt stbRent;
|
||||
} SCatalog;
|
||||
|
||||
typedef struct SCtgJob {
|
||||
int64_t refId;
|
||||
SArray* pTasks;
|
||||
int32_t taskDone;
|
||||
SMetaData jobRes;
|
||||
int32_t rspCode;
|
||||
|
||||
uint64_t queryId;
|
||||
SCatalog* pCtg;
|
||||
void* pTrans;
|
||||
const SEpSet* pMgmtEps;
|
||||
void* userParam;
|
||||
catalogCallback userFp;
|
||||
int32_t tbMetaNum;
|
||||
int32_t tbHashNum;
|
||||
int32_t dbVgNum;
|
||||
int32_t udfNum;
|
||||
int32_t qnodeNum;
|
||||
int32_t dbCfgNum;
|
||||
int32_t indexNum;
|
||||
int32_t userNum;
|
||||
} SCtgJob;
|
||||
|
||||
typedef struct SCtgMsgCtx {
|
||||
int32_t reqType;
|
||||
void* lastOut;
|
||||
void* out;
|
||||
char* target;
|
||||
} SCtgMsgCtx;
|
||||
|
||||
typedef struct SCtgTask {
|
||||
CTG_TASK_TYPE type;
|
||||
int32_t taskId;
|
||||
SCtgJob *pJob;
|
||||
void* taskCtx;
|
||||
SCtgMsgCtx msgCtx;
|
||||
void* res;
|
||||
} SCtgTask;
|
||||
|
||||
typedef int32_t (*ctgLanchTaskFp)(SCtgTask*);
|
||||
typedef int32_t (*ctgHandleTaskMsgRspFp)(SCtgTask*, int32_t, const SDataBuf *, int32_t);
|
||||
typedef int32_t (*ctgDumpTaskResFp)(SCtgTask*);
|
||||
|
||||
typedef struct SCtgAsyncFps {
|
||||
ctgLanchTaskFp launchFp;
|
||||
ctgHandleTaskMsgRspFp handleRspFp;
|
||||
ctgDumpTaskResFp dumpResFp;
|
||||
} SCtgAsyncFps;
|
||||
|
||||
typedef struct SCtgApiStat {
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -214,6 +311,7 @@ typedef struct SCtgQueue {
|
|||
|
||||
typedef struct SCatalogMgmt {
|
||||
bool exit;
|
||||
int32_t jobPool;
|
||||
SRWLatch lock;
|
||||
SCtgQueue queue;
|
||||
TdThread updateThread;
|
||||
|
@ -327,10 +425,80 @@ typedef struct SCtgAction {
|
|||
#define CTG_API_LEAVE(c) do { int32_t __code = c; CTG_UNLOCK(CTG_READ, &gCtgMgmt.lock); CTG_API_DEBUG("CTG API leave %s", __FUNCTION__); CTG_RET(__code); } while (0)
|
||||
#define CTG_API_ENTER() do { CTG_API_DEBUG("CTG API enter %s", __FUNCTION__); CTG_LOCK(CTG_READ, &gCtgMgmt.lock); if (atomic_load_8((int8_t*)&gCtgMgmt.exit)) { CTG_API_LEAVE(TSDB_CODE_CTG_OUT_OF_SERVICE); } } while (0)
|
||||
|
||||
#define CTG_PARAMS SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps
|
||||
#define CTG_PARAMS_LIST() pCtg, pTrans, pMgmtEps
|
||||
|
||||
extern void ctgdShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p);
|
||||
extern void ctgdShowClusterCache(SCatalog* pCtg);
|
||||
extern int32_t ctgdShowCacheInfo(void);
|
||||
void ctgdShowTableMeta(SCatalog* pCtg, const char *tbName, STableMeta* p);
|
||||
void ctgdShowClusterCache(SCatalog* pCtg);
|
||||
int32_t ctgdShowCacheInfo(void);
|
||||
|
||||
int32_t ctgRemoveTbMetaFromCache(SCatalog* pCtg, SName* pTableName, bool syncReq);
|
||||
int32_t ctgGetTbMetaFromCache(CTG_PARAMS, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta);
|
||||
|
||||
int32_t ctgActUpdateVg(SCtgMetaAction *action);
|
||||
int32_t ctgActUpdateTb(SCtgMetaAction *action);
|
||||
int32_t ctgActRemoveDB(SCtgMetaAction *action);
|
||||
int32_t ctgActRemoveStb(SCtgMetaAction *action);
|
||||
int32_t ctgActRemoveTb(SCtgMetaAction *action);
|
||||
int32_t ctgActUpdateUser(SCtgMetaAction *action);
|
||||
int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char *dbFName, SCtgDBCache **pCache);
|
||||
void ctgReleaseDBCache(SCatalog *pCtg, SCtgDBCache *dbCache);
|
||||
void ctgReleaseVgInfo(SCtgDBCache *dbCache);
|
||||
int32_t ctgAcquireVgInfoFromCache(SCatalog* pCtg, const char *dbFName, SCtgDBCache **pCache);
|
||||
int32_t ctgTbMetaExistInCache(SCatalog* pCtg, char *dbFName, char* tbName, int32_t *exist);
|
||||
int32_t ctgReadTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta);
|
||||
int32_t ctgReadTbSverFromCache(SCatalog *pCtg, const SName *pTableName, int32_t *sver, int32_t *tbType, uint64_t *suid, char *stbName);
|
||||
int32_t ctgChkAuthFromCache(SCatalog* pCtg, const char* user, const char* dbFName, AUTH_TYPE type, bool *inCache, bool *pass);
|
||||
int32_t ctgPutRmDBToQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId);
|
||||
int32_t ctgPutRmStbToQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *stbName, uint64_t suid, bool syncReq);
|
||||
int32_t ctgPutRmTbToQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *tbName, bool syncReq);
|
||||
int32_t ctgPutUpdateVgToQueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, SDBVgInfo* dbInfo, bool syncReq);
|
||||
int32_t ctgPutUpdateTbToQueue(SCatalog* pCtg, STableMetaOutput *output, bool syncReq);
|
||||
int32_t ctgPutUpdateUserToQueue(SCatalog* pCtg, SGetUserAuthRsp *pAuth, bool syncReq);
|
||||
int32_t ctgMetaRentInit(SCtgRentMgmt *mgmt, uint32_t rentSec, int8_t type);
|
||||
int32_t ctgMetaRentAdd(SCtgRentMgmt *mgmt, void *meta, int64_t id, int32_t size);
|
||||
int32_t ctgMetaRentGet(SCtgRentMgmt *mgmt, void **res, uint32_t *num, int32_t size);
|
||||
int32_t ctgUpdateTbMetaToCache(SCatalog* pCtg, STableMetaOutput* pOut, bool syncReq);
|
||||
int32_t ctgStartUpdateThread();
|
||||
int32_t ctgRelaunchGetTbMetaTask(SCtgTask *pTask);
|
||||
|
||||
|
||||
|
||||
int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, int32_t rspCode, char* target);
|
||||
int32_t ctgGetDBVgInfoFromMnode(CTG_PARAMS, SBuildUseDBInput *input, SUseDbOutput *out, SCtgTask* pTask);
|
||||
int32_t ctgGetQnodeListFromMnode(CTG_PARAMS, SArray *out, SCtgTask* pTask);
|
||||
int32_t ctgGetDBCfgFromMnode(CTG_PARAMS, const char *dbFName, SDbCfgInfo *out, SCtgTask* pTask);
|
||||
int32_t ctgGetIndexInfoFromMnode(CTG_PARAMS, const char *indexName, SIndexInfo *out, SCtgTask* pTask);
|
||||
int32_t ctgGetUdfInfoFromMnode(CTG_PARAMS, const char *funcName, SFuncInfo *out, SCtgTask* pTask);
|
||||
int32_t ctgGetUserDbAuthFromMnode(CTG_PARAMS, const char *user, SGetUserAuthRsp *out, SCtgTask* pTask);
|
||||
int32_t ctgGetTbMetaFromMnodeImpl(CTG_PARAMS, char *dbFName, char* tbName, STableMetaOutput* out, SCtgTask* pTask);
|
||||
int32_t ctgGetTbMetaFromMnode(CTG_PARAMS, const SName* pTableName, STableMetaOutput* out, SCtgTask* pTask);
|
||||
int32_t ctgGetTbMetaFromVnode(CTG_PARAMS, const SName* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* out, SCtgTask* pTask);
|
||||
|
||||
int32_t ctgInitJob(CTG_PARAMS, SCtgJob** job, uint64_t reqId, const SCatalogReq* pReq, catalogCallback fp, void* param);
|
||||
int32_t ctgLaunchJob(SCtgJob *pJob);
|
||||
int32_t ctgMakeAsyncRes(SCtgJob *pJob);
|
||||
|
||||
int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst);
|
||||
int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput);
|
||||
int32_t ctgGenerateVgList(SCatalog *pCtg, SHashObj *vgHash, SArray** pList);
|
||||
void ctgFreeJob(void* job);
|
||||
void ctgFreeHandle(SCatalog* pCtg);
|
||||
void ctgFreeVgInfo(SDBVgInfo *vgInfo);
|
||||
int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName *pTableName, SVgroupInfo *pVgroup);
|
||||
void ctgResetTbMetaTask(SCtgTask* pTask);
|
||||
void ctgFreeDbCache(SCtgDBCache *dbCache);
|
||||
int32_t ctgStbVersionSortCompare(const void* key1, const void* key2);
|
||||
int32_t ctgDbVgVersionSortCompare(const void* key1, const void* key2);
|
||||
int32_t ctgStbVersionSearchCompare(const void* key1, const void* key2);
|
||||
int32_t ctgDbVgVersionSearchCompare(const void* key1, const void* key2);
|
||||
void ctgFreeSTableMetaOutput(STableMetaOutput* pOutput);
|
||||
int32_t ctgUpdateMsgCtx(SCtgMsgCtx* pCtx, int32_t reqType, void* out, char* target);
|
||||
|
||||
|
||||
extern SCatalogMgmt gCtgMgmt;
|
||||
extern SCtgDebug gCTGDebug;
|
||||
extern SCtgAsyncFps gCtgAsyncFps[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _TD_CATALOG_REMOTE_H_
|
||||
#define _TD_CATALOG_REMOTE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SCtgTaskCallbackParam {
|
||||
uint64_t queryId;
|
||||
int64_t refId;
|
||||
uint64_t taskId;
|
||||
int32_t reqType;
|
||||
} SCtgTaskCallbackParam;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_CATALOG_REMOTE_H_*/
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,577 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "trpc.h"
|
||||
#include "query.h"
|
||||
#include "tname.h"
|
||||
#include "catalogInt.h"
|
||||
#include "systable.h"
|
||||
#include "ctgRemote.h"
|
||||
#include "tref.h"
|
||||
|
||||
int32_t ctgProcessRspMsg(void* out, int32_t reqType, char* msg, int32_t msgSize, int32_t rspCode, char* target) {
|
||||
int32_t code = 0;
|
||||
|
||||
switch (reqType) {
|
||||
case TDMT_MND_QNODE_LIST: {
|
||||
if (TSDB_CODE_SUCCESS != rspCode) {
|
||||
qError("error rsp for qnode list, error:%s", tstrerror(rspCode));
|
||||
CTG_ERR_RET(rspCode);
|
||||
}
|
||||
|
||||
code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
|
||||
if (code) {
|
||||
qError("Process qnode list rsp failed, error:%s", tstrerror(rspCode));
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
qDebug("Got qnode list from mnode, listNum:%d", (int32_t)taosArrayGetSize(out));
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_USE_DB: {
|
||||
if (TSDB_CODE_SUCCESS != rspCode) {
|
||||
qError("error rsp for use db, error:%s, dbFName:%s", tstrerror(rspCode), target);
|
||||
CTG_ERR_RET(rspCode);
|
||||
}
|
||||
|
||||
code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
|
||||
if (code) {
|
||||
qError("Process use db rsp failed, error:%s, dbFName:%s", tstrerror(code), target);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
qDebug("Got db vgInfo from mnode, dbFName:%s", target);
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_GET_DB_CFG: {
|
||||
if (TSDB_CODE_SUCCESS != rspCode) {
|
||||
qError("error rsp for get db cfg, error:%s, db:%s", tstrerror(rspCode), target);
|
||||
CTG_ERR_RET(rspCode);
|
||||
}
|
||||
|
||||
code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
|
||||
if (code) {
|
||||
qError("Process get db cfg rsp failed, error:%s, db:%s", tstrerror(code), target);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
qDebug("Got db cfg from mnode, dbFName:%s", target);
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_GET_INDEX: {
|
||||
if (TSDB_CODE_SUCCESS != rspCode) {
|
||||
qError("error rsp for get index, error:%s, indexName:%s", tstrerror(rspCode), target);
|
||||
CTG_ERR_RET(rspCode);
|
||||
}
|
||||
|
||||
code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
|
||||
if (code) {
|
||||
qError("Process get index rsp failed, error:%s, indexName:%s", tstrerror(code), target);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
qDebug("Got index from mnode, indexName:%s", target);
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_RETRIEVE_FUNC: {
|
||||
if (TSDB_CODE_SUCCESS != rspCode) {
|
||||
qError("error rsp for get udf, error:%s, funcName:%s", tstrerror(rspCode), target);
|
||||
CTG_ERR_RET(rspCode);
|
||||
}
|
||||
|
||||
code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
|
||||
if (code) {
|
||||
qError("Process get udf rsp failed, error:%s, funcName:%s", tstrerror(code), target);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
qDebug("Got udf from mnode, funcName:%s", target);
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_GET_USER_AUTH: {
|
||||
if (TSDB_CODE_SUCCESS != rspCode) {
|
||||
qError("error rsp for get user auth, error:%s, user:%s", tstrerror(rspCode), target);
|
||||
CTG_ERR_RET(rspCode);
|
||||
}
|
||||
|
||||
code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
|
||||
if (code) {
|
||||
qError("Process get user auth rsp failed, error:%s, user:%s", tstrerror(code), target);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
qDebug("Got user auth from mnode, user:%s", target);
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_TABLE_META: {
|
||||
if (TSDB_CODE_SUCCESS != rspCode) {
|
||||
if (CTG_TABLE_NOT_EXIST(rspCode)) {
|
||||
SET_META_TYPE_NULL(((STableMetaOutput*)out)->metaType);
|
||||
qDebug("stablemeta not exist in mnode, tbFName:%s", target);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
qError("error rsp for stablemeta from mnode, error:%s, tbFName:%s", tstrerror(rspCode), target);
|
||||
CTG_ERR_RET(rspCode);
|
||||
}
|
||||
|
||||
code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
|
||||
if (code) {
|
||||
qError("Process mnode stablemeta rsp failed, error:%s, tbFName:%s", tstrerror(code), target);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
qDebug("Got table meta from mnode, tbFName:%s", target);
|
||||
break;
|
||||
}
|
||||
case TDMT_VND_TABLE_META: {
|
||||
if (TSDB_CODE_SUCCESS != rspCode) {
|
||||
if (CTG_TABLE_NOT_EXIST(rspCode)) {
|
||||
SET_META_TYPE_NULL(((STableMetaOutput*)out)->metaType);
|
||||
qDebug("tablemeta not exist in vnode, tbFName:%s", target);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
qError("error rsp for table meta from vnode, code:%s, tbFName:%s", tstrerror(rspCode), target);
|
||||
CTG_ERR_RET(rspCode);
|
||||
}
|
||||
|
||||
code = queryProcessMsgRsp[TMSG_INDEX(reqType)](out, msg, msgSize);
|
||||
if (code) {
|
||||
qError("Process vnode tablemeta rsp failed, code:%s, tbFName:%s", tstrerror(code), target);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
qDebug("Got table meta from vnode, tbFName:%s", target);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgHandleMsgCallback(void *param, const SDataBuf *pMsg, int32_t rspCode) {
|
||||
SCtgTaskCallbackParam* cbParam = (SCtgTaskCallbackParam*)param;
|
||||
int32_t code = 0;
|
||||
|
||||
CTG_API_ENTER();
|
||||
|
||||
SCtgJob* pJob = taosAcquireRef(gCtgMgmt.jobPool, cbParam->refId);
|
||||
if (NULL == pJob) {
|
||||
qDebug("job refId %" PRIx64 " already dropped", cbParam->refId);
|
||||
goto _return;
|
||||
}
|
||||
|
||||
SCtgTask *pTask = taosArrayGet(pJob->pTasks, cbParam->taskId);
|
||||
|
||||
qDebug("QID:%" PRIx64 " task %d start to handle rsp %s", pJob->queryId, pTask->taskId, TMSG_INFO(cbParam->reqType + 1));
|
||||
|
||||
CTG_ERR_JRET((*gCtgAsyncFps[pTask->type].handleRspFp)(pTask, cbParam->reqType, pMsg, rspCode));
|
||||
|
||||
_return:
|
||||
|
||||
if (pJob) {
|
||||
taosReleaseRef(gCtgMgmt.jobPool, cbParam->refId);
|
||||
}
|
||||
|
||||
taosMemoryFree(param);
|
||||
|
||||
CTG_API_LEAVE(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgMakeMsgSendInfo(SCtgTask* pTask, int32_t msgType, SMsgSendInfo **pMsgSendInfo) {
|
||||
int32_t code = 0;
|
||||
SMsgSendInfo *msgSendInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
|
||||
if (NULL == msgSendInfo) {
|
||||
qError("calloc %d failed", (int32_t)sizeof(SMsgSendInfo));
|
||||
CTG_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SCtgTaskCallbackParam *param = taosMemoryCalloc(1, sizeof(SCtgTaskCallbackParam));
|
||||
if (NULL == param) {
|
||||
qError("calloc %d failed", (int32_t)sizeof(SCtgTaskCallbackParam));
|
||||
CTG_ERR_JRET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
param->reqType = msgType;
|
||||
param->queryId = pTask->pJob->queryId;
|
||||
param->refId = pTask->pJob->refId;
|
||||
param->taskId = pTask->taskId;
|
||||
|
||||
msgSendInfo->param = param;
|
||||
msgSendInfo->fp = ctgHandleMsgCallback;
|
||||
|
||||
*pMsgSendInfo = msgSendInfo;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
taosMemoryFree(param);
|
||||
taosMemoryFree(msgSendInfo);
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgAsyncSendMsg(CTG_PARAMS, SCtgTask* pTask, int32_t msgType, void *msg, uint32_t msgSize) {
|
||||
int32_t code = 0;
|
||||
SMsgSendInfo *pMsgSendInfo = NULL;
|
||||
CTG_ERR_JRET(ctgMakeMsgSendInfo(pTask, msgType, &pMsgSendInfo));
|
||||
|
||||
pMsgSendInfo->msgInfo.pData = msg;
|
||||
pMsgSendInfo->msgInfo.len = msgSize;
|
||||
pMsgSendInfo->msgInfo.handle = NULL;
|
||||
pMsgSendInfo->msgType = msgType;
|
||||
|
||||
int64_t transporterId = 0;
|
||||
code = asyncSendMsgToServer(pTrans, (SEpSet*)pMgmtEps, &transporterId, pMsgSendInfo);
|
||||
if (code) {
|
||||
ctgError("asyncSendMsgToSever failed, error: %s", tstrerror(code));
|
||||
CTG_ERR_JRET(code);
|
||||
}
|
||||
|
||||
ctgDebug("req msg sent, reqId:%" PRIx64 ", msg type:%d, %s", pTask->pJob->queryId, msgType, TMSG_INFO(msgType));
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
if (pMsgSendInfo) {
|
||||
taosMemoryFreeClear(pMsgSendInfo->param);
|
||||
taosMemoryFreeClear(pMsgSendInfo);
|
||||
}
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int32_t ctgGetQnodeListFromMnode(CTG_PARAMS, SArray *out, SCtgTask* pTask) {
|
||||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_QNODE_LIST;
|
||||
|
||||
ctgDebug("try to get qnode list from mnode, mgmtEpInUse:%d", pMgmtEps->inUse);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](NULL, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
ctgError("Build qnode list msg failed, error:%s", tstrerror(code));
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
if (pTask) {
|
||||
void* pOut = taosArrayInit(4, sizeof(struct SQueryNodeAddr));
|
||||
if (NULL == pOut) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, NULL));
|
||||
CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen));
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = reqType,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
rpcSendRecv(pTrans, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, NULL));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgGetDBVgInfoFromMnode(CTG_PARAMS, SBuildUseDBInput *input, SUseDbOutput *out, SCtgTask* pTask) {
|
||||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_USE_DB;
|
||||
|
||||
ctgDebug("try to get db vgInfo from mnode, dbFName:%s", input->db);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](input, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
ctgError("Build use db msg failed, code:%x, db:%s", code, input->db);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
if (pTask) {
|
||||
void* pOut = taosMemoryCalloc(1, sizeof(SUseDbOutput));
|
||||
if (NULL == pOut) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, input->db));
|
||||
|
||||
CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen));
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = reqType,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
rpcSendRecv(pTrans, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, input->db));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgGetDBCfgFromMnode(CTG_PARAMS, const char *dbFName, SDbCfgInfo *out, SCtgTask* pTask) {
|
||||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_GET_DB_CFG;
|
||||
|
||||
ctgDebug("try to get db cfg from mnode, dbFName:%s", dbFName);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)dbFName, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
ctgError("Build get db cfg msg failed, code:%x, db:%s", code, dbFName);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
if (pTask) {
|
||||
void* pOut = taosMemoryCalloc(1, sizeof(SDbCfgInfo));
|
||||
if (NULL == pOut) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)dbFName));
|
||||
|
||||
CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen));
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = TDMT_MND_GET_DB_CFG,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
rpcSendRecv(pTrans, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)dbFName));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgGetIndexInfoFromMnode(CTG_PARAMS, const char *indexName, SIndexInfo *out, SCtgTask* pTask) {
|
||||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_GET_INDEX;
|
||||
|
||||
ctgDebug("try to get index from mnode, indexName:%s", indexName);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)indexName, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
ctgError("Build get index msg failed, code:%x, db:%s", code, indexName);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
if (pTask) {
|
||||
void* pOut = taosMemoryCalloc(1, sizeof(SIndexInfo));
|
||||
if (NULL == pOut) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)indexName));
|
||||
|
||||
CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen));
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = reqType,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
rpcSendRecv(pTrans, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)indexName));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgGetUdfInfoFromMnode(CTG_PARAMS, const char *funcName, SFuncInfo *out, SCtgTask* pTask) {
|
||||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_RETRIEVE_FUNC;
|
||||
|
||||
ctgDebug("try to get udf info from mnode, funcName:%s", funcName);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)funcName, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
ctgError("Build get udf msg failed, code:%x, db:%s", code, funcName);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
if (pTask) {
|
||||
void* pOut = taosMemoryCalloc(1, sizeof(SFuncInfo));
|
||||
if (NULL == pOut) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)funcName));
|
||||
|
||||
CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen));
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = reqType,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
rpcSendRecv(pTrans, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)funcName));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgGetUserDbAuthFromMnode(CTG_PARAMS, const char *user, SGetUserAuthRsp *out, SCtgTask* pTask) {
|
||||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_GET_USER_AUTH;
|
||||
|
||||
ctgDebug("try to get user auth from mnode, user:%s", user);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)]((void *)user, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
ctgError("Build get user auth msg failed, code:%x, db:%s", code, user);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
if (pTask) {
|
||||
void* pOut = taosMemoryCalloc(1, sizeof(SGetUserAuthRsp));
|
||||
if (NULL == pOut) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, (char*)user));
|
||||
|
||||
CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen));
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = reqType,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
rpcSendRecv(pTrans, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, (char*)user));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgGetTbMetaFromMnodeImpl(CTG_PARAMS, char *dbFName, char* tbName, STableMetaOutput* out, SCtgTask* pTask) {
|
||||
SBuildTableMetaInput bInput = {.vgId = 0, .dbFName = dbFName, .tbName = tbName};
|
||||
char *msg = NULL;
|
||||
SEpSet *pVnodeEpSet = NULL;
|
||||
int32_t msgLen = 0;
|
||||
int32_t reqType = TDMT_MND_TABLE_META;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
sprintf(tbFName, "%s.%s", dbFName, tbName);
|
||||
|
||||
ctgDebug("try to get table meta from mnode, tbFName:%s", tbFName);
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
ctgError("Build mnode stablemeta msg failed, code:%x", code);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
if (pTask) {
|
||||
void* pOut = taosMemoryCalloc(1, sizeof(STableMetaOutput));
|
||||
if (NULL == pOut) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, tbFName));
|
||||
|
||||
CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen));
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = reqType,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
rpcSendRecv(pTrans, (SEpSet*)pMgmtEps, &rpcMsg, &rpcRsp);
|
||||
|
||||
CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, tbFName));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgGetTbMetaFromMnode(CTG_PARAMS, const SName* pTableName, STableMetaOutput* out, SCtgTask* pTask) {
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(pTableName, dbFName);
|
||||
|
||||
return ctgGetTbMetaFromMnodeImpl(CTG_PARAMS_LIST(), dbFName, (char *)pTableName->tname, out, pTask);
|
||||
}
|
||||
|
||||
int32_t ctgGetTbMetaFromVnode(CTG_PARAMS, const SName* pTableName, SVgroupInfo *vgroupInfo, STableMetaOutput* out, SCtgTask* pTask) {
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
tNameGetFullDbName(pTableName, dbFName);
|
||||
int32_t reqType = TDMT_VND_TABLE_META;
|
||||
char tbFName[TSDB_TABLE_FNAME_LEN];
|
||||
sprintf(tbFName, "%s.%s", dbFName, pTableName->tname);
|
||||
|
||||
ctgDebug("try to get table meta from vnode, vgId:%d, tbFName:%s", vgroupInfo->vgId, tbFName);
|
||||
|
||||
SBuildTableMetaInput bInput = {.vgId = vgroupInfo->vgId, .dbFName = dbFName, .tbName = (char *)tNameGetTableName(pTableName)};
|
||||
char *msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen);
|
||||
if (code) {
|
||||
ctgError("Build vnode tablemeta msg failed, code:%x, tbFName:%s", code, tbFName);
|
||||
CTG_ERR_RET(code);
|
||||
}
|
||||
|
||||
if (pTask) {
|
||||
void* pOut = taosMemoryCalloc(1, sizeof(STableMetaOutput));
|
||||
if (NULL == pOut) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
CTG_ERR_RET(ctgUpdateMsgCtx(&pTask->msgCtx, reqType, pOut, tbFName));
|
||||
|
||||
CTG_RET(ctgAsyncSendMsg(CTG_PARAMS_LIST(), pTask, reqType, msg, msgLen));
|
||||
}
|
||||
|
||||
SRpcMsg rpcMsg = {
|
||||
.msgType = reqType,
|
||||
.pCont = msg,
|
||||
.contLen = msgLen,
|
||||
};
|
||||
|
||||
SRpcMsg rpcRsp = {0};
|
||||
rpcSendRecv(pTrans, &vgroupInfo->epSet, &rpcMsg, &rpcRsp);
|
||||
|
||||
CTG_ERR_RET(ctgProcessRspMsg(out, reqType, rpcRsp.pCont, rpcRsp.contLen, rpcRsp.code, tbFName));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,577 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "trpc.h"
|
||||
#include "query.h"
|
||||
#include "tname.h"
|
||||
#include "catalogInt.h"
|
||||
#include "systable.h"
|
||||
|
||||
void ctgFreeSMetaData(SMetaData* pData) {
|
||||
taosArrayDestroy(pData->pTableMeta);
|
||||
pData->pTableMeta = NULL;
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pData->pDbVgroup); ++i) {
|
||||
SArray** pArray = taosArrayGet(pData->pDbVgroup, i);
|
||||
taosArrayDestroy(*pArray);
|
||||
}
|
||||
taosArrayDestroy(pData->pDbVgroup);
|
||||
pData->pDbVgroup = NULL;
|
||||
|
||||
taosArrayDestroy(pData->pTableHash);
|
||||
pData->pTableHash = NULL;
|
||||
|
||||
taosArrayDestroy(pData->pUdfList);
|
||||
pData->pUdfList = NULL;
|
||||
|
||||
for (int32_t i = 0; i < taosArrayGetSize(pData->pDbCfg); ++i) {
|
||||
SDbCfgInfo* pInfo = taosArrayGet(pData->pDbCfg, i);
|
||||
taosArrayDestroy(pInfo->pRetensions);
|
||||
}
|
||||
taosArrayDestroy(pData->pDbCfg);
|
||||
pData->pDbCfg = NULL;
|
||||
|
||||
taosArrayDestroy(pData->pIndex);
|
||||
pData->pIndex = NULL;
|
||||
|
||||
taosArrayDestroy(pData->pUser);
|
||||
pData->pUser = NULL;
|
||||
|
||||
taosArrayDestroy(pData->pQnodeList);
|
||||
pData->pQnodeList = NULL;
|
||||
}
|
||||
|
||||
void ctgFreeSCtgUserAuth(SCtgUserAuth *userCache) {
|
||||
taosHashCleanup(userCache->createdDbs);
|
||||
taosHashCleanup(userCache->readDbs);
|
||||
taosHashCleanup(userCache->writeDbs);
|
||||
}
|
||||
|
||||
void ctgFreeMetaRent(SCtgRentMgmt *mgmt) {
|
||||
if (NULL == mgmt->slots) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < mgmt->slotNum; ++i) {
|
||||
SCtgRentSlot *slot = &mgmt->slots[i];
|
||||
if (slot->meta) {
|
||||
taosArrayDestroy(slot->meta);
|
||||
slot->meta = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(mgmt->slots);
|
||||
}
|
||||
|
||||
|
||||
void ctgFreeTbMetaCache(SCtgTbMetaCache *cache) {
|
||||
CTG_LOCK(CTG_WRITE, &cache->stbLock);
|
||||
if (cache->stbCache) {
|
||||
int32_t stblNum = taosHashGetSize(cache->stbCache);
|
||||
taosHashCleanup(cache->stbCache);
|
||||
cache->stbCache = NULL;
|
||||
CTG_CACHE_STAT_SUB(stblNum, stblNum);
|
||||
}
|
||||
CTG_UNLOCK(CTG_WRITE, &cache->stbLock);
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &cache->metaLock);
|
||||
if (cache->metaCache) {
|
||||
int32_t tblNum = taosHashGetSize(cache->metaCache);
|
||||
taosHashCleanup(cache->metaCache);
|
||||
cache->metaCache = NULL;
|
||||
CTG_CACHE_STAT_SUB(tblNum, tblNum);
|
||||
}
|
||||
CTG_UNLOCK(CTG_WRITE, &cache->metaLock);
|
||||
}
|
||||
|
||||
void ctgFreeVgInfo(SDBVgInfo *vgInfo) {
|
||||
if (NULL == vgInfo) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (vgInfo->vgHash) {
|
||||
taosHashCleanup(vgInfo->vgHash);
|
||||
vgInfo->vgHash = NULL;
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(vgInfo);
|
||||
}
|
||||
|
||||
void ctgFreeDbCache(SCtgDBCache *dbCache) {
|
||||
if (NULL == dbCache) {
|
||||
return;
|
||||
}
|
||||
|
||||
CTG_LOCK(CTG_WRITE, &dbCache->vgLock);
|
||||
ctgFreeVgInfo (dbCache->vgInfo);
|
||||
CTG_UNLOCK(CTG_WRITE, &dbCache->vgLock);
|
||||
|
||||
ctgFreeTbMetaCache(&dbCache->tbCache);
|
||||
}
|
||||
|
||||
|
||||
void ctgFreeHandle(SCatalog* pCtg) {
|
||||
ctgFreeMetaRent(&pCtg->dbRent);
|
||||
ctgFreeMetaRent(&pCtg->stbRent);
|
||||
|
||||
if (pCtg->dbCache) {
|
||||
int32_t dbNum = taosHashGetSize(pCtg->dbCache);
|
||||
|
||||
void *pIter = taosHashIterate(pCtg->dbCache, NULL);
|
||||
while (pIter) {
|
||||
SCtgDBCache *dbCache = pIter;
|
||||
|
||||
atomic_store_8(&dbCache->deleted, 1);
|
||||
|
||||
ctgFreeDbCache(dbCache);
|
||||
|
||||
pIter = taosHashIterate(pCtg->dbCache, pIter);
|
||||
}
|
||||
|
||||
taosHashCleanup(pCtg->dbCache);
|
||||
|
||||
CTG_CACHE_STAT_SUB(dbNum, dbNum);
|
||||
}
|
||||
|
||||
if (pCtg->userCache) {
|
||||
int32_t userNum = taosHashGetSize(pCtg->userCache);
|
||||
|
||||
void *pIter = taosHashIterate(pCtg->userCache, NULL);
|
||||
while (pIter) {
|
||||
SCtgUserAuth *userCache = pIter;
|
||||
|
||||
ctgFreeSCtgUserAuth(userCache);
|
||||
|
||||
pIter = taosHashIterate(pCtg->userCache, pIter);
|
||||
}
|
||||
|
||||
taosHashCleanup(pCtg->userCache);
|
||||
|
||||
CTG_CACHE_STAT_SUB(userNum, userNum);
|
||||
}
|
||||
|
||||
taosMemoryFree(pCtg);
|
||||
}
|
||||
|
||||
|
||||
void ctgFreeSUseDbOutput(SUseDbOutput* pOutput) {
|
||||
if (NULL == pOutput || NULL == pOutput->dbVgroup) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosHashCleanup(pOutput->dbVgroup->vgHash);
|
||||
taosMemoryFreeClear(pOutput->dbVgroup);
|
||||
taosMemoryFree(pOutput);
|
||||
}
|
||||
|
||||
void ctgFreeMsgCtx(SCtgMsgCtx* pCtx) {
|
||||
taosMemoryFreeClear(pCtx->target);
|
||||
if (NULL == pCtx->out) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (pCtx->reqType) {
|
||||
case TDMT_MND_GET_DB_CFG: {
|
||||
SDbCfgInfo* pOut = (SDbCfgInfo*)pCtx->out;
|
||||
taosArrayDestroy(pOut->pRetensions);
|
||||
taosMemoryFreeClear(pCtx->out);
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_USE_DB:{
|
||||
SUseDbOutput* pOut = (SUseDbOutput*)pCtx->out;
|
||||
ctgFreeSUseDbOutput(pOut);
|
||||
pCtx->out = NULL;
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_GET_INDEX: {
|
||||
SIndexInfo* pOut = (SIndexInfo*)pCtx->out;
|
||||
taosMemoryFreeClear(pCtx->out);
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_QNODE_LIST: {
|
||||
SArray* pOut = (SArray*)pCtx->out;
|
||||
taosArrayDestroy(pOut);
|
||||
pCtx->out = NULL;
|
||||
break;
|
||||
}
|
||||
case TDMT_VND_TABLE_META:
|
||||
case TDMT_MND_TABLE_META: {
|
||||
STableMetaOutput* pOut = (STableMetaOutput*)pCtx->out;
|
||||
taosMemoryFree(pOut->tbMeta);
|
||||
taosMemoryFreeClear(pCtx->out);
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_RETRIEVE_FUNC: {
|
||||
SFuncInfo* pOut = (SFuncInfo*)pCtx->out;
|
||||
taosMemoryFree(pOut->pCode);
|
||||
taosMemoryFree(pOut->pComment);
|
||||
taosMemoryFreeClear(pCtx->out);
|
||||
break;
|
||||
}
|
||||
case TDMT_MND_GET_USER_AUTH: {
|
||||
SGetUserAuthRsp* pOut = (SGetUserAuthRsp*)pCtx->out;
|
||||
taosHashCleanup(pOut->createdDbs);
|
||||
taosHashCleanup(pOut->readDbs);
|
||||
taosHashCleanup(pOut->writeDbs);
|
||||
taosMemoryFreeClear(pCtx->out);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qError("invalid reqType %d", pCtx->reqType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ctgFreeSTableMetaOutput(STableMetaOutput* pOutput) {
|
||||
if (NULL == pOutput) {
|
||||
return;
|
||||
}
|
||||
|
||||
taosMemoryFree(pOutput->tbMeta);
|
||||
taosMemoryFree(pOutput);
|
||||
}
|
||||
|
||||
|
||||
void ctgResetTbMetaTask(SCtgTask* pTask) {
|
||||
SCtgTbMetaCtx* taskCtx = (SCtgTbMetaCtx*)pTask->taskCtx;
|
||||
memset(&taskCtx->tbInfo, 0, sizeof(taskCtx->tbInfo));
|
||||
taskCtx->flag = CTG_FLAG_UNKNOWN_STB;
|
||||
|
||||
if (pTask->msgCtx.lastOut) {
|
||||
ctgFreeSTableMetaOutput((STableMetaOutput*)pTask->msgCtx.lastOut);
|
||||
pTask->msgCtx.lastOut = NULL;
|
||||
}
|
||||
if (pTask->msgCtx.out) {
|
||||
ctgFreeSTableMetaOutput((STableMetaOutput*)pTask->msgCtx.out);
|
||||
pTask->msgCtx.out = NULL;
|
||||
}
|
||||
taosMemoryFreeClear(pTask->msgCtx.target);
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
}
|
||||
|
||||
void ctgFreeTask(SCtgTask* pTask) {
|
||||
ctgFreeMsgCtx(&pTask->msgCtx);
|
||||
|
||||
switch (pTask->type) {
|
||||
case CTG_TASK_GET_QNODE: {
|
||||
taosArrayDestroy((SArray*)pTask->res);
|
||||
pTask->res = NULL;
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_TB_META: {
|
||||
SCtgTbMetaCtx* taskCtx = (SCtgTbMetaCtx*)pTask->taskCtx;
|
||||
taosMemoryFreeClear(taskCtx->pName);
|
||||
if (pTask->msgCtx.lastOut) {
|
||||
ctgFreeSTableMetaOutput((STableMetaOutput*)pTask->msgCtx.lastOut);
|
||||
pTask->msgCtx.lastOut = NULL;
|
||||
}
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_DB_VGROUP: {
|
||||
taosArrayDestroy((SArray*)pTask->res);
|
||||
pTask->res = NULL;
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_DB_CFG: {
|
||||
if (pTask->res) {
|
||||
taosArrayDestroy(((SDbCfgInfo*)pTask->res)->pRetensions);
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_TB_HASH: {
|
||||
SCtgTbHashCtx* taskCtx = (SCtgTbHashCtx*)pTask->taskCtx;
|
||||
taosMemoryFreeClear(taskCtx->pName);
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_INDEX: {
|
||||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_UDF: {
|
||||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_USER: {
|
||||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
taosMemoryFreeClear(pTask->res);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qError("invalid task type %d", pTask->type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ctgFreeTasks(SArray* pArray) {
|
||||
if (NULL == pArray) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t num = taosArrayGetSize(pArray);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
SCtgTask* pTask = taosArrayGet(pArray, i);
|
||||
ctgFreeTask(pTask);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pArray);
|
||||
}
|
||||
|
||||
void ctgFreeJob(void* job) {
|
||||
if (NULL == job) {
|
||||
return;
|
||||
}
|
||||
|
||||
SCtgJob* pJob = (SCtgJob*)job;
|
||||
|
||||
int64_t rid = pJob->refId;
|
||||
uint64_t qid = pJob->queryId;
|
||||
|
||||
ctgFreeTasks(pJob->pTasks);
|
||||
|
||||
ctgFreeSMetaData(&pJob->jobRes);
|
||||
|
||||
taosMemoryFree(job);
|
||||
|
||||
qDebug("QID:%" PRIx64 ", job %" PRIx64 " freed", qid, rid);
|
||||
}
|
||||
|
||||
int32_t ctgUpdateMsgCtx(SCtgMsgCtx* pCtx, int32_t reqType, void* out, char* target) {
|
||||
ctgFreeMsgCtx(pCtx);
|
||||
|
||||
pCtx->reqType = reqType;
|
||||
pCtx->out = out;
|
||||
if (target) {
|
||||
pCtx->target = strdup(target);
|
||||
if (NULL == pCtx->target) {
|
||||
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
} else {
|
||||
pCtx->target = NULL;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgGetHashFunction(int8_t hashMethod, tableNameHashFp *fp) {
|
||||
switch (hashMethod) {
|
||||
default:
|
||||
*fp = MurmurHash3_32;
|
||||
break;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ctgGenerateVgList(SCatalog *pCtg, SHashObj *vgHash, SArray** pList) {
|
||||
SHashObj *vgroupHash = NULL;
|
||||
SVgroupInfo *vgInfo = NULL;
|
||||
SArray *vgList = NULL;
|
||||
int32_t code = 0;
|
||||
int32_t vgNum = taosHashGetSize(vgHash);
|
||||
|
||||
vgList = taosArrayInit(vgNum, sizeof(SVgroupInfo));
|
||||
if (NULL == vgList) {
|
||||
ctgError("taosArrayInit failed, num:%d", vgNum);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
}
|
||||
|
||||
void *pIter = taosHashIterate(vgHash, NULL);
|
||||
while (pIter) {
|
||||
vgInfo = pIter;
|
||||
|
||||
if (NULL == taosArrayPush(vgList, vgInfo)) {
|
||||
ctgError("taosArrayPush failed, vgId:%d", vgInfo->vgId);
|
||||
taosHashCancelIterate(vgHash, pIter);
|
||||
CTG_ERR_JRET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(vgHash, pIter);
|
||||
vgInfo = NULL;
|
||||
}
|
||||
|
||||
*pList = vgList;
|
||||
|
||||
ctgDebug("Got vgList from cache, vgNum:%d", vgNum);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
|
||||
if (vgList) {
|
||||
taosArrayDestroy(vgList);
|
||||
}
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
|
||||
int32_t ctgGetVgInfoFromHashValue(SCatalog *pCtg, SDBVgInfo *dbInfo, const SName *pTableName, SVgroupInfo *pVgroup) {
|
||||
int32_t code = 0;
|
||||
|
||||
int32_t vgNum = taosHashGetSize(dbInfo->vgHash);
|
||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||
tNameGetFullDbName(pTableName, db);
|
||||
|
||||
if (vgNum <= 0) {
|
||||
ctgError("db vgroup cache invalid, db:%s, vgroup number:%d", db, vgNum);
|
||||
CTG_ERR_RET(TSDB_CODE_TSC_DB_NOT_SELECTED);
|
||||
}
|
||||
|
||||
tableNameHashFp fp = NULL;
|
||||
SVgroupInfo *vgInfo = NULL;
|
||||
|
||||
CTG_ERR_RET(ctgGetHashFunction(dbInfo->hashMethod, &fp));
|
||||
|
||||
char tbFullName[TSDB_TABLE_FNAME_LEN];
|
||||
tNameExtractFullName(pTableName, tbFullName);
|
||||
|
||||
uint32_t hashValue = (*fp)(tbFullName, (uint32_t)strlen(tbFullName));
|
||||
|
||||
void *pIter = taosHashIterate(dbInfo->vgHash, NULL);
|
||||
while (pIter) {
|
||||
vgInfo = pIter;
|
||||
if (hashValue >= vgInfo->hashBegin && hashValue <= vgInfo->hashEnd) {
|
||||
taosHashCancelIterate(dbInfo->vgHash, pIter);
|
||||
break;
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(dbInfo->vgHash, pIter);
|
||||
vgInfo = NULL;
|
||||
}
|
||||
|
||||
if (NULL == vgInfo) {
|
||||
ctgError("no hash range found for hash value [%u], db:%s, numOfVgId:%d", hashValue, db, taosHashGetSize(dbInfo->vgHash));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
*pVgroup = *vgInfo;
|
||||
|
||||
CTG_RET(code);
|
||||
}
|
||||
|
||||
int32_t ctgStbVersionSearchCompare(const void* key1, const void* key2) {
|
||||
if (*(uint64_t *)key1 < ((SSTableMetaVersion*)key2)->suid) {
|
||||
return -1;
|
||||
} else if (*(uint64_t *)key1 > ((SSTableMetaVersion*)key2)->suid) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ctgDbVgVersionSearchCompare(const void* key1, const void* key2) {
|
||||
if (*(int64_t *)key1 < ((SDbVgVersion*)key2)->dbId) {
|
||||
return -1;
|
||||
} else if (*(int64_t *)key1 > ((SDbVgVersion*)key2)->dbId) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ctgStbVersionSortCompare(const void* key1, const void* key2) {
|
||||
if (((SSTableMetaVersion*)key1)->suid < ((SSTableMetaVersion*)key2)->suid) {
|
||||
return -1;
|
||||
} else if (((SSTableMetaVersion*)key1)->suid > ((SSTableMetaVersion*)key2)->suid) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t ctgDbVgVersionSortCompare(const void* key1, const void* key2) {
|
||||
if (((SDbVgVersion*)key1)->dbId < ((SDbVgVersion*)key2)->dbId) {
|
||||
return -1;
|
||||
} else if (((SDbVgVersion*)key1)->dbId > ((SDbVgVersion*)key2)->dbId) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int32_t ctgCloneVgInfo(SDBVgInfo *src, SDBVgInfo **dst) {
|
||||
*dst = taosMemoryMalloc(sizeof(SDBVgInfo));
|
||||
if (NULL == *dst) {
|
||||
qError("malloc %d failed", (int32_t)sizeof(SDBVgInfo));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
}
|
||||
|
||||
memcpy(*dst, src, sizeof(SDBVgInfo));
|
||||
|
||||
size_t hashSize = taosHashGetSize(src->vgHash);
|
||||
(*dst)->vgHash = taosHashInit(hashSize, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
|
||||
if (NULL == (*dst)->vgHash) {
|
||||
qError("taosHashInit %d failed", (int32_t)hashSize);
|
||||
taosMemoryFreeClear(*dst);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
}
|
||||
|
||||
int32_t *vgId = NULL;
|
||||
void *pIter = taosHashIterate(src->vgHash, NULL);
|
||||
while (pIter) {
|
||||
vgId = taosHashGetKey(pIter, NULL);
|
||||
|
||||
if (taosHashPut((*dst)->vgHash, (void *)vgId, sizeof(int32_t), pIter, sizeof(SVgroupInfo))) {
|
||||
qError("taosHashPut failed, hashSize:%d", (int32_t)hashSize);
|
||||
taosHashCancelIterate(src->vgHash, pIter);
|
||||
taosHashCleanup((*dst)->vgHash);
|
||||
taosMemoryFreeClear(*dst);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
}
|
||||
|
||||
pIter = taosHashIterate(src->vgHash, pIter);
|
||||
}
|
||||
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int32_t ctgCloneMetaOutput(STableMetaOutput *output, STableMetaOutput **pOutput) {
|
||||
*pOutput = taosMemoryMalloc(sizeof(STableMetaOutput));
|
||||
if (NULL == *pOutput) {
|
||||
qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput));
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
}
|
||||
|
||||
memcpy(*pOutput, output, sizeof(STableMetaOutput));
|
||||
|
||||
if (output->tbMeta) {
|
||||
int32_t metaSize = CTG_META_SIZE(output->tbMeta);
|
||||
(*pOutput)->tbMeta = taosMemoryMalloc(metaSize);
|
||||
if (NULL == (*pOutput)->tbMeta) {
|
||||
qError("malloc %d failed", (int32_t)sizeof(STableMetaOutput));
|
||||
taosMemoryFreeClear(*pOutput);
|
||||
CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR);
|
||||
}
|
||||
|
||||
memcpy((*pOutput)->tbMeta, output->tbMeta, metaSize);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -40,10 +40,8 @@
|
|||
|
||||
namespace {
|
||||
|
||||
extern "C" int32_t ctgGetTableMetaFromCache(struct SCatalog *pCatalog, const SName *pTableName, STableMeta **pTableMeta,
|
||||
bool *inCache, int32_t flag, uint64_t *dbId);
|
||||
extern "C" int32_t ctgdGetClusterCacheNum(struct SCatalog* pCatalog, int32_t type);
|
||||
extern "C" int32_t ctgActUpdateTbl(SCtgMetaAction *action);
|
||||
extern "C" int32_t ctgActUpdateTb(SCtgMetaAction *action);
|
||||
extern "C" int32_t ctgdEnableDebug(char *option);
|
||||
extern "C" int32_t ctgdGetStatNum(char *option, void *res);
|
||||
|
||||
|
@ -52,7 +50,7 @@ void ctgTestSetRspCTableMeta();
|
|||
void ctgTestSetRspSTableMeta();
|
||||
void ctgTestSetRspMultiSTableMeta();
|
||||
|
||||
extern "C" SCatalogMgmt gCtgMgmt;
|
||||
//extern "C" SCatalogMgmt gCtgMgmt;
|
||||
|
||||
enum {
|
||||
CTGT_RSP_VGINFO = 1,
|
||||
|
@ -859,8 +857,12 @@ void *ctgTestGetCtableMetaThread(void *param) {
|
|||
strcpy(cn.dbname, "db1");
|
||||
strcpy(cn.tname, ctgTestCTablename);
|
||||
|
||||
SCtgTbMetaCtx ctx = {0};
|
||||
ctx.pName = &cn;
|
||||
ctx.flag = CTG_FLAG_UNKNOWN_STB;
|
||||
|
||||
while (!ctgTestStop) {
|
||||
code = ctgGetTableMetaFromCache(pCtg, &cn, &tbMeta, &inCache, 0, NULL);
|
||||
code = ctgReadTbMetaFromCache(pCtg, &ctx, &tbMeta);
|
||||
if (code || !inCache) {
|
||||
assert(0);
|
||||
}
|
||||
|
@ -899,7 +901,7 @@ void *ctgTestSetCtableMetaThread(void *param) {
|
|||
msg->output = output;
|
||||
action.data = msg;
|
||||
|
||||
code = ctgActUpdateTbl(&action);
|
||||
code = ctgActUpdateTb(&action);
|
||||
if (code) {
|
||||
assert(0);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <executorimpl.h>
|
||||
#include "filter.h"
|
||||
#include "function.h"
|
||||
#include "functionMgt.h"
|
||||
|
@ -4059,7 +4058,7 @@ int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t n
|
|||
defaultBufsz = defaultPgsz * 4;
|
||||
}
|
||||
|
||||
int32_t code = createDiskbasedBuf(&pAggSup->pResultBuf, defaultPgsz, defaultBufsz, pKey, "/tmp/");
|
||||
int32_t code = createDiskbasedBuf(&pAggSup->pResultBuf, defaultPgsz, defaultBufsz, pKey, TD_TMP_DIR_PATH);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -614,7 +614,7 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
goto _error;
|
||||
}
|
||||
|
||||
int32_t code = createDiskbasedBuf(&pInfo->pBuf, 4096, 4096 * 256, pTaskInfo->id.str, "/tmp/");
|
||||
int32_t code = createDiskbasedBuf(&pInfo->pBuf, 4096, 4096 * 256, pTaskInfo->id.str, TD_TMP_DIR_PATH);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
|
|
@ -19,38 +19,11 @@
|
|||
#include "nodes.h"
|
||||
#include "tdatablock.h"
|
||||
|
||||
typedef struct SIFCtx {
|
||||
int32_t code;
|
||||
SHashObj *pRes; /* element is SScalarParam */
|
||||
bool noExec; // true: just iterate condition tree, and add hint to executor plan
|
||||
// SIdxFltStatus st;
|
||||
} SIFCtx;
|
||||
|
||||
#define SIF_ERR_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
return _code; \
|
||||
} \
|
||||
} while (0)
|
||||
#define SIF_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
} \
|
||||
return _code; \
|
||||
} while (0)
|
||||
#define SIF_ERR_JRET(c) \
|
||||
do { \
|
||||
code = c; \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = code; \
|
||||
goto _return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
// clang-format off
|
||||
#define SIF_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
|
||||
#define SIF_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
|
||||
#define SIF_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
|
||||
// clang-format on
|
||||
typedef struct SIFParam {
|
||||
SHashObj *pFilter;
|
||||
|
||||
|
@ -65,6 +38,13 @@ typedef struct SIFParam {
|
|||
char colName[TSDB_COL_NAME_LEN];
|
||||
} SIFParam;
|
||||
|
||||
typedef struct SIFCtx {
|
||||
int32_t code;
|
||||
SHashObj *pRes; /* element is SIFParam */
|
||||
bool noExec; // true: just iterate condition tree, and add hint to executor plan
|
||||
// SIdxFltStatus st;
|
||||
} SIFCtx;
|
||||
|
||||
static int32_t sifGetFuncFromSql(EOperatorType src, EIndexQueryType *dst) {
|
||||
if (src == OP_TYPE_GREATER_THAN) {
|
||||
*dst = QUERY_GREATER_THAN;
|
||||
|
|
|
@ -990,7 +990,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, void* pDataR
|
|||
|
||||
size_t childKeyBufSize = sizeof(int64_t) + sizeof(int64_t) + sizeof(TSKEY);
|
||||
initCatchSupporter(&pInfo->childAggSup, 1024, childKeyBufSize,
|
||||
"StreamFinalInterval", "/tmp/"); // TODO(liuyao) get row size from phy plan
|
||||
"StreamFinalInterval", TD_TMP_DIR_PATH); // TODO(liuyao) get row size from phy plan
|
||||
|
||||
pOperator->name = "StreamBlockScanOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN;
|
||||
|
|
|
@ -1181,6 +1181,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
|
||||
initExecTimeWindowInfo(&pInfo->twAggSup.timeWindowData, &pInfo->win);
|
||||
pInfo->invertible = allInvertible(pInfo->binfo.pCtx, numOfCols);
|
||||
pInfo->invertible = false; // Todo(liuyao): Dependent TSDB API
|
||||
|
||||
// pInfo->pTableQueryInfo = initTableQueryInfo(pTableGroupInfo);
|
||||
if (code != TSDB_CODE_SUCCESS /* || pInfo->pTableQueryInfo == NULL*/) {
|
||||
|
|
|
@ -247,7 +247,7 @@ SLHashObj* tHashInit(int32_t inMemPages, int32_t pageSize, _hash_fn_t fn, int32_
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int32_t code = createDiskbasedBuf(&pHashObj->pBuf, pageSize, inMemPages * pageSize, 0, "/tmp");
|
||||
int32_t code = createDiskbasedBuf(&pHashObj->pBuf, pageSize, inMemPages * pageSize, 0, TD_TMP_DIR_PATH);
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
return NULL;
|
||||
|
|
|
@ -155,7 +155,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) {
|
|||
int32_t start = 0;
|
||||
|
||||
if (pHandle->pBuf == NULL) {
|
||||
int32_t code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, "doAddToBuf", "/tmp");
|
||||
int32_t code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, "doAddToBuf", TD_TMP_DIR_PATH);
|
||||
dBufSetPrintInfo(pHandle->pBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
|
@ -217,7 +217,7 @@ static int32_t sortComparInit(SMsortComparParam* cmpParam, SArray* pSources, int
|
|||
} else {
|
||||
// multi-pass internal merge sort is required
|
||||
if (pHandle->pBuf == NULL) {
|
||||
code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, "sortComparInit", "/tmp");
|
||||
code = createDiskbasedBuf(&pHandle->pBuf, pHandle->pageSize, pHandle->numOfPages * pHandle->pageSize, "sortComparInit", TD_TMP_DIR_PATH);
|
||||
dBufSetPrintInfo(pHandle->pBuf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
|
|
|
@ -57,7 +57,7 @@ void sifInitLogFile() {
|
|||
|
||||
tsAsyncLog = 0;
|
||||
qDebugFlag = 159;
|
||||
strcpy(tsLogDir, "/tmp/sif");
|
||||
strcpy(tsLogDir, TD_TMP_DIR_PATH "sif");
|
||||
taosRemoveDir(tsLogDir);
|
||||
taosMkDir(tsLogDir);
|
||||
|
||||
|
|
|
@ -66,22 +66,18 @@ static bool isSpecificClassifyFunc(int32_t funcId, uint64_t classification) {
|
|||
}
|
||||
|
||||
static int32_t getUdfInfo(SFmGetFuncInfoParam* pParam, SFunctionNode* pFunc) {
|
||||
SFuncInfo* pInfo = NULL;
|
||||
int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFunc->functionName, &pInfo);
|
||||
SFuncInfo funcInfo = {0};
|
||||
int32_t code = catalogGetUdfInfo(pParam->pCtg, pParam->pRpc, pParam->pMgmtEps, pFunc->functionName, &funcInfo);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
if (NULL == pInfo) {
|
||||
snprintf(pParam->pErrBuf, pParam->errBufLen, "Invalid function name: %s", pFunc->functionName);
|
||||
return TSDB_CODE_FUNC_INVALID_FUNTION;
|
||||
}
|
||||
|
||||
pFunc->funcType = FUNCTION_TYPE_UDF;
|
||||
pFunc->funcId = TSDB_FUNC_TYPE_AGGREGATE == pInfo->funcType ? FUNC_AGGREGATE_UDF_ID : FUNC_SCALAR_UDF_ID;
|
||||
pFunc->node.resType.type = pInfo->outputType;
|
||||
pFunc->node.resType.bytes = pInfo->outputLen;
|
||||
pFunc->udfBufSize = pInfo->bufSize;
|
||||
tFreeSFuncInfo(pInfo);
|
||||
taosMemoryFree(pInfo);
|
||||
pFunc->funcId = TSDB_FUNC_TYPE_AGGREGATE == funcInfo.funcType ? FUNC_AGGREGATE_UDF_ID : FUNC_SCALAR_UDF_ID;
|
||||
pFunc->node.resType.type = funcInfo.outputType;
|
||||
pFunc->node.resType.bytes = funcInfo.outputLen;
|
||||
pFunc->udfBufSize = funcInfo.bufSize;
|
||||
tFreeSFuncInfo(&funcInfo);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ tMemBucket *tMemBucketCreate(int16_t nElemSize, int16_t dataType, double minval,
|
|||
|
||||
resetSlotInfo(pBucket);
|
||||
|
||||
int32_t ret = createDiskbasedBuf(&pBucket->pBuffer, pBucket->bufPageSize, pBucket->bufPageSize * 512, "1", "/tmp");
|
||||
int32_t ret = createDiskbasedBuf(&pBucket->pBuffer, pBucket->bufPageSize, pBucket->bufPageSize * 512, "1", TD_TMP_DIR_PATH);
|
||||
if (ret != 0) {
|
||||
tMemBucketDestroy(pBucket);
|
||||
return NULL;
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include "builtinsimpl.h"
|
||||
#include "functionMgt.h"
|
||||
|
||||
//TODO: add unit test
|
||||
typedef struct SUdfdData {
|
||||
bool startCalled;
|
||||
bool needCleanUp;
|
||||
|
@ -45,7 +44,15 @@ typedef struct SUdfdData {
|
|||
|
||||
SUdfdData udfdGlobal = {0};
|
||||
|
||||
int32_t udfStartUdfd(int32_t startDnodeId);
|
||||
int32_t udfStopUdfd();
|
||||
|
||||
static int32_t udfSpawnUdfd(SUdfdData *pData);
|
||||
void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal);
|
||||
static int32_t udfSpawnUdfd(SUdfdData* pData);
|
||||
static void udfUdfdCloseWalkCb(uv_handle_t* handle, void* arg);
|
||||
static void udfUdfdStopAsyncCb(uv_async_t *async);
|
||||
static void udfWatchUdfd(void *args);
|
||||
|
||||
void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) {
|
||||
fnInfo("udfd process exited with status %" PRId64 ", signal %d", exitStatus, termSignal);
|
||||
|
@ -65,12 +72,20 @@ static int32_t udfSpawnUdfd(SUdfdData* pData) {
|
|||
char path[PATH_MAX] = {0};
|
||||
if (tsProcPath == NULL) {
|
||||
path[0] = '.';
|
||||
#ifdef WINDOWS
|
||||
GetModuleFileName(NULL, path, PATH_MAX);
|
||||
taosDirName(path);
|
||||
#endif
|
||||
} else {
|
||||
strncpy(path, tsProcPath, strlen(tsProcPath));
|
||||
taosDirName(path);
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
if (strlen(path)==0) {
|
||||
strcat(path, "udfd.exe");
|
||||
} else {
|
||||
strcat(path, "\\udfd.exe");
|
||||
}
|
||||
#else
|
||||
strcat(path, "/udfd");
|
||||
#endif
|
||||
|
@ -413,6 +428,34 @@ enum {
|
|||
UDFC_STATE_STOPPING, // stopping after udfcClose
|
||||
};
|
||||
|
||||
int32_t getUdfdPipeName(char* pipeName, int32_t size);
|
||||
int32_t encodeUdfSetupRequest(void **buf, const SUdfSetupRequest *setup);
|
||||
void* decodeUdfSetupRequest(const void* buf, SUdfSetupRequest *request);
|
||||
int32_t encodeUdfInterBuf(void **buf, const SUdfInterBuf* state);
|
||||
void* decodeUdfInterBuf(const void* buf, SUdfInterBuf* state);
|
||||
int32_t encodeUdfCallRequest(void **buf, const SUdfCallRequest *call);
|
||||
void* decodeUdfCallRequest(const void* buf, SUdfCallRequest* call);
|
||||
int32_t encodeUdfTeardownRequest(void **buf, const SUdfTeardownRequest *teardown);
|
||||
void* decodeUdfTeardownRequest(const void* buf, SUdfTeardownRequest *teardown);
|
||||
int32_t encodeUdfRequest(void** buf, const SUdfRequest* request);
|
||||
void* decodeUdfRequest(const void* buf, SUdfRequest* request);
|
||||
int32_t encodeUdfSetupResponse(void **buf, const SUdfSetupResponse *setupRsp);
|
||||
void* decodeUdfSetupResponse(const void* buf, SUdfSetupResponse* setupRsp);
|
||||
int32_t encodeUdfCallResponse(void **buf, const SUdfCallResponse *callRsp);
|
||||
void* decodeUdfCallResponse(const void* buf, SUdfCallResponse* callRsp);
|
||||
int32_t encodeUdfTeardownResponse(void** buf, const SUdfTeardownResponse* teardownRsp);
|
||||
void* decodeUdfTeardownResponse(const void* buf, SUdfTeardownResponse* teardownResponse);
|
||||
int32_t encodeUdfResponse(void** buf, const SUdfResponse* rsp);
|
||||
void* decodeUdfResponse(const void* buf, SUdfResponse* rsp);
|
||||
void freeUdfColumnData(SUdfColumnData *data, SUdfColumnMeta *meta);
|
||||
void freeUdfColumn(SUdfColumn* col);
|
||||
void freeUdfDataDataBlock(SUdfDataBlock *block);
|
||||
void freeUdfInterBuf(SUdfInterBuf *buf);
|
||||
int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlock);
|
||||
int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block);
|
||||
int32_t convertScalarParamToDataBlock(SScalarParam *input, int32_t numOfCols, SSDataBlock *output);
|
||||
int32_t convertDataBlockToScalarParm(SSDataBlock *input, SScalarParam *output);
|
||||
|
||||
int32_t getUdfdPipeName(char* pipeName, int32_t size) {
|
||||
char dnodeId[8] = {0};
|
||||
size_t dnodeIdSize = sizeof(dnodeId);
|
||||
|
@ -650,7 +693,7 @@ int32_t encodeUdfResponse(void** buf, const SUdfResponse* rsp) {
|
|||
len += encodeUdfTeardownResponse(buf, &rsp->teardownRsp);
|
||||
break;
|
||||
default:
|
||||
//TODO: log error
|
||||
fnError("encode udf response, invalid udf response type %d", rsp->type);
|
||||
break;
|
||||
}
|
||||
return len;
|
||||
|
@ -676,7 +719,7 @@ void* decodeUdfResponse(const void* buf, SUdfResponse* rsp) {
|
|||
buf = decodeUdfTeardownResponse(buf, &rsp->teardownRsp);
|
||||
break;
|
||||
default:
|
||||
//TODO: log error
|
||||
fnError("decode udf response, invalid udf response type %d", rsp->type);
|
||||
break;
|
||||
}
|
||||
return (void*)buf;
|
||||
|
@ -817,6 +860,319 @@ int32_t convertDataBlockToScalarParm(SSDataBlock *input, SScalarParam *output) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//memory layout |---SUdfAggRes----|-----final result-----|---inter result----|
|
||||
typedef struct SUdfAggRes {
|
||||
int8_t finalResNum;
|
||||
int8_t interResNum;
|
||||
char* finalResBuf;
|
||||
char* interResBuf;
|
||||
} SUdfAggRes;
|
||||
void onUdfcPipeClose(uv_handle_t *handle);
|
||||
int32_t udfcGetUdfTaskResultFromUvTask(SClientUdfTask *task, SClientUvTaskNode *uvTask);
|
||||
void udfcAllocateBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf);
|
||||
bool isUdfcUvMsgComplete(SClientConnBuf *connBuf);
|
||||
void udfcUvHandleRsp(SClientUvConn *conn);
|
||||
void udfcUvHandleError(SClientUvConn *conn);
|
||||
void onUdfcPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf);
|
||||
void onUdfcPipetWrite(uv_write_t *write, int status);
|
||||
void onUdfcPipeConnect(uv_connect_t *connect, int status);
|
||||
int32_t udfcCreateUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvTaskNode **pUvTask);
|
||||
int32_t udfcQueueUvTask(SClientUvTaskNode *uvTask);
|
||||
int32_t udfcStartUvTask(SClientUvTaskNode *uvTask);
|
||||
void udfcAsyncTaskCb(uv_async_t *async);
|
||||
void cleanUpUvTasks(SUdfcProxy *udfc);
|
||||
void udfStopAsyncCb(uv_async_t *async);
|
||||
void constructUdfService(void *argsThread);
|
||||
int32_t udfcRunUdfUvTask(SClientUdfTask *task, int8_t uvTaskType);
|
||||
int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle);
|
||||
int compareUdfcFuncSub(const void* elem1, const void* elem2);
|
||||
int32_t doTeardownUdf(UdfcFuncHandle handle);
|
||||
|
||||
int32_t callUdf(UdfcFuncHandle handle, int8_t callType, SSDataBlock *input, SUdfInterBuf *state, SUdfInterBuf *state2,
|
||||
SSDataBlock* output, SUdfInterBuf *newState);
|
||||
int32_t doCallUdfAggInit(UdfcFuncHandle handle, SUdfInterBuf *interBuf);
|
||||
int32_t doCallUdfAggProcess(UdfcFuncHandle handle, SSDataBlock *block, SUdfInterBuf *state, SUdfInterBuf *newState);
|
||||
int32_t doCallUdfAggMerge(UdfcFuncHandle handle, SUdfInterBuf *interBuf1, SUdfInterBuf *interBuf2, SUdfInterBuf *resultBuf);
|
||||
int32_t doCallUdfAggFinalize(UdfcFuncHandle handle, SUdfInterBuf *interBuf, SUdfInterBuf *resultData);
|
||||
int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t numOfCols, SScalarParam* output);
|
||||
int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, SScalarParam *output);
|
||||
|
||||
int32_t udfcOpen();
|
||||
int32_t udfcClose();
|
||||
|
||||
int32_t acquireUdfFuncHandle(char* udfName, UdfcFuncHandle* pHandle);
|
||||
void releaseUdfFuncHandle(char* udfName);
|
||||
int32_t cleanUpUdfs();
|
||||
|
||||
bool udfAggGetEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo);
|
||||
int32_t udfAggProcess(struct SqlFunctionCtx *pCtx);
|
||||
int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock);
|
||||
|
||||
int compareUdfcFuncSub(const void* elem1, const void* elem2) {
|
||||
SUdfcFuncStub *stub1 = (SUdfcFuncStub *)elem1;
|
||||
SUdfcFuncStub *stub2 = (SUdfcFuncStub *)elem2;
|
||||
return strcmp(stub1->udfName, stub2->udfName);
|
||||
}
|
||||
|
||||
int32_t acquireUdfFuncHandle(char* udfName, UdfcFuncHandle* pHandle) {
|
||||
int32_t code = 0;
|
||||
uv_mutex_lock(&gUdfdProxy.udfStubsMutex);
|
||||
SUdfcFuncStub key = {0};
|
||||
strcpy(key.udfName, udfName);
|
||||
int32_t stubIndex = taosArraySearchIdx(gUdfdProxy.udfStubs, &key, compareUdfcFuncSub, TD_EQ);
|
||||
if (stubIndex != -1) {
|
||||
SUdfcFuncStub *foundStub = taosArrayGet(gUdfdProxy.udfStubs, stubIndex);
|
||||
UdfcFuncHandle handle = foundStub->handle;
|
||||
if (handle != NULL && ((SUdfcUvSession*)handle)->udfUvPipe != NULL) {
|
||||
*pHandle = foundStub->handle;
|
||||
++foundStub->refCount;
|
||||
foundStub->lastRefTime = taosGetTimestampUs();
|
||||
uv_mutex_unlock(&gUdfdProxy.udfStubsMutex);
|
||||
return 0;
|
||||
} else {
|
||||
fnInfo("invalid handle for %s, refCount: %d, last ref time: %"PRId64". remove it from cache",
|
||||
udfName, foundStub->refCount, foundStub->lastRefTime);
|
||||
taosArrayRemove(gUdfdProxy.udfStubs, stubIndex);
|
||||
}
|
||||
}
|
||||
*pHandle = NULL;
|
||||
code = doSetupUdf(udfName, pHandle);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
SUdfcFuncStub stub = {0};
|
||||
strcpy(stub.udfName, udfName);
|
||||
stub.handle = *pHandle;
|
||||
++stub.refCount;
|
||||
stub.lastRefTime = taosGetTimestampUs();
|
||||
taosArrayPush(gUdfdProxy.udfStubs, &stub);
|
||||
taosArraySort(gUdfdProxy.udfStubs, compareUdfcFuncSub);
|
||||
} else {
|
||||
*pHandle = NULL;
|
||||
}
|
||||
|
||||
uv_mutex_unlock(&gUdfdProxy.udfStubsMutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
void releaseUdfFuncHandle(char* udfName) {
|
||||
uv_mutex_lock(&gUdfdProxy.udfStubsMutex);
|
||||
SUdfcFuncStub key = {0};
|
||||
strcpy(key.udfName, udfName);
|
||||
SUdfcFuncStub *foundStub = taosArraySearch(gUdfdProxy.udfStubs, &key, compareUdfcFuncSub, TD_EQ);
|
||||
if (!foundStub) {
|
||||
return;
|
||||
}
|
||||
if (foundStub->refCount > 0) {
|
||||
--foundStub->refCount;
|
||||
}
|
||||
uv_mutex_unlock(&gUdfdProxy.udfStubsMutex);
|
||||
}
|
||||
|
||||
int32_t cleanUpUdfs() {
|
||||
uv_mutex_lock(&gUdfdProxy.udfStubsMutex);
|
||||
int32_t i = 0;
|
||||
SArray* udfStubs = taosArrayInit(16, sizeof(SUdfcFuncStub));
|
||||
while (i < taosArrayGetSize(gUdfdProxy.udfStubs)) {
|
||||
SUdfcFuncStub *stub = taosArrayGet(gUdfdProxy.udfStubs, i);
|
||||
if (stub->refCount == 0) {
|
||||
fnInfo("tear down udf. udf name: %s, handle: %p, ref count: %d", stub->udfName, stub->handle, stub->refCount);
|
||||
doTeardownUdf(stub->handle);
|
||||
} else {
|
||||
fnInfo("udf still in use. udf name: %s, ref count: %d, last ref time: %"PRId64", handle: %p",
|
||||
stub->udfName, stub->refCount, stub->lastRefTime, stub->handle);
|
||||
UdfcFuncHandle handle = stub->handle;
|
||||
if (handle != NULL && ((SUdfcUvSession*)handle)->udfUvPipe != NULL) {
|
||||
taosArrayPush(udfStubs, stub);
|
||||
} else {
|
||||
fnInfo("udf invalid handle for %s, refCount: %d, last ref time: %"PRId64". remove it from cache",
|
||||
stub->udfName, stub->refCount, stub->lastRefTime);
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
taosArrayDestroy(gUdfdProxy.udfStubs);
|
||||
gUdfdProxy.udfStubs = udfStubs;
|
||||
uv_mutex_unlock(&gUdfdProxy.udfStubsMutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, SScalarParam *output) {
|
||||
UdfcFuncHandle handle = NULL;
|
||||
int32_t code = acquireUdfFuncHandle(udfName, &handle);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
SUdfcUvSession *session = handle;
|
||||
code = doCallUdfScalarFunc(handle, input, numOfCols, output);
|
||||
if (output->columnData == NULL) {
|
||||
fnError("udfc scalar function calculate error. no column data");
|
||||
code = TSDB_CODE_UDF_INVALID_OUTPUT_TYPE;
|
||||
} else {
|
||||
if (session->outputType != output->columnData->info.type || session->outputLen != output->columnData->info.bytes) {
|
||||
fnError("udfc scalar function calculate error. type mismatch. session type: %d(%d), output type: %d(%d)", session->outputType,
|
||||
session->outputLen, output->columnData->info.type, output->columnData->info.bytes);
|
||||
code = TSDB_CODE_UDF_INVALID_OUTPUT_TYPE;
|
||||
}
|
||||
}
|
||||
releaseUdfFuncHandle(udfName);
|
||||
return code;
|
||||
}
|
||||
|
||||
bool udfAggGetEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
if (fmIsScalarFunc(pFunc->funcId)) {
|
||||
return false;
|
||||
}
|
||||
pEnv->calcMemSize = sizeof(SUdfAggRes) + pFunc->node.resType.bytes + pFunc->udfBufSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo) {
|
||||
if (functionSetup(pCtx, pResultCellInfo) != true) {
|
||||
return false;
|
||||
}
|
||||
UdfcFuncHandle handle;
|
||||
int32_t udfCode = 0;
|
||||
if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) {
|
||||
fnError("udfAggInit error. step doSetupUdf. udf code: %d", udfCode);
|
||||
return false;
|
||||
}
|
||||
SUdfcUvSession *session = (SUdfcUvSession *)handle;
|
||||
SUdfAggRes *udfRes = (SUdfAggRes*)GET_ROWCELL_INTERBUF(pResultCellInfo);
|
||||
int32_t envSize = sizeof(SUdfAggRes) + session->outputLen + session->bufSize;
|
||||
memset(udfRes, 0, envSize);
|
||||
|
||||
udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes);
|
||||
udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen;
|
||||
|
||||
SUdfInterBuf buf = {0};
|
||||
if ((udfCode = doCallUdfAggInit(handle, &buf)) != 0) {
|
||||
fnError("udfAggInit error. step doCallUdfAggInit. udf code: %d", udfCode);
|
||||
releaseUdfFuncHandle(pCtx->udfName);
|
||||
return false;
|
||||
}
|
||||
udfRes->interResNum = buf.numOfResult;
|
||||
if (buf.bufLen <= session->bufSize) {
|
||||
memcpy(udfRes->interResBuf, buf.buf, buf.bufLen);
|
||||
} else {
|
||||
fnError("udfc inter buf size %d is greater than function bufSize %d", buf.bufLen, session->bufSize);
|
||||
releaseUdfFuncHandle(pCtx->udfName);
|
||||
return false;
|
||||
}
|
||||
releaseUdfFuncHandle(pCtx->udfName);
|
||||
freeUdfInterBuf(&buf);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
|
||||
int32_t udfCode = 0;
|
||||
UdfcFuncHandle handle = 0;
|
||||
if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) {
|
||||
fnError("udfAggProcess error. step acquireUdfFuncHandle. udf code: %d", udfCode);
|
||||
return udfCode;
|
||||
}
|
||||
|
||||
SUdfcUvSession *session = handle;
|
||||
SUdfAggRes* udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes);
|
||||
udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen;
|
||||
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
int32_t numOfCols = pInput->numOfInputCols;
|
||||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
|
||||
SSDataBlock tempBlock = {0};
|
||||
tempBlock.info.numOfCols = numOfCols;
|
||||
tempBlock.info.rows = pInput->totalRows;
|
||||
tempBlock.info.uid = pInput->uid;
|
||||
bool hasVarCol = false;
|
||||
tempBlock.pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData));
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData *col = pInput->pData[i];
|
||||
if (IS_VAR_DATA_TYPE(col->info.type)) {
|
||||
hasVarCol = true;
|
||||
}
|
||||
taosArrayPush(tempBlock.pDataBlock, col);
|
||||
}
|
||||
tempBlock.info.hasVarCol = hasVarCol;
|
||||
|
||||
SSDataBlock *inputBlock = blockDataExtractBlock(&tempBlock, start, numOfRows);
|
||||
|
||||
SUdfInterBuf state = {.buf = udfRes->interResBuf,
|
||||
.bufLen = session->bufSize,
|
||||
.numOfResult = udfRes->interResNum};
|
||||
SUdfInterBuf newState = {0};
|
||||
|
||||
udfCode = doCallUdfAggProcess(session, inputBlock, &state, &newState);
|
||||
if (udfCode != 0) {
|
||||
fnError("udfAggProcess error. code: %d", udfCode);
|
||||
newState.numOfResult = 0;
|
||||
} else {
|
||||
udfRes->interResNum = newState.numOfResult;
|
||||
if (newState.bufLen <= session->bufSize) {
|
||||
memcpy(udfRes->interResBuf, newState.buf, newState.bufLen);
|
||||
} else {
|
||||
fnError("udfc inter buf size %d is greater than function bufSize %d", newState.bufLen, session->bufSize);
|
||||
udfCode = TSDB_CODE_UDF_INVALID_BUFSIZE;
|
||||
}
|
||||
}
|
||||
if (newState.numOfResult == 1 || state.numOfResult == 1) {
|
||||
GET_RES_INFO(pCtx)->numOfRes = 1;
|
||||
}
|
||||
|
||||
blockDataDestroy(inputBlock);
|
||||
taosArrayDestroy(tempBlock.pDataBlock);
|
||||
|
||||
releaseUdfFuncHandle(pCtx->udfName);
|
||||
freeUdfInterBuf(&newState);
|
||||
return udfCode;
|
||||
}
|
||||
|
||||
int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) {
|
||||
int32_t udfCode = 0;
|
||||
UdfcFuncHandle handle = 0;
|
||||
if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) {
|
||||
fnError("udfAggProcess error. step acquireUdfFuncHandle. udf code: %d", udfCode);
|
||||
return udfCode;
|
||||
}
|
||||
|
||||
SUdfcUvSession *session = handle;
|
||||
SUdfAggRes* udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes);
|
||||
udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen;
|
||||
|
||||
|
||||
SUdfInterBuf resultBuf = {0};
|
||||
SUdfInterBuf state = {.buf = udfRes->interResBuf,
|
||||
.bufLen = session->bufSize,
|
||||
.numOfResult = udfRes->interResNum};
|
||||
int32_t udfCallCode= 0;
|
||||
udfCallCode= doCallUdfAggFinalize(session, &state, &resultBuf);
|
||||
if (udfCallCode != 0) {
|
||||
fnError("udfAggFinalize error. doCallUdfAggFinalize step. udf code:%d", udfCallCode);
|
||||
GET_RES_INFO(pCtx)->numOfRes = 0;
|
||||
} else {
|
||||
if (resultBuf.bufLen <= session->outputLen) {
|
||||
memcpy(udfRes->finalResBuf, resultBuf.buf, session->outputLen);
|
||||
udfRes->finalResNum = resultBuf.numOfResult;
|
||||
GET_RES_INFO(pCtx)->numOfRes = udfRes->finalResNum;
|
||||
} else {
|
||||
fnError("udfc inter buf size %d is greater than function output size %d", resultBuf.bufLen, session->outputLen);
|
||||
GET_RES_INFO(pCtx)->numOfRes = 0;
|
||||
udfCallCode = TSDB_CODE_UDF_INVALID_OUTPUT_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
freeUdfInterBuf(&resultBuf);
|
||||
|
||||
int32_t numOfResults = functionFinalizeWithResultBuf(pCtx, pBlock, udfRes->finalResBuf);
|
||||
releaseUdfFuncHandle(pCtx->udfName);
|
||||
return udfCallCode == 0 ? numOfResults : udfCallCode;
|
||||
}
|
||||
|
||||
void onUdfcPipeClose(uv_handle_t *handle) {
|
||||
SClientUvConn *conn = handle->data;
|
||||
if (!QUEUE_EMPTY(&conn->taskQueue)) {
|
||||
|
@ -843,18 +1199,15 @@ int32_t udfcGetUdfTaskResultFromUvTask(SClientUdfTask *task, SClientUvTaskNode *
|
|||
|
||||
switch (task->type) {
|
||||
case UDF_TASK_SETUP: {
|
||||
//TODO: copy or not
|
||||
task->_setup.rsp = rsp.setupRsp;
|
||||
break;
|
||||
}
|
||||
case UDF_TASK_CALL: {
|
||||
task->_call.rsp = rsp.callRsp;
|
||||
//TODO: copy or not
|
||||
break;
|
||||
}
|
||||
case UDF_TASK_TEARDOWN: {
|
||||
task->_teardown.rsp = rsp.teardownRsp;
|
||||
//TODO: copy or not?
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -1050,7 +1403,7 @@ int32_t udfcCreateUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvTaskN
|
|||
request.teardown = task->_teardown.req;
|
||||
request.type = UDF_TASK_TEARDOWN;
|
||||
} else {
|
||||
//TODO log and return error
|
||||
fnError("udfc create uv task, invalid task type : %d", task->type);
|
||||
}
|
||||
int32_t bufLen = encodeUdfRequest(NULL, &request);
|
||||
request.msgLen = bufLen;
|
||||
|
@ -1314,93 +1667,6 @@ int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle) {
|
|||
return err;
|
||||
}
|
||||
|
||||
int compareUdfcFuncSub(const void* elem1, const void* elem2) {
|
||||
SUdfcFuncStub *stub1 = (SUdfcFuncStub *)elem1;
|
||||
SUdfcFuncStub *stub2 = (SUdfcFuncStub *)elem2;
|
||||
return strcmp(stub1->udfName, stub2->udfName);
|
||||
}
|
||||
|
||||
int32_t acquireUdfFuncHandle(char* udfName, UdfcFuncHandle* pHandle) {
|
||||
int32_t code = 0;
|
||||
uv_mutex_lock(&gUdfdProxy.udfStubsMutex);
|
||||
SUdfcFuncStub key = {0};
|
||||
strcpy(key.udfName, udfName);
|
||||
int32_t stubIndex = taosArraySearchIdx(gUdfdProxy.udfStubs, &key, compareUdfcFuncSub, TD_EQ);
|
||||
if (stubIndex != -1) {
|
||||
SUdfcFuncStub *foundStub = taosArrayGet(gUdfdProxy.udfStubs, stubIndex);
|
||||
UdfcFuncHandle handle = foundStub->handle;
|
||||
if (handle != NULL && ((SUdfcUvSession*)handle)->udfUvPipe != NULL) {
|
||||
*pHandle = foundStub->handle;
|
||||
++foundStub->refCount;
|
||||
foundStub->lastRefTime = taosGetTimestampUs();
|
||||
uv_mutex_unlock(&gUdfdProxy.udfStubsMutex);
|
||||
return 0;
|
||||
} else {
|
||||
fnInfo("invalid handle for %s, refCount: %d, last ref time: %"PRId64". remove it from cache",
|
||||
udfName, foundStub->refCount, foundStub->lastRefTime);
|
||||
taosArrayRemove(gUdfdProxy.udfStubs, stubIndex);
|
||||
}
|
||||
}
|
||||
*pHandle = NULL;
|
||||
code = doSetupUdf(udfName, pHandle);
|
||||
if (code == TSDB_CODE_SUCCESS) {
|
||||
SUdfcFuncStub stub = {0};
|
||||
strcpy(stub.udfName, udfName);
|
||||
stub.handle = *pHandle;
|
||||
++stub.refCount;
|
||||
stub.lastRefTime = taosGetTimestampUs();
|
||||
taosArrayPush(gUdfdProxy.udfStubs, &stub);
|
||||
taosArraySort(gUdfdProxy.udfStubs, compareUdfcFuncSub);
|
||||
} else {
|
||||
*pHandle = NULL;
|
||||
}
|
||||
|
||||
uv_mutex_unlock(&gUdfdProxy.udfStubsMutex);
|
||||
return code;
|
||||
}
|
||||
|
||||
void releaseUdfFuncHandle(char* udfName) {
|
||||
uv_mutex_lock(&gUdfdProxy.udfStubsMutex);
|
||||
SUdfcFuncStub key = {0};
|
||||
strcpy(key.udfName, udfName);
|
||||
SUdfcFuncStub *foundStub = taosArraySearch(gUdfdProxy.udfStubs, &key, compareUdfcFuncSub, TD_EQ);
|
||||
if (!foundStub) {
|
||||
return;
|
||||
}
|
||||
if (foundStub->refCount > 0) {
|
||||
--foundStub->refCount;
|
||||
}
|
||||
uv_mutex_unlock(&gUdfdProxy.udfStubsMutex);
|
||||
}
|
||||
|
||||
int32_t cleanUpUdfs() {
|
||||
uv_mutex_lock(&gUdfdProxy.udfStubsMutex);
|
||||
int32_t i = 0;
|
||||
SArray* udfStubs = taosArrayInit(16, sizeof(SUdfcFuncStub));
|
||||
while (i < taosArrayGetSize(gUdfdProxy.udfStubs)) {
|
||||
SUdfcFuncStub *stub = taosArrayGet(gUdfdProxy.udfStubs, i);
|
||||
if (stub->refCount == 0) {
|
||||
fnInfo("tear down udf. udf name: %s, handle: %p, ref count: %d", stub->udfName, stub->handle, stub->refCount);
|
||||
doTeardownUdf(stub->handle);
|
||||
} else {
|
||||
fnInfo("udf still in use. udf name: %s, ref count: %d, last ref time: %"PRId64", handle: %p",
|
||||
stub->udfName, stub->refCount, stub->lastRefTime, stub->handle);
|
||||
UdfcFuncHandle handle = stub->handle;
|
||||
if (handle != NULL && ((SUdfcUvSession*)handle)->udfUvPipe != NULL) {
|
||||
taosArrayPush(udfStubs, stub);
|
||||
} else {
|
||||
fnInfo("udf invalid handle for %s, refCount: %d, last ref time: %"PRId64". remove it from cache",
|
||||
stub->udfName, stub->refCount, stub->lastRefTime);
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
taosArrayDestroy(gUdfdProxy.udfStubs);
|
||||
gUdfdProxy.udfStubs = udfStubs;
|
||||
uv_mutex_unlock(&gUdfdProxy.udfStubsMutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t callUdf(UdfcFuncHandle handle, int8_t callType, SSDataBlock *input, SUdfInterBuf *state, SUdfInterBuf *state2,
|
||||
SSDataBlock* output, SUdfInterBuf *newState) {
|
||||
fnTrace("udfc call udf. callType: %d, funcHandle: %p", callType, handle);
|
||||
|
@ -1524,29 +1790,6 @@ int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t
|
|||
return err;
|
||||
}
|
||||
|
||||
|
||||
int32_t callUdfScalarFunc(char *udfName, SScalarParam *input, int32_t numOfCols, SScalarParam *output) {
|
||||
UdfcFuncHandle handle = NULL;
|
||||
int32_t code = acquireUdfFuncHandle(udfName, &handle);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
}
|
||||
SUdfcUvSession *session = handle;
|
||||
code = doCallUdfScalarFunc(handle, input, numOfCols, output);
|
||||
if (output->columnData == NULL) {
|
||||
fnError("udfc scalar function calculate error. no column data");
|
||||
code = TSDB_CODE_UDF_INVALID_OUTPUT_TYPE;
|
||||
} else {
|
||||
if (session->outputType != output->columnData->info.type || session->outputLen != output->columnData->info.bytes) {
|
||||
fnError("udfc scalar function calculate error. type mismatch. session type: %d(%d), output type: %d(%d)", session->outputType,
|
||||
session->outputLen, output->columnData->info.type, output->columnData->info.bytes);
|
||||
code = TSDB_CODE_UDF_INVALID_OUTPUT_TYPE;
|
||||
}
|
||||
}
|
||||
releaseUdfFuncHandle(udfName);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t doTeardownUdf(UdfcFuncHandle handle) {
|
||||
SUdfcUvSession *session = (SUdfcUvSession *) handle;
|
||||
|
||||
|
@ -1576,165 +1819,3 @@ int32_t doTeardownUdf(UdfcFuncHandle handle) {
|
|||
|
||||
return err;
|
||||
}
|
||||
|
||||
//memory layout |---SUdfAggRes----|-----final result-----|---inter result----|
|
||||
typedef struct SUdfAggRes {
|
||||
int8_t finalResNum;
|
||||
int8_t interResNum;
|
||||
char* finalResBuf;
|
||||
char* interResBuf;
|
||||
} SUdfAggRes;
|
||||
|
||||
bool udfAggGetEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
if (fmIsScalarFunc(pFunc->funcId)) {
|
||||
return false;
|
||||
}
|
||||
pEnv->calcMemSize = sizeof(SUdfAggRes) + pFunc->node.resType.bytes + pFunc->udfBufSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResultCellInfo) {
|
||||
if (functionSetup(pCtx, pResultCellInfo) != true) {
|
||||
return false;
|
||||
}
|
||||
UdfcFuncHandle handle;
|
||||
int32_t udfCode = 0;
|
||||
if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) {
|
||||
fnError("udfAggInit error. step doSetupUdf. udf code: %d", udfCode);
|
||||
return false;
|
||||
}
|
||||
SUdfcUvSession *session = (SUdfcUvSession *)handle;
|
||||
SUdfAggRes *udfRes = (SUdfAggRes*)GET_ROWCELL_INTERBUF(pResultCellInfo);
|
||||
int32_t envSize = sizeof(SUdfAggRes) + session->outputLen + session->bufSize;
|
||||
memset(udfRes, 0, envSize);
|
||||
|
||||
udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes);
|
||||
udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen;
|
||||
|
||||
SUdfInterBuf buf = {0};
|
||||
if ((udfCode = doCallUdfAggInit(handle, &buf)) != 0) {
|
||||
fnError("udfAggInit error. step doCallUdfAggInit. udf code: %d", udfCode);
|
||||
releaseUdfFuncHandle(pCtx->udfName);
|
||||
return false;
|
||||
}
|
||||
udfRes->interResNum = buf.numOfResult;
|
||||
if (buf.bufLen <= session->bufSize) {
|
||||
memcpy(udfRes->interResBuf, buf.buf, buf.bufLen);
|
||||
} else {
|
||||
fnError("udfc inter buf size %d is greater than function bufSize %d", buf.bufLen, session->bufSize);
|
||||
releaseUdfFuncHandle(pCtx->udfName);
|
||||
return false;
|
||||
}
|
||||
releaseUdfFuncHandle(pCtx->udfName);
|
||||
freeUdfInterBuf(&buf);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
|
||||
int32_t udfCode = 0;
|
||||
UdfcFuncHandle handle = 0;
|
||||
if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) {
|
||||
fnError("udfAggProcess error. step acquireUdfFuncHandle. udf code: %d", udfCode);
|
||||
return udfCode;
|
||||
}
|
||||
|
||||
SUdfcUvSession *session = handle;
|
||||
SUdfAggRes* udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes);
|
||||
udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen;
|
||||
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
int32_t numOfCols = pInput->numOfInputCols;
|
||||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
|
||||
SSDataBlock tempBlock = {0};
|
||||
tempBlock.info.numOfCols = numOfCols;
|
||||
tempBlock.info.rows = pInput->totalRows;
|
||||
tempBlock.info.uid = pInput->uid;
|
||||
bool hasVarCol = false;
|
||||
tempBlock.pDataBlock = taosArrayInit(numOfCols, sizeof(SColumnInfoData));
|
||||
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData *col = pInput->pData[i];
|
||||
if (IS_VAR_DATA_TYPE(col->info.type)) {
|
||||
hasVarCol = true;
|
||||
}
|
||||
taosArrayPush(tempBlock.pDataBlock, col);
|
||||
}
|
||||
tempBlock.info.hasVarCol = hasVarCol;
|
||||
|
||||
SSDataBlock *inputBlock = blockDataExtractBlock(&tempBlock, start, numOfRows);
|
||||
|
||||
SUdfInterBuf state = {.buf = udfRes->interResBuf,
|
||||
.bufLen = session->bufSize,
|
||||
.numOfResult = udfRes->interResNum};
|
||||
SUdfInterBuf newState = {0};
|
||||
|
||||
udfCode = doCallUdfAggProcess(session, inputBlock, &state, &newState);
|
||||
if (udfCode != 0) {
|
||||
fnError("udfAggProcess error. code: %d", udfCode);
|
||||
newState.numOfResult = 0;
|
||||
} else {
|
||||
udfRes->interResNum = newState.numOfResult;
|
||||
if (newState.bufLen <= session->bufSize) {
|
||||
memcpy(udfRes->interResBuf, newState.buf, newState.bufLen);
|
||||
} else {
|
||||
fnError("udfc inter buf size %d is greater than function bufSize %d", newState.bufLen, session->bufSize);
|
||||
udfCode = TSDB_CODE_UDF_INVALID_BUFSIZE;
|
||||
}
|
||||
}
|
||||
if (newState.numOfResult == 1 || state.numOfResult == 1) {
|
||||
GET_RES_INFO(pCtx)->numOfRes = 1;
|
||||
}
|
||||
|
||||
blockDataDestroy(inputBlock);
|
||||
taosArrayDestroy(tempBlock.pDataBlock);
|
||||
|
||||
releaseUdfFuncHandle(pCtx->udfName);
|
||||
freeUdfInterBuf(&newState);
|
||||
return udfCode;
|
||||
}
|
||||
|
||||
int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) {
|
||||
int32_t udfCode = 0;
|
||||
UdfcFuncHandle handle = 0;
|
||||
if ((udfCode = acquireUdfFuncHandle((char *)pCtx->udfName, &handle)) != 0) {
|
||||
fnError("udfAggProcess error. step acquireUdfFuncHandle. udf code: %d", udfCode);
|
||||
return udfCode;
|
||||
}
|
||||
|
||||
SUdfcUvSession *session = handle;
|
||||
SUdfAggRes* udfRes = (SUdfAggRes *)GET_ROWCELL_INTERBUF(GET_RES_INFO(pCtx));
|
||||
udfRes->finalResBuf = (char*)udfRes + sizeof(SUdfAggRes);
|
||||
udfRes->interResBuf = (char*)udfRes + sizeof(SUdfAggRes) + session->outputLen;
|
||||
|
||||
|
||||
SUdfInterBuf resultBuf = {0};
|
||||
SUdfInterBuf state = {.buf = udfRes->interResBuf,
|
||||
.bufLen = session->bufSize,
|
||||
.numOfResult = udfRes->interResNum};
|
||||
int32_t udfCallCode= 0;
|
||||
udfCallCode= doCallUdfAggFinalize(session, &state, &resultBuf);
|
||||
if (udfCallCode != 0) {
|
||||
fnError("udfAggFinalize error. doCallUdfAggFinalize step. udf code:%d", udfCallCode);
|
||||
GET_RES_INFO(pCtx)->numOfRes = 0;
|
||||
} else {
|
||||
if (resultBuf.bufLen <= session->outputLen) {
|
||||
memcpy(udfRes->finalResBuf, resultBuf.buf, session->outputLen);
|
||||
udfRes->finalResNum = resultBuf.numOfResult;
|
||||
GET_RES_INFO(pCtx)->numOfRes = udfRes->finalResNum;
|
||||
} else {
|
||||
fnError("udfc inter buf size %d is greater than function output size %d", resultBuf.bufLen, session->outputLen);
|
||||
GET_RES_INFO(pCtx)->numOfRes = 0;
|
||||
udfCallCode = TSDB_CODE_UDF_INVALID_OUTPUT_TYPE;
|
||||
}
|
||||
}
|
||||
|
||||
freeUdfInterBuf(&resultBuf);
|
||||
|
||||
int32_t numOfResults = functionFinalizeWithResultBuf(pCtx, pBlock, udfRes->finalResBuf);
|
||||
releaseUdfFuncHandle(pCtx->udfName);
|
||||
return udfCallCode == 0 ? numOfResults : udfCallCode;
|
||||
}
|
||||
|
|
|
@ -103,177 +103,65 @@ typedef struct SUdfdRpcSendRecvInfo {
|
|||
uv_sem_t resultSem;
|
||||
} SUdfdRpcSendRecvInfo;
|
||||
|
||||
void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SUdfdRpcSendRecvInfo *msgInfo = (SUdfdRpcSendRecvInfo *)pMsg->info.ahandle;
|
||||
ASSERT(pMsg->info.ahandle != NULL);
|
||||
static void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||
static int32_t udfdFillUdfInfoFromMNode(void *clientRpc, char *udfName, SUdf *udf);
|
||||
static int32_t udfdConnectToMnode();
|
||||
static int32_t udfdLoadUdf(char *udfName, SUdf *udf);
|
||||
static bool udfdRpcRfp(int32_t code);
|
||||
static int initEpSetFromCfg(const char *firstEp, const char *secondEp, SCorEpSet *pEpSet);
|
||||
static int32_t udfdOpenClientRpc();
|
||||
static int32_t udfdCloseClientRpc();
|
||||
|
||||
if (pEpSet) {
|
||||
if (!isEpsetEqual(&global.mgmtEp.epSet, pEpSet)) {
|
||||
updateEpSet_s(&global.mgmtEp, pEpSet);
|
||||
}
|
||||
static void udfdProcessSetupRequest(SUvUdfWork *uvUdf, SUdfRequest *request);
|
||||
static void udfdProcessCallRequest(SUvUdfWork *uvUdf, SUdfRequest *request);
|
||||
static void udfdProcessTeardownRequest(SUvUdfWork *uvUdf, SUdfRequest *request);
|
||||
static void udfdProcessRequest(uv_work_t *req);
|
||||
static void udfdOnWrite(uv_write_t *req, int status);
|
||||
static void udfdSendResponse(uv_work_t *work, int status);
|
||||
static void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf);
|
||||
static bool isUdfdUvMsgComplete(SUdfdUvConn *pipe);
|
||||
static void udfdHandleRequest(SUdfdUvConn *conn);
|
||||
static void udfdPipeCloseCb(uv_handle_t *pipe);
|
||||
static void udfdUvHandleError(SUdfdUvConn *conn) { uv_close((uv_handle_t *)conn->client, udfdPipeCloseCb); }
|
||||
static void udfdPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf);
|
||||
static void udfdOnNewConnection(uv_stream_t *server, int status);
|
||||
|
||||
static void udfdIntrSignalHandler(uv_signal_t *handle, int signum);
|
||||
static int32_t removeListeningPipe();
|
||||
|
||||
static void udfdPrintVersion();
|
||||
static int32_t udfdParseArgs(int32_t argc, char *argv[]);
|
||||
static int32_t udfdInitLog();
|
||||
|
||||
static void udfdCtrlAllocBufCb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
||||
static void udfdCtrlReadCb(uv_stream_t *q, ssize_t nread, const uv_buf_t *buf);
|
||||
static int32_t udfdUvInit();
|
||||
static void udfdCloseWalkCb(uv_handle_t *handle, void *arg);
|
||||
static int32_t udfdRun();
|
||||
|
||||
void udfdProcessRequest(uv_work_t *req) {
|
||||
SUvUdfWork *uvUdf = (SUvUdfWork *)(req->data);
|
||||
SUdfRequest request = {0};
|
||||
decodeUdfRequest(uvUdf->input.base, &request);
|
||||
|
||||
switch (request.type) {
|
||||
case UDF_TASK_SETUP: {
|
||||
udfdProcessSetupRequest(uvUdf, &request);
|
||||
break;
|
||||
}
|
||||
|
||||
if (pMsg->code != TSDB_CODE_SUCCESS) {
|
||||
fnError("udfd rpc error. code: %s", tstrerror(pMsg->code));
|
||||
msgInfo->code = pMsg->code;
|
||||
goto _return;
|
||||
case UDF_TASK_CALL: {
|
||||
udfdProcessCallRequest(uvUdf, &request);
|
||||
break;
|
||||
}
|
||||
|
||||
if (msgInfo->rpcType == UDFD_RPC_MNODE_CONNECT) {
|
||||
SConnectRsp connectRsp = {0};
|
||||
tDeserializeSConnectRsp(pMsg->pCont, pMsg->contLen, &connectRsp);
|
||||
if (connectRsp.epSet.numOfEps == 0) {
|
||||
msgInfo->code = TSDB_CODE_MND_APP_ERROR;
|
||||
goto _return;
|
||||
case UDF_TASK_TEARDOWN: {
|
||||
udfdProcessTeardownRequest(uvUdf, &request);
|
||||
break;
|
||||
}
|
||||
|
||||
if (connectRsp.dnodeNum > 1 && !isEpsetEqual(&global.mgmtEp.epSet, &connectRsp.epSet)) {
|
||||
updateEpSet_s(&global.mgmtEp, &connectRsp.epSet);
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
msgInfo->code = 0;
|
||||
} else if (msgInfo->rpcType == UDFD_RPC_RETRIVE_FUNC) {
|
||||
SRetrieveFuncRsp retrieveRsp = {0};
|
||||
tDeserializeSRetrieveFuncRsp(pMsg->pCont, pMsg->contLen, &retrieveRsp);
|
||||
|
||||
SFuncInfo *pFuncInfo = (SFuncInfo *)taosArrayGet(retrieveRsp.pFuncInfos, 0);
|
||||
SUdf * udf = msgInfo->param;
|
||||
udf->funcType = pFuncInfo->funcType;
|
||||
udf->scriptType = pFuncInfo->scriptType;
|
||||
udf->outputType = pFuncInfo->outputType;
|
||||
udf->outputLen = pFuncInfo->outputLen;
|
||||
udf->bufSize = pFuncInfo->bufSize;
|
||||
|
||||
char path[PATH_MAX] = {0};
|
||||
snprintf(path, sizeof(path), "%s/lib%s.so", "/tmp", pFuncInfo->name);
|
||||
TdFilePtr file =
|
||||
taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL);
|
||||
// TODO check for failure of flush to disk
|
||||
taosWriteFile(file, pFuncInfo->pCode, pFuncInfo->codeSize);
|
||||
taosCloseFile(&file);
|
||||
strncpy(udf->path, path, strlen(path));
|
||||
tFreeSFuncInfo(pFuncInfo);
|
||||
taosArrayDestroy(retrieveRsp.pFuncInfos);
|
||||
msgInfo->code = 0;
|
||||
}
|
||||
|
||||
_return:
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
uv_sem_post(&msgInfo->resultSem);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t udfdFillUdfInfoFromMNode(void *clientRpc, char *udfName, SUdf *udf) {
|
||||
SRetrieveFuncReq retrieveReq = {0};
|
||||
retrieveReq.numOfFuncs = 1;
|
||||
retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN);
|
||||
taosArrayPush(retrieveReq.pFuncNames, udfName);
|
||||
|
||||
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
|
||||
void * pReq = rpcMallocCont(contLen);
|
||||
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
|
||||
taosArrayDestroy(retrieveReq.pFuncNames);
|
||||
|
||||
SUdfdRpcSendRecvInfo *msgInfo = taosMemoryCalloc(1, sizeof(SUdfdRpcSendRecvInfo));
|
||||
msgInfo->rpcType = UDFD_RPC_RETRIVE_FUNC;
|
||||
msgInfo->param = udf;
|
||||
uv_sem_init(&msgInfo->resultSem, 0);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = contLen;
|
||||
rpcMsg.msgType = TDMT_MND_RETRIEVE_FUNC;
|
||||
rpcMsg.info.ahandle = msgInfo;
|
||||
rpcSendRequest(clientRpc, &global.mgmtEp.epSet, &rpcMsg, NULL);
|
||||
|
||||
uv_sem_wait(&msgInfo->resultSem);
|
||||
uv_sem_destroy(&msgInfo->resultSem);
|
||||
int32_t code = msgInfo->code;
|
||||
taosMemoryFree(msgInfo);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t udfdConnectToMnode() {
|
||||
SConnectReq connReq = {0};
|
||||
connReq.connType = CONN_TYPE__UDFD;
|
||||
tstrncpy(connReq.app, "udfd", sizeof(connReq.app));
|
||||
tstrncpy(connReq.user, TSDB_DEFAULT_USER, sizeof(connReq.user));
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)(TSDB_DEFAULT_PASS), strlen(TSDB_DEFAULT_PASS), pass);
|
||||
tstrncpy(connReq.passwd, pass, sizeof(connReq.passwd));
|
||||
connReq.pid = htonl(taosGetPId());
|
||||
connReq.startTime = htobe64(taosGetTimestampMs());
|
||||
|
||||
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connReq);
|
||||
void * pReq = rpcMallocCont(contLen);
|
||||
tSerializeSConnectReq(pReq, contLen, &connReq);
|
||||
|
||||
SUdfdRpcSendRecvInfo *msgInfo = taosMemoryCalloc(1, sizeof(SUdfdRpcSendRecvInfo));
|
||||
msgInfo->rpcType = UDFD_RPC_MNODE_CONNECT;
|
||||
uv_sem_init(&msgInfo->resultSem, 0);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.msgType = TDMT_MND_CONNECT;
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = contLen;
|
||||
rpcMsg.info.ahandle = msgInfo;
|
||||
rpcSendRequest(global.clientRpc, &global.mgmtEp.epSet, &rpcMsg, NULL);
|
||||
|
||||
uv_sem_wait(&msgInfo->resultSem);
|
||||
int32_t code = msgInfo->code;
|
||||
uv_sem_destroy(&msgInfo->resultSem);
|
||||
taosMemoryFree(msgInfo);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
|
||||
strcpy(udf->name, udfName);
|
||||
int32_t err = 0;
|
||||
|
||||
err = udfdFillUdfInfoFromMNode(global.clientRpc, udf->name, udf);
|
||||
if (err != 0) {
|
||||
fnError("can not retrieve udf from mnode. udf name %s", udfName);
|
||||
return TSDB_CODE_UDF_LOAD_UDF_FAILURE;
|
||||
}
|
||||
|
||||
err = uv_dlopen(udf->path, &udf->lib);
|
||||
if (err != 0) {
|
||||
fnError("can not load library %s. error: %s", udf->path, uv_strerror(err));
|
||||
return TSDB_CODE_UDF_LOAD_UDF_FAILURE;
|
||||
}
|
||||
|
||||
char initFuncName[TSDB_FUNC_NAME_LEN + 5] = {0};
|
||||
char *initSuffix = "_init";
|
||||
strcpy(initFuncName, udfName);
|
||||
strncat(initFuncName, initSuffix, strlen(initSuffix));
|
||||
uv_dlsym(&udf->lib, initFuncName, (void **)(&udf->initFunc));
|
||||
|
||||
char destroyFuncName[TSDB_FUNC_NAME_LEN + 5] = {0};
|
||||
char *destroySuffix = "_destroy";
|
||||
strcpy(destroyFuncName, udfName);
|
||||
strncat(destroyFuncName, destroySuffix, strlen(destroySuffix));
|
||||
uv_dlsym(&udf->lib, destroyFuncName, (void **)(&udf->destroyFunc));
|
||||
|
||||
if (udf->funcType == TSDB_FUNC_TYPE_SCALAR) {
|
||||
char processFuncName[TSDB_FUNC_NAME_LEN] = {0};
|
||||
strcpy(processFuncName, udfName);
|
||||
uv_dlsym(&udf->lib, processFuncName, (void **)(&udf->scalarProcFunc));
|
||||
} else if (udf->funcType == TSDB_FUNC_TYPE_AGGREGATE) {
|
||||
char processFuncName[TSDB_FUNC_NAME_LEN] = {0};
|
||||
strcpy(processFuncName, udfName);
|
||||
uv_dlsym(&udf->lib, processFuncName, (void **)(&udf->aggProcFunc));
|
||||
char startFuncName[TSDB_FUNC_NAME_LEN + 6] = {0};
|
||||
char *startSuffix = "_start";
|
||||
strncpy(startFuncName, processFuncName, strlen(processFuncName));
|
||||
strncat(startFuncName, startSuffix, strlen(startSuffix));
|
||||
uv_dlsym(&udf->lib, startFuncName, (void **)(&udf->aggStartFunc));
|
||||
char finishFuncName[TSDB_FUNC_NAME_LEN + 7] = {0};
|
||||
char *finishSuffix = "_finish";
|
||||
strncpy(finishFuncName, processFuncName, strlen(processFuncName));
|
||||
strncat(finishFuncName, finishSuffix, strlen(finishSuffix));
|
||||
uv_dlsym(&udf->lib, finishFuncName, (void **)(&udf->aggFinishFunc));
|
||||
// TODO: merge
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void udfdProcessSetupRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
|
||||
|
@ -471,173 +359,181 @@ void udfdProcessTeardownRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
|
|||
return;
|
||||
}
|
||||
|
||||
void udfdProcessRequest(uv_work_t *req) {
|
||||
SUvUdfWork *uvUdf = (SUvUdfWork *)(req->data);
|
||||
SUdfRequest request = {0};
|
||||
decodeUdfRequest(uvUdf->input.base, &request);
|
||||
void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SUdfdRpcSendRecvInfo *msgInfo = (SUdfdRpcSendRecvInfo *)pMsg->info.ahandle;
|
||||
ASSERT(pMsg->info.ahandle != NULL);
|
||||
|
||||
switch (request.type) {
|
||||
case UDF_TASK_SETUP: {
|
||||
udfdProcessSetupRequest(uvUdf, &request);
|
||||
break;
|
||||
}
|
||||
|
||||
case UDF_TASK_CALL: {
|
||||
udfdProcessCallRequest(uvUdf, &request);
|
||||
break;
|
||||
}
|
||||
case UDF_TASK_TEARDOWN: {
|
||||
udfdProcessTeardownRequest(uvUdf, &request);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
if (pEpSet) {
|
||||
if (!isEpsetEqual(&global.mgmtEp.epSet, pEpSet)) {
|
||||
updateEpSet_s(&global.mgmtEp, pEpSet);
|
||||
}
|
||||
}
|
||||
|
||||
void udfdOnWrite(uv_write_t *req, int status) {
|
||||
SUvUdfWork *work = (SUvUdfWork *)req->data;
|
||||
if (status < 0) {
|
||||
fnError("udfd send response error, length: %zu code: %s", work->output.len, uv_err_name(status));
|
||||
}
|
||||
taosMemoryFree(work->output.base);
|
||||
taosMemoryFree(work);
|
||||
taosMemoryFree(req);
|
||||
if (pMsg->code != TSDB_CODE_SUCCESS) {
|
||||
fnError("udfd rpc error. code: %s", tstrerror(pMsg->code));
|
||||
msgInfo->code = pMsg->code;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
void udfdSendResponse(uv_work_t *work, int status) {
|
||||
SUvUdfWork *udfWork = (SUvUdfWork *)(work->data);
|
||||
|
||||
uv_write_t *write_req = taosMemoryMalloc(sizeof(uv_write_t));
|
||||
write_req->data = udfWork;
|
||||
uv_write(write_req, udfWork->client, &udfWork->output, 1, udfdOnWrite);
|
||||
|
||||
taosMemoryFree(work);
|
||||
if (msgInfo->rpcType == UDFD_RPC_MNODE_CONNECT) {
|
||||
SConnectRsp connectRsp = {0};
|
||||
tDeserializeSConnectRsp(pMsg->pCont, pMsg->contLen, &connectRsp);
|
||||
if (connectRsp.epSet.numOfEps == 0) {
|
||||
msgInfo->code = TSDB_CODE_MND_APP_ERROR;
|
||||
goto _return;
|
||||
}
|
||||
|
||||
void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf) {
|
||||
SUdfdUvConn *ctx = handle->data;
|
||||
int32_t msgHeadSize = sizeof(int32_t) + sizeof(int64_t);
|
||||
if (ctx->inputCap == 0) {
|
||||
ctx->inputBuf = taosMemoryMalloc(msgHeadSize);
|
||||
if (ctx->inputBuf) {
|
||||
ctx->inputLen = 0;
|
||||
ctx->inputCap = msgHeadSize;
|
||||
ctx->inputTotal = -1;
|
||||
if (connectRsp.dnodeNum > 1 && !isEpsetEqual(&global.mgmtEp.epSet, &connectRsp.epSet)) {
|
||||
updateEpSet_s(&global.mgmtEp, &connectRsp.epSet);
|
||||
}
|
||||
msgInfo->code = 0;
|
||||
} else if (msgInfo->rpcType == UDFD_RPC_RETRIVE_FUNC) {
|
||||
SRetrieveFuncRsp retrieveRsp = {0};
|
||||
tDeserializeSRetrieveFuncRsp(pMsg->pCont, pMsg->contLen, &retrieveRsp);
|
||||
|
||||
buf->base = ctx->inputBuf;
|
||||
buf->len = ctx->inputCap;
|
||||
} else {
|
||||
// TODO: log error
|
||||
buf->base = NULL;
|
||||
buf->len = 0;
|
||||
SFuncInfo *pFuncInfo = (SFuncInfo *)taosArrayGet(retrieveRsp.pFuncInfos, 0);
|
||||
SUdf * udf = msgInfo->param;
|
||||
udf->funcType = pFuncInfo->funcType;
|
||||
udf->scriptType = pFuncInfo->scriptType;
|
||||
udf->outputType = pFuncInfo->outputType;
|
||||
udf->outputLen = pFuncInfo->outputLen;
|
||||
udf->bufSize = pFuncInfo->bufSize;
|
||||
|
||||
char path[PATH_MAX] = {0};
|
||||
snprintf(path, sizeof(path), "%s/lib%s.so", TD_TMP_DIR_PATH, pFuncInfo->name);
|
||||
TdFilePtr file =
|
||||
taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL);
|
||||
int64_t count = taosWriteFile(file, pFuncInfo->pCode, pFuncInfo->codeSize);
|
||||
if (count != pFuncInfo->codeSize) {
|
||||
fnError("udfd write udf shared library failed");
|
||||
msgInfo->code = TSDB_CODE_FILE_CORRUPTED;
|
||||
}
|
||||
} else {
|
||||
ctx->inputCap = ctx->inputTotal > ctx->inputCap ? ctx->inputTotal : ctx->inputCap;
|
||||
void *inputBuf = taosMemoryRealloc(ctx->inputBuf, ctx->inputCap);
|
||||
if (inputBuf) {
|
||||
ctx->inputBuf = inputBuf;
|
||||
buf->base = ctx->inputBuf + ctx->inputLen;
|
||||
buf->len = ctx->inputCap - ctx->inputLen;
|
||||
} else {
|
||||
// TODO: log error
|
||||
buf->base = NULL;
|
||||
buf->len = 0;
|
||||
}
|
||||
}
|
||||
fnDebug("allocate buf. input buf cap - len - total : %d - %d - %d", ctx->inputCap, ctx->inputLen, ctx->inputTotal);
|
||||
taosCloseFile(&file);
|
||||
strncpy(udf->path, path, strlen(path));
|
||||
tFreeSFuncInfo(pFuncInfo);
|
||||
taosArrayDestroy(retrieveRsp.pFuncInfos);
|
||||
msgInfo->code = 0;
|
||||
}
|
||||
|
||||
bool isUdfdUvMsgComplete(SUdfdUvConn *pipe) {
|
||||
if (pipe->inputTotal == -1 && pipe->inputLen >= sizeof(int32_t)) {
|
||||
pipe->inputTotal = *(int32_t *)(pipe->inputBuf);
|
||||
}
|
||||
if (pipe->inputLen == pipe->inputCap && pipe->inputTotal == pipe->inputCap) {
|
||||
fnDebug("receive request complete. length %d", pipe->inputLen);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void udfdHandleRequest(SUdfdUvConn *conn) {
|
||||
uv_work_t * work = taosMemoryMalloc(sizeof(uv_work_t));
|
||||
SUvUdfWork *udfWork = taosMemoryMalloc(sizeof(SUvUdfWork));
|
||||
udfWork->client = conn->client;
|
||||
udfWork->input = uv_buf_init(conn->inputBuf, conn->inputLen);
|
||||
conn->inputBuf = NULL;
|
||||
conn->inputLen = 0;
|
||||
conn->inputCap = 0;
|
||||
conn->inputTotal = -1;
|
||||
work->data = udfWork;
|
||||
uv_queue_work(global.loop, work, udfdProcessRequest, udfdSendResponse);
|
||||
}
|
||||
|
||||
void udfdPipeCloseCb(uv_handle_t *pipe) {
|
||||
SUdfdUvConn *conn = pipe->data;
|
||||
taosMemoryFree(conn->client);
|
||||
taosMemoryFree(conn->inputBuf);
|
||||
taosMemoryFree(conn);
|
||||
}
|
||||
|
||||
void udfdUvHandleError(SUdfdUvConn *conn) { uv_close((uv_handle_t *)conn->client, udfdPipeCloseCb); }
|
||||
|
||||
void udfdPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) {
|
||||
fnDebug("udf read %zd bytes from client", nread);
|
||||
if (nread == 0) return;
|
||||
|
||||
SUdfdUvConn *conn = client->data;
|
||||
|
||||
if (nread > 0) {
|
||||
conn->inputLen += nread;
|
||||
if (isUdfdUvMsgComplete(conn)) {
|
||||
udfdHandleRequest(conn);
|
||||
} else {
|
||||
// log error or continue;
|
||||
}
|
||||
_return:
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
uv_sem_post(&msgInfo->resultSem);
|
||||
return;
|
||||
}
|
||||
|
||||
if (nread < 0) {
|
||||
fnDebug("Receive error %s", uv_err_name(nread));
|
||||
if (nread == UV_EOF) {
|
||||
// TODO check more when close
|
||||
} else {
|
||||
}
|
||||
udfdUvHandleError(conn);
|
||||
}
|
||||
int32_t udfdFillUdfInfoFromMNode(void *clientRpc, char *udfName, SUdf *udf) {
|
||||
SRetrieveFuncReq retrieveReq = {0};
|
||||
retrieveReq.numOfFuncs = 1;
|
||||
retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN);
|
||||
taosArrayPush(retrieveReq.pFuncNames, udfName);
|
||||
|
||||
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
|
||||
void * pReq = rpcMallocCont(contLen);
|
||||
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
|
||||
taosArrayDestroy(retrieveReq.pFuncNames);
|
||||
|
||||
SUdfdRpcSendRecvInfo *msgInfo = taosMemoryCalloc(1, sizeof(SUdfdRpcSendRecvInfo));
|
||||
msgInfo->rpcType = UDFD_RPC_RETRIVE_FUNC;
|
||||
msgInfo->param = udf;
|
||||
uv_sem_init(&msgInfo->resultSem, 0);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = contLen;
|
||||
rpcMsg.msgType = TDMT_MND_RETRIEVE_FUNC;
|
||||
rpcMsg.info.ahandle = msgInfo;
|
||||
rpcSendRequest(clientRpc, &global.mgmtEp.epSet, &rpcMsg, NULL);
|
||||
|
||||
uv_sem_wait(&msgInfo->resultSem);
|
||||
uv_sem_destroy(&msgInfo->resultSem);
|
||||
int32_t code = msgInfo->code;
|
||||
taosMemoryFree(msgInfo);
|
||||
return code;
|
||||
}
|
||||
|
||||
void udfdOnNewConnection(uv_stream_t *server, int status) {
|
||||
if (status < 0) {
|
||||
fnError("udfd new connection error. code: %s", uv_strerror(status));
|
||||
return;
|
||||
int32_t udfdConnectToMnode() {
|
||||
SConnectReq connReq = {0};
|
||||
connReq.connType = CONN_TYPE__UDFD;
|
||||
tstrncpy(connReq.app, "udfd", sizeof(connReq.app));
|
||||
tstrncpy(connReq.user, TSDB_DEFAULT_USER, sizeof(connReq.user));
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)(TSDB_DEFAULT_PASS), strlen(TSDB_DEFAULT_PASS), pass);
|
||||
tstrncpy(connReq.passwd, pass, sizeof(connReq.passwd));
|
||||
connReq.pid = htonl(taosGetPId());
|
||||
connReq.startTime = htobe64(taosGetTimestampMs());
|
||||
|
||||
int32_t contLen = tSerializeSConnectReq(NULL, 0, &connReq);
|
||||
void * pReq = rpcMallocCont(contLen);
|
||||
tSerializeSConnectReq(pReq, contLen, &connReq);
|
||||
|
||||
SUdfdRpcSendRecvInfo *msgInfo = taosMemoryCalloc(1, sizeof(SUdfdRpcSendRecvInfo));
|
||||
msgInfo->rpcType = UDFD_RPC_MNODE_CONNECT;
|
||||
uv_sem_init(&msgInfo->resultSem, 0);
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
rpcMsg.msgType = TDMT_MND_CONNECT;
|
||||
rpcMsg.pCont = pReq;
|
||||
rpcMsg.contLen = contLen;
|
||||
rpcMsg.info.ahandle = msgInfo;
|
||||
rpcSendRequest(global.clientRpc, &global.mgmtEp.epSet, &rpcMsg, NULL);
|
||||
|
||||
uv_sem_wait(&msgInfo->resultSem);
|
||||
int32_t code = msgInfo->code;
|
||||
uv_sem_destroy(&msgInfo->resultSem);
|
||||
taosMemoryFree(msgInfo);
|
||||
return code;
|
||||
}
|
||||
|
||||
uv_pipe_t *client = (uv_pipe_t *)taosMemoryMalloc(sizeof(uv_pipe_t));
|
||||
uv_pipe_init(global.loop, client, 0);
|
||||
if (uv_accept(server, (uv_stream_t *)client) == 0) {
|
||||
SUdfdUvConn *ctx = taosMemoryMalloc(sizeof(SUdfdUvConn));
|
||||
ctx->client = (uv_stream_t *)client;
|
||||
ctx->inputBuf = 0;
|
||||
ctx->inputLen = 0;
|
||||
ctx->inputCap = 0;
|
||||
client->data = ctx;
|
||||
ctx->client = (uv_stream_t *)client;
|
||||
uv_read_start((uv_stream_t *)client, udfdAllocBuffer, udfdPipeRead);
|
||||
} else {
|
||||
uv_close((uv_handle_t *)client, NULL);
|
||||
}
|
||||
int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
|
||||
strcpy(udf->name, udfName);
|
||||
int32_t err = 0;
|
||||
|
||||
err = udfdFillUdfInfoFromMNode(global.clientRpc, udf->name, udf);
|
||||
if (err != 0) {
|
||||
fnError("can not retrieve udf from mnode. udf name %s", udfName);
|
||||
return TSDB_CODE_UDF_LOAD_UDF_FAILURE;
|
||||
}
|
||||
|
||||
void udfdIntrSignalHandler(uv_signal_t *handle, int signum) {
|
||||
fnInfo("udfd signal received: %d\n", signum);
|
||||
uv_fs_t req;
|
||||
uv_fs_unlink(global.loop, &req, global.listenPipeName, NULL);
|
||||
uv_signal_stop(handle);
|
||||
uv_stop(global.loop);
|
||||
err = uv_dlopen(udf->path, &udf->lib);
|
||||
if (err != 0) {
|
||||
fnError("can not load library %s. error: %s", udf->path, uv_strerror(err));
|
||||
return TSDB_CODE_UDF_LOAD_UDF_FAILURE;
|
||||
}
|
||||
|
||||
char initFuncName[TSDB_FUNC_NAME_LEN + 5] = {0};
|
||||
char *initSuffix = "_init";
|
||||
strcpy(initFuncName, udfName);
|
||||
strncat(initFuncName, initSuffix, strlen(initSuffix));
|
||||
uv_dlsym(&udf->lib, initFuncName, (void **)(&udf->initFunc));
|
||||
|
||||
char destroyFuncName[TSDB_FUNC_NAME_LEN + 5] = {0};
|
||||
char *destroySuffix = "_destroy";
|
||||
strcpy(destroyFuncName, udfName);
|
||||
strncat(destroyFuncName, destroySuffix, strlen(destroySuffix));
|
||||
uv_dlsym(&udf->lib, destroyFuncName, (void **)(&udf->destroyFunc));
|
||||
|
||||
if (udf->funcType == TSDB_FUNC_TYPE_SCALAR) {
|
||||
char processFuncName[TSDB_FUNC_NAME_LEN] = {0};
|
||||
strcpy(processFuncName, udfName);
|
||||
uv_dlsym(&udf->lib, processFuncName, (void **)(&udf->scalarProcFunc));
|
||||
} else if (udf->funcType == TSDB_FUNC_TYPE_AGGREGATE) {
|
||||
char processFuncName[TSDB_FUNC_NAME_LEN] = {0};
|
||||
strcpy(processFuncName, udfName);
|
||||
uv_dlsym(&udf->lib, processFuncName, (void **)(&udf->aggProcFunc));
|
||||
char startFuncName[TSDB_FUNC_NAME_LEN + 6] = {0};
|
||||
char *startSuffix = "_start";
|
||||
strncpy(startFuncName, processFuncName, strlen(processFuncName));
|
||||
strncat(startFuncName, startSuffix, strlen(startSuffix));
|
||||
uv_dlsym(&udf->lib, startFuncName, (void **)(&udf->aggStartFunc));
|
||||
char finishFuncName[TSDB_FUNC_NAME_LEN + 7] = {0};
|
||||
char *finishSuffix = "_finish";
|
||||
strncpy(finishFuncName, processFuncName, strlen(processFuncName));
|
||||
strncat(finishFuncName, finishSuffix, strlen(finishSuffix));
|
||||
uv_dlsym(&udf->lib, finishFuncName, (void **)(&udf->aggFinishFunc));
|
||||
// TODO: merge
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
static bool udfdRpcRfp(int32_t code) {
|
||||
if (code == TSDB_CODE_RPC_REDIRECT) {
|
||||
return true;
|
||||
|
@ -712,15 +608,144 @@ int32_t udfdCloseClientRpc() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void udfdPrintVersion() {
|
||||
#ifdef TD_ENTERPRISE
|
||||
char *releaseName = "enterprise";
|
||||
#else
|
||||
char *releaseName = "community";
|
||||
#endif
|
||||
printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version);
|
||||
printf("gitinfo: %s\n", gitinfo);
|
||||
printf("buildInfo: %s\n", buildinfo);
|
||||
void udfdOnWrite(uv_write_t *req, int status) {
|
||||
SUvUdfWork *work = (SUvUdfWork *)req->data;
|
||||
if (status < 0) {
|
||||
fnError("udfd send response error, length: %zu code: %s", work->output.len, uv_err_name(status));
|
||||
}
|
||||
taosMemoryFree(work->output.base);
|
||||
taosMemoryFree(work);
|
||||
taosMemoryFree(req);
|
||||
}
|
||||
|
||||
void udfdSendResponse(uv_work_t *work, int status) {
|
||||
SUvUdfWork *udfWork = (SUvUdfWork *)(work->data);
|
||||
|
||||
uv_write_t *write_req = taosMemoryMalloc(sizeof(uv_write_t));
|
||||
write_req->data = udfWork;
|
||||
uv_write(write_req, udfWork->client, &udfWork->output, 1, udfdOnWrite);
|
||||
|
||||
taosMemoryFree(work);
|
||||
}
|
||||
|
||||
void udfdAllocBuffer(uv_handle_t *handle, size_t suggestedSize, uv_buf_t *buf) {
|
||||
SUdfdUvConn *ctx = handle->data;
|
||||
int32_t msgHeadSize = sizeof(int32_t) + sizeof(int64_t);
|
||||
if (ctx->inputCap == 0) {
|
||||
ctx->inputBuf = taosMemoryMalloc(msgHeadSize);
|
||||
if (ctx->inputBuf) {
|
||||
ctx->inputLen = 0;
|
||||
ctx->inputCap = msgHeadSize;
|
||||
ctx->inputTotal = -1;
|
||||
|
||||
buf->base = ctx->inputBuf;
|
||||
buf->len = ctx->inputCap;
|
||||
} else {
|
||||
fnError("udfd can not allocate enough memory")
|
||||
buf->base = NULL;
|
||||
buf->len = 0;
|
||||
}
|
||||
} else {
|
||||
ctx->inputCap = ctx->inputTotal > ctx->inputCap ? ctx->inputTotal : ctx->inputCap;
|
||||
void *inputBuf = taosMemoryRealloc(ctx->inputBuf, ctx->inputCap);
|
||||
if (inputBuf) {
|
||||
ctx->inputBuf = inputBuf;
|
||||
buf->base = ctx->inputBuf + ctx->inputLen;
|
||||
buf->len = ctx->inputCap - ctx->inputLen;
|
||||
} else {
|
||||
fnError("udfd can not allocate enough memory")
|
||||
buf->base = NULL;
|
||||
buf->len = 0;
|
||||
}
|
||||
}
|
||||
fnDebug("allocate buf. input buf cap - len - total : %d - %d - %d", ctx->inputCap, ctx->inputLen, ctx->inputTotal);
|
||||
}
|
||||
|
||||
bool isUdfdUvMsgComplete(SUdfdUvConn *pipe) {
|
||||
if (pipe->inputTotal == -1 && pipe->inputLen >= sizeof(int32_t)) {
|
||||
pipe->inputTotal = *(int32_t *)(pipe->inputBuf);
|
||||
}
|
||||
if (pipe->inputLen == pipe->inputCap && pipe->inputTotal == pipe->inputCap) {
|
||||
fnDebug("receive request complete. length %d", pipe->inputLen);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void udfdHandleRequest(SUdfdUvConn *conn) {
|
||||
uv_work_t * work = taosMemoryMalloc(sizeof(uv_work_t));
|
||||
SUvUdfWork *udfWork = taosMemoryMalloc(sizeof(SUvUdfWork));
|
||||
udfWork->client = conn->client;
|
||||
udfWork->input = uv_buf_init(conn->inputBuf, conn->inputLen);
|
||||
conn->inputBuf = NULL;
|
||||
conn->inputLen = 0;
|
||||
conn->inputCap = 0;
|
||||
conn->inputTotal = -1;
|
||||
work->data = udfWork;
|
||||
uv_queue_work(global.loop, work, udfdProcessRequest, udfdSendResponse);
|
||||
}
|
||||
|
||||
void udfdPipeCloseCb(uv_handle_t *pipe) {
|
||||
SUdfdUvConn *conn = pipe->data;
|
||||
taosMemoryFree(conn->client);
|
||||
taosMemoryFree(conn->inputBuf);
|
||||
taosMemoryFree(conn);
|
||||
}
|
||||
|
||||
void udfdPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) {
|
||||
fnDebug("udf read %zd bytes from client", nread);
|
||||
if (nread == 0) return;
|
||||
|
||||
SUdfdUvConn *conn = client->data;
|
||||
|
||||
if (nread > 0) {
|
||||
conn->inputLen += nread;
|
||||
if (isUdfdUvMsgComplete(conn)) {
|
||||
udfdHandleRequest(conn);
|
||||
} else {
|
||||
// log error or continue;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (nread < 0) {
|
||||
fnError("Receive error %s", uv_err_name(nread));
|
||||
if (nread == UV_EOF) {
|
||||
// TODO check more when close
|
||||
} else {
|
||||
}
|
||||
udfdUvHandleError(conn);
|
||||
}
|
||||
}
|
||||
|
||||
void udfdOnNewConnection(uv_stream_t *server, int status) {
|
||||
if (status < 0) {
|
||||
fnError("udfd new connection error. code: %s", uv_strerror(status));
|
||||
return;
|
||||
}
|
||||
|
||||
uv_pipe_t *client = (uv_pipe_t *)taosMemoryMalloc(sizeof(uv_pipe_t));
|
||||
uv_pipe_init(global.loop, client, 0);
|
||||
if (uv_accept(server, (uv_stream_t *)client) == 0) {
|
||||
SUdfdUvConn *ctx = taosMemoryMalloc(sizeof(SUdfdUvConn));
|
||||
ctx->client = (uv_stream_t *)client;
|
||||
ctx->inputBuf = 0;
|
||||
ctx->inputLen = 0;
|
||||
ctx->inputCap = 0;
|
||||
client->data = ctx;
|
||||
ctx->client = (uv_stream_t *)client;
|
||||
uv_read_start((uv_stream_t *)client, udfdAllocBuffer, udfdPipeRead);
|
||||
} else {
|
||||
uv_close((uv_handle_t *)client, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void udfdIntrSignalHandler(uv_signal_t *handle, int signum) {
|
||||
fnInfo("udfd signal received: %d\n", signum);
|
||||
uv_fs_t req;
|
||||
uv_fs_unlink(global.loop, &req, global.listenPipeName, NULL);
|
||||
uv_signal_stop(handle);
|
||||
uv_stop(global.loop);
|
||||
}
|
||||
|
||||
static int32_t udfdParseArgs(int32_t argc, char *argv[]) {
|
||||
|
@ -745,6 +770,17 @@ static int32_t udfdParseArgs(int32_t argc, char *argv[]) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void udfdPrintVersion() {
|
||||
#ifdef TD_ENTERPRISE
|
||||
char *releaseName = "enterprise";
|
||||
#else
|
||||
char *releaseName = "community";
|
||||
#endif
|
||||
printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version);
|
||||
printf("gitinfo: %s\n", gitinfo);
|
||||
printf("buildInfo: %s\n", buildinfo);
|
||||
}
|
||||
|
||||
static int32_t udfdInitLog() {
|
||||
char logName[12] = {0};
|
||||
snprintf(logName, sizeof(logName), "%slog", "udfd");
|
||||
|
@ -868,8 +904,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
int32_t retryMnodeTimes = 0;
|
||||
int32_t code = 0;
|
||||
while (retryMnodeTimes++ < TSDB_MAX_REPLICA) {
|
||||
uv_sleep(500 * (1 << retryMnodeTimes));
|
||||
while (retryMnodeTimes++ <= TSDB_MAX_REPLICA) {
|
||||
uv_sleep(100 * (1 << retryMnodeTimes));
|
||||
code = udfdConnectToMnode();
|
||||
if (code == 0) {
|
||||
break;
|
||||
|
@ -890,6 +926,7 @@ int main(int argc, char *argv[]) {
|
|||
udfdRun();
|
||||
|
||||
removeListeningPipe();
|
||||
|
||||
udfdCloseClientRpc();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ if (${BUILD_WITH_INVERTEDINDEX})
|
|||
endif(${BUILD_WITH_INVERTEDINDEX})
|
||||
|
||||
|
||||
if (${BUILD_TEST})
|
||||
add_subdirectory(test)
|
||||
endif(${BUILD_TEST})
|
||||
#if (${BUILD_TEST})
|
||||
# add_subdirectory(test)
|
||||
#endif(${BUILD_TEST})
|
||||
|
||||
|
|
|
@ -63,7 +63,10 @@ typedef struct CacheTerm {
|
|||
|
||||
IndexCache* indexCacheCreate(SIndex* idx, uint64_t suid, const char* colName, int8_t type);
|
||||
|
||||
void indexCacheForceToMerge(void* cache);
|
||||
void indexCacheDestroy(void* cache);
|
||||
void indexCacheBroadcast(void* cache);
|
||||
void indexCacheWait(void* cache);
|
||||
|
||||
Iterate* indexCacheIteratorCreate(IndexCache* cache);
|
||||
void indexCacheIteratorDestroy(Iterate* iiter);
|
||||
|
|
|
@ -58,6 +58,8 @@ struct SIndex {
|
|||
|
||||
SIndexStat stat;
|
||||
TdThreadMutex mtx;
|
||||
tsem_t sem;
|
||||
bool quit;
|
||||
};
|
||||
|
||||
struct SIndexOpts {
|
||||
|
@ -69,6 +71,7 @@ struct SIndexOpts {
|
|||
int32_t cacheSize; // MB
|
||||
// add cache module later
|
||||
#endif
|
||||
int32_t cacheOpt; // MB
|
||||
};
|
||||
|
||||
struct SIndexMultiTermQuery {
|
||||
|
@ -131,42 +134,14 @@ int32_t indexSerialCacheKey(ICacheKey* key, char* buf);
|
|||
// int32_t indexSerialKey(ICacheKey* key, char* buf);
|
||||
// int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
|
||||
|
||||
#define indexFatal(...) \
|
||||
do { \
|
||||
if (sDebugFlag & DEBUG_FATAL) { \
|
||||
taosPrintLog("index FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#define indexError(...) \
|
||||
do { \
|
||||
if (sDebugFlag & DEBUG_ERROR) { \
|
||||
taosPrintLog("index ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#define indexWarn(...) \
|
||||
do { \
|
||||
if (sDebugFlag & DEBUG_WARN) { \
|
||||
taosPrintLog("index WARN ", DEBUG_WARN, 255, __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#define indexInfo(...) \
|
||||
do { \
|
||||
if (sDebugFlag & DEBUG_INFO) { \
|
||||
taosPrintLog("index ", DEBUG_INFO, 255, __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#define indexDebug(...) \
|
||||
do { \
|
||||
if (sDebugFlag & DEBUG_DEBUG) { \
|
||||
taosPrintLog("index ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#define indexTrace(...) \
|
||||
do { \
|
||||
if (sDebugFlag & DEBUG_TRACE) { \
|
||||
taosPrintLog("index ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
// clang-format off
|
||||
#define indexFatal(...) do { if (sDebugFlag & DEBUG_FATAL) { taosPrintLog("INDEX FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} while (0)
|
||||
#define indexError(...) do { if (sDebugFlag & DEBUG_ERROR) { taosPrintLog("INDEX ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} while (0)
|
||||
#define indexWarn(...) do { if (sDebugFlag & DEBUG_WARN) { taosPrintLog("INDEX WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} while (0)
|
||||
#define indexInfo(...) do { if (sDebugFlag & DEBUG_INFO) { taosPrintLog("INDEX ", DEBUG_INFO, 255, __VA_ARGS__); } } while (0)
|
||||
#define indexDebug(...) do { if (sDebugFlag & DEBUG_DEBUG) { taosPrintLog("INDEX ", DEBUG_DEBUG, sDebugFlag, __VA_ARGS__);} } while (0)
|
||||
#define indexTrace(...) do { if (sDebugFlag & DEBUG_TRACE) { taosPrintLog("INDEX ", DEBUG_TRACE, sDebugFlag, __VA_ARGS__);} } while (0)
|
||||
// clang-format on
|
||||
|
||||
#define INDEX_TYPE_CONTAIN_EXTERN_TYPE(ty, exTy) (((ty >> 4) & (exTy)) != 0)
|
||||
|
||||
|
|
|
@ -90,6 +90,15 @@ static void indexMergeCacheAndTFile(SArray* result, IterateValue* icache, Iterat
|
|||
// static int32_t indexSerialTermKey(SIndexTerm* itm, char* buf);
|
||||
// int32_t indexSerialKey(ICacheKey* key, char* buf);
|
||||
|
||||
static void indexPost(void* idx) {
|
||||
SIndex* pIdx = idx;
|
||||
tsem_post(&pIdx->sem);
|
||||
}
|
||||
static void indexWait(void* idx) {
|
||||
SIndex* pIdx = idx;
|
||||
tsem_wait(&pIdx->sem);
|
||||
}
|
||||
|
||||
int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
|
||||
taosThreadOnce(&isInit, indexInit);
|
||||
SIndex* sIdx = taosMemoryCalloc(1, sizeof(SIndex));
|
||||
|
@ -107,6 +116,8 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) {
|
|||
sIdx->cVersion = 1;
|
||||
sIdx->path = tstrdup(path);
|
||||
taosThreadMutexInit(&sIdx->mtx, NULL);
|
||||
tsem_init(&sIdx->sem, 0, 0);
|
||||
// taosThreadCondInit(&sIdx->finished, NULL);
|
||||
|
||||
sIdx->refId = indexAddRef(sIdx);
|
||||
indexAcquireRef(sIdx->refId);
|
||||
|
@ -124,16 +135,8 @@ END:
|
|||
|
||||
void indexDestroy(void* handle) {
|
||||
SIndex* sIdx = handle;
|
||||
void* iter = taosHashIterate(sIdx->colObj, NULL);
|
||||
while (iter) {
|
||||
IndexCache** pCache = iter;
|
||||
if (*pCache) {
|
||||
indexCacheUnRef(*pCache);
|
||||
}
|
||||
iter = taosHashIterate(sIdx->colObj, iter);
|
||||
}
|
||||
taosHashCleanup(sIdx->colObj);
|
||||
taosThreadMutexDestroy(&sIdx->mtx);
|
||||
tsem_destroy(&sIdx->sem);
|
||||
indexTFileDestroy(sIdx->tindex);
|
||||
taosMemoryFree(sIdx->path);
|
||||
taosMemoryFree(sIdx);
|
||||
|
@ -141,6 +144,20 @@ void indexDestroy(void* handle) {
|
|||
}
|
||||
void indexClose(SIndex* sIdx) {
|
||||
indexReleaseRef(sIdx->refId);
|
||||
bool ref = 0;
|
||||
if (sIdx->colObj != NULL) {
|
||||
void* iter = taosHashIterate(sIdx->colObj, NULL);
|
||||
while (iter) {
|
||||
IndexCache** pCache = iter;
|
||||
indexCacheForceToMerge((void*)(*pCache));
|
||||
indexWait((void*)(sIdx));
|
||||
iter = taosHashIterate(sIdx->colObj, iter);
|
||||
indexCacheUnRef(*pCache);
|
||||
}
|
||||
taosHashCleanup(sIdx->colObj);
|
||||
sIdx->colObj = NULL;
|
||||
}
|
||||
// taosMsleep(1000 * 5);
|
||||
indexRemoveRef(sIdx->refId);
|
||||
}
|
||||
int64_t indexAddRef(void* p) {
|
||||
|
@ -451,6 +468,18 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache) {
|
|||
}
|
||||
// handle flush
|
||||
Iterate* cacheIter = indexCacheIteratorCreate(pCache);
|
||||
if (cacheIter == NULL) {
|
||||
indexError("%p immtable is empty, ignore merge opera", pCache);
|
||||
indexCacheDestroyImm(pCache);
|
||||
tfileReaderUnRef(pReader);
|
||||
if (sIdx->quit) {
|
||||
indexPost(sIdx);
|
||||
// indexCacheBroadcast(pCache);
|
||||
}
|
||||
indexReleaseRef(sIdx->refId);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Iterate* tfileIter = tfileIteratorCreate(pReader);
|
||||
if (tfileIter == NULL) {
|
||||
indexWarn("empty tfile reader iterator");
|
||||
|
@ -506,7 +535,11 @@ int indexFlushCacheToTFile(SIndex* sIdx, void* cache) {
|
|||
} else {
|
||||
indexInfo("success to merge , time cost: %" PRId64 "ms", cost / 1000);
|
||||
}
|
||||
if (sIdx->quit) {
|
||||
indexPost(sIdx);
|
||||
}
|
||||
indexReleaseRef(sIdx->refId);
|
||||
|
||||
return ret;
|
||||
}
|
||||
void iterateValueDestroy(IterateValue* value, bool destroy) {
|
||||
|
@ -563,10 +596,11 @@ int32_t indexSerialCacheKey(ICacheKey* key, char* buf) {
|
|||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(key->colType, TSDB_DATA_TYPE_JSON);
|
||||
|
||||
char* p = buf;
|
||||
SERIALIZE_MEM_TO_BUF(buf, key, suid);
|
||||
char tbuf[65] = {0};
|
||||
indexInt2str((int64_t)key->suid, tbuf, 0);
|
||||
|
||||
SERIALIZE_STR_VAR_TO_BUF(buf, tbuf, strlen(tbuf));
|
||||
SERIALIZE_VAR_TO_BUF(buf, '_', char);
|
||||
// SERIALIZE_MEM_TO_BUF(buf, key, colType);
|
||||
// SERIALIZE_VAR_TO_BUF(buf, '_', char);
|
||||
if (hasJson) {
|
||||
SERIALIZE_STR_VAR_TO_BUF(buf, JSON_COLUMN, strlen(JSON_COLUMN));
|
||||
} else {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#define MEM_TERM_LIMIT 10 * 10000
|
||||
#define MEM_THRESHOLD 64 * 1024
|
||||
#define MEM_SIGNAL_QUIT MEM_THRESHOLD * 20
|
||||
#define MEM_ESTIMATE_RADIO 1.5
|
||||
|
||||
static void indexMemRef(MemTable* tbl);
|
||||
|
@ -385,7 +386,7 @@ void indexCacheDebug(IndexCache* cache) {
|
|||
|
||||
void indexCacheDestroySkiplist(SSkipList* slt) {
|
||||
SSkipListIterator* iter = tSkipListCreateIter(slt);
|
||||
while (tSkipListIterNext(iter)) {
|
||||
while (iter != NULL && tSkipListIterNext(iter)) {
|
||||
SSkipListNode* node = tSkipListIterGet(iter);
|
||||
CacheTerm* ct = (CacheTerm*)SL_GET_NODE_DATA(node);
|
||||
if (ct != NULL) {
|
||||
|
@ -396,17 +397,24 @@ void indexCacheDestroySkiplist(SSkipList* slt) {
|
|||
tSkipListDestroyIter(iter);
|
||||
tSkipListDestroy(slt);
|
||||
}
|
||||
void indexCacheBroadcast(void* cache) {
|
||||
IndexCache* pCache = cache;
|
||||
taosThreadCondBroadcast(&pCache->finished);
|
||||
}
|
||||
void indexCacheWait(void* cache) {
|
||||
IndexCache* pCache = cache;
|
||||
taosThreadCondWait(&pCache->finished, &pCache->mtx);
|
||||
}
|
||||
void indexCacheDestroyImm(IndexCache* cache) {
|
||||
if (cache == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
MemTable* tbl = NULL;
|
||||
taosThreadMutexLock(&cache->mtx);
|
||||
|
||||
tbl = cache->imm;
|
||||
cache->imm = NULL; // or throw int bg thread
|
||||
taosThreadCondBroadcast(&cache->finished);
|
||||
indexCacheBroadcast(cache);
|
||||
|
||||
taosThreadMutexUnlock(&cache->mtx);
|
||||
|
||||
|
@ -429,11 +437,13 @@ void indexCacheDestroy(void* cache) {
|
|||
}
|
||||
|
||||
Iterate* indexCacheIteratorCreate(IndexCache* cache) {
|
||||
if (cache->imm == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
Iterate* iiter = taosMemoryCalloc(1, sizeof(Iterate));
|
||||
if (iiter == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&cache->mtx);
|
||||
|
||||
indexMemRef(cache->imm);
|
||||
|
@ -458,17 +468,16 @@ void indexCacheIteratorDestroy(Iterate* iter) {
|
|||
taosMemoryFree(iter);
|
||||
}
|
||||
|
||||
int indexCacheSchedToMerge(IndexCache* pCache) {
|
||||
int indexCacheSchedToMerge(IndexCache* pCache, bool notify) {
|
||||
SSchedMsg schedMsg = {0};
|
||||
schedMsg.fp = doMergeWork;
|
||||
schedMsg.ahandle = pCache;
|
||||
schedMsg.thandle = NULL;
|
||||
// schedMsg.thandle = taosMemoryCalloc(1, sizeof(int64_t));
|
||||
// memcpy((char*)(schedMsg.thandle), (char*)&(pCache->index->refId), sizeof(int64_t));
|
||||
if (notify) {
|
||||
schedMsg.thandle = taosMemoryMalloc(1);
|
||||
}
|
||||
schedMsg.msg = NULL;
|
||||
indexAcquireRef(pCache->index->refId);
|
||||
taosScheduleTask(indexQhandle, &schedMsg);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -478,8 +487,10 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
|
|||
break;
|
||||
} else if (cache->imm != NULL) {
|
||||
// TODO: wake up by condition variable
|
||||
taosThreadCondWait(&cache->finished, &cache->mtx);
|
||||
indexCacheWait(cache);
|
||||
} else {
|
||||
bool notifyQuit = cache->occupiedMem >= MEM_SIGNAL_QUIT ? true : false;
|
||||
|
||||
indexCacheRef(cache);
|
||||
cache->imm = cache->mem;
|
||||
cache->mem = indexInternalCacheCreate(cache->type);
|
||||
|
@ -487,7 +498,7 @@ static void indexCacheMakeRoomForWrite(IndexCache* cache) {
|
|||
cache->occupiedMem = 0;
|
||||
// sched to merge
|
||||
// unref cache in bgwork
|
||||
indexCacheSchedToMerge(cache);
|
||||
indexCacheSchedToMerge(cache, notifyQuit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -533,6 +544,19 @@ int indexCachePut(void* cache, SIndexTerm* term, uint64_t uid) {
|
|||
return 0;
|
||||
// encode end
|
||||
}
|
||||
void indexCacheForceToMerge(void* cache) {
|
||||
IndexCache* pCache = cache;
|
||||
indexCacheRef(pCache);
|
||||
taosThreadMutexLock(&pCache->mtx);
|
||||
|
||||
indexInfo("%p is forced to merge into tfile", pCache);
|
||||
pCache->occupiedMem += MEM_SIGNAL_QUIT;
|
||||
indexCacheMakeRoomForWrite(pCache);
|
||||
|
||||
taosThreadMutexUnlock(&pCache->mtx);
|
||||
indexCacheUnRef(pCache);
|
||||
return;
|
||||
}
|
||||
int indexCacheDel(void* cache, const char* fieldValue, int32_t fvlen, uint64_t uid, int8_t operType) {
|
||||
IndexCache* pCache = cache;
|
||||
return 0;
|
||||
|
@ -691,6 +715,9 @@ static MemTable* indexInternalCacheCreate(int8_t type) {
|
|||
static void doMergeWork(SSchedMsg* msg) {
|
||||
IndexCache* pCache = msg->ahandle;
|
||||
SIndex* sidx = (SIndex*)pCache->index;
|
||||
|
||||
sidx->quit = msg->thandle ? true : false;
|
||||
taosMemoryFree(msg->thandle);
|
||||
indexFlushCacheToTFile(sidx, pCache);
|
||||
}
|
||||
static bool indexCacheIteratorNext(Iterate* itera) {
|
||||
|
@ -709,9 +736,6 @@ static bool indexCacheIteratorNext(Iterate* itera) {
|
|||
iv->type = ct->operaType;
|
||||
iv->ver = ct->version;
|
||||
iv->colVal = tstrdup(ct->colVal);
|
||||
// printf("col Val: %s\n", iv->colVal);
|
||||
// iv->colType = cv->colType;
|
||||
|
||||
taosArrayPush(iv->val, &ct->uid);
|
||||
}
|
||||
return next;
|
||||
|
|
|
@ -22,6 +22,29 @@
|
|||
#include "ttypes.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
#define INDEX_DATA_BOOL_NULL 0x02
|
||||
#define INDEX_DATA_TINYINT_NULL 0x80
|
||||
#define INDEX_DATA_SMALLINT_NULL 0x8000
|
||||
#define INDEX_DATA_INT_NULL 0x80000000L
|
||||
#define INDEX_DATA_BIGINT_NULL 0x8000000000000000L
|
||||
#define INDEX_DATA_TIMESTAMP_NULL TSDB_DATA_BIGINT_NULL
|
||||
|
||||
#define INDEX_DATA_FLOAT_NULL 0x7FF00000 // it is an NAN
|
||||
#define INDEX_DATA_DOUBLE_NULL 0x7FFFFF0000000000L // an NAN
|
||||
#define INDEX_DATA_NCHAR_NULL 0xFFFFFFFF
|
||||
#define INDEX_DATA_BINARY_NULL 0xFF
|
||||
#define INDEX_DATA_JSON_NULL 0xFFFFFFFF
|
||||
#define INDEX_DATA_JSON_null 0xFFFFFFFE
|
||||
#define INDEX_DATA_JSON_NOT_NULL 0x01
|
||||
|
||||
#define INDEX_DATA_UTINYINT_NULL 0xFF
|
||||
#define INDEX_DATA_USMALLINT_NULL 0xFFFF
|
||||
#define INDEX_DATA_UINT_NULL 0xFFFFFFFF
|
||||
#define INDEX_DATA_UBIGINT_NULL 0xFFFFFFFFFFFFFFFFL
|
||||
|
||||
#define INDEX_DATA_NULL_STR "NULL"
|
||||
#define INDEX_DATA_NULL_STR_L "null"
|
||||
|
||||
char JSON_COLUMN[] = "JSON";
|
||||
char JSON_VALUE_DELIM = '&';
|
||||
|
||||
|
|
|
@ -141,7 +141,6 @@ void tfileCacheDestroy(TFileCache* tcache) {
|
|||
TFileReader* p = *reader;
|
||||
indexInfo("drop table cache suid: %" PRIu64 ", colName: %s, colType: %d", p->header.suid, p->header.colName,
|
||||
p->header.colType);
|
||||
|
||||
tfileReaderUnRef(p);
|
||||
reader = taosHashIterate(tcache->tableCache, reader);
|
||||
}
|
||||
|
@ -172,7 +171,6 @@ void tfileCachePut(TFileCache* tcache, ICacheKey* key, TFileReader* reader) {
|
|||
oldReader->remove = true;
|
||||
tfileReaderUnRef(oldReader);
|
||||
}
|
||||
|
||||
taosHashPut(tcache->tableCache, buf, sz, &reader, sizeof(void*));
|
||||
tfileReaderRef(reader);
|
||||
return;
|
||||
|
@ -500,15 +498,15 @@ static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTempR
|
|||
int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResult* tr) {
|
||||
SIndexTerm* term = query->term;
|
||||
EIndexQueryType qtype = query->qType;
|
||||
|
||||
int ret = 0;
|
||||
if (INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) {
|
||||
return tfSearch[1][qtype](reader, term, tr);
|
||||
ret = tfSearch[1][qtype](reader, term, tr);
|
||||
} else {
|
||||
return tfSearch[0][qtype](reader, term, tr);
|
||||
ret = tfSearch[0][qtype](reader, term, tr);
|
||||
}
|
||||
|
||||
tfileReaderUnRef(reader);
|
||||
return 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
TFileWriter* tfileWriterOpen(char* path, uint64_t suid, int32_t version, const char* colName, uint8_t colType) {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#include "tutil.h"
|
||||
void* callback(void* s) { return s; }
|
||||
|
||||
static std::string fileName = "/tmp/tindex.tindex";
|
||||
static std::string fileName = TD_TMP_DIR_PATH "tindex.tindex";
|
||||
class FstWriter {
|
||||
public:
|
||||
FstWriter() {
|
||||
|
@ -48,7 +48,7 @@ class FstWriter {
|
|||
|
||||
class FstReadMemory {
|
||||
public:
|
||||
FstReadMemory(int32_t size, const std::string& fileName = "/tmp/tindex.tindex") {
|
||||
FstReadMemory(int32_t size, const std::string& fileName = TD_TMP_DIR_PATH "tindex.tindex") {
|
||||
_wc = writerCtxCreate(TFile, fileName.c_str(), true, 64 * 1024);
|
||||
_w = fstCountingWriterCreate(_wc);
|
||||
_size = size;
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#include "tskiplist.h"
|
||||
#include "tutil.h"
|
||||
|
||||
static std::string dir = "/tmp/index";
|
||||
static std::string dir = TD_TMP_DIR_PATH "index";
|
||||
|
||||
static char indexlog[PATH_MAX] = {0};
|
||||
static char tindex[PATH_MAX] = {0};
|
||||
|
|
|
@ -51,7 +51,7 @@ class DebugInfo {
|
|||
class FstWriter {
|
||||
public:
|
||||
FstWriter() {
|
||||
_wc = writerCtxCreate(TFile, "/tmp/tindex", false, 64 * 1024 * 1024);
|
||||
_wc = writerCtxCreate(TFile, TD_TMP_DIR_PATH "tindex", false, 64 * 1024 * 1024);
|
||||
_b = fstBuilderCreate(NULL, 0);
|
||||
}
|
||||
bool Put(const std::string& key, uint64_t val) {
|
||||
|
@ -75,7 +75,7 @@ class FstWriter {
|
|||
class FstReadMemory {
|
||||
public:
|
||||
FstReadMemory(size_t size) {
|
||||
_wc = writerCtxCreate(TFile, "/tmp/tindex", true, 64 * 1024);
|
||||
_wc = writerCtxCreate(TFile, TD_TMP_DIR_PATH "tindex", true, 64 * 1024);
|
||||
_w = fstCountingWriterCreate(_wc);
|
||||
_size = size;
|
||||
memset((void*)&_s, 0, sizeof(_s));
|
||||
|
@ -272,9 +272,26 @@ void validateFst() {
|
|||
}
|
||||
delete m;
|
||||
}
|
||||
static std::string logDir = "/tmp/log";
|
||||
|
||||
static void initLog() {
|
||||
const char* defaultLogFileNamePrefix = "taoslog";
|
||||
const int32_t maxLogFileNum = 10;
|
||||
|
||||
tsAsyncLog = 0;
|
||||
sDebugFlag = 143;
|
||||
strcpy(tsLogDir, logDir.c_str());
|
||||
taosRemoveDir(tsLogDir);
|
||||
taosMkDir(tsLogDir);
|
||||
|
||||
if (taosInitLog(defaultLogFileNamePrefix, maxLogFileNum) < 0) {
|
||||
printf("failed to open log file in directory:%s\n", tsLogDir);
|
||||
}
|
||||
}
|
||||
class IndexEnv : public ::testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
initLog();
|
||||
taosRemoveDir(path);
|
||||
opts = indexOptsCreate();
|
||||
int ret = indexOpen(opts, path, &index);
|
||||
|
@ -285,7 +302,7 @@ class IndexEnv : public ::testing::Test {
|
|||
indexOptsDestroy(opts);
|
||||
}
|
||||
|
||||
const char* path = "/tmp/tindex";
|
||||
const char* path = TD_TMP_DIR_PATH "tindex";
|
||||
SIndexOpts* opts;
|
||||
SIndex* index;
|
||||
};
|
||||
|
@ -342,7 +359,7 @@ class IndexEnv : public ::testing::Test {
|
|||
|
||||
class TFileObj {
|
||||
public:
|
||||
TFileObj(const std::string& path = "/tmp/tindex", const std::string& colName = "voltage")
|
||||
TFileObj(const std::string& path = TD_TMP_DIR_PATH "tindex", const std::string& colName = "voltage")
|
||||
: path_(path), colName_(colName) {
|
||||
colId_ = 10;
|
||||
reader_ = NULL;
|
||||
|
@ -437,7 +454,7 @@ class IndexTFileEnv : public ::testing::Test {
|
|||
// tfileWriterDestroy(twrite);
|
||||
}
|
||||
TFileObj* fObj;
|
||||
std::string dir = "/tmp/tindex";
|
||||
std::string dir = TD_TMP_DIR_PATH "tindex";
|
||||
std::string colName = "voltage";
|
||||
|
||||
int coldId = 2;
|
||||
|
@ -804,7 +821,7 @@ class IndexObj {
|
|||
}
|
||||
|
||||
~IndexObj() {
|
||||
indexCleanUp();
|
||||
// indexCleanUp();
|
||||
indexClose(idx);
|
||||
}
|
||||
|
||||
|
@ -817,12 +834,15 @@ class IndexObj {
|
|||
|
||||
class IndexEnv2 : public ::testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() { index = new IndexObj(); }
|
||||
virtual void SetUp() {
|
||||
initLog();
|
||||
index = new IndexObj();
|
||||
}
|
||||
virtual void TearDown() { delete index; }
|
||||
IndexObj* index;
|
||||
};
|
||||
TEST_F(IndexEnv2, testIndexOpen) {
|
||||
std::string path = "/tmp/test";
|
||||
std::string path = TD_TMP_DIR_PATH "test";
|
||||
if (index->Init(path) != 0) {
|
||||
std::cout << "failed to init index" << std::endl;
|
||||
exit(1);
|
||||
|
@ -884,14 +904,37 @@ TEST_F(IndexEnv2, testIndexOpen) {
|
|||
SArray* result = (SArray*)taosArrayInit(1, sizeof(uint64_t));
|
||||
index->Search(mq, result);
|
||||
std::cout << "target size: " << taosArrayGetSize(result) << std::endl;
|
||||
assert(taosArrayGetSize(result) == 400);
|
||||
EXPECT_EQ(400, taosArrayGetSize(result));
|
||||
taosArrayDestroy(result);
|
||||
indexMultiTermQueryDestroy(mq);
|
||||
}
|
||||
}
|
||||
TEST_F(IndexEnv2, testEmptyIndexOpen) {
|
||||
std::string path = "/tmp/test";
|
||||
if (index->Init(path) != 0) {
|
||||
std::cout << "failed to init index" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int targetSize = 1;
|
||||
{
|
||||
std::string colName("tag1"), colVal("Hello");
|
||||
|
||||
SIndexTerm* term = indexTermCreate(0, ADD_VALUE, TSDB_DATA_TYPE_BINARY, colName.c_str(), colName.size(),
|
||||
colVal.c_str(), colVal.size());
|
||||
SIndexMultiTerm* terms = indexMultiTermCreate();
|
||||
indexMultiTermAdd(terms, term);
|
||||
for (size_t i = 0; i < targetSize; i++) {
|
||||
int tableId = i;
|
||||
int ret = index->Put(terms, tableId);
|
||||
assert(ret == 0);
|
||||
}
|
||||
indexMultiTermDestroy(terms);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(IndexEnv2, testIndex_TrigeFlush) {
|
||||
std::string path = "/tmp/testxxx";
|
||||
std::string path = TD_TMP_DIR_PATH "testxxx";
|
||||
if (index->Init(path) != 0) {
|
||||
// r
|
||||
std::cout << "failed to init" << std::endl;
|
||||
|
@ -914,7 +957,7 @@ static void multi_write_and_search(IndexObj* idx) {
|
|||
idx->WriteMultiMillonData("tag2", "world test nothing", 100 * 10);
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
// opt
|
||||
}
|
||||
|
@ -934,7 +977,7 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) {
|
|||
}
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_MultiWrite_and_MultiRead) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
|
||||
|
@ -950,14 +993,14 @@ TEST_F(IndexEnv2, testIndex_MultiWrite_and_MultiRead) {
|
|||
}
|
||||
|
||||
// TEST_F(IndexEnv2, testIndex_restart) {
|
||||
// std::string path = "/tmp/cache_and_tfile";
|
||||
// std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
// if (index->Init(path) != 0) {
|
||||
// }
|
||||
// index->SearchOneTarget("tag1", "Hello", 10);
|
||||
// index->SearchOneTarget("tag2", "Test", 10);
|
||||
//}
|
||||
// TEST_F(IndexEnv2, testIndex_restart1) {
|
||||
// std::string path = "/tmp/cache_and_tfile";
|
||||
// std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
// if (index->Init(path) != 0) {
|
||||
// }
|
||||
// index->ReadMultiMillonData("tag1", "coding");
|
||||
|
@ -966,7 +1009,7 @@ TEST_F(IndexEnv2, testIndex_MultiWrite_and_MultiRead) {
|
|||
//}
|
||||
|
||||
// TEST_F(IndexEnv2, testIndex_read_performance) {
|
||||
// std::string path = "/tmp/cache_and_tfile";
|
||||
// std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
// if (index->Init(path) != 0) {
|
||||
// }
|
||||
// index->PutOneTarge("tag1", "Hello", 12);
|
||||
|
@ -976,7 +1019,7 @@ TEST_F(IndexEnv2, testIndex_MultiWrite_and_MultiRead) {
|
|||
// assert(3 == index->SearchOne("tag1", "Hello"));
|
||||
//}
|
||||
// TEST_F(IndexEnv2, testIndexMultiTag) {
|
||||
// std::string path = "/tmp/multi_tag";
|
||||
// std::string path = TD_TMP_DIR_PATH "multi_tag";
|
||||
// if (index->Init(path) != 0) {
|
||||
// }
|
||||
// int64_t st = taosGetTimestampUs();
|
||||
|
@ -986,7 +1029,7 @@ TEST_F(IndexEnv2, testIndex_MultiWrite_and_MultiRead) {
|
|||
// // index->WriteMultiMillonData("tag2", "xxxxxxxxxxxxxxxxxxxxxxxxx", 100 * 10000);
|
||||
//}
|
||||
TEST_F(IndexEnv2, testLongComVal1) {
|
||||
std::string path = "/tmp/long_colVal";
|
||||
std::string path = TD_TMP_DIR_PATH "long_colVal";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
// gen colVal by randstr
|
||||
|
@ -995,7 +1038,7 @@ TEST_F(IndexEnv2, testLongComVal1) {
|
|||
}
|
||||
|
||||
TEST_F(IndexEnv2, testLongComVal2) {
|
||||
std::string path = "/tmp/long_colVal";
|
||||
std::string path = TD_TMP_DIR_PATH "long_colVal";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
// gen colVal by randstr
|
||||
|
@ -1003,7 +1046,7 @@ TEST_F(IndexEnv2, testLongComVal2) {
|
|||
index->WriteMultiMillonData("tag1", randstr, 100 * 1000);
|
||||
}
|
||||
TEST_F(IndexEnv2, testLongComVal3) {
|
||||
std::string path = "/tmp/long_colVal";
|
||||
std::string path = TD_TMP_DIR_PATH "long_colVal";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
// gen colVal by randstr
|
||||
|
@ -1011,7 +1054,7 @@ TEST_F(IndexEnv2, testLongComVal3) {
|
|||
index->WriteMultiMillonData("tag1", randstr, 100 * 1000);
|
||||
}
|
||||
TEST_F(IndexEnv2, testLongComVal4) {
|
||||
std::string path = "/tmp/long_colVal";
|
||||
std::string path = TD_TMP_DIR_PATH "long_colVal";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
// gen colVal by randstr
|
||||
|
@ -1019,7 +1062,7 @@ TEST_F(IndexEnv2, testLongComVal4) {
|
|||
index->WriteMultiMillonData("tag1", randstr, 100 * 100);
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_read_performance1) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
index->PutOneTarge("tag1", "Hello", 12);
|
||||
|
@ -1029,7 +1072,7 @@ TEST_F(IndexEnv2, testIndex_read_performance1) {
|
|||
EXPECT_EQ(2, index->SearchOne("tag1", "Hello"));
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_read_performance2) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
index->PutOneTarge("tag1", "Hello", 12);
|
||||
|
@ -1039,7 +1082,7 @@ TEST_F(IndexEnv2, testIndex_read_performance2) {
|
|||
EXPECT_EQ(2, index->SearchOne("tag1", "Hello"));
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_read_performance3) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
index->PutOneTarge("tag1", "Hello", 12);
|
||||
|
@ -1049,7 +1092,7 @@ TEST_F(IndexEnv2, testIndex_read_performance3) {
|
|||
EXPECT_EQ(2, index->SearchOne("tag1", "Hello"));
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_read_performance4) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
index->PutOneTarge("tag10", "Hello", 12);
|
||||
|
@ -1059,7 +1102,7 @@ TEST_F(IndexEnv2, testIndex_read_performance4) {
|
|||
EXPECT_EQ(1, index->SearchOne("tag10", "Hello"));
|
||||
}
|
||||
TEST_F(IndexEnv2, testIndex_cache_del) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
@ -1098,7 +1141,7 @@ TEST_F(IndexEnv2, testIndex_cache_del) {
|
|||
}
|
||||
|
||||
TEST_F(IndexEnv2, testIndex_del) {
|
||||
std::string path = "/tmp/cache_and_tfile";
|
||||
std::string path = TD_TMP_DIR_PATH "cache_and_tfile";
|
||||
if (index->Init(path) != 0) {
|
||||
}
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
#include "tskiplist.h"
|
||||
#include "tutil.h"
|
||||
|
||||
static std::string dir = "/tmp/json";
|
||||
static std::string logDir = "/tmp/log";
|
||||
static std::string dir = TD_TMP_DIR_PATH "json";
|
||||
static std::string logDir = TD_TMP_DIR_PATH "log";
|
||||
|
||||
static void initLog() {
|
||||
const char* defaultLogFileNamePrefix = "taoslog";
|
||||
|
|
|
@ -4454,8 +4454,10 @@ static int32_t buildUpdateTagValReq(STranslateContext* pCxt, SAlterTableStmt* pS
|
|||
|
||||
pReq->isNull = (TSDB_DATA_TYPE_NULL == pStmt->pVal->node.resType.type);
|
||||
pReq->nTagVal = pStmt->pVal->node.resType.bytes;
|
||||
char* pVal = nodesGetValueFromNode(pStmt->pVal);
|
||||
pReq->pTagVal = IS_VAR_DATA_TYPE(pStmt->pVal->node.resType.type) ? pVal + VARSTR_HEADER_SIZE : pVal;
|
||||
if (TSDB_DATA_TYPE_NCHAR == pStmt->pVal->node.resType.type) {
|
||||
pReq->nTagVal = pReq->nTagVal * TSDB_NCHAR_SIZE;
|
||||
}
|
||||
pReq->pTagVal = nodesGetValueFromNode(pStmt->pVal);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -4479,6 +4481,9 @@ static int32_t buildAddColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, S
|
|||
|
||||
static int32_t buildDropColReq(STranslateContext* pCxt, SAlterTableStmt* pStmt, STableMeta* pTableMeta,
|
||||
SVAlterTbReq* pReq) {
|
||||
if (2 == getNumOfColumns(pTableMeta)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DROP_COL);
|
||||
}
|
||||
SSchema* pSchema = getColSchema(pTableMeta, pStmt->colName);
|
||||
if (NULL == pSchema) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_COLUMN, pStmt->colName);
|
||||
|
|
|
@ -169,6 +169,8 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
"And, cannot be mixed with other non scalar functions or columns.";
|
||||
case TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY:
|
||||
return "Window query not supported, since the result of subquery not include valid timestamp column";
|
||||
case TSDB_CODE_PAR_INVALID_DROP_COL:
|
||||
return "No columns can be dropped";
|
||||
case TSDB_CODE_OUT_OF_MEMORY:
|
||||
return "Out of memory";
|
||||
default:
|
||||
|
|
|
@ -204,7 +204,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
}
|
||||
};
|
||||
|
||||
auto setAlterTagFunc = [&](const char* pTbname, const char* pTagName, const uint8_t* pNewVal, uint32_t bytes) {
|
||||
auto setAlterTagFunc = [&](const char* pTbname, const char* pTagName, uint8_t* pNewVal, uint32_t bytes) {
|
||||
memset(&expect, 0, sizeof(SVAlterTbReq));
|
||||
expect.tbName = strdup(pTbname);
|
||||
expect.action = TSDB_ALTER_TABLE_UPDATE_TAG_VAL;
|
||||
|
@ -215,7 +215,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
expect.pTagVal = pNewVal;
|
||||
};
|
||||
|
||||
auto setAlterOptionsFunc = [&](const char* pTbname, int32_t ttl, const char* pComment = nullptr) {
|
||||
auto setAlterOptionsFunc = [&](const char* pTbname, int32_t ttl, char* pComment = nullptr) {
|
||||
memset(&expect, 0, sizeof(SVAlterTbReq));
|
||||
expect.tbName = strdup(pTbname);
|
||||
expect.action = TSDB_ALTER_TABLE_UPDATE_OPTIONS;
|
||||
|
@ -240,7 +240,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
void* pBuf = POINTER_SHIFT(pVgData->pData, sizeof(SMsgHead));
|
||||
SVAlterTbReq req = {0};
|
||||
SDecoder coder = {0};
|
||||
tDecoderInit(&coder, (const uint8_t*)pBuf, pVgData->size);
|
||||
tDecoderInit(&coder, (uint8_t*)pBuf, pVgData->size);
|
||||
ASSERT_EQ(tDecodeSVAlterTbReq(&coder, &req), TSDB_CODE_SUCCESS);
|
||||
|
||||
ASSERT_EQ(std::string(req.tbName), std::string(expect.tbName));
|
||||
|
@ -274,7 +274,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
setAlterOptionsFunc("t1", 10, nullptr);
|
||||
run("ALTER TABLE t1 TTL 10");
|
||||
|
||||
setAlterOptionsFunc("t1", -1, "test");
|
||||
setAlterOptionsFunc("t1", -1, (char*)"test");
|
||||
run("ALTER TABLE t1 COMMENT 'test'");
|
||||
|
||||
setAlterColFunc("t1", TSDB_ALTER_TABLE_ADD_COLUMN, "cc1", TSDB_DATA_TYPE_BIGINT);
|
||||
|
@ -290,7 +290,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
run("ALTER TABLE t1 RENAME COLUMN c1 cc1");
|
||||
|
||||
int32_t val = 10;
|
||||
setAlterTagFunc("st1s1", "tag1", (const uint8_t*)&val, sizeof(val));
|
||||
setAlterTagFunc("st1s1", "tag1", (uint8_t*)&val, sizeof(val));
|
||||
run("ALTER TABLE st1s1 SET TAG tag1=10");
|
||||
|
||||
// todo
|
||||
|
|
|
@ -25,7 +25,7 @@ class PlannerEnv : public testing::Environment {
|
|||
virtual void SetUp() {
|
||||
initMetaDataEnv();
|
||||
generateMetaData();
|
||||
initLog("/tmp/td");
|
||||
initLog(TD_TMP_DIR_PATH "td");
|
||||
}
|
||||
|
||||
virtual void TearDown() { destroyMetaDataEnv(); }
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "planTestUtil.h"
|
||||
#include <getopt.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
|
|
@ -528,20 +528,18 @@ int32_t qwDropTask(QW_FPARAMS_DEF) {
|
|||
}
|
||||
|
||||
int32_t qwHandleTaskComplete(QW_FPARAMS_DEF, SQWTaskCtx *ctx) {
|
||||
qTaskInfo_t *taskHandle = &ctx->taskHandle;
|
||||
qTaskInfo_t taskHandle = ctx->taskHandle;
|
||||
|
||||
if (TASK_TYPE_TEMP == ctx->taskType) {
|
||||
if (TASK_TYPE_TEMP == ctx->taskType && taskHandle) {
|
||||
if (ctx->explain) {
|
||||
SExplainExecInfo *execInfo = NULL;
|
||||
int32_t resNum = 0;
|
||||
QW_ERR_RET(qGetExplainExecInfo(ctx->taskHandle, &resNum, &execInfo));
|
||||
QW_ERR_RET(qGetExplainExecInfo(taskHandle, &resNum, &execInfo));
|
||||
|
||||
SRpcHandleInfo connInfo = ctx->ctrlConnInfo;
|
||||
connInfo.ahandle = NULL;
|
||||
QW_ERR_RET(qwBuildAndSendExplainRsp(&connInfo, execInfo, resNum));
|
||||
}
|
||||
|
||||
qwFreeTaskHandle(QW_FPARAMS(), taskHandle);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -554,17 +552,22 @@ int32_t qwExecTask(QW_FPARAMS_DEF, SQWTaskCtx *ctx, bool *queryEnd) {
|
|||
uint64_t useconds = 0;
|
||||
int32_t i = 0;
|
||||
int32_t execNum = 0;
|
||||
qTaskInfo_t *taskHandle = &ctx->taskHandle;
|
||||
qTaskInfo_t taskHandle = ctx->taskHandle;
|
||||
DataSinkHandle sinkHandle = ctx->sinkHandle;
|
||||
|
||||
while (true) {
|
||||
QW_TASK_DLOG("start to execTask, loopIdx:%d", i++);
|
||||
|
||||
code = qExecTask(*taskHandle, &pRes, &useconds);
|
||||
pRes = NULL;
|
||||
|
||||
// if *taskHandle is NULL, it's killed right now
|
||||
if (taskHandle) {
|
||||
code = qExecTask(taskHandle, &pRes, &useconds);
|
||||
if (code) {
|
||||
QW_TASK_ELOG("qExecTask failed, code:%x - %s", code, tstrerror(code));
|
||||
QW_ERR_RET(code);
|
||||
}
|
||||
}
|
||||
|
||||
++execNum;
|
||||
|
||||
|
|
|
@ -19,18 +19,24 @@
|
|||
#define DEFAULT_FALSE_POSITIVE 0.01
|
||||
#define DEFAULT_BUCKET_SIZE 1024
|
||||
#define ROWS_PER_MILLISECOND 1
|
||||
#define MAX_NUM_SCALABLE_BF 120
|
||||
#define MAX_NUM_SCALABLE_BF 100000
|
||||
#define MIN_NUM_SCALABLE_BF 10
|
||||
#define DEFAULT_PREADD_BUCKET 1
|
||||
#define MAX_INTERVAL MILLISECOND_PER_MINUTE
|
||||
#define MIN_INTERVAL (MILLISECOND_PER_SECOND * 10)
|
||||
#define DEFAULT_EXPECTED_ENTRIES 10000
|
||||
|
||||
static int64_t adjustExpEntries(int64_t entries) {
|
||||
return TMIN(DEFAULT_EXPECTED_ENTRIES, entries);
|
||||
}
|
||||
|
||||
static void windowSBfAdd(SUpdateInfo *pInfo, uint64_t count) {
|
||||
if (pInfo->numSBFs < count) {
|
||||
count = pInfo->numSBFs;
|
||||
}
|
||||
for (uint64_t i = 0; i < count; ++i) {
|
||||
SScalableBf *tsSBF = tScalableBfInit(pInfo->interval * ROWS_PER_MILLISECOND, DEFAULT_FALSE_POSITIVE);
|
||||
int64_t rows = adjustExpEntries(pInfo->interval * ROWS_PER_MILLISECOND);
|
||||
SScalableBf *tsSBF = tScalableBfInit(rows, DEFAULT_FALSE_POSITIVE);
|
||||
taosArrayPush(pInfo->pTsSBFs, &tsSBF);
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +44,9 @@ static void windowSBfAdd(SUpdateInfo *pInfo, uint64_t count) {
|
|||
static void windowSBfDelete(SUpdateInfo *pInfo, uint64_t count) {
|
||||
if (count < pInfo->numSBFs - 1) {
|
||||
for (uint64_t i = 0; i < count; ++i) {
|
||||
SScalableBf *pTsSBFs = taosArrayGetP(pInfo->pTsSBFs, i);
|
||||
SScalableBf *pTsSBFs = taosArrayGetP(pInfo->pTsSBFs, 0);
|
||||
tScalableBfDestroy(pTsSBFs);
|
||||
taosArrayRemove(pInfo->pTsSBFs, i);
|
||||
taosArrayRemove(pInfo->pTsSBFs, 0);
|
||||
}
|
||||
} else {
|
||||
taosArrayClearP(pInfo->pTsSBFs, (FDelete)tScalableBfDestroy);
|
||||
|
@ -66,7 +72,7 @@ static int64_t adjustInterval(int64_t interval, int32_t precision) {
|
|||
return val;
|
||||
}
|
||||
|
||||
static int64_t adjustWatermark(int64_t interval, int32_t watermark) {
|
||||
static int64_t adjustWatermark(int64_t interval, int64_t watermark) {
|
||||
if (watermark <= 0 || watermark > MAX_NUM_SCALABLE_BF * interval) {
|
||||
watermark = MAX_NUM_SCALABLE_BF * interval;
|
||||
} else if (watermark < MIN_NUM_SCALABLE_BF * interval) {
|
||||
|
@ -130,7 +136,8 @@ static SScalableBf *getSBf(SUpdateInfo *pInfo, TSKEY ts) {
|
|||
}
|
||||
SScalableBf *res = taosArrayGetP(pInfo->pTsSBFs, index);
|
||||
if (res == NULL) {
|
||||
res = tScalableBfInit(pInfo->interval * ROWS_PER_MILLISECOND, DEFAULT_FALSE_POSITIVE);
|
||||
int64_t rows = adjustExpEntries(pInfo->interval * ROWS_PER_MILLISECOND);
|
||||
res = tScalableBfInit(rows, DEFAULT_FALSE_POSITIVE);
|
||||
taosArrayPush(pInfo->pTsSBFs, &res);
|
||||
}
|
||||
return res;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "ttime.h"
|
||||
|
||||
using namespace std;
|
||||
#define MAX_NUM_SCALABLE_BF 100000
|
||||
|
||||
TEST(TD_STREAM_UPDATE_TEST, update) {
|
||||
int64_t interval = 20 * 1000;
|
||||
|
@ -91,11 +92,11 @@ TEST(TD_STREAM_UPDATE_TEST, update) {
|
|||
}
|
||||
|
||||
SUpdateInfo *pSU4 = updateInfoInit(-1, TSDB_TIME_PRECISION_MILLI, -1);
|
||||
GTEST_ASSERT_EQ(pSU4->watermark, 120 * pSU4->interval);
|
||||
GTEST_ASSERT_EQ(pSU4->watermark, MAX_NUM_SCALABLE_BF * pSU4->interval);
|
||||
GTEST_ASSERT_EQ(pSU4->interval, MILLISECOND_PER_MINUTE);
|
||||
|
||||
SUpdateInfo *pSU5 = updateInfoInit(0, TSDB_TIME_PRECISION_MILLI, 0);
|
||||
GTEST_ASSERT_EQ(pSU5->watermark, 120 * pSU4->interval);
|
||||
GTEST_ASSERT_EQ(pSU5->watermark, MAX_NUM_SCALABLE_BF * pSU4->interval);
|
||||
GTEST_ASSERT_EQ(pSU5->interval, MILLISECOND_PER_MINUTE);
|
||||
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue