Skip to content

Commit

Permalink
fix: Adds es pit close
Browse files Browse the repository at this point in the history
  • Loading branch information
salehkhazaei committed Dec 25, 2023
1 parent 8e039bd commit 688d219
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions pkg/kaytu-es-sdk/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,12 +528,41 @@ func (p *BaseESPaginator) Deallocate(ctx context.Context) error {
p.client.PointInTime.Delete.WithPitID(p.pitID),
)
if err != nil {
LogWarn(ctx, fmt.Sprintf("failed to delete PIT %v", err))
LogWarn(ctx, fmt.Sprintf("Deallocate.Err err=%v pitRaw=%v", err, pitRaw))
return err
} else if errIf := CheckError(pitRaw); errIf != nil {
LogWarn(ctx, fmt.Sprintf("failed to delete PIT %v", errIf))
return errIf
} else if errIf := CheckErrorWithContext(pitRaw, ctx); errIf != nil {
LogWarn(ctx, fmt.Sprintf("Deallocate.CheckErr err=%v errIf=%v pitRaw=%s", err, errIf, pitRaw.String()))

if pitRaw.StatusCode != http.StatusMethodNotAllowed {
return errIf
}

// try elasticsearch api instead
req := esapi.ClosePointInTimeRequest{
Body: strings.NewReader(fmt.Sprintf(`{"id": "%s"}`, p.pitID)),
}
res, err2 := req.Do(ctx, p.client.Transport)
defer ESCloseSafe(res)
if err2 != nil {
if errIf != nil {
return errIf
}
return err
} else if err2 := ESCheckError(res); err2 != nil {
if errIf != nil {
return errIf
}
return err
}
}
//
//if err != nil {
// LogWarn(ctx, fmt.Sprintf("failed to delete PIT %v", err))
// return err
//} else if errIf := CheckError(pitRaw); errIf != nil {
// LogWarn(ctx, fmt.Sprintf("failed to delete PIT %v", errIf))
// return errIf
//}
p.pitID = ""
}
return nil
Expand Down

0 comments on commit 688d219

Please sign in to comment.