diff --git a/api.go b/api.go index 691e076ff..3f3e8bd50 100644 --- a/api.go +++ b/api.go @@ -90,14 +90,14 @@ func (api *API) validate(f apiMethod) error { // Query parses a PQL query out of the request and executes it. func (api *API) Query(ctx context.Context, req *QueryRequest) (QueryResponse, error) { if err := api.validate(apiQuery); err != nil { - return QueryResponse{}, errors.Wrap(err, "validate api method") + return QueryResponse{}, errors.Wrap(err, "validating api method") } resp := QueryResponse{} q, err := pql.NewParser(strings.NewReader(req.Query)).Parse() if err != nil { - return resp, err + return resp, errors.Wrap(err, "parsing") } execOpts := &ExecOptions{ Remote: req.Remote, @@ -106,7 +106,7 @@ func (api *API) Query(ctx context.Context, req *QueryRequest) (QueryResponse, er } results, err := api.Executor.Execute(ctx, req.Index, q, req.Slices, execOpts) if err != nil { - return resp, err + return resp, errors.Wrap(err, "executing") } resp.Results = results @@ -125,7 +125,7 @@ func (api *API) Query(ctx context.Context, req *QueryRequest) (QueryResponse, er // Retrieve column attributes across all calls. columnAttrSets, err := api.readColumnAttrSets(api.Holder.Index(req.Index), columnIDs) if err != nil { - return resp, err + return resp, errors.Wrap(err, "reading column attrs") } resp.ColumnAttrSets = columnAttrSets } @@ -143,7 +143,7 @@ func (api *API) readColumnAttrSets(index *Index, ids []uint64) ([]*ColumnAttrSet // Read attributes for column. Skip column if empty. attrs, err := index.ColumnAttrStore().Attrs(id) if err != nil { - return nil, err + return nil, errors.Wrap(err, "getting attrs") } else if len(attrs) == 0 { continue } @@ -158,13 +158,13 @@ func (api *API) readColumnAttrSets(index *Index, ids []uint64) ([]*ColumnAttrSet // CreateIndex makes a new Pilosa index. func (api *API) CreateIndex(ctx context.Context, indexName string, options IndexOptions) (*Index, error) { if err := api.validate(apiCreateIndex); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } // Create index. index, err := api.Holder.CreateIndex(indexName, options) if err != nil { - return nil, err + return nil, errors.Wrap(err, "creating index") } // Send the create index message to all nodes. err = api.Broadcaster.SendSync( @@ -174,7 +174,7 @@ func (api *API) CreateIndex(ctx context.Context, indexName string, options Index }) if err != nil { api.Logger.Printf("problem sending CreateIndex message: %s", err) - return nil, err + return nil, errors.Wrap(err, "sending CreateIndex message") } api.Holder.Stats.Count("createIndex", 1, 1.0) return index, nil @@ -183,7 +183,7 @@ func (api *API) CreateIndex(ctx context.Context, indexName string, options Index // Index retrieves the named index. func (api *API) Index(ctx context.Context, indexName string) (*Index, error) { if err := api.validate(apiIndex); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } index := api.Holder.Index(indexName) @@ -197,13 +197,13 @@ func (api *API) Index(ctx context.Context, indexName string) (*Index, error) { // nothing and returns no error. func (api *API) DeleteIndex(ctx context.Context, indexName string) error { if err := api.validate(apiDeleteIndex); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } // Delete index from the holder. err := api.Holder.DeleteIndex(indexName) if err != nil { - return err + return errors.Wrap(err, "deleting index") } // Send the delete index message to all nodes. err = api.Broadcaster.SendSync( @@ -212,7 +212,7 @@ func (api *API) DeleteIndex(ctx context.Context, indexName string) error { }) if err != nil { api.Logger.Printf("problem sending DeleteIndex message: %s", err) - return err + return errors.Wrap(err, "sending DeleteIndex message") } api.Holder.Stats.Count("deleteIndex", 1, 1.0) return nil @@ -221,7 +221,7 @@ func (api *API) DeleteIndex(ctx context.Context, indexName string) error { // CreateFrame makes the named frame in the named index with the given options. func (api *API) CreateFrame(ctx context.Context, indexName string, frameName string, options FrameOptions) (*Frame, error) { if err := api.validate(apiCreateFrame); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } // Find index. @@ -233,7 +233,7 @@ func (api *API) CreateFrame(ctx context.Context, indexName string, frameName str // Create frame. frame, err := index.CreateFrame(frameName, options) if err != nil { - return nil, err + return nil, errors.Wrap(err, "creating frame") } // Send the create frame message to all nodes. @@ -245,7 +245,7 @@ func (api *API) CreateFrame(ctx context.Context, indexName string, frameName str }) if err != nil { api.Logger.Printf("problem sending CreateFrame message: %s", err) - return nil, err + return nil, errors.Wrap(err, "sending CreateFrame message") } api.Holder.Stats.CountWithCustomTags("createFrame", 1, 1.0, []string{fmt.Sprintf("index:%s", indexName)}) return frame, nil @@ -256,7 +256,7 @@ func (api *API) CreateFrame(ctx context.Context, indexName string, frameName str // action is taken. func (api *API) DeleteFrame(ctx context.Context, indexName string, frameName string) error { if err := api.validate(apiDeleteFrame); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } // Find index. @@ -267,7 +267,7 @@ func (api *API) DeleteFrame(ctx context.Context, indexName string, frameName str // Delete frame from the index. if err := index.DeleteFrame(frameName); err != nil { - return err + return errors.Wrap(err, "deleting frame") } // Send the delete frame message to all nodes. @@ -278,7 +278,7 @@ func (api *API) DeleteFrame(ctx context.Context, indexName string, frameName str }) if err != nil { api.Logger.Printf("problem sending DeleteFrame message: %s", err) - return err + return errors.Wrap(err, "sending DeleteFrame message") } api.Holder.Stats.CountWithCustomTags("deleteFrame", 1, 1.0, []string{fmt.Sprintf("index:%s", indexName)}) return nil @@ -288,7 +288,7 @@ func (api *API) DeleteFrame(ctx context.Context, indexName string, frameName str // CSV of the form , func (api *API) ExportCSV(ctx context.Context, indexName string, frameName string, viewName string, slice uint64, w io.Writer) error { if err := api.validate(apiExportCSV); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } // Validate that this handler owns the slice. @@ -313,7 +313,7 @@ func (api *API) ExportCSV(ctx context.Context, indexName string, frameName strin strconv.FormatUint(columnID, 10), }) }); err != nil { - return err + return errors.Wrap(err, "writing CSV") } // Ensure data is flushed. @@ -325,7 +325,7 @@ func (api *API) ExportCSV(ctx context.Context, indexName string, frameName strin // SliceNodes returns the node and all replicas which should contain a slice's data. func (api *API) SliceNodes(ctx context.Context, indexName string, slice uint64) ([]*Node, error) { if err := api.validate(apiSliceNodes); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } return api.Cluster.SliceNodes(indexName, slice), nil @@ -336,7 +336,7 @@ func (api *API) SliceNodes(ctx context.Context, indexName string, slice uint64) // the UnmarshalFragment API call. func (api *API) MarshalFragment(ctx context.Context, indexName string, frameName string, viewName string, slice uint64) (io.WriterTo, error) { if err := api.validate(apiMarshalFragment); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } // Retrieve fragment from holder. @@ -352,7 +352,7 @@ func (api *API) MarshalFragment(ctx context.Context, indexName string, frameName // fragment's data. func (api *API) UnmarshalFragment(ctx context.Context, indexName string, frameName string, viewName string, slice uint64, reader io.ReadCloser) error { if err := api.validate(apiUnmarshalFragment); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } // Retrieve frame. @@ -364,18 +364,18 @@ func (api *API) UnmarshalFragment(ctx context.Context, indexName string, frameNa // Retrieve view. view, err := f.CreateViewIfNotExists(viewName) if err != nil { - return err + return errors.Wrap(err, "creating view") } // Retrieve fragment from frame. frag, err := view.CreateFragmentIfNotExists(slice) if err != nil { - return err + return errors.Wrap(err, "creating fragment") } // Read fragment in from request body. if _, err := frag.ReadFrom(reader); err != nil { - return err + return errors.Wrap(err, "reading fragment") } return nil } @@ -385,7 +385,7 @@ func (api *API) UnmarshalFragment(ctx context.Context, indexName string, frameNa // ids from a "block" which is a subdivision of a fragment. func (api *API) FragmentBlockData(ctx context.Context, body io.Reader) ([]byte, error) { if err := api.validate(apiFragmentBlockData); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } reqBytes, err := ioutil.ReadAll(body) @@ -418,7 +418,7 @@ func (api *API) FragmentBlockData(ctx context.Context, body io.Reader) ([]byte, // FragmentBlocks returns the checksums and block ids for all blocks in the specified fragment. func (api *API) FragmentBlocks(ctx context.Context, indexName string, frameName string, viewName string, slice uint64) ([]FragmentBlock, error) { if err := api.validate(apiFragmentBlocks); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } // Retrieve fragment from holder. @@ -436,7 +436,7 @@ func (api *API) FragmentBlocks(ctx context.Context, indexName string, frameName // from replicas in the cluster and restores that data to it. func (api *API) RestoreFrame(ctx context.Context, indexName string, frameName string, host *URI) error { if err := api.validate(apiRestoreFrame); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } // Create a client for the remote cluster. @@ -445,7 +445,7 @@ func (api *API) RestoreFrame(ctx context.Context, indexName string, frameName st // Determine the maximum number of slices. maxSlices, err := client.MaxSliceByIndex(ctx) if err != nil { - return err + return errors.Wrap(err, "getting max slice") } // Retrieve frame. @@ -457,7 +457,7 @@ func (api *API) RestoreFrame(ctx context.Context, indexName string, frameName st // Retrieve list of all views. views, err := client.FrameViews(ctx, indexName, frameName) if err != nil { - return err + return errors.Wrap(err, "getting views") } // Loop over each slice and import it if this node owns it. @@ -472,19 +472,19 @@ func (api *API) RestoreFrame(ctx context.Context, indexName string, frameName st // Create view. v, err := f.CreateViewIfNotExists(view) if err != nil { - return err + return errors.Wrap(err, "creating view") } // Otherwise retrieve the local fragment. frag, err := v.CreateFragmentIfNotExists(slice) if err != nil { - return err + return errors.Wrap(err, "creating fragment") } // Stream backup from remote node. rd, err := client.BackupSlice(ctx, indexName, frameName, view, slice) if err != nil { - return err + return errors.Wrap(err, "getting backup") } else if rd == nil { continue // slice doesn't exist } @@ -493,7 +493,7 @@ func (api *API) RestoreFrame(ctx context.Context, indexName string, frameName st if err := func() error { defer rd.Close() if _, err := frag.ReadFrom(rd); err != nil { - return err + return errors.Wrap(err, "reading fragment") } return nil }(); err != nil { @@ -514,7 +514,7 @@ func (api *API) Hosts(ctx context.Context) []*Node { // CreateInputDefinition is deprecated and will be removed. Do not use it. func (api *API) CreateInputDefinition(ctx context.Context, indexName string, inputDefName string, inputDef InputDefinitionInfo) error { if err := api.validate(apiCreateInputDefinition); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } api.Logger.Printf(`CreateInputDefinition is deprecated and will be removed. @@ -552,7 +552,7 @@ Please open an issue if you need to continue using it.`) // InputDefinition is deprecated and will be removed. func (api *API) InputDefinition(ctx context.Context, indexName string, inputDefName string) (*InputDefinition, error) { if err := api.validate(apiInputDefinition); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } api.Logger.Printf(`InputDefinition is deprecated and will be removed.`) @@ -572,7 +572,7 @@ func (api *API) InputDefinition(ctx context.Context, indexName string, inputDefN // DeleteInputDefinition is deprecated and will be removed. func (api *API) DeleteInputDefinition(ctx context.Context, indexName string, inputDefName string) error { if err := api.validate(apiDeleteInputDefinition); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } api.Logger.Printf("DeleteInputDefinition is deprecated and will be removed.") @@ -601,7 +601,7 @@ func (api *API) DeleteInputDefinition(ctx context.Context, indexName string, inp // WriteInput is deprecated and will be removed. func (api *API) WriteInput(ctx context.Context, indexName string, inputDefName string, reqs []interface{}) error { if err := api.validate(apiWriteInput); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } api.Logger.Printf("WriteInput is deprecated and will be removed.") @@ -629,7 +629,7 @@ func (api *API) WriteInput(ctx context.Context, indexName string, inputDefName s // RecalculateCaches forces all TopN caches to be updated. Used mainly for integration tests. func (api *API) RecalculateCaches(ctx context.Context) error { if err := api.validate(apiRecalculateCaches); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } err := api.Broadcaster.SendSync(&internal.RecalculateCaches{}) @@ -644,7 +644,7 @@ func (api *API) RecalculateCaches(ctx context.Context) error { // the body and forwards it to the BroadcastHandler. func (api *API) ClusterMessage(ctx context.Context, reqBody io.Reader) error { if err := api.validate(apiClusterMessage); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } // Read entire body. @@ -680,7 +680,7 @@ func (api *API) Schema(ctx context.Context) []*IndexInfo { // CreateField creates a new BSI field in the given index and frame. func (api *API) CreateField(ctx context.Context, indexName string, frameName string, field *Field) error { if err := api.validate(apiCreateField); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } // Retrieve frame by name. @@ -691,7 +691,7 @@ func (api *API) CreateField(ctx context.Context, indexName string, frameName str // Create new field. if err := f.CreateField(field); err != nil { - return err + return errors.Wrap(err, "creating field") } // Send the create field message to all nodes. @@ -704,13 +704,13 @@ func (api *API) CreateField(ctx context.Context, indexName string, frameName str if err != nil { api.Logger.Printf("problem sending CreateField message: %s", err) } - return err + return errors.Wrap(err, "sending CreateField message") } // DeleteField deletes the given field. func (api *API) DeleteField(ctx context.Context, indexName string, frameName string, fieldName string) error { if err := api.validate(apiDeleteField); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } // Retrieve frame by name. @@ -721,7 +721,7 @@ func (api *API) DeleteField(ctx context.Context, indexName string, frameName str // Delete field. if err := f.DeleteField(fieldName); err != nil { - return err + return errors.Wrap(err, "deleting field") } // Send the delete field message to all nodes. @@ -734,13 +734,13 @@ func (api *API) DeleteField(ctx context.Context, indexName string, frameName str if err != nil { api.Logger.Printf("problem sending DeleteField message: %s", err) } - return err + return errors.Wrap(err, "sending DeleteField message") } // Fields returns the fields in the given frame. func (api *API) Fields(ctx context.Context, indexName string, frameName string) ([]*Field, error) { if err := api.validate(apiFields); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } index := api.Holder.index(indexName) @@ -759,7 +759,7 @@ func (api *API) Fields(ctx context.Context, indexName string, frameName string) // Views returns the views in the given frame. func (api *API) Views(ctx context.Context, indexName string, frameName string) ([]*View, error) { if err := api.validate(apiViews); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } // Retrieve views. @@ -776,7 +776,7 @@ func (api *API) Views(ctx context.Context, indexName string, frameName string) ( // DeleteView removes the given view. func (api *API) DeleteView(ctx context.Context, indexName string, frameName string, viewName string) error { if err := api.validate(apiDeleteView); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } // Retrieve frame. @@ -789,7 +789,7 @@ func (api *API) DeleteView(ctx context.Context, indexName string, frameName stri if err := f.DeleteView(viewName); err != nil { // Ignore this error because views do not exist on all nodes due to slice distribution. if err != ErrInvalidView { - return err + return errors.Wrap(err, "deleting view") } } @@ -804,13 +804,13 @@ func (api *API) DeleteView(ctx context.Context, indexName string, frameName stri api.Logger.Printf("problem sending DeleteView message: %s", err) } - return err + return errors.Wrap(err, "sending DeleteView message") } // IndexAttrDiff func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []AttrBlock) (map[uint64]map[string]interface{}, error) { if err := api.validate(apiIndexAttrDiff); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } // Retrieve index from holder. @@ -822,7 +822,7 @@ func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []At // Retrieve local blocks. localBlocks, err := index.ColumnAttrStore().Blocks() if err != nil { - return nil, err + return nil, errors.Wrap(err, "getting blocks") } // Read all attributes from all mismatched blocks. @@ -831,7 +831,7 @@ func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []At // Retrieve block data. m, err := index.ColumnAttrStore().BlockData(blockID) if err != nil { - return nil, err + return nil, errors.Wrap(err, "getting block") } // Copy to index-wide struct. @@ -844,7 +844,7 @@ func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []At func (api *API) FrameAttrDiff(ctx context.Context, indexName string, frameName string, blocks []AttrBlock) (map[uint64]map[string]interface{}, error) { if err := api.validate(apiFrameAttrDiff); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } // Retrieve index from holder. @@ -856,7 +856,7 @@ func (api *API) FrameAttrDiff(ctx context.Context, indexName string, frameName s // Retrieve local blocks. localBlocks, err := f.RowAttrStore().Blocks() if err != nil { - return nil, err + return nil, errors.Wrap(err, "getting blocks") } // Read all attributes from all mismatched blocks. @@ -865,7 +865,7 @@ func (api *API) FrameAttrDiff(ctx context.Context, indexName string, frameName s // Retrieve block data. m, err := f.RowAttrStore().BlockData(blockID) if err != nil { - return nil, err + return nil, errors.Wrap(err, "getting block") } // Copy to index-wide struct. @@ -879,12 +879,12 @@ func (api *API) FrameAttrDiff(ctx context.Context, indexName string, frameName s // Import bulk imports data into a particular index,frame,slice. func (api *API) Import(ctx context.Context, req internal.ImportRequest) error { if err := api.validate(apiImport); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } _, frame, err := api.indexFrame(req.Index, req.Frame, req.Slice) if err != nil { - return err + return errors.Wrap(err, "getting frame") } // Convert timestamps to time.Time. @@ -902,18 +902,18 @@ func (api *API) Import(ctx context.Context, req internal.ImportRequest) error { if err != nil { api.Logger.Printf("import error: index=%s, frame=%s, slice=%d, bits=%d, err=%s", req.Index, req.Frame, req.Slice, len(req.ColumnIDs), err) } - return err + return errors.Wrap(err, "importing") } // ImportValue bulk imports values into a particular field. func (api *API) ImportValue(ctx context.Context, req internal.ImportValueRequest) error { if err := api.validate(apiImportValue); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } _, frame, err := api.indexFrame(req.Index, req.Frame, req.Slice) if err != nil { - return err + return errors.Wrap(err, "getting frame") } // Import into fragment. @@ -921,7 +921,7 @@ func (api *API) ImportValue(ctx context.Context, req internal.ImportValueRequest if err != nil { api.Logger.Printf("import error: index=%s, frame=%s, slice=%d, field=%s, bits=%d, err=%s", req.Index, req.Frame, req.Slice, req.Field, len(req.ColumnIDs), err) } - return err + return errors.Wrap(err, "importing") } // MaxSlices returns the maximum slice number for each index in a map. @@ -1049,7 +1049,7 @@ func (api *API) inputJSONDataParser(req map[string]interface{}, index *Index, na // SetCoordinator makes a new Node the cluster coordinator. func (api *API) SetCoordinator(ctx context.Context, id string) (oldNode, newNode *Node, err error) { if err := api.validate(apiSetCoordinator); err != nil { - return nil, nil, errors.Wrap(err, "validate api method") + return nil, nil, errors.Wrap(err, "validating api method") } oldNode = api.Cluster.NodeByID(api.Cluster.Coordinator) @@ -1079,7 +1079,7 @@ func (api *API) SetCoordinator(ctx context.Context, id string) (oldNode, newNode // removing the given node. func (api *API) RemoveNode(id string) (*Node, error) { if err := api.validate(apiRemoveNode); err != nil { - return nil, errors.Wrap(err, "validate api method") + return nil, errors.Wrap(err, "validating api method") } removeNode := api.Cluster.nodeByID(id) @@ -1098,7 +1098,7 @@ func (api *API) RemoveNode(id string) (*Node, error) { // ResizeAbort stops the current resize job. func (api *API) ResizeAbort() error { if err := api.validate(apiResizeAbort); err != nil { - return errors.Wrap(err, "validate api method") + return errors.Wrap(err, "validating api method") } err := api.Cluster.CompleteCurrentJob(ResizeJobStateAborted) diff --git a/fragment.go b/fragment.go index 7168f4443..6b5021c99 100644 --- a/fragment.go +++ b/fragment.go @@ -21,7 +21,6 @@ import ( "container/heap" "context" "encoding/binary" - "errors" "fmt" "hash" "io" @@ -42,6 +41,7 @@ import ( "github.com/pilosa/pilosa/internal" "github.com/pilosa/pilosa/pql" "github.com/pilosa/pilosa/roaring" + "github.com/pkg/errors" ) const ( @@ -160,12 +160,12 @@ func (f *Fragment) Open() error { if err := func() error { // Initialize storage in a function so we can close if anything goes wrong. if err := f.openStorage(); err != nil { - return err + return errors.Wrap(err, "opening storage") } // Fill cache with rows persisted to disk. if err := f.openCache(); err != nil { - return err + return errors.Wrap(err, "opening cache") } // Clear checksums. @@ -206,7 +206,7 @@ func (f *Fragment) openStorage() error { // If the file is empty then initialize it with an empty bitmap. fi, err := f.file.Stat() if err != nil { - return err + return errors.Wrap(err, "statting file before") } else if fi.Size() == 0 { bi := bufio.NewWriter(f.file) if _, err := f.storage.WriteTo(bi); err != nil { @@ -215,7 +215,7 @@ func (f *Fragment) openStorage() error { bi.Flush() fi, err = f.file.Stat() if err != nil { - return err + return errors.Wrap(err, "statting file after") } } @@ -298,13 +298,13 @@ func (f *Fragment) close() error { // Flush cache if closing gracefully. if err := f.flushCache(); err != nil { f.Logger.Printf("fragment: error flushing cache on close: err=%s, path=%s", err, f.path) - return err + return errors.Wrap(err, "flushing cache") } // Close underlying storage. if err := f.closeStorage(); err != nil { f.Logger.Printf("fragment: error closing storage: err=%s, path=%s", err, f.path) - return err + return errors.Wrap(err, "closing storage") } // Remove checksums. @@ -393,12 +393,12 @@ func (f *Fragment) setBit(rowID, columnID uint64) (changed bool, err error) { // Determine the position of the bit in the storage. pos, err := f.pos(rowID, columnID) if err != nil { - return false, err + return false, errors.Wrap(err, "getting bit ops") } // Write to storage. if changed, err = f.storage.Add(pos); err != nil { - return false, err + return false, errors.Wrap(err, "writing") } // Don't update the cache if nothing changed. @@ -411,7 +411,7 @@ func (f *Fragment) setBit(rowID, columnID uint64) (changed bool, err error) { // Increment number of operations until snapshot is required. if err := f.incrementOpN(); err != nil { - return false, err + return false, errors.Wrap(err, "incrementing") } // Get the row from row cache or fragment.storage. @@ -445,12 +445,12 @@ func (f *Fragment) clearBit(rowID, columnID uint64) (changed bool, err error) { // Determine the position of the bit in the storage. pos, err := f.pos(rowID, columnID) if err != nil { - return false, err + return false, errors.Wrap(err, "getting bit pos") } // Write to storage. if changed, err = f.storage.Remove(pos); err != nil { - return false, err + return false, errors.Wrap(err, "writing") } // Don't update the cache if nothing changed. @@ -463,7 +463,7 @@ func (f *Fragment) clearBit(rowID, columnID uint64) (changed bool, err error) { // Increment number of operations until snapshot is required. if err := f.incrementOpN(); err != nil { - return false, err + return false, errors.Wrap(err, "incrementing") } // Get the row from cache or fragment.storage. @@ -493,7 +493,7 @@ func (f *Fragment) FieldValue(columnID uint64, bitDepth uint) (value uint64, exi // If existence bit is unset then ignore remaining bits. if v, err := f.bit(uint64(bitDepth), columnID); err != nil { - return 0, false, err + return 0, false, errors.Wrap(err, "getting existence bit") } else if !v { return 0, false, nil } @@ -501,7 +501,7 @@ func (f *Fragment) FieldValue(columnID uint64, bitDepth uint) (value uint64, exi // Compute other bits into a value. for i := uint(0); i < bitDepth; i++ { if v, err := f.bit(uint64(i), columnID); err != nil { - return 0, false, err + return 0, false, errors.Wrapf(err, "getting value bit %d", i) } else if v { value |= (1 << i) } @@ -533,7 +533,7 @@ func (f *Fragment) SetFieldValue(columnID uint64, bitDepth uint, value uint64) ( // Mark value as set. if c, err := f.setBit(uint64(bitDepth), columnID); err != nil { - return changed, err + return changed, errors.Wrap(err, "marking not-null") } else if c { changed = true } @@ -548,20 +548,20 @@ func (f *Fragment) importSetFieldValue(columnID uint64, bitDepth uint, value uin if value&(1<