2020-04-11 11:33:10 +03:00
|
|
|
package sync
|
2020-03-18 19:39:36 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2020-07-27 15:22:00 +03:00
|
|
|
"github.com/micro/go-micro/v3/store"
|
2020-03-18 19:39:36 +03:00
|
|
|
)
|
|
|
|
|
2020-04-11 11:33:10 +03:00
|
|
|
// Options represents Sync options
|
2020-03-18 19:39:36 +03:00
|
|
|
type Options struct {
|
2020-04-11 11:33:10 +03:00
|
|
|
// Stores represents layers in the sync in ascending order. L0, L1, L2, etc
|
2020-03-18 19:39:36 +03:00
|
|
|
Stores []store.Store
|
|
|
|
// SyncInterval is the duration between syncs from L0 to L1
|
|
|
|
SyncInterval time.Duration
|
|
|
|
// SyncMultiplier is the multiplication factor between each store.
|
|
|
|
SyncMultiplier int64
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:33:10 +03:00
|
|
|
// Option sets Sync Options
|
2020-03-18 19:39:36 +03:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
2020-04-11 11:33:10 +03:00
|
|
|
// Stores sets the layers that make up the sync
|
2020-03-18 19:39:36 +03:00
|
|
|
func Stores(stores ...store.Store) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.Stores = make([]store.Store, len(stores))
|
|
|
|
for i, s := range stores {
|
|
|
|
o.Stores[i] = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SyncInterval sets the duration between syncs from L0 to L1
|
|
|
|
func SyncInterval(d time.Duration) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.SyncInterval = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-11 11:33:10 +03:00
|
|
|
// SyncMultiplier sets the multiplication factor for time to wait each sync layer
|
2020-03-18 19:39:36 +03:00
|
|
|
func SyncMultiplier(i int64) Option {
|
|
|
|
return func(o *Options) {
|
|
|
|
o.SyncMultiplier = i
|
|
|
|
}
|
|
|
|
}
|