mirror of
https://gitee.com/milvus-io/milvus.git
synced 2025-12-07 17:48:29 +08:00
enhance: using timer instead of tickers for need to be executed successfully once (#35534)
https://github.com/milvus-io/milvus/issues/35533 Signed-off-by: fengjun2016 <jornfeng@gmail.com>
This commit is contained in:
parent
337e065902
commit
b96db798b9
@ -34,13 +34,13 @@ type LoadTask struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *LoadTask) Await(ctx context.Context) error {
|
func (t *LoadTask) Await(ctx context.Context) error {
|
||||||
ticker := time.NewTicker(t.interval)
|
timer := time.NewTimer(t.interval)
|
||||||
defer ticker.Stop()
|
defer timer.Stop()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-timer.C:
|
||||||
loaded := false
|
loaded := false
|
||||||
t.client.callService(func(milvusService milvuspb.MilvusServiceClient) error {
|
err := t.client.callService(func(milvusService milvuspb.MilvusServiceClient) error {
|
||||||
resp, err := milvusService.GetLoadingProgress(ctx, &milvuspb.GetLoadingProgressRequest{
|
resp, err := milvusService.GetLoadingProgress(ctx, &milvuspb.GetLoadingProgressRequest{
|
||||||
CollectionName: t.collectionName,
|
CollectionName: t.collectionName,
|
||||||
PartitionNames: t.partitionNames,
|
PartitionNames: t.partitionNames,
|
||||||
@ -51,10 +51,13 @@ func (t *LoadTask) Await(ctx context.Context) error {
|
|||||||
loaded = resp.GetProgress() == 100
|
loaded = resp.GetProgress() == 100
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if loaded {
|
if loaded {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ticker.Reset(t.interval)
|
timer.Reset(t.interval)
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
@ -134,13 +137,13 @@ type FlushTask struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *FlushTask) Await(ctx context.Context) error {
|
func (t *FlushTask) Await(ctx context.Context) error {
|
||||||
ticker := time.NewTicker(t.interval)
|
timer := time.NewTimer(t.interval)
|
||||||
defer ticker.Stop()
|
defer timer.Stop()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-timer.C:
|
||||||
flushed := false
|
flushed := false
|
||||||
t.client.callService(func(milvusService milvuspb.MilvusServiceClient) error {
|
err := t.client.callService(func(milvusService milvuspb.MilvusServiceClient) error {
|
||||||
resp, err := milvusService.GetFlushState(ctx, &milvuspb.GetFlushStateRequest{
|
resp, err := milvusService.GetFlushState(ctx, &milvuspb.GetFlushStateRequest{
|
||||||
CollectionName: t.collectionName,
|
CollectionName: t.collectionName,
|
||||||
SegmentIDs: t.segmentIDs,
|
SegmentIDs: t.segmentIDs,
|
||||||
@ -154,10 +157,13 @@ func (t *FlushTask) Await(ctx context.Context) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if flushed {
|
if flushed {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ticker.Reset(t.interval)
|
timer.Reset(t.interval)
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user