-
Notifications
You must be signed in to change notification settings - Fork 38
Call VerifySuccess before return to user #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,6 @@ package client | |
| import ( | ||
| "log" | ||
| "sync/atomic" | ||
|
|
||
| "github.com/apache/iotdb-client-go/v2/common" | ||
| ) | ||
|
|
||
| // TableSessionPool manages a pool of ITableSession instances, enabling efficient | ||
|
|
@@ -81,17 +79,16 @@ type PooledTableSession struct { | |
| // - tablet: A pointer to a Tablet containing time-series data to be inserted. | ||
| // | ||
| // Returns: | ||
| // - r: A pointer to TSStatus indicating the execution result. | ||
| // - err: An error if an issue occurs during the operation. | ||
| func (s *PooledTableSession) Insert(tablet *Tablet) (r *common.TSStatus, err error) { | ||
| r, err = s.session.insertRelationalTablet(tablet) | ||
| func (s *PooledTableSession) Insert(tablet *Tablet) error { | ||
| err := s.session.insertRelationalTablet(tablet) | ||
| if err == nil { | ||
| return | ||
| return nil | ||
| } | ||
| s.sessionPool.dropSession(s.session) | ||
| atomic.StoreInt32(&s.closed, 1) | ||
| s.session = Session{} | ||
| return | ||
| return err | ||
| } | ||
|
|
||
| // ExecuteNonQueryStatement executes a non-query SQL statement, such as a DDL or DML command. | ||
|
|
@@ -100,17 +97,16 @@ func (s *PooledTableSession) Insert(tablet *Tablet) (r *common.TSStatus, err err | |
| // - sql: The SQL statement to execute. | ||
| // | ||
| // Returns: | ||
| // - r: A pointer to TSStatus indicating the execution result. | ||
| // - err: An error if an issue occurs during the operation. | ||
| func (s *PooledTableSession) ExecuteNonQueryStatement(sql string) (r *common.TSStatus, err error) { | ||
| r, err = s.session.ExecuteNonQueryStatement(sql) | ||
| func (s *PooledTableSession) ExecuteNonQueryStatement(sql string) error { | ||
| err := s.session.ExecuteNonQueryStatement(sql) | ||
| if err == nil { | ||
| return | ||
| return nil | ||
| } | ||
| s.sessionPool.dropSession(s.session) | ||
| atomic.StoreInt32(&s.closed, 1) | ||
| s.session = Session{} | ||
| return | ||
| return err | ||
|
Comment on lines
+101
to
+109
|
||
| } | ||
|
|
||
| // ExecuteQueryStatement executes a query SQL statement and returns the result set. | ||
|
|
@@ -140,8 +136,8 @@ func (s *PooledTableSession) ExecuteQueryStatement(sql string, timeoutInMs *int6 | |
| func (s *PooledTableSession) Close() error { | ||
| if atomic.CompareAndSwapInt32(&s.closed, 0, 1) { | ||
| if s.session.config.Database != s.sessionPool.config.Database && s.sessionPool.config.Database != "" { | ||
| r, err := s.session.ExecuteNonQueryStatement("use " + s.sessionPool.config.Database) | ||
| if r.Code == ExecuteStatementError || err != nil { | ||
| err := s.session.ExecuteNonQueryStatement("use " + s.sessionPool.config.Database) | ||
| if err != nil { | ||
| log.Println("Failed to change back database by executing: use ", s.sessionPool.config.Database) | ||
| s.session.Close() | ||
| return nil | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PooledTableSession.Insertnow drops/invalidates the pooled session on any returned error. SinceinsertRelationalTabletnow callsVerifySuccessinternally, non-success server status codes (e.g., user/SQL/data errors) will also cause the session to be dropped even though the connection is still healthy. Consider only dropping the session for transport/connection errors, or otherwise preserve a way to distinguish retryable/connection failures from application-level status errors.