You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by qi...@apache.org on 2023/02/28 09:50:14 UTC

[iotdb] branch rel/0.13 updated: user guide adds sessionPool description (#9160)

This is an automated email from the ASF dual-hosted git repository.

qiaojialin pushed a commit to branch rel/0.13
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/rel/0.13 by this push:
     new 234cd13228 user guide adds sessionPool description (#9160)
234cd13228 is described below

commit 234cd13228a559a3f11a32aaefc5c7c5433d5dbe
Author: Liwen Fu <fu...@gmail.com>
AuthorDate: Tue Feb 28 17:50:06 2023 +0800

    user guide adds sessionPool description (#9160)
---
 docs/UserGuide/API/Programming-Go-Native-API.md    | 47 ++++++++++++++++++
 docs/zh/UserGuide/API/Programming-Go-Native-API.md | 55 ++++++++++++++++++++++
 2 files changed, 102 insertions(+)

diff --git a/docs/UserGuide/API/Programming-Go-Native-API.md b/docs/UserGuide/API/Programming-Go-Native-API.md
index 76818502cd..dca270713b 100644
--- a/docs/UserGuide/API/Programming-Go-Native-API.md
+++ b/docs/UserGuide/API/Programming-Go-Native-API.md
@@ -63,3 +63,50 @@ curl -o session_example.go -L https://github.com/apache/iotdb-client-go/raw/main
 go run session_example.go
 ```
 
+### How to Use the SessionPool
+SessionPool is a wrapper of a Session Set. Using SessionPool, the user do not need to consider how to reuse a session connection.
+If there is no available connections and the pool reaches its max size, the all methods will hang until there is a available connection.
+The PutBack method must be called after use
+
+#### New sessionPool
+
+```golang
+config := &client.PoolConfig{
+    Host:     host,
+    Port:     port,
+    UserName: user,
+    Password: password,
+}
+sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false)
+```
+
+#### Get session through sessionPool, putback after use
+
+set storage group
+
+```golang
+session, err := sessionPool.GetSession()
+defer sessionPool.PutBack(session)
+if err == nil {
+    session.SetStorageGroup(sg)
+}
+```
+
+query statement
+
+```golang
+var timeout int64 = 1000
+session, err := sessionPool.GetSession()
+defer sessionPool.PutBack(session)
+if err != nil {
+    log.Print(err)
+    return
+}
+sessionDataSet, err := session.ExecuteQueryStatement(sql, &timeout)
+if err == nil {
+    defer sessionDataSet.Close()
+    printDataSet1(sessionDataSet)
+} else {
+    log.Println(err)
+}
+```
\ No newline at end of file
diff --git a/docs/zh/UserGuide/API/Programming-Go-Native-API.md b/docs/zh/UserGuide/API/Programming-Go-Native-API.md
index 1fa5423d03..82de568eac 100644
--- a/docs/zh/UserGuide/API/Programming-Go-Native-API.md
+++ b/docs/zh/UserGuide/API/Programming-Go-Native-API.md
@@ -81,3 +81,58 @@ go mod tidy
 # 编译并运行程序
 go run session_example.go
 ```
+
+### SessionPool
+ * 通过SessionPool管理session,用户不需要考虑如何重用session
+ * 当到达pool的最大值时,获取session的请求会阻塞 
+ * 注意:session使用完成后需要调用PutBack方法
+
+#### 创建sessionPool
+
+```golang
+
+config := &client.PoolConfig{
+    Host:     host,
+    Port:     port,
+    UserName: user,
+    Password: password,
+}
+sessionPool = client.NewSessionPool(config, 3, 60000, 60000, false)
+
+```
+
+#### 使用sessionPool获取session,使用完手动调用PutBack
+
+* 设置存储组
+
+```golang
+
+session, err := sessionPool.GetSession()
+defer sessionPool.PutBack(session)
+if err == nil {
+    session.SetStorageGroup(sg)
+}
+
+```
+
+* 查询
+
+```golang
+
+var timeout int64 = 1000
+session, err := sessionPool.GetSession()
+defer sessionPool.PutBack(session)
+if err != nil {
+    log.Print(err)
+    return
+}
+sessionDataSet, err := session.ExecuteQueryStatement(sql, &timeout)
+if err == nil {
+    defer sessionDataSet.Close()
+    printDataSet1(sessionDataSet)
+} else {
+    log.Println(err)
+}
+
+```
+