repo
stringlengths
5
67
path
stringlengths
4
218
func_name
stringlengths
0
151
original_string
stringlengths
52
373k
language
stringclasses
6 values
code
stringlengths
52
373k
code_tokens
listlengths
10
512
docstring
stringlengths
3
47.2k
docstring_tokens
listlengths
3
234
sha
stringlengths
40
40
url
stringlengths
85
339
partition
stringclasses
3 values
pilosa/pilosa
api.go
DeleteAvailableShard
func (api *API) DeleteAvailableShard(_ context.Context, indexName, fieldName string, shardID uint64) error { if err := api.validate(apiDeleteAvailableShard); err != nil { return errors.Wrap(err, "validating api method") } // Find field. field := api.holder.Field(indexName, fieldName) if field == nil { return newNotFoundError(ErrFieldNotFound) } // Delete shard from the cache. if err := field.RemoveAvailableShard(shardID); err != nil { return errors.Wrap(err, "deleting available shard") } // Send the delete shard message to all nodes. err := api.server.SendSync( &DeleteAvailableShardMessage{ Index: indexName, Field: fieldName, ShardID: shardID, }) if err != nil { api.server.logger.Printf("problem sending DeleteAvailableShard message: %s", err) return errors.Wrap(err, "sending DeleteAvailableShard message") } api.holder.Stats.CountWithCustomTags("deleteAvailableShard", 1, 1.0, []string{fmt.Sprintf("index:%s", indexName), fmt.Sprintf("field:%s", fieldName)}) return nil }
go
func (api *API) DeleteAvailableShard(_ context.Context, indexName, fieldName string, shardID uint64) error { if err := api.validate(apiDeleteAvailableShard); err != nil { return errors.Wrap(err, "validating api method") } // Find field. field := api.holder.Field(indexName, fieldName) if field == nil { return newNotFoundError(ErrFieldNotFound) } // Delete shard from the cache. if err := field.RemoveAvailableShard(shardID); err != nil { return errors.Wrap(err, "deleting available shard") } // Send the delete shard message to all nodes. err := api.server.SendSync( &DeleteAvailableShardMessage{ Index: indexName, Field: fieldName, ShardID: shardID, }) if err != nil { api.server.logger.Printf("problem sending DeleteAvailableShard message: %s", err) return errors.Wrap(err, "sending DeleteAvailableShard message") } api.holder.Stats.CountWithCustomTags("deleteAvailableShard", 1, 1.0, []string{fmt.Sprintf("index:%s", indexName), fmt.Sprintf("field:%s", fieldName)}) return nil }
[ "func", "(", "api", "*", "API", ")", "DeleteAvailableShard", "(", "_", "context", ".", "Context", ",", "indexName", ",", "fieldName", "string", ",", "shardID", "uint64", ")", "error", "{", "if", "err", ":=", "api", ".", "validate", "(", "apiDeleteAvailable...
// DeleteAvailableShard a shard ID from the available shard set cache.
[ "DeleteAvailableShard", "a", "shard", "ID", "from", "the", "available", "shard", "set", "cache", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L394-L423
train
pilosa/pilosa
api.go
ShardNodes
func (api *API) ShardNodes(ctx context.Context, indexName string, shard uint64) ([]*Node, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.ShardNodes") defer span.Finish() if err := api.validate(apiShardNodes); err != nil { return nil, errors.Wrap(err, "validating api method") } return api.cluster.shardNodes(indexName, shard), nil }
go
func (api *API) ShardNodes(ctx context.Context, indexName string, shard uint64) ([]*Node, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.ShardNodes") defer span.Finish() if err := api.validate(apiShardNodes); err != nil { return nil, errors.Wrap(err, "validating api method") } return api.cluster.shardNodes(indexName, shard), nil }
[ "func", "(", "api", "*", "API", ")", "ShardNodes", "(", "ctx", "context", ".", "Context", ",", "indexName", "string", ",", "shard", "uint64", ")", "(", "[", "]", "*", "Node", ",", "error", ")", "{", "span", ",", "_", ":=", "tracing", ".", "StartSpa...
// ShardNodes returns the node and all replicas which should contain a shard's data.
[ "ShardNodes", "returns", "the", "node", "and", "all", "replicas", "which", "should", "contain", "a", "shard", "s", "data", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L504-L513
train
pilosa/pilosa
api.go
FragmentBlockData
func (api *API) FragmentBlockData(ctx context.Context, body io.Reader) ([]byte, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.FragmentBlockData") defer span.Finish() if err := api.validate(apiFragmentBlockData); err != nil { return nil, errors.Wrap(err, "validating api method") } reqBytes, err := ioutil.ReadAll(body) if err != nil { return nil, NewBadRequestError(errors.Wrap(err, "read body error")) } var req BlockDataRequest if err := api.Serializer.Unmarshal(reqBytes, &req); err != nil { return nil, NewBadRequestError(errors.Wrap(err, "unmarshal body error")) } // Retrieve fragment from holder. f := api.holder.fragment(req.Index, req.Field, req.View, req.Shard) if f == nil { return nil, ErrFragmentNotFound } var resp = BlockDataResponse{} resp.RowIDs, resp.ColumnIDs = f.blockData(int(req.Block)) // Encode response. buf, err := api.Serializer.Marshal(&resp) if err != nil { return nil, errors.Wrap(err, "merge block response encoding error") } return buf, nil }
go
func (api *API) FragmentBlockData(ctx context.Context, body io.Reader) ([]byte, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.FragmentBlockData") defer span.Finish() if err := api.validate(apiFragmentBlockData); err != nil { return nil, errors.Wrap(err, "validating api method") } reqBytes, err := ioutil.ReadAll(body) if err != nil { return nil, NewBadRequestError(errors.Wrap(err, "read body error")) } var req BlockDataRequest if err := api.Serializer.Unmarshal(reqBytes, &req); err != nil { return nil, NewBadRequestError(errors.Wrap(err, "unmarshal body error")) } // Retrieve fragment from holder. f := api.holder.fragment(req.Index, req.Field, req.View, req.Shard) if f == nil { return nil, ErrFragmentNotFound } var resp = BlockDataResponse{} resp.RowIDs, resp.ColumnIDs = f.blockData(int(req.Block)) // Encode response. buf, err := api.Serializer.Marshal(&resp) if err != nil { return nil, errors.Wrap(err, "merge block response encoding error") } return buf, nil }
[ "func", "(", "api", "*", "API", ")", "FragmentBlockData", "(", "ctx", "context", ".", "Context", ",", "body", "io", ".", "Reader", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "span", ",", "_", ":=", "tracing", ".", "StartSpanFromContext", "("...
// FragmentBlockData is an endpoint for internal usage. It is not guaranteed to // return anything useful. Currently it returns protobuf encoded row and column // ids from a "block" which is a subdivision of a fragment.
[ "FragmentBlockData", "is", "an", "endpoint", "for", "internal", "usage", ".", "It", "is", "not", "guaranteed", "to", "return", "anything", "useful", ".", "Currently", "it", "returns", "protobuf", "encoded", "row", "and", "column", "ids", "from", "a", "block", ...
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L518-L551
train
pilosa/pilosa
api.go
FragmentBlocks
func (api *API) FragmentBlocks(ctx context.Context, indexName, fieldName, viewName string, shard uint64) ([]FragmentBlock, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.FragmentBlocks") defer span.Finish() if err := api.validate(apiFragmentBlocks); err != nil { return nil, errors.Wrap(err, "validating api method") } // Retrieve fragment from holder. f := api.holder.fragment(indexName, fieldName, viewName, shard) if f == nil { return nil, ErrFragmentNotFound } // Retrieve blocks. blocks := f.Blocks() return blocks, nil }
go
func (api *API) FragmentBlocks(ctx context.Context, indexName, fieldName, viewName string, shard uint64) ([]FragmentBlock, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.FragmentBlocks") defer span.Finish() if err := api.validate(apiFragmentBlocks); err != nil { return nil, errors.Wrap(err, "validating api method") } // Retrieve fragment from holder. f := api.holder.fragment(indexName, fieldName, viewName, shard) if f == nil { return nil, ErrFragmentNotFound } // Retrieve blocks. blocks := f.Blocks() return blocks, nil }
[ "func", "(", "api", "*", "API", ")", "FragmentBlocks", "(", "ctx", "context", ".", "Context", ",", "indexName", ",", "fieldName", ",", "viewName", "string", ",", "shard", "uint64", ")", "(", "[", "]", "FragmentBlock", ",", "error", ")", "{", "span", ",...
// FragmentBlocks returns the checksums and block ids for all blocks in the specified fragment.
[ "FragmentBlocks", "returns", "the", "checksums", "and", "block", "ids", "for", "all", "blocks", "in", "the", "specified", "fragment", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L554-L571
train
pilosa/pilosa
api.go
FragmentData
func (api *API) FragmentData(ctx context.Context, indexName, fieldName, viewName string, shard uint64) (io.WriterTo, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.FragmentData") defer span.Finish() if err := api.validate(apiFragmentData); err != nil { return nil, errors.Wrap(err, "validating api method") } // Retrieve fragment from holder. f := api.holder.fragment(indexName, fieldName, viewName, shard) if f == nil { return nil, ErrFragmentNotFound } return f, nil }
go
func (api *API) FragmentData(ctx context.Context, indexName, fieldName, viewName string, shard uint64) (io.WriterTo, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.FragmentData") defer span.Finish() if err := api.validate(apiFragmentData); err != nil { return nil, errors.Wrap(err, "validating api method") } // Retrieve fragment from holder. f := api.holder.fragment(indexName, fieldName, viewName, shard) if f == nil { return nil, ErrFragmentNotFound } return f, nil }
[ "func", "(", "api", "*", "API", ")", "FragmentData", "(", "ctx", "context", ".", "Context", ",", "indexName", ",", "fieldName", ",", "viewName", "string", ",", "shard", "uint64", ")", "(", "io", ".", "WriterTo", ",", "error", ")", "{", "span", ",", "...
// FragmentData returns all data in the specified fragment.
[ "FragmentData", "returns", "all", "data", "in", "the", "specified", "fragment", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L574-L588
train
pilosa/pilosa
api.go
Hosts
func (api *API) Hosts(ctx context.Context) []*Node { span, _ := tracing.StartSpanFromContext(ctx, "API.Hosts") defer span.Finish() return api.cluster.Nodes() }
go
func (api *API) Hosts(ctx context.Context) []*Node { span, _ := tracing.StartSpanFromContext(ctx, "API.Hosts") defer span.Finish() return api.cluster.Nodes() }
[ "func", "(", "api", "*", "API", ")", "Hosts", "(", "ctx", "context", ".", "Context", ")", "[", "]", "*", "Node", "{", "span", ",", "_", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"API.Hosts\"", ")", "\n", "defer", "span", ".", ...
// Hosts returns a list of the hosts in the cluster including their ID, // URL, and which is the coordinator.
[ "Hosts", "returns", "a", "list", "of", "the", "hosts", "in", "the", "cluster", "including", "their", "ID", "URL", "and", "which", "is", "the", "coordinator", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L592-L596
train
pilosa/pilosa
api.go
RecalculateCaches
func (api *API) RecalculateCaches(ctx context.Context) error { span, _ := tracing.StartSpanFromContext(ctx, "API.RecalculateCaches") defer span.Finish() if err := api.validate(apiRecalculateCaches); err != nil { return errors.Wrap(err, "validating api method") } err := api.server.SendSync(&RecalculateCaches{}) if err != nil { return errors.Wrap(err, "broacasting message") } api.holder.recalculateCaches() return nil }
go
func (api *API) RecalculateCaches(ctx context.Context) error { span, _ := tracing.StartSpanFromContext(ctx, "API.RecalculateCaches") defer span.Finish() if err := api.validate(apiRecalculateCaches); err != nil { return errors.Wrap(err, "validating api method") } err := api.server.SendSync(&RecalculateCaches{}) if err != nil { return errors.Wrap(err, "broacasting message") } api.holder.recalculateCaches() return nil }
[ "func", "(", "api", "*", "API", ")", "RecalculateCaches", "(", "ctx", "context", ".", "Context", ")", "error", "{", "span", ",", "_", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"API.RecalculateCaches\"", ")", "\n", "defer", "span", "....
// RecalculateCaches forces all TopN caches to be updated. Used mainly for integration tests.
[ "RecalculateCaches", "forces", "all", "TopN", "caches", "to", "be", "updated", ".", "Used", "mainly", "for", "integration", "tests", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L605-L619
train
pilosa/pilosa
api.go
ClusterMessage
func (api *API) ClusterMessage(ctx context.Context, reqBody io.Reader) error { span, _ := tracing.StartSpanFromContext(ctx, "API.ClusterMessage") defer span.Finish() if err := api.validate(apiClusterMessage); err != nil { return errors.Wrap(err, "validating api method") } // Read entire body. body, err := ioutil.ReadAll(reqBody) if err != nil { return errors.Wrap(err, "reading body") } typ := body[0] msg := getMessage(typ) err = api.server.serializer.Unmarshal(body[1:], msg) if err != nil { return errors.Wrap(err, "deserializing cluster message") } // Forward the error message. if err := api.server.receiveMessage(msg); err != nil { return errors.Wrap(err, "receiving message") } return nil }
go
func (api *API) ClusterMessage(ctx context.Context, reqBody io.Reader) error { span, _ := tracing.StartSpanFromContext(ctx, "API.ClusterMessage") defer span.Finish() if err := api.validate(apiClusterMessage); err != nil { return errors.Wrap(err, "validating api method") } // Read entire body. body, err := ioutil.ReadAll(reqBody) if err != nil { return errors.Wrap(err, "reading body") } typ := body[0] msg := getMessage(typ) err = api.server.serializer.Unmarshal(body[1:], msg) if err != nil { return errors.Wrap(err, "deserializing cluster message") } // Forward the error message. if err := api.server.receiveMessage(msg); err != nil { return errors.Wrap(err, "receiving message") } return nil }
[ "func", "(", "api", "*", "API", ")", "ClusterMessage", "(", "ctx", "context", ".", "Context", ",", "reqBody", "io", ".", "Reader", ")", "error", "{", "span", ",", "_", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"API.ClusterMessage\"",...
// ClusterMessage is for internal use. It decodes a protobuf message out of // the body and forwards it to the BroadcastHandler.
[ "ClusterMessage", "is", "for", "internal", "use", ".", "It", "decodes", "a", "protobuf", "message", "out", "of", "the", "body", "and", "forwards", "it", "to", "the", "BroadcastHandler", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L623-L649
train
pilosa/pilosa
api.go
Schema
func (api *API) Schema(ctx context.Context) []*IndexInfo { span, _ := tracing.StartSpanFromContext(ctx, "API.Schema") defer span.Finish() return api.holder.limitedSchema() }
go
func (api *API) Schema(ctx context.Context) []*IndexInfo { span, _ := tracing.StartSpanFromContext(ctx, "API.Schema") defer span.Finish() return api.holder.limitedSchema() }
[ "func", "(", "api", "*", "API", ")", "Schema", "(", "ctx", "context", ".", "Context", ")", "[", "]", "*", "IndexInfo", "{", "span", ",", "_", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"API.Schema\"", ")", "\n", "defer", "span", ...
// Schema returns information about each index in Pilosa including which fields // they contain.
[ "Schema", "returns", "information", "about", "each", "index", "in", "Pilosa", "including", "which", "fields", "they", "contain", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L653-L657
train
pilosa/pilosa
api.go
Views
func (api *API) Views(ctx context.Context, indexName string, fieldName string) ([]*view, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.Views") defer span.Finish() if err := api.validate(apiViews); err != nil { return nil, errors.Wrap(err, "validating api method") } // Retrieve views. f := api.holder.Field(indexName, fieldName) if f == nil { return nil, ErrFieldNotFound } // Fetch views. views := f.views() return views, nil }
go
func (api *API) Views(ctx context.Context, indexName string, fieldName string) ([]*view, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.Views") defer span.Finish() if err := api.validate(apiViews); err != nil { return nil, errors.Wrap(err, "validating api method") } // Retrieve views. f := api.holder.Field(indexName, fieldName) if f == nil { return nil, ErrFieldNotFound } // Fetch views. views := f.views() return views, nil }
[ "func", "(", "api", "*", "API", ")", "Views", "(", "ctx", "context", ".", "Context", ",", "indexName", "string", ",", "fieldName", "string", ")", "(", "[", "]", "*", "view", ",", "error", ")", "{", "span", ",", "_", ":=", "tracing", ".", "StartSpan...
// Views returns the views in the given field.
[ "Views", "returns", "the", "views", "in", "the", "given", "field", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L687-L704
train
pilosa/pilosa
api.go
DeleteView
func (api *API) DeleteView(ctx context.Context, indexName string, fieldName string, viewName string) error { span, _ := tracing.StartSpanFromContext(ctx, "API.DeleteView") defer span.Finish() if err := api.validate(apiDeleteView); err != nil { return errors.Wrap(err, "validating api method") } // Retrieve field. f := api.holder.Field(indexName, fieldName) if f == nil { return ErrFieldNotFound } // Delete the view. if err := f.deleteView(viewName); err != nil { // Ignore this error because views do not exist on all nodes due to shard distribution. if err != ErrInvalidView { return errors.Wrap(err, "deleting view") } } // Send the delete view message to all nodes. err := api.server.SendSync( &DeleteViewMessage{ Index: indexName, Field: fieldName, View: viewName, }) if err != nil { api.server.logger.Printf("problem sending DeleteView message: %s", err) } return errors.Wrap(err, "sending DeleteView message") }
go
func (api *API) DeleteView(ctx context.Context, indexName string, fieldName string, viewName string) error { span, _ := tracing.StartSpanFromContext(ctx, "API.DeleteView") defer span.Finish() if err := api.validate(apiDeleteView); err != nil { return errors.Wrap(err, "validating api method") } // Retrieve field. f := api.holder.Field(indexName, fieldName) if f == nil { return ErrFieldNotFound } // Delete the view. if err := f.deleteView(viewName); err != nil { // Ignore this error because views do not exist on all nodes due to shard distribution. if err != ErrInvalidView { return errors.Wrap(err, "deleting view") } } // Send the delete view message to all nodes. err := api.server.SendSync( &DeleteViewMessage{ Index: indexName, Field: fieldName, View: viewName, }) if err != nil { api.server.logger.Printf("problem sending DeleteView message: %s", err) } return errors.Wrap(err, "sending DeleteView message") }
[ "func", "(", "api", "*", "API", ")", "DeleteView", "(", "ctx", "context", ".", "Context", ",", "indexName", "string", ",", "fieldName", "string", ",", "viewName", "string", ")", "error", "{", "span", ",", "_", ":=", "tracing", ".", "StartSpanFromContext", ...
// DeleteView removes the given view.
[ "DeleteView", "removes", "the", "given", "view", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L707-L741
train
pilosa/pilosa
api.go
IndexAttrDiff
func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []AttrBlock) (map[uint64]map[string]interface{}, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.IndexAttrDiff") defer span.Finish() if err := api.validate(apiIndexAttrDiff); err != nil { return nil, errors.Wrap(err, "validating api method") } // Retrieve index from holder. index := api.holder.Index(indexName) if index == nil { return nil, newNotFoundError(ErrIndexNotFound) } // Retrieve local blocks. localBlocks, err := index.ColumnAttrStore().Blocks() if err != nil { return nil, errors.Wrap(err, "getting blocks") } // Read all attributes from all mismatched blocks. attrs := make(map[uint64]map[string]interface{}) for _, blockID := range attrBlocks(localBlocks).Diff(blocks) { // Retrieve block data. m, err := index.ColumnAttrStore().BlockData(blockID) if err != nil { return nil, errors.Wrap(err, "getting block") } // Copy to index-wide struct. for k, v := range m { attrs[k] = v } } return attrs, nil }
go
func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []AttrBlock) (map[uint64]map[string]interface{}, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.IndexAttrDiff") defer span.Finish() if err := api.validate(apiIndexAttrDiff); err != nil { return nil, errors.Wrap(err, "validating api method") } // Retrieve index from holder. index := api.holder.Index(indexName) if index == nil { return nil, newNotFoundError(ErrIndexNotFound) } // Retrieve local blocks. localBlocks, err := index.ColumnAttrStore().Blocks() if err != nil { return nil, errors.Wrap(err, "getting blocks") } // Read all attributes from all mismatched blocks. attrs := make(map[uint64]map[string]interface{}) for _, blockID := range attrBlocks(localBlocks).Diff(blocks) { // Retrieve block data. m, err := index.ColumnAttrStore().BlockData(blockID) if err != nil { return nil, errors.Wrap(err, "getting block") } // Copy to index-wide struct. for k, v := range m { attrs[k] = v } } return attrs, nil }
[ "func", "(", "api", "*", "API", ")", "IndexAttrDiff", "(", "ctx", "context", ".", "Context", ",", "indexName", "string", ",", "blocks", "[", "]", "AttrBlock", ")", "(", "map", "[", "uint64", "]", "map", "[", "string", "]", "interface", "{", "}", ",",...
// IndexAttrDiff determines the local column attribute data blocks which differ from those provided.
[ "IndexAttrDiff", "determines", "the", "local", "column", "attribute", "data", "blocks", "which", "differ", "from", "those", "provided", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L744-L779
train
pilosa/pilosa
api.go
FieldAttrDiff
func (api *API) FieldAttrDiff(ctx context.Context, indexName string, fieldName string, blocks []AttrBlock) (map[uint64]map[string]interface{}, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.FieldAttrDiff") defer span.Finish() if err := api.validate(apiFieldAttrDiff); err != nil { return nil, errors.Wrap(err, "validating api method") } // Retrieve index from holder. f := api.holder.Field(indexName, fieldName) if f == nil { return nil, ErrFieldNotFound } // Retrieve local blocks. localBlocks, err := f.RowAttrStore().Blocks() if err != nil { return nil, errors.Wrap(err, "getting blocks") } // Read all attributes from all mismatched blocks. attrs := make(map[uint64]map[string]interface{}) for _, blockID := range attrBlocks(localBlocks).Diff(blocks) { // Retrieve block data. m, err := f.RowAttrStore().BlockData(blockID) if err != nil { return nil, errors.Wrap(err, "getting block") } // Copy to index-wide struct. for k, v := range m { attrs[k] = v } } return attrs, nil }
go
func (api *API) FieldAttrDiff(ctx context.Context, indexName string, fieldName string, blocks []AttrBlock) (map[uint64]map[string]interface{}, error) { span, _ := tracing.StartSpanFromContext(ctx, "API.FieldAttrDiff") defer span.Finish() if err := api.validate(apiFieldAttrDiff); err != nil { return nil, errors.Wrap(err, "validating api method") } // Retrieve index from holder. f := api.holder.Field(indexName, fieldName) if f == nil { return nil, ErrFieldNotFound } // Retrieve local blocks. localBlocks, err := f.RowAttrStore().Blocks() if err != nil { return nil, errors.Wrap(err, "getting blocks") } // Read all attributes from all mismatched blocks. attrs := make(map[uint64]map[string]interface{}) for _, blockID := range attrBlocks(localBlocks).Diff(blocks) { // Retrieve block data. m, err := f.RowAttrStore().BlockData(blockID) if err != nil { return nil, errors.Wrap(err, "getting block") } // Copy to index-wide struct. for k, v := range m { attrs[k] = v } } return attrs, nil }
[ "func", "(", "api", "*", "API", ")", "FieldAttrDiff", "(", "ctx", "context", ".", "Context", ",", "indexName", "string", ",", "fieldName", "string", ",", "blocks", "[", "]", "AttrBlock", ")", "(", "map", "[", "uint64", "]", "map", "[", "string", "]", ...
// FieldAttrDiff determines the local row attribute data blocks which differ from those provided.
[ "FieldAttrDiff", "determines", "the", "local", "row", "attribute", "data", "blocks", "which", "differ", "from", "those", "provided", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L782-L817
train
pilosa/pilosa
api.go
OptImportOptionsClear
func OptImportOptionsClear(c bool) ImportOption { return func(o *ImportOptions) error { o.Clear = c return nil } }
go
func OptImportOptionsClear(c bool) ImportOption { return func(o *ImportOptions) error { o.Clear = c return nil } }
[ "func", "OptImportOptionsClear", "(", "c", "bool", ")", "ImportOption", "{", "return", "func", "(", "o", "*", "ImportOptions", ")", "error", "{", "o", ".", "Clear", "=", "c", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// OptImportOptionsClear is a functional option on ImportOption // used to specify whether the import is a set or clear operation.
[ "OptImportOptionsClear", "is", "a", "functional", "option", "on", "ImportOption", "used", "to", "specify", "whether", "the", "import", "is", "a", "set", "or", "clear", "operation", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L830-L835
train
pilosa/pilosa
api.go
OptImportOptionsIgnoreKeyCheck
func OptImportOptionsIgnoreKeyCheck(b bool) ImportOption { return func(o *ImportOptions) error { o.IgnoreKeyCheck = b return nil } }
go
func OptImportOptionsIgnoreKeyCheck(b bool) ImportOption { return func(o *ImportOptions) error { o.IgnoreKeyCheck = b return nil } }
[ "func", "OptImportOptionsIgnoreKeyCheck", "(", "b", "bool", ")", "ImportOption", "{", "return", "func", "(", "o", "*", "ImportOptions", ")", "error", "{", "o", ".", "IgnoreKeyCheck", "=", "b", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// OptImportOptionsIgnoreKeyCheck is a functional option on ImportOption // used to specify whether key check should be ignored.
[ "OptImportOptionsIgnoreKeyCheck", "is", "a", "functional", "option", "on", "ImportOption", "used", "to", "specify", "whether", "key", "check", "should", "be", "ignored", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L839-L844
train
pilosa/pilosa
api.go
AvailableShardsByIndex
func (api *API) AvailableShardsByIndex(ctx context.Context) map[string]*roaring.Bitmap { span, _ := tracing.StartSpanFromContext(ctx, "API.AvailableShardsByIndex") defer span.Finish() return api.holder.availableShardsByIndex() }
go
func (api *API) AvailableShardsByIndex(ctx context.Context) map[string]*roaring.Bitmap { span, _ := tracing.StartSpanFromContext(ctx, "API.AvailableShardsByIndex") defer span.Finish() return api.holder.availableShardsByIndex() }
[ "func", "(", "api", "*", "API", ")", "AvailableShardsByIndex", "(", "ctx", "context", ".", "Context", ")", "map", "[", "string", "]", "*", "roaring", ".", "Bitmap", "{", "span", ",", "_", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "...
// AvailableShardsByIndex returns bitmaps of shards with available by index name.
[ "AvailableShardsByIndex", "returns", "bitmaps", "of", "shards", "with", "available", "by", "index", "name", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L1064-L1068
train
pilosa/pilosa
api.go
StatsWithTags
func (api *API) StatsWithTags(tags []string) stats.StatsClient { if api.holder == nil || api.cluster == nil { return nil } return api.holder.Stats.WithTags(tags...) }
go
func (api *API) StatsWithTags(tags []string) stats.StatsClient { if api.holder == nil || api.cluster == nil { return nil } return api.holder.Stats.WithTags(tags...) }
[ "func", "(", "api", "*", "API", ")", "StatsWithTags", "(", "tags", "[", "]", "string", ")", "stats", ".", "StatsClient", "{", "if", "api", ".", "holder", "==", "nil", "||", "api", ".", "cluster", "==", "nil", "{", "return", "nil", "\n", "}", "\n", ...
// StatsWithTags returns an instance of whatever implementation of StatsClient // pilosa is using with the given tags.
[ "StatsWithTags", "returns", "an", "instance", "of", "whatever", "implementation", "of", "StatsClient", "pilosa", "is", "using", "with", "the", "given", "tags", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L1072-L1077
train
pilosa/pilosa
api.go
SetCoordinator
func (api *API) SetCoordinator(ctx context.Context, id string) (oldNode, newNode *Node, err error) { span, _ := tracing.StartSpanFromContext(ctx, "API.SetCoordinator") defer span.Finish() if err := api.validate(apiSetCoordinator); err != nil { return nil, nil, errors.Wrap(err, "validating api method") } oldNode = api.cluster.nodeByID(api.cluster.Coordinator) newNode = api.cluster.nodeByID(id) if newNode == nil { return nil, nil, errors.Wrap(ErrNodeIDNotExists, "getting new node") } // If the new coordinator is this node, do the SetCoordinator directly. if newNode.ID == api.Node().ID { return oldNode, newNode, api.cluster.setCoordinator(newNode) } // Send the set-coordinator message to new node. err = api.server.SendTo( newNode, &SetCoordinatorMessage{ New: newNode, }) if err != nil { return nil, nil, fmt.Errorf("problem sending SetCoordinator message: %s", err) } return oldNode, newNode, nil }
go
func (api *API) SetCoordinator(ctx context.Context, id string) (oldNode, newNode *Node, err error) { span, _ := tracing.StartSpanFromContext(ctx, "API.SetCoordinator") defer span.Finish() if err := api.validate(apiSetCoordinator); err != nil { return nil, nil, errors.Wrap(err, "validating api method") } oldNode = api.cluster.nodeByID(api.cluster.Coordinator) newNode = api.cluster.nodeByID(id) if newNode == nil { return nil, nil, errors.Wrap(ErrNodeIDNotExists, "getting new node") } // If the new coordinator is this node, do the SetCoordinator directly. if newNode.ID == api.Node().ID { return oldNode, newNode, api.cluster.setCoordinator(newNode) } // Send the set-coordinator message to new node. err = api.server.SendTo( newNode, &SetCoordinatorMessage{ New: newNode, }) if err != nil { return nil, nil, fmt.Errorf("problem sending SetCoordinator message: %s", err) } return oldNode, newNode, nil }
[ "func", "(", "api", "*", "API", ")", "SetCoordinator", "(", "ctx", "context", ".", "Context", ",", "id", "string", ")", "(", "oldNode", ",", "newNode", "*", "Node", ",", "err", "error", ")", "{", "span", ",", "_", ":=", "tracing", ".", "StartSpanFrom...
// SetCoordinator makes a new Node the cluster coordinator.
[ "SetCoordinator", "makes", "a", "new", "Node", "the", "cluster", "coordinator", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L1117-L1146
train
pilosa/pilosa
api.go
RemoveNode
func (api *API) RemoveNode(id string) (*Node, error) { if err := api.validate(apiRemoveNode); err != nil { return nil, errors.Wrap(err, "validating api method") } removeNode := api.cluster.nodeByID(id) if removeNode == nil { if !api.cluster.topologyContainsNode(id) { return nil, errors.Wrap(ErrNodeIDNotExists, "finding node to remove") } removeNode = &Node{ ID: id, } } // Start the resize process (similar to NodeJoin) err := api.cluster.nodeLeave(id) if err != nil { return removeNode, errors.Wrap(err, "calling node leave") } return removeNode, nil }
go
func (api *API) RemoveNode(id string) (*Node, error) { if err := api.validate(apiRemoveNode); err != nil { return nil, errors.Wrap(err, "validating api method") } removeNode := api.cluster.nodeByID(id) if removeNode == nil { if !api.cluster.topologyContainsNode(id) { return nil, errors.Wrap(ErrNodeIDNotExists, "finding node to remove") } removeNode = &Node{ ID: id, } } // Start the resize process (similar to NodeJoin) err := api.cluster.nodeLeave(id) if err != nil { return removeNode, errors.Wrap(err, "calling node leave") } return removeNode, nil }
[ "func", "(", "api", "*", "API", ")", "RemoveNode", "(", "id", "string", ")", "(", "*", "Node", ",", "error", ")", "{", "if", "err", ":=", "api", ".", "validate", "(", "apiRemoveNode", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "erro...
// RemoveNode puts the cluster into the "RESIZING" state and begins the job of // removing the given node.
[ "RemoveNode", "puts", "the", "cluster", "into", "the", "RESIZING", "state", "and", "begins", "the", "job", "of", "removing", "the", "given", "node", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L1150-L1171
train
pilosa/pilosa
api.go
ResizeAbort
func (api *API) ResizeAbort() error { if err := api.validate(apiResizeAbort); err != nil { return errors.Wrap(err, "validating api method") } err := api.cluster.completeCurrentJob(resizeJobStateAborted) return errors.Wrap(err, "complete current job") }
go
func (api *API) ResizeAbort() error { if err := api.validate(apiResizeAbort); err != nil { return errors.Wrap(err, "validating api method") } err := api.cluster.completeCurrentJob(resizeJobStateAborted) return errors.Wrap(err, "complete current job") }
[ "func", "(", "api", "*", "API", ")", "ResizeAbort", "(", ")", "error", "{", "if", "err", ":=", "api", ".", "validate", "(", "apiResizeAbort", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"validating api method\...
// ResizeAbort stops the current resize job.
[ "ResizeAbort", "stops", "the", "current", "resize", "job", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L1174-L1181
train
pilosa/pilosa
api.go
GetTranslateData
func (api *API) GetTranslateData(ctx context.Context, offset int64) (io.ReadCloser, error) { span, ctx := tracing.StartSpanFromContext(ctx, "API.GetTranslateData") defer span.Finish() rc, err := api.holder.translateFile.Reader(ctx, offset) if err != nil { return nil, errors.Wrap(err, "read from translate store") } // Ensure reader is closed when the client disconnects. go func() { <-ctx.Done(); rc.Close() }() return rc, nil }
go
func (api *API) GetTranslateData(ctx context.Context, offset int64) (io.ReadCloser, error) { span, ctx := tracing.StartSpanFromContext(ctx, "API.GetTranslateData") defer span.Finish() rc, err := api.holder.translateFile.Reader(ctx, offset) if err != nil { return nil, errors.Wrap(err, "read from translate store") } // Ensure reader is closed when the client disconnects. go func() { <-ctx.Done(); rc.Close() }() return rc, nil }
[ "func", "(", "api", "*", "API", ")", "GetTranslateData", "(", "ctx", "context", ".", "Context", ",", "offset", "int64", ")", "(", "io", ".", "ReadCloser", ",", "error", ")", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "c...
// GetTranslateData provides a reader for key translation logs starting at offset.
[ "GetTranslateData", "provides", "a", "reader", "for", "key", "translation", "logs", "starting", "at", "offset", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L1184-L1197
train
pilosa/pilosa
api.go
Info
func (api *API) Info() serverInfo { si := api.server.systemInfo // we don't report errors on failures to get this information physicalCores, logicalCores, _ := si.CPUCores() mhz, _ := si.CPUMHz() mem, _ := si.MemTotal() return serverInfo{ ShardWidth: ShardWidth, CPUPhysicalCores: physicalCores, CPULogicalCores: logicalCores, CPUMHz: mhz, CPUType: si.CPUModel(), Memory: mem, } }
go
func (api *API) Info() serverInfo { si := api.server.systemInfo // we don't report errors on failures to get this information physicalCores, logicalCores, _ := si.CPUCores() mhz, _ := si.CPUMHz() mem, _ := si.MemTotal() return serverInfo{ ShardWidth: ShardWidth, CPUPhysicalCores: physicalCores, CPULogicalCores: logicalCores, CPUMHz: mhz, CPUType: si.CPUModel(), Memory: mem, } }
[ "func", "(", "api", "*", "API", ")", "Info", "(", ")", "serverInfo", "{", "si", ":=", "api", ".", "server", ".", "systemInfo", "\n", "physicalCores", ",", "logicalCores", ",", "_", ":=", "si", ".", "CPUCores", "(", ")", "\n", "mhz", ",", "_", ":=",...
// Info returns information about this server instance.
[ "Info", "returns", "information", "about", "this", "server", "instance", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L1212-L1226
train
pilosa/pilosa
api.go
TranslateKeys
func (api *API) TranslateKeys(body io.Reader) ([]byte, error) { reqBytes, err := ioutil.ReadAll(body) if err != nil { return nil, NewBadRequestError(errors.Wrap(err, "read body error")) } var req TranslateKeysRequest if err := api.Serializer.Unmarshal(reqBytes, &req); err != nil { return nil, NewBadRequestError(errors.Wrap(err, "unmarshal body error")) } var ids []uint64 if req.Field == "" { ids, err = api.holder.translateFile.TranslateColumnsToUint64(req.Index, req.Keys) } else { ids, err = api.holder.translateFile.TranslateRowsToUint64(req.Index, req.Field, req.Keys) } if err != nil { return nil, err } resp := TranslateKeysResponse{ IDs: ids, } // Encode response. buf, err := api.Serializer.Marshal(&resp) if err != nil { return nil, errors.Wrap(err, "translate keys response encoding error") } return buf, nil }
go
func (api *API) TranslateKeys(body io.Reader) ([]byte, error) { reqBytes, err := ioutil.ReadAll(body) if err != nil { return nil, NewBadRequestError(errors.Wrap(err, "read body error")) } var req TranslateKeysRequest if err := api.Serializer.Unmarshal(reqBytes, &req); err != nil { return nil, NewBadRequestError(errors.Wrap(err, "unmarshal body error")) } var ids []uint64 if req.Field == "" { ids, err = api.holder.translateFile.TranslateColumnsToUint64(req.Index, req.Keys) } else { ids, err = api.holder.translateFile.TranslateRowsToUint64(req.Index, req.Field, req.Keys) } if err != nil { return nil, err } resp := TranslateKeysResponse{ IDs: ids, } // Encode response. buf, err := api.Serializer.Marshal(&resp) if err != nil { return nil, errors.Wrap(err, "translate keys response encoding error") } return buf, nil }
[ "func", "(", "api", "*", "API", ")", "TranslateKeys", "(", "body", "io", ".", "Reader", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "reqBytes", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "body", ")", "\n", "if", "err", "!=", "nil", ...
// TranslateKeys handles a TranslateKeyRequest.
[ "TranslateKeys", "handles", "a", "TranslateKeyRequest", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/api.go#L1229-L1257
train
pilosa/pilosa
tracing/opentracing/opentracing.go
StartSpanFromContext
func (t *Tracer) StartSpanFromContext(ctx context.Context, operationName string) (tracing.Span, context.Context) { var opts []opentracing.StartSpanOption if parent := opentracing.SpanFromContext(ctx); parent != nil { opts = append(opts, opentracing.ChildOf(parent.Context())) } span := t.tracer.StartSpan(operationName, opts...) return span, opentracing.ContextWithSpan(ctx, span) }
go
func (t *Tracer) StartSpanFromContext(ctx context.Context, operationName string) (tracing.Span, context.Context) { var opts []opentracing.StartSpanOption if parent := opentracing.SpanFromContext(ctx); parent != nil { opts = append(opts, opentracing.ChildOf(parent.Context())) } span := t.tracer.StartSpan(operationName, opts...) return span, opentracing.ContextWithSpan(ctx, span) }
[ "func", "(", "t", "*", "Tracer", ")", "StartSpanFromContext", "(", "ctx", "context", ".", "Context", ",", "operationName", "string", ")", "(", "tracing", ".", "Span", ",", "context", ".", "Context", ")", "{", "var", "opts", "[", "]", "opentracing", ".", ...
// StartSpanFromContext returns a new child span and context from a given context.
[ "StartSpanFromContext", "returns", "a", "new", "child", "span", "and", "context", "from", "a", "given", "context", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/tracing/opentracing/opentracing.go#L41-L48
train
pilosa/pilosa
tracing/opentracing/opentracing.go
InjectHTTPHeaders
func (t *Tracer) InjectHTTPHeaders(r *http.Request) { if span := opentracing.SpanFromContext(r.Context()); span != nil { if err := t.tracer.Inject( span.Context(), opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(r.Header), ); err != nil { log.Printf("opentracing inject error: %s", err) } } }
go
func (t *Tracer) InjectHTTPHeaders(r *http.Request) { if span := opentracing.SpanFromContext(r.Context()); span != nil { if err := t.tracer.Inject( span.Context(), opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(r.Header), ); err != nil { log.Printf("opentracing inject error: %s", err) } } }
[ "func", "(", "t", "*", "Tracer", ")", "InjectHTTPHeaders", "(", "r", "*", "http", ".", "Request", ")", "{", "if", "span", ":=", "opentracing", ".", "SpanFromContext", "(", "r", ".", "Context", "(", ")", ")", ";", "span", "!=", "nil", "{", "if", "er...
// InjectHTTPHeaders adds the required HTTP headers to pass context between nodes.
[ "InjectHTTPHeaders", "adds", "the", "required", "HTTP", "headers", "to", "pass", "context", "between", "nodes", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/tracing/opentracing/opentracing.go#L51-L61
train
pilosa/pilosa
tracing/opentracing/opentracing.go
ExtractHTTPHeaders
func (t *Tracer) ExtractHTTPHeaders(r *http.Request) (tracing.Span, context.Context) { // Deserialize tracing context into request. wireContext, _ := t.tracer.Extract( opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(r.Header), ) span := t.tracer.StartSpan("HTTP", ext.RPCServerOption(wireContext)) ctx := opentracing.ContextWithSpan(r.Context(), span) return span, ctx }
go
func (t *Tracer) ExtractHTTPHeaders(r *http.Request) (tracing.Span, context.Context) { // Deserialize tracing context into request. wireContext, _ := t.tracer.Extract( opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(r.Header), ) span := t.tracer.StartSpan("HTTP", ext.RPCServerOption(wireContext)) ctx := opentracing.ContextWithSpan(r.Context(), span) return span, ctx }
[ "func", "(", "t", "*", "Tracer", ")", "ExtractHTTPHeaders", "(", "r", "*", "http", ".", "Request", ")", "(", "tracing", ".", "Span", ",", "context", ".", "Context", ")", "{", "wireContext", ",", "_", ":=", "t", ".", "tracer", ".", "Extract", "(", "...
// ExtractHTTPHeaders reads the HTTP headers to derive incoming context.
[ "ExtractHTTPHeaders", "reads", "the", "HTTP", "headers", "to", "derive", "incoming", "context", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/tracing/opentracing/opentracing.go#L64-L74
train
pilosa/pilosa
logger/logger.go
Printf
func (cl *CaptureLogger) Printf(format string, v ...interface{}) { cl.Prints = append(cl.Prints, fmt.Sprintf(format, v...)) }
go
func (cl *CaptureLogger) Printf(format string, v ...interface{}) { cl.Prints = append(cl.Prints, fmt.Sprintf(format, v...)) }
[ "func", "(", "cl", "*", "CaptureLogger", ")", "Printf", "(", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "cl", ".", "Prints", "=", "append", "(", "cl", ".", "Prints", ",", "fmt", ".", "Sprintf", "(", "format", ",", "v", ...
// Printf formats a message and appends it to Prints.
[ "Printf", "formats", "a", "message", "and", "appends", "it", "to", "Prints", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/logger/logger.go#L100-L102
train
pilosa/pilosa
logger/logger.go
Debugf
func (cl *CaptureLogger) Debugf(format string, v ...interface{}) { cl.Debugs = append(cl.Debugs, fmt.Sprintf(format, v...)) }
go
func (cl *CaptureLogger) Debugf(format string, v ...interface{}) { cl.Debugs = append(cl.Debugs, fmt.Sprintf(format, v...)) }
[ "func", "(", "cl", "*", "CaptureLogger", ")", "Debugf", "(", "format", "string", ",", "v", "...", "interface", "{", "}", ")", "{", "cl", ".", "Debugs", "=", "append", "(", "cl", ".", "Debugs", ",", "fmt", ".", "Sprintf", "(", "format", ",", "v", ...
// Debugf formats a message and appends it to Debugs.
[ "Debugf", "formats", "a", "message", "and", "appends", "it", "to", "Debugs", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/logger/logger.go#L105-L107
train
pilosa/pilosa
view.go
newView
func newView(path, index, field, name string, fieldOptions FieldOptions) *view { return &view{ path: path, index: index, field: field, name: name, fieldType: fieldOptions.Type, cacheType: fieldOptions.CacheType, cacheSize: fieldOptions.CacheSize, fragments: make(map[uint64]*fragment), broadcaster: NopBroadcaster, stats: stats.NopStatsClient, logger: logger.NopLogger, } }
go
func newView(path, index, field, name string, fieldOptions FieldOptions) *view { return &view{ path: path, index: index, field: field, name: name, fieldType: fieldOptions.Type, cacheType: fieldOptions.CacheType, cacheSize: fieldOptions.CacheSize, fragments: make(map[uint64]*fragment), broadcaster: NopBroadcaster, stats: stats.NopStatsClient, logger: logger.NopLogger, } }
[ "func", "newView", "(", "path", ",", "index", ",", "field", ",", "name", "string", ",", "fieldOptions", "FieldOptions", ")", "*", "view", "{", "return", "&", "view", "{", "path", ":", "path", ",", "index", ":", "index", ",", "field", ":", "field", ",...
// newView returns a new instance of View.
[ "newView", "returns", "a", "new", "instance", "of", "View", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L62-L79
train
pilosa/pilosa
view.go
open
func (v *view) open() error { // Never keep a cache for field views. if strings.HasPrefix(v.name, viewBSIGroupPrefix) { v.cacheType = CacheTypeNone } if err := func() error { // Ensure the view's path exists. v.logger.Debugf("ensure view path exists: %s", v.path) if err := os.MkdirAll(v.path, 0777); err != nil { return errors.Wrap(err, "creating view directory") } else if err := os.MkdirAll(filepath.Join(v.path, "fragments"), 0777); err != nil { return errors.Wrap(err, "creating fragments directory") } v.logger.Debugf("open fragments for index/field/view: %s/%s/%s", v.index, v.field, v.name) if err := v.openFragments(); err != nil { return errors.Wrap(err, "opening fragments") } return nil }(); err != nil { v.close() return err } v.logger.Debugf("successfully opened index/field/view: %s/%s/%s", v.index, v.field, v.name) return nil }
go
func (v *view) open() error { // Never keep a cache for field views. if strings.HasPrefix(v.name, viewBSIGroupPrefix) { v.cacheType = CacheTypeNone } if err := func() error { // Ensure the view's path exists. v.logger.Debugf("ensure view path exists: %s", v.path) if err := os.MkdirAll(v.path, 0777); err != nil { return errors.Wrap(err, "creating view directory") } else if err := os.MkdirAll(filepath.Join(v.path, "fragments"), 0777); err != nil { return errors.Wrap(err, "creating fragments directory") } v.logger.Debugf("open fragments for index/field/view: %s/%s/%s", v.index, v.field, v.name) if err := v.openFragments(); err != nil { return errors.Wrap(err, "opening fragments") } return nil }(); err != nil { v.close() return err } v.logger.Debugf("successfully opened index/field/view: %s/%s/%s", v.index, v.field, v.name) return nil }
[ "func", "(", "v", "*", "view", ")", "open", "(", ")", "error", "{", "if", "strings", ".", "HasPrefix", "(", "v", ".", "name", ",", "viewBSIGroupPrefix", ")", "{", "v", ".", "cacheType", "=", "CacheTypeNone", "\n", "}", "\n", "if", "err", ":=", "fun...
// open opens and initializes the view.
[ "open", "opens", "and", "initializes", "the", "view", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L82-L111
train
pilosa/pilosa
view.go
openFragments
func (v *view) openFragments() error { file, err := os.Open(filepath.Join(v.path, "fragments")) if os.IsNotExist(err) { return nil } else if err != nil { return errors.Wrap(err, "opening fragments directory") } defer file.Close() fis, err := file.Readdir(0) if err != nil { return errors.Wrap(err, "reading fragments directory") } for _, fi := range fis { if fi.IsDir() { continue } // Parse filename into integer. shard, err := strconv.ParseUint(filepath.Base(fi.Name()), 10, 64) if err != nil { v.logger.Debugf("WARNING: couldn't use non-integer file as shard in index/field/view %s/%s/%s: %s", v.index, v.field, v.name, fi.Name()) continue } v.logger.Debugf("open index/field/view/fragment: %s/%s/%s/%d", v.index, v.field, v.name, shard) frag := v.newFragment(v.fragmentPath(shard), shard) if err := frag.Open(); err != nil { return fmt.Errorf("open fragment: shard=%d, err=%s", frag.shard, err) } frag.RowAttrStore = v.rowAttrStore v.logger.Debugf("add index/field/view/fragment to view.fragments: %s/%s/%s/%d", v.index, v.field, v.name, shard) v.fragments[frag.shard] = frag } return nil }
go
func (v *view) openFragments() error { file, err := os.Open(filepath.Join(v.path, "fragments")) if os.IsNotExist(err) { return nil } else if err != nil { return errors.Wrap(err, "opening fragments directory") } defer file.Close() fis, err := file.Readdir(0) if err != nil { return errors.Wrap(err, "reading fragments directory") } for _, fi := range fis { if fi.IsDir() { continue } // Parse filename into integer. shard, err := strconv.ParseUint(filepath.Base(fi.Name()), 10, 64) if err != nil { v.logger.Debugf("WARNING: couldn't use non-integer file as shard in index/field/view %s/%s/%s: %s", v.index, v.field, v.name, fi.Name()) continue } v.logger.Debugf("open index/field/view/fragment: %s/%s/%s/%d", v.index, v.field, v.name, shard) frag := v.newFragment(v.fragmentPath(shard), shard) if err := frag.Open(); err != nil { return fmt.Errorf("open fragment: shard=%d, err=%s", frag.shard, err) } frag.RowAttrStore = v.rowAttrStore v.logger.Debugf("add index/field/view/fragment to view.fragments: %s/%s/%s/%d", v.index, v.field, v.name, shard) v.fragments[frag.shard] = frag } return nil }
[ "func", "(", "v", "*", "view", ")", "openFragments", "(", ")", "error", "{", "file", ",", "err", ":=", "os", ".", "Open", "(", "filepath", ".", "Join", "(", "v", ".", "path", ",", "\"fragments\"", ")", ")", "\n", "if", "os", ".", "IsNotExist", "(...
// openFragments opens and initializes the fragments inside the view.
[ "openFragments", "opens", "and", "initializes", "the", "fragments", "inside", "the", "view", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L114-L151
train
pilosa/pilosa
view.go
close
func (v *view) close() error { v.mu.Lock() defer v.mu.Unlock() // Close all fragments. for _, frag := range v.fragments { if err := frag.Close(); err != nil { return errors.Wrap(err, "closing fragment") } } v.fragments = make(map[uint64]*fragment) return nil }
go
func (v *view) close() error { v.mu.Lock() defer v.mu.Unlock() // Close all fragments. for _, frag := range v.fragments { if err := frag.Close(); err != nil { return errors.Wrap(err, "closing fragment") } } v.fragments = make(map[uint64]*fragment) return nil }
[ "func", "(", "v", "*", "view", ")", "close", "(", ")", "error", "{", "v", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "v", ".", "mu", ".", "Unlock", "(", ")", "\n", "for", "_", ",", "frag", ":=", "range", "v", ".", "fragments", "{", "i...
// close closes the view and its fragments.
[ "close", "closes", "the", "view", "and", "its", "fragments", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L154-L167
train
pilosa/pilosa
view.go
availableShards
func (v *view) availableShards() *roaring.Bitmap { v.mu.RLock() defer v.mu.RUnlock() b := roaring.NewBitmap() for shard := range v.fragments { _, _ = b.Add(shard) // ignore error, no writer attached } return b }
go
func (v *view) availableShards() *roaring.Bitmap { v.mu.RLock() defer v.mu.RUnlock() b := roaring.NewBitmap() for shard := range v.fragments { _, _ = b.Add(shard) // ignore error, no writer attached } return b }
[ "func", "(", "v", "*", "view", ")", "availableShards", "(", ")", "*", "roaring", ".", "Bitmap", "{", "v", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "v", ".", "mu", ".", "RUnlock", "(", ")", "\n", "b", ":=", "roaring", ".", "NewBitmap", ...
// availableShards returns a bitmap of shards which contain data.
[ "availableShards", "returns", "a", "bitmap", "of", "shards", "which", "contain", "data", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L170-L179
train
pilosa/pilosa
view.go
fragmentPath
func (v *view) fragmentPath(shard uint64) string { return filepath.Join(v.path, "fragments", strconv.FormatUint(shard, 10)) }
go
func (v *view) fragmentPath(shard uint64) string { return filepath.Join(v.path, "fragments", strconv.FormatUint(shard, 10)) }
[ "func", "(", "v", "*", "view", ")", "fragmentPath", "(", "shard", "uint64", ")", "string", "{", "return", "filepath", ".", "Join", "(", "v", ".", "path", ",", "\"fragments\"", ",", "strconv", ".", "FormatUint", "(", "shard", ",", "10", ")", ")", "\n"...
// fragmentPath returns the path to a fragment in the view.
[ "fragmentPath", "returns", "the", "path", "to", "a", "fragment", "in", "the", "view", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L182-L184
train
pilosa/pilosa
view.go
Fragment
func (v *view) Fragment(shard uint64) *fragment { v.mu.RLock() defer v.mu.RUnlock() return v.fragments[shard] }
go
func (v *view) Fragment(shard uint64) *fragment { v.mu.RLock() defer v.mu.RUnlock() return v.fragments[shard] }
[ "func", "(", "v", "*", "view", ")", "Fragment", "(", "shard", "uint64", ")", "*", "fragment", "{", "v", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "v", ".", "mu", ".", "RUnlock", "(", ")", "\n", "return", "v", ".", "fragments", "[", "sha...
// Fragment returns a fragment in the view by shard.
[ "Fragment", "returns", "a", "fragment", "in", "the", "view", "by", "shard", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L187-L191
train
pilosa/pilosa
view.go
allFragments
func (v *view) allFragments() []*fragment { v.mu.Lock() defer v.mu.Unlock() other := make([]*fragment, 0, len(v.fragments)) for _, fragment := range v.fragments { other = append(other, fragment) } return other }
go
func (v *view) allFragments() []*fragment { v.mu.Lock() defer v.mu.Unlock() other := make([]*fragment, 0, len(v.fragments)) for _, fragment := range v.fragments { other = append(other, fragment) } return other }
[ "func", "(", "v", "*", "view", ")", "allFragments", "(", ")", "[", "]", "*", "fragment", "{", "v", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "v", ".", "mu", ".", "Unlock", "(", ")", "\n", "other", ":=", "make", "(", "[", "]", "*", "f...
// allFragments returns a list of all fragments in the view.
[ "allFragments", "returns", "a", "list", "of", "all", "fragments", "in", "the", "view", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L194-L203
train
pilosa/pilosa
view.go
CreateFragmentIfNotExists
func (v *view) CreateFragmentIfNotExists(shard uint64) (*fragment, error) { v.mu.Lock() defer v.mu.Unlock() // Find fragment in cache first. if frag := v.fragments[shard]; frag != nil { return frag, nil } // Initialize and open fragment. frag := v.newFragment(v.fragmentPath(shard), shard) if err := frag.Open(); err != nil { return nil, errors.Wrap(err, "opening fragment") } frag.RowAttrStore = v.rowAttrStore v.fragments[shard] = frag broadcastChan := make(chan struct{}) go func() { msg := &CreateShardMessage{ Index: v.index, Field: v.field, Shard: shard, } // Broadcast a message that a new max shard was just created. err := v.broadcaster.SendSync(msg) if err != nil { v.logger.Printf("broadcasting create shard: %v", err) } close(broadcastChan) }() // We want to wait until the broadcast is complete, but what if it // takes a really long time? So we time out. select { case <-broadcastChan: case <-time.After(50 * time.Millisecond): v.logger.Debugf("broadcasting create shard took >50ms") } return frag, nil }
go
func (v *view) CreateFragmentIfNotExists(shard uint64) (*fragment, error) { v.mu.Lock() defer v.mu.Unlock() // Find fragment in cache first. if frag := v.fragments[shard]; frag != nil { return frag, nil } // Initialize and open fragment. frag := v.newFragment(v.fragmentPath(shard), shard) if err := frag.Open(); err != nil { return nil, errors.Wrap(err, "opening fragment") } frag.RowAttrStore = v.rowAttrStore v.fragments[shard] = frag broadcastChan := make(chan struct{}) go func() { msg := &CreateShardMessage{ Index: v.index, Field: v.field, Shard: shard, } // Broadcast a message that a new max shard was just created. err := v.broadcaster.SendSync(msg) if err != nil { v.logger.Printf("broadcasting create shard: %v", err) } close(broadcastChan) }() // We want to wait until the broadcast is complete, but what if it // takes a really long time? So we time out. select { case <-broadcastChan: case <-time.After(50 * time.Millisecond): v.logger.Debugf("broadcasting create shard took >50ms") } return frag, nil }
[ "func", "(", "v", "*", "view", ")", "CreateFragmentIfNotExists", "(", "shard", "uint64", ")", "(", "*", "fragment", ",", "error", ")", "{", "v", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "v", ".", "mu", ".", "Unlock", "(", ")", "\n", "if",...
// CreateFragmentIfNotExists returns a fragment in the view by shard.
[ "CreateFragmentIfNotExists", "returns", "a", "fragment", "in", "the", "view", "by", "shard", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L213-L254
train
pilosa/pilosa
view.go
deleteFragment
func (v *view) deleteFragment(shard uint64) error { fragment := v.Fragment(shard) if fragment == nil { return ErrFragmentNotFound } v.logger.Printf("delete fragment: (%s/%s/%s) %d", v.index, v.field, v.name, shard) // Close data files before deletion. if err := fragment.Close(); err != nil { return errors.Wrap(err, "closing fragment") } // Delete fragment file. if err := os.Remove(fragment.path); err != nil { return errors.Wrap(err, "deleting fragment file") } // Delete fragment cache file. if err := os.Remove(fragment.cachePath()); err != nil { v.logger.Printf("no cache file to delete for shard %d", shard) } delete(v.fragments, shard) return nil }
go
func (v *view) deleteFragment(shard uint64) error { fragment := v.Fragment(shard) if fragment == nil { return ErrFragmentNotFound } v.logger.Printf("delete fragment: (%s/%s/%s) %d", v.index, v.field, v.name, shard) // Close data files before deletion. if err := fragment.Close(); err != nil { return errors.Wrap(err, "closing fragment") } // Delete fragment file. if err := os.Remove(fragment.path); err != nil { return errors.Wrap(err, "deleting fragment file") } // Delete fragment cache file. if err := os.Remove(fragment.cachePath()); err != nil { v.logger.Printf("no cache file to delete for shard %d", shard) } delete(v.fragments, shard) return nil }
[ "func", "(", "v", "*", "view", ")", "deleteFragment", "(", "shard", "uint64", ")", "error", "{", "fragment", ":=", "v", ".", "Fragment", "(", "shard", ")", "\n", "if", "fragment", "==", "nil", "{", "return", "ErrFragmentNotFound", "\n", "}", "\n", "v",...
// deleteFragment removes the fragment from the view.
[ "deleteFragment", "removes", "the", "fragment", "from", "the", "view", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L271-L297
train
pilosa/pilosa
view.go
row
func (v *view) row(rowID uint64) *Row { row := NewRow() for _, frag := range v.allFragments() { fr := frag.row(rowID) if fr == nil { continue } row.Merge(fr) } return row }
go
func (v *view) row(rowID uint64) *Row { row := NewRow() for _, frag := range v.allFragments() { fr := frag.row(rowID) if fr == nil { continue } row.Merge(fr) } return row }
[ "func", "(", "v", "*", "view", ")", "row", "(", "rowID", "uint64", ")", "*", "Row", "{", "row", ":=", "NewRow", "(", ")", "\n", "for", "_", ",", "frag", ":=", "range", "v", ".", "allFragments", "(", ")", "{", "fr", ":=", "frag", ".", "row", "...
// row returns a row for a shard of the view.
[ "row", "returns", "a", "row", "for", "a", "shard", "of", "the", "view", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L300-L311
train
pilosa/pilosa
view.go
setBit
func (v *view) setBit(rowID, columnID uint64) (changed bool, err error) { shard := columnID / ShardWidth frag, err := v.CreateFragmentIfNotExists(shard) if err != nil { return changed, err } return frag.setBit(rowID, columnID) }
go
func (v *view) setBit(rowID, columnID uint64) (changed bool, err error) { shard := columnID / ShardWidth frag, err := v.CreateFragmentIfNotExists(shard) if err != nil { return changed, err } return frag.setBit(rowID, columnID) }
[ "func", "(", "v", "*", "view", ")", "setBit", "(", "rowID", ",", "columnID", "uint64", ")", "(", "changed", "bool", ",", "err", "error", ")", "{", "shard", ":=", "columnID", "/", "ShardWidth", "\n", "frag", ",", "err", ":=", "v", ".", "CreateFragment...
// setBit sets a bit within the view.
[ "setBit", "sets", "a", "bit", "within", "the", "view", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L314-L321
train
pilosa/pilosa
view.go
clearBit
func (v *view) clearBit(rowID, columnID uint64) (changed bool, err error) { shard := columnID / ShardWidth frag := v.Fragment(shard) if frag == nil { return false, nil } return frag.clearBit(rowID, columnID) }
go
func (v *view) clearBit(rowID, columnID uint64) (changed bool, err error) { shard := columnID / ShardWidth frag := v.Fragment(shard) if frag == nil { return false, nil } return frag.clearBit(rowID, columnID) }
[ "func", "(", "v", "*", "view", ")", "clearBit", "(", "rowID", ",", "columnID", "uint64", ")", "(", "changed", "bool", ",", "err", "error", ")", "{", "shard", ":=", "columnID", "/", "ShardWidth", "\n", "frag", ":=", "v", ".", "Fragment", "(", "shard",...
// clearBit clears a bit within the view.
[ "clearBit", "clears", "a", "bit", "within", "the", "view", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L324-L331
train
pilosa/pilosa
view.go
sum
func (v *view) sum(filter *Row, bitDepth uint) (sum, count uint64, err error) { for _, f := range v.allFragments() { fsum, fcount, err := f.sum(filter, bitDepth) if err != nil { return sum, count, err } sum += fsum count += fcount } return sum, count, nil }
go
func (v *view) sum(filter *Row, bitDepth uint) (sum, count uint64, err error) { for _, f := range v.allFragments() { fsum, fcount, err := f.sum(filter, bitDepth) if err != nil { return sum, count, err } sum += fsum count += fcount } return sum, count, nil }
[ "func", "(", "v", "*", "view", ")", "sum", "(", "filter", "*", "Row", ",", "bitDepth", "uint", ")", "(", "sum", ",", "count", "uint64", ",", "err", "error", ")", "{", "for", "_", ",", "f", ":=", "range", "v", ".", "allFragments", "(", ")", "{",...
// sum returns the sum & count of a field.
[ "sum", "returns", "the", "sum", "&", "count", "of", "a", "field", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L354-L364
train
pilosa/pilosa
view.go
min
func (v *view) min(filter *Row, bitDepth uint) (min, count uint64, err error) { var minHasValue bool for _, f := range v.allFragments() { fmin, fcount, err := f.min(filter, bitDepth) if err != nil { return min, count, err } // Don't consider a min based on zero columns. if fcount == 0 { continue } if !minHasValue { min = fmin minHasValue = true count += fcount continue } if fmin < min { min = fmin count += fcount } } return min, count, nil }
go
func (v *view) min(filter *Row, bitDepth uint) (min, count uint64, err error) { var minHasValue bool for _, f := range v.allFragments() { fmin, fcount, err := f.min(filter, bitDepth) if err != nil { return min, count, err } // Don't consider a min based on zero columns. if fcount == 0 { continue } if !minHasValue { min = fmin minHasValue = true count += fcount continue } if fmin < min { min = fmin count += fcount } } return min, count, nil }
[ "func", "(", "v", "*", "view", ")", "min", "(", "filter", "*", "Row", ",", "bitDepth", "uint", ")", "(", "min", ",", "count", "uint64", ",", "err", "error", ")", "{", "var", "minHasValue", "bool", "\n", "for", "_", ",", "f", ":=", "range", "v", ...
// min returns the min and count of a field.
[ "min", "returns", "the", "min", "and", "count", "of", "a", "field", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L367-L392
train
pilosa/pilosa
view.go
max
func (v *view) max(filter *Row, bitDepth uint) (max, count uint64, err error) { for _, f := range v.allFragments() { fmax, fcount, err := f.max(filter, bitDepth) if err != nil { return max, count, err } if fcount > 0 && fmax > max { max = fmax count += fcount } } return max, count, nil }
go
func (v *view) max(filter *Row, bitDepth uint) (max, count uint64, err error) { for _, f := range v.allFragments() { fmax, fcount, err := f.max(filter, bitDepth) if err != nil { return max, count, err } if fcount > 0 && fmax > max { max = fmax count += fcount } } return max, count, nil }
[ "func", "(", "v", "*", "view", ")", "max", "(", "filter", "*", "Row", ",", "bitDepth", "uint", ")", "(", "max", ",", "count", "uint64", ",", "err", "error", ")", "{", "for", "_", ",", "f", ":=", "range", "v", ".", "allFragments", "(", ")", "{",...
// max returns the max and count of a field.
[ "max", "returns", "the", "max", "and", "count", "of", "a", "field", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L395-L407
train
pilosa/pilosa
view.go
rangeOp
func (v *view) rangeOp(op pql.Token, bitDepth uint, predicate uint64) (*Row, error) { r := NewRow() for _, frag := range v.allFragments() { other, err := frag.rangeOp(op, bitDepth, predicate) if err != nil { return nil, err } r = r.Union(other) } return r, nil }
go
func (v *view) rangeOp(op pql.Token, bitDepth uint, predicate uint64) (*Row, error) { r := NewRow() for _, frag := range v.allFragments() { other, err := frag.rangeOp(op, bitDepth, predicate) if err != nil { return nil, err } r = r.Union(other) } return r, nil }
[ "func", "(", "v", "*", "view", ")", "rangeOp", "(", "op", "pql", ".", "Token", ",", "bitDepth", "uint", ",", "predicate", "uint64", ")", "(", "*", "Row", ",", "error", ")", "{", "r", ":=", "NewRow", "(", ")", "\n", "for", "_", ",", "frag", ":="...
// rangeOp returns rows with a field value encoding matching the predicate.
[ "rangeOp", "returns", "rows", "with", "a", "field", "value", "encoding", "matching", "the", "predicate", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/view.go#L410-L420
train
pilosa/pilosa
ctl/config.go
NewConfigCommand
func NewConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *ConfigCommand { return &ConfigCommand{ CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr), } }
go
func NewConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *ConfigCommand { return &ConfigCommand{ CmdIO: pilosa.NewCmdIO(stdin, stdout, stderr), } }
[ "func", "NewConfigCommand", "(", "stdin", "io", ".", "Reader", ",", "stdout", ",", "stderr", "io", ".", "Writer", ")", "*", "ConfigCommand", "{", "return", "&", "ConfigCommand", "{", "CmdIO", ":", "pilosa", ".", "NewCmdIO", "(", "stdin", ",", "stdout", "...
// NewConfigCommand returns a new instance of ConfigCommand.
[ "NewConfigCommand", "returns", "a", "new", "instance", "of", "ConfigCommand", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/ctl/config.go#L34-L38
train
pilosa/pilosa
holder.go
NewHolder
func NewHolder() *Holder { return &Holder{ indexes: make(map[string]*Index), closing: make(chan struct{}), opened: lockedChan{ch: make(chan struct{})}, translateFile: NewTranslateFile(), NewPrimaryTranslateStore: newNopTranslateStore, broadcaster: NopBroadcaster, Stats: stats.NopStatsClient, NewAttrStore: newNopAttrStore, cacheFlushInterval: defaultCacheFlushInterval, Logger: logger.NopLogger, } }
go
func NewHolder() *Holder { return &Holder{ indexes: make(map[string]*Index), closing: make(chan struct{}), opened: lockedChan{ch: make(chan struct{})}, translateFile: NewTranslateFile(), NewPrimaryTranslateStore: newNopTranslateStore, broadcaster: NopBroadcaster, Stats: stats.NopStatsClient, NewAttrStore: newNopAttrStore, cacheFlushInterval: defaultCacheFlushInterval, Logger: logger.NopLogger, } }
[ "func", "NewHolder", "(", ")", "*", "Holder", "{", "return", "&", "Holder", "{", "indexes", ":", "make", "(", "map", "[", "string", "]", "*", "Index", ")", ",", "closing", ":", "make", "(", "chan", "struct", "{", "}", ")", ",", "opened", ":", "lo...
// NewHolder returns a new instance of Holder.
[ "NewHolder", "returns", "a", "new", "instance", "of", "Holder", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L110-L129
train
pilosa/pilosa
holder.go
Open
func (h *Holder) Open() error { // Reset closing in case Holder is being reopened. h.closing = make(chan struct{}) h.setFileLimit() h.Logger.Printf("open holder path: %s", h.Path) if err := os.MkdirAll(h.Path, 0777); err != nil { return errors.Wrap(err, "creating directory") } // Open path to read all index directories. f, err := os.Open(h.Path) if err != nil { return errors.Wrap(err, "opening directory") } defer f.Close() fis, err := f.Readdir(0) if err != nil { return errors.Wrap(err, "reading directory") } for _, fi := range fis { // Skip files or hidden directories. if !fi.IsDir() || strings.HasPrefix(fi.Name(), ".") { continue } h.Logger.Printf("opening index: %s", filepath.Base(fi.Name())) index, err := h.newIndex(h.IndexPath(filepath.Base(fi.Name())), filepath.Base(fi.Name())) if errors.Cause(err) == ErrName { h.Logger.Printf("ERROR opening index: %s, err=%s", fi.Name(), err) continue } else if err != nil { return errors.Wrap(err, "opening index") } if err := index.Open(); err != nil { if err == ErrName { h.Logger.Printf("ERROR opening index: %s, err=%s", index.Name(), err) continue } return fmt.Errorf("open index: name=%s, err=%s", index.Name(), err) } h.mu.Lock() h.indexes[index.Name()] = index h.mu.Unlock() } h.Logger.Printf("open holder: complete") // Periodically flush cache. h.wg.Add(1) go func() { defer h.wg.Done(); h.monitorCacheFlush() }() h.Stats.Open() h.opened.Close() return nil }
go
func (h *Holder) Open() error { // Reset closing in case Holder is being reopened. h.closing = make(chan struct{}) h.setFileLimit() h.Logger.Printf("open holder path: %s", h.Path) if err := os.MkdirAll(h.Path, 0777); err != nil { return errors.Wrap(err, "creating directory") } // Open path to read all index directories. f, err := os.Open(h.Path) if err != nil { return errors.Wrap(err, "opening directory") } defer f.Close() fis, err := f.Readdir(0) if err != nil { return errors.Wrap(err, "reading directory") } for _, fi := range fis { // Skip files or hidden directories. if !fi.IsDir() || strings.HasPrefix(fi.Name(), ".") { continue } h.Logger.Printf("opening index: %s", filepath.Base(fi.Name())) index, err := h.newIndex(h.IndexPath(filepath.Base(fi.Name())), filepath.Base(fi.Name())) if errors.Cause(err) == ErrName { h.Logger.Printf("ERROR opening index: %s, err=%s", fi.Name(), err) continue } else if err != nil { return errors.Wrap(err, "opening index") } if err := index.Open(); err != nil { if err == ErrName { h.Logger.Printf("ERROR opening index: %s, err=%s", index.Name(), err) continue } return fmt.Errorf("open index: name=%s, err=%s", index.Name(), err) } h.mu.Lock() h.indexes[index.Name()] = index h.mu.Unlock() } h.Logger.Printf("open holder: complete") // Periodically flush cache. h.wg.Add(1) go func() { defer h.wg.Done(); h.monitorCacheFlush() }() h.Stats.Open() h.opened.Close() return nil }
[ "func", "(", "h", "*", "Holder", ")", "Open", "(", ")", "error", "{", "h", ".", "closing", "=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "h", ".", "setFileLimit", "(", ")", "\n", "h", ".", "Logger", ".", "Printf", "(", "\"open holder p...
// Open initializes the root data directory for the holder.
[ "Open", "initializes", "the", "root", "data", "directory", "for", "the", "holder", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L132-L191
train
pilosa/pilosa
holder.go
Close
func (h *Holder) Close() error { h.Stats.Close() // Notify goroutines of closing and wait for completion. close(h.closing) h.wg.Wait() for _, index := range h.indexes { if err := index.Close(); err != nil { return errors.Wrap(err, "closing index") } } if h.translateFile != nil { if err := h.translateFile.Close(); err != nil { return err } } // Reset opened in case Holder needs to be reopened. h.opened.mu.Lock() h.opened.ch = make(chan struct{}) h.opened.mu.Unlock() return nil }
go
func (h *Holder) Close() error { h.Stats.Close() // Notify goroutines of closing and wait for completion. close(h.closing) h.wg.Wait() for _, index := range h.indexes { if err := index.Close(); err != nil { return errors.Wrap(err, "closing index") } } if h.translateFile != nil { if err := h.translateFile.Close(); err != nil { return err } } // Reset opened in case Holder needs to be reopened. h.opened.mu.Lock() h.opened.ch = make(chan struct{}) h.opened.mu.Unlock() return nil }
[ "func", "(", "h", "*", "Holder", ")", "Close", "(", ")", "error", "{", "h", ".", "Stats", ".", "Close", "(", ")", "\n", "close", "(", "h", ".", "closing", ")", "\n", "h", ".", "wg", ".", "Wait", "(", ")", "\n", "for", "_", ",", "index", ":=...
// Close closes all open fragments.
[ "Close", "closes", "all", "open", "fragments", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L194-L219
train
pilosa/pilosa
holder.go
HasData
func (h *Holder) HasData() (bool, error) { h.mu.Lock() defer h.mu.Unlock() if len(h.indexes) > 0 { return true, nil } // Open path to read all index directories. if _, err := os.Stat(h.Path); os.IsNotExist(err) { return false, nil } else if err != nil { return false, errors.Wrap(err, "statting data dir") } f, err := os.Open(h.Path) if err != nil { return false, errors.Wrap(err, "opening data dir") } defer f.Close() fis, err := f.Readdir(0) if err != nil { return false, errors.Wrap(err, "reading data dir") } for _, fi := range fis { if !fi.IsDir() { continue } return true, nil } return false, nil }
go
func (h *Holder) HasData() (bool, error) { h.mu.Lock() defer h.mu.Unlock() if len(h.indexes) > 0 { return true, nil } // Open path to read all index directories. if _, err := os.Stat(h.Path); os.IsNotExist(err) { return false, nil } else if err != nil { return false, errors.Wrap(err, "statting data dir") } f, err := os.Open(h.Path) if err != nil { return false, errors.Wrap(err, "opening data dir") } defer f.Close() fis, err := f.Readdir(0) if err != nil { return false, errors.Wrap(err, "reading data dir") } for _, fi := range fis { if !fi.IsDir() { continue } return true, nil } return false, nil }
[ "func", "(", "h", "*", "Holder", ")", "HasData", "(", ")", "(", "bool", ",", "error", ")", "{", "h", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "len", "(", "h", ".", "indexes", ")",...
// HasData returns true if Holder contains at least one index. // This is used to determine if the rebalancing of data is necessary // when a node joins the cluster.
[ "HasData", "returns", "true", "if", "Holder", "contains", "at", "least", "one", "index", ".", "This", "is", "used", "to", "determine", "if", "the", "rebalancing", "of", "data", "is", "necessary", "when", "a", "node", "joins", "the", "cluster", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L224-L255
train
pilosa/pilosa
holder.go
availableShardsByIndex
func (h *Holder) availableShardsByIndex() map[string]*roaring.Bitmap { m := make(map[string]*roaring.Bitmap) for _, index := range h.Indexes() { m[index.Name()] = index.AvailableShards() } return m }
go
func (h *Holder) availableShardsByIndex() map[string]*roaring.Bitmap { m := make(map[string]*roaring.Bitmap) for _, index := range h.Indexes() { m[index.Name()] = index.AvailableShards() } return m }
[ "func", "(", "h", "*", "Holder", ")", "availableShardsByIndex", "(", ")", "map", "[", "string", "]", "*", "roaring", ".", "Bitmap", "{", "m", ":=", "make", "(", "map", "[", "string", "]", "*", "roaring", ".", "Bitmap", ")", "\n", "for", "_", ",", ...
// availableShardsByIndex returns a bitmap of all shards by indexes.
[ "availableShardsByIndex", "returns", "a", "bitmap", "of", "all", "shards", "by", "indexes", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L258-L264
train
pilosa/pilosa
holder.go
Schema
func (h *Holder) Schema() []*IndexInfo { var a []*IndexInfo for _, index := range h.Indexes() { di := &IndexInfo{Name: index.Name()} for _, field := range index.Fields() { fi := &FieldInfo{Name: field.Name(), Options: field.Options()} for _, view := range field.views() { fi.Views = append(fi.Views, &ViewInfo{Name: view.name}) } sort.Sort(viewInfoSlice(fi.Views)) di.Fields = append(di.Fields, fi) } sort.Sort(fieldInfoSlice(di.Fields)) a = append(a, di) } sort.Sort(indexInfoSlice(a)) return a }
go
func (h *Holder) Schema() []*IndexInfo { var a []*IndexInfo for _, index := range h.Indexes() { di := &IndexInfo{Name: index.Name()} for _, field := range index.Fields() { fi := &FieldInfo{Name: field.Name(), Options: field.Options()} for _, view := range field.views() { fi.Views = append(fi.Views, &ViewInfo{Name: view.name}) } sort.Sort(viewInfoSlice(fi.Views)) di.Fields = append(di.Fields, fi) } sort.Sort(fieldInfoSlice(di.Fields)) a = append(a, di) } sort.Sort(indexInfoSlice(a)) return a }
[ "func", "(", "h", "*", "Holder", ")", "Schema", "(", ")", "[", "]", "*", "IndexInfo", "{", "var", "a", "[", "]", "*", "IndexInfo", "\n", "for", "_", ",", "index", ":=", "range", "h", ".", "Indexes", "(", ")", "{", "di", ":=", "&", "IndexInfo", ...
// Schema returns schema information for all indexes, fields, and views.
[ "Schema", "returns", "schema", "information", "for", "all", "indexes", "fields", "and", "views", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L267-L284
train
pilosa/pilosa
holder.go
limitedSchema
func (h *Holder) limitedSchema() []*IndexInfo { var a []*IndexInfo for _, index := range h.Indexes() { di := &IndexInfo{ Name: index.Name(), Options: index.Options(), ShardWidth: ShardWidth, } for _, field := range index.Fields() { if strings.HasPrefix(field.name, "_") { continue } fi := &FieldInfo{Name: field.Name(), Options: field.Options()} di.Fields = append(di.Fields, fi) } sort.Sort(fieldInfoSlice(di.Fields)) a = append(a, di) } sort.Sort(indexInfoSlice(a)) return a }
go
func (h *Holder) limitedSchema() []*IndexInfo { var a []*IndexInfo for _, index := range h.Indexes() { di := &IndexInfo{ Name: index.Name(), Options: index.Options(), ShardWidth: ShardWidth, } for _, field := range index.Fields() { if strings.HasPrefix(field.name, "_") { continue } fi := &FieldInfo{Name: field.Name(), Options: field.Options()} di.Fields = append(di.Fields, fi) } sort.Sort(fieldInfoSlice(di.Fields)) a = append(a, di) } sort.Sort(indexInfoSlice(a)) return a }
[ "func", "(", "h", "*", "Holder", ")", "limitedSchema", "(", ")", "[", "]", "*", "IndexInfo", "{", "var", "a", "[", "]", "*", "IndexInfo", "\n", "for", "_", ",", "index", ":=", "range", "h", ".", "Indexes", "(", ")", "{", "di", ":=", "&", "Index...
// limitedSchema returns schema information for all indexes and fields.
[ "limitedSchema", "returns", "schema", "information", "for", "all", "indexes", "and", "fields", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L287-L307
train
pilosa/pilosa
holder.go
applySchema
func (h *Holder) applySchema(schema *Schema) error { // Create indexes that don't exist. for _, index := range schema.Indexes { idx, err := h.CreateIndexIfNotExists(index.Name, index.Options) if err != nil { return errors.Wrap(err, "creating index") } // Create fields that don't exist. for _, f := range index.Fields { field, err := idx.createFieldIfNotExists(f.Name, f.Options) if err != nil { return errors.Wrap(err, "creating field") } // Create views that don't exist. for _, v := range f.Views { _, err := field.createViewIfNotExists(v.Name) if err != nil { return errors.Wrap(err, "creating view") } } } } return nil }
go
func (h *Holder) applySchema(schema *Schema) error { // Create indexes that don't exist. for _, index := range schema.Indexes { idx, err := h.CreateIndexIfNotExists(index.Name, index.Options) if err != nil { return errors.Wrap(err, "creating index") } // Create fields that don't exist. for _, f := range index.Fields { field, err := idx.createFieldIfNotExists(f.Name, f.Options) if err != nil { return errors.Wrap(err, "creating field") } // Create views that don't exist. for _, v := range f.Views { _, err := field.createViewIfNotExists(v.Name) if err != nil { return errors.Wrap(err, "creating view") } } } } return nil }
[ "func", "(", "h", "*", "Holder", ")", "applySchema", "(", "schema", "*", "Schema", ")", "error", "{", "for", "_", ",", "index", ":=", "range", "schema", ".", "Indexes", "{", "idx", ",", "err", ":=", "h", ".", "CreateIndexIfNotExists", "(", "index", "...
// applySchema applies an internal Schema to Holder.
[ "applySchema", "applies", "an", "internal", "Schema", "to", "Holder", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L310-L333
train
pilosa/pilosa
holder.go
Index
func (h *Holder) Index(name string) *Index { h.mu.RLock() defer h.mu.RUnlock() return h.index(name) }
go
func (h *Holder) Index(name string) *Index { h.mu.RLock() defer h.mu.RUnlock() return h.index(name) }
[ "func", "(", "h", "*", "Holder", ")", "Index", "(", "name", "string", ")", "*", "Index", "{", "h", ".", "mu", ".", "RLock", "(", ")", "\n", "defer", "h", ".", "mu", ".", "RUnlock", "(", ")", "\n", "return", "h", ".", "index", "(", "name", ")"...
// Index returns the index by name.
[ "Index", "returns", "the", "index", "by", "name", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L339-L343
train
pilosa/pilosa
holder.go
Indexes
func (h *Holder) Indexes() []*Index { h.mu.RLock() a := make([]*Index, 0, len(h.indexes)) for _, index := range h.indexes { a = append(a, index) } h.mu.RUnlock() sort.Sort(indexSlice(a)) return a }
go
func (h *Holder) Indexes() []*Index { h.mu.RLock() a := make([]*Index, 0, len(h.indexes)) for _, index := range h.indexes { a = append(a, index) } h.mu.RUnlock() sort.Sort(indexSlice(a)) return a }
[ "func", "(", "h", "*", "Holder", ")", "Indexes", "(", ")", "[", "]", "*", "Index", "{", "h", ".", "mu", ".", "RLock", "(", ")", "\n", "a", ":=", "make", "(", "[", "]", "*", "Index", ",", "0", ",", "len", "(", "h", ".", "indexes", ")", ")"...
// Indexes returns a list of all indexes in the holder.
[ "Indexes", "returns", "a", "list", "of", "all", "indexes", "in", "the", "holder", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L348-L358
train
pilosa/pilosa
holder.go
CreateIndex
func (h *Holder) CreateIndex(name string, opt IndexOptions) (*Index, error) { h.mu.Lock() defer h.mu.Unlock() // Ensure index doesn't already exist. if h.indexes[name] != nil { return nil, newConflictError(ErrIndexExists) } return h.createIndex(name, opt) }
go
func (h *Holder) CreateIndex(name string, opt IndexOptions) (*Index, error) { h.mu.Lock() defer h.mu.Unlock() // Ensure index doesn't already exist. if h.indexes[name] != nil { return nil, newConflictError(ErrIndexExists) } return h.createIndex(name, opt) }
[ "func", "(", "h", "*", "Holder", ")", "CreateIndex", "(", "name", "string", ",", "opt", "IndexOptions", ")", "(", "*", "Index", ",", "error", ")", "{", "h", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "mu", ".", "Unlock", "(", ")...
// CreateIndex creates an index. // An error is returned if the index already exists.
[ "CreateIndex", "creates", "an", "index", ".", "An", "error", "is", "returned", "if", "the", "index", "already", "exists", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L362-L371
train
pilosa/pilosa
holder.go
CreateIndexIfNotExists
func (h *Holder) CreateIndexIfNotExists(name string, opt IndexOptions) (*Index, error) { h.mu.Lock() defer h.mu.Unlock() // Find index in cache first. if index := h.indexes[name]; index != nil { return index, nil } return h.createIndex(name, opt) }
go
func (h *Holder) CreateIndexIfNotExists(name string, opt IndexOptions) (*Index, error) { h.mu.Lock() defer h.mu.Unlock() // Find index in cache first. if index := h.indexes[name]; index != nil { return index, nil } return h.createIndex(name, opt) }
[ "func", "(", "h", "*", "Holder", ")", "CreateIndexIfNotExists", "(", "name", "string", ",", "opt", "IndexOptions", ")", "(", "*", "Index", ",", "error", ")", "{", "h", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "mu", ".", "Unlock", ...
// CreateIndexIfNotExists returns an index by name. // The index is created if it does not already exist.
[ "CreateIndexIfNotExists", "returns", "an", "index", "by", "name", ".", "The", "index", "is", "created", "if", "it", "does", "not", "already", "exist", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L375-L385
train
pilosa/pilosa
holder.go
DeleteIndex
func (h *Holder) DeleteIndex(name string) error { h.mu.Lock() defer h.mu.Unlock() // Confirm index exists. index := h.index(name) if index == nil { return newNotFoundError(ErrIndexNotFound) } // Close index. if err := index.Close(); err != nil { return errors.Wrap(err, "closing") } // Delete index directory. if err := os.RemoveAll(h.IndexPath(name)); err != nil { return errors.Wrap(err, "removing directory") } // Remove reference. delete(h.indexes, name) return nil }
go
func (h *Holder) DeleteIndex(name string) error { h.mu.Lock() defer h.mu.Unlock() // Confirm index exists. index := h.index(name) if index == nil { return newNotFoundError(ErrIndexNotFound) } // Close index. if err := index.Close(); err != nil { return errors.Wrap(err, "closing") } // Delete index directory. if err := os.RemoveAll(h.IndexPath(name)); err != nil { return errors.Wrap(err, "removing directory") } // Remove reference. delete(h.indexes, name) return nil }
[ "func", "(", "h", "*", "Holder", ")", "DeleteIndex", "(", "name", "string", ")", "error", "{", "h", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "h", ".", "mu", ".", "Unlock", "(", ")", "\n", "index", ":=", "h", ".", "index", "(", "name", ...
// DeleteIndex removes an index from the holder.
[ "DeleteIndex", "removes", "an", "index", "from", "the", "holder", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L432-L456
train
pilosa/pilosa
holder.go
Field
func (h *Holder) Field(index, name string) *Field { idx := h.Index(index) if idx == nil { return nil } return idx.Field(name) }
go
func (h *Holder) Field(index, name string) *Field { idx := h.Index(index) if idx == nil { return nil } return idx.Field(name) }
[ "func", "(", "h", "*", "Holder", ")", "Field", "(", "index", ",", "name", "string", ")", "*", "Field", "{", "idx", ":=", "h", ".", "Index", "(", "index", ")", "\n", "if", "idx", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "idx...
// Field returns the field for an index and name.
[ "Field", "returns", "the", "field", "for", "an", "index", "and", "name", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L459-L465
train
pilosa/pilosa
holder.go
view
func (h *Holder) view(index, field, name string) *view { f := h.Field(index, field) if f == nil { return nil } return f.view(name) }
go
func (h *Holder) view(index, field, name string) *view { f := h.Field(index, field) if f == nil { return nil } return f.view(name) }
[ "func", "(", "h", "*", "Holder", ")", "view", "(", "index", ",", "field", ",", "name", "string", ")", "*", "view", "{", "f", ":=", "h", ".", "Field", "(", "index", ",", "field", ")", "\n", "if", "f", "==", "nil", "{", "return", "nil", "\n", "...
// view returns the view for an index, field, and name.
[ "view", "returns", "the", "view", "for", "an", "index", "field", "and", "name", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L468-L474
train
pilosa/pilosa
holder.go
fragment
func (h *Holder) fragment(index, field, view string, shard uint64) *fragment { v := h.view(index, field, view) if v == nil { return nil } return v.Fragment(shard) }
go
func (h *Holder) fragment(index, field, view string, shard uint64) *fragment { v := h.view(index, field, view) if v == nil { return nil } return v.Fragment(shard) }
[ "func", "(", "h", "*", "Holder", ")", "fragment", "(", "index", ",", "field", ",", "view", "string", ",", "shard", "uint64", ")", "*", "fragment", "{", "v", ":=", "h", ".", "view", "(", "index", ",", "field", ",", "view", ")", "\n", "if", "v", ...
// fragment returns the fragment for an index, field & shard.
[ "fragment", "returns", "the", "fragment", "for", "an", "index", "field", "&", "shard", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L477-L483
train
pilosa/pilosa
holder.go
monitorCacheFlush
func (h *Holder) monitorCacheFlush() { ticker := time.NewTicker(h.cacheFlushInterval) defer ticker.Stop() for { select { case <-h.closing: return case <-ticker.C: h.flushCaches() } } }
go
func (h *Holder) monitorCacheFlush() { ticker := time.NewTicker(h.cacheFlushInterval) defer ticker.Stop() for { select { case <-h.closing: return case <-ticker.C: h.flushCaches() } } }
[ "func", "(", "h", "*", "Holder", ")", "monitorCacheFlush", "(", ")", "{", "ticker", ":=", "time", ".", "NewTicker", "(", "h", ".", "cacheFlushInterval", ")", "\n", "defer", "ticker", ".", "Stop", "(", ")", "\n", "for", "{", "select", "{", "case", "<-...
// monitorCacheFlush periodically flushes all fragment caches sequentially. // This is run in a goroutine.
[ "monitorCacheFlush", "periodically", "flushes", "all", "fragment", "caches", "sequentially", ".", "This", "is", "run", "in", "a", "goroutine", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L487-L499
train
pilosa/pilosa
holder.go
setFileLimit
func (h *Holder) setFileLimit() { oldLimit := &syscall.Rlimit{} newLimit := &syscall.Rlimit{} if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, oldLimit); err != nil { h.Logger.Printf("ERROR checking open file limit: %s", err) return } // If the soft limit is lower than the FileLimit constant, we will try to change it. if oldLimit.Cur < fileLimit { newLimit.Cur = fileLimit // If the hard limit is not high enough, we will try to change it too. if oldLimit.Max < fileLimit { newLimit.Max = fileLimit } else { newLimit.Max = oldLimit.Max } // Try to set the limit if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, newLimit); err != nil { // If we just tried to change the hard limit and failed, we probably don't have permission. Let's try again without setting the hard limit. if newLimit.Max > oldLimit.Max { newLimit.Max = oldLimit.Max // Obviously the hard limit cannot be higher than the soft limit. if newLimit.Cur >= newLimit.Max { newLimit.Cur = newLimit.Max } // Try setting again with lowered Max (hard limit) if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, newLimit); err != nil { h.Logger.Printf("ERROR setting open file limit: %s", err) } // If we weren't trying to change the hard limit, let the user know something is wrong. } else { h.Logger.Printf("ERROR setting open file limit: %s", err) } } // Check the limit after setting it. OS may not obey Setrlimit call. if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, oldLimit); err != nil { h.Logger.Printf("ERROR checking open file limit: %s", err) } else { if oldLimit.Cur < fileLimit { h.Logger.Printf("WARNING: Tried to set open file limit to %d, but it is %d. You may consider running \"sudo ulimit -n %d\" before starting Pilosa to avoid \"too many open files\" error. See https://www.pilosa.com/docs/latest/administration/#open-file-limits for more information.", fileLimit, oldLimit.Cur, fileLimit) } } } }
go
func (h *Holder) setFileLimit() { oldLimit := &syscall.Rlimit{} newLimit := &syscall.Rlimit{} if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, oldLimit); err != nil { h.Logger.Printf("ERROR checking open file limit: %s", err) return } // If the soft limit is lower than the FileLimit constant, we will try to change it. if oldLimit.Cur < fileLimit { newLimit.Cur = fileLimit // If the hard limit is not high enough, we will try to change it too. if oldLimit.Max < fileLimit { newLimit.Max = fileLimit } else { newLimit.Max = oldLimit.Max } // Try to set the limit if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, newLimit); err != nil { // If we just tried to change the hard limit and failed, we probably don't have permission. Let's try again without setting the hard limit. if newLimit.Max > oldLimit.Max { newLimit.Max = oldLimit.Max // Obviously the hard limit cannot be higher than the soft limit. if newLimit.Cur >= newLimit.Max { newLimit.Cur = newLimit.Max } // Try setting again with lowered Max (hard limit) if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, newLimit); err != nil { h.Logger.Printf("ERROR setting open file limit: %s", err) } // If we weren't trying to change the hard limit, let the user know something is wrong. } else { h.Logger.Printf("ERROR setting open file limit: %s", err) } } // Check the limit after setting it. OS may not obey Setrlimit call. if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, oldLimit); err != nil { h.Logger.Printf("ERROR checking open file limit: %s", err) } else { if oldLimit.Cur < fileLimit { h.Logger.Printf("WARNING: Tried to set open file limit to %d, but it is %d. You may consider running \"sudo ulimit -n %d\" before starting Pilosa to avoid \"too many open files\" error. See https://www.pilosa.com/docs/latest/administration/#open-file-limits for more information.", fileLimit, oldLimit.Cur, fileLimit) } } } }
[ "func", "(", "h", "*", "Holder", ")", "setFileLimit", "(", ")", "{", "oldLimit", ":=", "&", "syscall", ".", "Rlimit", "{", "}", "\n", "newLimit", ":=", "&", "syscall", ".", "Rlimit", "{", "}", "\n", "if", "err", ":=", "syscall", ".", "Getrlimit", "...
// setFileLimit attempts to set the open file limit to the FileLimit constant defined above.
[ "setFileLimit", "attempts", "to", "set", "the", "open", "file", "limit", "to", "the", "FileLimit", "constant", "defined", "above", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L532-L578
train
pilosa/pilosa
holder.go
IsClosing
func (s *holderSyncer) IsClosing() bool { if s.Cluster.abortAntiEntropyQ() { return true } select { case <-s.Closing: return true default: return false } }
go
func (s *holderSyncer) IsClosing() bool { if s.Cluster.abortAntiEntropyQ() { return true } select { case <-s.Closing: return true default: return false } }
[ "func", "(", "s", "*", "holderSyncer", ")", "IsClosing", "(", ")", "bool", "{", "if", "s", ".", "Cluster", ".", "abortAntiEntropyQ", "(", ")", "{", "return", "true", "\n", "}", "\n", "select", "{", "case", "<-", "s", ".", "Closing", ":", "return", ...
// IsClosing returns true if the syncer has been asked to close.
[ "IsClosing", "returns", "true", "if", "the", "syncer", "has", "been", "asked", "to", "close", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L651-L661
train
pilosa/pilosa
holder.go
SyncHolder
func (s *holderSyncer) SyncHolder() error { s.mu.Lock() // only allow one instance of SyncHolder to be running at a time defer s.mu.Unlock() ti := time.Now() // Iterate over schema in sorted order. for _, di := range s.Holder.Schema() { // Verify syncer has not closed. if s.IsClosing() { return nil } // Sync index column attributes. if err := s.syncIndex(di.Name); err != nil { return fmt.Errorf("index sync error: index=%s, err=%s", di.Name, err) } tf := time.Now() for _, fi := range di.Fields { // Verify syncer has not closed. if s.IsClosing() { return nil } // Sync field row attributes. if err := s.syncField(di.Name, fi.Name); err != nil { return fmt.Errorf("field sync error: index=%s, field=%s, err=%s", di.Name, fi.Name, err) } for _, vi := range fi.Views { // Verify syncer has not closed. if s.IsClosing() { return nil } itr := s.Holder.Index(di.Name).AvailableShards().Iterator() itr.Seek(0) for shard, eof := itr.Next(); !eof; shard, eof = itr.Next() { // Ignore shards that this host doesn't own. if !s.Cluster.ownsShard(s.Node.ID, di.Name, shard) { continue } // Verify syncer has not closed. if s.IsClosing() { return nil } // Sync fragment if own it. if err := s.syncFragment(di.Name, fi.Name, vi.Name, shard); err != nil { return fmt.Errorf("fragment sync error: index=%s, field=%s, view=%s, shard=%d, err=%s", di.Name, fi.Name, vi.Name, shard, err) } } } s.Stats.Histogram("syncField", float64(time.Since(tf)), 1.0) tf = time.Now() // reset tf } s.Stats.Histogram("syncIndex", float64(time.Since(ti)), 1.0) ti = time.Now() // reset ti } return nil }
go
func (s *holderSyncer) SyncHolder() error { s.mu.Lock() // only allow one instance of SyncHolder to be running at a time defer s.mu.Unlock() ti := time.Now() // Iterate over schema in sorted order. for _, di := range s.Holder.Schema() { // Verify syncer has not closed. if s.IsClosing() { return nil } // Sync index column attributes. if err := s.syncIndex(di.Name); err != nil { return fmt.Errorf("index sync error: index=%s, err=%s", di.Name, err) } tf := time.Now() for _, fi := range di.Fields { // Verify syncer has not closed. if s.IsClosing() { return nil } // Sync field row attributes. if err := s.syncField(di.Name, fi.Name); err != nil { return fmt.Errorf("field sync error: index=%s, field=%s, err=%s", di.Name, fi.Name, err) } for _, vi := range fi.Views { // Verify syncer has not closed. if s.IsClosing() { return nil } itr := s.Holder.Index(di.Name).AvailableShards().Iterator() itr.Seek(0) for shard, eof := itr.Next(); !eof; shard, eof = itr.Next() { // Ignore shards that this host doesn't own. if !s.Cluster.ownsShard(s.Node.ID, di.Name, shard) { continue } // Verify syncer has not closed. if s.IsClosing() { return nil } // Sync fragment if own it. if err := s.syncFragment(di.Name, fi.Name, vi.Name, shard); err != nil { return fmt.Errorf("fragment sync error: index=%s, field=%s, view=%s, shard=%d, err=%s", di.Name, fi.Name, vi.Name, shard, err) } } } s.Stats.Histogram("syncField", float64(time.Since(tf)), 1.0) tf = time.Now() // reset tf } s.Stats.Histogram("syncIndex", float64(time.Since(ti)), 1.0) ti = time.Now() // reset ti } return nil }
[ "func", "(", "s", "*", "holderSyncer", ")", "SyncHolder", "(", ")", "error", "{", "s", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "ti", ":=", "time", ".", "Now", "(", ")", "\n", "for", "_",...
// SyncHolder compares the holder on host with the local holder and resolves differences.
[ "SyncHolder", "compares", "the", "holder", "on", "host", "with", "the", "local", "holder", "and", "resolves", "differences", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L664-L725
train
pilosa/pilosa
holder.go
syncIndex
func (s *holderSyncer) syncIndex(index string) error { span, ctx := tracing.StartSpanFromContext(context.Background(), "HolderSyncer.syncIndex") defer span.Finish() // Retrieve index reference. idx := s.Holder.Index(index) if idx == nil { return nil } indexTag := fmt.Sprintf("index:%s", index) // Read block checksums. blks, err := idx.ColumnAttrStore().Blocks() if err != nil { return errors.Wrap(err, "getting blocks") } s.Stats.CountWithCustomTags("ColumnAttrStoreBlocks", int64(len(blks)), 1.0, []string{indexTag}) // Sync with every other host. for _, node := range Nodes(s.Cluster.nodes).FilterID(s.Node.ID) { // Retrieve attributes from differing blocks. // Skip update and recomputation if no attributes have changed. m, err := s.Cluster.InternalClient.ColumnAttrDiff(ctx, &node.URI, index, blks) if err != nil { return errors.Wrap(err, "getting differing blocks") } else if len(m) == 0 { continue } s.Stats.CountWithCustomTags("ColumnAttrDiff", int64(len(m)), 1.0, []string{indexTag, node.ID}) // Update local copy. if err := idx.ColumnAttrStore().SetBulkAttrs(m); err != nil { return errors.Wrap(err, "setting attrs") } // Recompute blocks. blks, err = idx.ColumnAttrStore().Blocks() if err != nil { return errors.Wrap(err, "recomputing blocks") } } return nil }
go
func (s *holderSyncer) syncIndex(index string) error { span, ctx := tracing.StartSpanFromContext(context.Background(), "HolderSyncer.syncIndex") defer span.Finish() // Retrieve index reference. idx := s.Holder.Index(index) if idx == nil { return nil } indexTag := fmt.Sprintf("index:%s", index) // Read block checksums. blks, err := idx.ColumnAttrStore().Blocks() if err != nil { return errors.Wrap(err, "getting blocks") } s.Stats.CountWithCustomTags("ColumnAttrStoreBlocks", int64(len(blks)), 1.0, []string{indexTag}) // Sync with every other host. for _, node := range Nodes(s.Cluster.nodes).FilterID(s.Node.ID) { // Retrieve attributes from differing blocks. // Skip update and recomputation if no attributes have changed. m, err := s.Cluster.InternalClient.ColumnAttrDiff(ctx, &node.URI, index, blks) if err != nil { return errors.Wrap(err, "getting differing blocks") } else if len(m) == 0 { continue } s.Stats.CountWithCustomTags("ColumnAttrDiff", int64(len(m)), 1.0, []string{indexTag, node.ID}) // Update local copy. if err := idx.ColumnAttrStore().SetBulkAttrs(m); err != nil { return errors.Wrap(err, "setting attrs") } // Recompute blocks. blks, err = idx.ColumnAttrStore().Blocks() if err != nil { return errors.Wrap(err, "recomputing blocks") } } return nil }
[ "func", "(", "s", "*", "holderSyncer", ")", "syncIndex", "(", "index", "string", ")", "error", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "context", ".", "Background", "(", ")", ",", "\"HolderSyncer.syncIndex\"", ")", "\n", ...
// syncIndex synchronizes index attributes with the rest of the cluster.
[ "syncIndex", "synchronizes", "index", "attributes", "with", "the", "rest", "of", "the", "cluster", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L728-L771
train
pilosa/pilosa
holder.go
syncField
func (s *holderSyncer) syncField(index, name string) error { span, ctx := tracing.StartSpanFromContext(context.Background(), "HolderSyncer.syncField") defer span.Finish() // Retrieve field reference. f := s.Holder.Field(index, name) if f == nil { return nil } indexTag := fmt.Sprintf("index:%s", index) fieldTag := fmt.Sprintf("field:%s", name) // Read block checksums. blks, err := f.RowAttrStore().Blocks() if err != nil { return errors.Wrap(err, "getting blocks") } s.Stats.CountWithCustomTags("RowAttrStoreBlocks", int64(len(blks)), 1.0, []string{indexTag, fieldTag}) // Sync with every other host. for _, node := range Nodes(s.Cluster.nodes).FilterID(s.Node.ID) { // Retrieve attributes from differing blocks. // Skip update and recomputation if no attributes have changed. m, err := s.Cluster.InternalClient.RowAttrDiff(ctx, &node.URI, index, name, blks) if err == ErrFieldNotFound { continue // field not created remotely yet, skip } else if err != nil { return errors.Wrap(err, "getting differing blocks") } else if len(m) == 0 { continue } s.Stats.CountWithCustomTags("RowAttrDiff", int64(len(m)), 1.0, []string{indexTag, fieldTag, node.ID}) // Update local copy. if err := f.RowAttrStore().SetBulkAttrs(m); err != nil { return errors.Wrap(err, "setting attrs") } // Recompute blocks. blks, err = f.RowAttrStore().Blocks() if err != nil { return errors.Wrap(err, "recomputing blocks") } } return nil }
go
func (s *holderSyncer) syncField(index, name string) error { span, ctx := tracing.StartSpanFromContext(context.Background(), "HolderSyncer.syncField") defer span.Finish() // Retrieve field reference. f := s.Holder.Field(index, name) if f == nil { return nil } indexTag := fmt.Sprintf("index:%s", index) fieldTag := fmt.Sprintf("field:%s", name) // Read block checksums. blks, err := f.RowAttrStore().Blocks() if err != nil { return errors.Wrap(err, "getting blocks") } s.Stats.CountWithCustomTags("RowAttrStoreBlocks", int64(len(blks)), 1.0, []string{indexTag, fieldTag}) // Sync with every other host. for _, node := range Nodes(s.Cluster.nodes).FilterID(s.Node.ID) { // Retrieve attributes from differing blocks. // Skip update and recomputation if no attributes have changed. m, err := s.Cluster.InternalClient.RowAttrDiff(ctx, &node.URI, index, name, blks) if err == ErrFieldNotFound { continue // field not created remotely yet, skip } else if err != nil { return errors.Wrap(err, "getting differing blocks") } else if len(m) == 0 { continue } s.Stats.CountWithCustomTags("RowAttrDiff", int64(len(m)), 1.0, []string{indexTag, fieldTag, node.ID}) // Update local copy. if err := f.RowAttrStore().SetBulkAttrs(m); err != nil { return errors.Wrap(err, "setting attrs") } // Recompute blocks. blks, err = f.RowAttrStore().Blocks() if err != nil { return errors.Wrap(err, "recomputing blocks") } } return nil }
[ "func", "(", "s", "*", "holderSyncer", ")", "syncField", "(", "index", ",", "name", "string", ")", "error", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "context", ".", "Background", "(", ")", ",", "\"HolderSyncer.syncField\"",...
// syncField synchronizes field attributes with the rest of the cluster.
[ "syncField", "synchronizes", "field", "attributes", "with", "the", "rest", "of", "the", "cluster", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L774-L820
train
pilosa/pilosa
holder.go
syncFragment
func (s *holderSyncer) syncFragment(index, field, view string, shard uint64) error { // Retrieve local field. f := s.Holder.Field(index, field) if f == nil { return ErrFieldNotFound } // Ensure view exists locally. v, err := f.createViewIfNotExists(view) if err != nil { return errors.Wrap(err, "creating view") } // Ensure fragment exists locally. frag, err := v.CreateFragmentIfNotExists(shard) if err != nil { return errors.Wrap(err, "creating fragment") } // Sync fragments together. fs := fragmentSyncer{ Fragment: frag, Node: s.Node, Cluster: s.Cluster, Closing: s.Closing, } if err := fs.syncFragment(); err != nil { return errors.Wrap(err, "syncing fragment") } return nil }
go
func (s *holderSyncer) syncFragment(index, field, view string, shard uint64) error { // Retrieve local field. f := s.Holder.Field(index, field) if f == nil { return ErrFieldNotFound } // Ensure view exists locally. v, err := f.createViewIfNotExists(view) if err != nil { return errors.Wrap(err, "creating view") } // Ensure fragment exists locally. frag, err := v.CreateFragmentIfNotExists(shard) if err != nil { return errors.Wrap(err, "creating fragment") } // Sync fragments together. fs := fragmentSyncer{ Fragment: frag, Node: s.Node, Cluster: s.Cluster, Closing: s.Closing, } if err := fs.syncFragment(); err != nil { return errors.Wrap(err, "syncing fragment") } return nil }
[ "func", "(", "s", "*", "holderSyncer", ")", "syncFragment", "(", "index", ",", "field", ",", "view", "string", ",", "shard", "uint64", ")", "error", "{", "f", ":=", "s", ".", "Holder", ".", "Field", "(", "index", ",", "field", ")", "\n", "if", "f",...
// syncFragment synchronizes a fragment with the rest of the cluster.
[ "syncFragment", "synchronizes", "a", "fragment", "with", "the", "rest", "of", "the", "cluster", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L823-L854
train
pilosa/pilosa
holder.go
CleanHolder
func (c *holderCleaner) CleanHolder() error { for _, index := range c.Holder.Indexes() { // Verify cleaner has not closed. if c.IsClosing() { return nil } // Get the fragments that node is responsible for (based on hash(index, node)). containedShards := c.Cluster.containsShards(index.Name(), index.AvailableShards(), c.Node) // Get the fragments registered in memory. for _, field := range index.Fields() { for _, view := range field.views() { for _, fragment := range view.allFragments() { fragShard := fragment.shard // Ignore fragments that should be present. if uint64InSlice(fragShard, containedShards) { continue } // Delete fragment. if err := view.deleteFragment(fragShard); err != nil { return errors.Wrap(err, "deleting fragment") } } } } } return nil }
go
func (c *holderCleaner) CleanHolder() error { for _, index := range c.Holder.Indexes() { // Verify cleaner has not closed. if c.IsClosing() { return nil } // Get the fragments that node is responsible for (based on hash(index, node)). containedShards := c.Cluster.containsShards(index.Name(), index.AvailableShards(), c.Node) // Get the fragments registered in memory. for _, field := range index.Fields() { for _, view := range field.views() { for _, fragment := range view.allFragments() { fragShard := fragment.shard // Ignore fragments that should be present. if uint64InSlice(fragShard, containedShards) { continue } // Delete fragment. if err := view.deleteFragment(fragShard); err != nil { return errors.Wrap(err, "deleting fragment") } } } } } return nil }
[ "func", "(", "c", "*", "holderCleaner", ")", "CleanHolder", "(", ")", "error", "{", "for", "_", ",", "index", ":=", "range", "c", ".", "Holder", ".", "Indexes", "(", ")", "{", "if", "c", ".", "IsClosing", "(", ")", "{", "return", "nil", "\n", "}"...
// CleanHolder compares the holder with the cluster state and removes // any unnecessary fragments and files.
[ "CleanHolder", "compares", "the", "holder", "with", "the", "cluster", "state", "and", "removes", "any", "unnecessary", "fragments", "and", "files", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/holder.go#L879-L907
train
pilosa/pilosa
fragment.go
newFragment
func newFragment(path, index, field, view string, shard uint64) *fragment { return &fragment{ path: path, index: index, field: field, view: view, shard: shard, CacheType: DefaultCacheType, CacheSize: DefaultCacheSize, Logger: logger.NopLogger, MaxOpN: defaultFragmentMaxOpN, stats: stats.NopStatsClient, } }
go
func newFragment(path, index, field, view string, shard uint64) *fragment { return &fragment{ path: path, index: index, field: field, view: view, shard: shard, CacheType: DefaultCacheType, CacheSize: DefaultCacheSize, Logger: logger.NopLogger, MaxOpN: defaultFragmentMaxOpN, stats: stats.NopStatsClient, } }
[ "func", "newFragment", "(", "path", ",", "index", ",", "field", ",", "view", "string", ",", "shard", "uint64", ")", "*", "fragment", "{", "return", "&", "fragment", "{", "path", ":", "path", ",", "index", ":", "index", ",", "field", ":", "field", ","...
// newFragment returns a new instance of Fragment.
[ "newFragment", "returns", "a", "new", "instance", "of", "Fragment", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L139-L154
train
pilosa/pilosa
fragment.go
Open
func (f *fragment) Open() error { f.mu.Lock() defer f.mu.Unlock() if err := func() error { // Initialize storage in a function so we can close if anything goes wrong. f.Logger.Debugf("open storage for index/field/view/fragment: %s/%s/%s/%d", f.index, f.field, f.view, f.shard) if err := f.openStorage(); err != nil { return errors.Wrap(err, "opening storage") } // Fill cache with rows persisted to disk. f.Logger.Debugf("open cache for index/field/view/fragment: %s/%s/%s/%d", f.index, f.field, f.view, f.shard) if err := f.openCache(); err != nil { return errors.Wrap(err, "opening cache") } // Clear checksums. f.checksums = make(map[int][]byte) // Read last bit to determine max row. pos := f.storage.Max() f.maxRowID = pos / ShardWidth f.stats.Gauge("rows", float64(f.maxRowID), 1.0) return nil }(); err != nil { f.close() return err } f.Logger.Debugf("successfully opened index/field/view/fragment: %s/%s/%s/%d", f.index, f.field, f.view, f.shard) return nil }
go
func (f *fragment) Open() error { f.mu.Lock() defer f.mu.Unlock() if err := func() error { // Initialize storage in a function so we can close if anything goes wrong. f.Logger.Debugf("open storage for index/field/view/fragment: %s/%s/%s/%d", f.index, f.field, f.view, f.shard) if err := f.openStorage(); err != nil { return errors.Wrap(err, "opening storage") } // Fill cache with rows persisted to disk. f.Logger.Debugf("open cache for index/field/view/fragment: %s/%s/%s/%d", f.index, f.field, f.view, f.shard) if err := f.openCache(); err != nil { return errors.Wrap(err, "opening cache") } // Clear checksums. f.checksums = make(map[int][]byte) // Read last bit to determine max row. pos := f.storage.Max() f.maxRowID = pos / ShardWidth f.stats.Gauge("rows", float64(f.maxRowID), 1.0) return nil }(); err != nil { f.close() return err } f.Logger.Debugf("successfully opened index/field/view/fragment: %s/%s/%s/%d", f.index, f.field, f.view, f.shard) return nil }
[ "func", "(", "f", "*", "fragment", ")", "Open", "(", ")", "error", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "err", ":=", "func", "(", ")", "error", "{", "f", ".", "Logge...
// Open opens the underlying storage.
[ "Open", "opens", "the", "underlying", "storage", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L160-L192
train
pilosa/pilosa
fragment.go
openStorage
func (f *fragment) openStorage() error { // Create a roaring bitmap to serve as storage for the shard. if f.storage == nil { f.storage = roaring.NewFileBitmap() } // Open the data file to be mmap'd and used as an ops log. file, mustClose, err := syswrap.OpenFile(f.path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { return fmt.Errorf("open file: %s", err) } f.file = file if mustClose { defer f.safeClose() } // Lock the underlying file. if err := syscall.Flock(int(f.file.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil { return fmt.Errorf("flock: %s", err) } // If the file is empty then initialize it with an empty bitmap. fi, err := f.file.Stat() if err != nil { 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 { return fmt.Errorf("init storage file: %s", err) } bi.Flush() _, err = f.file.Stat() if err != nil { return errors.Wrap(err, "statting file after") } } else { // Mmap the underlying file so it can be zero copied. data, err := syswrap.Mmap(int(f.file.Fd()), 0, int(fi.Size()), syscall.PROT_READ, syscall.MAP_SHARED) if err == syswrap.ErrMaxMapCountReached { f.Logger.Debugf("maximum number of maps reached, reading file instead") data, err = ioutil.ReadAll(file) if err != nil { return errors.Wrap(err, "failure file readall") } } else if err != nil { return errors.Wrap(err, "mmap failed") } else { f.storageData = data // Advise the kernel that the mmap is accessed randomly. if err := madvise(f.storageData, syscall.MADV_RANDOM); err != nil { return fmt.Errorf("madvise: %s", err) } } if err := f.storage.UnmarshalBinary(data); err != nil { return fmt.Errorf("unmarshal storage: file=%s, err=%s", f.file.Name(), err) } } f.opN = f.storage.Info().OpN // Attach the file to the bitmap to act as a write-ahead log. f.storage.OpWriter = f.file f.rowCache = &simpleCache{make(map[uint64]*Row)} return nil }
go
func (f *fragment) openStorage() error { // Create a roaring bitmap to serve as storage for the shard. if f.storage == nil { f.storage = roaring.NewFileBitmap() } // Open the data file to be mmap'd and used as an ops log. file, mustClose, err := syswrap.OpenFile(f.path, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { return fmt.Errorf("open file: %s", err) } f.file = file if mustClose { defer f.safeClose() } // Lock the underlying file. if err := syscall.Flock(int(f.file.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil { return fmt.Errorf("flock: %s", err) } // If the file is empty then initialize it with an empty bitmap. fi, err := f.file.Stat() if err != nil { 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 { return fmt.Errorf("init storage file: %s", err) } bi.Flush() _, err = f.file.Stat() if err != nil { return errors.Wrap(err, "statting file after") } } else { // Mmap the underlying file so it can be zero copied. data, err := syswrap.Mmap(int(f.file.Fd()), 0, int(fi.Size()), syscall.PROT_READ, syscall.MAP_SHARED) if err == syswrap.ErrMaxMapCountReached { f.Logger.Debugf("maximum number of maps reached, reading file instead") data, err = ioutil.ReadAll(file) if err != nil { return errors.Wrap(err, "failure file readall") } } else if err != nil { return errors.Wrap(err, "mmap failed") } else { f.storageData = data // Advise the kernel that the mmap is accessed randomly. if err := madvise(f.storageData, syscall.MADV_RANDOM); err != nil { return fmt.Errorf("madvise: %s", err) } } if err := f.storage.UnmarshalBinary(data); err != nil { return fmt.Errorf("unmarshal storage: file=%s, err=%s", f.file.Name(), err) } } f.opN = f.storage.Info().OpN // Attach the file to the bitmap to act as a write-ahead log. f.storage.OpWriter = f.file f.rowCache = &simpleCache{make(map[uint64]*Row)} return nil }
[ "func", "(", "f", "*", "fragment", ")", "openStorage", "(", ")", "error", "{", "if", "f", ".", "storage", "==", "nil", "{", "f", ".", "storage", "=", "roaring", ".", "NewFileBitmap", "(", ")", "\n", "}", "\n", "file", ",", "mustClose", ",", "err", ...
// openStorage opens the storage bitmap.
[ "openStorage", "opens", "the", "storage", "bitmap", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L207-L274
train
pilosa/pilosa
fragment.go
openCache
func (f *fragment) openCache() error { // Determine cache type from field name. switch f.CacheType { case CacheTypeRanked: f.cache = NewRankCache(f.CacheSize) case CacheTypeLRU: f.cache = newLRUCache(f.CacheSize) case CacheTypeNone: f.cache = globalNopCache return nil default: return ErrInvalidCacheType } // Read cache data from disk. path := f.cachePath() buf, err := ioutil.ReadFile(path) if os.IsNotExist(err) { return nil } else if err != nil { return fmt.Errorf("open cache: %s", err) } // Unmarshal cache data. var pb internal.Cache if err := proto.Unmarshal(buf, &pb); err != nil { f.Logger.Printf("error unmarshaling cache data, skipping: path=%s, err=%s", path, err) return nil } // Read in all rows by ID. // This will cause them to be added to the cache. for _, id := range pb.IDs { n := f.storage.CountRange(id*ShardWidth, (id+1)*ShardWidth) f.cache.BulkAdd(id, n) } f.cache.Invalidate() return nil }
go
func (f *fragment) openCache() error { // Determine cache type from field name. switch f.CacheType { case CacheTypeRanked: f.cache = NewRankCache(f.CacheSize) case CacheTypeLRU: f.cache = newLRUCache(f.CacheSize) case CacheTypeNone: f.cache = globalNopCache return nil default: return ErrInvalidCacheType } // Read cache data from disk. path := f.cachePath() buf, err := ioutil.ReadFile(path) if os.IsNotExist(err) { return nil } else if err != nil { return fmt.Errorf("open cache: %s", err) } // Unmarshal cache data. var pb internal.Cache if err := proto.Unmarshal(buf, &pb); err != nil { f.Logger.Printf("error unmarshaling cache data, skipping: path=%s, err=%s", path, err) return nil } // Read in all rows by ID. // This will cause them to be added to the cache. for _, id := range pb.IDs { n := f.storage.CountRange(id*ShardWidth, (id+1)*ShardWidth) f.cache.BulkAdd(id, n) } f.cache.Invalidate() return nil }
[ "func", "(", "f", "*", "fragment", ")", "openCache", "(", ")", "error", "{", "switch", "f", ".", "CacheType", "{", "case", "CacheTypeRanked", ":", "f", ".", "cache", "=", "NewRankCache", "(", "f", ".", "CacheSize", ")", "\n", "case", "CacheTypeLRU", ":...
// openCache initializes the cache from row ids persisted to disk.
[ "openCache", "initializes", "the", "cache", "from", "row", "ids", "persisted", "to", "disk", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L277-L316
train
pilosa/pilosa
fragment.go
Close
func (f *fragment) Close() error { f.mu.Lock() defer f.mu.Unlock() return f.close() }
go
func (f *fragment) Close() error { f.mu.Lock() defer f.mu.Unlock() return f.close() }
[ "func", "(", "f", "*", "fragment", ")", "Close", "(", ")", "error", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "f", ".", "close", "(", ")", "\n", "}" ]
// Close flushes the underlying storage, closes the file and unlocks it.
[ "Close", "flushes", "the", "underlying", "storage", "closes", "the", "file", "and", "unlocks", "it", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L319-L323
train
pilosa/pilosa
fragment.go
safeClose
func (f *fragment) safeClose() error { // Flush file, unlock & close. if f.file != nil { if err := f.file.Sync(); err != nil { return fmt.Errorf("sync: %s", err) } if err := syscall.Flock(int(f.file.Fd()), syscall.LOCK_UN); err != nil { return fmt.Errorf("unlock: %s", err) } if err := syswrap.CloseFile(f.file); err != nil { return fmt.Errorf("close file: %s", err) } } f.file = nil f.storage.OpWriter = nil return nil }
go
func (f *fragment) safeClose() error { // Flush file, unlock & close. if f.file != nil { if err := f.file.Sync(); err != nil { return fmt.Errorf("sync: %s", err) } if err := syscall.Flock(int(f.file.Fd()), syscall.LOCK_UN); err != nil { return fmt.Errorf("unlock: %s", err) } if err := syswrap.CloseFile(f.file); err != nil { return fmt.Errorf("close file: %s", err) } } f.file = nil f.storage.OpWriter = nil return nil }
[ "func", "(", "f", "*", "fragment", ")", "safeClose", "(", ")", "error", "{", "if", "f", ".", "file", "!=", "nil", "{", "if", "err", ":=", "f", ".", "file", ".", "Sync", "(", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "...
// safeClose is unprotected.
[ "safeClose", "is", "unprotected", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L345-L362
train
pilosa/pilosa
fragment.go
row
func (f *fragment) row(rowID uint64) *Row { f.mu.Lock() defer f.mu.Unlock() return f.unprotectedRow(rowID) }
go
func (f *fragment) row(rowID uint64) *Row { f.mu.Lock() defer f.mu.Unlock() return f.unprotectedRow(rowID) }
[ "func", "(", "f", "*", "fragment", ")", "row", "(", "rowID", "uint64", ")", "*", "Row", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "f", ".", "unprotectedRow", "(", "rowID"...
// row returns a row by ID.
[ "row", "returns", "a", "row", "by", "ID", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L390-L394
train
pilosa/pilosa
fragment.go
rowFromStorage
func (f *fragment) rowFromStorage(rowID uint64) *Row { // Only use a subset of the containers. // NOTE: The start & end ranges must be divisible by container width. data := f.storage.OffsetRange(f.shard*ShardWidth, rowID*ShardWidth, (rowID+1)*ShardWidth) // Reference bitmap subrange in storage. We Clone() data because otherwise // row will contain pointers to containers in storage. This causes // unexpected results when we cache the row and try to use it later. // Basically, since we return the Row and release the fragment lock, the // underlying fragment storage could be changed or snapshotted and thrown // out at any point. row := &Row{ segments: []rowSegment{{ data: *data.Clone(), shard: f.shard, writable: false, // this Row will probably be cached and shared, so it must be read only. }}, } row.invalidateCount() return row }
go
func (f *fragment) rowFromStorage(rowID uint64) *Row { // Only use a subset of the containers. // NOTE: The start & end ranges must be divisible by container width. data := f.storage.OffsetRange(f.shard*ShardWidth, rowID*ShardWidth, (rowID+1)*ShardWidth) // Reference bitmap subrange in storage. We Clone() data because otherwise // row will contain pointers to containers in storage. This causes // unexpected results when we cache the row and try to use it later. // Basically, since we return the Row and release the fragment lock, the // underlying fragment storage could be changed or snapshotted and thrown // out at any point. row := &Row{ segments: []rowSegment{{ data: *data.Clone(), shard: f.shard, writable: false, // this Row will probably be cached and shared, so it must be read only. }}, } row.invalidateCount() return row }
[ "func", "(", "f", "*", "fragment", ")", "rowFromStorage", "(", "rowID", "uint64", ")", "*", "Row", "{", "data", ":=", "f", ".", "storage", ".", "OffsetRange", "(", "f", ".", "shard", "*", "ShardWidth", ",", "rowID", "*", "ShardWidth", ",", "(", "rowI...
// rowFromStorage clones a row data out of fragment storage and returns it as a // Row object.
[ "rowFromStorage", "clones", "a", "row", "data", "out", "of", "fragment", "storage", "and", "returns", "it", "as", "a", "Row", "object", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L411-L432
train
pilosa/pilosa
fragment.go
setBit
func (f *fragment) setBit(rowID, columnID uint64) (changed bool, err error) { f.mu.Lock() defer f.mu.Unlock() mustClose, err := f.reopen() if err != nil { return false, errors.Wrap(err, "reopening") } if mustClose { defer f.safeClose() } // handle mutux field type if f.mutexVector != nil { if err := f.handleMutex(rowID, columnID); err != nil { return changed, errors.Wrap(err, "handling mutex") } } return f.unprotectedSetBit(rowID, columnID) }
go
func (f *fragment) setBit(rowID, columnID uint64) (changed bool, err error) { f.mu.Lock() defer f.mu.Unlock() mustClose, err := f.reopen() if err != nil { return false, errors.Wrap(err, "reopening") } if mustClose { defer f.safeClose() } // handle mutux field type if f.mutexVector != nil { if err := f.handleMutex(rowID, columnID); err != nil { return changed, errors.Wrap(err, "handling mutex") } } return f.unprotectedSetBit(rowID, columnID) }
[ "func", "(", "f", "*", "fragment", ")", "setBit", "(", "rowID", ",", "columnID", "uint64", ")", "(", "changed", "bool", ",", "err", "error", ")", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")"...
// setBit sets a bit for a given column & row within the fragment. // This updates both the on-disk storage and the in-cache bitmap.
[ "setBit", "sets", "a", "bit", "for", "a", "given", "column", "&", "row", "within", "the", "fragment", ".", "This", "updates", "both", "the", "on", "-", "disk", "storage", "and", "the", "in", "-", "cache", "bitmap", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L436-L455
train
pilosa/pilosa
fragment.go
handleMutex
func (f *fragment) handleMutex(rowID, columnID uint64) error { if existingRowID, found, err := f.mutexVector.Get(columnID); err != nil { return errors.Wrap(err, "getting mutex vector data") } else if found && existingRowID != rowID { if _, err := f.unprotectedClearBit(existingRowID, columnID); err != nil { return errors.Wrap(err, "clearing mutex value") } } return nil }
go
func (f *fragment) handleMutex(rowID, columnID uint64) error { if existingRowID, found, err := f.mutexVector.Get(columnID); err != nil { return errors.Wrap(err, "getting mutex vector data") } else if found && existingRowID != rowID { if _, err := f.unprotectedClearBit(existingRowID, columnID); err != nil { return errors.Wrap(err, "clearing mutex value") } } return nil }
[ "func", "(", "f", "*", "fragment", ")", "handleMutex", "(", "rowID", ",", "columnID", "uint64", ")", "error", "{", "if", "existingRowID", ",", "found", ",", "err", ":=", "f", ".", "mutexVector", ".", "Get", "(", "columnID", ")", ";", "err", "!=", "ni...
// handleMutex will clear an existing row and store the new row // in the vector.
[ "handleMutex", "will", "clear", "an", "existing", "row", "and", "store", "the", "new", "row", "in", "the", "vector", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L459-L468
train
pilosa/pilosa
fragment.go
clearBit
func (f *fragment) clearBit(rowID, columnID uint64) (bool, error) { f.mu.Lock() defer f.mu.Unlock() mustClose, err := f.reopen() if err != nil { return false, errors.Wrap(err, "reopening") } if mustClose { defer f.safeClose() } return f.unprotectedClearBit(rowID, columnID) }
go
func (f *fragment) clearBit(rowID, columnID uint64) (bool, error) { f.mu.Lock() defer f.mu.Unlock() mustClose, err := f.reopen() if err != nil { return false, errors.Wrap(err, "reopening") } if mustClose { defer f.safeClose() } return f.unprotectedClearBit(rowID, columnID) }
[ "func", "(", "f", "*", "fragment", ")", "clearBit", "(", "rowID", ",", "columnID", "uint64", ")", "(", "bool", ",", "error", ")", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "mustClo...
// clearBit clears a bit for a given column & row within the fragment. // This updates both the on-disk storage and the in-cache bitmap.
[ "clearBit", "clears", "a", "bit", "for", "a", "given", "column", "&", "row", "within", "the", "fragment", ".", "This", "updates", "both", "the", "on", "-", "disk", "storage", "and", "the", "in", "-", "cache", "bitmap", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L517-L528
train
pilosa/pilosa
fragment.go
clearRow
func (f *fragment) clearRow(rowID uint64) (bool, error) { f.mu.Lock() defer f.mu.Unlock() mustClose, err := f.reopen() if err != nil { return false, errors.Wrap(err, "reopening") } if mustClose { defer f.safeClose() } return f.unprotectedClearRow(rowID) }
go
func (f *fragment) clearRow(rowID uint64) (bool, error) { f.mu.Lock() defer f.mu.Unlock() mustClose, err := f.reopen() if err != nil { return false, errors.Wrap(err, "reopening") } if mustClose { defer f.safeClose() } return f.unprotectedClearRow(rowID) }
[ "func", "(", "f", "*", "fragment", ")", "clearRow", "(", "rowID", "uint64", ")", "(", "bool", ",", "error", ")", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "mustClose", ",", "err", ...
// ClearRow clears a row for a given rowID within the fragment. // This updates both the on-disk storage and the in-cache bitmap.
[ "ClearRow", "clears", "a", "row", "for", "a", "given", "rowID", "within", "the", "fragment", ".", "This", "updates", "both", "the", "on", "-", "disk", "storage", "and", "the", "in", "-", "cache", "bitmap", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L629-L640
train
pilosa/pilosa
fragment.go
clearValue
func (f *fragment) clearValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { return f.setValueBase(columnID, bitDepth, value, true) }
go
func (f *fragment) clearValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { return f.setValueBase(columnID, bitDepth, value, true) }
[ "func", "(", "f", "*", "fragment", ")", "clearValue", "(", "columnID", "uint64", ",", "bitDepth", "uint", ",", "value", "uint64", ")", "(", "changed", "bool", ",", "err", "error", ")", "{", "return", "f", ".", "setValueBase", "(", "columnID", ",", "bit...
// clearValue uses a column of bits to clear a multi-bit value.
[ "clearValue", "uses", "a", "column", "of", "bits", "to", "clear", "a", "multi", "-", "bit", "value", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L706-L708
train
pilosa/pilosa
fragment.go
setValue
func (f *fragment) setValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { return f.setValueBase(columnID, bitDepth, value, false) }
go
func (f *fragment) setValue(columnID uint64, bitDepth uint, value uint64) (changed bool, err error) { return f.setValueBase(columnID, bitDepth, value, false) }
[ "func", "(", "f", "*", "fragment", ")", "setValue", "(", "columnID", "uint64", ",", "bitDepth", "uint", ",", "value", "uint64", ")", "(", "changed", "bool", ",", "err", "error", ")", "{", "return", "f", ".", "setValueBase", "(", "columnID", ",", "bitDe...
// setValue uses a column of bits to set a multi-bit value.
[ "setValue", "uses", "a", "column", "of", "bits", "to", "set", "a", "multi", "-", "bit", "value", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L711-L713
train
pilosa/pilosa
fragment.go
importSetValue
func (f *fragment) importSetValue(columnID uint64, bitDepth uint, value uint64, clear bool) (changed bool, err error) { // nolint: unparam for i := uint(0); i < bitDepth; i++ { if value&(1<<i) != 0 { bit, err := f.pos(uint64(i), columnID) if err != nil { return changed, errors.Wrap(err, "getting set pos") } if c, err := f.storage.Add(bit); err != nil { return changed, errors.Wrap(err, "adding") } else if c { changed = true } } else { bit, err := f.pos(uint64(i), columnID) if err != nil { return changed, errors.Wrap(err, "getting clear pos") } if c, err := f.storage.Remove(bit); err != nil { return changed, errors.Wrap(err, "removing") } else if c { changed = true } } } // Mark value as set. p, err := f.pos(uint64(bitDepth), columnID) if err != nil { return changed, errors.Wrap(err, "getting not-null pos") } if clear { if c, err := f.storage.Remove(p); err != nil { return changed, errors.Wrap(err, "removing not-null from storage") } else if c { changed = true } } else { if c, err := f.storage.Add(p); err != nil { return changed, errors.Wrap(err, "adding not-null to storage") } else if c { changed = true } } return changed, nil }
go
func (f *fragment) importSetValue(columnID uint64, bitDepth uint, value uint64, clear bool) (changed bool, err error) { // nolint: unparam for i := uint(0); i < bitDepth; i++ { if value&(1<<i) != 0 { bit, err := f.pos(uint64(i), columnID) if err != nil { return changed, errors.Wrap(err, "getting set pos") } if c, err := f.storage.Add(bit); err != nil { return changed, errors.Wrap(err, "adding") } else if c { changed = true } } else { bit, err := f.pos(uint64(i), columnID) if err != nil { return changed, errors.Wrap(err, "getting clear pos") } if c, err := f.storage.Remove(bit); err != nil { return changed, errors.Wrap(err, "removing") } else if c { changed = true } } } // Mark value as set. p, err := f.pos(uint64(bitDepth), columnID) if err != nil { return changed, errors.Wrap(err, "getting not-null pos") } if clear { if c, err := f.storage.Remove(p); err != nil { return changed, errors.Wrap(err, "removing not-null from storage") } else if c { changed = true } } else { if c, err := f.storage.Add(p); err != nil { return changed, errors.Wrap(err, "adding not-null to storage") } else if c { changed = true } } return changed, nil }
[ "func", "(", "f", "*", "fragment", ")", "importSetValue", "(", "columnID", "uint64", ",", "bitDepth", "uint", ",", "value", "uint64", ",", "clear", "bool", ")", "(", "changed", "bool", ",", "err", "error", ")", "{", "for", "i", ":=", "uint", "(", "0"...
// importSetValue is a more efficient SetValue just for imports.
[ "importSetValue", "is", "a", "more", "efficient", "SetValue", "just", "for", "imports", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L789-L834
train
pilosa/pilosa
fragment.go
sum
func (f *fragment) sum(filter *Row, bitDepth uint) (sum, count uint64, err error) { // Compute count based on the existence row. consider := f.row(uint64(bitDepth)) if filter != nil { consider = consider.Intersect(filter) } count = consider.Count() // Compute the sum based on the bit count of each row multiplied by the // place value of each row. For example, 10 bits in the 1's place plus // 4 bits in the 2's place plus 3 bits in the 4's place equals a total // sum of 30: // // 10*(2^0) + 4*(2^1) + 3*(2^2) = 30 // var cnt uint64 for i := uint(0); i < bitDepth; i++ { row := f.row(uint64(i)) cnt = row.intersectionCount(consider) sum += (1 << i) * cnt } return sum, count, nil }
go
func (f *fragment) sum(filter *Row, bitDepth uint) (sum, count uint64, err error) { // Compute count based on the existence row. consider := f.row(uint64(bitDepth)) if filter != nil { consider = consider.Intersect(filter) } count = consider.Count() // Compute the sum based on the bit count of each row multiplied by the // place value of each row. For example, 10 bits in the 1's place plus // 4 bits in the 2's place plus 3 bits in the 4's place equals a total // sum of 30: // // 10*(2^0) + 4*(2^1) + 3*(2^2) = 30 // var cnt uint64 for i := uint(0); i < bitDepth; i++ { row := f.row(uint64(i)) cnt = row.intersectionCount(consider) sum += (1 << i) * cnt } return sum, count, nil }
[ "func", "(", "f", "*", "fragment", ")", "sum", "(", "filter", "*", "Row", ",", "bitDepth", "uint", ")", "(", "sum", ",", "count", "uint64", ",", "err", "error", ")", "{", "consider", ":=", "f", ".", "row", "(", "uint64", "(", "bitDepth", ")", ")"...
// sum returns the sum of a given bsiGroup as well as the number of columns involved. // A bitmap can be passed in to optionally filter the computed columns.
[ "sum", "returns", "the", "sum", "of", "a", "given", "bsiGroup", "as", "well", "as", "the", "number", "of", "columns", "involved", ".", "A", "bitmap", "can", "be", "passed", "in", "to", "optionally", "filter", "the", "computed", "columns", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L838-L861
train
pilosa/pilosa
fragment.go
min
func (f *fragment) min(filter *Row, bitDepth uint) (min, count uint64, err error) { consider := f.row(uint64(bitDepth)) if filter != nil { consider = consider.Intersect(filter) } // If there are no columns to consider, return early. if consider.Count() == 0 { return 0, 0, nil } for i := bitDepth; i > uint(0); i-- { ii := i - 1 // allow for uint range: (bitDepth-1) to 0 row := f.row(uint64(ii)) x := consider.Difference(row) count = x.Count() if count > 0 { consider = x } else { min += (1 << ii) if ii == 0 { count = consider.Count() } } } return min, count, nil }
go
func (f *fragment) min(filter *Row, bitDepth uint) (min, count uint64, err error) { consider := f.row(uint64(bitDepth)) if filter != nil { consider = consider.Intersect(filter) } // If there are no columns to consider, return early. if consider.Count() == 0 { return 0, 0, nil } for i := bitDepth; i > uint(0); i-- { ii := i - 1 // allow for uint range: (bitDepth-1) to 0 row := f.row(uint64(ii)) x := consider.Difference(row) count = x.Count() if count > 0 { consider = x } else { min += (1 << ii) if ii == 0 { count = consider.Count() } } } return min, count, nil }
[ "func", "(", "f", "*", "fragment", ")", "min", "(", "filter", "*", "Row", ",", "bitDepth", "uint", ")", "(", "min", ",", "count", "uint64", ",", "err", "error", ")", "{", "consider", ":=", "f", ".", "row", "(", "uint64", "(", "bitDepth", ")", ")"...
// min returns the min of a given bsiGroup as well as the number of columns involved. // A bitmap can be passed in to optionally filter the computed columns.
[ "min", "returns", "the", "min", "of", "a", "given", "bsiGroup", "as", "well", "as", "the", "number", "of", "columns", "involved", ".", "A", "bitmap", "can", "be", "passed", "in", "to", "optionally", "filter", "the", "computed", "columns", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L865-L894
train
pilosa/pilosa
fragment.go
rangeOp
func (f *fragment) rangeOp(op pql.Token, bitDepth uint, predicate uint64) (*Row, error) { switch op { case pql.EQ: return f.rangeEQ(bitDepth, predicate) case pql.NEQ: return f.rangeNEQ(bitDepth, predicate) case pql.LT, pql.LTE: return f.rangeLT(bitDepth, predicate, op == pql.LTE) case pql.GT, pql.GTE: return f.rangeGT(bitDepth, predicate, op == pql.GTE) default: return nil, ErrInvalidRangeOperation } }
go
func (f *fragment) rangeOp(op pql.Token, bitDepth uint, predicate uint64) (*Row, error) { switch op { case pql.EQ: return f.rangeEQ(bitDepth, predicate) case pql.NEQ: return f.rangeNEQ(bitDepth, predicate) case pql.LT, pql.LTE: return f.rangeLT(bitDepth, predicate, op == pql.LTE) case pql.GT, pql.GTE: return f.rangeGT(bitDepth, predicate, op == pql.GTE) default: return nil, ErrInvalidRangeOperation } }
[ "func", "(", "f", "*", "fragment", ")", "rangeOp", "(", "op", "pql", ".", "Token", ",", "bitDepth", "uint", ",", "predicate", "uint64", ")", "(", "*", "Row", ",", "error", ")", "{", "switch", "op", "{", "case", "pql", ".", "EQ", ":", "return", "f...
// rangeOp returns bitmaps with a bsiGroup value encoding matching the predicate.
[ "rangeOp", "returns", "bitmaps", "with", "a", "bsiGroup", "value", "encoding", "matching", "the", "predicate", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L928-L941
train
pilosa/pilosa
fragment.go
rangeBetween
func (f *fragment) rangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Row, error) { b := f.row(uint64(bitDepth)) keep1 := NewRow() // GTE keep2 := NewRow() // LTE // Filter any bits that don't match the current bit value. for i := int(bitDepth - 1); i >= 0; i-- { row := f.row(uint64(i)) bit1 := (predicateMin >> uint(i)) & 1 bit2 := (predicateMax >> uint(i)) & 1 // GTE predicateMin // If bit is set then remove all unset columns not already kept. if bit1 == 1 { b = b.Difference(b.Difference(row).Difference(keep1)) } else { // If bit is unset then add columns with set bit to keep. // Don't bother to compute this on the final iteration. if i > 0 { keep1 = keep1.Union(b.Intersect(row)) } } // LTE predicateMin // If bit is zero then remove all set bits not in excluded bitmap. if bit2 == 0 { b = b.Difference(row.Difference(keep2)) } else { // If bit is set then add columns for set bits to exclude. // Don't bother to compute this on the final iteration. if i > 0 { keep2 = keep2.Union(b.Difference(row)) } } } return b, nil }
go
func (f *fragment) rangeBetween(bitDepth uint, predicateMin, predicateMax uint64) (*Row, error) { b := f.row(uint64(bitDepth)) keep1 := NewRow() // GTE keep2 := NewRow() // LTE // Filter any bits that don't match the current bit value. for i := int(bitDepth - 1); i >= 0; i-- { row := f.row(uint64(i)) bit1 := (predicateMin >> uint(i)) & 1 bit2 := (predicateMax >> uint(i)) & 1 // GTE predicateMin // If bit is set then remove all unset columns not already kept. if bit1 == 1 { b = b.Difference(b.Difference(row).Difference(keep1)) } else { // If bit is unset then add columns with set bit to keep. // Don't bother to compute this on the final iteration. if i > 0 { keep1 = keep1.Union(b.Intersect(row)) } } // LTE predicateMin // If bit is zero then remove all set bits not in excluded bitmap. if bit2 == 0 { b = b.Difference(row.Difference(keep2)) } else { // If bit is set then add columns for set bits to exclude. // Don't bother to compute this on the final iteration. if i > 0 { keep2 = keep2.Union(b.Difference(row)) } } } return b, nil }
[ "func", "(", "f", "*", "fragment", ")", "rangeBetween", "(", "bitDepth", "uint", ",", "predicateMin", ",", "predicateMax", "uint64", ")", "(", "*", "Row", ",", "error", ")", "{", "b", ":=", "f", ".", "row", "(", "uint64", "(", "bitDepth", ")", ")", ...
// rangeBetween returns bitmaps with a bsiGroup value encoding matching any value between predicateMin and predicateMax.
[ "rangeBetween", "returns", "bitmaps", "with", "a", "bsiGroup", "value", "encoding", "matching", "any", "value", "between", "predicateMin", "and", "predicateMax", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1067-L1104
train
pilosa/pilosa
fragment.go
pos
func (f *fragment) pos(rowID, columnID uint64) (uint64, error) { // Return an error if the column ID is out of the range of the fragment's shard. minColumnID := f.shard * ShardWidth if columnID < minColumnID || columnID >= minColumnID+ShardWidth { return 0, errors.Errorf("column:%d out of bounds", columnID) } return pos(rowID, columnID), nil }
go
func (f *fragment) pos(rowID, columnID uint64) (uint64, error) { // Return an error if the column ID is out of the range of the fragment's shard. minColumnID := f.shard * ShardWidth if columnID < minColumnID || columnID >= minColumnID+ShardWidth { return 0, errors.Errorf("column:%d out of bounds", columnID) } return pos(rowID, columnID), nil }
[ "func", "(", "f", "*", "fragment", ")", "pos", "(", "rowID", ",", "columnID", "uint64", ")", "(", "uint64", ",", "error", ")", "{", "minColumnID", ":=", "f", ".", "shard", "*", "ShardWidth", "\n", "if", "columnID", "<", "minColumnID", "||", "columnID",...
// pos translates the row ID and column ID into a position in the storage bitmap.
[ "pos", "translates", "the", "row", "ID", "and", "column", "ID", "into", "a", "position", "in", "the", "storage", "bitmap", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1107-L1114
train
pilosa/pilosa
fragment.go
forEachBit
func (f *fragment) forEachBit(fn func(rowID, columnID uint64) error) error { f.mu.Lock() defer f.mu.Unlock() var err error f.storage.ForEach(func(i uint64) { // Skip if an error has already occurred. if err != nil { return } // Invoke caller's function. err = fn(i/ShardWidth, (f.shard*ShardWidth)+(i%ShardWidth)) }) return err }
go
func (f *fragment) forEachBit(fn func(rowID, columnID uint64) error) error { f.mu.Lock() defer f.mu.Unlock() var err error f.storage.ForEach(func(i uint64) { // Skip if an error has already occurred. if err != nil { return } // Invoke caller's function. err = fn(i/ShardWidth, (f.shard*ShardWidth)+(i%ShardWidth)) }) return err }
[ "func", "(", "f", "*", "fragment", ")", "forEachBit", "(", "fn", "func", "(", "rowID", ",", "columnID", "uint64", ")", "error", ")", "error", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\...
// forEachBit executes fn for every bit set in the fragment. // Errors returned from fn are passed through.
[ "forEachBit", "executes", "fn", "for", "every", "bit", "set", "in", "the", "fragment", ".", "Errors", "returned", "from", "fn", "are", "passed", "through", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1118-L1133
train
pilosa/pilosa
fragment.go
Checksum
func (f *fragment) Checksum() []byte { h := xxhash.New() for _, block := range f.Blocks() { _, _ = h.Write(block.Checksum) } return h.Sum(nil) }
go
func (f *fragment) Checksum() []byte { h := xxhash.New() for _, block := range f.Blocks() { _, _ = h.Write(block.Checksum) } return h.Sum(nil) }
[ "func", "(", "f", "*", "fragment", ")", "Checksum", "(", ")", "[", "]", "byte", "{", "h", ":=", "xxhash", ".", "New", "(", ")", "\n", "for", "_", ",", "block", ":=", "range", "f", ".", "Blocks", "(", ")", "{", "_", ",", "_", "=", "h", ".", ...
// Checksum returns a checksum for the entire fragment. // If two fragments have the same checksum then they have the same data.
[ "Checksum", "returns", "a", "checksum", "for", "the", "entire", "fragment", ".", "If", "two", "fragments", "have", "the", "same", "checksum", "then", "they", "have", "the", "same", "data", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1330-L1336
train
pilosa/pilosa
fragment.go
InvalidateChecksums
func (f *fragment) InvalidateChecksums() { f.mu.Lock() f.checksums = make(map[int][]byte) f.mu.Unlock() }
go
func (f *fragment) InvalidateChecksums() { f.mu.Lock() f.checksums = make(map[int][]byte) f.mu.Unlock() }
[ "func", "(", "f", "*", "fragment", ")", "InvalidateChecksums", "(", ")", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "f", ".", "checksums", "=", "make", "(", "map", "[", "int", "]", "[", "]", "byte", ")", "\n", "f", ".", "mu", ".", "Unl...
// InvalidateChecksums clears all cached block checksums.
[ "InvalidateChecksums", "clears", "all", "cached", "block", "checksums", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1339-L1343
train
pilosa/pilosa
fragment.go
Blocks
func (f *fragment) Blocks() []FragmentBlock { f.mu.Lock() defer f.mu.Unlock() var a []FragmentBlock // Initialize the iterator. itr := f.storage.Iterator() itr.Seek(0) // Initialize block hasher. h := newBlockHasher() // Iterate over each value in the fragment. v, eof := itr.Next() if eof { return nil } blockID := int(v / (HashBlockSize * ShardWidth)) for { // Check for multiple block checksums in a row. if n := f.readContiguousChecksums(&a, blockID); n > 0 { itr.Seek(uint64(blockID+n) * HashBlockSize * ShardWidth) v, eof = itr.Next() if eof { break } blockID = int(v / (HashBlockSize * ShardWidth)) continue } // Reset hasher. h.blockID = blockID h.Reset() // Read all values for the block. for ; ; v, eof = itr.Next() { // Once we hit the next block, save the value for the next iteration. blockID = int(v / (HashBlockSize * ShardWidth)) if blockID != h.blockID || eof { break } h.WriteValue(v) } // Cache checksum. chksum := h.Sum() f.checksums[h.blockID] = chksum // Append block. a = append(a, FragmentBlock{ ID: h.blockID, Checksum: chksum, }) // Exit if we're at the end. if eof { break } } return a }
go
func (f *fragment) Blocks() []FragmentBlock { f.mu.Lock() defer f.mu.Unlock() var a []FragmentBlock // Initialize the iterator. itr := f.storage.Iterator() itr.Seek(0) // Initialize block hasher. h := newBlockHasher() // Iterate over each value in the fragment. v, eof := itr.Next() if eof { return nil } blockID := int(v / (HashBlockSize * ShardWidth)) for { // Check for multiple block checksums in a row. if n := f.readContiguousChecksums(&a, blockID); n > 0 { itr.Seek(uint64(blockID+n) * HashBlockSize * ShardWidth) v, eof = itr.Next() if eof { break } blockID = int(v / (HashBlockSize * ShardWidth)) continue } // Reset hasher. h.blockID = blockID h.Reset() // Read all values for the block. for ; ; v, eof = itr.Next() { // Once we hit the next block, save the value for the next iteration. blockID = int(v / (HashBlockSize * ShardWidth)) if blockID != h.blockID || eof { break } h.WriteValue(v) } // Cache checksum. chksum := h.Sum() f.checksums[h.blockID] = chksum // Append block. a = append(a, FragmentBlock{ ID: h.blockID, Checksum: chksum, }) // Exit if we're at the end. if eof { break } } return a }
[ "func", "(", "f", "*", "fragment", ")", "Blocks", "(", ")", "[", "]", "FragmentBlock", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "var", "a", "[", "]", "FragmentBlock", "\n", "itr",...
// Blocks returns info for all blocks containing data.
[ "Blocks", "returns", "info", "for", "all", "blocks", "containing", "data", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1346-L1409
train
pilosa/pilosa
fragment.go
readContiguousChecksums
func (f *fragment) readContiguousChecksums(a *[]FragmentBlock, blockID int) (n int) { for i := 0; ; i++ { chksum := f.checksums[blockID+i] if chksum == nil { return i } *a = append(*a, FragmentBlock{ ID: blockID + i, Checksum: chksum, }) } }
go
func (f *fragment) readContiguousChecksums(a *[]FragmentBlock, blockID int) (n int) { for i := 0; ; i++ { chksum := f.checksums[blockID+i] if chksum == nil { return i } *a = append(*a, FragmentBlock{ ID: blockID + i, Checksum: chksum, }) } }
[ "func", "(", "f", "*", "fragment", ")", "readContiguousChecksums", "(", "a", "*", "[", "]", "FragmentBlock", ",", "blockID", "int", ")", "(", "n", "int", ")", "{", "for", "i", ":=", "0", ";", ";", "i", "++", "{", "chksum", ":=", "f", ".", "checks...
// readContiguousChecksums appends multiple checksums in a row and returns the count added.
[ "readContiguousChecksums", "appends", "multiple", "checksums", "in", "a", "row", "and", "returns", "the", "count", "added", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1412-L1424
train
pilosa/pilosa
fragment.go
blockData
func (f *fragment) blockData(id int) (rowIDs, columnIDs []uint64) { f.mu.Lock() defer f.mu.Unlock() f.storage.ForEachRange(uint64(id)*HashBlockSize*ShardWidth, (uint64(id)+1)*HashBlockSize*ShardWidth, func(i uint64) { rowIDs = append(rowIDs, i/ShardWidth) columnIDs = append(columnIDs, i%ShardWidth) }) return rowIDs, columnIDs }
go
func (f *fragment) blockData(id int) (rowIDs, columnIDs []uint64) { f.mu.Lock() defer f.mu.Unlock() f.storage.ForEachRange(uint64(id)*HashBlockSize*ShardWidth, (uint64(id)+1)*HashBlockSize*ShardWidth, func(i uint64) { rowIDs = append(rowIDs, i/ShardWidth) columnIDs = append(columnIDs, i%ShardWidth) }) return rowIDs, columnIDs }
[ "func", "(", "f", "*", "fragment", ")", "blockData", "(", "id", "int", ")", "(", "rowIDs", ",", "columnIDs", "[", "]", "uint64", ")", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "f...
// blockData returns bits in a block as row & column ID pairs.
[ "blockData", "returns", "bits", "in", "a", "block", "as", "row", "&", "column", "ID", "pairs", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1427-L1435
train
pilosa/pilosa
fragment.go
bulkImport
func (f *fragment) bulkImport(rowIDs, columnIDs []uint64, options *ImportOptions) error { // Verify that there are an equal number of row ids and column ids. if len(rowIDs) != len(columnIDs) { return fmt.Errorf("mismatch of row/column len: %d != %d", len(rowIDs), len(columnIDs)) } if f.mutexVector != nil && !options.Clear { return f.bulkImportMutex(rowIDs, columnIDs) } return f.bulkImportStandard(rowIDs, columnIDs, options) }
go
func (f *fragment) bulkImport(rowIDs, columnIDs []uint64, options *ImportOptions) error { // Verify that there are an equal number of row ids and column ids. if len(rowIDs) != len(columnIDs) { return fmt.Errorf("mismatch of row/column len: %d != %d", len(rowIDs), len(columnIDs)) } if f.mutexVector != nil && !options.Clear { return f.bulkImportMutex(rowIDs, columnIDs) } return f.bulkImportStandard(rowIDs, columnIDs, options) }
[ "func", "(", "f", "*", "fragment", ")", "bulkImport", "(", "rowIDs", ",", "columnIDs", "[", "]", "uint64", ",", "options", "*", "ImportOptions", ")", "error", "{", "if", "len", "(", "rowIDs", ")", "!=", "len", "(", "columnIDs", ")", "{", "return", "f...
// bulkImport bulk imports a set of bits and then snapshots the storage. // The cache is updated to reflect the new data.
[ "bulkImport", "bulk", "imports", "a", "set", "of", "bits", "and", "then", "snapshots", "the", "storage", ".", "The", "cache", "is", "updated", "to", "reflect", "the", "new", "data", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1565-L1575
train
pilosa/pilosa
fragment.go
bulkImportStandard
func (f *fragment) bulkImportStandard(rowIDs, columnIDs []uint64, options *ImportOptions) (err error) { // rowSet maintains the set of rowIDs present in this import. It allows the // cache to be updated once per row, instead of once per bit. TODO: consider // sorting by rowID/columnID first and avoiding the map allocation here. (we // could reuse rowIDs to store the list of unique row IDs) rowSet := make(map[uint64]struct{}) lastRowID := uint64(1 << 63) // replace columnIDs with calculated positions to avoid allocation. for i := 0; i < len(columnIDs); i++ { rowID, columnID := rowIDs[i], columnIDs[i] pos, err := f.pos(rowID, columnID) if err != nil { return err } columnIDs[i] = pos // Add row to rowSet. if rowID != lastRowID { lastRowID = rowID rowSet[rowID] = struct{}{} } } positions := columnIDs f.mu.Lock() defer f.mu.Unlock() if options.Clear { err = f.importPositions(nil, positions, rowSet) } else { err = f.importPositions(positions, nil, rowSet) } return errors.Wrap(err, "bulkImportStandard") }
go
func (f *fragment) bulkImportStandard(rowIDs, columnIDs []uint64, options *ImportOptions) (err error) { // rowSet maintains the set of rowIDs present in this import. It allows the // cache to be updated once per row, instead of once per bit. TODO: consider // sorting by rowID/columnID first and avoiding the map allocation here. (we // could reuse rowIDs to store the list of unique row IDs) rowSet := make(map[uint64]struct{}) lastRowID := uint64(1 << 63) // replace columnIDs with calculated positions to avoid allocation. for i := 0; i < len(columnIDs); i++ { rowID, columnID := rowIDs[i], columnIDs[i] pos, err := f.pos(rowID, columnID) if err != nil { return err } columnIDs[i] = pos // Add row to rowSet. if rowID != lastRowID { lastRowID = rowID rowSet[rowID] = struct{}{} } } positions := columnIDs f.mu.Lock() defer f.mu.Unlock() if options.Clear { err = f.importPositions(nil, positions, rowSet) } else { err = f.importPositions(positions, nil, rowSet) } return errors.Wrap(err, "bulkImportStandard") }
[ "func", "(", "f", "*", "fragment", ")", "bulkImportStandard", "(", "rowIDs", ",", "columnIDs", "[", "]", "uint64", ",", "options", "*", "ImportOptions", ")", "(", "err", "error", ")", "{", "rowSet", ":=", "make", "(", "map", "[", "uint64", "]", "struct...
// bulkImportStandard performs a bulk import on a standard fragment. May mutate // its rowIDs and columnIDs arguments.
[ "bulkImportStandard", "performs", "a", "bulk", "import", "on", "a", "standard", "fragment", ".", "May", "mutate", "its", "rowIDs", "and", "columnIDs", "arguments", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1579-L1611
train
pilosa/pilosa
fragment.go
bulkImportMutex
func (f *fragment) bulkImportMutex(rowIDs, columnIDs []uint64) error { f.mu.Lock() defer f.mu.Unlock() rowSet := make(map[uint64]struct{}) // we have to maintain which columns are getting bits set as a map so that // we don't end up setting multiple bits in the same column if a column is // repeated within the import. colSet := make(map[uint64]uint64) // Since each imported bit will at most set one bit and clear one bit, we // can reuse the rowIDs and columnIDs slices as the set and clear slice // arguments to importPositions. The set positions we'll get from the // colSet, but we maintain clearIdx as we loop through row and col ids so // that we know how many bits we need to clear and how far through columnIDs // we are. clearIdx := 0 for i := range rowIDs { rowID, columnID := rowIDs[i], columnIDs[i] if existingRowID, found, err := f.mutexVector.Get(columnID); err != nil { return errors.Wrap(err, "getting mutex vector data") } else if found && existingRowID != rowID { // Determine the position of the bit in the storage. clearPos, err := f.pos(existingRowID, columnID) if err != nil { return err } columnIDs[clearIdx] = clearPos clearIdx++ rowSet[existingRowID] = struct{}{} } else if found && existingRowID == rowID { continue } pos, err := f.pos(rowID, columnID) if err != nil { return err } colSet[columnID] = pos rowSet[rowID] = struct{}{} } // re-use rowIDs by populating positions to set from colSet. i := 0 for _, pos := range colSet { rowIDs[i] = pos i++ } toSet := rowIDs[:i] toClear := columnIDs[:clearIdx] return errors.Wrap(f.importPositions(toSet, toClear, rowSet), "importing positions") }
go
func (f *fragment) bulkImportMutex(rowIDs, columnIDs []uint64) error { f.mu.Lock() defer f.mu.Unlock() rowSet := make(map[uint64]struct{}) // we have to maintain which columns are getting bits set as a map so that // we don't end up setting multiple bits in the same column if a column is // repeated within the import. colSet := make(map[uint64]uint64) // Since each imported bit will at most set one bit and clear one bit, we // can reuse the rowIDs and columnIDs slices as the set and clear slice // arguments to importPositions. The set positions we'll get from the // colSet, but we maintain clearIdx as we loop through row and col ids so // that we know how many bits we need to clear and how far through columnIDs // we are. clearIdx := 0 for i := range rowIDs { rowID, columnID := rowIDs[i], columnIDs[i] if existingRowID, found, err := f.mutexVector.Get(columnID); err != nil { return errors.Wrap(err, "getting mutex vector data") } else if found && existingRowID != rowID { // Determine the position of the bit in the storage. clearPos, err := f.pos(existingRowID, columnID) if err != nil { return err } columnIDs[clearIdx] = clearPos clearIdx++ rowSet[existingRowID] = struct{}{} } else if found && existingRowID == rowID { continue } pos, err := f.pos(rowID, columnID) if err != nil { return err } colSet[columnID] = pos rowSet[rowID] = struct{}{} } // re-use rowIDs by populating positions to set from colSet. i := 0 for _, pos := range colSet { rowIDs[i] = pos i++ } toSet := rowIDs[:i] toClear := columnIDs[:clearIdx] return errors.Wrap(f.importPositions(toSet, toClear, rowSet), "importing positions") }
[ "func", "(", "f", "*", "fragment", ")", "bulkImportMutex", "(", "rowIDs", ",", "columnIDs", "[", "]", "uint64", ")", "error", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "rowSet", ":="...
// bulkImportMutex performs a bulk import on a fragment while ensuring // mutex restrictions. Because the mutex requirements must be checked // against storage, this method must acquire a write lock on the fragment // during the entire process, and it handles every bit independently.
[ "bulkImportMutex", "performs", "a", "bulk", "import", "on", "a", "fragment", "while", "ensuring", "mutex", "restrictions", ".", "Because", "the", "mutex", "requirements", "must", "be", "checked", "against", "storage", "this", "method", "must", "acquire", "a", "w...
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1684-L1736
train
pilosa/pilosa
fragment.go
importValue
func (f *fragment) importValue(columnIDs, values []uint64, bitDepth uint, clear bool) error { f.mu.Lock() defer f.mu.Unlock() // Verify that there are an equal number of column ids and values. if len(columnIDs) != len(values) { return fmt.Errorf("mismatch of column/value len: %d != %d", len(columnIDs), len(values)) } if len(columnIDs)*int(bitDepth+1)+f.opN < f.MaxOpN { return errors.Wrap(f.importValueSmallWrite(columnIDs, values, bitDepth, clear), "import small write") } f.storage.OpWriter = nil // Process every value. // If an error occurs then reopen the storage. if err := func() (err error) { for i := range columnIDs { columnID, value := columnIDs[i], values[i] if _, err := f.importSetValue(columnID, bitDepth, value, clear); err != nil { return errors.Wrapf(err, "importSetValue") } } return nil }(); err != nil { _ = f.closeStorage() _ = f.openStorage() return err } err := f.snapshot() return errors.Wrap(err, "snapshotting") }
go
func (f *fragment) importValue(columnIDs, values []uint64, bitDepth uint, clear bool) error { f.mu.Lock() defer f.mu.Unlock() // Verify that there are an equal number of column ids and values. if len(columnIDs) != len(values) { return fmt.Errorf("mismatch of column/value len: %d != %d", len(columnIDs), len(values)) } if len(columnIDs)*int(bitDepth+1)+f.opN < f.MaxOpN { return errors.Wrap(f.importValueSmallWrite(columnIDs, values, bitDepth, clear), "import small write") } f.storage.OpWriter = nil // Process every value. // If an error occurs then reopen the storage. if err := func() (err error) { for i := range columnIDs { columnID, value := columnIDs[i], values[i] if _, err := f.importSetValue(columnID, bitDepth, value, clear); err != nil { return errors.Wrapf(err, "importSetValue") } } return nil }(); err != nil { _ = f.closeStorage() _ = f.openStorage() return err } err := f.snapshot() return errors.Wrap(err, "snapshotting") }
[ "func", "(", "f", "*", "fragment", ")", "importValue", "(", "columnIDs", ",", "values", "[", "]", "uint64", ",", "bitDepth", "uint", ",", "clear", "bool", ")", "error", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", "....
// importValue bulk imports a set of range-encoded values.
[ "importValue", "bulk", "imports", "a", "set", "of", "range", "-", "encoded", "values", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1775-L1809
train