repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
list
docstring
stringlengths
6
2.61k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
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", "{", "return", "nil", ",", "NewBadRequestError", "(", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "var", "req", "TranslateKeysRequest", "\n", "if", "err", ":=", "api", ".", "Serializer", ".", "Unmarshal", "(", "reqBytes", ",", "&", "req", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "NewBadRequestError", "(", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", ")", "\n", "}", "\n", "var", "ids", "[", "]", "uint64", "\n", "if", "req", ".", "Field", "==", "\"", "\"", "{", "ids", ",", "err", "=", "api", ".", "holder", ".", "translateFile", ".", "TranslateColumnsToUint64", "(", "req", ".", "Index", ",", "req", ".", "Keys", ")", "\n", "}", "else", "{", "ids", ",", "err", "=", "api", ".", "holder", ".", "translateFile", ".", "TranslateRowsToUint64", "(", "req", ".", "Index", ",", "req", ".", "Field", ",", "req", ".", "Keys", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "resp", ":=", "TranslateKeysResponse", "{", "IDs", ":", "ids", ",", "}", "\n", "// Encode response.", "buf", ",", "err", ":=", "api", ".", "Serializer", ".", "Marshal", "(", "&", "resp", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "return", "buf", ",", "nil", "\n", "}" ]
// 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", ".", "StartSpanOption", "\n", "if", "parent", ":=", "opentracing", ".", "SpanFromContext", "(", "ctx", ")", ";", "parent", "!=", "nil", "{", "opts", "=", "append", "(", "opts", ",", "opentracing", ".", "ChildOf", "(", "parent", ".", "Context", "(", ")", ")", ")", "\n", "}", "\n", "span", ":=", "t", ".", "tracer", ".", "StartSpan", "(", "operationName", ",", "opts", "...", ")", "\n", "return", "span", ",", "opentracing", ".", "ContextWithSpan", "(", "ctx", ",", "span", ")", "\n", "}" ]
// 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", "err", ":=", "t", ".", "tracer", ".", "Inject", "(", "span", ".", "Context", "(", ")", ",", "opentracing", ".", "HTTPHeaders", ",", "opentracing", ".", "HTTPHeadersCarrier", "(", "r", ".", "Header", ")", ",", ")", ";", "err", "!=", "nil", "{", "log", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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", ")", "{", "// Deserialize tracing context into request.", "wireContext", ",", "_", ":=", "t", ".", "tracer", ".", "Extract", "(", "opentracing", ".", "HTTPHeaders", ",", "opentracing", ".", "HTTPHeadersCarrier", "(", "r", ".", "Header", ")", ",", ")", "\n\n", "span", ":=", "t", ".", "tracer", ".", "StartSpan", "(", "\"", "\"", ",", "ext", ".", "RPCServerOption", "(", "wireContext", ")", ")", "\n", "ctx", ":=", "opentracing", ".", "ContextWithSpan", "(", "r", ".", "Context", "(", ")", ",", "span", ")", "\n", "return", "span", ",", "ctx", "\n", "}" ]
// 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", "...", ")", ")", "\n", "}" ]
// 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", "...", ")", ")", "\n", "}" ]
// 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", ",", "name", ":", "name", ",", "fieldType", ":", "fieldOptions", ".", "Type", ",", "cacheType", ":", "fieldOptions", ".", "CacheType", ",", "cacheSize", ":", "fieldOptions", ".", "CacheSize", ",", "fragments", ":", "make", "(", "map", "[", "uint64", "]", "*", "fragment", ")", ",", "broadcaster", ":", "NopBroadcaster", ",", "stats", ":", "stats", ".", "NopStatsClient", ",", "logger", ":", "logger", ".", "NopLogger", ",", "}", "\n", "}" ]
// 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", "{", "// Never keep a cache for field views.", "if", "strings", ".", "HasPrefix", "(", "v", ".", "name", ",", "viewBSIGroupPrefix", ")", "{", "v", ".", "cacheType", "=", "CacheTypeNone", "\n", "}", "\n\n", "if", "err", ":=", "func", "(", ")", "error", "{", "// Ensure the view's path exists.", "v", ".", "logger", ".", "Debugf", "(", "\"", "\"", ",", "v", ".", "path", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "v", ".", "path", ",", "0777", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "if", "err", ":=", "os", ".", "MkdirAll", "(", "filepath", ".", "Join", "(", "v", ".", "path", ",", "\"", "\"", ")", ",", "0777", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "v", ".", "logger", ".", "Debugf", "(", "\"", "\"", ",", "v", ".", "index", ",", "v", ".", "field", ",", "v", ".", "name", ")", "\n", "if", "err", ":=", "v", ".", "openFragments", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}", "(", ")", ";", "err", "!=", "nil", "{", "v", ".", "close", "(", ")", "\n", "return", "err", "\n", "}", "\n\n", "v", ".", "logger", ".", "Debugf", "(", "\"", "\"", ",", "v", ".", "index", ",", "v", ".", "field", ",", "v", ".", "name", ")", "\n", "return", "nil", "\n", "}" ]
// 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", ",", "\"", "\"", ")", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "defer", "file", ".", "Close", "(", ")", "\n\n", "fis", ",", "err", ":=", "file", ".", "Readdir", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "for", "_", ",", "fi", ":=", "range", "fis", "{", "if", "fi", ".", "IsDir", "(", ")", "{", "continue", "\n", "}", "\n\n", "// Parse filename into integer.", "shard", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "filepath", ".", "Base", "(", "fi", ".", "Name", "(", ")", ")", ",", "10", ",", "64", ")", "\n", "if", "err", "!=", "nil", "{", "v", ".", "logger", ".", "Debugf", "(", "\"", "\"", ",", "v", ".", "index", ",", "v", ".", "field", ",", "v", ".", "name", ",", "fi", ".", "Name", "(", ")", ")", "\n", "continue", "\n", "}", "\n\n", "v", ".", "logger", ".", "Debugf", "(", "\"", "\"", ",", "v", ".", "index", ",", "v", ".", "field", ",", "v", ".", "name", ",", "shard", ")", "\n", "frag", ":=", "v", ".", "newFragment", "(", "v", ".", "fragmentPath", "(", "shard", ")", ",", "shard", ")", "\n", "if", "err", ":=", "frag", ".", "Open", "(", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "frag", ".", "shard", ",", "err", ")", "\n", "}", "\n", "frag", ".", "RowAttrStore", "=", "v", ".", "rowAttrStore", "\n", "v", ".", "logger", ".", "Debugf", "(", "\"", "\"", ",", "v", ".", "index", ",", "v", ".", "field", ",", "v", ".", "name", ",", "shard", ")", "\n", "v", ".", "fragments", "[", "frag", ".", "shard", "]", "=", "frag", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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\n", "// Close all fragments.", "for", "_", ",", "frag", ":=", "range", "v", ".", "fragments", "{", "if", "err", ":=", "frag", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "v", ".", "fragments", "=", "make", "(", "map", "[", "uint64", "]", "*", "fragment", ")", "\n\n", "return", "nil", "\n", "}" ]
// 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\n", "b", ":=", "roaring", ".", "NewBitmap", "(", ")", "\n", "for", "shard", ":=", "range", "v", ".", "fragments", "{", "_", ",", "_", "=", "b", ".", "Add", "(", "shard", ")", "// ignore error, no writer attached", "\n", "}", "\n", "return", "b", "\n", "}" ]
// 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", ",", "\"", "\"", ",", "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", "[", "shard", "]", "\n", "}" ]
// 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\n", "other", ":=", "make", "(", "[", "]", "*", "fragment", ",", "0", ",", "len", "(", "v", ".", "fragments", ")", ")", "\n", "for", "_", ",", "fragment", ":=", "range", "v", ".", "fragments", "{", "other", "=", "append", "(", "other", ",", "fragment", ")", "\n", "}", "\n", "return", "other", "\n", "}" ]
// 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", "// Find fragment in cache first.", "if", "frag", ":=", "v", ".", "fragments", "[", "shard", "]", ";", "frag", "!=", "nil", "{", "return", "frag", ",", "nil", "\n", "}", "\n\n", "// Initialize and open fragment.", "frag", ":=", "v", ".", "newFragment", "(", "v", ".", "fragmentPath", "(", "shard", ")", ",", "shard", ")", "\n", "if", "err", ":=", "frag", ".", "Open", "(", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "frag", ".", "RowAttrStore", "=", "v", ".", "rowAttrStore", "\n\n", "v", ".", "fragments", "[", "shard", "]", "=", "frag", "\n", "broadcastChan", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n\n", "go", "func", "(", ")", "{", "msg", ":=", "&", "CreateShardMessage", "{", "Index", ":", "v", ".", "index", ",", "Field", ":", "v", ".", "field", ",", "Shard", ":", "shard", ",", "}", "\n", "// Broadcast a message that a new max shard was just created.", "err", ":=", "v", ".", "broadcaster", ".", "SendSync", "(", "msg", ")", "\n", "if", "err", "!=", "nil", "{", "v", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "close", "(", "broadcastChan", ")", "\n", "}", "(", ")", "\n\n", "// 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", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "frag", ",", "nil", "\n", "}" ]
// 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\n", "v", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "v", ".", "index", ",", "v", ".", "field", ",", "v", ".", "name", ",", "shard", ")", "\n\n", "// Close data files before deletion.", "if", "err", ":=", "fragment", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Delete fragment file.", "if", "err", ":=", "os", ".", "Remove", "(", "fragment", ".", "path", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Delete fragment cache file.", "if", "err", ":=", "os", ".", "Remove", "(", "fragment", ".", "cachePath", "(", ")", ")", ";", "err", "!=", "nil", "{", "v", ".", "logger", ".", "Printf", "(", "\"", "\"", ",", "shard", ")", "\n", "}", "\n\n", "delete", "(", "v", ".", "fragments", ",", "shard", ")", "\n\n", "return", "nil", "\n", "}" ]
// 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", "(", "rowID", ")", "\n", "if", "fr", "==", "nil", "{", "continue", "\n", "}", "\n", "row", ".", "Merge", "(", "fr", ")", "\n", "}", "\n", "return", "row", "\n\n", "}" ]
// 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", ".", "CreateFragmentIfNotExists", "(", "shard", ")", "\n", "if", "err", "!=", "nil", "{", "return", "changed", ",", "err", "\n", "}", "\n", "return", "frag", ".", "setBit", "(", "rowID", ",", "columnID", ")", "\n", "}" ]
// 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", ")", "\n", "if", "frag", "==", "nil", "{", "return", "false", ",", "nil", "\n", "}", "\n", "return", "frag", ".", "clearBit", "(", "rowID", ",", "columnID", ")", "\n", "}" ]
// 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", "(", ")", "{", "fsum", ",", "fcount", ",", "err", ":=", "f", ".", "sum", "(", "filter", ",", "bitDepth", ")", "\n", "if", "err", "!=", "nil", "{", "return", "sum", ",", "count", ",", "err", "\n", "}", "\n", "sum", "+=", "fsum", "\n", "count", "+=", "fcount", "\n", "}", "\n", "return", "sum", ",", "count", ",", "nil", "\n", "}" ]
// 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", ".", "allFragments", "(", ")", "{", "fmin", ",", "fcount", ",", "err", ":=", "f", ".", "min", "(", "filter", ",", "bitDepth", ")", "\n", "if", "err", "!=", "nil", "{", "return", "min", ",", "count", ",", "err", "\n", "}", "\n", "// Don't consider a min based on zero columns.", "if", "fcount", "==", "0", "{", "continue", "\n", "}", "\n\n", "if", "!", "minHasValue", "{", "min", "=", "fmin", "\n", "minHasValue", "=", "true", "\n", "count", "+=", "fcount", "\n", "continue", "\n", "}", "\n\n", "if", "fmin", "<", "min", "{", "min", "=", "fmin", "\n", "count", "+=", "fcount", "\n", "}", "\n", "}", "\n", "return", "min", ",", "count", ",", "nil", "\n", "}" ]
// 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", "(", ")", "{", "fmax", ",", "fcount", ",", "err", ":=", "f", ".", "max", "(", "filter", ",", "bitDepth", ")", "\n", "if", "err", "!=", "nil", "{", "return", "max", ",", "count", ",", "err", "\n", "}", "\n", "if", "fcount", ">", "0", "&&", "fmax", ">", "max", "{", "max", "=", "fmax", "\n", "count", "+=", "fcount", "\n", "}", "\n", "}", "\n", "return", "max", ",", "count", ",", "nil", "\n", "}" ]
// 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", ":=", "range", "v", ".", "allFragments", "(", ")", "{", "other", ",", "err", ":=", "frag", ".", "rangeOp", "(", "op", ",", "bitDepth", ",", "predicate", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "r", "=", "r", ".", "Union", "(", "other", ")", "\n", "}", "\n", "return", "r", ",", "nil", "\n", "}" ]
// 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", ",", "stderr", ")", ",", "}", "\n", "}" ]
// 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", ":", "lockedChan", "{", "ch", ":", "make", "(", "chan", "struct", "{", "}", ")", "}", ",", "translateFile", ":", "NewTranslateFile", "(", ")", ",", "NewPrimaryTranslateStore", ":", "newNopTranslateStore", ",", "broadcaster", ":", "NopBroadcaster", ",", "Stats", ":", "stats", ".", "NopStatsClient", ",", "NewAttrStore", ":", "newNopAttrStore", ",", "cacheFlushInterval", ":", "defaultCacheFlushInterval", ",", "Logger", ":", "logger", ".", "NopLogger", ",", "}", "\n", "}" ]
// 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", "{", "// Reset closing in case Holder is being reopened.", "h", ".", "closing", "=", "make", "(", "chan", "struct", "{", "}", ")", "\n\n", "h", ".", "setFileLimit", "(", ")", "\n\n", "h", ".", "Logger", ".", "Printf", "(", "\"", "\"", ",", "h", ".", "Path", ")", "\n", "if", "err", ":=", "os", ".", "MkdirAll", "(", "h", ".", "Path", ",", "0777", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Open path to read all index directories.", "f", ",", "err", ":=", "os", ".", "Open", "(", "h", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "fis", ",", "err", ":=", "f", ".", "Readdir", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "for", "_", ",", "fi", ":=", "range", "fis", "{", "// Skip files or hidden directories.", "if", "!", "fi", ".", "IsDir", "(", ")", "||", "strings", ".", "HasPrefix", "(", "fi", ".", "Name", "(", ")", ",", "\"", "\"", ")", "{", "continue", "\n", "}", "\n\n", "h", ".", "Logger", ".", "Printf", "(", "\"", "\"", ",", "filepath", ".", "Base", "(", "fi", ".", "Name", "(", ")", ")", ")", "\n\n", "index", ",", "err", ":=", "h", ".", "newIndex", "(", "h", ".", "IndexPath", "(", "filepath", ".", "Base", "(", "fi", ".", "Name", "(", ")", ")", ")", ",", "filepath", ".", "Base", "(", "fi", ".", "Name", "(", ")", ")", ")", "\n", "if", "errors", ".", "Cause", "(", "err", ")", "==", "ErrName", "{", "h", ".", "Logger", ".", "Printf", "(", "\"", "\"", ",", "fi", ".", "Name", "(", ")", ",", "err", ")", "\n", "continue", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "err", ":=", "index", ".", "Open", "(", ")", ";", "err", "!=", "nil", "{", "if", "err", "==", "ErrName", "{", "h", ".", "Logger", ".", "Printf", "(", "\"", "\"", ",", "index", ".", "Name", "(", ")", ",", "err", ")", "\n", "continue", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "index", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n", "h", ".", "mu", ".", "Lock", "(", ")", "\n", "h", ".", "indexes", "[", "index", ".", "Name", "(", ")", "]", "=", "index", "\n", "h", ".", "mu", ".", "Unlock", "(", ")", "\n", "}", "\n", "h", ".", "Logger", ".", "Printf", "(", "\"", "\"", ")", "\n\n", "// Periodically flush cache.", "h", ".", "wg", ".", "Add", "(", "1", ")", "\n", "go", "func", "(", ")", "{", "defer", "h", ".", "wg", ".", "Done", "(", ")", ";", "h", ".", "monitorCacheFlush", "(", ")", "}", "(", ")", "\n\n", "h", ".", "Stats", ".", "Open", "(", ")", "\n\n", "h", ".", "opened", ".", "Close", "(", ")", "\n", "return", "nil", "\n", "}" ]
// 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\n", "// Notify goroutines of closing and wait for completion.", "close", "(", "h", ".", "closing", ")", "\n", "h", ".", "wg", ".", "Wait", "(", ")", "\n\n", "for", "_", ",", "index", ":=", "range", "h", ".", "indexes", "{", "if", "err", ":=", "index", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "if", "h", ".", "translateFile", "!=", "nil", "{", "if", "err", ":=", "h", ".", "translateFile", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "// Reset opened in case Holder needs to be reopened.", "h", ".", "opened", ".", "mu", ".", "Lock", "(", ")", "\n", "h", ".", "opened", ".", "ch", "=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "h", ".", "opened", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// 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", ")", ">", "0", "{", "return", "true", ",", "nil", "\n", "}", "\n", "// Open path to read all index directories.", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "h", ".", "Path", ")", ";", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "false", ",", "nil", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "f", ",", "err", ":=", "os", ".", "Open", "(", "h", ".", "Path", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "fis", ",", "err", ":=", "f", ".", "Readdir", "(", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "for", "_", ",", "fi", ":=", "range", "fis", "{", "if", "!", "fi", ".", "IsDir", "(", ")", "{", "continue", "\n", "}", "\n", "return", "true", ",", "nil", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
// 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", "_", ",", "index", ":=", "range", "h", ".", "Indexes", "(", ")", "{", "m", "[", "index", ".", "Name", "(", ")", "]", "=", "index", ".", "AvailableShards", "(", ")", "\n", "}", "\n", "return", "m", "\n", "}" ]
// 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", "{", "Name", ":", "index", ".", "Name", "(", ")", "}", "\n", "for", "_", ",", "field", ":=", "range", "index", ".", "Fields", "(", ")", "{", "fi", ":=", "&", "FieldInfo", "{", "Name", ":", "field", ".", "Name", "(", ")", ",", "Options", ":", "field", ".", "Options", "(", ")", "}", "\n", "for", "_", ",", "view", ":=", "range", "field", ".", "views", "(", ")", "{", "fi", ".", "Views", "=", "append", "(", "fi", ".", "Views", ",", "&", "ViewInfo", "{", "Name", ":", "view", ".", "name", "}", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "viewInfoSlice", "(", "fi", ".", "Views", ")", ")", "\n", "di", ".", "Fields", "=", "append", "(", "di", ".", "Fields", ",", "fi", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "fieldInfoSlice", "(", "di", ".", "Fields", ")", ")", "\n", "a", "=", "append", "(", "a", ",", "di", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "indexInfoSlice", "(", "a", ")", ")", "\n", "return", "a", "\n", "}" ]
// 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", ":=", "&", "IndexInfo", "{", "Name", ":", "index", ".", "Name", "(", ")", ",", "Options", ":", "index", ".", "Options", "(", ")", ",", "ShardWidth", ":", "ShardWidth", ",", "}", "\n", "for", "_", ",", "field", ":=", "range", "index", ".", "Fields", "(", ")", "{", "if", "strings", ".", "HasPrefix", "(", "field", ".", "name", ",", "\"", "\"", ")", "{", "continue", "\n", "}", "\n", "fi", ":=", "&", "FieldInfo", "{", "Name", ":", "field", ".", "Name", "(", ")", ",", "Options", ":", "field", ".", "Options", "(", ")", "}", "\n", "di", ".", "Fields", "=", "append", "(", "di", ".", "Fields", ",", "fi", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "fieldInfoSlice", "(", "di", ".", "Fields", ")", ")", "\n", "a", "=", "append", "(", "a", ",", "di", ")", "\n", "}", "\n", "sort", ".", "Sort", "(", "indexInfoSlice", "(", "a", ")", ")", "\n", "return", "a", "\n", "}" ]
// 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", "{", "// Create indexes that don't exist.", "for", "_", ",", "index", ":=", "range", "schema", ".", "Indexes", "{", "idx", ",", "err", ":=", "h", ".", "CreateIndexIfNotExists", "(", "index", ".", "Name", ",", "index", ".", "Options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "// Create fields that don't exist.", "for", "_", ",", "f", ":=", "range", "index", ".", "Fields", "{", "field", ",", "err", ":=", "idx", ".", "createFieldIfNotExists", "(", "f", ".", "Name", ",", "f", ".", "Options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "// Create views that don't exist.", "for", "_", ",", "v", ":=", "range", "f", ".", "Views", "{", "_", ",", "err", ":=", "field", ".", "createViewIfNotExists", "(", "v", ".", "Name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", ")", "\n", "}" ]
// 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", ")", ")", "\n", "for", "_", ",", "index", ":=", "range", "h", ".", "indexes", "{", "a", "=", "append", "(", "a", ",", "index", ")", "\n", "}", "\n", "h", ".", "mu", ".", "RUnlock", "(", ")", "\n\n", "sort", ".", "Sort", "(", "indexSlice", "(", "a", ")", ")", "\n", "return", "a", "\n", "}" ]
// 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", "(", ")", "\n\n", "// Ensure index doesn't already exist.", "if", "h", ".", "indexes", "[", "name", "]", "!=", "nil", "{", "return", "nil", ",", "newConflictError", "(", "ErrIndexExists", ")", "\n", "}", "\n", "return", "h", ".", "createIndex", "(", "name", ",", "opt", ")", "\n", "}" ]
// 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", "(", ")", "\n\n", "// Find index in cache first.", "if", "index", ":=", "h", ".", "indexes", "[", "name", "]", ";", "index", "!=", "nil", "{", "return", "index", ",", "nil", "\n", "}", "\n\n", "return", "h", ".", "createIndex", "(", "name", ",", "opt", ")", "\n", "}" ]
// 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\n", "// Confirm index exists.", "index", ":=", "h", ".", "index", "(", "name", ")", "\n", "if", "index", "==", "nil", "{", "return", "newNotFoundError", "(", "ErrIndexNotFound", ")", "\n", "}", "\n\n", "// Close index.", "if", "err", ":=", "index", ".", "Close", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Delete index directory.", "if", "err", ":=", "os", ".", "RemoveAll", "(", "h", ".", "IndexPath", "(", "name", ")", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Remove reference.", "delete", "(", "h", ".", "indexes", ",", "name", ")", "\n\n", "return", "nil", "\n", "}" ]
// 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", "(", "name", ")", "\n", "}" ]
// 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", "}", "\n", "return", "f", ".", "view", "(", "name", ")", "\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", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "return", "v", ".", "Fragment", "(", "shard", ")", "\n", "}" ]
// 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\n", "for", "{", "select", "{", "case", "<-", "h", ".", "closing", ":", "return", "\n", "case", "<-", "ticker", ".", "C", ":", "h", ".", "flushCaches", "(", ")", "\n", "}", "\n", "}", "\n", "}" ]
// 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\n", "if", "err", ":=", "syscall", ".", "Getrlimit", "(", "syscall", ".", "RLIMIT_NOFILE", ",", "oldLimit", ")", ";", "err", "!=", "nil", "{", "h", ".", "Logger", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "// If the soft limit is lower than the FileLimit constant, we will try to change it.", "if", "oldLimit", ".", "Cur", "<", "fileLimit", "{", "newLimit", ".", "Cur", "=", "fileLimit", "\n", "// If the hard limit is not high enough, we will try to change it too.", "if", "oldLimit", ".", "Max", "<", "fileLimit", "{", "newLimit", ".", "Max", "=", "fileLimit", "\n", "}", "else", "{", "newLimit", ".", "Max", "=", "oldLimit", ".", "Max", "\n", "}", "\n\n", "// 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", "\n", "// Obviously the hard limit cannot be higher than the soft limit.", "if", "newLimit", ".", "Cur", ">=", "newLimit", ".", "Max", "{", "newLimit", ".", "Cur", "=", "newLimit", ".", "Max", "\n", "}", "\n", "// Try setting again with lowered Max (hard limit)", "if", "err", ":=", "syscall", ".", "Setrlimit", "(", "syscall", ".", "RLIMIT_NOFILE", ",", "newLimit", ")", ";", "err", "!=", "nil", "{", "h", ".", "Logger", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "// If we weren't trying to change the hard limit, let the user know something is wrong.", "}", "else", "{", "h", ".", "Logger", ".", "Printf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "// 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", "(", "\"", "\"", ",", "err", ")", "\n", "}", "else", "{", "if", "oldLimit", ".", "Cur", "<", "fileLimit", "{", "h", ".", "Logger", ".", "Printf", "(", "\"", "\\\"", "\\\"", "\\\"", "\\\"", "\"", ",", "fileLimit", ",", "oldLimit", ".", "Cur", ",", "fileLimit", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// 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", "true", "\n", "default", ":", "return", "false", "\n", "}", "\n", "}" ]
// 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", "(", ")", "// only allow one instance of SyncHolder to be running at a time", "\n", "defer", "s", ".", "mu", ".", "Unlock", "(", ")", "\n", "ti", ":=", "time", ".", "Now", "(", ")", "\n", "// Iterate over schema in sorted order.", "for", "_", ",", "di", ":=", "range", "s", ".", "Holder", ".", "Schema", "(", ")", "{", "// Verify syncer has not closed.", "if", "s", ".", "IsClosing", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "// Sync index column attributes.", "if", "err", ":=", "s", ".", "syncIndex", "(", "di", ".", "Name", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "di", ".", "Name", ",", "err", ")", "\n", "}", "\n\n", "tf", ":=", "time", ".", "Now", "(", ")", "\n", "for", "_", ",", "fi", ":=", "range", "di", ".", "Fields", "{", "// Verify syncer has not closed.", "if", "s", ".", "IsClosing", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "// Sync field row attributes.", "if", "err", ":=", "s", ".", "syncField", "(", "di", ".", "Name", ",", "fi", ".", "Name", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "di", ".", "Name", ",", "fi", ".", "Name", ",", "err", ")", "\n", "}", "\n\n", "for", "_", ",", "vi", ":=", "range", "fi", ".", "Views", "{", "// Verify syncer has not closed.", "if", "s", ".", "IsClosing", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "itr", ":=", "s", ".", "Holder", ".", "Index", "(", "di", ".", "Name", ")", ".", "AvailableShards", "(", ")", ".", "Iterator", "(", ")", "\n", "itr", ".", "Seek", "(", "0", ")", "\n", "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", "\n", "}", "\n\n", "// Verify syncer has not closed.", "if", "s", ".", "IsClosing", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "// Sync fragment if own it.", "if", "err", ":=", "s", ".", "syncFragment", "(", "di", ".", "Name", ",", "fi", ".", "Name", ",", "vi", ".", "Name", ",", "shard", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "di", ".", "Name", ",", "fi", ".", "Name", ",", "vi", ".", "Name", ",", "shard", ",", "err", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "s", ".", "Stats", ".", "Histogram", "(", "\"", "\"", ",", "float64", "(", "time", ".", "Since", "(", "tf", ")", ")", ",", "1.0", ")", "\n", "tf", "=", "time", ".", "Now", "(", ")", "// reset tf", "\n", "}", "\n", "s", ".", "Stats", ".", "Histogram", "(", "\"", "\"", ",", "float64", "(", "time", ".", "Since", "(", "ti", ")", ")", ",", "1.0", ")", "\n", "ti", "=", "time", ".", "Now", "(", ")", "// reset ti", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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", "(", ")", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "// Retrieve index reference.", "idx", ":=", "s", ".", "Holder", ".", "Index", "(", "index", ")", "\n", "if", "idx", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "indexTag", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "index", ")", "\n\n", "// Read block checksums.", "blks", ",", "err", ":=", "idx", ".", "ColumnAttrStore", "(", ")", ".", "Blocks", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "s", ".", "Stats", ".", "CountWithCustomTags", "(", "\"", "\"", ",", "int64", "(", "len", "(", "blks", ")", ")", ",", "1.0", ",", "[", "]", "string", "{", "indexTag", "}", ")", "\n\n", "// 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", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "if", "len", "(", "m", ")", "==", "0", "{", "continue", "\n", "}", "\n", "s", ".", "Stats", ".", "CountWithCustomTags", "(", "\"", "\"", ",", "int64", "(", "len", "(", "m", ")", ")", ",", "1.0", ",", "[", "]", "string", "{", "indexTag", ",", "node", ".", "ID", "}", ")", "\n\n", "// Update local copy.", "if", "err", ":=", "idx", ".", "ColumnAttrStore", "(", ")", ".", "SetBulkAttrs", "(", "m", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Recompute blocks.", "blks", ",", "err", "=", "idx", ".", "ColumnAttrStore", "(", ")", ".", "Blocks", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\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", "(", ")", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "// Retrieve field reference.", "f", ":=", "s", ".", "Holder", ".", "Field", "(", "index", ",", "name", ")", "\n", "if", "f", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "indexTag", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "index", ")", "\n", "fieldTag", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ")", "\n\n", "// Read block checksums.", "blks", ",", "err", ":=", "f", ".", "RowAttrStore", "(", ")", ".", "Blocks", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "s", ".", "Stats", ".", "CountWithCustomTags", "(", "\"", "\"", ",", "int64", "(", "len", "(", "blks", ")", ")", ",", "1.0", ",", "[", "]", "string", "{", "indexTag", ",", "fieldTag", "}", ")", "\n\n", "// 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", ")", "\n", "if", "err", "==", "ErrFieldNotFound", "{", "continue", "// field not created remotely yet, skip", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "if", "len", "(", "m", ")", "==", "0", "{", "continue", "\n", "}", "\n", "s", ".", "Stats", ".", "CountWithCustomTags", "(", "\"", "\"", ",", "int64", "(", "len", "(", "m", ")", ")", ",", "1.0", ",", "[", "]", "string", "{", "indexTag", ",", "fieldTag", ",", "node", ".", "ID", "}", ")", "\n\n", "// Update local copy.", "if", "err", ":=", "f", ".", "RowAttrStore", "(", ")", ".", "SetBulkAttrs", "(", "m", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Recompute blocks.", "blks", ",", "err", "=", "f", ".", "RowAttrStore", "(", ")", ".", "Blocks", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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", "{", "// Retrieve local field.", "f", ":=", "s", ".", "Holder", ".", "Field", "(", "index", ",", "field", ")", "\n", "if", "f", "==", "nil", "{", "return", "ErrFieldNotFound", "\n", "}", "\n\n", "// Ensure view exists locally.", "v", ",", "err", ":=", "f", ".", "createViewIfNotExists", "(", "view", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Ensure fragment exists locally.", "frag", ",", "err", ":=", "v", ".", "CreateFragmentIfNotExists", "(", "shard", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Sync fragments together.", "fs", ":=", "fragmentSyncer", "{", "Fragment", ":", "frag", ",", "Node", ":", "s", ".", "Node", ",", "Cluster", ":", "s", ".", "Cluster", ",", "Closing", ":", "s", ".", "Closing", ",", "}", "\n", "if", "err", ":=", "fs", ".", "syncFragment", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// 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", "(", ")", "{", "// Verify cleaner has not closed.", "if", "c", ".", "IsClosing", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "// Get the fragments that node is responsible for (based on hash(index, node)).", "containedShards", ":=", "c", ".", "Cluster", ".", "containsShards", "(", "index", ".", "Name", "(", ")", ",", "index", ".", "AvailableShards", "(", ")", ",", "c", ".", "Node", ")", "\n\n", "// Get the fragments registered in memory.", "for", "_", ",", "field", ":=", "range", "index", ".", "Fields", "(", ")", "{", "for", "_", ",", "view", ":=", "range", "field", ".", "views", "(", ")", "{", "for", "_", ",", "fragment", ":=", "range", "view", ".", "allFragments", "(", ")", "{", "fragShard", ":=", "fragment", ".", "shard", "\n", "// Ignore fragments that should be present.", "if", "uint64InSlice", "(", "fragShard", ",", "containedShards", ")", "{", "continue", "\n", "}", "\n", "// Delete fragment.", "if", "err", ":=", "view", ".", "deleteFragment", "(", "fragShard", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n", "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", ",", "view", ":", "view", ",", "shard", ":", "shard", ",", "CacheType", ":", "DefaultCacheType", ",", "CacheSize", ":", "DefaultCacheSize", ",", "Logger", ":", "logger", ".", "NopLogger", ",", "MaxOpN", ":", "defaultFragmentMaxOpN", ",", "stats", ":", "stats", ".", "NopStatsClient", ",", "}", "\n", "}" ]
// 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\n", "if", "err", ":=", "func", "(", ")", "error", "{", "// Initialize storage in a function so we can close if anything goes wrong.", "f", ".", "Logger", ".", "Debugf", "(", "\"", "\"", ",", "f", ".", "index", ",", "f", ".", "field", ",", "f", ".", "view", ",", "f", ".", "shard", ")", "\n", "if", "err", ":=", "f", ".", "openStorage", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Fill cache with rows persisted to disk.", "f", ".", "Logger", ".", "Debugf", "(", "\"", "\"", ",", "f", ".", "index", ",", "f", ".", "field", ",", "f", ".", "view", ",", "f", ".", "shard", ")", "\n", "if", "err", ":=", "f", ".", "openCache", "(", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Clear checksums.", "f", ".", "checksums", "=", "make", "(", "map", "[", "int", "]", "[", "]", "byte", ")", "\n\n", "// Read last bit to determine max row.", "pos", ":=", "f", ".", "storage", ".", "Max", "(", ")", "\n", "f", ".", "maxRowID", "=", "pos", "/", "ShardWidth", "\n", "f", ".", "stats", ".", "Gauge", "(", "\"", "\"", ",", "float64", "(", "f", ".", "maxRowID", ")", ",", "1.0", ")", "\n", "return", "nil", "\n", "}", "(", ")", ";", "err", "!=", "nil", "{", "f", ".", "close", "(", ")", "\n", "return", "err", "\n", "}", "\n\n", "f", ".", "Logger", ".", "Debugf", "(", "\"", "\"", ",", "f", ".", "index", ",", "f", ".", "field", ",", "f", ".", "view", ",", "f", ".", "shard", ")", "\n", "return", "nil", "\n", "}" ]
// 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", "{", "// Create a roaring bitmap to serve as storage for the shard.", "if", "f", ".", "storage", "==", "nil", "{", "f", ".", "storage", "=", "roaring", ".", "NewFileBitmap", "(", ")", "\n", "}", "\n", "// 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", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "f", ".", "file", "=", "file", "\n", "if", "mustClose", "{", "defer", "f", ".", "safeClose", "(", ")", "\n", "}", "\n\n", "// Lock the underlying file.", "if", "err", ":=", "syscall", ".", "Flock", "(", "int", "(", "f", ".", "file", ".", "Fd", "(", ")", ")", ",", "syscall", ".", "LOCK_EX", "|", "syscall", ".", "LOCK_NB", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// If the file is empty then initialize it with an empty bitmap.", "fi", ",", "err", ":=", "f", ".", "file", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "if", "fi", ".", "Size", "(", ")", "==", "0", "{", "bi", ":=", "bufio", ".", "NewWriter", "(", "f", ".", "file", ")", "\n", "if", "_", ",", "err", ":=", "f", ".", "storage", ".", "WriteTo", "(", "bi", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "bi", ".", "Flush", "(", ")", "\n", "_", ",", "err", "=", "f", ".", "file", ".", "Stat", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "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", ")", "\n", "if", "err", "==", "syswrap", ".", "ErrMaxMapCountReached", "{", "f", ".", "Logger", ".", "Debugf", "(", "\"", "\"", ")", "\n", "data", ",", "err", "=", "ioutil", ".", "ReadAll", "(", "file", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "{", "f", ".", "storageData", "=", "data", "\n", "// Advise the kernel that the mmap is accessed randomly.", "if", "err", ":=", "madvise", "(", "f", ".", "storageData", ",", "syscall", ".", "MADV_RANDOM", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "if", "err", ":=", "f", ".", "storage", ".", "UnmarshalBinary", "(", "data", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "f", ".", "file", ".", "Name", "(", ")", ",", "err", ")", "\n", "}", "\n\n", "}", "\n\n", "f", ".", "opN", "=", "f", ".", "storage", ".", "Info", "(", ")", ".", "OpN", "\n\n", "// Attach the file to the bitmap to act as a write-ahead log.", "f", ".", "storage", ".", "OpWriter", "=", "f", ".", "file", "\n", "f", ".", "rowCache", "=", "&", "simpleCache", "{", "make", "(", "map", "[", "uint64", "]", "*", "Row", ")", "}", "\n\n", "return", "nil", "\n\n", "}" ]
// 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", "{", "// Determine cache type from field name.", "switch", "f", ".", "CacheType", "{", "case", "CacheTypeRanked", ":", "f", ".", "cache", "=", "NewRankCache", "(", "f", ".", "CacheSize", ")", "\n", "case", "CacheTypeLRU", ":", "f", ".", "cache", "=", "newLRUCache", "(", "f", ".", "CacheSize", ")", "\n", "case", "CacheTypeNone", ":", "f", ".", "cache", "=", "globalNopCache", "\n", "return", "nil", "\n", "default", ":", "return", "ErrInvalidCacheType", "\n", "}", "\n\n", "// Read cache data from disk.", "path", ":=", "f", ".", "cachePath", "(", ")", "\n", "buf", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "path", ")", "\n", "if", "os", ".", "IsNotExist", "(", "err", ")", "{", "return", "nil", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Unmarshal cache data.", "var", "pb", "internal", ".", "Cache", "\n", "if", "err", ":=", "proto", ".", "Unmarshal", "(", "buf", ",", "&", "pb", ")", ";", "err", "!=", "nil", "{", "f", ".", "Logger", ".", "Printf", "(", "\"", "\"", ",", "path", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n\n", "// 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", ")", "\n", "f", ".", "cache", ".", "BulkAdd", "(", "id", ",", "n", ")", "\n", "}", "\n", "f", ".", "cache", ".", "Invalidate", "(", ")", "\n\n", "return", "nil", "\n", "}" ]
// 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", "{", "// Flush file, unlock & close.", "if", "f", ".", "file", "!=", "nil", "{", "if", "err", ":=", "f", ".", "file", ".", "Sync", "(", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "syscall", ".", "Flock", "(", "int", "(", "f", ".", "file", ".", "Fd", "(", ")", ")", ",", "syscall", ".", "LOCK_UN", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "syswrap", ".", "CloseFile", "(", "f", ".", "file", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "}", "\n", "f", ".", "file", "=", "nil", "\n", "f", ".", "storage", ".", "OpWriter", "=", "nil", "\n\n", "return", "nil", "\n", "}" ]
// 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", ")", "\n", "}" ]
// 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", "{", "// 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", ")", "\n\n", "// 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.", "}", "}", ",", "}", "\n", "row", ".", "invalidateCount", "(", ")", "\n\n", "return", "row", "\n", "}" ]
// 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", "(", ")", "\n", "mustClose", ",", "err", ":=", "f", ".", "reopen", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "mustClose", "{", "defer", "f", ".", "safeClose", "(", ")", "\n", "}", "\n\n", "// handle mutux field type", "if", "f", ".", "mutexVector", "!=", "nil", "{", "if", "err", ":=", "f", ".", "handleMutex", "(", "rowID", ",", "columnID", ")", ";", "err", "!=", "nil", "{", "return", "changed", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "return", "f", ".", "unprotectedSetBit", "(", "rowID", ",", "columnID", ")", "\n", "}" ]
// 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", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "if", "found", "&&", "existingRowID", "!=", "rowID", "{", "if", "_", ",", "err", ":=", "f", ".", "unprotectedClearBit", "(", "existingRowID", ",", "columnID", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// 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", "mustClose", ",", "err", ":=", "f", ".", "reopen", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "mustClose", "{", "defer", "f", ".", "safeClose", "(", ")", "\n", "}", "\n", "return", "f", ".", "unprotectedClearBit", "(", "rowID", ",", "columnID", ")", "\n", "}" ]
// 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", ":=", "f", ".", "reopen", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "mustClose", "{", "defer", "f", ".", "safeClose", "(", ")", "\n", "}", "\n", "return", "f", ".", "unprotectedClearRow", "(", "rowID", ")", "\n", "}" ]
// 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", ",", "bitDepth", ",", "value", ",", "true", ")", "\n", "}" ]
// 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", ",", "bitDepth", ",", "value", ",", "false", ")", "\n", "}" ]
// 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", ")", "{", "// nolint: unparam", "for", "i", ":=", "uint", "(", "0", ")", ";", "i", "<", "bitDepth", ";", "i", "++", "{", "if", "value", "&", "(", "1", "<<", "i", ")", "!=", "0", "{", "bit", ",", "err", ":=", "f", ".", "pos", "(", "uint64", "(", "i", ")", ",", "columnID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "changed", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "c", ",", "err", ":=", "f", ".", "storage", ".", "Add", "(", "bit", ")", ";", "err", "!=", "nil", "{", "return", "changed", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "if", "c", "{", "changed", "=", "true", "\n", "}", "\n", "}", "else", "{", "bit", ",", "err", ":=", "f", ".", "pos", "(", "uint64", "(", "i", ")", ",", "columnID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "changed", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "c", ",", "err", ":=", "f", ".", "storage", ".", "Remove", "(", "bit", ")", ";", "err", "!=", "nil", "{", "return", "changed", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "if", "c", "{", "changed", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Mark value as set.", "p", ",", "err", ":=", "f", ".", "pos", "(", "uint64", "(", "bitDepth", ")", ",", "columnID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "changed", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "clear", "{", "if", "c", ",", "err", ":=", "f", ".", "storage", ".", "Remove", "(", "p", ")", ";", "err", "!=", "nil", "{", "return", "changed", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "if", "c", "{", "changed", "=", "true", "\n", "}", "\n", "}", "else", "{", "if", "c", ",", "err", ":=", "f", ".", "storage", ".", "Add", "(", "p", ")", ";", "err", "!=", "nil", "{", "return", "changed", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "if", "c", "{", "changed", "=", "true", "\n", "}", "\n", "}", "\n\n", "return", "changed", ",", "nil", "\n", "}" ]
// 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", ")", "{", "// Compute count based on the existence row.", "consider", ":=", "f", ".", "row", "(", "uint64", "(", "bitDepth", ")", ")", "\n", "if", "filter", "!=", "nil", "{", "consider", "=", "consider", ".", "Intersect", "(", "filter", ")", "\n", "}", "\n", "count", "=", "consider", ".", "Count", "(", ")", "\n\n", "// 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", "\n", "for", "i", ":=", "uint", "(", "0", ")", ";", "i", "<", "bitDepth", ";", "i", "++", "{", "row", ":=", "f", ".", "row", "(", "uint64", "(", "i", ")", ")", "\n", "cnt", "=", "row", ".", "intersectionCount", "(", "consider", ")", "\n", "sum", "+=", "(", "1", "<<", "i", ")", "*", "cnt", "\n", "}", "\n\n", "return", "sum", ",", "count", ",", "nil", "\n", "}" ]
// 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", ")", ")", "\n", "if", "filter", "!=", "nil", "{", "consider", "=", "consider", ".", "Intersect", "(", "filter", ")", "\n", "}", "\n\n", "// If there are no columns to consider, return early.", "if", "consider", ".", "Count", "(", ")", "==", "0", "{", "return", "0", ",", "0", ",", "nil", "\n", "}", "\n\n", "for", "i", ":=", "bitDepth", ";", "i", ">", "uint", "(", "0", ")", ";", "i", "--", "{", "ii", ":=", "i", "-", "1", "// allow for uint range: (bitDepth-1) to 0", "\n", "row", ":=", "f", ".", "row", "(", "uint64", "(", "ii", ")", ")", "\n\n", "x", ":=", "consider", ".", "Difference", "(", "row", ")", "\n", "count", "=", "x", ".", "Count", "(", ")", "\n", "if", "count", ">", "0", "{", "consider", "=", "x", "\n", "}", "else", "{", "min", "+=", "(", "1", "<<", "ii", ")", "\n", "if", "ii", "==", "0", "{", "count", "=", "consider", ".", "Count", "(", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "min", ",", "count", ",", "nil", "\n", "}" ]
// 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", ".", "rangeEQ", "(", "bitDepth", ",", "predicate", ")", "\n", "case", "pql", ".", "NEQ", ":", "return", "f", ".", "rangeNEQ", "(", "bitDepth", ",", "predicate", ")", "\n", "case", "pql", ".", "LT", ",", "pql", ".", "LTE", ":", "return", "f", ".", "rangeLT", "(", "bitDepth", ",", "predicate", ",", "op", "==", "pql", ".", "LTE", ")", "\n", "case", "pql", ".", "GT", ",", "pql", ".", "GTE", ":", "return", "f", ".", "rangeGT", "(", "bitDepth", ",", "predicate", ",", "op", "==", "pql", ".", "GTE", ")", "\n", "default", ":", "return", "nil", ",", "ErrInvalidRangeOperation", "\n", "}", "\n", "}" ]
// 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", ")", ")", "\n", "keep1", ":=", "NewRow", "(", ")", "// GTE", "\n", "keep2", ":=", "NewRow", "(", ")", "// LTE", "\n\n", "// Filter any bits that don't match the current bit value.", "for", "i", ":=", "int", "(", "bitDepth", "-", "1", ")", ";", "i", ">=", "0", ";", "i", "--", "{", "row", ":=", "f", ".", "row", "(", "uint64", "(", "i", ")", ")", "\n", "bit1", ":=", "(", "predicateMin", ">>", "uint", "(", "i", ")", ")", "&", "1", "\n", "bit2", ":=", "(", "predicateMax", ">>", "uint", "(", "i", ")", ")", "&", "1", "\n\n", "// 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", ")", ")", "\n", "}", "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", ")", ")", "\n", "}", "\n", "}", "\n\n", "// LTE predicateMin", "// If bit is zero then remove all set bits not in excluded bitmap.", "if", "bit2", "==", "0", "{", "b", "=", "b", ".", "Difference", "(", "row", ".", "Difference", "(", "keep2", ")", ")", "\n", "}", "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", ")", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "b", ",", "nil", "\n", "}" ]
// 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", ")", "{", "// Return an error if the column ID is out of the range of the fragment's shard.", "minColumnID", ":=", "f", ".", "shard", "*", "ShardWidth", "\n", "if", "columnID", "<", "minColumnID", "||", "columnID", ">=", "minColumnID", "+", "ShardWidth", "{", "return", "0", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "columnID", ")", "\n", "}", "\n", "return", "pos", "(", "rowID", ",", "columnID", ")", ",", "nil", "\n", "}" ]
// 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", "(", ")", "\n\n", "var", "err", "error", "\n", "f", ".", "storage", ".", "ForEach", "(", "func", "(", "i", "uint64", ")", "{", "// Skip if an error has already occurred.", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n\n", "// Invoke caller's function.", "err", "=", "fn", "(", "i", "/", "ShardWidth", ",", "(", "f", ".", "shard", "*", "ShardWidth", ")", "+", "(", "i", "%", "ShardWidth", ")", ")", "\n", "}", ")", "\n", "return", "err", "\n", "}" ]
// 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", ".", "Write", "(", "block", ".", "Checksum", ")", "\n", "}", "\n", "return", "h", ".", "Sum", "(", "nil", ")", "\n", "}" ]
// 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", ".", "Unlock", "(", ")", "\n", "}" ]
// 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\n", "var", "a", "[", "]", "FragmentBlock", "\n\n", "// Initialize the iterator.", "itr", ":=", "f", ".", "storage", ".", "Iterator", "(", ")", "\n", "itr", ".", "Seek", "(", "0", ")", "\n\n", "// Initialize block hasher.", "h", ":=", "newBlockHasher", "(", ")", "\n\n", "// Iterate over each value in the fragment.", "v", ",", "eof", ":=", "itr", ".", "Next", "(", ")", "\n", "if", "eof", "{", "return", "nil", "\n", "}", "\n", "blockID", ":=", "int", "(", "v", "/", "(", "HashBlockSize", "*", "ShardWidth", ")", ")", "\n", "for", "{", "// Check for multiple block checksums in a row.", "if", "n", ":=", "f", ".", "readContiguousChecksums", "(", "&", "a", ",", "blockID", ")", ";", "n", ">", "0", "{", "itr", ".", "Seek", "(", "uint64", "(", "blockID", "+", "n", ")", "*", "HashBlockSize", "*", "ShardWidth", ")", "\n", "v", ",", "eof", "=", "itr", ".", "Next", "(", ")", "\n", "if", "eof", "{", "break", "\n", "}", "\n", "blockID", "=", "int", "(", "v", "/", "(", "HashBlockSize", "*", "ShardWidth", ")", ")", "\n", "continue", "\n", "}", "\n\n", "// Reset hasher.", "h", ".", "blockID", "=", "blockID", "\n", "h", ".", "Reset", "(", ")", "\n\n", "// 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", ")", ")", "\n", "if", "blockID", "!=", "h", ".", "blockID", "||", "eof", "{", "break", "\n", "}", "\n\n", "h", ".", "WriteValue", "(", "v", ")", "\n", "}", "\n\n", "// Cache checksum.", "chksum", ":=", "h", ".", "Sum", "(", ")", "\n", "f", ".", "checksums", "[", "h", ".", "blockID", "]", "=", "chksum", "\n\n", "// Append block.", "a", "=", "append", "(", "a", ",", "FragmentBlock", "{", "ID", ":", "h", ".", "blockID", ",", "Checksum", ":", "chksum", ",", "}", ")", "\n\n", "// Exit if we're at the end.", "if", "eof", "{", "break", "\n", "}", "\n", "}", "\n\n", "return", "a", "\n", "}" ]
// 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", ".", "checksums", "[", "blockID", "+", "i", "]", "\n", "if", "chksum", "==", "nil", "{", "return", "i", "\n", "}", "\n\n", "*", "a", "=", "append", "(", "*", "a", ",", "FragmentBlock", "{", "ID", ":", "blockID", "+", "i", ",", "Checksum", ":", "chksum", ",", "}", ")", "\n", "}", "\n", "}" ]
// 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", ".", "storage", ".", "ForEachRange", "(", "uint64", "(", "id", ")", "*", "HashBlockSize", "*", "ShardWidth", ",", "(", "uint64", "(", "id", ")", "+", "1", ")", "*", "HashBlockSize", "*", "ShardWidth", ",", "func", "(", "i", "uint64", ")", "{", "rowIDs", "=", "append", "(", "rowIDs", ",", "i", "/", "ShardWidth", ")", "\n", "columnIDs", "=", "append", "(", "columnIDs", ",", "i", "%", "ShardWidth", ")", "\n", "}", ")", "\n", "return", "rowIDs", ",", "columnIDs", "\n", "}" ]
// 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", "{", "// Verify that there are an equal number of row ids and column ids.", "if", "len", "(", "rowIDs", ")", "!=", "len", "(", "columnIDs", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "rowIDs", ")", ",", "len", "(", "columnIDs", ")", ")", "\n", "}", "\n\n", "if", "f", ".", "mutexVector", "!=", "nil", "&&", "!", "options", ".", "Clear", "{", "return", "f", ".", "bulkImportMutex", "(", "rowIDs", ",", "columnIDs", ")", "\n", "}", "\n", "return", "f", ".", "bulkImportStandard", "(", "rowIDs", ",", "columnIDs", ",", "options", ")", "\n", "}" ]
// 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 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", "{", "}", ")", "\n", "lastRowID", ":=", "uint64", "(", "1", "<<", "63", ")", "\n\n", "// replace columnIDs with calculated positions to avoid allocation.", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "columnIDs", ")", ";", "i", "++", "{", "rowID", ",", "columnID", ":=", "rowIDs", "[", "i", "]", ",", "columnIDs", "[", "i", "]", "\n", "pos", ",", "err", ":=", "f", ".", "pos", "(", "rowID", ",", "columnID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "columnIDs", "[", "i", "]", "=", "pos", "\n\n", "// Add row to rowSet.", "if", "rowID", "!=", "lastRowID", "{", "lastRowID", "=", "rowID", "\n", "rowSet", "[", "rowID", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n", "}", "\n", "positions", ":=", "columnIDs", "\n", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "if", "options", ".", "Clear", "{", "err", "=", "f", ".", "importPositions", "(", "nil", ",", "positions", ",", "rowSet", ")", "\n", "}", "else", "{", "err", "=", "f", ".", "importPositions", "(", "positions", ",", "nil", ",", "rowSet", ")", "\n", "}", "\n", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}" ]
// 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\n", "rowSet", ":=", "make", "(", "map", "[", "uint64", "]", "struct", "{", "}", ")", "\n", "// 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", ")", "\n\n", "// 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", "\n", "for", "i", ":=", "range", "rowIDs", "{", "rowID", ",", "columnID", ":=", "rowIDs", "[", "i", "]", ",", "columnIDs", "[", "i", "]", "\n", "if", "existingRowID", ",", "found", ",", "err", ":=", "f", ".", "mutexVector", ".", "Get", "(", "columnID", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "else", "if", "found", "&&", "existingRowID", "!=", "rowID", "{", "// Determine the position of the bit in the storage.", "clearPos", ",", "err", ":=", "f", ".", "pos", "(", "existingRowID", ",", "columnID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "columnIDs", "[", "clearIdx", "]", "=", "clearPos", "\n", "clearIdx", "++", "\n\n", "rowSet", "[", "existingRowID", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "else", "if", "found", "&&", "existingRowID", "==", "rowID", "{", "continue", "\n", "}", "\n", "pos", ",", "err", ":=", "f", ".", "pos", "(", "rowID", ",", "columnID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "colSet", "[", "columnID", "]", "=", "pos", "\n", "rowSet", "[", "rowID", "]", "=", "struct", "{", "}", "{", "}", "\n", "}", "\n\n", "// re-use rowIDs by populating positions to set from colSet.", "i", ":=", "0", "\n", "for", "_", ",", "pos", ":=", "range", "colSet", "{", "rowIDs", "[", "i", "]", "=", "pos", "\n", "i", "++", "\n", "}", "\n", "toSet", ":=", "rowIDs", "[", ":", "i", "]", "\n", "toClear", ":=", "columnIDs", "[", ":", "clearIdx", "]", "\n\n", "return", "errors", ".", "Wrap", "(", "f", ".", "importPositions", "(", "toSet", ",", "toClear", ",", "rowSet", ")", ",", "\"", "\"", ")", "\n", "}" ]
// 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", "write", "lock", "on", "the", "fragment", "during", "the", "entire", "process", "and", "it", "handles", "every", "bit", "independently", "." ]
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", ".", "Unlock", "(", ")", "\n\n", "// Verify that there are an equal number of column ids and values.", "if", "len", "(", "columnIDs", ")", "!=", "len", "(", "values", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "columnIDs", ")", ",", "len", "(", "values", ")", ")", "\n", "}", "\n\n", "if", "len", "(", "columnIDs", ")", "*", "int", "(", "bitDepth", "+", "1", ")", "+", "f", ".", "opN", "<", "f", ".", "MaxOpN", "{", "return", "errors", ".", "Wrap", "(", "f", ".", "importValueSmallWrite", "(", "columnIDs", ",", "values", ",", "bitDepth", ",", "clear", ")", ",", "\"", "\"", ")", "\n\n", "}", "\n\n", "f", ".", "storage", ".", "OpWriter", "=", "nil", "\n\n", "// 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", "]", "\n", "if", "_", ",", "err", ":=", "f", ".", "importSetValue", "(", "columnID", ",", "bitDepth", ",", "value", ",", "clear", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "(", ")", ";", "err", "!=", "nil", "{", "_", "=", "f", ".", "closeStorage", "(", ")", "\n", "_", "=", "f", ".", "openStorage", "(", ")", "\n", "return", "err", "\n", "}", "\n\n", "err", ":=", "f", ".", "snapshot", "(", ")", "\n", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}" ]
// 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
pilosa/pilosa
fragment.go
incrementOpN
func (f *fragment) incrementOpN() error { f.opN++ if f.opN <= f.MaxOpN { return nil } if err := f.snapshot(); err != nil { return fmt.Errorf("snapshot: %s", err) } return nil }
go
func (f *fragment) incrementOpN() error { f.opN++ if f.opN <= f.MaxOpN { return nil } if err := f.snapshot(); err != nil { return fmt.Errorf("snapshot: %s", err) } return nil }
[ "func", "(", "f", "*", "fragment", ")", "incrementOpN", "(", ")", "error", "{", "f", ".", "opN", "++", "\n", "if", "f", ".", "opN", "<=", "f", ".", "MaxOpN", "{", "return", "nil", "\n", "}", "\n\n", "if", "err", ":=", "f", ".", "snapshot", "(", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// incrementOpN increase the operation count by one. // If the count exceeds the maximum allowed then a snapshot is performed.
[ "incrementOpN", "increase", "the", "operation", "count", "by", "one", ".", "If", "the", "count", "exceeds", "the", "maximum", "allowed", "then", "a", "snapshot", "is", "performed", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1896-L1906
train
pilosa/pilosa
fragment.go
Snapshot
func (f *fragment) Snapshot() error { f.mu.Lock() defer f.mu.Unlock() return f.snapshot() }
go
func (f *fragment) Snapshot() error { f.mu.Lock() defer f.mu.Unlock() return f.snapshot() }
[ "func", "(", "f", "*", "fragment", ")", "Snapshot", "(", ")", "error", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "f", ".", "snapshot", "(", ")", "\n", "}" ]
// Snapshot writes the storage bitmap to disk and reopens it.
[ "Snapshot", "writes", "the", "storage", "bitmap", "to", "disk", "and", "reopens", "it", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1909-L1913
train
pilosa/pilosa
fragment.go
unprotectedWriteToFragment
func unprotectedWriteToFragment(f *fragment, bm *roaring.Bitmap) (n int64, err error) { // nolint: interfacer completeMessage := fmt.Sprintf("fragment: snapshot complete %s/%s/%s/%d", f.index, f.field, f.view, f.shard) start := time.Now() defer track(start, completeMessage, f.stats, f.Logger) // Create a temporary file to snapshot to. snapshotPath := f.path + snapshotExt file, err := os.Create(snapshotPath) if err != nil { return n, fmt.Errorf("create snapshot file: %s", err) } defer file.Close() // Write storage to snapshot. bw := bufio.NewWriter(file) if n, err = bm.WriteTo(bw); err != nil { return n, fmt.Errorf("snapshot write to: %s", err) } if err := bw.Flush(); err != nil { return n, fmt.Errorf("flush: %s", err) } // Close current storage. if err := f.closeStorage(); err != nil { return n, fmt.Errorf("close storage: %s", err) } // Move snapshot to data file location. if err := os.Rename(snapshotPath, f.path); err != nil { return n, fmt.Errorf("rename snapshot: %s", err) } // Reopen storage. if err := f.openStorage(); err != nil { return n, fmt.Errorf("open storage: %s", err) } // Reset operation count. f.opN = 0 return n, nil }
go
func unprotectedWriteToFragment(f *fragment, bm *roaring.Bitmap) (n int64, err error) { // nolint: interfacer completeMessage := fmt.Sprintf("fragment: snapshot complete %s/%s/%s/%d", f.index, f.field, f.view, f.shard) start := time.Now() defer track(start, completeMessage, f.stats, f.Logger) // Create a temporary file to snapshot to. snapshotPath := f.path + snapshotExt file, err := os.Create(snapshotPath) if err != nil { return n, fmt.Errorf("create snapshot file: %s", err) } defer file.Close() // Write storage to snapshot. bw := bufio.NewWriter(file) if n, err = bm.WriteTo(bw); err != nil { return n, fmt.Errorf("snapshot write to: %s", err) } if err := bw.Flush(); err != nil { return n, fmt.Errorf("flush: %s", err) } // Close current storage. if err := f.closeStorage(); err != nil { return n, fmt.Errorf("close storage: %s", err) } // Move snapshot to data file location. if err := os.Rename(snapshotPath, f.path); err != nil { return n, fmt.Errorf("rename snapshot: %s", err) } // Reopen storage. if err := f.openStorage(); err != nil { return n, fmt.Errorf("open storage: %s", err) } // Reset operation count. f.opN = 0 return n, nil }
[ "func", "unprotectedWriteToFragment", "(", "f", "*", "fragment", ",", "bm", "*", "roaring", ".", "Bitmap", ")", "(", "n", "int64", ",", "err", "error", ")", "{", "// nolint: interfacer", "completeMessage", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "f", ".", "index", ",", "f", ".", "field", ",", "f", ".", "view", ",", "f", ".", "shard", ")", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "defer", "track", "(", "start", ",", "completeMessage", ",", "f", ".", "stats", ",", "f", ".", "Logger", ")", "\n\n", "// Create a temporary file to snapshot to.", "snapshotPath", ":=", "f", ".", "path", "+", "snapshotExt", "\n", "file", ",", "err", ":=", "os", ".", "Create", "(", "snapshotPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "n", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "defer", "file", ".", "Close", "(", ")", "\n\n", "// Write storage to snapshot.", "bw", ":=", "bufio", ".", "NewWriter", "(", "file", ")", "\n", "if", "n", ",", "err", "=", "bm", ".", "WriteTo", "(", "bw", ")", ";", "err", "!=", "nil", "{", "return", "n", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "bw", ".", "Flush", "(", ")", ";", "err", "!=", "nil", "{", "return", "n", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Close current storage.", "if", "err", ":=", "f", ".", "closeStorage", "(", ")", ";", "err", "!=", "nil", "{", "return", "n", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Move snapshot to data file location.", "if", "err", ":=", "os", ".", "Rename", "(", "snapshotPath", ",", "f", ".", "path", ")", ";", "err", "!=", "nil", "{", "return", "n", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Reopen storage.", "if", "err", ":=", "f", ".", "openStorage", "(", ")", ";", "err", "!=", "nil", "{", "return", "n", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Reset operation count.", "f", ".", "opN", "=", "0", "\n\n", "return", "n", ",", "nil", "\n", "}" ]
// unprotectedWriteToFragment writes the fragment f with bm as the data. It is unprotected, and // f.mu must be locked when calling it.
[ "unprotectedWriteToFragment", "writes", "the", "fragment", "f", "with", "bm", "as", "the", "data", ".", "It", "is", "unprotected", "and", "f", ".", "mu", "must", "be", "locked", "when", "calling", "it", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1927-L1970
train
pilosa/pilosa
fragment.go
RecalculateCache
func (f *fragment) RecalculateCache() { f.mu.Lock() f.cache.Recalculate() f.mu.Unlock() }
go
func (f *fragment) RecalculateCache() { f.mu.Lock() f.cache.Recalculate() f.mu.Unlock() }
[ "func", "(", "f", "*", "fragment", ")", "RecalculateCache", "(", ")", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "f", ".", "cache", ".", "Recalculate", "(", ")", "\n", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "}" ]
// RecalculateCache rebuilds the cache regardless of invalidate time delay.
[ "RecalculateCache", "rebuilds", "the", "cache", "regardless", "of", "invalidate", "time", "delay", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1973-L1977
train
pilosa/pilosa
fragment.go
FlushCache
func (f *fragment) FlushCache() error { f.mu.Lock() defer f.mu.Unlock() return f.flushCache() }
go
func (f *fragment) FlushCache() error { f.mu.Lock() defer f.mu.Unlock() return f.flushCache() }
[ "func", "(", "f", "*", "fragment", ")", "FlushCache", "(", ")", "error", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n", "return", "f", ".", "flushCache", "(", ")", "\n", "}" ]
// FlushCache writes the cache data to disk.
[ "FlushCache", "writes", "the", "cache", "data", "to", "disk", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L1980-L1984
train
pilosa/pilosa
fragment.go
WriteTo
func (f *fragment) WriteTo(w io.Writer) (n int64, err error) { // Force cache flush. if err := f.FlushCache(); err != nil { return 0, errors.Wrap(err, "flushing cache") } // Write out data and cache to a tar archive. tw := tar.NewWriter(w) if err := f.writeStorageToArchive(tw); err != nil { return 0, fmt.Errorf("write storage: %s", err) } if err := f.writeCacheToArchive(tw); err != nil { return 0, fmt.Errorf("write cache: %s", err) } return 0, nil }
go
func (f *fragment) WriteTo(w io.Writer) (n int64, err error) { // Force cache flush. if err := f.FlushCache(); err != nil { return 0, errors.Wrap(err, "flushing cache") } // Write out data and cache to a tar archive. tw := tar.NewWriter(w) if err := f.writeStorageToArchive(tw); err != nil { return 0, fmt.Errorf("write storage: %s", err) } if err := f.writeCacheToArchive(tw); err != nil { return 0, fmt.Errorf("write cache: %s", err) } return 0, nil }
[ "func", "(", "f", "*", "fragment", ")", "WriteTo", "(", "w", "io", ".", "Writer", ")", "(", "n", "int64", ",", "err", "error", ")", "{", "// Force cache flush.", "if", "err", ":=", "f", ".", "FlushCache", "(", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Write out data and cache to a tar archive.", "tw", ":=", "tar", ".", "NewWriter", "(", "w", ")", "\n", "if", "err", ":=", "f", ".", "writeStorageToArchive", "(", "tw", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "if", "err", ":=", "f", ".", "writeCacheToArchive", "(", "tw", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "0", ",", "nil", "\n", "}" ]
// WriteTo writes the fragment's data to w.
[ "WriteTo", "writes", "the", "fragment", "s", "data", "to", "w", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L2013-L2028
train
pilosa/pilosa
fragment.go
ReadFrom
func (f *fragment) ReadFrom(r io.Reader) (n int64, err error) { f.mu.Lock() defer f.mu.Unlock() tr := tar.NewReader(r) for { // Read next tar header. hdr, err := tr.Next() if err == io.EOF { break } else if err != nil { return 0, errors.Wrap(err, "opening") } // Process file based on file name. switch hdr.Name { case "data": if err := f.readStorageFromArchive(tr); err != nil { return 0, errors.Wrap(err, "reading storage") } case "cache": if err := f.readCacheFromArchive(tr); err != nil { return 0, errors.Wrap(err, "reading cache") } default: return 0, fmt.Errorf("invalid fragment archive file: %s", hdr.Name) } } return 0, nil }
go
func (f *fragment) ReadFrom(r io.Reader) (n int64, err error) { f.mu.Lock() defer f.mu.Unlock() tr := tar.NewReader(r) for { // Read next tar header. hdr, err := tr.Next() if err == io.EOF { break } else if err != nil { return 0, errors.Wrap(err, "opening") } // Process file based on file name. switch hdr.Name { case "data": if err := f.readStorageFromArchive(tr); err != nil { return 0, errors.Wrap(err, "reading storage") } case "cache": if err := f.readCacheFromArchive(tr); err != nil { return 0, errors.Wrap(err, "reading cache") } default: return 0, fmt.Errorf("invalid fragment archive file: %s", hdr.Name) } } return 0, nil }
[ "func", "(", "f", "*", "fragment", ")", "ReadFrom", "(", "r", "io", ".", "Reader", ")", "(", "n", "int64", ",", "err", "error", ")", "{", "f", ".", "mu", ".", "Lock", "(", ")", "\n", "defer", "f", ".", "mu", ".", "Unlock", "(", ")", "\n\n", "tr", ":=", "tar", ".", "NewReader", "(", "r", ")", "\n", "for", "{", "// Read next tar header.", "hdr", ",", "err", ":=", "tr", ".", "Next", "(", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "else", "if", "err", "!=", "nil", "{", "return", "0", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Process file based on file name.", "switch", "hdr", ".", "Name", "{", "case", "\"", "\"", ":", "if", "err", ":=", "f", ".", "readStorageFromArchive", "(", "tr", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "case", "\"", "\"", ":", "if", "err", ":=", "f", ".", "readCacheFromArchive", "(", "tr", ")", ";", "err", "!=", "nil", "{", "return", "0", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "default", ":", "return", "0", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "hdr", ".", "Name", ")", "\n", "}", "\n", "}", "\n\n", "return", "0", ",", "nil", "\n", "}" ]
// ReadFrom reads a data file from r and loads it into the fragment.
[ "ReadFrom", "reads", "a", "data", "file", "from", "r", "and", "loads", "it", "into", "the", "fragment", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L2104-L2134
train
pilosa/pilosa
fragment.go
syncFragment
func (s *fragmentSyncer) syncFragment() error { span, ctx := tracing.StartSpanFromContext(context.Background(), "FragmentSyncer.syncFragment") defer span.Finish() // Determine replica set. nodes := s.Cluster.shardNodes(s.Fragment.index, s.Fragment.shard) if len(nodes) == 1 { return nil } // Create a set of blocks. blockSets := make([][]FragmentBlock, 0, len(nodes)) for _, node := range nodes { // Read local blocks. if node.ID == s.Node.ID { b := s.Fragment.Blocks() blockSets = append(blockSets, b) continue } // Retrieve remote blocks. blocks, err := s.Cluster.InternalClient.FragmentBlocks(ctx, &node.URI, s.Fragment.index, s.Fragment.field, s.Fragment.view, s.Fragment.shard) if err != nil && err != ErrFragmentNotFound { return errors.Wrap(err, "getting blocks") } blockSets = append(blockSets, blocks) // Verify sync is not prematurely closing. if s.isClosing() { return nil } } // Iterate over all blocks and find differences. checksums := make([][]byte, len(nodes)) for { // Find min block id. blockID := -1 for _, blocks := range blockSets { if len(blocks) == 0 { continue } else if blockID == -1 || blocks[0].ID < blockID { blockID = blocks[0].ID } } // Exit loop if no blocks are left. if blockID == -1 { break } // Read the checksum for the current block. for i, blocks := range blockSets { // Clear checksum if the next block for the node doesn't match current ID. if len(blocks) == 0 || blocks[0].ID != blockID { checksums[i] = nil continue } // Otherwise set checksum and move forward. checksums[i] = blocks[0].Checksum blockSets[i] = blockSets[i][1:] } // Ignore if all the blocks on each node match. if byteSlicesEqual(checksums) { continue } // Synchronize block. if err := s.syncBlock(blockID); err != nil { return fmt.Errorf("sync block: id=%d, err=%s", blockID, err) } s.Fragment.stats.Count("BlockRepair", 1, 1.0) } return nil }
go
func (s *fragmentSyncer) syncFragment() error { span, ctx := tracing.StartSpanFromContext(context.Background(), "FragmentSyncer.syncFragment") defer span.Finish() // Determine replica set. nodes := s.Cluster.shardNodes(s.Fragment.index, s.Fragment.shard) if len(nodes) == 1 { return nil } // Create a set of blocks. blockSets := make([][]FragmentBlock, 0, len(nodes)) for _, node := range nodes { // Read local blocks. if node.ID == s.Node.ID { b := s.Fragment.Blocks() blockSets = append(blockSets, b) continue } // Retrieve remote blocks. blocks, err := s.Cluster.InternalClient.FragmentBlocks(ctx, &node.URI, s.Fragment.index, s.Fragment.field, s.Fragment.view, s.Fragment.shard) if err != nil && err != ErrFragmentNotFound { return errors.Wrap(err, "getting blocks") } blockSets = append(blockSets, blocks) // Verify sync is not prematurely closing. if s.isClosing() { return nil } } // Iterate over all blocks and find differences. checksums := make([][]byte, len(nodes)) for { // Find min block id. blockID := -1 for _, blocks := range blockSets { if len(blocks) == 0 { continue } else if blockID == -1 || blocks[0].ID < blockID { blockID = blocks[0].ID } } // Exit loop if no blocks are left. if blockID == -1 { break } // Read the checksum for the current block. for i, blocks := range blockSets { // Clear checksum if the next block for the node doesn't match current ID. if len(blocks) == 0 || blocks[0].ID != blockID { checksums[i] = nil continue } // Otherwise set checksum and move forward. checksums[i] = blocks[0].Checksum blockSets[i] = blockSets[i][1:] } // Ignore if all the blocks on each node match. if byteSlicesEqual(checksums) { continue } // Synchronize block. if err := s.syncBlock(blockID); err != nil { return fmt.Errorf("sync block: id=%d, err=%s", blockID, err) } s.Fragment.stats.Count("BlockRepair", 1, 1.0) } return nil }
[ "func", "(", "s", "*", "fragmentSyncer", ")", "syncFragment", "(", ")", "error", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "context", ".", "Background", "(", ")", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "// Determine replica set.", "nodes", ":=", "s", ".", "Cluster", ".", "shardNodes", "(", "s", ".", "Fragment", ".", "index", ",", "s", ".", "Fragment", ".", "shard", ")", "\n", "if", "len", "(", "nodes", ")", "==", "1", "{", "return", "nil", "\n", "}", "\n\n", "// Create a set of blocks.", "blockSets", ":=", "make", "(", "[", "]", "[", "]", "FragmentBlock", ",", "0", ",", "len", "(", "nodes", ")", ")", "\n", "for", "_", ",", "node", ":=", "range", "nodes", "{", "// Read local blocks.", "if", "node", ".", "ID", "==", "s", ".", "Node", ".", "ID", "{", "b", ":=", "s", ".", "Fragment", ".", "Blocks", "(", ")", "\n", "blockSets", "=", "append", "(", "blockSets", ",", "b", ")", "\n", "continue", "\n", "}", "\n\n", "// Retrieve remote blocks.", "blocks", ",", "err", ":=", "s", ".", "Cluster", ".", "InternalClient", ".", "FragmentBlocks", "(", "ctx", ",", "&", "node", ".", "URI", ",", "s", ".", "Fragment", ".", "index", ",", "s", ".", "Fragment", ".", "field", ",", "s", ".", "Fragment", ".", "view", ",", "s", ".", "Fragment", ".", "shard", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "ErrFragmentNotFound", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "blockSets", "=", "append", "(", "blockSets", ",", "blocks", ")", "\n\n", "// Verify sync is not prematurely closing.", "if", "s", ".", "isClosing", "(", ")", "{", "return", "nil", "\n", "}", "\n", "}", "\n\n", "// Iterate over all blocks and find differences.", "checksums", ":=", "make", "(", "[", "]", "[", "]", "byte", ",", "len", "(", "nodes", ")", ")", "\n", "for", "{", "// Find min block id.", "blockID", ":=", "-", "1", "\n", "for", "_", ",", "blocks", ":=", "range", "blockSets", "{", "if", "len", "(", "blocks", ")", "==", "0", "{", "continue", "\n", "}", "else", "if", "blockID", "==", "-", "1", "||", "blocks", "[", "0", "]", ".", "ID", "<", "blockID", "{", "blockID", "=", "blocks", "[", "0", "]", ".", "ID", "\n", "}", "\n", "}", "\n\n", "// Exit loop if no blocks are left.", "if", "blockID", "==", "-", "1", "{", "break", "\n", "}", "\n\n", "// Read the checksum for the current block.", "for", "i", ",", "blocks", ":=", "range", "blockSets", "{", "// Clear checksum if the next block for the node doesn't match current ID.", "if", "len", "(", "blocks", ")", "==", "0", "||", "blocks", "[", "0", "]", ".", "ID", "!=", "blockID", "{", "checksums", "[", "i", "]", "=", "nil", "\n", "continue", "\n", "}", "\n\n", "// Otherwise set checksum and move forward.", "checksums", "[", "i", "]", "=", "blocks", "[", "0", "]", ".", "Checksum", "\n", "blockSets", "[", "i", "]", "=", "blockSets", "[", "i", "]", "[", "1", ":", "]", "\n", "}", "\n\n", "// Ignore if all the blocks on each node match.", "if", "byteSlicesEqual", "(", "checksums", ")", "{", "continue", "\n", "}", "\n", "// Synchronize block.", "if", "err", ":=", "s", ".", "syncBlock", "(", "blockID", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "blockID", ",", "err", ")", "\n", "}", "\n", "s", ".", "Fragment", ".", "stats", ".", "Count", "(", "\"", "\"", ",", "1", ",", "1.0", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// syncFragment compares checksums for the local and remote fragments and // then merges any blocks which have differences.
[ "syncFragment", "compares", "checksums", "for", "the", "local", "and", "remote", "fragments", "and", "then", "merges", "any", "blocks", "which", "have", "differences", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L2381-L2457
train
pilosa/pilosa
fragment.go
syncBlock
func (s *fragmentSyncer) syncBlock(id int) error { span, ctx := tracing.StartSpanFromContext(context.Background(), "FragmentSyncer.syncBlock") defer span.Finish() f := s.Fragment // Read pairs from each remote block. var uris []*URI var pairSets []pairSet for _, node := range s.Cluster.shardNodes(f.index, f.shard) { if s.Node.ID == node.ID { continue } // Verify sync is not prematurely closing. if s.isClosing() { return nil } uri := &node.URI uris = append(uris, uri) // Only sync the standard block. rowIDs, columnIDs, err := s.Cluster.InternalClient.BlockData(ctx, &node.URI, f.index, f.field, f.view, f.shard, id) if err != nil { return errors.Wrap(err, "getting block") } pairSets = append(pairSets, pairSet{ columnIDs: columnIDs, rowIDs: rowIDs, }) } // Verify sync is not prematurely closing. if s.isClosing() { return nil } // Merge blocks together. sets, clears, err := f.mergeBlock(id, pairSets) if err != nil { return errors.Wrap(err, "merging") } // Write updates to remote blocks. for i := 0; i < len(uris); i++ { set, clear := sets[i], clears[i] // Handle Sets. if len(set.columnIDs) > 0 { setData, err := bitsToRoaringData(set) if err != nil { return errors.Wrap(err, "converting bits to roaring data (set)") } setReq := &ImportRoaringRequest{ Clear: false, Views: map[string][]byte{cleanViewName(f.view): setData}, } if err := s.Cluster.InternalClient.ImportRoaring(ctx, uris[i], f.index, f.field, f.shard, true, setReq); err != nil { return errors.Wrap(err, "sending roaring data (set)") } } // Handle Clears. if len(clear.columnIDs) > 0 { clearData, err := bitsToRoaringData(clear) if err != nil { return errors.Wrap(err, "converting bits to roaring data (clear)") } clearReq := &ImportRoaringRequest{ Clear: true, Views: map[string][]byte{"": clearData}, } if err := s.Cluster.InternalClient.ImportRoaring(ctx, uris[i], f.index, f.field, f.shard, true, clearReq); err != nil { return errors.Wrap(err, "sending roaring data (clear)") } } } return nil }
go
func (s *fragmentSyncer) syncBlock(id int) error { span, ctx := tracing.StartSpanFromContext(context.Background(), "FragmentSyncer.syncBlock") defer span.Finish() f := s.Fragment // Read pairs from each remote block. var uris []*URI var pairSets []pairSet for _, node := range s.Cluster.shardNodes(f.index, f.shard) { if s.Node.ID == node.ID { continue } // Verify sync is not prematurely closing. if s.isClosing() { return nil } uri := &node.URI uris = append(uris, uri) // Only sync the standard block. rowIDs, columnIDs, err := s.Cluster.InternalClient.BlockData(ctx, &node.URI, f.index, f.field, f.view, f.shard, id) if err != nil { return errors.Wrap(err, "getting block") } pairSets = append(pairSets, pairSet{ columnIDs: columnIDs, rowIDs: rowIDs, }) } // Verify sync is not prematurely closing. if s.isClosing() { return nil } // Merge blocks together. sets, clears, err := f.mergeBlock(id, pairSets) if err != nil { return errors.Wrap(err, "merging") } // Write updates to remote blocks. for i := 0; i < len(uris); i++ { set, clear := sets[i], clears[i] // Handle Sets. if len(set.columnIDs) > 0 { setData, err := bitsToRoaringData(set) if err != nil { return errors.Wrap(err, "converting bits to roaring data (set)") } setReq := &ImportRoaringRequest{ Clear: false, Views: map[string][]byte{cleanViewName(f.view): setData}, } if err := s.Cluster.InternalClient.ImportRoaring(ctx, uris[i], f.index, f.field, f.shard, true, setReq); err != nil { return errors.Wrap(err, "sending roaring data (set)") } } // Handle Clears. if len(clear.columnIDs) > 0 { clearData, err := bitsToRoaringData(clear) if err != nil { return errors.Wrap(err, "converting bits to roaring data (clear)") } clearReq := &ImportRoaringRequest{ Clear: true, Views: map[string][]byte{"": clearData}, } if err := s.Cluster.InternalClient.ImportRoaring(ctx, uris[i], f.index, f.field, f.shard, true, clearReq); err != nil { return errors.Wrap(err, "sending roaring data (clear)") } } } return nil }
[ "func", "(", "s", "*", "fragmentSyncer", ")", "syncBlock", "(", "id", "int", ")", "error", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "context", ".", "Background", "(", ")", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "f", ":=", "s", ".", "Fragment", "\n\n", "// Read pairs from each remote block.", "var", "uris", "[", "]", "*", "URI", "\n", "var", "pairSets", "[", "]", "pairSet", "\n", "for", "_", ",", "node", ":=", "range", "s", ".", "Cluster", ".", "shardNodes", "(", "f", ".", "index", ",", "f", ".", "shard", ")", "{", "if", "s", ".", "Node", ".", "ID", "==", "node", ".", "ID", "{", "continue", "\n", "}", "\n\n", "// Verify sync is not prematurely closing.", "if", "s", ".", "isClosing", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "uri", ":=", "&", "node", ".", "URI", "\n", "uris", "=", "append", "(", "uris", ",", "uri", ")", "\n\n", "// Only sync the standard block.", "rowIDs", ",", "columnIDs", ",", "err", ":=", "s", ".", "Cluster", ".", "InternalClient", ".", "BlockData", "(", "ctx", ",", "&", "node", ".", "URI", ",", "f", ".", "index", ",", "f", ".", "field", ",", "f", ".", "view", ",", "f", ".", "shard", ",", "id", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "pairSets", "=", "append", "(", "pairSets", ",", "pairSet", "{", "columnIDs", ":", "columnIDs", ",", "rowIDs", ":", "rowIDs", ",", "}", ")", "\n", "}", "\n\n", "// Verify sync is not prematurely closing.", "if", "s", ".", "isClosing", "(", ")", "{", "return", "nil", "\n", "}", "\n\n", "// Merge blocks together.", "sets", ",", "clears", ",", "err", ":=", "f", ".", "mergeBlock", "(", "id", ",", "pairSets", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Write updates to remote blocks.", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "uris", ")", ";", "i", "++", "{", "set", ",", "clear", ":=", "sets", "[", "i", "]", ",", "clears", "[", "i", "]", "\n\n", "// Handle Sets.", "if", "len", "(", "set", ".", "columnIDs", ")", ">", "0", "{", "setData", ",", "err", ":=", "bitsToRoaringData", "(", "set", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "setReq", ":=", "&", "ImportRoaringRequest", "{", "Clear", ":", "false", ",", "Views", ":", "map", "[", "string", "]", "[", "]", "byte", "{", "cleanViewName", "(", "f", ".", "view", ")", ":", "setData", "}", ",", "}", "\n\n", "if", "err", ":=", "s", ".", "Cluster", ".", "InternalClient", ".", "ImportRoaring", "(", "ctx", ",", "uris", "[", "i", "]", ",", "f", ".", "index", ",", "f", ".", "field", ",", "f", ".", "shard", ",", "true", ",", "setReq", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "// Handle Clears.", "if", "len", "(", "clear", ".", "columnIDs", ")", ">", "0", "{", "clearData", ",", "err", ":=", "bitsToRoaringData", "(", "clear", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "clearReq", ":=", "&", "ImportRoaringRequest", "{", "Clear", ":", "true", ",", "Views", ":", "map", "[", "string", "]", "[", "]", "byte", "{", "\"", "\"", ":", "clearData", "}", ",", "}", "\n\n", "if", "err", ":=", "s", ".", "Cluster", ".", "InternalClient", ".", "ImportRoaring", "(", "ctx", ",", "uris", "[", "i", "]", ",", "f", ".", "index", ",", "f", ".", "field", ",", "f", ".", "shard", ",", "true", ",", "clearReq", ")", ";", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// syncBlock sends and receives all rows for a given block. // Returns an error if any remote hosts are unreachable.
[ "syncBlock", "sends", "and", "receives", "all", "rows", "for", "a", "given", "block", ".", "Returns", "an", "error", "if", "any", "remote", "hosts", "are", "unreachable", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L2461-L2546
train
pilosa/pilosa
fragment.go
bitsToRoaringData
func bitsToRoaringData(ps pairSet) ([]byte, error) { bmp := roaring.NewBitmap() for j := 0; j < len(ps.columnIDs); j++ { bmp.DirectAdd(ps.rowIDs[j]*ShardWidth + (ps.columnIDs[j] % ShardWidth)) } var buf bytes.Buffer _, err := bmp.WriteTo(&buf) if err != nil { return nil, errors.Wrap(err, "writing to buffer") } return buf.Bytes(), nil }
go
func bitsToRoaringData(ps pairSet) ([]byte, error) { bmp := roaring.NewBitmap() for j := 0; j < len(ps.columnIDs); j++ { bmp.DirectAdd(ps.rowIDs[j]*ShardWidth + (ps.columnIDs[j] % ShardWidth)) } var buf bytes.Buffer _, err := bmp.WriteTo(&buf) if err != nil { return nil, errors.Wrap(err, "writing to buffer") } return buf.Bytes(), nil }
[ "func", "bitsToRoaringData", "(", "ps", "pairSet", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "bmp", ":=", "roaring", ".", "NewBitmap", "(", ")", "\n", "for", "j", ":=", "0", ";", "j", "<", "len", "(", "ps", ".", "columnIDs", ")", ";", "j", "++", "{", "bmp", ".", "DirectAdd", "(", "ps", ".", "rowIDs", "[", "j", "]", "*", "ShardWidth", "+", "(", "ps", ".", "columnIDs", "[", "j", "]", "%", "ShardWidth", ")", ")", "\n", "}", "\n\n", "var", "buf", "bytes", ".", "Buffer", "\n", "_", ",", "err", ":=", "bmp", ".", "WriteTo", "(", "&", "buf", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "return", "buf", ".", "Bytes", "(", ")", ",", "nil", "\n", "}" ]
// bitsToRoaringData converts a pairSet into a roaring.Bitmap // which represents the data within a single shard.
[ "bitsToRoaringData", "converts", "a", "pairSet", "into", "a", "roaring", ".", "Bitmap", "which", "represents", "the", "data", "within", "a", "single", "shard", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L2566-L2579
train
pilosa/pilosa
fragment.go
byteSlicesEqual
func byteSlicesEqual(a [][]byte) bool { if len(a) == 0 { return true } for _, v := range a[1:] { if !bytes.Equal(a[0], v) { return false } } return true }
go
func byteSlicesEqual(a [][]byte) bool { if len(a) == 0 { return true } for _, v := range a[1:] { if !bytes.Equal(a[0], v) { return false } } return true }
[ "func", "byteSlicesEqual", "(", "a", "[", "]", "[", "]", "byte", ")", "bool", "{", "if", "len", "(", "a", ")", "==", "0", "{", "return", "true", "\n", "}", "\n\n", "for", "_", ",", "v", ":=", "range", "a", "[", "1", ":", "]", "{", "if", "!", "bytes", ".", "Equal", "(", "a", "[", "0", "]", ",", "v", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// byteSlicesEqual returns true if all slices are equal.
[ "byteSlicesEqual", "returns", "true", "if", "all", "slices", "are", "equal", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/fragment.go#L2596-L2607
train
pilosa/pilosa
http/client.go
NewInternalClient
func NewInternalClient(host string, remoteClient *http.Client) (*InternalClient, error) { if host == "" { return nil, pilosa.ErrHostRequired } uri, err := pilosa.NewURIFromAddress(host) if err != nil { return nil, errors.Wrap(err, "getting URI") } client := NewInternalClientFromURI(uri, remoteClient) return client, nil }
go
func NewInternalClient(host string, remoteClient *http.Client) (*InternalClient, error) { if host == "" { return nil, pilosa.ErrHostRequired } uri, err := pilosa.NewURIFromAddress(host) if err != nil { return nil, errors.Wrap(err, "getting URI") } client := NewInternalClientFromURI(uri, remoteClient) return client, nil }
[ "func", "NewInternalClient", "(", "host", "string", ",", "remoteClient", "*", "http", ".", "Client", ")", "(", "*", "InternalClient", ",", "error", ")", "{", "if", "host", "==", "\"", "\"", "{", "return", "nil", ",", "pilosa", ".", "ErrHostRequired", "\n", "}", "\n\n", "uri", ",", "err", ":=", "pilosa", ".", "NewURIFromAddress", "(", "host", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "client", ":=", "NewInternalClientFromURI", "(", "uri", ",", "remoteClient", ")", "\n", "return", "client", ",", "nil", "\n", "}" ]
// NewInternalClient returns a new instance of InternalClient to connect to host.
[ "NewInternalClient", "returns", "a", "new", "instance", "of", "InternalClient", "to", "connect", "to", "host", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L46-L58
train
pilosa/pilosa
http/client.go
MaxShardByIndex
func (c *InternalClient) MaxShardByIndex(ctx context.Context) (map[string]uint64, error) { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.MaxShardByIndex") defer span.Finish() return c.maxShardByIndex(ctx) }
go
func (c *InternalClient) MaxShardByIndex(ctx context.Context) (map[string]uint64, error) { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.MaxShardByIndex") defer span.Finish() return c.maxShardByIndex(ctx) }
[ "func", "(", "c", "*", "InternalClient", ")", "MaxShardByIndex", "(", "ctx", "context", ".", "Context", ")", "(", "map", "[", "string", "]", "uint64", ",", "error", ")", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "return", "c", ".", "maxShardByIndex", "(", "ctx", ")", "\n", "}" ]
// MaxShardByIndex returns the number of shards on a server by index.
[ "MaxShardByIndex", "returns", "the", "number", "of", "shards", "on", "a", "server", "by", "index", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L69-L73
train
pilosa/pilosa
http/client.go
maxShardByIndex
func (c *InternalClient) maxShardByIndex(ctx context.Context) (map[string]uint64, error) { // Execute request against the host. u := uriPathToURL(c.defaultURI, "/internal/shards/max") // Build request. req, err := http.NewRequest("GET", u.String(), nil) if err != nil { return nil, errors.Wrap(err, "creating request") } req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) req.Header.Set("Accept", "application/json") // Execute request. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() var rsp getShardsMaxResponse if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil { return nil, fmt.Errorf("json decode: %s", err) } return rsp.Standard, nil }
go
func (c *InternalClient) maxShardByIndex(ctx context.Context) (map[string]uint64, error) { // Execute request against the host. u := uriPathToURL(c.defaultURI, "/internal/shards/max") // Build request. req, err := http.NewRequest("GET", u.String(), nil) if err != nil { return nil, errors.Wrap(err, "creating request") } req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) req.Header.Set("Accept", "application/json") // Execute request. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() var rsp getShardsMaxResponse if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil { return nil, fmt.Errorf("json decode: %s", err) } return rsp.Standard, nil }
[ "func", "(", "c", "*", "InternalClient", ")", "maxShardByIndex", "(", "ctx", "context", ".", "Context", ")", "(", "map", "[", "string", "]", "uint64", ",", "error", ")", "{", "// Execute request against the host.", "u", ":=", "uriPathToURL", "(", "c", ".", "defaultURI", ",", "\"", "\"", ")", "\n\n", "// Build request.", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", "+", "pilosa", ".", "Version", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "// Execute request.", "resp", ",", "err", ":=", "c", ".", "executeRequest", "(", "req", ".", "WithContext", "(", "ctx", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n\n", "var", "rsp", "getShardsMaxResponse", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "rsp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "rsp", ".", "Standard", ",", "nil", "\n", "}" ]
// maxShardByIndex returns the number of shards on a server by index.
[ "maxShardByIndex", "returns", "the", "number", "of", "shards", "on", "a", "server", "by", "index", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L76-L102
train
pilosa/pilosa
http/client.go
Schema
func (c *InternalClient) Schema(ctx context.Context) ([]*pilosa.IndexInfo, error) { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.Schema") defer span.Finish() // Execute request against the host. u := c.defaultURI.Path("/schema") // Build request. req, err := http.NewRequest("GET", u, nil) if err != nil { return nil, errors.Wrap(err, "creating request") } req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) req.Header.Set("Accept", "application/json") // Execute request. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() var rsp getSchemaResponse if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil { return nil, fmt.Errorf("json decode: %s", err) } return rsp.Indexes, nil }
go
func (c *InternalClient) Schema(ctx context.Context) ([]*pilosa.IndexInfo, error) { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.Schema") defer span.Finish() // Execute request against the host. u := c.defaultURI.Path("/schema") // Build request. req, err := http.NewRequest("GET", u, nil) if err != nil { return nil, errors.Wrap(err, "creating request") } req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) req.Header.Set("Accept", "application/json") // Execute request. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() var rsp getSchemaResponse if err := json.NewDecoder(resp.Body).Decode(&rsp); err != nil { return nil, fmt.Errorf("json decode: %s", err) } return rsp.Indexes, nil }
[ "func", "(", "c", "*", "InternalClient", ")", "Schema", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "*", "pilosa", ".", "IndexInfo", ",", "error", ")", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "// Execute request against the host.", "u", ":=", "c", ".", "defaultURI", ".", "Path", "(", "\"", "\"", ")", "\n\n", "// Build request.", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", "+", "pilosa", ".", "Version", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "// Execute request.", "resp", ",", "err", ":=", "c", ".", "executeRequest", "(", "req", ".", "WithContext", "(", "ctx", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n\n", "var", "rsp", "getSchemaResponse", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "rsp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "rsp", ".", "Indexes", ",", "nil", "\n", "}" ]
// Schema returns all index and field schema information.
[ "Schema", "returns", "all", "index", "and", "field", "schema", "information", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L105-L133
train
pilosa/pilosa
http/client.go
CreateIndex
func (c *InternalClient) CreateIndex(ctx context.Context, index string, opt pilosa.IndexOptions) error { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.CreateIndex") defer span.Finish() // Encode query request. buf, err := json.Marshal(&postIndexRequest{ Options: opt, }) if err != nil { return errors.Wrap(err, "encoding request") } // Create URL & HTTP request. u := uriPathToURL(c.defaultURI, fmt.Sprintf("/index/%s", index)) req, err := http.NewRequest("POST", u.String(), bytes.NewReader(buf)) if err != nil { return errors.Wrap(err, "creating request") } req.Header.Set("Content-Length", strconv.Itoa(len(buf))) req.Header.Set("Content-Type", "application/json") req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) // Execute request against the host. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { if resp != nil && resp.StatusCode == http.StatusConflict { return pilosa.ErrIndexExists } return err } return errors.Wrap(resp.Body.Close(), "closing response body") }
go
func (c *InternalClient) CreateIndex(ctx context.Context, index string, opt pilosa.IndexOptions) error { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.CreateIndex") defer span.Finish() // Encode query request. buf, err := json.Marshal(&postIndexRequest{ Options: opt, }) if err != nil { return errors.Wrap(err, "encoding request") } // Create URL & HTTP request. u := uriPathToURL(c.defaultURI, fmt.Sprintf("/index/%s", index)) req, err := http.NewRequest("POST", u.String(), bytes.NewReader(buf)) if err != nil { return errors.Wrap(err, "creating request") } req.Header.Set("Content-Length", strconv.Itoa(len(buf))) req.Header.Set("Content-Type", "application/json") req.Header.Set("Accept", "application/json") req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) // Execute request against the host. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { if resp != nil && resp.StatusCode == http.StatusConflict { return pilosa.ErrIndexExists } return err } return errors.Wrap(resp.Body.Close(), "closing response body") }
[ "func", "(", "c", "*", "InternalClient", ")", "CreateIndex", "(", "ctx", "context", ".", "Context", ",", "index", "string", ",", "opt", "pilosa", ".", "IndexOptions", ")", "error", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "// Encode query request.", "buf", ",", "err", ":=", "json", ".", "Marshal", "(", "&", "postIndexRequest", "{", "Options", ":", "opt", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Create URL & HTTP request.", "u", ":=", "uriPathToURL", "(", "c", ".", "defaultURI", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "index", ")", ")", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "bytes", ".", "NewReader", "(", "buf", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "len", "(", "buf", ")", ")", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", "+", "pilosa", ".", "Version", ")", "\n\n", "// Execute request against the host.", "resp", ",", "err", ":=", "c", ".", "executeRequest", "(", "req", ".", "WithContext", "(", "ctx", ")", ")", "\n", "if", "err", "!=", "nil", "{", "if", "resp", "!=", "nil", "&&", "resp", ".", "StatusCode", "==", "http", ".", "StatusConflict", "{", "return", "pilosa", ".", "ErrIndexExists", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "return", "errors", ".", "Wrap", "(", "resp", ".", "Body", ".", "Close", "(", ")", ",", "\"", "\"", ")", "\n", "}" ]
// CreateIndex creates a new index on the server.
[ "CreateIndex", "creates", "a", "new", "index", "on", "the", "server", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L163-L195
train
pilosa/pilosa
http/client.go
FragmentNodes
func (c *InternalClient) FragmentNodes(ctx context.Context, index string, shard uint64) ([]*pilosa.Node, error) { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.FragmentNodes") defer span.Finish() // Execute request against the host. u := uriPathToURL(c.defaultURI, "/internal/fragment/nodes") u.RawQuery = (url.Values{"index": {index}, "shard": {strconv.FormatUint(shard, 10)}}).Encode() // Build request. req, err := http.NewRequest("GET", u.String(), nil) if err != nil { return nil, errors.Wrap(err, "creating request") } req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) req.Header.Set("Accept", "application/json") // Execute request. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() var a []*pilosa.Node if err := json.NewDecoder(resp.Body).Decode(&a); err != nil { return nil, fmt.Errorf("json decode: %s", err) } return a, nil }
go
func (c *InternalClient) FragmentNodes(ctx context.Context, index string, shard uint64) ([]*pilosa.Node, error) { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.FragmentNodes") defer span.Finish() // Execute request against the host. u := uriPathToURL(c.defaultURI, "/internal/fragment/nodes") u.RawQuery = (url.Values{"index": {index}, "shard": {strconv.FormatUint(shard, 10)}}).Encode() // Build request. req, err := http.NewRequest("GET", u.String(), nil) if err != nil { return nil, errors.Wrap(err, "creating request") } req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) req.Header.Set("Accept", "application/json") // Execute request. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() var a []*pilosa.Node if err := json.NewDecoder(resp.Body).Decode(&a); err != nil { return nil, fmt.Errorf("json decode: %s", err) } return a, nil }
[ "func", "(", "c", "*", "InternalClient", ")", "FragmentNodes", "(", "ctx", "context", ".", "Context", ",", "index", "string", ",", "shard", "uint64", ")", "(", "[", "]", "*", "pilosa", ".", "Node", ",", "error", ")", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "// Execute request against the host.", "u", ":=", "uriPathToURL", "(", "c", ".", "defaultURI", ",", "\"", "\"", ")", "\n", "u", ".", "RawQuery", "=", "(", "url", ".", "Values", "{", "\"", "\"", ":", "{", "index", "}", ",", "\"", "\"", ":", "{", "strconv", ".", "FormatUint", "(", "shard", ",", "10", ")", "}", "}", ")", ".", "Encode", "(", ")", "\n\n", "// Build request.", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", "+", "pilosa", ".", "Version", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "// Execute request.", "resp", ",", "err", ":=", "c", ".", "executeRequest", "(", "req", ".", "WithContext", "(", "ctx", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n\n", "var", "a", "[", "]", "*", "pilosa", ".", "Node", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "a", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "a", ",", "nil", "\n", "}" ]
// FragmentNodes returns a list of nodes that own a shard.
[ "FragmentNodes", "returns", "a", "list", "of", "nodes", "that", "own", "a", "shard", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L198-L227
train
pilosa/pilosa
http/client.go
Nodes
func (c *InternalClient) Nodes(ctx context.Context) ([]*pilosa.Node, error) { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.Nodes") defer span.Finish() // Execute request against the host. u := uriPathToURL(c.defaultURI, "/internal/nodes") // Build request. req, err := http.NewRequest("GET", u.String(), nil) if err != nil { return nil, errors.Wrap(err, "creating request") } req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) req.Header.Set("Accept", "application/json") // Execute request. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() var a []*pilosa.Node if err := json.NewDecoder(resp.Body).Decode(&a); err != nil { return nil, fmt.Errorf("json decode: %s", err) } return a, nil }
go
func (c *InternalClient) Nodes(ctx context.Context) ([]*pilosa.Node, error) { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.Nodes") defer span.Finish() // Execute request against the host. u := uriPathToURL(c.defaultURI, "/internal/nodes") // Build request. req, err := http.NewRequest("GET", u.String(), nil) if err != nil { return nil, errors.Wrap(err, "creating request") } req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) req.Header.Set("Accept", "application/json") // Execute request. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() var a []*pilosa.Node if err := json.NewDecoder(resp.Body).Decode(&a); err != nil { return nil, fmt.Errorf("json decode: %s", err) } return a, nil }
[ "func", "(", "c", "*", "InternalClient", ")", "Nodes", "(", "ctx", "context", ".", "Context", ")", "(", "[", "]", "*", "pilosa", ".", "Node", ",", "error", ")", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "// Execute request against the host.", "u", ":=", "uriPathToURL", "(", "c", ".", "defaultURI", ",", "\"", "\"", ")", "\n\n", "// Build request.", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ".", "String", "(", ")", ",", "nil", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", "+", "pilosa", ".", "Version", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "// Execute request.", "resp", ",", "err", ":=", "c", ".", "executeRequest", "(", "req", ".", "WithContext", "(", "ctx", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n\n", "var", "a", "[", "]", "*", "pilosa", ".", "Node", "\n", "if", "err", ":=", "json", ".", "NewDecoder", "(", "resp", ".", "Body", ")", ".", "Decode", "(", "&", "a", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "a", ",", "nil", "\n", "}" ]
// Nodes returns a list of all nodes.
[ "Nodes", "returns", "a", "list", "of", "all", "nodes", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L230-L258
train
pilosa/pilosa
http/client.go
Query
func (c *InternalClient) Query(ctx context.Context, index string, queryRequest *pilosa.QueryRequest) (*pilosa.QueryResponse, error) { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.Query") defer span.Finish() return c.QueryNode(ctx, c.defaultURI, index, queryRequest) }
go
func (c *InternalClient) Query(ctx context.Context, index string, queryRequest *pilosa.QueryRequest) (*pilosa.QueryResponse, error) { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.Query") defer span.Finish() return c.QueryNode(ctx, c.defaultURI, index, queryRequest) }
[ "func", "(", "c", "*", "InternalClient", ")", "Query", "(", "ctx", "context", ".", "Context", ",", "index", "string", ",", "queryRequest", "*", "pilosa", ".", "QueryRequest", ")", "(", "*", "pilosa", ".", "QueryResponse", ",", "error", ")", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n", "return", "c", ".", "QueryNode", "(", "ctx", ",", "c", ".", "defaultURI", ",", "index", ",", "queryRequest", ")", "\n", "}" ]
// Query executes query against the index.
[ "Query", "executes", "query", "against", "the", "index", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L261-L265
train
pilosa/pilosa
http/client.go
QueryNode
func (c *InternalClient) QueryNode(ctx context.Context, uri *pilosa.URI, index string, queryRequest *pilosa.QueryRequest) (*pilosa.QueryResponse, error) { span, ctx := tracing.StartSpanFromContext(ctx, "QueryNode") defer span.Finish() if index == "" { return nil, pilosa.ErrIndexRequired } else if queryRequest.Query == "" { return nil, pilosa.ErrQueryRequired } buf, err := c.serializer.Marshal(queryRequest) if err != nil { return nil, errors.Wrap(err, "marshaling queryRequest") } // Create HTTP request. u := uri.Path(fmt.Sprintf("/index/%s/query", index)) req, err := http.NewRequest("POST", u, bytes.NewReader(buf)) if err != nil { return nil, errors.Wrap(err, "creating request") } req.Header.Set("Content-Length", strconv.Itoa(len(buf))) req.Header.Set("Content-Type", "application/x-protobuf") req.Header.Set("Accept", "application/x-protobuf") req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) // Execute request against the host. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() // Read body and unmarshal response. body, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, errors.Wrap(err, "reading") } qresp := &pilosa.QueryResponse{} if err := c.serializer.Unmarshal(body, qresp); err != nil { return nil, fmt.Errorf("unmarshal response: %s", err) } else if qresp.Err != nil { return nil, qresp.Err } return qresp, nil }
go
func (c *InternalClient) QueryNode(ctx context.Context, uri *pilosa.URI, index string, queryRequest *pilosa.QueryRequest) (*pilosa.QueryResponse, error) { span, ctx := tracing.StartSpanFromContext(ctx, "QueryNode") defer span.Finish() if index == "" { return nil, pilosa.ErrIndexRequired } else if queryRequest.Query == "" { return nil, pilosa.ErrQueryRequired } buf, err := c.serializer.Marshal(queryRequest) if err != nil { return nil, errors.Wrap(err, "marshaling queryRequest") } // Create HTTP request. u := uri.Path(fmt.Sprintf("/index/%s/query", index)) req, err := http.NewRequest("POST", u, bytes.NewReader(buf)) if err != nil { return nil, errors.Wrap(err, "creating request") } req.Header.Set("Content-Length", strconv.Itoa(len(buf))) req.Header.Set("Content-Type", "application/x-protobuf") req.Header.Set("Accept", "application/x-protobuf") req.Header.Set("User-Agent", "pilosa/"+pilosa.Version) // Execute request against the host. resp, err := c.executeRequest(req.WithContext(ctx)) if err != nil { return nil, err } defer resp.Body.Close() // Read body and unmarshal response. body, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, errors.Wrap(err, "reading") } qresp := &pilosa.QueryResponse{} if err := c.serializer.Unmarshal(body, qresp); err != nil { return nil, fmt.Errorf("unmarshal response: %s", err) } else if qresp.Err != nil { return nil, qresp.Err } return qresp, nil }
[ "func", "(", "c", "*", "InternalClient", ")", "QueryNode", "(", "ctx", "context", ".", "Context", ",", "uri", "*", "pilosa", ".", "URI", ",", "index", "string", ",", "queryRequest", "*", "pilosa", ".", "QueryRequest", ")", "(", "*", "pilosa", ".", "QueryResponse", ",", "error", ")", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "if", "index", "==", "\"", "\"", "{", "return", "nil", ",", "pilosa", ".", "ErrIndexRequired", "\n", "}", "else", "if", "queryRequest", ".", "Query", "==", "\"", "\"", "{", "return", "nil", ",", "pilosa", ".", "ErrQueryRequired", "\n", "}", "\n\n", "buf", ",", "err", ":=", "c", ".", "serializer", ".", "Marshal", "(", "queryRequest", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Create HTTP request.", "u", ":=", "uri", ".", "Path", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "index", ")", ")", "\n", "req", ",", "err", ":=", "http", ".", "NewRequest", "(", "\"", "\"", ",", "u", ",", "bytes", ".", "NewReader", "(", "buf", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "len", "(", "buf", ")", ")", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", ")", "\n", "req", ".", "Header", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", "+", "pilosa", ".", "Version", ")", "\n\n", "// Execute request against the host.", "resp", ",", "err", ":=", "c", ".", "executeRequest", "(", "req", ".", "WithContext", "(", "ctx", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "resp", ".", "Body", ".", "Close", "(", ")", "\n\n", "// Read body and unmarshal response.", "body", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "resp", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n\n", "qresp", ":=", "&", "pilosa", ".", "QueryResponse", "{", "}", "\n", "if", "err", ":=", "c", ".", "serializer", ".", "Unmarshal", "(", "body", ",", "qresp", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "else", "if", "qresp", ".", "Err", "!=", "nil", "{", "return", "nil", ",", "qresp", ".", "Err", "\n", "}", "\n\n", "return", "qresp", ",", "nil", "\n", "}" ]
// QueryNode executes query against the index, sending the request to the node specified.
[ "QueryNode", "executes", "query", "against", "the", "index", "sending", "the", "request", "to", "the", "node", "specified", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L268-L316
train
pilosa/pilosa
http/client.go
Import
func (c *InternalClient) Import(ctx context.Context, index, field string, shard uint64, bits []pilosa.Bit, opts ...pilosa.ImportOption) error { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.Import") defer span.Finish() if index == "" { return pilosa.ErrIndexRequired } else if field == "" { return pilosa.ErrFieldRequired } // Set up import options. options := &pilosa.ImportOptions{} for _, opt := range opts { err := opt(options) if err != nil { return errors.Wrap(err, "applying option") } } buf, err := c.marshalImportPayload(index, field, shard, bits) if err != nil { return fmt.Errorf("Error Creating Payload: %s", err) } // Retrieve a list of nodes that own the shard. nodes, err := c.FragmentNodes(ctx, index, shard) if err != nil { return fmt.Errorf("shard nodes: %s", err) } // Import to each node. for _, node := range nodes { if err := c.importNode(ctx, node, index, field, buf, options); err != nil { return fmt.Errorf("import node: host=%s, err=%s", node.URI, err) } } return nil }
go
func (c *InternalClient) Import(ctx context.Context, index, field string, shard uint64, bits []pilosa.Bit, opts ...pilosa.ImportOption) error { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.Import") defer span.Finish() if index == "" { return pilosa.ErrIndexRequired } else if field == "" { return pilosa.ErrFieldRequired } // Set up import options. options := &pilosa.ImportOptions{} for _, opt := range opts { err := opt(options) if err != nil { return errors.Wrap(err, "applying option") } } buf, err := c.marshalImportPayload(index, field, shard, bits) if err != nil { return fmt.Errorf("Error Creating Payload: %s", err) } // Retrieve a list of nodes that own the shard. nodes, err := c.FragmentNodes(ctx, index, shard) if err != nil { return fmt.Errorf("shard nodes: %s", err) } // Import to each node. for _, node := range nodes { if err := c.importNode(ctx, node, index, field, buf, options); err != nil { return fmt.Errorf("import node: host=%s, err=%s", node.URI, err) } } return nil }
[ "func", "(", "c", "*", "InternalClient", ")", "Import", "(", "ctx", "context", ".", "Context", ",", "index", ",", "field", "string", ",", "shard", "uint64", ",", "bits", "[", "]", "pilosa", ".", "Bit", ",", "opts", "...", "pilosa", ".", "ImportOption", ")", "error", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "if", "index", "==", "\"", "\"", "{", "return", "pilosa", ".", "ErrIndexRequired", "\n", "}", "else", "if", "field", "==", "\"", "\"", "{", "return", "pilosa", ".", "ErrFieldRequired", "\n", "}", "\n\n", "// Set up import options.", "options", ":=", "&", "pilosa", ".", "ImportOptions", "{", "}", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "err", ":=", "opt", "(", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "buf", ",", "err", ":=", "c", ".", "marshalImportPayload", "(", "index", ",", "field", ",", "shard", ",", "bits", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Retrieve a list of nodes that own the shard.", "nodes", ",", "err", ":=", "c", ".", "FragmentNodes", "(", "ctx", ",", "index", ",", "shard", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Import to each node.", "for", "_", ",", "node", ":=", "range", "nodes", "{", "if", "err", ":=", "c", ".", "importNode", "(", "ctx", ",", "node", ",", "index", ",", "field", ",", "buf", ",", "options", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "node", ".", "URI", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// Import bulk imports bits for a single shard to a host.
[ "Import", "bulk", "imports", "bits", "for", "a", "single", "shard", "to", "a", "host", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L319-L357
train
pilosa/pilosa
http/client.go
ImportK
func (c *InternalClient) ImportK(ctx context.Context, index, field string, bits []pilosa.Bit, opts ...pilosa.ImportOption) error { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.ImportK") defer span.Finish() if index == "" { return pilosa.ErrIndexRequired } else if field == "" { return pilosa.ErrFieldRequired } // Set up import options. options := &pilosa.ImportOptions{} for _, opt := range opts { err := opt(options) if err != nil { return errors.Wrap(err, "applying option") } } buf, err := c.marshalImportPayload(index, field, 0, bits) if err != nil { return fmt.Errorf("Error Creating Payload: %s", err) } // Get the coordinator node; all bits are sent to the // primary translate store (i.e. coordinator). nodes, err := c.Nodes(ctx) if err != nil { return fmt.Errorf("getting nodes: %s", err) } coord := getCoordinatorNode(nodes) if coord == nil { return fmt.Errorf("could not find the coordinator node") } // Import to node. if err := c.importNode(ctx, coord, index, field, buf, options); err != nil { return fmt.Errorf("import node: host=%s, err=%s", coord.URI, err) } return nil }
go
func (c *InternalClient) ImportK(ctx context.Context, index, field string, bits []pilosa.Bit, opts ...pilosa.ImportOption) error { span, ctx := tracing.StartSpanFromContext(ctx, "InternalClient.ImportK") defer span.Finish() if index == "" { return pilosa.ErrIndexRequired } else if field == "" { return pilosa.ErrFieldRequired } // Set up import options. options := &pilosa.ImportOptions{} for _, opt := range opts { err := opt(options) if err != nil { return errors.Wrap(err, "applying option") } } buf, err := c.marshalImportPayload(index, field, 0, bits) if err != nil { return fmt.Errorf("Error Creating Payload: %s", err) } // Get the coordinator node; all bits are sent to the // primary translate store (i.e. coordinator). nodes, err := c.Nodes(ctx) if err != nil { return fmt.Errorf("getting nodes: %s", err) } coord := getCoordinatorNode(nodes) if coord == nil { return fmt.Errorf("could not find the coordinator node") } // Import to node. if err := c.importNode(ctx, coord, index, field, buf, options); err != nil { return fmt.Errorf("import node: host=%s, err=%s", coord.URI, err) } return nil }
[ "func", "(", "c", "*", "InternalClient", ")", "ImportK", "(", "ctx", "context", ".", "Context", ",", "index", ",", "field", "string", ",", "bits", "[", "]", "pilosa", ".", "Bit", ",", "opts", "...", "pilosa", ".", "ImportOption", ")", "error", "{", "span", ",", "ctx", ":=", "tracing", ".", "StartSpanFromContext", "(", "ctx", ",", "\"", "\"", ")", "\n", "defer", "span", ".", "Finish", "(", ")", "\n\n", "if", "index", "==", "\"", "\"", "{", "return", "pilosa", ".", "ErrIndexRequired", "\n", "}", "else", "if", "field", "==", "\"", "\"", "{", "return", "pilosa", ".", "ErrFieldRequired", "\n", "}", "\n\n", "// Set up import options.", "options", ":=", "&", "pilosa", ".", "ImportOptions", "{", "}", "\n", "for", "_", ",", "opt", ":=", "range", "opts", "{", "err", ":=", "opt", "(", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "errors", ".", "Wrap", "(", "err", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "buf", ",", "err", ":=", "c", ".", "marshalImportPayload", "(", "index", ",", "field", ",", "0", ",", "bits", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "// Get the coordinator node; all bits are sent to the", "// primary translate store (i.e. coordinator).", "nodes", ",", "err", ":=", "c", ".", "Nodes", "(", "ctx", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "coord", ":=", "getCoordinatorNode", "(", "nodes", ")", "\n", "if", "coord", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// Import to node.", "if", "err", ":=", "c", ".", "importNode", "(", "ctx", ",", "coord", ",", "index", ",", "field", ",", "buf", ",", "options", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "coord", ".", "URI", ",", "err", ")", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ImportK bulk imports bits specified by string keys to a host.
[ "ImportK", "bulk", "imports", "bits", "specified", "by", "string", "keys", "to", "a", "host", "." ]
67d53f6b48a43f7fe090f48e35518ca8d024747c
https://github.com/pilosa/pilosa/blob/67d53f6b48a43f7fe090f48e35518ca8d024747c/http/client.go#L369-L410
train