Skip to content

Commit 58cf1db

Browse files
authored
Enhance Initialization and Resilience with Multiple Node URLs for Improved Failover Handling (#8)
1 parent 1d5ab6c commit 58cf1db

File tree

107 files changed

+13238
-6805
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+13238
-6805
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
# Apache IoTDB Client for C#
2424

25+
[![E2E Tests](https://github.com/apache/iotdb-client-csharp/actions/workflows/e2e.yml/badge.svg)](https://github.com/apache/iotdb-client-csharp/actions/workflows/e2e.yml)
26+
[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
2527
## Overview
2628

2729
This is the C# client of Apache IoTDB.
@@ -41,7 +43,8 @@ We have prepared Nuget Package for C# users. Users can directly install the clie
4143
dotnet add package Apache.IoTDB
4244
```
4345

44-
Note that the `Apache.IoTDB` package only supports versions greater than `.net framework 4.6.1`.
46+
> [!NOTE]
47+
> The `Apache.IoTDB` package only supports versions greater than `.net framework 4.6.1`.
4548
4649
## Prerequisites
4750

@@ -65,7 +68,7 @@ NLog >= 4.7.9
6568

6669
### OS
6770

68-
* Linux, Macos or other unix-like OS
71+
* Linux, MacOS or other unix-like OS
6972
* Windows+bash(WSL, cygwin, Git Bash)
7073

7174
### Command Line Tools

README_ZH.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
[English](./README.md) | [中文](./README_ZH.md)
2222

2323
# Apache IoTDB C#语言客户端
24-
24+
[![E2E Tests](https://github.com/apache/iotdb-client-csharp/actions/workflows/e2e.yml/badge.svg)](https://github.com/apache/iotdb-client-csharp/actions/workflows/e2e.yml)
25+
[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
2526
## 概览
2627

2728
本仓库是Apache IoTDB的C#语言客户端,与其他语言支持相同语义的用户接口。
@@ -38,8 +39,9 @@ Apache IoTDB Github: https://github.com/apache/iotdb
3839
```sh
3940
dotnet add package Apache.IoTDB
4041
```
42+
> [!NOTE]
43+
> 请注意,`Apache.IoTDB`这个包仅支持大于`.net framework 4.6.1`的版本。
4144
42-
请注意,`Apache.IoTDB`这个包仅支持大于`.net framework 4.6.1`的版本。
4345
## 环境准备
4446

4547
.NET SDK Version >= 5.0
@@ -62,7 +64,7 @@ NLog >= 4.7.9
6264

6365
### 操作系统
6466

65-
* Linux、Macos或其他类unix系统
67+
* Linux、MacOS或其他类unix系统
6668
* Windows+bash(WSL、cygwin、Git Bash)
6769

6870
### 命令行工具

courgette.log

Whitespace-only changes.

samples/Apache.IoTDB.Samples/Program.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
using System;
44
using System.Threading.Tasks;
55

6-
namespace Apache.IoTDB.Samples
7-
{
8-
public static class Program
6+
namespace Apache.IoTDB.Samples
7+
{
8+
public static class Program
99
{
1010
public static async Task Main(string[] args)
11-
{
12-
var sessionPoolTest = new SessionPoolTest("iotdb");
13-
await sessionPoolTest.Test() ;
11+
{
12+
var utilsTest = new UtilsTest();
13+
utilsTest.TestParseEndPoint();
14+
var sessionPoolTest = new SessionPoolTest("iotdb");
15+
await sessionPoolTest.Test();
1416
}
1517

1618
public static void OpenDebugMode(this SessionPool session)
@@ -20,6 +22,6 @@ public static void OpenDebugMode(this SessionPool session)
2022
builder.AddConsole();
2123
builder.AddNLog();
2224
});
23-
}
24-
}
25+
}
26+
}
2527
}

samples/Apache.IoTDB.Samples/SessionPoolTest.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Apache.IoTDB.DataStructure;
77
using ConsoleTableExt;
88
using System.Net.Sockets;
9+
using System.Diagnostics;
910

1011
namespace Apache.IoTDB.Samples
1112
{
@@ -15,6 +16,7 @@ public partial class SessionPoolTest
1516
public int port = 6667;
1617
public string user = "root";
1718
public string passwd = "root";
19+
public List<string> node_urls = new();
1820
public int fetch_size = 500;
1921
public int processed_size = 4;
2022
public bool debug = false;
@@ -36,10 +38,17 @@ public partial class SessionPoolTest
3638
public SessionPoolTest(string _host = "localhost")
3739
{
3840
host = _host;
41+
node_urls.Add(host + ":" + port);
3942
}
4043

4144
public async Task Test()
4245
{
46+
await TestOpenWithNodeUrls();
47+
48+
await TestOpenWith2NodeUrls();
49+
50+
await TestOpenWithNodeUrlsAndInsertOneRecord();
51+
4352
await TestInsertOneRecord();
4453

4554
await TestInsertAlignedRecord();
@@ -112,6 +121,50 @@ public async Task Test()
112121

113122
await TestNonSqlBy_ADO();
114123
}
124+
public async Task TestOpenWithNodeUrls()
125+
{
126+
var session_pool = new SessionPool(node_urls, 8);
127+
await session_pool.Open(false);
128+
Debug.Assert(session_pool.IsOpen());
129+
if (debug) session_pool.OpenDebugMode();
130+
await session_pool.Close();
131+
Console.WriteLine("TestOpenWithNodeUrls Passed!");
132+
}
133+
public async Task TestOpenWith2NodeUrls()
134+
{
135+
var session_pool = new SessionPool(new List<string>() { host + ":" + port, host + ":" + (port + 1) }, 8);
136+
await session_pool.Open(false);
137+
Debug.Assert(session_pool.IsOpen());
138+
if (debug) session_pool.OpenDebugMode();
139+
await session_pool.Close();
140+
141+
session_pool = new SessionPool(new List<string>() { host + ":" + (port + 1), host + ":" + port }, 8);
142+
await session_pool.Open(false);
143+
Debug.Assert(session_pool.IsOpen());
144+
if (debug) session_pool.OpenDebugMode();
145+
await session_pool.Close();
146+
Console.WriteLine("TestOpenWith2NodeUrls Passed!");
147+
}
148+
public async Task TestOpenWithNodeUrlsAndInsertOneRecord()
149+
{
150+
var session_pool = new SessionPool(node_urls, 8);
151+
await session_pool.Open(false);
152+
if (debug) session_pool.OpenDebugMode();
153+
await session_pool.DeleteStorageGroupAsync(test_group_name);
154+
var status = await session_pool.CreateTimeSeries(
155+
string.Format("{0}.{1}.{2}", test_group_name, test_device, test_measurements[0]),
156+
TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY);
157+
status = await session_pool.CreateTimeSeries(
158+
string.Format("{0}.{1}.{2}", test_group_name, test_device, test_measurements[1]),
159+
TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY);
160+
status = await session_pool.CreateTimeSeries(
161+
string.Format("{0}.{1}.{2}", test_group_name, test_device, test_measurements[2]),
162+
TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY);
163+
var rowRecord = new RowRecord(1668404120807, new() { "1111111", "22222", "333333" }, new() { test_measurements[0], test_measurements[1], test_measurements[2] });
164+
status = await session_pool.InsertRecordsAsync(new List<string>() { string.Format("{0}.{1}", test_group_name, test_device) }, new List<RowRecord>() { rowRecord });
165+
Debug.Assert(status == 0);
166+
Console.WriteLine("TestOpenWithNodeUrlsAndInsertOneRecord Passed!");
167+
}
115168
public async Task TestInsertOneRecord()
116169
{
117170
var session_pool = new SessionPool(host, port, 1);
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace Apache.IoTDB.Samples
5+
{
6+
public class UtilsTest
7+
{
8+
private Utils _utilFunctions = new Utils();
9+
public void Test()
10+
{
11+
TestParseEndPoint();
12+
}
13+
14+
public void TestParseEndPoint()
15+
{
16+
TestIPv4Address();
17+
TestIPv6Address();
18+
TestInvalidInputs();
19+
}
20+
21+
private void TestIPv4Address()
22+
{
23+
string correctEndpointIPv4 = "192.168.1.1:8080";
24+
var endpoint = _utilFunctions.ParseTEndPointIpv4AndIpv6Url(correctEndpointIPv4);
25+
Debug.Assert(endpoint.Ip == "192.168.1.1", "IPv4 address mismatch.");
26+
Debug.Assert(endpoint.Port == 8080, "IPv4 port mismatch.");
27+
Console.WriteLine("TestIPv4Address passed.");
28+
}
29+
30+
private void TestIPv6Address()
31+
{
32+
string correctEndpointIPv6 = "[2001:db8:85a3::8a2e:370:7334]:443";
33+
var endpoint = _utilFunctions.ParseTEndPointIpv4AndIpv6Url(correctEndpointIPv6);
34+
Debug.Assert(endpoint.Ip == "2001:db8:85a3::8a2e:370:7334", "IPv6 address mismatch.");
35+
Debug.Assert(endpoint.Port == 443, "IPv6 port mismatch.");
36+
Console.WriteLine("TestIPv6Address passed.");
37+
}
38+
39+
private void TestInvalidInputs()
40+
{
41+
string noPort = "192.168.1.1";
42+
var endpointNoPort = _utilFunctions.ParseTEndPointIpv4AndIpv6Url(noPort);
43+
Debug.Assert(string.IsNullOrEmpty(endpointNoPort.Ip) && endpointNoPort.Port == 0, "Failed to handle missing port.");
44+
45+
string emptyInput = "";
46+
var endpointEmpty = _utilFunctions.ParseTEndPointIpv4AndIpv6Url(emptyInput);
47+
Debug.Assert(string.IsNullOrEmpty(endpointEmpty.Ip) && endpointEmpty.Port == 0, "Failed to handle empty input.");
48+
49+
string invalidFormat = "192.168.1.1:port";
50+
try
51+
{
52+
var endpointInvalid = _utilFunctions.ParseTEndPointIpv4AndIpv6Url(invalidFormat);
53+
Debug.Fail("Should have thrown an exception due to invalid port.");
54+
}
55+
catch (FormatException)
56+
{
57+
// Expected exception
58+
}
59+
Console.WriteLine("TestInvalidInputs passed.");
60+
}
61+
}
62+
}
Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

3-
<PropertyGroup>
4-
<TargetFrameworks>net5.0;net6.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
5-
<LangVersion>latest</LangVersion>
3+
<PropertyGroup>
4+
<TargetFrameworks>net5.0;net6.0;netstandard2.1;netstandard2.0;net461</TargetFrameworks>
5+
<LangVersion>latest</LangVersion>
6+
<Authors>eedalong, lausannel, MysticBoy, Aiemu, HTHou</Authors>
7+
<Company>LiuLin Lab</Company>
8+
<PackageDescription>C# client for Apache IoTDB</PackageDescription>
9+
<PackageProjectUrl>https://github.com/apache/iotdb-client-csharp</PackageProjectUrl>
10+
<RepositoryUrl>https://github.com/apache/iotdb-client-csharp</RepositoryUrl>
611

7-
</PropertyGroup>
812

9-
<ItemGroup>
10-
<PackageReference Include="ApacheThrift" Version="0.14.1" />
11-
</ItemGroup>
12-
<ItemGroup Condition="'$(TargetFramework)' == 'net461' or '$(TargetFramework)' == 'netstandard2.0'">
13-
<PackageReference Include="IndexRange" Version="1.0.2" />
14-
</ItemGroup>
13+
</PropertyGroup>
1514

16-
</Project>
15+
<ItemGroup>
16+
<PackageReference Include="ApacheThrift" Version="0.14.1" />
17+
</ItemGroup>
18+
<ItemGroup
19+
Condition="'$(TargetFramework)' == 'net461' or '$(TargetFramework)' == 'netstandard2.0'">
20+
<PackageReference Include="IndexRange" Version="1.0.2" />
21+
</ItemGroup>
22+
23+
</Project>

src/Apache.IoTDB/Client.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ public class Client
88
public long SessionId { get; }
99
public long StatementId { get; }
1010
public TFramedTransport Transport { get; }
11+
public TEndPoint EndPoint { get; }
1112

12-
public Client(IClientRPCService.Client client, long sessionId, long statementId, TFramedTransport transport)
13+
public Client(IClientRPCService.Client client, long sessionId, long statementId, TFramedTransport transport, TEndPoint endpoint)
1314
{
1415
ServiceClient = client;
1516
SessionId = sessionId;
1617
StatementId = statementId;
1718
Transport = transport;
19+
EndPoint = endpoint;
1820
}
1921
}
2022
}

0 commit comments

Comments
 (0)