Skip to content

Commit 61b4c7f

Browse files
committed
修改#272
1 parent 75d4d89 commit 61b4c7f

File tree

6 files changed

+233
-34
lines changed

6 files changed

+233
-34
lines changed

EFCore.Taos.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1515
LICENSE = LICENSE
1616
docs\logo.png = docs\logo.png
1717
README.md = README.md
18+
taos.cfg = taos.cfg
1819
docs\taos_ch.png = docs\taos_ch.png
1920
docs\taos_ch_600.png = docs\taos_ch_600.png
2021
EndProjectSection

docker-compose.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ services:
1414
- taos-network
1515

1616
taos:
17-
image: tdengine/tdengine:3.0.5.1
17+
image: tdengine/tdengine:3.2.1.0
1818
restart: always
1919
hostname: taos
20+
volumes:
21+
- "./taos.cfg:/etc/taos/taos.cfg"
2022
ports:
2123
- 6030:6030
2224
- 6035:6035

src/Example/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ MAINTAINER Yanhong Ma 2023
55
RUN echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free" > /etc/apt/sources.list && \
66
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free" >> /etc/apt/sources.list && \
77
echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free" >> /etc/apt/sources.list && \
8-
apt-get -y -q update && apt-get install -y --no-install-recommends -q apt-utils libgdiplus libc6-dev lsof net-tools wget curl iputils-ping inetutils-tools && \
8+
apt-get -y -q update && apt-get install -y --no-install-recommends -q apt-utils lsof net-tools wget curl iputils-ping inetutils-tools && \
99
apt-get autoremove -y && apt-get clean && apt-get autoclean && rm /var/cache/apt/* -rf && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
10-
RUN curl -o TDengine-client.tar.gz "https://www.taosdata.com/assets-download/3.0/TDengine-client-3.0.5.1-Linux-x64.tar.gz" && \
10+
RUN curl -o TDengine-client.tar.gz "https://www.taosdata.com/assets-download/3.0/TDengine-client-3.2.1.0-Linux-x64.tar.gz" && \
1111
tar -xvf TDengine-client.tar.gz && rm TDengine-client.tar.gz -f && cd $(ls TDengine-client* -d) && \
1212
./install_client.sh && \
1313
rm $(pwd) -rf
1414
WORKDIR /app
15-
15+
1616
FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build
1717
WORKDIR /src
1818

src/Example/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ private static void Main(string[] args)
3636
{
3737
issue259_258();
3838
var IS_RUNNING_IN_CONTAINER = bool.TryParse(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), out bool _DOTNET_RUNNING_IN_CONTAINER) && _DOTNET_RUNNING_IN_CONTAINER;
39-
var _dbhost = IS_RUNNING_IN_CONTAINER ? "taos" : System.Net.Dns.GetHostName();
39+
var _dbhost = IS_RUNNING_IN_CONTAINER ? System.Net.Dns.GetHostName() : System.Net.Dns.GetHostName();
4040
Console.WriteLine($"主机名:{_dbhost} 当前程序运行在{(IS_RUNNING_IN_CONTAINER ? "容器内" : "主机中")} ");
4141
Console.WriteLine($"CPU:{Environment.ProcessorCount} 主机名:{Environment.MachineName}");
4242
var p = new Ping();
@@ -323,6 +323,7 @@ private static void ExecSqlByStmt(TaosConnectionStringBuilder builder)
323323
{
324324
using (var connection = new TaosConnection(builder.ConnectionString))
325325
{
326+
Console.WriteLine(builder.ConnectionString);
326327
connection.Open();
327328
connection.CreateCommand("create database if not exists test_ws_stmt precision 'ns';").ExecuteNonQuery();
328329
connection.CreateCommand("create table if not exists test_ws_stmt.st(ts timestamp,c1 bool, c2 tinyint,c3 smallint, c4 int, c5 bigint, c6 tinyint unsigned, c7 smallint unsigned, c8 int unsigned, c9 bigint unsigned, c10 float, c11 double, c12 binary(20), c13 nchar(20) ) tags (info json);").ExecuteNonQuery();

src/IoTSharp.Data.Taos/Protocols/TDNative/TaosNative.cs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using IoTSharp.Data.Taos;
22
using System;
33
using System.Collections;
4+
using System.Collections.Concurrent;
45
using System.Collections.Generic;
56
using System.Data;
67
using System.Diagnostics;
@@ -14,7 +15,7 @@ namespace IoTSharp.Data.Taos.Protocols
1415
{
1516
internal class TaosNative : ITaosProtocol
1617
{
17-
private static readonly Dictionary<string, ConcurrentTaosQueue> g_pool = new Dictionary<string, ConcurrentTaosQueue>();
18+
private static readonly ConcurrentDictionary<string, ConcurrentTaosQueue> g_pool = new ConcurrentDictionary<string, ConcurrentTaosQueue>();
1819
private ConcurrentTaosQueue _queue = null;
1920
private static bool _dll_isloaded = false;
2021
private readonly DateTime _dt1970;
@@ -117,52 +118,53 @@ public string GetClientVersion()
117118
public bool Open(TaosConnectionStringBuilder builder)
118119
{
119120
var _connectionString = builder.ConnectionString;
120-
if (!g_pool.ContainsKey(_connectionString))
121+
lock (g_pool)
121122
{
122-
g_pool.Add(_connectionString, new ConcurrentTaosQueue() { Timeout = builder.ConnectionTimeout });
123-
}
124-
_queue = g_pool[_connectionString];
125-
_queue.AddRef();
126-
127-
for (int i = 0; i < builder.PoolSize + 1; i++)
128-
{
129-
var c = TDengine.Connect(builder.DataSource, builder.Username, builder.Password, "", (short)builder.Port);
130-
if (c != IntPtr.Zero)
123+
_queue = g_pool.GetOrAdd(_connectionString, new ConcurrentTaosQueue() { Timeout = builder.ConnectionTimeout });
124+
_queue.AddRef();
125+
for (int i = 0; i < builder.PoolSize + 1; i++)
131126
{
132-
_queue.Return(c);
127+
var c = TDengine.Connect(builder.DataSource, builder.Username, builder.Password, "", (short)builder.Port);
128+
if (c != IntPtr.Zero)
129+
{
130+
_queue.Return(c);
131+
}
132+
}
133+
if (_queue.TaosQueue.IsEmpty)
134+
{
135+
TaosException.ThrowExceptionForRC(new TaosErrorResult() { Code = -1, Error = "Can't open connection." });
133136
}
134-
}
135-
if (_queue.TaosQueue.IsEmpty)
136-
{
137-
TaosException.ThrowExceptionForRC(new TaosErrorResult() { Code = -1, Error = "Can't open connection." });
138137
}
139138
return true;
140139
}
141140

142141
public void Close(TaosConnectionStringBuilder builder)
143142
{
144143
var _connectionString = builder.ConnectionString;
145-
_queue.RemoveRef();
146-
if (_queue.GetRef() == 0)
144+
lock (g_pool)
147145
{
148-
for (int i = 0; i < _queue.TaosQueue.Count; i++)
146+
_queue.RemoveRef();
147+
if (_queue.GetRef() == 0)
149148
{
150-
try
149+
for (int i = 0; i < _queue.TaosQueue.Count; i++)
151150
{
152-
var tk = _queue.Take();
153-
if (tk != IntPtr.Zero)
151+
try
154152
{
155-
TDengine.Close(tk);
153+
var tk = _queue.Take();
154+
if (tk != IntPtr.Zero)
155+
{
156+
TDengine.Close(tk);
157+
}
156158
}
157-
}
158-
catch (Exception)
159-
{
159+
catch (Exception)
160+
{
160161

161-
162+
163+
}
162164
}
165+
_queue = null;
166+
g_pool.TryRemove(_connectionString, out var va1l);
163167
}
164-
_queue = null;
165-
g_pool.Remove(_connectionString);
166168
}
167169
}
168170

taos.cfg

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
########################################################
2+
# #
3+
# Configuration #
4+
# #
5+
########################################################
6+
7+
######### 0. Client only configurations #############
8+
9+
# The interval for CLI to send heartbeat to mnode
10+
# shellActivityTimer 3
11+
12+
13+
############### 1. Cluster End point ############################
14+
15+
# The end point of the first dnode in the cluster to be connected to when this dnode or the CLI utility is started
16+
# firstEp hostname:6030
17+
18+
# The end point of the second dnode to be connected to if the firstEp is not available
19+
# secondEp
20+
21+
22+
############### 2. Configuration Parameters of current dnode #####
23+
24+
# The FQDN of the host on which this dnode will be started. It can be IP address
25+
# fqdn hostname
26+
27+
# The port for external access after this dnode is started
28+
# serverPort 6030
29+
30+
# The maximum number of connections a dnode can accept
31+
# maxShellConns 5000
32+
33+
# The directory for writing log files, if you are using Windows platform please change to Windows path
34+
# logDir /var/log/taos
35+
36+
# All data files are stored in this directory, if you are using Windows platform please change to Windows path
37+
# dataDir /var/lib/taos
38+
39+
# temporary file's directory, if you are using Windows platform please change to Windows path
40+
# tempDir /tmp/
41+
42+
# Switch for allowing to collect and report service usage information
43+
# telemetryReporting 0
44+
45+
# Switch for allowing to collect and report crash information
46+
# crashReporting 0
47+
48+
# The maximum number of vnodes supported by this dnode
49+
supportVnodes 8
50+
51+
# The interval of this dnode reporting status to mnode, [1..10] seconds
52+
# statusInterval 1
53+
54+
# The minimum sliding window time, milli-second
55+
# minSlidingTime 10
56+
57+
# The minimum time window, milli-second
58+
# minIntervalTime 10
59+
60+
# The maximum allowed query buffer size in MB during query processing for each data node
61+
# -1 no limit (default)
62+
# 0 no query allowed, queries are disabled
63+
# queryBufferSize -1
64+
65+
# The compressed rpc message, option:
66+
# -1 (no compression)
67+
# 0 (all message compressed),
68+
# > 0 (rpc message body which larger than this value will be compressed)
69+
# compressMsgSize -1
70+
71+
# query retrieved column data compression option:
72+
# -1 (no compression)
73+
# 0 (all retrieved column data compressed),
74+
# > 0 (any retrieved column size greater than this value all data will be compressed.)
75+
# compressColData -1
76+
77+
# system time zone
78+
# timezone UTC-8
79+
80+
# system time zone (for windows 10)
81+
# timezone Asia/Shanghai (CST, +0800)
82+
83+
# system locale
84+
# locale en_US.UTF-8
85+
86+
# system charset
87+
# charset UTF-8
88+
89+
# stop writing logs when the disk size of the log folder is less than this value
90+
# minimalLogDirGB 1.0
91+
92+
# stop writing temporary files when the disk size of the tmp folder is less than this value
93+
# minimalTmpDirGB 1.0
94+
95+
# if free disk space is less than this value, this dnode will fail to start
96+
# minimalDataDirGB 2.0
97+
98+
# enable/disable system monitor
99+
# monitor 1
100+
101+
# enable/disable audit log
102+
# audit 1
103+
104+
# enable/disable audit create table
105+
# auditCreateTable 1
106+
107+
# The following parameter is used to limit the maximum number of lines in log files.
108+
# max number of lines per log filters
109+
# numOfLogLines 10000000
110+
111+
# write log in async way: 1 - async, 0 - sync
112+
# asyncLog 1
113+
114+
# time period of keeping log files, in days
115+
# logKeepDays 0
116+
117+
118+
############ 3. Debug Flag and levels #############################################
119+
120+
# The following parameters are used for debug purpose only by this dnode.
121+
# debugFlag is a 8 bits mask: FILE-SCREEN-UNUSED-HeartBeat-DUMP-TRACE_WARN-ERROR
122+
# Available debug levels are:
123+
# 131: output warning and error
124+
# 135: output debug, warning and error
125+
# 143: output trace, debug, warning and error to log
126+
# 199: output debug, warning and error to both screen and file
127+
# 207: output trace, debug, warning and error to both screen and file
128+
129+
# debug flag for all log type, take effect when non-zero value
130+
# debugFlag 0
131+
132+
# debug flag for timer
133+
# tmrDebugFlag 131
134+
135+
# debug flag for util
136+
# uDebugFlag 131
137+
138+
# debug flag for rpc
139+
# rpcDebugFlag 131
140+
141+
# debug flag for jni
142+
# jniDebugFlag 131
143+
144+
# debug flag for query
145+
# qDebugFlag 131
146+
147+
# debug flag for client driver
148+
# cDebugFlag 131
149+
150+
# debug flag for dnode messages
151+
# dDebugFlag 135
152+
153+
# debug flag for vnode
154+
# vDebugFlag 131
155+
156+
# debug flag for meta management messages
157+
# mDebugFlag 135
158+
159+
# debug flag for wal
160+
# wDebugFlag 135
161+
162+
# debug flag for sync module
163+
# sDebugFlag 135
164+
165+
# debug flag for tsdb
166+
# tsdbDebugFlag 131
167+
168+
# debug flag for tq
169+
# tqDebugFlag 131
170+
171+
# debug flag for fs
172+
# fsDebugFlag 131
173+
174+
# debug flag for udf
175+
# udfDebugFlag 131
176+
177+
# debug flag for sma
178+
# smaDebugFlag 131
179+
180+
# debug flag for index
181+
# idxDebugFlag 131
182+
183+
# debug flag for tdb
184+
# tdbDebugFlag 131
185+
186+
# debug flag for meta
187+
# metaDebugFlag 131
188+
189+
# generate core file when service crash
190+
# enableCoreFile 1
191+
#monitor 1
192+
#monitorFQDN buildkitsandbox
193+
#audit 1

0 commit comments

Comments
 (0)