etcd: redesign commit queue to make it more robust and scalable
This commit builds on the ideas of @cfromknecht in lnd/5153. The addition is that the design is now simpler and more robust by queueing up everything, but allowing maximal parallelism where txns don't block. Furthermore the commit makes CommitQueue.Done() private essentially removing the need to understand the queue externally.
This commit is contained in:
5 files changed
+136
-62
No files matched your search
+9
-2
@@ -122,6 +122,7 @@ func (c *commitStatsCollector) callback(succ bool, stats CommitStats) {
|
||||
type db struct {
|
||||
cfg Config
|
||||
ctx context.Context
|
||||
cancel func()
|
||||
cli *clientv3.Client
|
||||
commitStatsCollector *commitStatsCollector
|
||||
txQueue *commitQueue
|
||||
@@ -135,7 +136,6 @@ var _ walletdb.DB = (*db)(nil)
|
||||
// config. If etcd connection cannot be established, then returns error.
|
||||
func newEtcdBackend(ctx context.Context, cfg Config) (*db, error) {
|
||||
clientCfg := clientv3.Config{
|
||||
Context: ctx,
|
||||
Endpoints: []string{cfg.Host},
|
||||
DialTimeout: etcdConnectionTimeout,
|
||||
Username: cfg.User,
|
||||
@@ -158,8 +158,11 @@ func newEtcdBackend(ctx context.Context, cfg Config) (*db, error) {
|
||||
clientCfg.TLS = tlsConfig
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
clientCfg.Context = ctx
|
||||
cli, err := clientv3.New(clientCfg)
|
||||
if err != nil {
|
||||
cancel()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -171,6 +174,7 @@ func newEtcdBackend(ctx context.Context, cfg Config) (*db, error) {
|
||||
backend := &db{
|
||||
cfg: cfg,
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
cli: cli,
|
||||
txQueue: NewCommitQueue(ctx),
|
||||
}
|
||||
@@ -296,5 +300,8 @@ func (db *db) Copy(w io.Writer) error {
|
||||
// Close cleanly shuts down the database and syncs all data.
|
||||
// This function is part of the walletdb.Db interface implementation.
|
||||
func (db *db) Close() error {
|
||||
return db.cli.Close()
|
||||
err := db.cli.Close()
|
||||
db.cancel()
|
||||
db.txQueue.Stop()
|
||||
return err
|
||||
}
|
||||
Reference in new issue
Block a user