Merge branch 'develop' into feature/TD-1925_new
This commit is contained in:
commit
7f865342f9
|
@ -339,9 +339,10 @@ conn.close();
|
||||||
config.setUsername("root");
|
config.setUsername("root");
|
||||||
config.setPassword("taosdata");
|
config.setPassword("taosdata");
|
||||||
// connection pool configurations
|
// connection pool configurations
|
||||||
config.setMinimumIdle(3); //minimum number of idle connection
|
config.setMinimumIdle(10); //minimum number of idle connection
|
||||||
config.setMaximumPoolSize(10); //maximum number of connection in the pool
|
config.setMaximumPoolSize(10); //maximum number of connection in the pool
|
||||||
config.setConnectionTimeout(30000); //maximum wait milliseconds for get connection from pool
|
config.setConnectionTimeout(30000); //maximum wait milliseconds for get connection from pool
|
||||||
|
config.setMaxLifetime(0); // maximum life time for each connection
|
||||||
config.setIdleTimeout(0); // max idle time for recycle idle connection
|
config.setIdleTimeout(0); // max idle time for recycle idle connection
|
||||||
config.setConnectionTestQuery("select server_status()"); //validation query
|
config.setConnectionTestQuery("select server_status()"); //validation query
|
||||||
|
|
||||||
|
@ -375,24 +376,22 @@ conn.close();
|
||||||
* 使用示例如下:
|
* 使用示例如下:
|
||||||
```java
|
```java
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
Properties properties = new Properties();
|
|
||||||
|
DruidDataSource dataSource = new DruidDataSource();
|
||||||
// jdbc properties
|
// jdbc properties
|
||||||
properties.put("driverClassName","com.taosdata.jdbc.TSDBDriver");
|
dataSource.setDriverClassName("com.taosdata.jdbc.TSDBDriver");
|
||||||
properties.put("url","jdbc:TAOS://127.0.0.1:6030/log");
|
dataSource.setUrl(url);
|
||||||
properties.put("username","root");
|
dataSource.setUsername("root");
|
||||||
properties.put("password","taosdata");
|
dataSource.setPassword("taosdata");
|
||||||
// pool configurations
|
// pool configurations
|
||||||
properties.put("maxActive","10"); //maximum number of connection in the pool
|
dataSource.setInitialSize(10);
|
||||||
properties.put("initialSize","3"); //initial number of connection
|
dataSource.setMinIdle(10);
|
||||||
properties.put("minIdle","3"); //minimum number of connection in the pool
|
dataSource.setMaxActive(10);
|
||||||
properties.put("maxWait","30000"); //maximum wait milliseconds for get connection from pool
|
dataSource.setMaxWait(30000);
|
||||||
properties.put("validationQuery","select server_status()"); //validation query
|
dataSource.setValidationQuery("select server_status()");
|
||||||
|
|
||||||
//create druid datasource
|
Connection connection = dataSource.getConnection(); // get connection
|
||||||
DataSource ds = DruidDataSourceFactory.createDataSource(properties);
|
|
||||||
Connection connection = ds.getConnection(); // get connection
|
|
||||||
Statement statement = connection.createStatement(); // get statement
|
Statement statement = connection.createStatement(); // get statement
|
||||||
|
|
||||||
//query or insert
|
//query or insert
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
|
@ -419,7 +418,7 @@ Query OK, 1 row(s) in set (0.000141s)
|
||||||
## 与框架使用
|
## 与框架使用
|
||||||
|
|
||||||
* Spring JdbcTemplate 中使用 taos-jdbcdriver,可参考 [SpringJdbcTemplate][11]
|
* Spring JdbcTemplate 中使用 taos-jdbcdriver,可参考 [SpringJdbcTemplate][11]
|
||||||
* Springboot + Mybatis 中使用,可参考 [springbootdemo
|
* Springboot + Mybatis 中使用,可参考 [springbootdemo][12]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -905,6 +905,13 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql) {
|
||||||
return tscInvalidSQLErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z);
|
return tscInvalidSQLErrMsg(pCmd->payload, "keyword TAGS expected", sToken.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
sToken = tStrGetToken(sql, &index, false, 0, NULL);
|
||||||
|
sql += index;
|
||||||
|
if (sToken.type != TK_LP) {
|
||||||
|
return tscInvalidSQLErrMsg(pCmd->payload, NULL, sToken.z);
|
||||||
|
}
|
||||||
|
|
||||||
SKVRowBuilder kvRowBuilder = {0};
|
SKVRowBuilder kvRowBuilder = {0};
|
||||||
if (tdInitKVRowBuilder(&kvRowBuilder) < 0) {
|
if (tdInitKVRowBuilder(&kvRowBuilder) < 0) {
|
||||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
@ -1554,6 +1561,7 @@ void tscImportDataFromFile(SSqlObj *pSql) {
|
||||||
tscError("%p failed to open file %s to load data from file, code:%s", pSql, pCmd->payload, tstrerror(pSql->res.code));
|
tscError("%p failed to open file %s to load data from file, code:%s", pSql, pCmd->payload, tstrerror(pSql->res.code));
|
||||||
|
|
||||||
tfree(pSupporter);
|
tfree(pSupporter);
|
||||||
|
taos_free_result(pNew);
|
||||||
tscAsyncResultOnError(pSql);
|
tscAsyncResultOnError(pSql);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1991,7 +1991,22 @@ static void tscAbortFurtherRetryRetrieval(SRetrieveSupport *trsupport, TAOS_RES
|
||||||
* current query failed, and the retry count is less than the available
|
* current query failed, and the retry count is less than the available
|
||||||
* count, retry query clear previous retrieved data, then launch a new sub query
|
* count, retry query clear previous retrieved data, then launch a new sub query
|
||||||
*/
|
*/
|
||||||
static int32_t tscReissueSubquery(SRetrieveSupport *trsupport, SSqlObj *pSql, int32_t code) {
|
static int32_t tscReissueSubquery(SRetrieveSupport *oriTrs, SSqlObj *pSql, int32_t code) {
|
||||||
|
SRetrieveSupport *trsupport = malloc(sizeof(SRetrieveSupport));
|
||||||
|
if (trsupport == NULL) {
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(trsupport, oriTrs, sizeof(*trsupport));
|
||||||
|
|
||||||
|
const uint32_t nBufferSize = (1u << 16u); // 64KB
|
||||||
|
trsupport->localBuffer = (tFilePage *)calloc(1, nBufferSize + sizeof(tFilePage));
|
||||||
|
if (trsupport->localBuffer == NULL) {
|
||||||
|
tscError("%p failed to malloc buffer for local buffer, reason:%s", pSql, strerror(errno));
|
||||||
|
tfree(trsupport);
|
||||||
|
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
SSqlObj *pParentSql = trsupport->pParentSql;
|
SSqlObj *pParentSql = trsupport->pParentSql;
|
||||||
int32_t subqueryIndex = trsupport->subqueryIndex;
|
int32_t subqueryIndex = trsupport->subqueryIndex;
|
||||||
|
|
||||||
|
|
|
@ -2127,6 +2127,10 @@ SSqlObj* createSubqueryObj(SSqlObj* pSql, int16_t tableIndex, __async_cb_func_t
|
||||||
pTableMetaInfo->tagColList, pTableMetaInfo->pVgroupTables);
|
pTableMetaInfo->tagColList, pTableMetaInfo->pVgroupTables);
|
||||||
} else { // transfer the ownership of pTableMeta to the newly create sql object.
|
} else { // transfer the ownership of pTableMeta to the newly create sql object.
|
||||||
STableMetaInfo* pPrevInfo = tscGetTableMetaInfoFromCmd(&pPrevSql->cmd, pPrevSql->cmd.clauseIndex, 0);
|
STableMetaInfo* pPrevInfo = tscGetTableMetaInfoFromCmd(&pPrevSql->cmd, pPrevSql->cmd.clauseIndex, 0);
|
||||||
|
if (pPrevInfo->pTableMeta && pPrevInfo->pTableMeta->tableType < 0) {
|
||||||
|
terrno = TSDB_CODE_TSC_APP_ERROR;
|
||||||
|
goto _error;
|
||||||
|
}
|
||||||
|
|
||||||
STableMeta* pPrevTableMeta = tscTableMetaDup(pPrevInfo->pTableMeta);
|
STableMeta* pPrevTableMeta = tscTableMetaDup(pPrevInfo->pTableMeta);
|
||||||
SVgroupsInfo* pVgroupsInfo = pPrevInfo->vgroupList;
|
SVgroupsInfo* pVgroupsInfo = pPrevInfo->vgroupList;
|
||||||
|
|
|
@ -31,7 +31,11 @@
|
||||||
#include "mnodeAcct.h"
|
#include "mnodeAcct.h"
|
||||||
#include "dnodeTelemetry.h"
|
#include "dnodeTelemetry.h"
|
||||||
|
|
||||||
static tsem_t tsExitSem;
|
// sem_timedwait is NOT implemented on MacOSX
|
||||||
|
// thus, we use pthread_mutex_t/pthread_cond_t to simulate
|
||||||
|
static pthread_mutex_t tsExitLock = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
static pthread_cond_t tsExitCond = PTHREAD_COND_INITIALIZER;
|
||||||
|
static volatile int tsExit = 0;
|
||||||
static pthread_t tsTelemetryThread;
|
static pthread_t tsTelemetryThread;
|
||||||
|
|
||||||
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
#define TELEMETRY_SERVER "telemetry.taosdata.com"
|
||||||
|
@ -236,24 +240,19 @@ static void sendTelemetryReport() {
|
||||||
taosCloseSocket(fd);
|
taosCloseSocket(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
|
||||||
static int sem_timedwait(tsem_t *sem, struct timespec *to) {
|
|
||||||
fprintf(stderr, "%s[%d]%s(): not implemented yet!\n", basename(__FILE__), __LINE__, __func__);
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
#endif // __APPLE__
|
|
||||||
|
|
||||||
static void* telemetryThread(void* param) {
|
static void* telemetryThread(void* param) {
|
||||||
struct timespec end = {0};
|
struct timespec end = {0};
|
||||||
clock_gettime(CLOCK_REALTIME, &end);
|
clock_gettime(CLOCK_REALTIME, &end);
|
||||||
end.tv_sec += 300; // wait 5 minutes before send first report
|
end.tv_sec += 300; // wait 5 minutes before send first report
|
||||||
|
|
||||||
while (1) {
|
while (!tsExit) {
|
||||||
if (sem_timedwait(&tsExitSem, &end) == 0) {
|
int r = 0;
|
||||||
break;
|
struct timespec ts = end;
|
||||||
} else if (errno != ETIMEDOUT) {
|
pthread_mutex_lock(&tsExitLock);
|
||||||
continue;
|
r = pthread_cond_timedwait(&tsExitCond, &tsExitLock, &ts);
|
||||||
}
|
pthread_mutex_unlock(&tsExitLock);
|
||||||
|
if (r==0) break;
|
||||||
|
if (r!=ETIMEDOUT) continue;
|
||||||
|
|
||||||
if (sdbIsMaster()) {
|
if (sdbIsMaster()) {
|
||||||
sendTelemetryReport();
|
sendTelemetryReport();
|
||||||
|
@ -284,12 +283,6 @@ int32_t dnodeInitTelemetry() {
|
||||||
|
|
||||||
dnodeGetEmail("/usr/local/taos/email");
|
dnodeGetEmail("/usr/local/taos/email");
|
||||||
|
|
||||||
if (tsem_init(&tsExitSem, 0, 0) == -1) {
|
|
||||||
// just log the error, it is ok for telemetry to fail
|
|
||||||
dTrace("failed to create semaphore for telemetry, reason:%s", strerror(errno));
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
pthread_attr_init(&attr);
|
pthread_attr_init(&attr);
|
||||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
|
||||||
|
@ -310,8 +303,11 @@ void dnodeCleanupTelemetry() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosCheckPthreadValid(tsTelemetryThread)) {
|
if (taosCheckPthreadValid(tsTelemetryThread)) {
|
||||||
tsem_post(&tsExitSem);
|
pthread_mutex_lock(&tsExitLock);
|
||||||
|
tsExit = 1;
|
||||||
|
pthread_cond_signal(&tsExitCond);
|
||||||
|
pthread_mutex_unlock(&tsExitLock);
|
||||||
|
|
||||||
pthread_join(tsTelemetryThread, NULL);
|
pthread_join(tsTelemetryThread, NULL);
|
||||||
tsem_destroy(&tsExitSem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,6 +258,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_QRY_HAS_RSP, 0, 0x0708, "Query shou
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_IN_EXEC, 0, 0x0709, "Multiple retrieval of this query")
|
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_IN_EXEC, 0, 0x0709, "Multiple retrieval of this query")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW, 0, 0x070A, "Too many time window in query")
|
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_TOO_MANY_TIMEWINDOW, 0, 0x070A, "Too many time window in query")
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NOT_ENOUGH_BUFFER, 0, 0x070B, "Query buffer limit has reached")
|
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_NOT_ENOUGH_BUFFER, 0, 0x070B, "Query buffer limit has reached")
|
||||||
|
TAOS_DEFINE_ERROR(TSDB_CODE_QRY_INCONSISTAN, 0, 0x070C, "File inconsistance in replica")
|
||||||
|
|
||||||
|
|
||||||
// grant
|
// grant
|
||||||
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 0x0800, "License expired")
|
TAOS_DEFINE_ERROR(TSDB_CODE_GRANT_EXPIRED, 0, 0x0800, "License expired")
|
||||||
|
|
|
@ -47,7 +47,7 @@ static struct argp_option options[] = {
|
||||||
{"thread", 'T', "THREADNUM", 0, "Number of threads when using multi-thread to import data."},
|
{"thread", 'T', "THREADNUM", 0, "Number of threads when using multi-thread to import data."},
|
||||||
{"database", 'd', "DATABASE", 0, "Database to use when connecting to the server."},
|
{"database", 'd', "DATABASE", 0, "Database to use when connecting to the server."},
|
||||||
{"timezone", 't', "TIMEZONE", 0, "Time zone of the shell, default is local."},
|
{"timezone", 't', "TIMEZONE", 0, "Time zone of the shell, default is local."},
|
||||||
{"netrole", 'n', "NETROLE", 0, "Net role when network connectivity test, default is startup, options: client|server|rpc|startup."},
|
{"netrole", 'n', "NETROLE", 0, "Net role when network connectivity test, default is startup, options: client|server|rpc|startup|sync."},
|
||||||
{"pktlen", 'l', "PKTLEN", 0, "Packet length used for net test, default is 1000 bytes."},
|
{"pktlen", 'l', "PKTLEN", 0, "Packet length used for net test, default is 1000 bytes."},
|
||||||
{0}};
|
{0}};
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ void printHelp() {
|
||||||
printf("%s%s\n", indent, "-t");
|
printf("%s%s\n", indent, "-t");
|
||||||
printf("%s%s%s\n", indent, indent, "Time zone of the shell, default is local.");
|
printf("%s%s%s\n", indent, indent, "Time zone of the shell, default is local.");
|
||||||
printf("%s%s\n", indent, "-n");
|
printf("%s%s\n", indent, "-n");
|
||||||
printf("%s%s%s\n", indent, indent, "Net role when network connectivity test, default is startup, options: client|server|rpc|startup.");
|
printf("%s%s%s\n", indent, indent, "Net role when network connectivity test, default is startup, options: client|server|rpc|startup|sync.");
|
||||||
printf("%s%s\n", indent, "-l");
|
printf("%s%s\n", indent, "-l");
|
||||||
printf("%s%s%s\n", indent, indent, "Packet length used for net test, default is 1000 bytes.");
|
printf("%s%s%s\n", indent, indent, "Packet length used for net test, default is 1000 bytes.");
|
||||||
printf("%s%s\n", indent, "-V");
|
printf("%s%s\n", indent, "-V");
|
||||||
|
|
|
@ -248,7 +248,7 @@ static void taosGetSystemLocale() { // get and set default locale
|
||||||
if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) {
|
if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) {
|
||||||
locale = setlocale(LC_CTYPE, "");
|
locale = setlocale(LC_CTYPE, "");
|
||||||
if (locale == NULL) {
|
if (locale == NULL) {
|
||||||
uError("can't get locale from system, set it to en_US.UTF-8");
|
uError("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno));
|
||||||
strcpy(tsLocale, "en_US.UTF-8");
|
strcpy(tsLocale, "en_US.UTF-8");
|
||||||
} else {
|
} else {
|
||||||
tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
|
tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
|
||||||
|
|
|
@ -1398,13 +1398,13 @@ static int32_t doTSJoinFilter(SQueryRuntimeEnv *pRuntimeEnv, int32_t offset) {
|
||||||
if (key < elem.ts) {
|
if (key < elem.ts) {
|
||||||
return TS_JOIN_TS_NOT_EQUALS;
|
return TS_JOIN_TS_NOT_EQUALS;
|
||||||
} else if (key > elem.ts) {
|
} else if (key > elem.ts) {
|
||||||
assert(false);
|
longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_INCONSISTAN);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (key > elem.ts) {
|
if (key > elem.ts) {
|
||||||
return TS_JOIN_TS_NOT_EQUALS;
|
return TS_JOIN_TS_NOT_EQUALS;
|
||||||
} else if (key < elem.ts) {
|
} else if (key < elem.ts) {
|
||||||
assert(false);
|
longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_INCONSISTAN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3828,6 +3828,11 @@ void scanOneTableDataBlocks(SQueryRuntimeEnv *pRuntimeEnv, TSKEY start) {
|
||||||
setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
|
setQueryStatus(pQuery, QUERY_NOT_COMPLETED);
|
||||||
pRuntimeEnv->scanFlag = REPEAT_SCAN;
|
pRuntimeEnv->scanFlag = REPEAT_SCAN;
|
||||||
|
|
||||||
|
if (pRuntimeEnv->pTsBuf) {
|
||||||
|
bool ret = tsBufNextPos(pRuntimeEnv->pTsBuf);
|
||||||
|
assert(ret);
|
||||||
|
}
|
||||||
|
|
||||||
qDebug("QInfo:%p start to repeat scan data blocks due to query func required, qrange:%"PRId64"-%"PRId64, pQInfo,
|
qDebug("QInfo:%p start to repeat scan data blocks due to query func required, qrange:%"PRId64"-%"PRId64, pQInfo,
|
||||||
cond.twindow.skey, cond.twindow.ekey);
|
cond.twindow.skey, cond.twindow.ekey);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,8 @@ typedef enum {
|
||||||
TAOS_SMSG_SETUP_RSP = 12,
|
TAOS_SMSG_SETUP_RSP = 12,
|
||||||
TAOS_SMSG_SYNC_FILE = 13,
|
TAOS_SMSG_SYNC_FILE = 13,
|
||||||
TAOS_SMSG_SYNC_FILE_RSP = 14,
|
TAOS_SMSG_SYNC_FILE_RSP = 14,
|
||||||
TAOS_SMSG_END = 15,
|
TAOS_SMSG_TEST = 15,
|
||||||
|
TAOS_SMSG_END = 16
|
||||||
} ESyncMsgType;
|
} ESyncMsgType;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
@ -128,6 +129,7 @@ void syncBuildSyncReqMsg(SSyncMsg *pMsg, int32_t vgId);
|
||||||
void syncBuildSyncDataMsg(SSyncMsg *pMsg, int32_t vgId);
|
void syncBuildSyncDataMsg(SSyncMsg *pMsg, int32_t vgId);
|
||||||
void syncBuildSyncSetupMsg(SSyncMsg *pMsg, int32_t vgId);
|
void syncBuildSyncSetupMsg(SSyncMsg *pMsg, int32_t vgId);
|
||||||
void syncBuildPeersStatus(SPeersStatus *pMsg, int32_t vgId);
|
void syncBuildPeersStatus(SPeersStatus *pMsg, int32_t vgId);
|
||||||
|
void syncBuildSyncTestMsg(SSyncMsg *pMsg, int32_t vgId);
|
||||||
|
|
||||||
void syncBuildFileAck(SFileAck *pMsg, int32_t vgId);
|
void syncBuildFileAck(SFileAck *pMsg, int32_t vgId);
|
||||||
void syncBuildFileVersion(SFileVersion *pMsg, int32_t vgId);
|
void syncBuildFileVersion(SFileVersion *pMsg, int32_t vgId);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
#include "syncTcp.h"
|
#include "syncTcp.h"
|
||||||
|
|
||||||
|
extern void syncProcessTestMsg(SSyncMsg *pMsg, SOCKET connFd);
|
||||||
static void arbSignalHandler(int32_t signum, void *sigInfo, void *context);
|
static void arbSignalHandler(int32_t signum, void *sigInfo, void *context);
|
||||||
static void arbProcessIncommingConnection(SOCKET connFd, uint32_t sourceIp);
|
static void arbProcessIncommingConnection(SOCKET connFd, uint32_t sourceIp);
|
||||||
static void arbProcessBrokenLink(int64_t rid);
|
static void arbProcessBrokenLink(int64_t rid);
|
||||||
|
@ -118,6 +119,11 @@ static void arbProcessIncommingConnection(SOCKET connFd, uint32_t sourceIp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (msg.head.type == TAOS_SMSG_TEST) {
|
||||||
|
syncProcessTestMsg(&msg, connFd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SNodeConn *pNode = calloc(sizeof(SNodeConn), 1);
|
SNodeConn *pNode = calloc(sizeof(SNodeConn), 1);
|
||||||
if (pNode == NULL) {
|
if (pNode == NULL) {
|
||||||
sError("failed to allocate memory since %s", strerror(errno));
|
sError("failed to allocate memory since %s", strerror(errno));
|
||||||
|
|
|
@ -1182,6 +1182,20 @@ static void syncCreateRestoreDataThread(SSyncPeer *pPeer) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void syncProcessTestMsg(SSyncMsg *pMsg, SOCKET connFd) {
|
||||||
|
sInfo("recv sync test msg");
|
||||||
|
|
||||||
|
SSyncMsg rsp;
|
||||||
|
syncBuildSyncTestMsg(&rsp, -1);
|
||||||
|
if (taosWriteMsg(connFd, &rsp, sizeof(SSyncMsg)) != sizeof(SSyncMsg)) {
|
||||||
|
sInfo("failed to send sync test rsp since %s", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
sInfo("send sync test rsp");
|
||||||
|
taosMsleep(1000);
|
||||||
|
taosCloseSocket(connFd);
|
||||||
|
}
|
||||||
|
|
||||||
static void syncProcessIncommingConnection(SOCKET connFd, uint32_t sourceIp) {
|
static void syncProcessIncommingConnection(SOCKET connFd, uint32_t sourceIp) {
|
||||||
char ipstr[24];
|
char ipstr[24];
|
||||||
int32_t i;
|
int32_t i;
|
||||||
|
@ -1203,6 +1217,11 @@ static void syncProcessIncommingConnection(SOCKET connFd, uint32_t sourceIp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (msg.head.type == TAOS_SMSG_TEST) {
|
||||||
|
syncProcessTestMsg(&msg, connFd);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t vgId = msg.head.vgId;
|
int32_t vgId = msg.head.vgId;
|
||||||
SSyncNode **ppNode = taosHashGet(tsVgIdHash, &vgId, sizeof(int32_t));
|
SSyncNode **ppNode = taosHashGet(tsVgIdHash, &vgId, sizeof(int32_t));
|
||||||
if (ppNode == NULL || *ppNode == NULL) {
|
if (ppNode == NULL || *ppNode == NULL) {
|
||||||
|
|
|
@ -86,6 +86,7 @@ static void syncBuildMsg(SSyncMsg *pMsg, int32_t vgId, ESyncMsgType type) {
|
||||||
void syncBuildSyncReqMsg(SSyncMsg *pMsg, int32_t vgId) { syncBuildMsg(pMsg, vgId, TAOS_SMSG_SYNC_REQ); }
|
void syncBuildSyncReqMsg(SSyncMsg *pMsg, int32_t vgId) { syncBuildMsg(pMsg, vgId, TAOS_SMSG_SYNC_REQ); }
|
||||||
void syncBuildSyncDataMsg(SSyncMsg *pMsg, int32_t vgId) { syncBuildMsg(pMsg, vgId, TAOS_SMSG_SYNC_DATA); }
|
void syncBuildSyncDataMsg(SSyncMsg *pMsg, int32_t vgId) { syncBuildMsg(pMsg, vgId, TAOS_SMSG_SYNC_DATA); }
|
||||||
void syncBuildSyncSetupMsg(SSyncMsg *pMsg, int32_t vgId) { syncBuildMsg(pMsg, vgId, TAOS_SMSG_SETUP); }
|
void syncBuildSyncSetupMsg(SSyncMsg *pMsg, int32_t vgId) { syncBuildMsg(pMsg, vgId, TAOS_SMSG_SETUP); }
|
||||||
|
void syncBuildSyncTestMsg(SSyncMsg *pMsg, int32_t vgId) { syncBuildMsg(pMsg, vgId, TAOS_SMSG_TEST); }
|
||||||
|
|
||||||
void syncBuildPeersStatus(SPeersStatus *pMsg, int32_t vgId) {
|
void syncBuildPeersStatus(SPeersStatus *pMsg, int32_t vgId) {
|
||||||
pMsg->head.type = TAOS_SMSG_STATUS;
|
pMsg->head.type = TAOS_SMSG_STATUS;
|
||||||
|
|
|
@ -2,6 +2,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
|
||||||
PROJECT(TDengine)
|
PROJECT(TDengine)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc)
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/rpc/inc)
|
||||||
|
INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/sync/inc)
|
||||||
AUX_SOURCE_DIRECTORY(src SRC)
|
AUX_SOURCE_DIRECTORY(src SRC)
|
||||||
ADD_LIBRARY(tutil ${SRC})
|
ADD_LIBRARY(tutil ${SRC})
|
||||||
TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4 z)
|
TARGET_LINK_LIBRARIES(tutil pthread osdetail lz4 z)
|
||||||
|
|
|
@ -23,6 +23,8 @@
|
||||||
#include "tsocket.h"
|
#include "tsocket.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "rpcHead.h"
|
#include "rpcHead.h"
|
||||||
|
#include "tchecksum.h"
|
||||||
|
#include "syncMsg.h"
|
||||||
|
|
||||||
#define MAX_PKG_LEN (64 * 1000)
|
#define MAX_PKG_LEN (64 * 1000)
|
||||||
#define BUFFER_SIZE (MAX_PKG_LEN + 1024)
|
#define BUFFER_SIZE (MAX_PKG_LEN + 1024)
|
||||||
|
@ -408,13 +410,51 @@ static void taosNetTestStartup(char *host, int32_t port) {
|
||||||
free(pStep);
|
free(pStep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void taosNetCheckSync(char *host, int32_t port) {
|
||||||
|
uint32_t ip = taosGetIpv4FromFqdn(host);
|
||||||
|
if (ip == 0xffffffff) {
|
||||||
|
uError("failed to get IP address from %s since %s", host, strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SOCKET connFd = taosOpenTcpClientSocket(ip, (uint16_t)port, 0);
|
||||||
|
if (connFd < 0) {
|
||||||
|
uError("failed to create socket while test port:%d since %s", port, strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSyncMsg msg;
|
||||||
|
memset(&msg, 0, sizeof(SSyncMsg));
|
||||||
|
SSyncHead *pHead = &msg.head;
|
||||||
|
pHead->type = TAOS_SMSG_TEST;
|
||||||
|
pHead->protocol = SYNC_PROTOCOL_VERSION;
|
||||||
|
pHead->signature = SYNC_SIGNATURE;
|
||||||
|
pHead->code = 0;
|
||||||
|
pHead->cId = 0;
|
||||||
|
pHead->vgId = -1;
|
||||||
|
pHead->len = sizeof(SSyncMsg) - sizeof(SSyncHead);
|
||||||
|
taosCalcChecksumAppend(0, (uint8_t *)pHead, sizeof(SSyncHead));
|
||||||
|
|
||||||
|
if (taosWriteMsg(connFd, &msg, sizeof(SSyncMsg)) != sizeof(SSyncMsg)) {
|
||||||
|
uError("failed to test port:%d while send msg since %s", port, strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosReadMsg(connFd, &msg, sizeof(SSyncMsg)) != sizeof(SSyncMsg)) {
|
||||||
|
uError("failed to test port:%d while recv msg since %s", port, strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
uInfo("successed to test TCP port:%d", port);
|
||||||
|
taosCloseSocket(connFd);
|
||||||
|
}
|
||||||
|
|
||||||
static void taosNetTestRpc(char *host, int32_t startPort, int32_t pkgLen) {
|
static void taosNetTestRpc(char *host, int32_t startPort, int32_t pkgLen) {
|
||||||
int32_t endPort = startPort + 9;
|
int32_t endPort = startPort + TSDB_PORT_SYNC;
|
||||||
char spi = 0;
|
char spi = 0;
|
||||||
|
|
||||||
uInfo("check rpc, host:%s startPort:%d endPort:%d pkgLen:%d\n", host, startPort, endPort, pkgLen);
|
uInfo("check rpc, host:%s startPort:%d endPort:%d pkgLen:%d\n", host, startPort, endPort, pkgLen);
|
||||||
|
|
||||||
for (uint16_t port = startPort; port <= endPort; port++) {
|
for (uint16_t port = startPort; port < endPort; port++) {
|
||||||
int32_t sendpkgLen;
|
int32_t sendpkgLen;
|
||||||
if (pkgLen <= tsRpcMaxUdpSize) {
|
if (pkgLen <= tsRpcMaxUdpSize) {
|
||||||
sendpkgLen = tsRpcMaxUdpSize + 1000;
|
sendpkgLen = tsRpcMaxUdpSize + 1000;
|
||||||
|
@ -442,6 +482,9 @@ static void taosNetTestRpc(char *host, int32_t startPort, int32_t pkgLen) {
|
||||||
uInfo("successed to test UDP port:%d", port);
|
uInfo("successed to test UDP port:%d", port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
taosNetCheckSync(host, startPort + TSDB_PORT_SYNC);
|
||||||
|
taosNetCheckSync(host, startPort + TSDB_PORT_ARBITRATOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void taosNetTestClient(char *host, int32_t startPort, int32_t pkgLen) {
|
static void taosNetTestClient(char *host, int32_t startPort, int32_t pkgLen) {
|
||||||
|
@ -508,6 +551,8 @@ void taosNetTest(char *role, char *host, int32_t port, int32_t pkgLen) {
|
||||||
taosNetTestServer(host, port, pkgLen);
|
taosNetTestServer(host, port, pkgLen);
|
||||||
} else if (0 == strcmp("rpc", role)) {
|
} else if (0 == strcmp("rpc", role)) {
|
||||||
taosNetTestRpc(host, port, pkgLen);
|
taosNetTestRpc(host, port, pkgLen);
|
||||||
|
} else if (0 == strcmp("sync", role)) {
|
||||||
|
taosNetCheckSync(host, port);
|
||||||
} else if (0 == strcmp("startup", role)) {
|
} else if (0 == strcmp("startup", role)) {
|
||||||
taosNetTestStartup(host, port);
|
taosNetTestStartup(host, port);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -9,6 +9,14 @@
|
||||||
<version>SNAPSHOT</version>
|
<version>SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
|
<version>2.0.18</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -48,12 +56,4 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
|
||||||
<version>2.0.15</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -11,12 +11,12 @@ Download the tdengine package on our website: ``https://www.taosdata.com/cn/all-
|
||||||
## Run jdbcDemo using mvn plugin
|
## Run jdbcDemo using mvn plugin
|
||||||
run command:
|
run command:
|
||||||
```
|
```
|
||||||
mvn clean compile exec:java -Dexec.mainClass="com.taosdata.example.JdbcDemo"
|
mvn clean compile exec:java -Dexec.mainClass="com.taosdata.example.JDBCDemo"
|
||||||
```
|
```
|
||||||
|
|
||||||
and run with your customed args
|
and run with your customed args
|
||||||
```
|
```
|
||||||
mvn clean compile exec:java -Dexec.mainClass="com.taosdata.example.JdbcDemo" -Dexec.args="-host [HOSTNAME]"
|
mvn clean compile exec:java -Dexec.mainClass="com.taosdata.example.JDBCDemo" -Dexec.args="-host [HOSTNAME]"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Compile the Demo Code and Run It
|
## Compile the Demo Code and Run It
|
||||||
|
|
|
@ -5,7 +5,6 @@ import java.util.Properties;
|
||||||
|
|
||||||
public class JDBCDemo {
|
public class JDBCDemo {
|
||||||
private static String host;
|
private static String host;
|
||||||
private static String driverType = "jni";
|
|
||||||
private static final String dbName = "test";
|
private static final String dbName = "test";
|
||||||
private static final String tbName = "weather";
|
private static final String tbName = "weather";
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
|
@ -14,17 +13,10 @@ public class JDBCDemo {
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1)
|
if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1)
|
||||||
host = args[++i];
|
host = args[++i];
|
||||||
if ("-driverType".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
|
||||||
driverType = args[++i];
|
|
||||||
if (!"jni".equalsIgnoreCase(driverType) && !"restful".equalsIgnoreCase(driverType))
|
|
||||||
printHelp();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
printHelp();
|
printHelp();
|
||||||
}
|
}
|
||||||
|
|
||||||
JDBCDemo demo = new JDBCDemo();
|
JDBCDemo demo = new JDBCDemo();
|
||||||
demo.init();
|
demo.init();
|
||||||
demo.createDatabase();
|
demo.createDatabase();
|
||||||
|
@ -38,15 +30,10 @@ public class JDBCDemo {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
final String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
|
||||||
// get connection
|
// get connection
|
||||||
try {
|
try {
|
||||||
String url = "jdbc:TAOS://" + host + ":6030/?user=root&password=taosdata";
|
|
||||||
if (driverType.equals("restful")) {
|
|
||||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
|
||||||
url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
|
||||||
} else {
|
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
}
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
properties.setProperty("charset", "UTF-8");
|
properties.setProperty("charset", "UTF-8");
|
||||||
properties.setProperty("locale", "en_US.UTF-8");
|
properties.setProperty("locale", "en_US.UTF-8");
|
||||||
|
@ -70,11 +57,39 @@ public class JDBCDemo {
|
||||||
exuete(sql);
|
exuete(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void dropTable() {
|
||||||
|
final String sql = "drop table if exists " + dbName + "." + tbName + "";
|
||||||
|
exuete(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createTable() {
|
||||||
|
final String sql = "create table if not exists " + dbName + "." + tbName + " (ts timestamp, temperature float, humidity int)";
|
||||||
|
exuete(sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void insert() {
|
||||||
|
final String sql = "insert into test.weather (ts, temperature, humidity) values(now, 20.5, 34)";
|
||||||
|
exuete(sql);
|
||||||
|
}
|
||||||
|
|
||||||
private void select() {
|
private void select() {
|
||||||
final String sql = "select * from test.weather";
|
final String sql = "select * from test.weather";
|
||||||
executeQuery(sql);
|
executeQuery(sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void close() {
|
||||||
|
try {
|
||||||
|
if (connection != null) {
|
||||||
|
this.connection.close();
|
||||||
|
System.out.println("connection closed.");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/************************************************************************/
|
||||||
|
|
||||||
private void executeQuery(String sql) {
|
private void executeQuery(String sql) {
|
||||||
try (Statement statement = connection.createStatement()) {
|
try (Statement statement = connection.createStatement()) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
@ -99,15 +114,6 @@ public class JDBCDemo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insert() {
|
|
||||||
final String sql = "insert into test.weather (ts, temperature, humidity) values(now, 20.5, 34)";
|
|
||||||
exuete(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createTable() {
|
|
||||||
final String sql = "create table if not exists " + dbName + "." + tbName + " (ts timestamp, temperature float, humidity int)";
|
|
||||||
exuete(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void printSql(String sql, boolean succeed, long cost) {
|
private void printSql(String sql, boolean succeed, long cost) {
|
||||||
System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql);
|
System.out.println("[ " + (succeed ? "OK" : "ERROR!") + " ] time cost: " + cost + " ms, execute statement ====> " + sql);
|
||||||
|
@ -125,24 +131,8 @@ public class JDBCDemo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void close() {
|
|
||||||
try {
|
|
||||||
if (connection != null) {
|
|
||||||
this.connection.close();
|
|
||||||
System.out.println("connection closed.");
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void dropTable() {
|
|
||||||
final String sql = "drop table if exists " + dbName + "." + tbName + "";
|
|
||||||
exuete(sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void printHelp() {
|
private static void printHelp() {
|
||||||
System.out.println("Usage: java -jar JdbcDemo.jar -host <hostname> -driverType <jni|restful>");
|
System.out.println("Usage: java -jar JDBCDemo.jar -host <hostname>");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,9 @@ public class JdbcRestfulDemo {
|
||||||
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
|
||||||
|
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
// properties.setProperty("charset", "UTF-8");
|
properties.setProperty("charset", "UTF-8");
|
||||||
// properties.setProperty("locale", "en_US.UTF-8");
|
properties.setProperty("locale", "en_US.UTF-8");
|
||||||
// properties.setProperty("timezone", "UTC-8");
|
properties.setProperty("timezone", "UTC-8");
|
||||||
|
|
||||||
Connection conn = DriverManager.getConnection(url, properties);
|
Connection conn = DriverManager.getConnection(url, properties);
|
||||||
Statement stmt = conn.createStatement();
|
Statement stmt = conn.createStatement();
|
||||||
|
|
|
@ -6,75 +6,70 @@ import com.taosdata.jdbc.TSDBResultSet;
|
||||||
import com.taosdata.jdbc.TSDBSubscribe;
|
import com.taosdata.jdbc.TSDBSubscribe;
|
||||||
|
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.ResultSetMetaData;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class SubscribeDemo {
|
public class SubscribeDemo {
|
||||||
|
private static final String usage = "java -jar SubscribeDemo.jar -host <hostname> -database <database name> -topic <topic> -sql <sql>";
|
||||||
|
|
||||||
public static TSDBConnection getConnection(String host, String database) throws Exception {
|
public static void main(String[] args) {
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
// parse args from command line
|
||||||
Properties properties = new Properties();
|
String host = "", database = "", topic = "", sql = "";
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_HOST, host);
|
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
|
||||||
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
|
||||||
|
|
||||||
String cs = String.format("jdbc:TAOS://%s:0/%s", host, database);
|
|
||||||
return (TSDBConnection) DriverManager.getConnection(cs, properties);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
String usage = "java -Djava.ext.dirs=../ TestTSDBSubscribe [-host host] <-db database> <-topic topic> <-sql sql>";
|
|
||||||
if (args.length < 2) {
|
|
||||||
System.err.println(usage);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String host = "localhost", database = "", topic = "", sql = "";
|
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
if ("-db".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
||||||
|
host = args[++i];
|
||||||
|
}
|
||||||
|
if ("-database".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
||||||
database = args[++i];
|
database = args[++i];
|
||||||
}
|
}
|
||||||
if ("-topic".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
if ("-topic".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
||||||
topic = args[++i];
|
topic = args[++i];
|
||||||
}
|
}
|
||||||
if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
|
||||||
host = args[++i];
|
|
||||||
}
|
|
||||||
if ("-sql".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
if ("-sql".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
||||||
sql = args[++i];
|
sql = args[++i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (database.isEmpty() || topic.isEmpty() || sql.isEmpty()) {
|
if (host.isEmpty() || database.isEmpty() || topic.isEmpty() || sql.isEmpty()) {
|
||||||
System.err.println(usage);
|
System.out.println(usage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
/*********************************************************************************************/
|
||||||
TSDBConnection connection = null;
|
|
||||||
TSDBSubscribe sub = null;
|
|
||||||
try {
|
try {
|
||||||
connection = getConnection(host, database);
|
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
||||||
sub = ((TSDBConnection) connection).subscribe(topic, sql, false);
|
Properties properties = new Properties();
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
|
||||||
|
properties.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
|
||||||
|
final String url = "jdbc:TAOS://" + host + ":6030/" + database + "?user=root&password=taosdata";
|
||||||
|
// get TSDBConnection
|
||||||
|
TSDBConnection connection = (TSDBConnection) DriverManager.getConnection(url, properties);
|
||||||
|
// create TSDBSubscribe
|
||||||
|
TSDBSubscribe sub = connection.subscribe(topic, sql, false);
|
||||||
|
|
||||||
int total = 0;
|
int total = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
TSDBResultSet rs = sub.consume();
|
TSDBResultSet rs = sub.consume();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
ResultSetMetaData meta = rs.getMetaData();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
|
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||||
|
System.out.print(meta.getColumnLabel(i) + ": " + rs.getString(i) + "\t");
|
||||||
|
}
|
||||||
|
System.out.println();
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
total += count;
|
total += count;
|
||||||
System.out.printf("%d rows consumed, total %d\n", count, total);
|
// System.out.printf("%d rows consumed, total %d\n", count, total);
|
||||||
Thread.sleep(900);
|
if (total >= 10)
|
||||||
|
break;
|
||||||
|
TimeUnit.SECONDS.sleep(1);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
sub.close(false);
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (null != sub) {
|
|
||||||
sub.close(true);
|
|
||||||
}
|
|
||||||
if (null != connection) {
|
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
} catch (Exception e) {
|
||||||
|
System.out.println("host: " + host + ", database: " + database + ", topic: " + topic + ", sql: " + sql);
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,53 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
|
|
||||||
<groupId>com.taosdata.example.calcite</groupId>
|
|
||||||
<artifactId>calciteDemo</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- slf4j -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-simple</artifactId>
|
|
||||||
<version>1.7.25</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<!-- calcite -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.calcite</groupId>
|
|
||||||
<artifactId>calcite-core</artifactId>
|
|
||||||
<version>1.23.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-dbcp2</artifactId>
|
|
||||||
<version>2.7.0</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.calcite.avatica</groupId>
|
|
||||||
<artifactId>avatica-core</artifactId>
|
|
||||||
<version>1.17.0</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- mysql -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
<version>5.1.47</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- tdengine -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
|
||||||
<version>2.0.8</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
|
|
||||||
</project>
|
|
|
@ -1,67 +0,0 @@
|
||||||
package com.taosdata.example.calcite;
|
|
||||||
|
|
||||||
import org.apache.calcite.adapter.jdbc.JdbcSchema;
|
|
||||||
import org.apache.calcite.jdbc.CalciteConnection;
|
|
||||||
import org.apache.calcite.schema.Schema;
|
|
||||||
import org.apache.calcite.schema.SchemaPlus;
|
|
||||||
import org.apache.calcite.sql.parser.SqlParseException;
|
|
||||||
import org.apache.commons.dbcp2.BasicDataSource;
|
|
||||||
|
|
||||||
import java.sql.*;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class CalciteDemo {
|
|
||||||
|
|
||||||
private static String url_taos = "jdbc:TAOS://192.168.236.135:6030/test";
|
|
||||||
private static String url_mysql = "jdbc:mysql://master:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8";
|
|
||||||
|
|
||||||
public static void main(String[] args) throws SqlParseException, ClassNotFoundException, SQLException {
|
|
||||||
Class.forName("org.apache.calcite.jdbc.Driver");
|
|
||||||
Properties info = new Properties();
|
|
||||||
info.setProperty("caseSensitive", "false");
|
|
||||||
|
|
||||||
Connection connection = DriverManager.getConnection("jdbc:calcite:", info);
|
|
||||||
CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class);
|
|
||||||
|
|
||||||
SchemaPlus rootSchema = calciteConnection.getRootSchema();
|
|
||||||
|
|
||||||
//这里hdb是在tdengine中创建的数据库名
|
|
||||||
Schema schema = mysqlTest(rootSchema);
|
|
||||||
// Schema schema = tdengineTest(rootSchema);
|
|
||||||
|
|
||||||
//创建新的schema自动映射到原来的hdb数据库
|
|
||||||
rootSchema.add("test", schema);
|
|
||||||
|
|
||||||
Statement stmt = calciteConnection.createStatement();
|
|
||||||
//查询schema test中的表,表名是tdengine中的表
|
|
||||||
ResultSet rs = stmt.executeQuery("select * from test.t");
|
|
||||||
ResultSetMetaData metaData = rs.getMetaData();
|
|
||||||
while (rs.next()) {
|
|
||||||
for (int i = 1; i <= metaData.getColumnCount(); i++) {
|
|
||||||
System.out.println(metaData.getColumnLabel(i) + " : " + rs.getString(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private static Schema tdengineTest(SchemaPlus rootSchema) throws ClassNotFoundException {
|
|
||||||
Class.forName("com.taosdata.jdbc.TSDBDriver");
|
|
||||||
BasicDataSource dataSource = new BasicDataSource();
|
|
||||||
dataSource.setUrl(url_taos);
|
|
||||||
dataSource.setUsername("root");
|
|
||||||
dataSource.setPassword("taosdata");
|
|
||||||
|
|
||||||
return JdbcSchema.create(rootSchema, "test", dataSource, "hdb", null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Schema mysqlTest(SchemaPlus rootSchema) throws ClassNotFoundException {
|
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
|
||||||
BasicDataSource dataSource = new BasicDataSource();
|
|
||||||
dataSource.setUrl(url_mysql);
|
|
||||||
dataSource.setUsername("root");
|
|
||||||
dataSource.setPassword("123456");
|
|
||||||
|
|
||||||
//Schema schema = JdbcSchema.create(rootSchema, "test", dataSource, "hdb", null);
|
|
||||||
return JdbcSchema.create(rootSchema, "test", dataSource, "test", null);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
log4j.rootLogger=info,stdout
|
|
||||||
|
|
||||||
#console
|
|
||||||
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
|
||||||
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
|
||||||
log4j.appender.stdout.layout.ConversionPattern= [%d{yyyy-MM-dd HH:mm:ss a}]:%p %l%m%n
|
|
|
@ -1,23 +1,25 @@
|
||||||
这个example中,我们适配了java常见的连接池:
|
这个example中,我们适配了java常见的连接池:
|
||||||
* c3p0
|
* HikariCP(默认)
|
||||||
* dbcp
|
|
||||||
* druid
|
* druid
|
||||||
* HikariCP
|
* dbcp
|
||||||
|
* c3p0
|
||||||
|
|
||||||
### 说明
|
### 说明
|
||||||
ConnectionPoolDemo的程序逻辑:
|
ConnectionPoolDemo的程序逻辑:
|
||||||
1. 创建到host的connection连接池
|
1. 创建到host的connection连接池
|
||||||
2. 创建名称为pool_test的database,创建表超级weather,创建tableSize个子表
|
2. 创建名称为pool_test的database,创建表超级weather,创建tableSize个子表
|
||||||
3. 不断向所有子表进行插入。
|
3. 总共插入totalNumber条数据。
|
||||||
|
|
||||||
### 如何运行这个例子:
|
### 如何运行这个例子:
|
||||||
|
|
||||||
```shell script
|
```shell script
|
||||||
# mvn exec:java -Dexec.mainClass="com.taosdata.demo.ConnectionPoolDemo" -Dexec.args="-host localhost"
|
mvn clean package assembly:single
|
||||||
|
java -jar target/connectionPools-1.0-SNAPSHOT-jar-with-dependencies.jar -host 127.0.0.1
|
||||||
```
|
```
|
||||||
使用mvn运行ConnectionPoolDemo的main方法,可以指定参数
|
使用mvn运行ConnectionPoolDemo的main方法,可以指定参数
|
||||||
```shell script
|
```shell script
|
||||||
Usage:
|
Usage:
|
||||||
mvn exec:java -Dexec.mainClass="com.taosdata.demo.ConnectionPoolDemo" -Dexec.args="<args>"
|
java -jar target/connectionPools-1.0-SNAPSHOT-jar-with-dependencies.jar
|
||||||
-host : hostname
|
-host : hostname
|
||||||
-poolType <c3p0| dbcp| druid| hikari>
|
-poolType <c3p0| dbcp| druid| hikari>
|
||||||
-poolSize <poolSize>
|
-poolSize <poolSize>
|
||||||
|
@ -26,8 +28,5 @@ mvn exec:java -Dexec.mainClass="com.taosdata.demo.ConnectionPoolDemo" -Dexec.arg
|
||||||
-sleep : 每次插入任务提交后的
|
-sleep : 每次插入任务提交后的
|
||||||
```
|
```
|
||||||
|
|
||||||
### 如何停止程序:
|
|
||||||
ConnectionPoolDemo不会自己停止,会一直执行插入,需要手动Ctrl+C运行。
|
|
||||||
|
|
||||||
### 日志
|
### 日志
|
||||||
使用log4j,将日志和错误分别输出到了debug.log和error.log中
|
使用log4j,将日志和错误分别输出到了debug.log和error.log中
|
|
@ -12,7 +12,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.17</version>
|
<version>2.0.18</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- druid -->
|
<!-- druid -->
|
||||||
|
@ -50,6 +50,35 @@
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>1.2.17</version>
|
<version>1.2.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.taosdata.example.ConnectionPoolDemo</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -1,77 +0,0 @@
|
||||||
package com.taosdata.demo.common;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class InsertTask implements Runnable {
|
|
||||||
private final Random random = new Random(System.currentTimeMillis());
|
|
||||||
private static final Logger logger = Logger.getLogger(InsertTask.class);
|
|
||||||
|
|
||||||
private final DataSource ds;
|
|
||||||
private final int batchSize;
|
|
||||||
private final String dbName;
|
|
||||||
private final int tableSize;
|
|
||||||
|
|
||||||
public InsertTask(DataSource ds, String dbName, int tableSize, int batchSize) {
|
|
||||||
this.ds = ds;
|
|
||||||
this.dbName = dbName;
|
|
||||||
this.tableSize = tableSize;
|
|
||||||
this.batchSize = batchSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Connection conn = null;
|
|
||||||
Statement stmt = null;
|
|
||||||
int affectedRows = 0;
|
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
try {
|
|
||||||
conn = ds.getConnection();
|
|
||||||
stmt = conn.createStatement();
|
|
||||||
|
|
||||||
for (int tb_index = 1; tb_index <= tableSize; tb_index++) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append("insert into ");
|
|
||||||
sb.append(dbName);
|
|
||||||
sb.append(".t_");
|
|
||||||
sb.append(tb_index);
|
|
||||||
sb.append("(ts, temperature, humidity) values ");
|
|
||||||
for (int i = 0; i < batchSize; i++) {
|
|
||||||
sb.append("(");
|
|
||||||
sb.append(start + i);
|
|
||||||
sb.append(", ");
|
|
||||||
sb.append(random.nextFloat() * 30);
|
|
||||||
sb.append(", ");
|
|
||||||
sb.append(random.nextInt(70));
|
|
||||||
sb.append(") ");
|
|
||||||
}
|
|
||||||
logger.info("SQL >>> " + sb.toString());
|
|
||||||
affectedRows += stmt.executeUpdate(sb.toString());
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (stmt != null) {
|
|
||||||
try {
|
|
||||||
stmt.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (conn != null) {
|
|
||||||
try {
|
|
||||||
conn.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
logger.info(">>> affectedRows:" + affectedRows + " TimeCost:" + (System.currentTimeMillis() - start) + " ms");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,10 @@
|
||||||
package com.taosdata.demo;
|
package com.taosdata.example;
|
||||||
|
|
||||||
import com.taosdata.demo.common.InsertTask;
|
import com.taosdata.example.common.InsertTask;
|
||||||
import com.taosdata.demo.pool.C3p0Builder;
|
import com.taosdata.example.pool.C3p0Builder;
|
||||||
import com.taosdata.demo.pool.DbcpBuilder;
|
import com.taosdata.example.pool.DbcpBuilder;
|
||||||
import com.taosdata.demo.pool.DruidPoolBuilder;
|
import com.taosdata.example.pool.DruidPoolBuilder;
|
||||||
import com.taosdata.demo.pool.HikariCpBuilder;
|
import com.taosdata.example.pool.HikariCpBuilder;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
@ -20,44 +20,43 @@ public class ConnectionPoolDemo {
|
||||||
private static Logger logger = Logger.getLogger(DruidPoolBuilder.class);
|
private static Logger logger = Logger.getLogger(DruidPoolBuilder.class);
|
||||||
private static final String dbName = "pool_test";
|
private static final String dbName = "pool_test";
|
||||||
|
|
||||||
private static int batchSize = 10;
|
|
||||||
private static int sleep = 1000;
|
|
||||||
private static int poolSize = 50;
|
|
||||||
private static int tableSize = 1000;
|
|
||||||
private static int threadCount = 50;
|
|
||||||
private static String poolType = "hikari";
|
private static String poolType = "hikari";
|
||||||
|
private static long totalSize = 1_000_000l;
|
||||||
|
private static long tableSize = 1;
|
||||||
|
private static long batchSize = 1;
|
||||||
|
|
||||||
|
private static int poolSize = 50;
|
||||||
|
private static int threadCount = 50;
|
||||||
|
private static int sleep = 0;
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) {
|
||||||
String host = null;
|
String host = null;
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
if ("-host".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
||||||
host = args[++i];
|
host = args[++i];
|
||||||
}
|
}
|
||||||
if ("-batchSize".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
|
||||||
batchSize = Integer.parseInt(args[++i]);
|
|
||||||
}
|
|
||||||
if ("-sleep".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
|
||||||
sleep = Integer.parseInt(args[++i]);
|
|
||||||
}
|
|
||||||
if ("-poolSize".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
|
||||||
poolSize = Integer.parseInt(args[++i]);
|
|
||||||
}
|
|
||||||
if ("-tableSize".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
|
||||||
tableSize = Integer.parseInt(args[++i]);
|
|
||||||
}
|
|
||||||
if ("-poolType".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
if ("-poolType".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
||||||
poolType = args[++i];
|
poolType = args[++i];
|
||||||
}
|
}
|
||||||
|
if ("-recordNumber".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
||||||
|
totalSize = Long.parseLong(args[++i]);
|
||||||
|
}
|
||||||
|
if ("-tableNumber".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
||||||
|
tableSize = Long.parseLong(args[++i]);
|
||||||
|
}
|
||||||
|
if ("-batchNumber".equalsIgnoreCase(args[i]) && i < args.length - 1) {
|
||||||
|
batchSize = Long.parseLong(args[++i]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
System.out.println("Usage: java -jar XXX.jar " +
|
System.out.println("Usage: java -jar XXX.jar -host <hostname> " +
|
||||||
"-host <hostname> " +
|
"-poolType <c3p0| dbcp| druid| hikari>" +
|
||||||
"-batchSize <batchSize> " +
|
"-recordNumber <number> " +
|
||||||
"-sleep <sleep> " +
|
"-tableNumber <number> " +
|
||||||
"-poolSize <poolSize> " +
|
"-batchNumber <number> " +
|
||||||
"-tableSize <tableSize>" +
|
"-sleep <number> "
|
||||||
"-poolType <c3p0| dbcp| druid| hikari>");
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,30 +78,35 @@ public class ConnectionPoolDemo {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(">>>>>>>>>>>>>> connection pool Type: " + poolType);
|
logger.info(">>>>>>>>>>>>>> connection pool Type: " + poolType);
|
||||||
|
|
||||||
init(dataSource);
|
init(dataSource);
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// Connection connection = dataSource.getConnection();
|
||||||
|
// Statement statement = connection.createStatement();
|
||||||
|
// String sql = "insert into " + dbName + ".t_1 values('2020-01-01 00:00:00.000',12.12,111)";
|
||||||
|
// int affectRows = statement.executeUpdate(sql);
|
||||||
|
// System.out.println("affectRows >>> " + affectRows);
|
||||||
|
// affectRows = statement.executeUpdate(sql);
|
||||||
|
// System.out.println("affectRows >>> " + affectRows);
|
||||||
|
// statement.close();
|
||||||
|
// connection.close();
|
||||||
|
// } catch (SQLException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
|
||||||
|
ExecutorService executor = Executors.newFixedThreadPool(threadCount);
|
||||||
|
for (long i = 0; i < totalSize / tableSize / batchSize; i++) {
|
||||||
|
executor.execute(new InsertTask(dataSource, dbName, tableSize, batchSize));
|
||||||
|
// sleep few seconds
|
||||||
try {
|
try {
|
||||||
Connection connection = dataSource.getConnection();
|
if (sleep > 0)
|
||||||
Statement statement = connection.createStatement();
|
TimeUnit.MILLISECONDS.sleep(sleep);
|
||||||
String sql = "insert into " + dbName + ".t_1 values('2020-01-01 00:00:00.000',12.12,111)";
|
} catch (InterruptedException e) {
|
||||||
int affectRows = statement.executeUpdate(sql);
|
|
||||||
System.out.println("affectRows >>> " + affectRows);
|
|
||||||
affectRows = statement.executeUpdate(sql);
|
|
||||||
System.out.println("affectRows >>> " + affectRows);
|
|
||||||
statement.close();
|
|
||||||
connection.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
executor.shutdown();
|
||||||
|
|
||||||
|
|
||||||
// ExecutorService executor = Executors.newFixedThreadPool(threadCount);
|
|
||||||
// while (true) {
|
|
||||||
// executor.execute(new InsertTask(dataSource, dbName, tableSize, batchSize));
|
|
||||||
// if (sleep > 0)
|
|
||||||
// TimeUnit.MILLISECONDS.sleep(sleep);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void init(DataSource dataSource) {
|
private static void init(DataSource dataSource) {
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.taosdata.example.common;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class InsertTask implements Runnable {
|
||||||
|
private final Random random = new Random(System.currentTimeMillis());
|
||||||
|
private static final Logger logger = Logger.getLogger(InsertTask.class);
|
||||||
|
|
||||||
|
private final DataSource ds;
|
||||||
|
private final String dbName;
|
||||||
|
private final long tableSize;
|
||||||
|
private final long batchSize;
|
||||||
|
|
||||||
|
public InsertTask(DataSource ds, String dbName, long tableSize, long batchSize) {
|
||||||
|
this.ds = ds;
|
||||||
|
this.dbName = dbName;
|
||||||
|
this.tableSize = tableSize;
|
||||||
|
this.batchSize = batchSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
int affectedRows = 0;
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
try (Connection conn = ds.getConnection(); Statement stmt = conn.createStatement()) {
|
||||||
|
for (int tb_index = 1; tb_index <= tableSize; tb_index++) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("insert into ").append(dbName).append(".t_").append(tb_index).append("(ts, temperature, humidity) values ");
|
||||||
|
for (int i = 0; i < batchSize; i++) {
|
||||||
|
sb.append("(").append(start + i).append(", ").append(random.nextFloat() * 30).append(", ").append(random.nextInt(70)).append(") ");
|
||||||
|
}
|
||||||
|
logger.info("SQL >>> " + sb.toString());
|
||||||
|
affectedRows += stmt.executeUpdate(sb.toString());
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
logger.info(">>> affectedRows:" + affectedRows + " TimeCost:" + (System.currentTimeMillis() - start) + " ms");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
package com.taosdata.demo.pool;
|
package com.taosdata.example.pool;
|
||||||
|
|
||||||
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
import com.mchange.v2.c3p0.ComboPooledDataSource;
|
||||||
import org.apache.commons.dbcp.BasicDataSource;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.beans.PropertyVetoException;
|
import java.beans.PropertyVetoException;
|
|
@ -1,4 +1,4 @@
|
||||||
package com.taosdata.demo.pool;
|
package com.taosdata.example.pool;
|
||||||
|
|
||||||
import org.apache.commons.dbcp.BasicDataSource;
|
import org.apache.commons.dbcp.BasicDataSource;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.taosdata.demo.pool;
|
package com.taosdata.example.pool;
|
||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
|
|
||||||
|
@ -11,19 +11,17 @@ public class DruidPoolBuilder {
|
||||||
|
|
||||||
DruidDataSource dataSource = new DruidDataSource();
|
DruidDataSource dataSource = new DruidDataSource();
|
||||||
// jdbc properties
|
// jdbc properties
|
||||||
dataSource.setUrl(url);
|
|
||||||
dataSource.setDriverClassName("com.taosdata.jdbc.TSDBDriver");
|
dataSource.setDriverClassName("com.taosdata.jdbc.TSDBDriver");
|
||||||
|
dataSource.setUrl(url);
|
||||||
dataSource.setUsername("root");
|
dataSource.setUsername("root");
|
||||||
dataSource.setPassword("taosdata");
|
dataSource.setPassword("taosdata");
|
||||||
|
|
||||||
// pool configurations
|
// pool configurations
|
||||||
dataSource.setInitialSize(poolSize);//初始连接数,默认0
|
dataSource.setInitialSize(poolSize);
|
||||||
dataSource.setMinIdle(poolSize);//最小闲置数
|
dataSource.setMinIdle(poolSize);
|
||||||
dataSource.setMaxActive(poolSize);//最大连接数,默认8
|
dataSource.setMaxActive(poolSize);
|
||||||
dataSource.setMaxWait(30000);//获取连接的最大等待时间,单位毫秒
|
dataSource.setMaxWait(30000);
|
||||||
dataSource.setValidationQuery("select server_status()");
|
dataSource.setValidationQuery("select server_status()");
|
||||||
return dataSource;
|
return dataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package com.taosdata.demo.pool;
|
package com.taosdata.example.pool;
|
||||||
|
|
||||||
import com.zaxxer.hikari.HikariConfig;
|
import com.zaxxer.hikari.HikariConfig;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
@ -15,9 +15,10 @@ public class HikariCpBuilder {
|
||||||
config.setUsername("root");
|
config.setUsername("root");
|
||||||
config.setPassword("taosdata");
|
config.setPassword("taosdata");
|
||||||
// pool configurations
|
// pool configurations
|
||||||
config.setMinimumIdle(3); //minimum number of idle connection
|
config.setMinimumIdle(poolSize); //minimum number of idle connection
|
||||||
config.setMaximumPoolSize(10); //maximum number of connection in the pool
|
config.setMaximumPoolSize(poolSize); //maximum number of connection in the pool
|
||||||
config.setConnectionTimeout(30000); //maximum wait milliseconds for get connection from pool
|
config.setConnectionTimeout(30000); //maximum wait milliseconds for get connection from pool
|
||||||
|
config.setMaxLifetime(0); // maximum life time for each connection
|
||||||
config.setIdleTimeout(0); // max idle time for recycle idle connection
|
config.setIdleTimeout(0); // max idle time for recycle idle connection
|
||||||
config.setConnectionTestQuery("select server_status()"); //validation query
|
config.setConnectionTestQuery("select server_status()"); //validation query
|
||||||
|
|
|
@ -47,15 +47,9 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.14</version>
|
<version>2.0.18</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
<version>5.1.47</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
spring:
|
spring:
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.taosdata.jdbc.TSDBDriver
|
driver-class-name: com.taosdata.jdbc.TSDBDriver
|
||||||
url: jdbc:TAOS://localhost:6030/mp_test
|
url: jdbc:TAOS://localhost:6030/mp_test?charset=UTF-8&locale=en_US.UTF-8&timezone=UTC-8
|
||||||
user: root
|
user: root
|
||||||
password: taosdata
|
password: taosdata
|
||||||
charset: UTF-8
|
|
||||||
locale: en_US.UTF-8
|
|
||||||
timezone: UTC-8
|
|
||||||
|
|
||||||
druid:
|
druid:
|
||||||
initial-size: 5
|
initial-size: 5
|
||||||
min-idle: 5
|
min-idle: 5
|
||||||
max-active: 5
|
max-active: 5
|
||||||
|
|
||||||
|
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
configuration:
|
configuration:
|
||||||
map-underscore-to-camel-case: false
|
map-underscore-to-camel-case: false
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<version>2.2.1.RELEASE</version>
|
<version>2.2.1.RELEASE</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.example</groupId>
|
||||||
<artifactId>springbootdemo</artifactId>
|
<artifactId>springbootdemo</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>springbootdemo</name>
|
<name>springbootdemo</name>
|
||||||
|
@ -63,7 +63,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.4</version>
|
<version>2.0.18</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -71,8 +71,6 @@
|
||||||
<artifactId>druid-spring-boot-starter</artifactId>
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
<version>1.1.17</version>
|
<version>1.1.17</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -47,7 +47,7 @@ logging.level.com.taosdata.jdbc.springbootdemo.dao=debug
|
||||||
* 插入单条记录
|
* 插入单条记录
|
||||||
```xml
|
```xml
|
||||||
<!-- weatherMapper.xml -->
|
<!-- weatherMapper.xml -->
|
||||||
<insert id="insert" parameterType="com.taosdata.jdbc.springbootdemo.domain.Weather" >
|
<insert id="insert" parameterType="Weather" >
|
||||||
insert into test.weather (ts, temperature, humidity) values (now, #{temperature,jdbcType=INTEGER}, #{humidity,jdbcType=FLOAT})
|
insert into test.weather (ts, temperature, humidity) values (now, #{temperature,jdbcType=INTEGER}, #{humidity,jdbcType=FLOAT})
|
||||||
</insert>
|
</insert>
|
||||||
```
|
```
|
||||||
|
@ -67,9 +67,9 @@ logging.level.com.taosdata.jdbc.springbootdemo.dao=debug
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
<mapper namespace="com.taosdata.jdbc.springbootdemo.dao.WeatherMapper">
|
<mapper namespace="WeatherMapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="com.taosdata.jdbc.springbootdemo.domain.Weather">
|
<resultMap id="BaseResultMap" type="Weather">
|
||||||
<id column="ts" jdbcType="TIMESTAMP" property="ts" />
|
<id column="ts" jdbcType="TIMESTAMP" property="ts" />
|
||||||
<result column="temperature" jdbcType="INTEGER" property="temperature" />
|
<result column="temperature" jdbcType="INTEGER" property="temperature" />
|
||||||
<result column="humidity" jdbcType="FLOAT" property="humidity" />
|
<result column="humidity" jdbcType="FLOAT" property="humidity" />
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
package com.taosdata.jdbc.springbootdemo;
|
package com.taosdata.example.springbootdemo;
|
||||||
|
|
||||||
import org.mybatis.spring.annotation.MapperScan;
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@MapperScan(basePackages = {"com.taosdata.jdbc.springbootdemo.dao"})
|
@MapperScan(basePackages = {"com.taosdata.example.springbootdemo.dao"})
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class cd {
|
public class SpringbootdemoApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(SpringbootdemoApplication.class, args);
|
SpringApplication.run(SpringbootdemoApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.controller;
|
package com.taosdata.example.springbootdemo.controller;
|
||||||
|
|
||||||
import com.taosdata.jdbc.springbootdemo.domain.Weather;
|
import com.taosdata.example.springbootdemo.domain.Weather;
|
||||||
import com.taosdata.jdbc.springbootdemo.service.WeatherService;
|
import com.taosdata.example.springbootdemo.service.WeatherService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@ -45,7 +45,6 @@ public class WeatherController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/{temperature}/{humidity}")
|
@PostMapping("/{temperature}/{humidity}")
|
||||||
public int saveWeather(@PathVariable int temperature, @PathVariable float humidity) {
|
public int saveWeather(@PathVariable int temperature, @PathVariable float humidity) {
|
||||||
|
|
||||||
return weatherService.save(temperature, humidity);
|
return weatherService.save(temperature, humidity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +56,6 @@ public class WeatherController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/batch")
|
@PostMapping("/batch")
|
||||||
public int batchSaveWeather(@RequestBody List<Weather> weatherList) {
|
public int batchSaveWeather(@RequestBody List<Weather> weatherList) {
|
||||||
|
|
||||||
return weatherService.save(weatherList);
|
return weatherService.save(weatherList);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.dao;
|
package com.taosdata.example.springbootdemo.dao;
|
||||||
|
|
||||||
import com.taosdata.jdbc.springbootdemo.domain.Weather;
|
import com.taosdata.example.springbootdemo.domain.Weather;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -1,9 +1,9 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
|
||||||
<mapper namespace="com.taosdata.jdbc.springbootdemo.dao.WeatherMapper">
|
<mapper namespace="com.taosdata.example.springbootdemo.dao.WeatherMapper">
|
||||||
|
|
||||||
<resultMap id="BaseResultMap" type="com.taosdata.jdbc.springbootdemo.domain.Weather">
|
<resultMap id="BaseResultMap" type="com.taosdata.example.springbootdemo.domain.Weather">
|
||||||
<id column="ts" jdbcType="TIMESTAMP" property="ts" />
|
<id column="ts" jdbcType="TIMESTAMP" property="ts" />
|
||||||
<result column="temperature" jdbcType="INTEGER" property="temperature" />
|
<result column="temperature" jdbcType="INTEGER" property="temperature" />
|
||||||
<result column="humidity" jdbcType="FLOAT" property="humidity" />
|
<result column="humidity" jdbcType="FLOAT" property="humidity" />
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<insert id="insert" parameterType="com.taosdata.jdbc.springbootdemo.domain.Weather" >
|
<insert id="insert" parameterType="com.taosdata.example.springbootdemo.domain.Weather" >
|
||||||
insert into test.weather (ts, temperature, humidity) values (now, #{temperature,jdbcType=INTEGER}, #{humidity,jdbcType=FLOAT})
|
insert into test.weather (ts, temperature, humidity) values (now, #{temperature,jdbcType=INTEGER}, #{humidity,jdbcType=FLOAT})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.domain;
|
package com.taosdata.example.springbootdemo.domain;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.service;
|
package com.taosdata.example.springbootdemo.service;
|
||||||
|
|
||||||
import com.taosdata.jdbc.springbootdemo.dao.WeatherMapper;
|
import com.taosdata.example.springbootdemo.dao.WeatherMapper;
|
||||||
import com.taosdata.jdbc.springbootdemo.domain.Weather;
|
import com.taosdata.example.springbootdemo.domain.Weather;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.controller;
|
|
||||||
|
|
||||||
|
|
||||||
import com.taosdata.jdbc.springbootdemo.domain.Rainfall;
|
|
||||||
import com.taosdata.jdbc.springbootdemo.service.RainStationService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/rainstation")
|
|
||||||
public class RainStationController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RainStationService service;
|
|
||||||
|
|
||||||
@GetMapping("/init")
|
|
||||||
public boolean init() {
|
|
||||||
service.init();
|
|
||||||
service.createTable();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/insert")
|
|
||||||
public int insert(@RequestBody Rainfall rainfall){
|
|
||||||
return service.insert(rainfall);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.dao;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface DatabaseMapper {
|
|
||||||
|
|
||||||
int createDatabase(String dbname);
|
|
||||||
|
|
||||||
int dropDatabase(String dbname);
|
|
||||||
|
|
||||||
int creatDatabaseWithParameters(Map<String,String> map);
|
|
||||||
|
|
||||||
int useDatabase(String dbname);
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
|
|
||||||
<mapper namespace="com.taosdata.jdbc.springbootdemo.dao.DatabaseMapper">
|
|
||||||
|
|
||||||
<update id="createDatabase" parameterType="java.lang.String">
|
|
||||||
create database if not exists ${dbname}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<update id="dropDatabase" parameterType="java.lang.String">
|
|
||||||
DROP database if exists ${dbname}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
|
|
||||||
<update id="creatDatabaseWithParameters" parameterType="map">
|
|
||||||
CREATE database if not EXISTS ${dbname}
|
|
||||||
<if test="keep != null">
|
|
||||||
KEEP ${keep}
|
|
||||||
</if>
|
|
||||||
<if test="days != null">
|
|
||||||
DAYS ${days}
|
|
||||||
</if>
|
|
||||||
<if test="replica != null">
|
|
||||||
REPLICA ${replica}
|
|
||||||
</if>
|
|
||||||
<if test="cache != null">
|
|
||||||
cache ${cache}
|
|
||||||
</if>
|
|
||||||
<if test="blocks != null">
|
|
||||||
blocks ${blocks}
|
|
||||||
</if>
|
|
||||||
<if test="minrows != null">
|
|
||||||
minrows ${minrows}
|
|
||||||
</if>
|
|
||||||
<if test="maxrows != null">
|
|
||||||
maxrows ${maxrows}
|
|
||||||
</if>
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<update id="useDatabase" parameterType="java.lang.String">
|
|
||||||
use ${dbname}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
</mapper>
|
|
|
@ -1,9 +0,0 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.dao;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public interface RainfallMapper {
|
|
||||||
|
|
||||||
|
|
||||||
int save(Map<String, Object> map);
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
|
|
||||||
<mapper namespace="com.taosdata.jdbc.springbootdemo.dao.RainfallMapper">
|
|
||||||
|
|
||||||
<insert id="save" parameterType="map">
|
|
||||||
INSERT INTO ${table} using ${dbname}.${stable} tags(#{values.station_code}, #{values.station_name}) (ts, name, code, rainfall) values (#{values.ts}, #{values.name}, #{values.code}, #{values.rainfall})
|
|
||||||
</insert>
|
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
|
|
@ -1,8 +0,0 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.dao;
|
|
||||||
|
|
||||||
import com.taosdata.jdbc.springbootdemo.domain.TableMetadata;
|
|
||||||
|
|
||||||
public interface TableMapper {
|
|
||||||
|
|
||||||
boolean createSTable(TableMetadata tableMetadata);
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
|
||||||
|
|
||||||
<mapper namespace="com.taosdata.jdbc.springbootdemo.dao.TableMapper">
|
|
||||||
|
|
||||||
<update id="createSTable" parameterType="com.taosdata.jdbc.springbootdemo.domain.TableMetadata">
|
|
||||||
create table if not exists ${dbname}.${tablename}
|
|
||||||
<foreach collection="fields" item="field" index="index" open="(" close=")" separator=",">
|
|
||||||
${field.name} ${field.type}
|
|
||||||
</foreach>
|
|
||||||
TAGS
|
|
||||||
<foreach collection="tags" item="tag" index="index" open="(" close=")" separator=",">
|
|
||||||
${tag.name} ${tag.type}
|
|
||||||
</foreach>
|
|
||||||
</update>
|
|
||||||
|
|
||||||
<update id="dropTable" parameterType="java.lang.String">
|
|
||||||
drop ${tablename}
|
|
||||||
</update>
|
|
||||||
|
|
||||||
</mapper>
|
|
|
@ -1,28 +0,0 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.domain;
|
|
||||||
|
|
||||||
public class FieldMetadata {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
public FieldMetadata(String name, String type) {
|
|
||||||
this.name = name;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.domain;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
|
|
||||||
public class Rainfall {
|
|
||||||
|
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS",timezone = "GMT+8")
|
|
||||||
private Timestamp ts;
|
|
||||||
private String name;
|
|
||||||
private String code;
|
|
||||||
private float rainfall;
|
|
||||||
private String station_code;
|
|
||||||
private String station_name;
|
|
||||||
|
|
||||||
public Timestamp getTs() {
|
|
||||||
return ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTs(Timestamp ts) {
|
|
||||||
this.ts = ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCode() {
|
|
||||||
return code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCode(String code) {
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getRainfall() {
|
|
||||||
return rainfall;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRainfall(float rainfall) {
|
|
||||||
this.rainfall = rainfall;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStation_code() {
|
|
||||||
return station_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStation_code(String station_code) {
|
|
||||||
this.station_code = station_code;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getStation_name() {
|
|
||||||
return station_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStation_name(String station_name) {
|
|
||||||
this.station_name = station_name;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.domain;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TableMetadata {
|
|
||||||
|
|
||||||
private String dbname;
|
|
||||||
private String tablename;
|
|
||||||
private List<FieldMetadata> fields;
|
|
||||||
private List<TagMetadata> tags;
|
|
||||||
|
|
||||||
public String getDbname() {
|
|
||||||
return dbname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDbname(String dbname) {
|
|
||||||
this.dbname = dbname;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTablename() {
|
|
||||||
return tablename;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTablename(String tablename) {
|
|
||||||
this.tablename = tablename;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<FieldMetadata> getFields() {
|
|
||||||
return fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFields(List<FieldMetadata> fields) {
|
|
||||||
this.fields = fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<TagMetadata> getTags() {
|
|
||||||
return tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTags(List<TagMetadata> tags) {
|
|
||||||
this.tags = tags;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,27 +0,0 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.domain;
|
|
||||||
|
|
||||||
public class TagMetadata {
|
|
||||||
private String name;
|
|
||||||
private String type;
|
|
||||||
|
|
||||||
public TagMetadata(String name, String type) {
|
|
||||||
this.name = name;
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(String type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,72 +0,0 @@
|
||||||
package com.taosdata.jdbc.springbootdemo.service;
|
|
||||||
|
|
||||||
import com.taosdata.jdbc.springbootdemo.dao.DatabaseMapper;
|
|
||||||
import com.taosdata.jdbc.springbootdemo.dao.RainfallMapper;
|
|
||||||
import com.taosdata.jdbc.springbootdemo.dao.TableMapper;
|
|
||||||
import com.taosdata.jdbc.springbootdemo.domain.FieldMetadata;
|
|
||||||
import com.taosdata.jdbc.springbootdemo.domain.Rainfall;
|
|
||||||
import com.taosdata.jdbc.springbootdemo.domain.TableMetadata;
|
|
||||||
import com.taosdata.jdbc.springbootdemo.domain.TagMetadata;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class RainStationService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private DatabaseMapper databaseMapper;
|
|
||||||
@Autowired
|
|
||||||
private TableMapper tableMapper;
|
|
||||||
@Autowired
|
|
||||||
private RainfallMapper rainfallMapper;
|
|
||||||
|
|
||||||
public boolean init() {
|
|
||||||
databaseMapper.dropDatabase("rainstation");
|
|
||||||
|
|
||||||
Map<String, String> map = new HashMap<>();
|
|
||||||
map.put("dbname", "rainstation");
|
|
||||||
map.put("keep", "36500");
|
|
||||||
map.put("days", "30");
|
|
||||||
map.put("blocks", "4");
|
|
||||||
databaseMapper.creatDatabaseWithParameters(map);
|
|
||||||
|
|
||||||
databaseMapper.useDatabase("rainstation");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean createTable() {
|
|
||||||
TableMetadata tableMetadata = new TableMetadata();
|
|
||||||
tableMetadata.setDbname("rainstation");
|
|
||||||
tableMetadata.setTablename("monitoring");
|
|
||||||
|
|
||||||
List<FieldMetadata> fields = new ArrayList<>();
|
|
||||||
fields.add(new FieldMetadata("ts", "timestamp"));
|
|
||||||
fields.add(new FieldMetadata("name", "NCHAR(10)"));
|
|
||||||
fields.add(new FieldMetadata("code", " BINARY(8)"));
|
|
||||||
fields.add(new FieldMetadata("rainfall", "float"));
|
|
||||||
tableMetadata.setFields(fields);
|
|
||||||
|
|
||||||
List<TagMetadata> tags = new ArrayList<>();
|
|
||||||
tags.add(new TagMetadata("station_code", "BINARY(8)"));
|
|
||||||
tags.add(new TagMetadata("station_name", "NCHAR(10)"));
|
|
||||||
tableMetadata.setTags(tags);
|
|
||||||
|
|
||||||
tableMapper.createSTable(tableMetadata);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int insert(Rainfall rainfall) {
|
|
||||||
Map<String, Object> map = new HashMap<>();
|
|
||||||
map.put("dbname", "rainstation");
|
|
||||||
map.put("table", "S_53646");
|
|
||||||
map.put("stable", "monitoring");
|
|
||||||
map.put("values", rainfall);
|
|
||||||
return rainfallMapper.save(map);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,24 +1,18 @@
|
||||||
# datasource config
|
# datasource config - JDBC-JNI
|
||||||
spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
|
spring.datasource.driver-class-name=com.taosdata.jdbc.TSDBDriver
|
||||||
spring.datasource.url=jdbc:TAOS://localhost:6030/log
|
spring.datasource.url=jdbc:TAOS://127.0.0.1:6030/test?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
|
||||||
spring.datasource.username=root
|
spring.datasource.username=root
|
||||||
spring.datasource.password=taosdata
|
spring.datasource.password=taosdata
|
||||||
|
|
||||||
|
# datasource config - JDBC-RESTful
|
||||||
|
#spring.datasource.driver-class-name=com.taosdata.jdbc.rs.RestfulDriver
|
||||||
|
#spring.datasource.url=jdbc:TAOS-RS://master:6041/test?user=root&password=taosdata
|
||||||
|
|
||||||
spring.datasource.druid.initial-size=5
|
spring.datasource.druid.initial-size=5
|
||||||
spring.datasource.druid.min-idle=5
|
spring.datasource.druid.min-idle=5
|
||||||
spring.datasource.druid.max-active=5
|
spring.datasource.druid.max-active=5
|
||||||
# max wait time for get connection, ms
|
spring.datasource.druid.max-wait=30000
|
||||||
spring.datasource.druid.max-wait=60000
|
|
||||||
|
|
||||||
spring.datasource.druid.validation-query=select server_status();
|
spring.datasource.druid.validation-query=select server_status();
|
||||||
spring.datasource.druid.validation-query-timeout=5000
|
|
||||||
spring.datasource.druid.test-on-borrow=false
|
|
||||||
spring.datasource.druid.test-on-return=false
|
|
||||||
spring.datasource.druid.test-while-idle=true
|
|
||||||
spring.datasource.druid.time-between-eviction-runs-millis=60000
|
|
||||||
spring.datasource.druid.min-evictable-idle-time-millis=600000
|
|
||||||
spring.datasource.druid.max-evictable-idle-time-millis=900000
|
|
||||||
|
|
||||||
|
|
||||||
#mybatis
|
#mybatis
|
||||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||||
|
|
|
@ -1,13 +0,0 @@
|
||||||
package com.taosdata.jdbc.springbootdemo;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
|
||||||
|
|
||||||
@SpringBootTest
|
|
||||||
class SpringbootdemoApplicationTests {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void contextLoads() {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -67,7 +67,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.taosdata.jdbc</groupId>
|
<groupId>com.taosdata.jdbc</groupId>
|
||||||
<artifactId>taos-jdbcdriver</artifactId>
|
<artifactId>taos-jdbcdriver</artifactId>
|
||||||
<version>2.0.17</version>
|
<version>2.0.18</version>
|
||||||
<!-- <scope>system</scope>-->
|
<!-- <scope>system</scope>-->
|
||||||
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
|
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
|
||||||
|
class ClusterTestcase:
|
||||||
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
os.system("./buildClusterEnv.sh -n 3 -v 2.0.14.1")
|
||||||
|
os.system("yes|taosdemo -h 172.27.0.7 -n 100 -t 100 -x")
|
||||||
|
os.system("python3 ../../concurrent_inquiry.py -H 172.27.0.7 -T 4 -t 4 -l 10")
|
||||||
|
|
||||||
|
clusterTest = ClusterTestcase()
|
||||||
|
clusterTest.run()
|
|
@ -85,18 +85,18 @@ function clusterUp {
|
||||||
cd $DOCKER_DIR
|
cd $DOCKER_DIR
|
||||||
|
|
||||||
if [ $NUM_OF_NODES -eq 3 ]; then
|
if [ $NUM_OF_NODES -eq 3 ]; then
|
||||||
PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION docker-compose up -d
|
PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION VERSION=$VERSION docker-compose up -d
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $NUM_OF_NODES -eq 4 ]; then
|
if [ $NUM_OF_NODES -eq 4 ]; then
|
||||||
PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION docker-compose -f docker-compose.yml -f node4.yml up -d
|
PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION VERSION=$VERSION docker-compose -f docker-compose.yml -f node4.yml up -d
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $NUM_OF_NODES -eq 5 ]; then
|
if [ $NUM_OF_NODES -eq 5 ]; then
|
||||||
PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION docker-compose -f docker-compose.yml -f node4.yml -f node5.yml up -d
|
PACKAGE=TDengine-server-$VERSION-Linux-x64.tar.gz DIR=TDengine-server-$VERSION VERSION=$VERSION docker-compose -f docker-compose.yml -f node4.yml -f node5.yml up -d
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanEnv
|
cleanEnv
|
||||||
# prepareBuild
|
prepareBuild
|
||||||
# clusterUp
|
clusterUp
|
|
@ -7,7 +7,7 @@ services:
|
||||||
args:
|
args:
|
||||||
- PACKAGE=${PACKAGE}
|
- PACKAGE=${PACKAGE}
|
||||||
- EXTRACTDIR=${DIR}
|
- EXTRACTDIR=${DIR}
|
||||||
image: 'tdengine:2.0.13.1'
|
image: 'tdengine:${VERSION}'
|
||||||
container_name: 'td2.0-node1'
|
container_name: 'td2.0-node1'
|
||||||
cap_add:
|
cap_add:
|
||||||
- ALL
|
- ALL
|
||||||
|
@ -35,6 +35,7 @@ services:
|
||||||
- type: bind
|
- type: bind
|
||||||
source: /data
|
source: /data
|
||||||
target: /root
|
target: /root
|
||||||
|
hostname: node1
|
||||||
networks:
|
networks:
|
||||||
taos_update_net:
|
taos_update_net:
|
||||||
ipv4_address: 172.27.0.7
|
ipv4_address: 172.27.0.7
|
||||||
|
@ -46,7 +47,7 @@ services:
|
||||||
args:
|
args:
|
||||||
- PACKAGE=${PACKAGE}
|
- PACKAGE=${PACKAGE}
|
||||||
- EXTRACTDIR=${DIR}
|
- EXTRACTDIR=${DIR}
|
||||||
image: 'tdengine:2.0.13.1'
|
image: 'tdengine:${VERSION}'
|
||||||
container_name: 'td2.0-node2'
|
container_name: 'td2.0-node2'
|
||||||
cap_add:
|
cap_add:
|
||||||
- ALL
|
- ALL
|
||||||
|
@ -85,7 +86,7 @@ services:
|
||||||
args:
|
args:
|
||||||
- PACKAGE=${PACKAGE}
|
- PACKAGE=${PACKAGE}
|
||||||
- EXTRACTDIR=${DIR}
|
- EXTRACTDIR=${DIR}
|
||||||
image: 'tdengine:2.0.13.1'
|
image: 'tdengine:${VERSION}'
|
||||||
container_name: 'td2.0-node3'
|
container_name: 'td2.0-node3'
|
||||||
cap_add:
|
cap_add:
|
||||||
- ALL
|
- ALL
|
||||||
|
|
|
@ -18,18 +18,36 @@ from util.cases import *
|
||||||
from util.sql import *
|
from util.sql import *
|
||||||
from util.dnodes import *
|
from util.dnodes import *
|
||||||
|
|
||||||
|
dataDir = ['data00','data01','data02','data03','data04']
|
||||||
|
dataDict = {'data00':0,'data01':0,'data02':0,'data03':0,'data04':0}
|
||||||
class TDTestCase:
|
class TDTestCase:
|
||||||
def init(self, conn, logSql):
|
def init(self, conn, logSql):
|
||||||
tdLog.debug("start to execute %s" % __file__)
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
tdSql.init(conn.cursor(), logSql)
|
tdSql.init(conn.cursor(), logSql)
|
||||||
|
|
||||||
|
def getfiles(self,ospath):
|
||||||
|
try:
|
||||||
|
files = os.listdir(ospath)
|
||||||
|
for f in files:
|
||||||
|
path = os.path.join(ospath, f)
|
||||||
|
if os.path.isfile(path):
|
||||||
|
if path.endswith('.data'):
|
||||||
|
for i in dataDir:
|
||||||
|
if i in path:
|
||||||
|
dataDict[i] = dataDict[i] + 1
|
||||||
|
print(path)
|
||||||
|
if os.path.isdir(path):
|
||||||
|
self.getfiles(path)
|
||||||
|
except Exception as e :
|
||||||
|
print(str(e))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.ntables = 1000
|
self.ntables = 1000
|
||||||
self.ts = 1520000010000
|
self.ts = 1520000010000
|
||||||
|
|
||||||
tdDnodes.stop(1)
|
tdDnodes.stop(1)
|
||||||
# Test1 1 dataDir
|
# Test1 1 dataDir
|
||||||
|
tdLog.info("================= step1")
|
||||||
cfg={
|
cfg={
|
||||||
'10' : 'maxVgroupsPerDb',
|
'10' : 'maxVgroupsPerDb',
|
||||||
'100' : 'maxTablesPerVnode',
|
'100' : 'maxTablesPerVnode',
|
||||||
|
@ -55,15 +73,33 @@ class TDTestCase:
|
||||||
|
|
||||||
for i in range(self.ntables):
|
for i in range(self.ntables):
|
||||||
tdSql.execute("create table tb%d using stb tags(%d)" %(i, i))
|
tdSql.execute("create table tb%d using stb tags(%d)" %(i, i))
|
||||||
tdSql.execute("insert into tb%d values(%d, 1)" % (self.ts + int (i / 100) * 86400000))
|
tdSql.execute("insert into tb%d values(%d, 1)" % (i,self.ts + int (i / 100) * 86400000))
|
||||||
|
|
||||||
|
tdLog.info("================= step2")
|
||||||
tdDnodes.stop(1)
|
tdDnodes.stop(1)
|
||||||
tdDnodes.start(1)
|
tdDnodes.start(1)
|
||||||
|
|
||||||
tdSql.query("select * from test.stb")
|
tdSql.query("select * from test.stb")
|
||||||
tdSql.checkRows(1000)
|
tdSql.checkRows(1000)
|
||||||
|
|
||||||
|
tdLog.info("================= step3")
|
||||||
|
tdSql.execute('drop database test')
|
||||||
|
for i in range(50):
|
||||||
|
tdSql.execute("create database test%d days 1" %(i))
|
||||||
|
tdSql.execute("use test%d" %(i))
|
||||||
|
tdSql.execute("create table tb (ts timestamp,i int)")
|
||||||
|
for j in range(10):
|
||||||
|
tdSql.execute("insert into tb values(%d, 1)" % (self.ts + int (i / 100) * 86400000))
|
||||||
|
tdDnodes.stop(1)
|
||||||
|
tdDnodes.start(1)
|
||||||
|
flag = True
|
||||||
|
for i in range(4):
|
||||||
|
if dataDict[dataDir[i]] == dataDict[dataDir[i+1]]:
|
||||||
|
flag = flag & True
|
||||||
|
else:
|
||||||
|
flag = flag & False
|
||||||
|
break
|
||||||
|
if not flag : tdLog.exit("%s failed, expect not occured" % (sys.argv[0]))
|
||||||
def stop(self):
|
def stop(self):
|
||||||
tdSql.close()
|
tdSql.close()
|
||||||
tdLog.success("%s successfully executed" % __file__)
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import taos
|
||||||
|
from util.log import tdLog
|
||||||
|
from util.cases import tdCases
|
||||||
|
from util.sql import tdSql
|
||||||
|
|
||||||
|
|
||||||
|
class TDTestCase:
|
||||||
|
def init(self, conn, logSql):
|
||||||
|
tdLog.debug("start to execute %s" % __file__)
|
||||||
|
tdSql.init(conn.cursor(), logSql)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
ts = 1500000000000
|
||||||
|
tbNum = 10
|
||||||
|
rowNum = 20
|
||||||
|
|
||||||
|
tdSql.prepare()
|
||||||
|
|
||||||
|
tdLog.info("===== step1 =====")
|
||||||
|
tdSql.execute(
|
||||||
|
"create table stb0(ts timestamp, col1 binary(20), col2 nchar(20)) tags(tgcol int)")
|
||||||
|
for i in range(tbNum):
|
||||||
|
tdSql.execute("create table tb%d using stb0 tags(%d)" % (i, i))
|
||||||
|
for j in range(rowNum):
|
||||||
|
tdSql.execute(
|
||||||
|
"insert into tb%d values (%d, 'binary%d', 'nchar%d')" %
|
||||||
|
(i, ts + 60000 * j, j, j))
|
||||||
|
tdSql.execute("insert into tb0 values(%d, null, null)" % (ts + 10000000))
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
tdLog.info("===== step2 =====")
|
||||||
|
tdSql.query(
|
||||||
|
"select count(*), count(col1), count(col2) from stb0 interval(1d)")
|
||||||
|
tdSql.checkData(0, 1, rowNum * tbNum + 1)
|
||||||
|
tdSql.checkData(0, 2, rowNum * tbNum)
|
||||||
|
tdSql.checkData(0, 3, rowNum * tbNum)
|
||||||
|
|
||||||
|
tdSql.query("show tables")
|
||||||
|
tdSql.checkRows(tbNum)
|
||||||
|
tdSql.execute(
|
||||||
|
"create table s0 as select count(*), count(col1), count(col2) from stb0 interval(1d)")
|
||||||
|
tdSql.query("show tables")
|
||||||
|
tdSql.checkRows(tbNum + 1)
|
||||||
|
|
||||||
|
tdLog.info("===== step3 =====")
|
||||||
|
tdSql.waitedQuery("select * from s0", 1, 120)
|
||||||
|
try:
|
||||||
|
tdSql.checkData(0, 1, rowNum * tbNum + 1)
|
||||||
|
tdSql.checkData(0, 2, rowNum * tbNum)
|
||||||
|
tdSql.checkData(0, 3, rowNum * tbNum)
|
||||||
|
except Exception as e:
|
||||||
|
tdLog.info(repr(e))
|
||||||
|
|
||||||
|
tdLog.info("===== step4 =====")
|
||||||
|
tdSql.execute("drop table s0")
|
||||||
|
tdSql.query("show tables")
|
||||||
|
tdSql.checkRows(tbNum)
|
||||||
|
|
||||||
|
tdLog.info("===== step5 =====")
|
||||||
|
tdSql.error("select * from s0")
|
||||||
|
|
||||||
|
tdLog.info("===== step6 =====")
|
||||||
|
time.sleep(0.1)
|
||||||
|
tdSql.execute(
|
||||||
|
"create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)")
|
||||||
|
tdSql.query("show tables")
|
||||||
|
tdSql.checkRows(tbNum + 1)
|
||||||
|
|
||||||
|
tdLog.info("===== step7 =====")
|
||||||
|
tdSql.waitedQuery("select * from s0", 1, 120)
|
||||||
|
try:
|
||||||
|
tdSql.checkData(0, 1, rowNum + 1)
|
||||||
|
tdSql.checkData(0, 2, rowNum)
|
||||||
|
tdSql.checkData(0, 3, rowNum)
|
||||||
|
except Exception as e:
|
||||||
|
tdLog.info(repr(e))
|
||||||
|
|
||||||
|
tdLog.info("===== step8 =====")
|
||||||
|
tdSql.query(
|
||||||
|
"select count(*), count(col1), count(col2) from stb0 interval(1d)")
|
||||||
|
tdSql.checkData(0, 1, rowNum * tbNum + 1)
|
||||||
|
tdSql.checkData(0, 2, rowNum * tbNum)
|
||||||
|
tdSql.checkData(0, 3, rowNum * tbNum)
|
||||||
|
tdSql.query("show tables")
|
||||||
|
tdSql.checkRows(tbNum + 1)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
|
@ -196,6 +196,7 @@ cd ../../../debug; make
|
||||||
./test.sh -f general/table/table.sim
|
./test.sh -f general/table/table.sim
|
||||||
./test.sh -f general/table/tinyint.sim
|
./test.sh -f general/table/tinyint.sim
|
||||||
./test.sh -f general/table/vgroup.sim
|
./test.sh -f general/table/vgroup.sim
|
||||||
|
./test.sh -f general/table/createmulti.sim
|
||||||
|
|
||||||
./test.sh -f general/tag/3.sim
|
./test.sh -f general/tag/3.sim
|
||||||
./test.sh -f general/tag/4.sim
|
./test.sh -f general/tag/4.sim
|
||||||
|
|
|
@ -157,4 +157,4 @@
|
||||||
./test.sh -f general/table/table.sim
|
./test.sh -f general/table/table.sim
|
||||||
./test.sh -f general/table/tinyint.sim
|
./test.sh -f general/table/tinyint.sim
|
||||||
./test.sh -f general/table/vgroup.sim
|
./test.sh -f general/table/vgroup.sim
|
||||||
|
./test.sh -f general/table/createmulti.sim
|
|
@ -10,7 +10,7 @@ cd ../../../debug; make
|
||||||
./test.sh -f general/tag/binary_binary.sim
|
./test.sh -f general/tag/binary_binary.sim
|
||||||
./test.sh -f general/tag/binary.sim
|
./test.sh -f general/tag/binary.sim
|
||||||
./test.sh -f general/tag/bool_binary.sim
|
./test.sh -f general/tag/bool_binary.sim
|
||||||
#./test.sh -f general/tag/bool_int.sim
|
./test.sh -f general/tag/bool_int.sim
|
||||||
./test.sh -f general/tag/bool.sim
|
./test.sh -f general/tag/bool.sim
|
||||||
./test.sh -f general/tag/change.sim
|
./test.sh -f general/tag/change.sim
|
||||||
./test.sh -f general/tag/column.sim
|
./test.sh -f general/tag/column.sim
|
||||||
|
|
Loading…
Reference in New Issue