milvus/internal/master/task.go
bigsheeper 2df04b6947 Add collection creation, and refactor master
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
2020-10-28 15:38:24 +08:00

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,
}
}
}
}