You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@iotdb.apache.org by "fuliwen (via GitHub)" <gi...@apache.org> on 2023/02/16 08:47:40 UTC

[GitHub] [iotdb-client-go] fuliwen opened a new pull request, #75: Rel/0.13

fuliwen opened a new pull request, #75:
URL: https://github.com/apache/iotdb-client-go/pull/75

   added session pool and example


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb-client-go] citrusreticulata commented on a diff in pull request #75: [To rel/0.13] Add SessionPool and example

Posted by "citrusreticulata (via GitHub)" <gi...@apache.org>.
citrusreticulata commented on code in PR #75:
URL: https://github.com/apache/iotdb-client-go/pull/75#discussion_r1109436680


##########
client/sessionpool.go:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package client
+
+import (
+	"errors"
+	"log"
+	"runtime"
+	"time"
+)
+
+var errTimeout = errors.New("get session timeout")
+var errPoolClosed = errors.New("sessionPool has closed")
+var defaultMultiple = 5
+
+type SessionPool struct {
+	config                      *PoolConfig
+	maxSize                     int
+	waitToGetSessionTimeoutInMs int
+	enableCompression           bool
+	connectionTimeoutInMs       int
+	ch                          chan Session
+	sem                         chan int8
+}
+
+type PoolConfig struct {
+	Host            string
+	Port            string
+	NodeUrls        []string
+	UserName        string
+	Password        string
+	FetchSize       int32
+	TimeZone        string
+	ConnectRetryMax int
+}
+
+func NewSessionPool(conf *PoolConfig, maxSize, connectionTimeoutInMs, waitToGetSessionTimeoutInMs int,
+	enableCompression bool) SessionPool {
+	if maxSize <= 0 {
+		maxSize = runtime.NumCPU() * defaultMultiple
+	}
+	var ch = make(chan Session, maxSize)
+	var sem = make(chan int8, maxSize)
+	return SessionPool{
+		config:                      conf,
+		maxSize:                     maxSize,
+		waitToGetSessionTimeoutInMs: waitToGetSessionTimeoutInMs,
+		connectionTimeoutInMs:       connectionTimeoutInMs,
+		enableCompression:           enableCompression,
+		ch:                          ch,
+		sem:                         sem,
+	}
+}
+
+func (spool *SessionPool) GetSession() (session Session, err error) {
+	for {
+		select {
+		case spool.sem <- 1:
+			select {
+			case session, ok := <-spool.ch:
+				if ok {
+					return session, nil
+				} else {
+					log.Println("sessonpool has closed")

Review Comment:
   ```suggestion
   					log.Println("sessionpool has closed")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb-client-go] iotopo commented on pull request #75: Rel/0.13

Posted by "iotopo (via GitHub)" <gi...@apache.org>.
iotopo commented on PR #75:
URL: https://github.com/apache/iotdb-client-go/pull/75#issuecomment-1433966926

   @fuliwen @HTHou 代码里 ConstructSession 没有提供集群支持吗?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb-client-go] qiaojialin commented on a diff in pull request #75: [To rel/0.13] Add SessionPool and example

Posted by "qiaojialin (via GitHub)" <gi...@apache.org>.
qiaojialin commented on code in PR #75:
URL: https://github.com/apache/iotdb-client-go/pull/75#discussion_r1109504691


##########
client/sessionpool.go:
##########
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package client
+
+import (
+	"errors"
+	"log"
+	"runtime"
+	"time"
+)
+
+var errTimeout = errors.New("get session timeout")
+var errPoolClosed = errors.New("sessionPool has closed")
+var defaultMultiple = 5
+
+type SessionPool struct {
+	config                      *PoolConfig
+	maxSize                     int
+	waitToGetSessionTimeoutInMs int
+	enableCompression           bool
+	connectionTimeoutInMs       int
+	ch                          chan Session
+	sem                         chan int8
+}
+
+type PoolConfig struct {
+	Host            string
+	Port            string
+	NodeUrls        []string
+	UserName        string
+	Password        string
+	FetchSize       int32
+	TimeZone        string
+	ConnectRetryMax int
+}
+
+func NewSessionPool(conf *PoolConfig, maxSize, connectionTimeoutInMs, waitToGetSessionTimeoutInMs int,
+	enableCompression bool) SessionPool {
+	if maxSize <= 0 {
+		maxSize = runtime.NumCPU() * defaultMultiple
+	}
+	var ch = make(chan Session, maxSize)
+	var sem = make(chan int8, maxSize)
+	return SessionPool{
+		config:                      conf,
+		maxSize:                     maxSize,
+		waitToGetSessionTimeoutInMs: waitToGetSessionTimeoutInMs,
+		connectionTimeoutInMs:       connectionTimeoutInMs,
+		enableCompression:           enableCompression,
+		ch:                          ch,
+		sem:                         sem,
+	}
+}
+
+func (spool *SessionPool) GetSession() (session Session, err error) {
+	for {
+		select {
+		case spool.sem <- 1:
+			select {
+			case session, ok := <-spool.ch:
+				if ok {
+					return session, nil
+				} else {
+					log.Println("sessonpool has closed")

Review Comment:
   ```suggestion
   					log.Println("sessionpool has closed")
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb-client-go] qiaojialin merged pull request #75: [To rel/0.13] Add SessionPool and example

Posted by "qiaojialin (via GitHub)" <gi...@apache.org>.
qiaojialin merged PR #75:
URL: https://github.com/apache/iotdb-client-go/pull/75


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [iotdb-client-go] fuliwen commented on pull request #75: Rel/0.13

Posted by "fuliwen (via GitHub)" <gi...@apache.org>.
fuliwen commented on PR #75:
URL: https://github.com/apache/iotdb-client-go/pull/75#issuecomment-1432723753

   jira: https://issues.apache.org/jira/browse/IOTDB-5503


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org