mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
improve concurrent access and high availability of aptly with the help of the characteristics of etcd
46 lines
835 B
Go
46 lines
835 B
Go
package etcddb
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/aptly-dev/aptly/database"
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
|
)
|
|
|
|
var Ctx = context.TODO()
|
|
|
|
func internalOpen(url string) (*clientv3.Client, error) {
|
|
cfg := clientv3.Config{
|
|
Endpoints: []string{url},
|
|
DialTimeout: 30 * time.Second,
|
|
MaxCallSendMsgSize: 2048 * 1024 * 1024,
|
|
MaxCallRecvMsgSize: 2048 * 1024 * 1024,
|
|
DialKeepAliveTimeout: 7200 * time.Second,
|
|
}
|
|
|
|
cli, err := clientv3.New(cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return cli, nil
|
|
}
|
|
|
|
func NewDB(url string) (database.Storage, error) {
|
|
cli, err := internalOpen(url)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &EtcDStorage{url, cli}, nil
|
|
}
|
|
|
|
func NewOpenDB(url string) (database.Storage, error) {
|
|
db, err := NewDB(url)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return db, nil
|
|
}
|