mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-20 19:38:39 +00:00
feat: Add etcd database support
improve concurrent access and high availability of aptly with the help of the characteristics of etcd
This commit is contained in:
45
database/etcddb/database.go
Normal file
45
database/etcddb/database.go
Normal file
@@ -0,0 +1,45 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user