2020-10-28 07:38:24 +00:00
|
|
|
package master
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-11-03 06:53:36 +00:00
|
|
|
|
2021-01-16 07:06:19 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/errors"
|
2020-10-28 07:38:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: get timestamp from timestampOracle
|
|
|
|
|
|
|
|
type baseTask struct {
|
2020-11-20 09:10:24 +00:00
|
|
|
sch *ddRequestScheduler
|
|
|
|
mt *metaTable
|
|
|
|
cv chan error
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type task interface {
|
2021-01-16 07:06:19 +00:00
|
|
|
Type() commonpb.MsgType
|
2020-10-28 07:38:24 +00:00
|
|
|
Ts() (Timestamp, error)
|
2020-10-29 04:39:41 +00:00
|
|
|
Execute() error
|
|
|
|
WaitToFinish(ctx context.Context) error
|
2020-11-12 03:18:23 +00:00
|
|
|
Notify(err error)
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
2020-11-12 03:18:23 +00:00
|
|
|
func (bt *baseTask) Notify(err error) {
|
|
|
|
bt.cv <- err
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
func (bt *baseTask) WaitToFinish(ctx context.Context) error {
|
2020-10-28 07:38:24 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
2020-11-12 03:18:23 +00:00
|
|
|
return errors.Errorf("context done")
|
|
|
|
case err, ok := <-bt.cv:
|
|
|
|
if !ok {
|
|
|
|
return errors.Errorf("notify chan closed")
|
|
|
|
}
|
|
|
|
return err
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|