Skip to content

Commit

Permalink
fix: Adds deallocate
Browse files Browse the repository at this point in the history
  • Loading branch information
salehkhazaei committed Dec 25, 2023
1 parent 77cadaa commit 8e039bd
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pkg/kaytu-es-sdk/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func CheckError(resp *opensearchapi.Response) error {

var e ErrorResponse
if err := json.Unmarshal(data, &e); err != nil {
return fmt.Errorf(string(data))
return fmt.Errorf("%s: %s", resp.String(), string(data))
}
if strings.TrimSpace(e.Info.Type) == "" && strings.TrimSpace(e.Info.Reason) == "" {
return fmt.Errorf(string(data))
return fmt.Errorf("%s: %s", resp.String(), string(data))
}

return e
Expand Down Expand Up @@ -522,6 +522,23 @@ func (p *BaseESPaginator) Search(ctx context.Context, response any) error {
return p.SearchWithLog(ctx, response, false)
}

func (p *BaseESPaginator) Deallocate(ctx context.Context) error {
if p.pitID != "" {
pitRaw, _, err := p.client.PointInTime.Delete(
p.client.PointInTime.Delete.WithPitID(p.pitID),
)
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
}

func (p *BaseESPaginator) SearchWithLog(ctx context.Context, response any, doLog bool) error {
if p.done {
return errors.New("no more page to query")
Expand Down

0 comments on commit 8e039bd

Please sign in to comment.