From ff86f82ef278c3a9de24dca46c5d116465a8d13c Mon Sep 17 00:00:00 2001 From: Todd Gruben Date: Sun, 23 May 2021 10:27:50 -0500 Subject: [PATCH] applied ben's suggestions --- api.go | 18 +++++++++++++----- ctl/restore.go | 2 +- http/handler.go | 5 ----- index.go | 4 ---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/api.go b/api.go index 1f3bbdfcd..35ff82b20 100644 --- a/api.go +++ b/api.go @@ -2246,11 +2246,19 @@ func (api *API) RestoreShard(ctx context.Context, indexName string, shard uint64 if err != nil { return err } - w := bufio.NewWriter(o) - //close db if open - _, err = io.Copy(w, rd) - w.Flush() - o.Close() + defer o.Close() + + bw := bufio.NewWriter(o) + if _, err = io.Copy(bw, rd); err != nil { + return err + } else if err := bw.Flush(); err != nil { + return err + } else if err := o.Sync(); err != nil { + return err + } else if err := o.Close(); err != nil { + return err + } + if err != nil { _ = os.Remove(tempPath) return err diff --git a/ctl/restore.go b/ctl/restore.go index d4ff058bb..7793f39e6 100644 --- a/ctl/restore.go +++ b/ctl/restore.go @@ -120,7 +120,7 @@ func (cmd *RestoreCommand) Run(ctx context.Context) error { return err } default: - panic("UNKNOWN " + record[0]) + return err } continue diff --git a/http/handler.go b/http/handler.go index b87198a5d..f43a0f000 100644 --- a/http/handler.go +++ b/http/handler.go @@ -2924,11 +2924,6 @@ func (h *Handler) handleRestoreIDAlloc(w http.ResponseWriter, r *http.Request) { w.Write([]byte("OK")) //nolint:errcheck } func (h *Handler) handlePostRestore(w http.ResponseWriter, r *http.Request) { - /* - if !validHeaderAcceptType(r.Header, "text", "plain") { - http.Error(w, "text/plain is not an acceptable response type", http.StatusNotAcceptable) - } - */ indexName, ok := mux.Vars(r)["index"] if !ok { http.Error(w, "index name is required", http.StatusBadRequest) diff --git a/index.go b/index.go index 5f8ca9f25..18fa1d49e 100644 --- a/index.go +++ b/index.go @@ -814,10 +814,6 @@ func (i *Index) DeleteField(name string) error { return i.translationSyncer.Reset() } -func (i *Index) UpdateAvailbleShards(field, view string, shard uint64) { - -} - type indexSlice []*Index func (p indexSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }