mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-05 05:18:52 +08:00
2df04b6947
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package master
|
|
|
|
import (
|
|
"context"
|
|
"github.com/zilliztech/milvus-distributed/internal/master/kv"
|
|
"github.com/zilliztech/milvus-distributed/internal/proto/commonpb"
|
|
"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)
|
|
Execute() commonpb.Status
|
|
WaitToFinish(ctx context.Context) commonpb.Status
|
|
Notify() commonpb.Status
|
|
}
|
|
|
|
func (bt *baseTask) Notify() commonpb.Status {
|
|
bt.cv <- 0
|
|
return commonpb.Status{
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
}
|
|
}
|
|
|
|
func (bt *baseTask) WaitToFinish(ctx context.Context) commonpb.Status {
|
|
for {
|
|
select {
|
|
case <-ctx.Done():
|
|
return commonpb.Status{
|
|
// TODO: if to return unexpected error
|
|
ErrorCode: commonpb.ErrorCode_UNEXPECTED_ERROR,
|
|
}
|
|
case <-bt.cv:
|
|
return commonpb.Status{
|
|
ErrorCode: commonpb.ErrorCode_SUCCESS,
|
|
}
|
|
}
|
|
}
|
|
}
|