Skip to content

Commit

Permalink
release 3.00.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hitomizzz committed Jul 10, 2024
1 parent 4b47e2e commit 91d6d20
Show file tree
Hide file tree
Showing 20 changed files with 3,866 additions and 697 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ Go API 提供的最核心的接口是 `DolphinDB`。Go API 通过该接口在 `D

## 2. 安装依赖

Go API 需要运行在 golang 1.15 或以上版本的环境。
Go API 需要运行在 Go 1.15 或以上版本的环境。注意,Go API 只支持在 64 位的 Go 环境中运行
使用 `go get` 下载安装 `Go API`

```sh
Expand Down Expand Up @@ -605,6 +605,7 @@ func main() {
| GetPoolSize() | 获取连接数 |
| Close() | 关闭连接池 |
| IsClosed() | 检查连接池是否关闭 |
| RefreshTimeout(t time.Duration) | 重置超时时间 |

PoolOption 参数说明:

Expand All @@ -615,6 +616,7 @@ PoolOption 参数说明:
- LoadBalanceAddresses: 字符串数组,用于指定数据节点。
- EnableHighAvailability: 指定是否开启高可用。
- HighAvailabilitySites: 指定高可用节点地址,当从 Server 获取到的节点地址无法访问时,可通过该配置手动指定。
- Timeout: 指定每个任务执行的超时时间。

`Task` 封装了查看任务执行结果的相关方法。

Expand Down Expand Up @@ -1035,14 +1037,18 @@ err = writer.Insert("2", time.Date(2022, time.Month(1), 1, 1, 1, 0, 0, time.UTC)
#### GetUnwrittenData

```go
GetUnwrittenData() [][]model.DataType
GetUnwrittenData() [][]interface{}
```

函数说明:

返回一个嵌套列表,表示未写入服务器的数据。

注意:该方法获取到数据资源后,`MultiGoroutineTable` 将释放这些数据资源。
注意

1. 返回的结果以 `MultiGoroutineTable` 存储的中间变量的形式存在,只能给写入相同 schema 表的 `MultiGoroutineTable` 使用。

2. 该方法获取到数据资源后,`MultiGoroutineTable` 将释放这些数据资源。

示例:

Expand All @@ -1053,12 +1059,12 @@ unwrittenData := writer.GetUnwrittenData()
#### InsertUnwrittenData

```go
InsertUnwrittenData(records [][]model.DataType) error
InsertUnwrittenData(records [][]interface{}) error
```

函数说明:

将数据插入数据表。返回值同 insert 方法。与 insert 方法的区别在于,insert 只能插入单行数据,而 insertUnwrittenData 可以同时插入多行数据
将通过 GetUnwrittenData 得到的数据插入数据表。返回值同 insert 方法

参数说明:

Expand Down
17 changes: 17 additions & 0 deletions api/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"strings"
"sync"
"time"

"github.com/dolphindb/api-go/dialer"
"github.com/dolphindb/api-go/model"
Expand All @@ -19,6 +20,7 @@ type DBConnectionPool struct {
loadBalanceAddresses []string

connections chan dialer.Conn
timeout time.Duration
}

// PoolOption helps you to configure DBConnectionPool by calling NewDBConnectionPool.
Expand Down Expand Up @@ -47,13 +49,24 @@ type PoolOption struct {

// addresses of load balance
LoadBalanceAddresses []string

// refresh time of every connection
Timeout time.Duration
}

// NewDBConnectionPool inits a DBConnectionPool object and configures it with opt, finally returns it.
func NewDBConnectionPool(opt *PoolOption) (*DBConnectionPool, error) {
timeout := time.Minute
if opt.Timeout != 0 {
if opt.Timeout < 0 {
return nil, errors.New("Timeout must be equal or greater than 0")
}
timeout = opt.Timeout
}
p := &DBConnectionPool{
isLoadBalance: opt.LoadBalance,
loadBalanceAddresses: opt.LoadBalanceAddresses,
timeout: timeout,
}

if opt.PoolSize < 1 {
Expand Down Expand Up @@ -107,6 +120,9 @@ func newConn(addr string, opt *PoolOption) (dialer.Conn, error) {
return conn, nil
}

func (d *DBConnectionPool) RefreshTimeout(t time.Duration) {
d.timeout = t
}
// Execute executes all task by connections with DBConnectionPool.
func (d *DBConnectionPool) Execute(tasks []*Task) error {
wg := sync.WaitGroup{}
Expand All @@ -118,6 +134,7 @@ func (d *DBConnectionPool) Execute(tasks []*Task) error {
wg.Add(1)
go func(task *Task) {
conn := <-d.connections
conn.RefreshTimeout(d.timeout)
task.result, task.err = d.RunTask(conn, task)
d.connections <- conn
wg.Done()
Expand Down
4 changes: 2 additions & 2 deletions api/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
)

func generateDBName() string {
u1 := uuid.Must(uuid.NewV4())
u1 := uuid.NewV4()
return fmt.Sprintf("db_%s", u1.String()[:8])
}

func generateTableName() string {
u1 := uuid.Must(uuid.NewV4())
u1 := uuid.NewV4()
return fmt.Sprintf("tb_%s", u1.String()[:8])
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/dolphindb/api-go
go 1.15

require (
github.com/satori/go.uuid v1.2.1-0.20181016170032-d91630c85102
github.com/satori/go.uuid v1.1.0
github.com/smallnest/chanx v1.0.0
github.com/stretchr/testify v1.7.2
)
Expand Down
Loading

0 comments on commit 91d6d20

Please sign in to comment.