2020-10-28 07:38:24 +00:00
|
|
|
package master
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-10-29 04:39:41 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/errors"
|
2020-10-29 03:46:34 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/kv"
|
2020-10-28 07:38:24 +00:00
|
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/internalpb"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: get timestamp from timestampOracle
|
|
|
|
type Timestamp uint64
|
|
|
|
|
|
|
|
type baseTask struct {
|
|
|
|
kvBase *kv.Base
|
|
|
|
mt *metaTable
|
|
|
|
cv chan int
|
|
|
|
}
|
|
|
|
|
|
|
|
type task interface {
|
|
|
|
Type() internalpb.ReqType
|
|
|
|
Ts() (Timestamp, error)
|
2020-10-29 04:39:41 +00:00
|
|
|
Execute() error
|
|
|
|
WaitToFinish(ctx context.Context) error
|
|
|
|
Notify() error
|
|
|
|
NotifyTimeout() error
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 04:39:41 +00:00
|
|
|
func (bt *baseTask) Notify() error {
|
2020-10-28 07:38:24 +00:00
|
|
|
bt.cv <- 0
|
2020-10-29 04:39:41 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (bt *baseTask) NotifyTimeout() error {
|
|
|
|
bt.cv <- 0
|
|
|
|
return errors.New("request timeout")
|
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-10-29 04:39:41 +00:00
|
|
|
return nil
|
2020-10-28 07:38:24 +00:00
|
|
|
case <-bt.cv:
|
2020-10-29 04:39:41 +00:00
|
|
|
return nil
|
2020-10-28 07:38:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|