Revert "Unistore : Ensure Watch works in HA mode." (#94097)
Revert "Unistore : Ensure Watch works in HA mode. (#93428)"
This reverts commit 0a26c9e9ae.
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
)
|
||||
|
||||
const trace_prefix = "sql.resource."
|
||||
const defaultPollingInterval = 100 * time.Millisecond
|
||||
|
||||
type Backend interface {
|
||||
resource.StorageBackend
|
||||
@@ -31,9 +30,8 @@ type Backend interface {
|
||||
}
|
||||
|
||||
type BackendOptions struct {
|
||||
DBProvider db.DBProvider
|
||||
Tracer trace.Tracer
|
||||
PollingInterval time.Duration
|
||||
DBProvider db.DBProvider
|
||||
Tracer trace.Tracer
|
||||
}
|
||||
|
||||
func NewBackend(opts BackendOptions) (Backend, error) {
|
||||
@@ -45,17 +43,12 @@ func NewBackend(opts BackendOptions) (Backend, error) {
|
||||
}
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
pollingInterval := opts.PollingInterval
|
||||
if pollingInterval == 0 {
|
||||
pollingInterval = defaultPollingInterval
|
||||
}
|
||||
return &backend{
|
||||
done: ctx.Done(),
|
||||
cancel: cancel,
|
||||
log: log.New("sql-resource-server"),
|
||||
tracer: opts.Tracer,
|
||||
dbProvider: opts.DBProvider,
|
||||
pollingInterval: pollingInterval,
|
||||
done: ctx.Done(),
|
||||
cancel: cancel,
|
||||
log: log.New("sql-resource-server"),
|
||||
tracer: opts.Tracer,
|
||||
dbProvider: opts.DBProvider,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -77,7 +70,6 @@ type backend struct {
|
||||
|
||||
// watch streaming
|
||||
//stream chan *resource.WatchEvent
|
||||
pollingInterval time.Duration
|
||||
}
|
||||
|
||||
func (b *backend) Init(ctx context.Context) error {
|
||||
@@ -188,6 +180,7 @@ func (b *backend) create(ctx context.Context, event resource.WriteEvent) (int64,
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
return newVersion, err
|
||||
}
|
||||
|
||||
@@ -519,7 +512,8 @@ func (b *backend) WatchWriteEvents(ctx context.Context) (<-chan *resource.Writte
|
||||
}
|
||||
|
||||
func (b *backend) poller(ctx context.Context, since groupResourceRV, stream chan<- *resource.WrittenEvent) {
|
||||
t := time.NewTicker(b.pollingInterval)
|
||||
interval := 100 * time.Millisecond // TODO make this configurable
|
||||
t := time.NewTicker(interval)
|
||||
defer close(stream)
|
||||
defer t.Stop()
|
||||
|
||||
@@ -532,7 +526,7 @@ func (b *backend) poller(ctx context.Context, since groupResourceRV, stream chan
|
||||
grv, err := b.listLatestRVs(ctx)
|
||||
if err != nil {
|
||||
b.log.Error("get the latest resource version", "err", err)
|
||||
t.Reset(b.pollingInterval)
|
||||
t.Reset(interval)
|
||||
continue
|
||||
}
|
||||
for group, items := range grv {
|
||||
@@ -549,7 +543,7 @@ func (b *backend) poller(ctx context.Context, since groupResourceRV, stream chan
|
||||
next, err := b.poll(ctx, group, resource, since[group][resource], stream)
|
||||
if err != nil {
|
||||
b.log.Error("polling for resource", "err", err)
|
||||
t.Reset(b.pollingInterval)
|
||||
t.Reset(interval)
|
||||
continue
|
||||
}
|
||||
if next > since[group][resource] {
|
||||
@@ -558,7 +552,7 @@ func (b *backend) poller(ctx context.Context, since groupResourceRV, stream chan
|
||||
}
|
||||
}
|
||||
|
||||
t.Reset(b.pollingInterval)
|
||||
t.Reset(interval)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -642,8 +636,7 @@ func (b *backend) poll(ctx context.Context, grp string, res string, since int64,
|
||||
Resource: rec.Key.Resource,
|
||||
Name: rec.Key.Name,
|
||||
},
|
||||
Type: resource.WatchEvent_Type(rec.Action),
|
||||
PreviousRV: rec.PreviousRV,
|
||||
Type: resource.WatchEvent_Type(rec.Action),
|
||||
},
|
||||
ResourceVersion: rec.ResourceVersion,
|
||||
// Timestamp: , // TODO: add timestamp
|
||||
@@ -670,16 +663,15 @@ func resourceVersionAtomicInc(ctx context.Context, x db.ContextExecer, d sqltemp
|
||||
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
// if there wasn't a row associated with the given resource, we create one with
|
||||
// version 2 to match the etcd behavior.
|
||||
// version 1
|
||||
if _, err = dbutil.Exec(ctx, x, sqlResourceVersionInsert, sqlResourceVersionRequest{
|
||||
SQLTemplate: sqltemplate.New(d),
|
||||
Group: key.Group,
|
||||
Resource: key.Resource,
|
||||
resourceVersion: &resourceVersion{1},
|
||||
SQLTemplate: sqltemplate.New(d),
|
||||
Group: key.Group,
|
||||
Resource: key.Resource,
|
||||
}); err != nil {
|
||||
return 0, fmt.Errorf("insert into resource_version: %w", err)
|
||||
}
|
||||
return 2, nil
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user