Merge pull request #1470 from codysoyland/unexport-all

Unexport all possible items
This commit is contained in:
Cody Soyland 2018-07-05 23:18:19 -05:00 • committed by GitHub
commit 48aefd82be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
61 changed files with 1000 additions and 1000 deletions

30
api.go
View file

@ -40,10 +40,10 @@ type API struct {
Serializer Serializer
}
// APIOption is a functional option type for pilosa.API
type APIOption func(*API) error
// apiOption is a functional option type for pilosa.API
type apiOption func(*API) error
func OptAPIServer(s *Server) APIOption {
func OptAPIServer(s *Server) apiOption {
return func(a *API) error {
a.server = s
a.holder = s.holder
@ -54,7 +54,7 @@ func OptAPIServer(s *Server) APIOption {
}
// NewAPI returns a new API instance.
func NewAPI(opts ...APIOption) (*API, error) {
func NewAPI(opts ...apiOption) (*API, error) {
api := &API{}
for _, opt := range opts {
@ -90,7 +90,7 @@ func (api *API) validate(f apiMethod) error {
if _, ok := validAPIMethods[state][f]; ok {
return nil
}
return NewApiMethodNotAllowedError(errors.Errorf("api method %s not allowed in state %s", f, state))
return newApiMethodNotAllowedError(errors.Errorf("api method %s not allowed in state %s", f, state))
}
// Query parses a PQL query out of the request and executes it.
@ -205,7 +205,7 @@ func (api *API) Index(ctx context.Context, indexName string) (*Index, error) {
index := api.holder.Index(indexName)
if index == nil {
return nil, NewNotFoundError(ErrIndexNotFound)
return nil, newNotFoundError(ErrIndexNotFound)
}
return index, nil
}
@ -255,7 +255,7 @@ func (api *API) CreateField(ctx context.Context, indexName string, fieldName str
// Find index.
index := api.holder.Index(indexName)
if index == nil {
return nil, NewNotFoundError(ErrIndexNotFound)
return nil, newNotFoundError(ErrIndexNotFound)
}
// Create field.
@ -287,7 +287,7 @@ func (api *API) Field(ctx context.Context, indexName, fieldName string) (*Field,
field := api.holder.Field(indexName, fieldName)
if field == nil {
return nil, NewNotFoundError(ErrFieldNotFound)
return nil, newNotFoundError(ErrFieldNotFound)
}
return field, nil
}
@ -303,7 +303,7 @@ func (api *API) DeleteField(ctx context.Context, indexName string, fieldName str
// Find index.
index := api.holder.Index(indexName)
if index == nil {
return NewNotFoundError(ErrIndexNotFound)
return newNotFoundError(ErrIndexNotFound)
}
// Delete field from the index.
@ -446,7 +446,7 @@ func (api *API) RecalculateCaches(ctx context.Context) error {
if err != nil {
return errors.Wrap(err, "broacasting message")
}
api.holder.RecalculateCaches()
api.holder.recalculateCaches()
return nil
}
@ -543,7 +543,7 @@ func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []At
// Retrieve index from holder.
index := api.holder.Index(indexName)
if index == nil {
return nil, NewNotFoundError(ErrIndexNotFound)
return nil, newNotFoundError(ErrIndexNotFound)
}
// Retrieve local blocks.
@ -554,7 +554,7 @@ func (api *API) IndexAttrDiff(ctx context.Context, indexName string, blocks []At
// Read all attributes from all mismatched blocks.
attrs := make(map[uint64]map[string]interface{})
for _, blockID := range AttrBlocks(localBlocks).Diff(blocks) {
for _, blockID := range attrBlocks(localBlocks).Diff(blocks) {
// Retrieve block data.
m, err := index.ColumnAttrStore().BlockData(blockID)
if err != nil {
@ -588,7 +588,7 @@ func (api *API) FieldAttrDiff(ctx context.Context, indexName string, fieldName s
// Read all attributes from all mismatched blocks.
attrs := make(map[uint64]map[string]interface{})
for _, blockID := range AttrBlocks(localBlocks).Diff(blocks) {
for _, blockID := range attrBlocks(localBlocks).Diff(blocks) {
// Retrieve block data.
m, err := f.RowAttrStore().BlockData(blockID)
if err != nil {
@ -643,7 +643,7 @@ func (api *API) ImportValue(ctx context.Context, req *ImportValueRequest) error
return errors.Wrap(err, "getting field")
}
// Import into fragment.
err = field.ImportValue(req.ColumnIDs, req.Values)
err = field.importValue(req.ColumnIDs, req.Values)
if err != nil {
api.server.logger.Printf("import error: index=%s, field=%s, shard=%d, columns=%d, err=%s", req.Index, req.Field, req.Shard, len(req.ColumnIDs), err)
}
@ -685,7 +685,7 @@ func (api *API) indexField(indexName string, fieldName string, shard uint64) (*I
index := api.holder.Index(indexName)
if index == nil {
api.server.logger.Printf("fragment error: index=%s, field=%s, shard=%d, err=%s", indexName, fieldName, shard, ErrIndexNotFound.Error())
return nil, nil, NewNotFoundError(ErrIndexNotFound)
return nil, nil, newNotFoundError(ErrIndexNotFound)
}
// Retrieve field.

View file

@ -82,12 +82,12 @@ type AttrBlock struct {
Checksum []byte `json:"checksum"`
}
// AttrBlocks represents a list of blocks.
type AttrBlocks []AttrBlock
// attrBlocks represents a list of blocks.
type attrBlocks []AttrBlock
// Diff returns a list of block ids that are different or are new in other.
// Block lists must be in sorted order.
func (a AttrBlocks) Diff(other []AttrBlock) []uint64 {
func (a attrBlocks) Diff(other []AttrBlock) []uint64 {
var ids []uint64
for {
// Read next block from each list.

View file

@ -30,17 +30,17 @@ import (
"github.com/pkg/errors"
)
// AttrBlockSize is the size of attribute blocks for anti-entropy.
const AttrBlockSize = 100
// attrBlockSize is the size of attribute blocks for anti-entropy.
const attrBlockSize = 100
// AttrCache represents a cache for attributes.
type AttrCache struct {
// attrCache represents a cache for attributes.
type attrCache struct {
mu sync.RWMutex
attrs map[uint64]map[string]interface{}
}
// Get returns the cached attributes for a given id.
func (c *AttrCache) Get(id uint64) map[string]interface{} {
func (c *attrCache) Get(id uint64) map[string]interface{} {
c.mu.RLock()
defer c.mu.RUnlock()
attrs := c.attrs[id]
@ -57,40 +57,40 @@ func (c *AttrCache) Get(id uint64) map[string]interface{} {
}
// Set updates the cached attributes for a given id.
func (c *AttrCache) Set(id uint64, attrs map[string]interface{}) {
func (c *attrCache) Set(id uint64, attrs map[string]interface{}) {
c.mu.Lock()
defer c.mu.Unlock()
c.attrs[id] = attrs
}
// AttrStore represents a storage layer for attributes.
type AttrStore struct {
// attrStore represents a storage layer for attributes.
type attrStore struct {
mu sync.RWMutex
path string
db *bolt.DB
attrCache *AttrCache
attrCache *attrCache
}
// NewAttrCache returns a new instance of AttrCache.
func NewAttrCache() *AttrCache {
return &AttrCache{
// newAttrCache returns a new instance of AttrCache.
func newAttrCache() *attrCache {
return &attrCache{
attrs: make(map[uint64]map[string]interface{}),
}
}
// NewAttrStore returns a new instance of AttrStore.
func NewAttrStore(path string) pilosa.AttrStore {
return &AttrStore{
return &attrStore{
path: path,
attrCache: NewAttrCache(),
attrCache: newAttrCache(),
}
}
// Path returns path to the store's data file.
func (s *AttrStore) Path() string { return s.path }
func (s *attrStore) Path() string { return s.path }
// Open opens and initializes the store.
func (s *AttrStore) Open() error {
func (s *attrStore) Open() error {
// Open storage.
db, err := bolt.Open(s.path, 0666, &bolt.Options{Timeout: 1 * time.Second})
if err != nil {
@ -112,7 +112,7 @@ func (s *AttrStore) Open() error {
}
// Close closes the store.
func (s *AttrStore) Close() error {
func (s *attrStore) Close() error {
if s.db != nil {
s.db.Close()
}
@ -120,7 +120,7 @@ func (s *AttrStore) Close() error {
}
// Attrs returns a set of attributes by ID.
func (s *AttrStore) Attrs(id uint64) (m map[string]interface{}, err error) {
func (s *attrStore) Attrs(id uint64) (m map[string]interface{}, err error) {
s.mu.RLock()
defer s.mu.RUnlock()
@ -147,7 +147,7 @@ func (s *AttrStore) Attrs(id uint64) (m map[string]interface{}, err error) {
}
// SetAttrs sets attribute values for a given ID.
func (s *AttrStore) SetAttrs(id uint64, m map[string]interface{}) error {
func (s *attrStore) SetAttrs(id uint64, m map[string]interface{}) error {
// Ignore empty maps.
if len(m) == 0 {
return nil
@ -184,7 +184,7 @@ func (s *AttrStore) SetAttrs(id uint64, m map[string]interface{}) error {
}
// SetBulkAttrs sets attribute values for a set of ids.
func (s *AttrStore) SetBulkAttrs(m map[uint64]map[string]interface{}) error {
func (s *attrStore) SetBulkAttrs(m map[uint64]map[string]interface{}) error {
s.mu.Lock()
defer s.mu.Unlock()
@ -220,7 +220,7 @@ func (s *AttrStore) SetBulkAttrs(m map[uint64]map[string]interface{}) error {
}
// Blocks returns a list of all blocks in the store.
func (s *AttrStore) Blocks() ([]pilosa.AttrBlock, error) {
func (s *attrStore) Blocks() ([]pilosa.AttrBlock, error) {
tx, err := s.db.Begin(false)
if err != nil {
return nil, errors.Wrap(err, "starting transaction")
@ -228,7 +228,7 @@ func (s *AttrStore) Blocks() ([]pilosa.AttrBlock, error) {
defer tx.Rollback()
// Wrap cursor to segment by block.
cur := newBlockCursor(tx.Bucket([]byte("attrs")).Cursor(), AttrBlockSize)
cur := newBlockCursor(tx.Bucket([]byte("attrs")).Cursor(), attrBlockSize)
// Iterate over each block.
var blocks []pilosa.AttrBlock
@ -251,7 +251,7 @@ func (s *AttrStore) Blocks() ([]pilosa.AttrBlock, error) {
}
// BlockData returns all data for a single block.
func (s *AttrStore) BlockData(i uint64) (map[uint64]map[string]interface{}, error) {
func (s *attrStore) BlockData(i uint64) (map[uint64]map[string]interface{}, error) {
m := make(map[uint64]map[string]interface{})
// Start read-only transaction.
@ -262,8 +262,8 @@ func (s *AttrStore) BlockData(i uint64) (map[uint64]map[string]interface{}, erro
defer tx.Rollback()
// Move to the start of the block.
min := u64tob(uint64(i) * AttrBlockSize)
max := u64tob(uint64(i+1) * AttrBlockSize)
min := u64tob(uint64(i) * attrBlockSize)
max := u64tob(uint64(i+1) * attrBlockSize)
cur := tx.Bucket([]byte("attrs")).Cursor()
for k, v := cur.Seek(min); k != nil; k, v = cur.Next() {
// Exit if we're past the end of the block.

View file

@ -56,78 +56,78 @@ type InternalQueryClient interface {
QueryNode(ctx context.Context, uri *URI, index string, queryRequest *QueryRequest) (*QueryResponse, error)
}
type NopInternalQueryClient struct{}
type nopInternalQueryClient struct{}
func (n *NopInternalQueryClient) QueryNode(ctx context.Context, uri *URI, index string, queryRequest *QueryRequest) (*QueryResponse, error) {
func (n *nopInternalQueryClient) QueryNode(ctx context.Context, uri *URI, index string, queryRequest *QueryRequest) (*QueryResponse, error) {
return nil, nil
}
func NewNopInternalQueryClient() *NopInternalQueryClient {
return &NopInternalQueryClient{}
func newNopInternalQueryClient() *nopInternalQueryClient {
return &nopInternalQueryClient{}
}
var _ InternalQueryClient = NewNopInternalQueryClient()
var _ InternalQueryClient = newNopInternalQueryClient()
//===============
type NopInternalClient struct{}
type nopInternalClient struct{}
func NewNopInternalClient() NopInternalClient {
return NopInternalClient{}
func newNopInternalClient() nopInternalClient {
return nopInternalClient{}
}
var _ InternalClient = NewNopInternalClient()
var _ InternalClient = newNopInternalClient()
func (n NopInternalClient) MaxShardByIndex(context.Context) (map[string]uint64, error) {
func (n nopInternalClient) MaxShardByIndex(context.Context) (map[string]uint64, error) {
return nil, nil
}
func (n NopInternalClient) Schema(ctx context.Context) ([]*IndexInfo, error) { return nil, nil }
func (n NopInternalClient) CreateIndex(ctx context.Context, index string, opt IndexOptions) error {
func (n nopInternalClient) Schema(ctx context.Context) ([]*IndexInfo, error) { return nil, nil }
func (n nopInternalClient) CreateIndex(ctx context.Context, index string, opt IndexOptions) error {
return nil
}
func (n NopInternalClient) FragmentNodes(ctx context.Context, index string, shard uint64) ([]*Node, error) {
func (n nopInternalClient) FragmentNodes(ctx context.Context, index string, shard uint64) ([]*Node, error) {
return nil, nil
}
func (n NopInternalClient) Query(ctx context.Context, index string, queryRequest *QueryRequest) (*QueryResponse, error) {
func (n nopInternalClient) Query(ctx context.Context, index string, queryRequest *QueryRequest) (*QueryResponse, error) {
return nil, nil
}
func (n NopInternalClient) QueryNode(ctx context.Context, uri *URI, index string, queryRequest *QueryRequest) (*QueryResponse, error) {
func (n nopInternalClient) QueryNode(ctx context.Context, uri *URI, index string, queryRequest *QueryRequest) (*QueryResponse, error) {
return nil, nil
}
func (n NopInternalClient) Import(ctx context.Context, index, field string, shard uint64, bits []Bit) error {
func (n nopInternalClient) Import(ctx context.Context, index, field string, shard uint64, bits []Bit) error {
return nil
}
func (n NopInternalClient) ImportK(ctx context.Context, index, field string, bits []Bit) error {
func (n nopInternalClient) ImportK(ctx context.Context, index, field string, bits []Bit) error {
return nil
}
func (n NopInternalClient) EnsureIndex(ctx context.Context, name string, options IndexOptions) error {
func (n nopInternalClient) EnsureIndex(ctx context.Context, name string, options IndexOptions) error {
return nil
}
func (n NopInternalClient) EnsureField(ctx context.Context, indexName string, fieldName string) error {
func (n nopInternalClient) EnsureField(ctx context.Context, indexName string, fieldName string) error {
return nil
}
func (n NopInternalClient) ImportValue(ctx context.Context, index, field string, shard uint64, vals []FieldValue) error {
func (n nopInternalClient) ImportValue(ctx context.Context, index, field string, shard uint64, vals []FieldValue) error {
return nil
}
func (n NopInternalClient) ExportCSV(ctx context.Context, index, field string, shard uint64, w io.Writer) error {
func (n nopInternalClient) ExportCSV(ctx context.Context, index, field string, shard uint64, w io.Writer) error {
return nil
}
func (n NopInternalClient) CreateField(ctx context.Context, index, field string) error { return nil }
func (n NopInternalClient) FragmentBlocks(ctx context.Context, uri *URI, index, field string, shard uint64) ([]FragmentBlock, error) {
func (n nopInternalClient) CreateField(ctx context.Context, index, field string) error { return nil }
func (n nopInternalClient) FragmentBlocks(ctx context.Context, uri *URI, index, field string, shard uint64) ([]FragmentBlock, error) {
return nil, nil
}
func (n NopInternalClient) BlockData(ctx context.Context, uri *URI, index, field string, shard uint64, block int) ([]uint64, []uint64, error) {
func (n nopInternalClient) BlockData(ctx context.Context, uri *URI, index, field string, shard uint64, block int) ([]uint64, []uint64, error) {
return nil, nil, nil
}
func (n NopInternalClient) ColumnAttrDiff(ctx context.Context, uri *URI, index string, blks []AttrBlock) (map[uint64]map[string]interface{}, error) {
func (n nopInternalClient) ColumnAttrDiff(ctx context.Context, uri *URI, index string, blks []AttrBlock) (map[uint64]map[string]interface{}, error) {
return nil, nil
}
func (n NopInternalClient) RowAttrDiff(ctx context.Context, uri *URI, index, field string, blks []AttrBlock) (map[uint64]map[string]interface{}, error) {
func (n nopInternalClient) RowAttrDiff(ctx context.Context, uri *URI, index, field string, blks []AttrBlock) (map[uint64]map[string]interface{}, error) {
return nil, nil
}
func (n NopInternalClient) SendMessage(ctx context.Context, uri *URI, msg []byte) error {
func (n nopInternalClient) SendMessage(ctx context.Context, uri *URI, msg []byte) error {
return nil
}
func (n NopInternalClient) RetrieveShardFromURI(ctx context.Context, index, field string, shard uint64, uri URI) (io.ReadCloser, error) {
func (n nopInternalClient) RetrieveShardFromURI(ctx context.Context, index, field string, shard uint64, uri URI) (io.ReadCloser, error) {
return nil, nil
}

View file

@ -36,8 +36,8 @@ import (
)
const (
// DefaultPartitionN is the default number of partitions in a cluster.
DefaultPartitionN = 256
// defaultPartitionN is the default number of partitions in a cluster.
defaultPartitionN = 256
// ClusterState represents the state returned in the /status endpoint.
ClusterStateStarting = "STARTING"
@ -45,7 +45,7 @@ const (
ClusterStateResizing = "RESIZING"
// NodeState represents the state of a node during startup.
NodeStateReady = "READY"
nodeStateReady = "READY"
// resizeJob states.
resizeJobStateRunning = "RUNNING"
@ -219,7 +219,7 @@ type cluster struct {
func newCluster() *cluster {
return &cluster{
Hasher: &jmphasher{},
partitionN: DefaultPartitionN,
partitionN: defaultPartitionN,
ReplicaN: 1,
joiningLeavingNodes: make(chan nodeAction, 10), // buffered channel
@ -227,7 +227,7 @@ func newCluster() *cluster {
closing: make(chan struct{}),
joining: make(chan struct{}),
InternalClient: NewNopInternalClient(),
InternalClient: newNopInternalClient(),
logger: NopLogger,
}
@ -323,7 +323,7 @@ func (c *cluster) addNode(node *Node) error {
if c.Topology == nil {
return fmt.Errorf("Cluster.Topology is nil")
}
if !c.Topology.AddID(node.ID) {
if !c.Topology.addID(node.ID) {
return nil
}
@ -343,7 +343,7 @@ func (c *cluster) removeNode(node *Node) error {
if c.Topology == nil {
return fmt.Errorf("Cluster.Topology is nil")
}
if !c.Topology.RemoveID(node.ID) {
if !c.Topology.removeID(node.ID) {
return nil
}
@ -364,7 +364,7 @@ func (c *cluster) setID(id string) {
c.id = id
// Make sure the Topology is updated.
c.Topology.ClusterID = c.id
c.Topology.clusterID = c.id
}
func (c *cluster) State() string {
@ -818,7 +818,7 @@ func (c *cluster) setup() error {
return errors.Wrap(err, "loading topology")
}
c.id = c.Topology.ClusterID
c.id = c.Topology.clusterID
// Only the coordinator needs to consider the .topology file.
if c.isCoordinator() {
@ -888,22 +888,22 @@ func (c *cluster) markAsJoined() {
}
func (c *cluster) needTopologyAgreement() bool {
return c.State() == ClusterStateStarting && !stringSlicesAreEqual(c.Topology.NodeIDs, c.nodeIDs())
return c.State() == ClusterStateStarting && !stringSlicesAreEqual(c.Topology.nodeIDs, c.nodeIDs())
}
func (c *cluster) haveTopologyAgreement() bool {
if c.Static {
return true
}
return stringSlicesAreEqual(c.Topology.NodeIDs, c.nodeIDs())
return stringSlicesAreEqual(c.Topology.nodeIDs, c.nodeIDs())
}
func (c *cluster) allNodesReady() bool {
if c.Static {
return true
}
for _, uri := range c.Topology.NodeIDs {
if c.Topology.nodeStates[uri] != NodeStateReady {
for _, uri := range c.Topology.nodeIDs {
if c.Topology.nodeStates[uri] != nodeStateReady {
return false
}
}
@ -1375,14 +1375,14 @@ func (j *resizeJob) distributeResizeInstructions() error {
return nil
}
type NodeIDs []string
type nodeIDs []string
func (n NodeIDs) Len() int { return len(n) }
func (n NodeIDs) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
func (n NodeIDs) Less(i, j int) bool { return n[i] < n[j] }
func (n nodeIDs) Len() int { return len(n) }
func (n nodeIDs) Swap(i, j int) { n[i], n[j] = n[j], n[i] }
func (n nodeIDs) Less(i, j int) bool { return n[i] < n[j] }
// ContainsID returns true if idi matches one of the nodesets's IDs.
func (n NodeIDs) ContainsID(id string) bool {
func (n nodeIDs) ContainsID(id string) bool {
for _, nid := range n {
if nid == id {
return true
@ -1394,16 +1394,16 @@ func (n NodeIDs) ContainsID(id string) bool {
// Topology represents the list of hosts in the cluster.
type Topology struct {
mu sync.RWMutex
NodeIDs []string
nodeIDs []string
ClusterID string
clusterID string
// nodeStates holds the state of each node according to
// the coordinator. Used during startup and data load.
nodeStates map[string]string
}
func NewTopology() *Topology {
func newTopology() *Topology {
return &Topology{
nodeStates: make(map[string]string),
}
@ -1417,11 +1417,11 @@ func (t *Topology) ContainsID(id string) bool {
}
func (t *Topology) containsID(id string) bool {
return NodeIDs(t.NodeIDs).ContainsID(id)
return nodeIDs(t.nodeIDs).ContainsID(id)
}
func (t *Topology) positionByID(nodeID string) int {
for i, tid := range t.NodeIDs {
for i, tid := range t.nodeIDs {
if tid == nodeID {
return i
}
@ -1429,25 +1429,25 @@ func (t *Topology) positionByID(nodeID string) int {
return -1
}
// AddID adds the node ID to the topology and returns true if added.
func (t *Topology) AddID(nodeID string) bool {
// addID adds the node ID to the topology and returns true if added.
func (t *Topology) addID(nodeID string) bool {
t.mu.Lock()
defer t.mu.Unlock()
if t.containsID(nodeID) {
return false
}
t.NodeIDs = append(t.NodeIDs, nodeID)
t.nodeIDs = append(t.nodeIDs, nodeID)
sort.Slice(t.NodeIDs,
sort.Slice(t.nodeIDs,
func(i, j int) bool {
return t.NodeIDs[i] < t.NodeIDs[j]
return t.nodeIDs[i] < t.nodeIDs[j]
})
return true
}
// RemoveID removes the node ID from the topology and returns true if removed.
func (t *Topology) RemoveID(nodeID string) bool {
// removeID removes the node ID from the topology and returns true if removed.
func (t *Topology) removeID(nodeID string) bool {
t.mu.Lock()
defer t.mu.Unlock()
@ -1456,15 +1456,15 @@ func (t *Topology) RemoveID(nodeID string) bool {
return false
}
copy(t.NodeIDs[i:], t.NodeIDs[i+1:])
t.NodeIDs[len(t.NodeIDs)-1] = ""
t.NodeIDs = t.NodeIDs[:len(t.NodeIDs)-1]
copy(t.nodeIDs[i:], t.nodeIDs[i+1:])
t.nodeIDs[len(t.nodeIDs)-1] = ""
t.nodeIDs = t.nodeIDs[:len(t.nodeIDs)-1]
return true
}
// Encode converts t into its internal representation.
func (t *Topology) Encode() *internal.Topology {
// encode converts t into its internal representation.
func (t *Topology) encode() *internal.Topology {
return encodeTopology(t)
}
@ -1472,7 +1472,7 @@ func (t *Topology) Encode() *internal.Topology {
func (c *cluster) loadTopology() error {
buf, err := ioutil.ReadFile(filepath.Join(c.Path, ".topology"))
if os.IsNotExist(err) {
c.Topology = NewTopology()
c.Topology = newTopology()
return nil
} else if err != nil {
return errors.Wrap(err, "reading file")
@ -1511,7 +1511,7 @@ func (c *cluster) considerTopology() error {
if c.id == "" {
u := uuid.NewV4()
c.id = u.String()
c.Topology.ClusterID = c.id
c.Topology.clusterID = c.id
}
if c.Static {
@ -1519,13 +1519,13 @@ func (c *cluster) considerTopology() error {
}
// If there is no .topology file, it's safe to proceed.
if len(c.Topology.NodeIDs) == 0 {
if len(c.Topology.nodeIDs) == 0 {
return nil
}
// The local node (coordinator) must be in the .topology.
if !c.Topology.ContainsID(c.Node.ID) {
return fmt.Errorf("coordinator %s is not in topology: %v", c.Node.ID, c.Topology.NodeIDs)
return fmt.Errorf("coordinator %s is not in topology: %v", c.Node.ID, c.Topology.nodeIDs)
}
// If local node is the only thing in .topology, continue.
@ -1774,8 +1774,8 @@ func encodeTopology(topology *Topology) *internal.Topology {
return nil
}
return &internal.Topology{
ClusterID: topology.ClusterID,
NodeIDs: topology.NodeIDs,
ClusterID: topology.clusterID,
NodeIDs: topology.nodeIDs,
}
}
@ -1784,12 +1784,12 @@ func decodeTopology(topology *internal.Topology) (*Topology, error) {
return nil, nil
}
t := NewTopology()
t.ClusterID = topology.ClusterID
t.NodeIDs = topology.NodeIDs
sort.Slice(t.NodeIDs,
t := newTopology()
t.clusterID = topology.ClusterID
t.nodeIDs = topology.NodeIDs
sort.Slice(t.nodeIDs,
func(i, j int) bool {
return t.NodeIDs[i] < t.NodeIDs[j]
return t.nodeIDs[i] < t.nodeIDs[j]
})
return t, nil

View file

@ -536,12 +536,12 @@ func TestCluster_ResizeStates(t *testing.T) {
}
expectedTop := &Topology{
NodeIDs: []string{node.Node.ID},
nodeIDs: []string{node.Node.ID},
}
// Verify topology file.
if !reflect.DeepEqual(node.Topology.NodeIDs, expectedTop.NodeIDs) {
t.Errorf("expected topology: %v, but got: %v", expectedTop.NodeIDs, node.Topology.NodeIDs)
if !reflect.DeepEqual(node.Topology.nodeIDs, expectedTop.nodeIDs) {
t.Errorf("expected topology: %v, but got: %v", expectedTop.nodeIDs, node.Topology.nodeIDs)
}
// Close TestCluster.
@ -558,7 +558,7 @@ func TestCluster_ResizeStates(t *testing.T) {
// write topology to data file
top := &Topology{
NodeIDs: []string{node.Node.ID},
nodeIDs: []string{node.Node.ID},
}
tc.WriteTopology(node.Path, top)
@ -586,7 +586,7 @@ func TestCluster_ResizeStates(t *testing.T) {
// write topology to data file
top := &Topology{
NodeIDs: []string{"some-other-host"},
nodeIDs: []string{"some-other-host"},
}
tc.WriteTopology(node.Path, top)
@ -625,14 +625,14 @@ func TestCluster_ResizeStates(t *testing.T) {
}
expectedTop := &Topology{
NodeIDs: []string{node0.Node.ID, node1.Node.ID},
nodeIDs: []string{node0.Node.ID, node1.Node.ID},
}
// Verify topology file.
if !reflect.DeepEqual(node0.Topology.NodeIDs, expectedTop.NodeIDs) {
t.Errorf("expected node0 topology: %v, but got: %v", expectedTop.NodeIDs, node0.Topology.NodeIDs)
} else if !reflect.DeepEqual(node1.Topology.NodeIDs, expectedTop.NodeIDs) {
t.Errorf("expected node1 topology: %v, but got: %v", expectedTop.NodeIDs, node1.Topology.NodeIDs)
if !reflect.DeepEqual(node0.Topology.nodeIDs, expectedTop.nodeIDs) {
t.Errorf("expected node0 topology: %v, but got: %v", expectedTop.nodeIDs, node0.Topology.nodeIDs)
} else if !reflect.DeepEqual(node1.Topology.nodeIDs, expectedTop.nodeIDs) {
t.Errorf("expected node1 topology: %v, but got: %v", expectedTop.nodeIDs, node1.Topology.nodeIDs)
}
// Close TestCluster.
@ -648,7 +648,7 @@ func TestCluster_ResizeStates(t *testing.T) {
// write topology to data file
top := &Topology{
NodeIDs: []string{"node0", "node2"},
nodeIDs: []string{"node0", "node2"},
}
tc.WriteTopology(node0.Path, top)
@ -721,14 +721,14 @@ func TestCluster_ResizeStates(t *testing.T) {
}
expectedTop := &Topology{
NodeIDs: []string{node0.Node.ID, node1.Node.ID},
nodeIDs: []string{node0.Node.ID, node1.Node.ID},
}
// Verify topology file.
if !reflect.DeepEqual(node0.Topology.NodeIDs, expectedTop.NodeIDs) {
t.Errorf("expected node0 topology: %v, but got: %v", expectedTop.NodeIDs, node0.Topology.NodeIDs)
} else if !reflect.DeepEqual(node1.Topology.NodeIDs, expectedTop.NodeIDs) {
t.Errorf("expected node1 topology: %v, but got: %v", expectedTop.NodeIDs, node1.Topology.NodeIDs)
if !reflect.DeepEqual(node0.Topology.nodeIDs, expectedTop.nodeIDs) {
t.Errorf("expected node0 topology: %v, but got: %v", expectedTop.nodeIDs, node0.Topology.nodeIDs)
} else if !reflect.DeepEqual(node1.Topology.nodeIDs, expectedTop.nodeIDs) {
t.Errorf("expected node1 topology: %v, but got: %v", expectedTop.nodeIDs, node1.Topology.nodeIDs)
}
// Bits

View file

@ -25,10 +25,10 @@ import (
"github.com/pilosa/pilosa/ctl"
)
var Checker *ctl.CheckCommand
var checker *ctl.CheckCommand
func NewCheckCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
Checker = ctl.NewCheckCommand(os.Stdin, os.Stdout, os.Stderr)
func newCheckCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
checker = ctl.NewCheckCommand(os.Stdin, os.Stdout, os.Stderr)
checkCmd := &cobra.Command{
Use: "check <path> [path2]...",
Short: "Do a consistency check on a pilosa data file.",
@ -39,8 +39,8 @@ Performs a consistency check on data files.
if len(args) == 0 {
return fmt.Errorf("path required")
}
Checker.Paths = args
if err := Checker.Run(context.Background()); err != nil {
checker.Paths = args
if err := checker.Run(context.Background()); err != nil {
return err
}
return nil
@ -50,5 +50,5 @@ Performs a consistency check on data files.
}
func init() {
subcommandFns["check"] = NewCheckCommand
subcommandFns["check"] = newCheckCommand
}

View file

@ -25,10 +25,10 @@ import (
"github.com/pilosa/pilosa/server"
)
var Conf *ctl.ConfigCommand
var conf *ctl.ConfigCommand
func NewConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
Conf = ctl.NewConfigCommand(os.Stdin, os.Stdout, os.Stderr)
func newConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
conf = ctl.NewConfigCommand(os.Stdin, os.Stdout, os.Stderr)
Server := server.NewCommand(stdin, stdout, stderr)
confCmd := &cobra.Command{
Use: "config",
@ -36,8 +36,8 @@ func NewConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command
Long: `config prints the current configuration to stdout`,
RunE: func(cmd *cobra.Command, args []string) error {
Conf.Config = Server.Config
if err := Conf.Run(context.Background()); err != nil {
conf.Config = Server.Config
if err := conf.Run(context.Background()); err != nil {
return err
}
return nil
@ -51,5 +51,5 @@ func NewConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command
}
func init() {
subcommandFns["config"] = NewConfigCommand
subcommandFns["config"] = newConfigCommand
}

View file

@ -26,7 +26,7 @@ import (
var Exporter *ctl.ExportCommand
func NewExportCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
func newExportCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
Exporter = ctl.NewExportCommand(os.Stdin, os.Stdout, os.Stderr)
exportCmd := &cobra.Command{
Use: "export",
@ -60,5 +60,5 @@ The file does not contain any headers.
}
func init() {
subcommandFns["export"] = NewExportCommand
subcommandFns["export"] = newExportCommand
}

View file

@ -24,17 +24,17 @@ import (
"github.com/pilosa/pilosa/ctl"
)
var GenerateConf *ctl.GenerateConfigCommand
var generateConf *ctl.GenerateConfigCommand
func NewGenerateConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
GenerateConf = ctl.NewGenerateConfigCommand(os.Stdin, os.Stdout, os.Stderr)
func newGenerateConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
generateConf = ctl.NewGenerateConfigCommand(os.Stdin, os.Stdout, os.Stderr)
confCmd := &cobra.Command{
Use: "generate-config",
Short: "Print the default configuration.",
Long: `generate-config prints the default configuration to stdout
`,
RunE: func(cmd *cobra.Command, args []string) error {
if err := GenerateConf.Run(context.Background()); err != nil {
if err := generateConf.Run(context.Background()); err != nil {
return err
}
return nil
@ -45,5 +45,5 @@ func NewGenerateConfigCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.
}
func init() {
subcommandFns["generate-config"] = NewGenerateConfigCommand
subcommandFns["generate-config"] = newGenerateConfigCommand
}

View file

@ -25,8 +25,8 @@ import (
var Importer *ctl.ImportCommand
// NewImportCommand runs the Pilosa import subcommand for ingesting bulk data.
func NewImportCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
// newImportCommand runs the Pilosa import subcommand for ingesting bulk data.
func newImportCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
Importer = ctl.NewImportCommand(stdin, stdout, stderr)
importCmd := &cobra.Command{
Use: "import",
@ -67,5 +67,5 @@ omitted. If it is present then its format should be YYYY-MM-DDTHH:MM.
}
func init() {
subcommandFns["import"] = NewImportCommand
subcommandFns["import"] = newImportCommand
}

View file

@ -25,10 +25,10 @@ import (
"github.com/pilosa/pilosa/ctl"
)
var Inspector *ctl.InspectCommand
var inspector *ctl.InspectCommand
func NewInspectCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
Inspector = ctl.NewInspectCommand(os.Stdin, os.Stdout, os.Stderr)
func newInspectCommand(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
inspector = ctl.NewInspectCommand(os.Stdin, os.Stdout, os.Stderr)
inspectCmd := &cobra.Command{
Use: "inspect",
@ -42,8 +42,8 @@ Inspects a data file and provides stats.
} else if len(args) > 1 {
return fmt.Errorf("only one path allowed")
}
Inspector.Path = args[0]
if err := Inspector.Run(context.Background()); err != nil {
inspector.Path = args[0]
if err := inspector.Run(context.Background()); err != nil {
return err
}
return nil
@ -53,5 +53,5 @@ Inspects a data file and provides stats.
}
func init() {
subcommandFns["inspect"] = NewInspectCommand
subcommandFns["inspect"] = newInspectCommand
}

View file

@ -27,8 +27,8 @@ import (
// Server is global so that tests can control and verify it.
var Server *server.Command
// NewServeCmd creates a pilosa server and runs it with command line flags.
func NewServeCmd(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
// newServeCmd creates a pilosa server and runs it with command line flags.
func newServeCmd(stdin io.Reader, stdout, stderr io.Writer) *cobra.Command {
Server = server.NewCommand(stdin, stdout, stderr)
serveCmd := &cobra.Command{
Use: "server",
@ -52,5 +52,5 @@ on the configured port.`,
}
func init() {
subcommandFns["server"] = NewServeCmd
subcommandFns["server"] = newServeCmd
}

View file

@ -36,8 +36,8 @@ func SetTLSConfig(flags *pflag.FlagSet, certificatePath *string, certificateKeyP
flags.BoolVarP(skipVerify, "tls.skip-verify", "", false, "Skip TLS certificate verification (not secure)")
}
// CommandClient returns a pilosa.InternalHTTPClient for the command
func CommandClient(cmd CommandWithTLSSupport) (*http.InternalClient, error) {
// commandClient returns a pilosa.InternalHTTPClient for the command
func commandClient(cmd CommandWithTLSSupport) (*http.InternalClient, error) {
tlsConfig := cmd.TLSConfiguration()
var TLSConfig *tls.Config
if tlsConfig.CertificatePath != "" && tlsConfig.CertificateKeyPath != "" {

View file

@ -75,7 +75,7 @@ func (cmd *ExportCommand) Run(ctx context.Context) error {
}
// Create a client to the server.
client, err := CommandClient(cmd)
client, err := commandClient(cmd)
if err != nil {
return errors.Wrap(err, "creating client")
}

View file

@ -41,7 +41,7 @@ type ImportCommand struct {
Field string `json:"field"`
// Options for index & field to be created if they don't exist
IndexOptions pilosa.IndexOptions
indexOptions pilosa.IndexOptions
// CreateSchema ensures the schema exists before import
CreateSchema bool
@ -59,7 +59,7 @@ type ImportCommand struct {
Sort bool `json:"sort"`
// Reusable client.
Client pilosa.InternalClient `json:"-"`
client pilosa.InternalClient `json:"-"`
// Standard input/output
*pilosa.CmdIO
@ -89,11 +89,11 @@ func (cmd *ImportCommand) Run(ctx context.Context) error {
return errors.New("path required")
}
// Create a client to the server.
client, err := CommandClient(cmd)
client, err := commandClient(cmd)
if err != nil {
return errors.Wrap(err, "creating client")
}
cmd.Client = client
cmd.client = client
if cmd.CreateSchema {
err := cmd.ensureSchema(ctx)
@ -104,7 +104,7 @@ func (cmd *ImportCommand) Run(ctx context.Context) error {
// Determine the field type in order to correctly handle the input data.
fieldType := pilosa.DefaultFieldType
schema, err := cmd.Client.Schema(ctx)
schema, err := cmd.client.Schema(ctx)
if err != nil {
return errors.Wrap(err, "getting schema")
}
@ -130,11 +130,11 @@ func (cmd *ImportCommand) Run(ctx context.Context) error {
}
func (cmd *ImportCommand) ensureSchema(ctx context.Context) error {
err := cmd.Client.EnsureIndex(ctx, cmd.Index, cmd.IndexOptions)
err := cmd.client.EnsureIndex(ctx, cmd.Index, cmd.indexOptions)
if err != nil {
return fmt.Errorf("Error Creating Index: %s", err)
}
err = cmd.Client.EnsureField(ctx, cmd.Index, cmd.Field)
err = cmd.client.EnsureField(ctx, cmd.Index, cmd.Field)
if err != nil {
return fmt.Errorf("Error Creating Field: %s", err)
}
@ -254,7 +254,7 @@ func (cmd *ImportCommand) importBits(ctx context.Context, bits []pilosa.Bit) err
}
logger.Printf("importing shard: %d, n=%d", shard, len(chunk))
if err := cmd.Client.Import(ctx, cmd.Index, cmd.Field, shard, chunk); err != nil {
if err := cmd.client.Import(ctx, cmd.Index, cmd.Field, shard, chunk); err != nil {
return errors.Wrap(err, "importing")
}
}
@ -351,7 +351,7 @@ func (cmd *ImportCommand) importBitsK(ctx context.Context, bits []pilosa.Bit) er
// TODO: does it help to sort the rowKeys?
logger.Printf("importing keys: n=%d", len(bits))
if err := cmd.Client.ImportK(ctx, cmd.Index, cmd.Field, bits); err != nil {
if err := cmd.client.ImportK(ctx, cmd.Index, cmd.Field, bits); err != nil {
return errors.Wrap(err, "importing keys")
}
@ -448,7 +448,7 @@ func (cmd *ImportCommand) importValues(ctx context.Context, vals []pilosa.FieldV
}
logger.Printf("importing shard: %d, n=%d", shard, len(vals))
if err := cmd.Client.ImportValue(ctx, cmd.Index, cmd.Field, shard, vals); err != nil {
if err := cmd.client.ImportValue(ctx, cmd.Index, cmd.Field, shard, vals); err != nil {
return errors.Wrap(err, "importing values")
}
}

View file

@ -37,8 +37,8 @@ type versionResponse struct {
Message string `json:"message"`
}
// DiagnosticsCollector represents a collector/sender of diagnostics data.
type DiagnosticsCollector struct {
// diagnosticsCollector represents a collector/sender of diagnostics data.
type diagnosticsCollector struct {
mu sync.Mutex
host string
VersionURL string
@ -56,9 +56,9 @@ type DiagnosticsCollector struct {
server *Server
}
// NewDiagnosticsCollector returns a new DiagnosticsCollector given an addr in the format "hostname:port".
func NewDiagnosticsCollector(host string) *DiagnosticsCollector {
return &DiagnosticsCollector{
// newDiagnosticsCollector returns a new DiagnosticsCollector given an addr in the format "hostname:port".
func newDiagnosticsCollector(host string) *diagnosticsCollector {
return &diagnosticsCollector{
host: host,
VersionURL: defaultVersionCheckURL,
startTime: time.Now().Unix(),
@ -70,13 +70,13 @@ func NewDiagnosticsCollector(host string) *DiagnosticsCollector {
}
// SetVersion of locally running Pilosa Cluster to check against master.
func (d *DiagnosticsCollector) SetVersion(v string) {
func (d *diagnosticsCollector) SetVersion(v string) {
d.version = v
d.Set("Version", v)
}
// Flush sends the current metrics.
func (d *DiagnosticsCollector) Flush() error {
func (d *diagnosticsCollector) Flush() error {
d.mu.Lock()
defer d.mu.Unlock()
d.metrics["Uptime"] = (time.Now().Unix() - d.startTime)
@ -99,7 +99,7 @@ func (d *DiagnosticsCollector) Flush() error {
}
// CheckVersion of the local build against Pilosa master.
func (d *DiagnosticsCollector) CheckVersion() error {
func (d *diagnosticsCollector) CheckVersion() error {
var rsp versionResponse
req, err := http.NewRequest("GET", d.VersionURL, nil)
if err != nil {
@ -131,7 +131,7 @@ func (d *DiagnosticsCollector) CheckVersion() error {
}
// compareVersion check version strings.
func (d *DiagnosticsCollector) compareVersion(value string) error {
func (d *diagnosticsCollector) compareVersion(value string) error {
currentVersion := versionSegments(value)
localVersion := versionSegments(d.version)
@ -147,12 +147,12 @@ func (d *DiagnosticsCollector) compareVersion(value string) error {
}
// Encode metrics maps into the json message format.
func (d *DiagnosticsCollector) encode() ([]byte, error) {
func (d *diagnosticsCollector) encode() ([]byte, error) {
return json.Marshal(d.metrics)
}
// Set adds a key value metric.
func (d *DiagnosticsCollector) Set(name string, value interface{}) {
func (d *diagnosticsCollector) Set(name string, value interface{}) {
switch v := value.(type) {
case string:
if v == "" {
@ -166,7 +166,7 @@ func (d *DiagnosticsCollector) Set(name string, value interface{}) {
}
// logErr logs the error and returns true if an error exists
func (d *DiagnosticsCollector) logErr(err error) bool {
func (d *diagnosticsCollector) logErr(err error) bool {
if err != nil {
d.Logger.Printf("%v", err)
return true
@ -175,7 +175,7 @@ func (d *DiagnosticsCollector) logErr(err error) bool {
}
// EnrichWithOSInfo adds OS information to the diagnostics payload.
func (d *DiagnosticsCollector) EnrichWithOSInfo() {
func (d *diagnosticsCollector) EnrichWithOSInfo() {
uptime, err := d.server.systemInfo.Uptime()
if !d.logErr(err) {
d.Set("HostUptime", uptime)
@ -199,7 +199,7 @@ func (d *DiagnosticsCollector) EnrichWithOSInfo() {
}
// EnrichWithMemoryInfo adds memory information to the diagnostics payload.
func (d *DiagnosticsCollector) EnrichWithMemoryInfo() {
func (d *diagnosticsCollector) EnrichWithMemoryInfo() {
memFree, err := d.server.systemInfo.MemFree()
if !d.logErr(err) {
d.Set("MemFree", memFree)
@ -215,7 +215,7 @@ func (d *DiagnosticsCollector) EnrichWithMemoryInfo() {
}
// EnrichWithSchemaProperties adds schema info to the diagnostics payload.
func (d *DiagnosticsCollector) EnrichWithSchemaProperties() {
func (d *diagnosticsCollector) EnrichWithSchemaProperties() {
var numShards uint64
numFields := 0
numIndexes := 0
@ -267,51 +267,51 @@ type SystemInfo interface {
MemUsed() (uint64, error)
}
// NewNopSystemInfo creates a no-op implementation of SystemInfo.
func NewNopSystemInfo() *NopSystemInfo {
return &NopSystemInfo{}
// newNopSystemInfo creates a no-op implementation of SystemInfo.
func newNopSystemInfo() *nopSystemInfo {
return &nopSystemInfo{}
}
// NopSystemInfo is a no-op implementation of SystemInfo.
type NopSystemInfo struct {
// nopSystemInfo is a no-op implementation of SystemInfo.
type nopSystemInfo struct {
}
// Uptime is a no-op implementation of SystemInfo.Uptime.
func (n *NopSystemInfo) Uptime() (uint64, error) {
func (n *nopSystemInfo) Uptime() (uint64, error) {
return 0, nil
}
// Platform is a no-op implementation of SystemInfo.Platform.
func (n *NopSystemInfo) Platform() (string, error) {
func (n *nopSystemInfo) Platform() (string, error) {
return "", nil
}
// Family is a no-op implementation of SystemInfo.Family.
func (n *NopSystemInfo) Family() (string, error) {
func (n *nopSystemInfo) Family() (string, error) {
return "", nil
}
// OSVersion is a no-op implementation of SystemInfo.OSVersion.
func (n *NopSystemInfo) OSVersion() (string, error) {
func (n *nopSystemInfo) OSVersion() (string, error) {
return "", nil
}
// KernelVersion is a no-op implementation of SystemInfo.KernelVersion.
func (n *NopSystemInfo) KernelVersion() (string, error) {
func (n *nopSystemInfo) KernelVersion() (string, error) {
return "", nil
}
// MemFree is a no-op implementation of SystemInfo.MemFree.
func (n *NopSystemInfo) MemFree() (uint64, error) {
func (n *nopSystemInfo) MemFree() (uint64, error) {
return 0, nil
}
// MemTotal is a no-op implementation of SystemInfo.MemTotal.
func (n *NopSystemInfo) MemTotal() (uint64, error) {
func (n *nopSystemInfo) MemTotal() (uint64, error) {
return 0, nil
}
// MemUsed is a no-op implementation of SystemInfo.MemUsed.
func (n *NopSystemInfo) MemUsed() (uint64, error) {
func (n *nopSystemInfo) MemUsed() (uint64, error) {
return 0, nil
}

View file

@ -29,7 +29,7 @@ func TestDiagnosticsClient(t *testing.T) {
server := httptest.NewServer(nil)
// Create a new client.
d := NewDiagnosticsCollector(server.URL)
d := newDiagnosticsCollector(server.URL)
d.Set("gg", 10)
d.Set("ss", "ss")
@ -76,7 +76,7 @@ func TestDiagnosticsVersion_Parse(t *testing.T) {
}
func TestDiagnosticsVersion_Compare(t *testing.T) {
d := NewDiagnosticsCollector("localhost:10101")
d := newDiagnosticsCollector("localhost:10101")
version := "v0.1.1"
d.SetVersion(version)
@ -118,7 +118,7 @@ func TestDiagnosticsVersion_Check(t *testing.T) {
}))
// Create a new client.
d := NewDiagnosticsCollector("localhost:10101")
d := newDiagnosticsCollector("localhost:10101")
version := "0.1.1"
d.SetVersion(version)
@ -143,7 +143,7 @@ func BenchmarkDiagnostics(b *testing.B) {
server := httptest.NewServer(nil)
// Create a new client.
d := NewDiagnosticsCollector(server.URL)
d := newDiagnosticsCollector(server.URL)
prev := runtime.GOMAXPROCS(4)
defer runtime.GOMAXPROCS(prev)

View file

@ -337,7 +337,7 @@ func encodeQueryRequest(m *pilosa.QueryRequest) *internal.QueryRequest {
func encodeQueryResponse(m *pilosa.QueryResponse) *internal.QueryResponse {
pb := &internal.QueryResponse{
Results: make([]*internal.QueryResult, len(m.Results)),
ColumnAttrSets: EncodeColumnAttrSets(m.ColumnAttrSets),
ColumnAttrSets: encodeColumnAttrSets(m.ColumnAttrSets),
}
for i := range m.Results {
@ -346,13 +346,13 @@ func encodeQueryResponse(m *pilosa.QueryResponse) *internal.QueryResponse {
switch result := m.Results[i].(type) {
case *pilosa.Row:
pb.Results[i].Type = queryResultTypeRow
pb.Results[i].Row = EncodeRow(result)
pb.Results[i].Row = encodeRow(result)
case []pilosa.Pair:
pb.Results[i].Type = queryResultTypePairs
pb.Results[i].Pairs = EncodePairs(result)
pb.Results[i].Pairs = encodePairs(result)
case pilosa.ValCount:
pb.Results[i].Type = queryResultTypeValCount
pb.Results[i].ValCount = EncodeValCount(result)
pb.Results[i].ValCount = encodeValCount(result)
case uint64:
pb.Results[i].Type = queryResultTypeUint64
pb.Results[i].N = result
@ -457,8 +457,8 @@ func encodeFieldOptions(o *pilosa.FieldOptions) *internal.FieldOptions {
}
}
// EncodeNodes converts a slice of Nodes into its internal representation.
func EncodeNodes(a []*pilosa.Node) []*internal.Node {
// encodeNodes converts a slice of Nodes into its internal representation.
func encodeNodes(a []*pilosa.Node) []*internal.Node {
other := make([]*internal.Node, len(a))
for i := range a {
other[i] = encodeNode(a[i])
@ -487,7 +487,7 @@ func encodeClusterStatus(m *pilosa.ClusterStatus) *internal.ClusterStatus {
return &internal.ClusterStatus{
State: m.State,
ClusterID: m.ClusterID,
Nodes: EncodeNodes(m.Nodes),
Nodes: encodeNodes(m.Nodes),
}
}
@ -950,22 +950,22 @@ func decodeValCount(pb *internal.ValCount) pilosa.ValCount {
}
}
func EncodeColumnAttrSets(a []*pilosa.ColumnAttrSet) []*internal.ColumnAttrSet {
func encodeColumnAttrSets(a []*pilosa.ColumnAttrSet) []*internal.ColumnAttrSet {
other := make([]*internal.ColumnAttrSet, len(a))
for i := range a {
other[i] = EncodeColumnAttrSet(a[i])
other[i] = encodeColumnAttrSet(a[i])
}
return other
}
func EncodeColumnAttrSet(set *pilosa.ColumnAttrSet) *internal.ColumnAttrSet {
func encodeColumnAttrSet(set *pilosa.ColumnAttrSet) *internal.ColumnAttrSet {
return &internal.ColumnAttrSet{
ID: set.ID,
Attrs: encodeAttrs(set.Attrs),
}
}
func EncodeRow(r *pilosa.Row) *internal.Row {
func encodeRow(r *pilosa.Row) *internal.Row {
if r == nil {
return nil
}
@ -976,7 +976,7 @@ func EncodeRow(r *pilosa.Row) *internal.Row {
}
}
func EncodePairs(a pilosa.Pairs) []*internal.Pair {
func encodePairs(a pilosa.Pairs) []*internal.Pair {
other := make([]*internal.Pair, len(a))
for i := range a {
other[i] = encodePair(a[i])
@ -992,7 +992,7 @@ func encodePair(p pilosa.Pair) *internal.Pair {
}
}
func EncodeValCount(vc pilosa.ValCount) *internal.ValCount {
func encodeValCount(vc pilosa.ValCount) *internal.ValCount {
return &internal.ValCount{
Val: vc.Val,
Count: vc.Count,

View file

@ -56,23 +56,23 @@ func init() {
var (
btDPool = sync.Pool{New: func() interface{} { return &d{} }}
btEPool = btEpool{sync.Pool{New: func() interface{} { return &Enumerator{} }}}
btTPool = btTpool{sync.Pool{New: func() interface{} { return &Tree{} }}}
btEPool = btEpool{sync.Pool{New: func() interface{} { return &enumerator{} }}}
btTPool = btTpool{sync.Pool{New: func() interface{} { return &tree{} }}}
btXPool = sync.Pool{New: func() interface{} { return &x{} }}
)
type btTpool struct{ sync.Pool }
func (p *btTpool) get(cmp Cmp) *Tree {
x := p.Get().(*Tree)
func (p *btTpool) get(cmp Cmp) *tree {
x := p.Get().(*tree)
x.cmp = cmp
return x
}
type btEpool struct{ sync.Pool }
func (p *btEpool) get(err error, hit bool, i int, k uint64, q *d, t *Tree, ver int64) *Enumerator {
x := p.Get().(*Enumerator)
func (p *btEpool) get(err error, hit bool, i int, k uint64, q *d, t *tree, ver int64) *enumerator {
x := p.Get().(*enumerator)
x.err, x.hit, x.i, x.k, x.q, x.t, x.ver = err, hit, i, k, q, t, ver
return x
}
@ -98,26 +98,26 @@ type (
v *roaring.Container
}
// Enumerator captures the state of enumerating a tree. It is returned
// enumerator captures the state of enumerating a tree. It is returned
// from the Seek* methods. The enumerator is aware of any mutations
// made to the tree in the process of enumerating it and automatically
// resumes the enumeration at the proper key, if possible.
//
// However, once an Enumerator returns io.EOF to signal "no more
// However, once an enumerator returns io.EOF to signal "no more
// items", it does no more attempt to "resync" on tree mutation(s). In
// other words, io.EOF from an Enumerator is "sticky" (idempotent).
Enumerator struct {
// other words, io.EOF from an enumerator is "sticky" (idempotent).
enumerator struct {
err error
hit bool
i int
k uint64
q *d
t *Tree
t *tree
ver int64
}
// Tree is a B+tree.
Tree struct {
// tree is a B+tree.
tree struct {
c int
cmp Cmp
first *d
@ -140,9 +140,9 @@ type (
var ( // R/O zero values
zd d
zde de
ze Enumerator
ze enumerator
zk uint64
zt Tree
zt tree
zx x
zxe xe
)
@ -233,14 +233,14 @@ func (l *d) mvR(r *d, c int) {
// ----------------------------------------------------------------------- Tree
// TreeNew returns a newly created, empty Tree. The compare function is used
// treeNew returns a newly created, empty Tree. The compare function is used
// for key collation.
func TreeNew(cmp Cmp) *Tree {
func treeNew(cmp Cmp) *tree {
return btTPool.get(cmp)
}
// Clear removes all K/V pairs from the tree.
func (t *Tree) Clear() {
func (t *tree) Clear() {
if t.r == nil {
return
}
@ -252,13 +252,13 @@ func (t *Tree) Clear() {
// Close performs Clear and recycles t to a pool for possible later reuse. No
// references to t should exist or such references must not be used afterwards.
func (t *Tree) Close() {
func (t *tree) Close() {
t.Clear()
*t = zt
btTPool.Put(t)
}
func (t *Tree) cat(p *x, q, r *d, pi int) {
func (t *tree) cat(p *x, q, r *d, pi int) {
t.ver++
q.mvL(r, r.c)
if r.n != nil {
@ -286,7 +286,7 @@ func (t *Tree) cat(p *x, q, r *d, pi int) {
t.r = q
}
func (t *Tree) catX(p, q, r *x, pi int) {
func (t *tree) catX(p, q, r *x, pi int) {
t.ver++
q.x[q.c].k = p.x[pi].k
copy(q.x[q.c+1:], r.x[:r.c])
@ -320,7 +320,7 @@ func (t *Tree) catX(p, q, r *x, pi int) {
// Delete removes the k's KV pair, if it exists, in which case Delete returns
// true.
func (t *Tree) Delete(k uint64) (ok bool) {
func (t *tree) Delete(k uint64) (ok bool) {
pi := -1
var p *x
q := t.r
@ -370,7 +370,7 @@ func (t *Tree) Delete(k uint64) (ok bool) {
}
}
func (t *Tree) extract(q *d, i int) { // (r *container) {
func (t *tree) extract(q *d, i int) { // (r *container) {
t.ver++
//r = q.d[i].v // prepared for Extract
q.c--
@ -381,7 +381,7 @@ func (t *Tree) extract(q *d, i int) { // (r *container) {
t.c--
}
func (t *Tree) find(q interface{}, k uint64) (i int, ok bool) {
func (t *tree) find(q interface{}, k uint64) (i int, ok bool) {
var mk uint64
l := 0
switch x := q.(type) {
@ -419,7 +419,7 @@ func (t *Tree) find(q interface{}, k uint64) (i int, ok bool) {
// First returns the first item of the tree in the key collating order, or
// (zero-value, zero-value) if the tree is empty.
func (t *Tree) First() (k uint64, v *roaring.Container) {
func (t *tree) First() (k uint64, v *roaring.Container) {
if q := t.first; q != nil {
q := &q.d[0]
k, v = q.k, q.v
@ -429,7 +429,7 @@ func (t *Tree) First() (k uint64, v *roaring.Container) {
// Get returns the value associated with k and true if it exists. Otherwise Get
// returns (zero-value, false).
func (t *Tree) Get(k uint64) (v *roaring.Container, ok bool) {
func (t *tree) Get(k uint64) (v *roaring.Container, ok bool) {
q := t.r
if q == nil {
return
@ -455,7 +455,7 @@ func (t *Tree) Get(k uint64) (v *roaring.Container, ok bool) {
}
}
func (t *Tree) insert(q *d, i int, k uint64, v *roaring.Container) *d {
func (t *tree) insert(q *d, i int, k uint64, v *roaring.Container) *d {
t.ver++
c := q.c
if i < c {
@ -470,7 +470,7 @@ func (t *Tree) insert(q *d, i int, k uint64, v *roaring.Container) *d {
// Last returns the last item of the tree in the key collating order, or
// (zero-value, zero-value) if the tree is empty.
func (t *Tree) Last() (k uint64, v *roaring.Container) {
func (t *tree) Last() (k uint64, v *roaring.Container) {
if q := t.last; q != nil {
q := &q.d[q.c-1]
k, v = q.k, q.v
@ -479,11 +479,11 @@ func (t *Tree) Last() (k uint64, v *roaring.Container) {
}
// Len returns the number of items in the tree.
func (t *Tree) Len() int {
func (t *tree) Len() int {
return t.c
}
func (t *Tree) overflow(p *x, q *d, pi, i int, k uint64, v *roaring.Container) {
func (t *tree) overflow(p *x, q *d, pi, i int, k uint64, v *roaring.Container) {
t.ver++
l, r := p.siblings(pi)
@ -528,7 +528,7 @@ func (t *Tree) overflow(p *x, q *d, pi, i int, k uint64, v *roaring.Container) {
// Seek returns an Enumerator positioned on an item such that k >= item's key.
// ok reports if k == item.key The Enumerator's position is possibly after the
// last item in the tree.
func (t *Tree) Seek(k uint64) (e *Enumerator, ok bool) {
func (t *tree) Seek(k uint64) (e *enumerator, ok bool) {
q := t.r
if q == nil {
e = btEPool.get(nil, false, 0, k, nil, t, t.ver)
@ -558,7 +558,7 @@ func (t *Tree) Seek(k uint64) (e *Enumerator, ok bool) {
// SeekFirst returns an enumerator positioned on the first KV pair in the tree,
// if any. For an empty tree, err == io.EOF is returned and e will be nil.
func (t *Tree) SeekFirst() (e *Enumerator, err error) {
func (t *tree) SeekFirst() (e *enumerator, err error) {
q := t.first
if q == nil {
return nil, io.EOF
@ -569,7 +569,7 @@ func (t *Tree) SeekFirst() (e *Enumerator, err error) {
// SeekLast returns an enumerator positioned on the last KV pair in the tree,
// if any. For an empty tree, err == io.EOF is returned and e will be nil.
func (t *Tree) SeekLast() (e *Enumerator, err error) {
func (t *tree) SeekLast() (e *enumerator, err error) {
q := t.last
if q == nil {
return nil, io.EOF
@ -579,7 +579,7 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) {
}
// Set sets the value associated with k.
func (t *Tree) Set(k uint64, v *roaring.Container) {
func (t *tree) Set(k uint64, v *roaring.Container) {
//dbg("--- PRE Set(%v, %v)\n%s", k, v, t.dump())
//defer func() {
// dbg("--- POST\n%s\n====\n", t.dump())
@ -645,7 +645,7 @@ func (t *Tree) Set(k uint64, v *roaring.Container) {
// tree.Put(k, func(uint64, bool){ return v, true })
//
// modulo the differing return values.
func (t *Tree) Put(k uint64, upd func(oldV *roaring.Container, exists bool) (newV *roaring.Container, write bool)) (oldV *roaring.Container, written bool) {
func (t *tree) Put(k uint64, upd func(oldV *roaring.Container, exists bool) (newV *roaring.Container, write bool)) (oldV *roaring.Container, written bool) {
pi := -1
var p *x
q := t.r
@ -712,7 +712,7 @@ func (t *Tree) Put(k uint64, upd func(oldV *roaring.Container, exists bool) (new
}
}
func (t *Tree) split(p *x, q *d, pi, i int, k uint64, v *roaring.Container) {
func (t *tree) split(p *x, q *d, pi, i int, k uint64, v *roaring.Container) {
t.ver++
r := btDPool.Get().(*d)
if q.n != nil {
@ -747,7 +747,7 @@ func (t *Tree) split(p *x, q *d, pi, i int, k uint64, v *roaring.Container) {
t.insert(q, i, k, v)
}
func (t *Tree) splitX(p *x, q *x, pi int, i int) (*x, int) {
func (t *tree) splitX(p *x, q *x, pi int, i int) (*x, int) {
t.ver++
r := btXPool.Get().(*x)
copy(r.x[:], q.x[kx+1:])
@ -771,7 +771,7 @@ func (t *Tree) splitX(p *x, q *x, pi int, i int) (*x, int) {
return q, i
}
func (t *Tree) underflow(p *x, q *d, pi int) {
func (t *tree) underflow(p *x, q *d, pi int) {
t.ver++
l, r := p.siblings(pi)
@ -796,7 +796,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
t.cat(p, q, r, pi)
}
func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) {
func (t *tree) underflowX(p *x, q *x, pi int, i int) (*x, int) {
t.ver++
var l, r *x
@ -850,7 +850,7 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) {
// Close recycles e to a pool for possible later reuse. No references to e
// should exist or such references must not be used afterwards.
func (e *Enumerator) Close() {
func (e *enumerator) Close() {
*e = ze
btEPool.Put(e)
}
@ -858,7 +858,7 @@ func (e *Enumerator) Close() {
// Next returns the currently enumerated item, if it exists and moves to the
// next item in the key collation order. If there is no item to return, err ==
// io.EOF is returned.
func (e *Enumerator) Next() (k uint64, v *roaring.Container, err error) {
func (e *enumerator) Next() (k uint64, v *roaring.Container, err error) {
if err = e.err; err != nil {
return
}
@ -886,7 +886,7 @@ func (e *Enumerator) Next() (k uint64, v *roaring.Container, err error) {
return
}
func (e *Enumerator) next() error {
func (e *enumerator) next() error {
if e.q == nil {
e.err = io.EOF
return io.EOF
@ -906,7 +906,7 @@ func (e *Enumerator) next() error {
// Prev returns the currently enumerated item, if it exists and moves to the
// previous item in the key collation order. If there is no item to return, err
// == io.EOF is returned.
func (e *Enumerator) Prev() (k uint64, v *roaring.Container, err error) {
func (e *enumerator) Prev() (k uint64, v *roaring.Container, err error) {
if err = e.err; err != nil {
return
}
@ -941,7 +941,7 @@ func (e *Enumerator) Prev() (k uint64, v *roaring.Container, err error) {
return
}
func (e *Enumerator) prev() error {
func (e *enumerator) prev() error {
if e.q == nil {
e.err = io.EOF
return io.EOF

View file

@ -27,28 +27,28 @@ func cmp(a, b uint64) int {
return int(a - b)
}
type BTreeContainers struct {
tree *Tree
type bTreeContainers struct {
tree *tree
lastKey uint64
lastContainer *roaring.Container
}
func NewBTreeContainers() *BTreeContainers {
return &BTreeContainers{
tree: TreeNew(cmp),
func newBTreeContainers() *bTreeContainers {
return &bTreeContainers{
tree: treeNew(cmp),
}
}
func NewBTreeBitmap(a ...uint64) *roaring.Bitmap {
b := &roaring.Bitmap{
Containers: NewBTreeContainers(),
Containers: newBTreeContainers(),
}
b.Add(a...)
return b
}
func (btc *BTreeContainers) Get(key uint64) *roaring.Container {
func (btc *bTreeContainers) Get(key uint64) *roaring.Container {
// Check the last* cache for same container.
if key == btc.lastKey && btc.lastContainer != nil {
return btc.lastContainer
@ -64,7 +64,7 @@ func (btc *BTreeContainers) Get(key uint64) *roaring.Container {
return c
}
func (btc *BTreeContainers) Put(key uint64, c *roaring.Container) {
func (btc *bTreeContainers) Put(key uint64, c *roaring.Container) {
// If a mapped container is added to the tree, reset the
// lastContainer cache so that the cache is not pointing
// at a read-only mmap.
@ -93,16 +93,16 @@ type updater struct {
mapped bool
}
func (btc *BTreeContainers) PutContainerValues(key uint64, containerType byte, n int, mapped bool) {
func (btc *bTreeContainers) PutContainerValues(key uint64, containerType byte, n int, mapped bool) {
a := updater{key, containerType, n, mapped}
btc.tree.Put(key, a.update)
}
func (btc *BTreeContainers) Remove(key uint64) {
func (btc *bTreeContainers) Remove(key uint64) {
btc.tree.Delete(key)
}
func (btc *BTreeContainers) GetOrCreate(key uint64) *roaring.Container {
func (btc *bTreeContainers) GetOrCreate(key uint64) *roaring.Container {
// Check the last* cache for same container.
if key == btc.lastKey && btc.lastContainer != nil {
return btc.lastContainer
@ -121,7 +121,7 @@ func (btc *BTreeContainers) GetOrCreate(key uint64) *roaring.Container {
return btc.lastContainer
}
func (btc *BTreeContainers) Count() (n uint64) {
func (btc *bTreeContainers) Count() (n uint64) {
e, _ := btc.tree.Seek(0)
_, c, err := e.Next()
for err != io.EOF {
@ -131,8 +131,8 @@ func (btc *BTreeContainers) Count() (n uint64) {
return
}
func (btc *BTreeContainers) Clone() roaring.Containers {
nbtc := NewBTreeContainers()
func (btc *bTreeContainers) Clone() roaring.Containers {
nbtc := newBTreeContainers()
itr, err := btc.tree.SeekFirst()
if err == io.EOF {
@ -148,7 +148,7 @@ func (btc *BTreeContainers) Clone() roaring.Containers {
return nbtc
}
func (btc *BTreeContainers) Last() (key uint64, c *roaring.Container) {
func (btc *bTreeContainers) Last() (key uint64, c *roaring.Container) {
if btc.tree.Len() == 0 {
return 0, nil
}
@ -156,34 +156,34 @@ func (btc *BTreeContainers) Last() (key uint64, c *roaring.Container) {
return k, v
}
func (btc *BTreeContainers) Size() int {
func (btc *bTreeContainers) Size() int {
return btc.tree.Len()
}
func (btc *BTreeContainers) Reset() {
btc.tree = TreeNew(cmp)
func (btc *bTreeContainers) Reset() {
btc.tree = treeNew(cmp)
btc.lastKey = 0
btc.lastContainer = nil
}
func (btc *BTreeContainers) Iterator(key uint64) (citer roaring.ContainerIterator, found bool) {
func (btc *bTreeContainers) Iterator(key uint64) (citer roaring.ContainerIterator, found bool) {
e, ok := btc.tree.Seek(key)
if ok {
found = true
}
return &BTCIterator{
return &btcIterator{
e: e,
}, found
}
type BTCIterator struct {
e *Enumerator
type btcIterator struct {
e *enumerator
key uint64
val *roaring.Container
}
func (i *BTCIterator) Next() bool {
func (i *btcIterator) Next() bool {
k, v, err := i.e.Next()
if err == io.EOF {
@ -194,7 +194,7 @@ func (i *BTCIterator) Next() bool {
return true
}
func (i *BTCIterator) Value() (uint64, *roaring.Container) {
func (i *btcIterator) Value() (uint64, *roaring.Container) {
if i.val == nil {
return 0, nil
}

View file

@ -67,7 +67,7 @@ func optExecutorInternalQueryClient(c InternalQueryClient) executorOption {
// newExecutor returns a new instance of Executor.
func newExecutor(opts ...executorOption) *executor {
e := &executor{
client: NewNopInternalQueryClient(),
client: newNopInternalQueryClient(),
}
for _, opt := range opts {
err := opt(e)
@ -234,7 +234,7 @@ func (e *executor) executeSum(ctx context.Context, index string, c *pql.Call, sh
// Merge returned results at coordinating node.
reduceFn := func(prev, v interface{}) interface{} {
other, _ := prev.(ValCount)
return other.Add(v.(ValCount))
return other.add(v.(ValCount))
}
result, err := e.mapReduce(ctx, index, shards, c, opt, mapFn, reduceFn)
@ -267,7 +267,7 @@ func (e *executor) executeMin(ctx context.Context, index string, c *pql.Call, sh
// Merge returned results at coordinating node.
reduceFn := func(prev, v interface{}) interface{} {
other, _ := prev.(ValCount)
return other.Smaller(v.(ValCount))
return other.smaller(v.(ValCount))
}
result, err := e.mapReduce(ctx, index, shards, c, opt, mapFn, reduceFn)
@ -300,7 +300,7 @@ func (e *executor) executeMax(ctx context.Context, index string, c *pql.Call, sh
// Merge returned results at coordinating node.
reduceFn := func(prev, v interface{}) interface{} {
other, _ := prev.(ValCount)
return other.Larger(v.(ValCount))
return other.larger(v.(ValCount))
}
result, err := e.mapReduce(ctx, index, shards, c, opt, mapFn, reduceFn)
@ -375,7 +375,7 @@ func (e *executor) executeBitmapCall(ctx context.Context, index string, c *pql.C
}
if opt.ExcludeColumns {
row.segments = []RowSegment{}
row.segments = []rowSegment{}
}
return row, nil
@ -661,7 +661,7 @@ func (e *executor) executeDifferenceShard(ctx context.Context, index string, c *
other = other.Difference(row)
}
}
other.InvalidateCount()
other.invalidateCount()
return other, nil
}
@ -712,10 +712,10 @@ func (e *executor) executeIntersectShard(ctx context.Context, index string, c *p
if i == 0 {
other = row
} else {
other = other.Intersect(row)
other = other.intersect(row)
}
}
other.InvalidateCount()
other.invalidateCount()
return other, nil
}
@ -937,7 +937,7 @@ func (e *executor) executeUnionShard(ctx context.Context, index string, c *pql.C
other = other.Union(row)
}
}
other.InvalidateCount()
other.invalidateCount()
return other, nil
}
@ -956,7 +956,7 @@ func (e *executor) executeXorShard(ctx context.Context, index string, c *pql.Cal
other = other.Xor(row)
}
}
other.InvalidateCount()
other.invalidateCount()
return other, nil
}
@ -1577,7 +1577,7 @@ func (e *executor) translateCall(index string, idx *Index, c *pql.Call) error {
if field == nil {
return ErrFieldNotFound
}
if field.Keys() {
if field.keys() {
if c.Args[rowKey] != nil && !isString(c.Args[rowKey]) {
return errors.New("row value must be a string when field 'keys' option enabled")
}
@ -1628,7 +1628,7 @@ func (e *executor) translateResult(index string, idx *Index, call *pql.Call, res
if field == nil {
return nil, ErrFieldNotFound
}
if field.Keys() {
if field.keys() {
other := make([]Pair, len(result))
for i := range result {
key, err := e.TranslateStore.TranslateRowToString(index, fieldName, result[i].ID)
@ -1713,15 +1713,15 @@ type ValCount struct {
Count int64 `json:"count"`
}
func (vc *ValCount) Add(other ValCount) ValCount {
func (vc *ValCount) add(other ValCount) ValCount {
return ValCount{
Val: vc.Val + other.Val,
Count: vc.Count + other.Count,
}
}
// Smaller returns the smaller of the two ValCounts.
func (vc *ValCount) Smaller(other ValCount) ValCount {
// smaller returns the smaller of the two ValCounts.
func (vc *ValCount) smaller(other ValCount) ValCount {
if vc.Count == 0 || (other.Val < vc.Val && other.Count > 0) {
return other
}
@ -1731,8 +1731,8 @@ func (vc *ValCount) Smaller(other ValCount) ValCount {
}
}
// Larger returns the larger of the two ValCounts.
func (vc *ValCount) Larger(other ValCount) ValCount {
// larger returns the larger of the two ValCounts.
func (vc *ValCount) larger(other ValCount) ValCount {
if vc.Count == 0 || (other.Val > vc.Val && other.Count > 0) {
return other
}

View file

@ -72,7 +72,7 @@ type Field struct {
bsiGroups []*bsiGroup
Logger Logger
logger Logger
}
// FieldOption is a functional option type for pilosa.fieldOptions.
@ -166,7 +166,7 @@ func NewField(path, index, name string, opts FieldOption) (*Field, error) {
options: applyDefaultOptions(fo),
Logger: NopLogger,
logger: NopLogger,
}
return f, nil
}
@ -183,8 +183,8 @@ func (f *Field) Path() string { return f.path }
// RowAttrStore returns the attribute storage.
func (f *Field) RowAttrStore() AttrStore { return f.rowAttrStore }
// MaxShard returns the max shard in the field.
func (f *Field) MaxShard() uint64 {
// maxShard returns the max shard in the field.
func (f *Field) maxShard() uint64 {
f.mu.RLock()
defer f.mu.RUnlock()
@ -337,7 +337,7 @@ func (f *Field) loadMeta() error {
func (f *Field) saveMeta() error {
// Marshal metadata.
fo := f.options
buf, err := proto.Marshal(fo.Encode())
buf, err := proto.Marshal(fo.encode())
if err != nil {
return errors.Wrap(err, "marshaling")
}
@ -396,7 +396,7 @@ func (f *Field) applyOptions(opt FieldOptions) error {
f.options.Max = 0
f.options.Keys = opt.Keys
// Set the time quantum.
if err := f.SetTimeQuantum(opt.TimeQuantum); err != nil {
if err := f.setTimeQuantum(opt.TimeQuantum); err != nil {
f.Close()
return errors.Wrap(err, "setting time quantum")
}
@ -428,8 +428,8 @@ func (f *Field) Close() error {
return nil
}
// Keys returns true if the field uses string keys.
func (f *Field) Keys() bool {
// keys returns true if the field uses string keys.
func (f *Field) keys() bool {
f.mu.RLock()
defer f.mu.RUnlock()
return f.options.Keys
@ -533,8 +533,8 @@ func (f *Field) TimeQuantum() TimeQuantum {
return f.options.TimeQuantum
}
// SetTimeQuantum sets the time quantum for the field.
func (f *Field) SetTimeQuantum(q TimeQuantum) error {
// setTimeQuantum sets the time quantum for the field.
func (f *Field) setTimeQuantum(q TimeQuantum) error {
f.mu.Lock()
defer f.mu.Unlock()
@ -606,8 +606,8 @@ func (f *Field) viewNames() []string {
return other
}
// RecalculateCaches recalculates caches on every view in the field.
func (f *Field) RecalculateCaches() {
// recalculateCaches recalculates caches on every view in the field.
func (f *Field) recalculateCaches() {
for _, view := range f.views() {
view.recalculateCaches()
}
@ -660,7 +660,7 @@ func (f *Field) createViewIfNotExistsBase(name string) (*view, bool, error) {
func (f *Field) newView(path, name string) *view {
view := newView(path, f.index, f.name, name, f.options.CacheSize)
view.cacheType = f.options.CacheType
view.logger = f.Logger
view.logger = f.logger
view.rowAttrStore = f.rowAttrStore
view.stats = f.Stats.WithTags(fmt.Sprintf("view:%s", name))
view.broadcaster = f.broadcaster
@ -955,7 +955,7 @@ func (f *Field) Range(name string, op pql.Token, predicate int64) (*Row, error)
return view.rangeOp(op, bsig.BitDepth(), baseValue)
}
func (f *Field) RangeBetween(name string, predicateMin, predicateMax int64) (*Row, error) {
func (f *Field) rangeBetween(name string, predicateMin, predicateMax int64) (*Row, error) {
// Retrieve and validate bsiGroup.
bsig := f.bsiGroup(name)
if bsig == nil {
@ -1035,8 +1035,8 @@ func (f *Field) Import(rowIDs, columnIDs []uint64, timestamps []*time.Time) erro
return nil
}
// ImportValue bulk imports range-encoded value data.
func (f *Field) ImportValue(columnIDs []uint64, values []int64) error {
// importValue bulk imports range-encoded value data.
func (f *Field) importValue(columnIDs []uint64, values []int64) error {
viewName := viewBSIGroupPrefix + f.name
// Get the bsiGroup so we know bitDepth.
bsig := f.bsiGroup(f.name)
@ -1135,8 +1135,8 @@ func applyDefaultOptions(o FieldOptions) FieldOptions {
return o
}
// Encode converts o into its internal representation.
func (o *FieldOptions) Encode() *internal.FieldOptions {
// encode converts o into its internal representation.
func (o *FieldOptions) encode() *internal.FieldOptions {
return encodeFieldOptions(o)
}

View file

@ -282,7 +282,7 @@ func TestField_SetTimeQuantum(t *testing.T) {
defer f.Close()
// Set & retrieve time quantum.
if err := f.SetTimeQuantum(TimeQuantum("YMDH")); err != nil {
if err := f.setTimeQuantum(TimeQuantum("YMDH")); err != nil {
t.Fatal(err)
} else if q := f.TimeQuantum(); q != TimeQuantum("YMDH") {
t.Fatalf("unexpected quantum: %s", q)
@ -300,7 +300,7 @@ func TestField_RowTime(t *testing.T) {
f := MustOpenField(OptFieldTypeTime(TimeQuantum("")))
defer f.Close()
if err := f.SetTimeQuantum(TimeQuantum("YMDH")); err != nil {
if err := f.setTimeQuantum(TimeQuantum("YMDH")); err != nil {
t.Fatal(err)
}

View file

@ -343,13 +343,13 @@ func (f *fragment) unprotectedRow(rowID uint64, checkRowCache bool, updateRowCac
// We Clone() data because otherwise row will contains pointers to containers in storage.
// This causes unexpected results when we cache the row and try to use it later.
row := &Row{
segments: []RowSegment{{
segments: []rowSegment{{
data: *data.Clone(),
shard: f.shard,
writable: false,
}},
}
row.InvalidateCount()
row.invalidateCount()
if updateRowCache {
f.rowCache.Add(rowID, row)
@ -446,7 +446,7 @@ func (f *fragment) unprotectedClearBit(rowID, columnID uint64) (changed bool, er
// Get the row from cache or fragment.storage.
row := f.unprotectedRow(rowID, true, true)
row.ClearBit(columnID)
row.clearBit(columnID)
// Update the cache.
f.cache.Add(rowID, row.Count())
@ -566,7 +566,7 @@ func (f *fragment) sum(filter *Row, bitDepth uint) (sum, count uint64, err error
// Compute count based on the existence row.
row := f.row(uint64(bitDepth))
if filter != nil {
count = row.IntersectionCount(filter)
count = row.intersectionCount(filter)
} else {
count = row.Count()
}
@ -582,7 +582,7 @@ func (f *fragment) sum(filter *Row, bitDepth uint) (sum, count uint64, err error
row := f.row(uint64(i))
cnt := uint64(0)
if filter != nil {
cnt = row.IntersectionCount(filter)
cnt = row.intersectionCount(filter)
} else {
cnt = row.Count()
}
@ -598,7 +598,7 @@ 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)
consider = consider.intersect(filter)
}
// If there are no columns to consider, return early.
@ -631,7 +631,7 @@ func (f *fragment) max(filter *Row, bitDepth uint) (max, count uint64, err error
consider := f.row(uint64(bitDepth))
if filter != nil {
consider = consider.Intersect(filter)
consider = consider.intersect(filter)
}
// If there are no columns to consider, return early.
@ -643,7 +643,7 @@ func (f *fragment) max(filter *Row, bitDepth uint) (max, count uint64, err error
ii := i - 1 // allow for uint range: (bitDepth-1) to 0
row := f.row(uint64(ii))
x := row.Intersect(consider)
x := row.intersect(consider)
count = x.Count()
if count > 0 {
max += (1 << ii)
@ -682,7 +682,7 @@ func (f *fragment) rangeEQ(bitDepth uint, predicate uint64) (*Row, error) {
bit := (predicate >> uint(i)) & 1
if bit == 1 {
b = b.Intersect(row)
b = b.intersect(row)
} else {
b = b.Difference(row)
}
@ -783,7 +783,7 @@ func (f *fragment) rangeGT(bitDepth uint, predicate uint64, allowEquality bool)
// 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 {
keep = keep.Union(b.Intersect(row))
keep = keep.Union(b.intersect(row))
}
}
@ -815,7 +815,7 @@ func (f *fragment) rangeBetween(bitDepth uint, predicateMin, predicateMax uint64
// 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))
keep1 = keep1.Union(b.intersect(row))
}
}
@ -938,7 +938,7 @@ func (f *fragment) top(opt topOptions) ([]Pair, error) {
// Calculate count and append.
count := cnt
if opt.Src != nil {
count = opt.Src.IntersectionCount(f.row(rowID))
count = opt.Src.intersectionCount(f.row(rowID))
}
if count == 0 {
continue
@ -982,7 +982,7 @@ func (f *fragment) top(opt topOptions) ([]Pair, error) {
// Calculate the intersecting column count and skip if it's below our
// last row in our current result set.
count := opt.Src.IntersectionCount(f.row(rowID))
count := opt.Src.intersectionCount(f.row(rowID))
if count < threshold {
continue
}

View file

@ -1063,7 +1063,7 @@ func BenchmarkFragment_IntersectionCount(b *testing.B) {
// Start benchmark
b.ResetTimer()
for i := 0; i < b.N; i++ {
if n := f.row(1).IntersectionCount(f.row(2)); n == 0 {
if n := f.row(1).intersectionCount(f.row(2)); n == 0 {
b.Fatalf("unexpected count: %d", n)
}
}

View file

@ -20,25 +20,25 @@ import (
)
// Ensure ActiveGCNotifier implements interface.
var _ pilosa.GCNotifier = &ActiveGCNotifier{}
var _ pilosa.GCNotifier = &activeGCNotifier{}
type ActiveGCNotifier struct {
type activeGCNotifier struct {
gcn *gcnotifier.GCNotifier
}
// NewActiveGCNotifier creates an active GCNotifier.
func NewActiveGCNotifier() *ActiveGCNotifier {
return &ActiveGCNotifier{
func NewActiveGCNotifier() *activeGCNotifier {
return &activeGCNotifier{
gcn: gcnotifier.New(),
}
}
// Close implements the GCNotifier interface.
func (n *ActiveGCNotifier) Close() {
func (n *activeGCNotifier) Close() {
n.gcn.Close()
}
// AfterGC implements the GCNotifier interface.
func (n *ActiveGCNotifier) AfterGC() <-chan struct{} {
func (n *activeGCNotifier) AfterGC() <-chan struct{} {
return n.gcn.AfterGC()
}

View file

@ -22,15 +22,15 @@ import (
var _ pilosa.SystemInfo = NewSystemInfo()
// SystemInfo is an implementation of pilosa.SystemInfo that uses gopsutil to collect information about the host OS.
type SystemInfo struct {
// systemInfo is an implementation of pilosa.systemInfo that uses gopsutil to collect information about the host OS.
type systemInfo struct {
platform string
family string
osVersion string
}
// Uptime returns the system uptime in seconds.
func (s *SystemInfo) Uptime() (uptime uint64, err error) {
func (s *systemInfo) Uptime() (uptime uint64, err error) {
hostInfo, err := host.Info()
if err != nil {
return 0, err
@ -39,7 +39,7 @@ func (s *SystemInfo) Uptime() (uptime uint64, err error) {
}
// collectPlatformInfo fetches and caches system platform information.
func (s *SystemInfo) collectPlatformInfo() error {
func (s *systemInfo) collectPlatformInfo() error {
var err error
if s.platform == "" {
s.platform, s.family, s.osVersion, err = host.PlatformInformation()
@ -51,7 +51,7 @@ func (s *SystemInfo) collectPlatformInfo() error {
}
// Platform returns the system platform.
func (s *SystemInfo) Platform() (string, error) {
func (s *systemInfo) Platform() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
@ -60,7 +60,7 @@ func (s *SystemInfo) Platform() (string, error) {
}
// Family returns the system family.
func (s *SystemInfo) Family() (string, error) {
func (s *systemInfo) Family() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
@ -69,7 +69,7 @@ func (s *SystemInfo) Family() (string, error) {
}
// OSVersion returns the OS Version.
func (s *SystemInfo) OSVersion() (string, error) {
func (s *systemInfo) OSVersion() (string, error) {
err := s.collectPlatformInfo()
if err != nil {
return "", err
@ -78,7 +78,7 @@ func (s *SystemInfo) OSVersion() (string, error) {
}
// MemFree returns the amount of free memory in bytes.
func (s *SystemInfo) MemFree() (uint64, error) {
func (s *systemInfo) MemFree() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
@ -87,7 +87,7 @@ func (s *SystemInfo) MemFree() (uint64, error) {
}
// MemTotal returns the amount of total memory in bytes.
func (s *SystemInfo) MemTotal() (uint64, error) {
func (s *systemInfo) MemTotal() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
@ -96,7 +96,7 @@ func (s *SystemInfo) MemTotal() (uint64, error) {
}
// MemUsed returns the amount of used memory in bytes.
func (s *SystemInfo) MemUsed() (uint64, error) {
func (s *systemInfo) MemUsed() (uint64, error) {
memInfo, err := mem.VirtualMemory()
if err != nil {
return 0, err
@ -105,11 +105,11 @@ func (s *SystemInfo) MemUsed() (uint64, error) {
}
// KernelVersion returns the kernel version as a string.
func (s *SystemInfo) KernelVersion() (string, error) {
func (s *systemInfo) KernelVersion() (string, error) {
return host.KernelVersion()
}
// NewSystemInfo is a constructor for the gopsutil implementation of SystemInfo.
func NewSystemInfo() *SystemInfo {
return &SystemInfo{}
func NewSystemInfo() *systemInfo {
return &systemInfo{}
}

View file

@ -33,10 +33,10 @@ import (
)
// Ensure GossipMemberSet implements interfaces.
var _ memberlist.Delegate = &GossipMemberSet{}
var _ memberlist.Delegate = &gossipMemberSet{}
// GossipMemberSet represents a gossip implementation of MemberSet using memberlist.
type GossipMemberSet struct {
// gossipMemberSet represents a gossip implementation of MemberSet using memberlist.
type gossipMemberSet struct {
mu sync.RWMutex
memberlist *memberlist.Memberlist
@ -54,7 +54,7 @@ type GossipMemberSet struct {
}
// Open implements the MemberSet interface to start network activity.
func (g *GossipMemberSet) Open() (err error) {
func (g *gossipMemberSet) Open() (err error) {
g.mu.Lock()
g.memberlist, err = memberlist.Create(g.config.memberlistConfig)
g.mu.Unlock()
@ -94,7 +94,7 @@ func (g *GossipMemberSet) Open() (err error) {
}
// joinWithRetry wraps the standard memberlist Join function in a retry.
func (g *GossipMemberSet) joinWithRetry(hosts []string) error {
func (g *gossipMemberSet) joinWithRetry(hosts []string) error {
err := retry(60, 2*time.Second, func() error {
_, err := g.memberlist.Join(hosts)
return err
@ -125,29 +125,29 @@ type gossipConfig struct {
memberlistConfig *memberlist.Config
}
// GossipMemberSetOption describes a functional option for GossipMemberSet.
type GossipMemberSetOption func(*GossipMemberSet) error
// gossipMemberSetOption describes a functional option for GossipMemberSet.
type gossipMemberSetOption func(*gossipMemberSet) error
// WithTransport is a functional option for providing a transport to NewGossipMemberSet.
func WithTransport(transport *Transport) GossipMemberSetOption {
return func(g *GossipMemberSet) error {
func WithTransport(transport *Transport) gossipMemberSetOption {
return func(g *gossipMemberSet) error {
g.transport = transport
return nil
}
}
// WithLogger is a functional option for providing a logger to NewGossipMemberSet.
func WithLogger(logger *log.Logger) GossipMemberSetOption {
return func(g *GossipMemberSet) error {
func WithLogger(logger *log.Logger) gossipMemberSetOption {
return func(g *gossipMemberSet) error {
g.logger = logger
return nil
}
}
// NewGossipMemberSet returns a new instance of GossipMemberSet based on options.
func NewGossipMemberSet(cfg Config, api *pilosa.API, options ...GossipMemberSetOption) (*GossipMemberSet, error) {
func NewGossipMemberSet(cfg Config, api *pilosa.API, options ...gossipMemberSetOption) (*gossipMemberSet, error) {
host := api.Node().URI.Host
g := &GossipMemberSet{
g := &gossipMemberSet{
papi: api,
Logger: pilosa.NopLogger,
}
@ -176,7 +176,7 @@ func NewGossipMemberSet(cfg Config, api *pilosa.API, options ...GossipMemberSetO
g.transport = transport
}
port := g.transport.Net.GetAutoBindPort()
port := g.transport.net.GetAutoBindPort()
var gossipKey []byte
var err error
@ -189,7 +189,7 @@ func NewGossipMemberSet(cfg Config, api *pilosa.API, options ...GossipMemberSetO
// memberlist config
conf := memberlist.DefaultWANConfig()
conf.Transport = g.transport.Net
conf.Transport = g.transport.net
conf.Name = api.Node().ID
conf.BindAddr = api.Node().URI.Host
conf.BindPort = port
@ -219,7 +219,7 @@ func NewGossipMemberSet(cfg Config, api *pilosa.API, options ...GossipMemberSetO
}
// NodeMeta implementation of the memberlist.Delegate interface.
func (g *GossipMemberSet) NodeMeta(limit int) []byte {
func (g *gossipMemberSet) NodeMeta(limit int) []byte {
buf, err := g.papi.Serializer.Marshal(g.papi.Node())
if err != nil {
g.Logger.Printf("marshal message error: %s", err)
@ -230,7 +230,7 @@ func (g *GossipMemberSet) NodeMeta(limit int) []byte {
// NotifyMsg implementation of the memberlist.Delegate interface
// called when a user-data message is received.
func (g *GossipMemberSet) NotifyMsg(b []byte) {
func (g *gossipMemberSet) NotifyMsg(b []byte) {
err := g.papi.ClusterMessage(context.Background(), bytes.NewBuffer(b))
if err != nil {
g.Logger.Printf("cluster message error: %s", err)
@ -239,13 +239,13 @@ func (g *GossipMemberSet) NotifyMsg(b []byte) {
// GetBroadcasts implementation of the memberlist.Delegate interface
// called when user data messages can be broadcast.
func (g *GossipMemberSet) GetBroadcasts(overhead, limit int) [][]byte {
func (g *gossipMemberSet) GetBroadcasts(overhead, limit int) [][]byte {
return g.broadcasts.GetBroadcasts(overhead, limit)
}
// LocalState implementation of the memberlist.Delegate interface
// sends this Node's state data.
func (g *GossipMemberSet) LocalState(join bool) []byte {
func (g *gossipMemberSet) LocalState(join bool) []byte {
m := &pilosa.NodeStatus{
Node: g.papi.Node(),
MaxShards: g.papi.MaxShards(context.Background()),
@ -263,7 +263,7 @@ func (g *GossipMemberSet) LocalState(join bool) []byte {
// MergeRemoteState implementation of the memberlist.Delegate interface
// receive and process the remote side's LocalState.
func (g *GossipMemberSet) MergeRemoteState(buf []byte, join bool) {
func (g *gossipMemberSet) MergeRemoteState(buf []byte, join bool) {
err := g.papi.ClusterMessage(context.Background(), bytes.NewBuffer(buf))
if err != nil {
g.Logger.Printf("merge state error: %s", err)
@ -343,7 +343,7 @@ func (g *gossipEventReceiver) listen() {
// Transport is a gossip transport for binding to a port.
type Transport struct {
//memberlist.Transport
Net *memberlist.NetTransport
net *memberlist.NetTransport
URI *pilosa.URI
}
@ -370,7 +370,7 @@ func NewTransport(host string, port int, logger *log.Logger) (*Transport, error)
}
return &Transport{
Net: net,
net: net,
URI: uri,
}, nil
}

View file

@ -304,7 +304,7 @@ func (h *Holder) CreateIndex(name string, opt IndexOptions) (*Index, error) {
// Ensure index doesn't already exist.
if h.indexes[name] != nil {
return nil, NewConflictError(ErrIndexExists)
return nil, newConflictError(ErrIndexExists)
}
return h.createIndex(name, opt)
}
@ -374,7 +374,7 @@ func (h *Holder) DeleteIndex(name string) error {
// Confirm index exists.
index := h.index(name)
if index == nil {
return NewNotFoundError(ErrIndexNotFound)
return newNotFoundError(ErrIndexNotFound)
}
// Close index.
@ -456,13 +456,13 @@ func (h *Holder) flushCaches() {
}
}
// RecalculateCaches recalculates caches on every index in the holder. This is
// recalculateCaches recalculates caches on every index in the holder. This is
// probably not practical to call in real-world workloads, but makes writing
// integration tests much eaiser, since one doesn't have to wait 10 seconds
// after setting bits to get expected response.
func (h *Holder) RecalculateCaches() {
func (h *Holder) recalculateCaches() {
for _, index := range h.Indexes() {
index.RecalculateCaches()
index.recalculateCaches()
}
}

View file

@ -38,7 +38,7 @@ type InternalClient struct {
serializer pilosa.Serializer
// The client to use for HTTP communication.
HTTPClient *http.Client
httpClient *http.Client
}
// NewInternalClient returns a new instance of InternalClient to connect to host.
@ -60,7 +60,7 @@ func NewInternalClientFromURI(defaultURI *pilosa.URI, remoteClient *http.Client)
return &InternalClient{
defaultURI: defaultURI,
serializer: proto.Serializer{},
HTTPClient: remoteClient,
httpClient: remoteClient,
}
}
@ -84,7 +84,7 @@ func (c *InternalClient) maxShardByIndex(ctx context.Context) (map[string]uint64
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, errors.Wrap(err, "executing request")
}
@ -115,7 +115,7 @@ func (c *InternalClient) Schema(ctx context.Context) ([]*pilosa.IndexInfo, error
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, errors.Wrap(err, "executing request")
}
@ -152,7 +152,7 @@ func (c *InternalClient) CreateIndex(ctx context.Context, index string, opt pilo
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return errors.Wrap(err, "executing request")
}
@ -191,7 +191,7 @@ func (c *InternalClient) FragmentNodes(ctx context.Context, index string, shard
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, errors.Wrap(err, "executing request")
}
@ -238,7 +238,7 @@ func (c *InternalClient) QueryNode(ctx context.Context, uri *pilosa.URI, index s
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, errors.Wrap(err, "executing request")
}
@ -390,7 +390,7 @@ func (c *InternalClient) importNode(ctx context.Context, node *pilosa.Node, inde
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return errors.Wrap(err, "executing request")
}
@ -512,7 +512,7 @@ func (c *InternalClient) exportNodeCSV(ctx context.Context, node *pilosa.Node, i
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return errors.Wrap(err, "executing request")
}
@ -555,7 +555,7 @@ func (c *InternalClient) backupShardNode(ctx context.Context, index, field strin
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, errors.Wrap(err, "executing request")
}
@ -599,7 +599,7 @@ func (c *InternalClient) CreateField(ctx context.Context, index, field string) e
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
// Execute request against the host.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return errors.Wrap(err, "executing request")
}
@ -645,7 +645,7 @@ func (c *InternalClient) FragmentBlocks(ctx context.Context, uri *pilosa.URI, in
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, errors.Wrap(err, "executing request")
}
@ -693,7 +693,7 @@ func (c *InternalClient) BlockData(ctx context.Context, uri *pilosa.URI, index,
req.Header.Set("Accept", "application/protobuf")
req.Header.Set("User-Agent", "pilosa/"+pilosa.Version)
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, nil, errors.Wrap(err, "executing request")
}
@ -741,7 +741,7 @@ func (c *InternalClient) ColumnAttrDiff(ctx context.Context, uri *pilosa.URI, in
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, errors.Wrap(err, "executing request")
}
@ -785,7 +785,7 @@ func (c *InternalClient) RowAttrDiff(ctx context.Context, uri *pilosa.URI, index
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return nil, errors.Wrap(err, "executing request")
}
@ -820,7 +820,7 @@ func (c *InternalClient) SendMessage(ctx context.Context, uri *pilosa.URI, msg [
req.Header.Set("Accept", "application/json")
// Execute request.
resp, err := c.HTTPClient.Do(req.WithContext(ctx))
resp, err := c.httpClient.Do(req.WithContext(ctx))
if err != nil {
return fmt.Errorf("executing http request: %v", err)
}

View file

@ -17,7 +17,7 @@ package http
// Error defines a standard application error.
type Error struct {
// Machine-readable error code.
Code string `json:"code,omitempty"`
code string `json:"code,omitempty"`
// Human-readable message.
Message string `json:"message"`

View file

@ -44,14 +44,14 @@ import (
type Handler struct {
Handler http.Handler
Logger pilosa.Logger
logger pilosa.Logger
// Keeps the query argument validators for each handler
validators map[string]*queryValidationSpec
API *pilosa.API
api *pilosa.API
AllowedOrigins []string
allowedOrigins []string
ln net.Listener
@ -75,10 +75,10 @@ type errorResponse struct {
Error string `json:"error"`
}
// HandlerOption is a functional option type for pilosa.Handler
type HandlerOption func(s *Handler) error
// handlerOption is a functional option type for pilosa.Handler
type handlerOption func(s *Handler) error
func OptHandlerAllowedOrigins(origins []string) HandlerOption {
func OptHandlerAllowedOrigins(origins []string) handlerOption {
return func(h *Handler) error {
h.Handler = handlers.CORS(
handlers.AllowedOrigins(origins),
@ -88,21 +88,21 @@ func OptHandlerAllowedOrigins(origins []string) HandlerOption {
}
}
func OptHandlerAPI(api *pilosa.API) HandlerOption {
func OptHandlerAPI(api *pilosa.API) handlerOption {
return func(h *Handler) error {
h.API = api
h.api = api
return nil
}
}
func OptHandlerLogger(logger pilosa.Logger) HandlerOption {
func OptHandlerLogger(logger pilosa.Logger) handlerOption {
return func(h *Handler) error {
h.Logger = logger
h.logger = logger
return nil
}
}
func OptHandlerListener(ln net.Listener) HandlerOption {
func OptHandlerListener(ln net.Listener) handlerOption {
return func(h *Handler) error {
h.ln = ln
return nil
@ -110,11 +110,11 @@ func OptHandlerListener(ln net.Listener) HandlerOption {
}
// NewHandler returns a new instance of Handler with a default logger.
func NewHandler(opts ...HandlerOption) (*Handler, error) {
func NewHandler(opts ...handlerOption) (*Handler, error) {
handler := &Handler{
Logger: pilosa.NopLogger,
logger: pilosa.NopLogger,
}
handler.Handler = NewRouter(handler)
handler.Handler = newRouter(handler)
handler.populateValidators()
for _, opt := range opts {
@ -124,7 +124,7 @@ func NewHandler(opts ...HandlerOption) (*Handler, error) {
}
}
if handler.API == nil {
if handler.api == nil {
return nil, errors.New("must pass OptHandlerAPI")
}
@ -140,7 +140,7 @@ func NewHandler(opts ...HandlerOption) (*Handler, error) {
func (h *Handler) Serve() error {
err := h.server.Serve(h.ln)
if err != nil && err.Error() != "http: Server closed" {
h.Logger.Printf("HTTP handler terminated with error: %s\n", err)
h.logger.Printf("HTTP handler terminated with error: %s\n", err)
return errors.Wrap(err, "serve http")
}
return nil
@ -183,8 +183,8 @@ func (h *Handler) queryArgValidator(next http.Handler) http.Handler {
})
}
// NewRouter creates a new mux http router.
func NewRouter(handler *Handler) *mux.Router {
// newRouter creates a new mux http router.
func newRouter(handler *Handler) *mux.Router {
router := mux.NewRouter()
router.HandleFunc("/", handler.handleHome).Methods("GET")
router.HandleFunc("/cluster/resize/abort", handler.handlePostClusterResizeAbort).Methods("POST")
@ -240,7 +240,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
stack := debug.Stack()
msg := "PANIC: %s\n%s"
h.Logger.Printf(msg, err, stack)
h.logger.Printf(msg, err, stack)
fmt.Fprintf(w, msg, err, stack)
}
}()
@ -252,9 +252,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Calculate per request StatsD metrics when the handler is fully configured.
statsTags := make([]string, 0, 3)
longQueryTime := h.API.LongQueryTime()
longQueryTime := h.api.LongQueryTime()
if longQueryTime > 0 && dif > longQueryTime {
h.Logger.Printf("%s %s %v", r.Method, r.URL.String(), dif)
h.logger.Printf("%s %s %v", r.Method, r.URL.String(), dif)
statsTags = append(statsTags, "slow_query")
}
@ -267,7 +267,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// useragent tag identifies internal/external endpoints
statsTags = append(statsTags, "useragent:"+r.UserAgent())
stats := h.API.StatsWithTags(statsTags)
stats := h.api.StatsWithTags(statsTags)
if stats != nil {
stats.Histogram("http."+endpointName, float64(dif), 0.1)
}
@ -355,9 +355,9 @@ func (h *Handler) handleGetSchema(w http.ResponseWriter, r *http.Request) {
return
}
schema := h.API.Schema(r.Context())
schema := h.api.Schema(r.Context())
if err := json.NewEncoder(w).Encode(map[string]interface{}{"indexes": schema}); err != nil {
h.Logger.Printf("write schema response error: %s", err)
h.logger.Printf("write schema response error: %s", err)
}
}
@ -368,12 +368,12 @@ func (h *Handler) handleGetStatus(w http.ResponseWriter, r *http.Request) {
return
}
status := getStatusResponse{
State: h.API.State(),
Nodes: h.API.Hosts(r.Context()),
LocalID: h.API.Node().ID,
State: h.api.State(),
Nodes: h.api.Hosts(r.Context()),
LocalID: h.api.Node().ID,
}
if err := json.NewEncoder(w).Encode(status); err != nil {
h.Logger.Printf("write status response error: %s", err)
h.logger.Printf("write status response error: %s", err)
}
}
@ -382,9 +382,9 @@ func (h *Handler) handleGetInfo(w http.ResponseWriter, r *http.Request) {
http.Error(w, "JSON only acceptable response", http.StatusNotAcceptable)
return
}
info := h.API.Info()
info := h.api.Info()
if err := json.NewEncoder(w).Encode(info); err != nil {
h.Logger.Printf("write info response error: %s", err)
h.logger.Printf("write info response error: %s", err)
}
}
@ -410,7 +410,7 @@ func (h *Handler) handlePostQuery(w http.ResponseWriter, r *http.Request) {
// TODO: Remove
req.Index = mux.Vars(r)["index"]
resp, err := h.API.Query(r.Context(), req)
resp, err := h.api.Query(r.Context(), req)
if err != nil {
switch errors.Cause(resp.Err) {
case pilosa.ErrTooManyWrites:
@ -436,7 +436,7 @@ func (h *Handler) handlePostQuery(w http.ResponseWriter, r *http.Request) {
// Write response back to client.
if err := h.writeQueryResponse(w, r, &resp); err != nil {
h.Logger.Printf("write query response error: %s", err)
h.logger.Printf("write query response error: %s", err)
}
}
@ -447,9 +447,9 @@ func (h *Handler) handleGetShardsMax(w http.ResponseWriter, r *http.Request) {
return
}
if err := json.NewEncoder(w).Encode(getShardsMaxResponse{
Standard: h.API.MaxShards(r.Context()),
Standard: h.api.MaxShards(r.Context()),
}); err != nil {
h.Logger.Printf("write shards-max response error: %s", err)
h.logger.Printf("write shards-max response error: %s", err)
}
}
@ -469,10 +469,10 @@ func (h *Handler) handleGetIndex(w http.ResponseWriter, r *http.Request) {
return
}
indexName := mux.Vars(r)["index"]
for _, idx := range h.API.Schema(r.Context()) {
for _, idx := range h.api.Schema(r.Context()) {
if idx.Name == indexName {
if err := json.NewEncoder(w).Encode(idx); err != nil {
h.Logger.Printf("write response error: %s", err)
h.logger.Printf("write response error: %s", err)
}
return
}
@ -563,7 +563,7 @@ func (h *Handler) handleDeleteIndex(w http.ResponseWriter, r *http.Request) {
indexName := mux.Vars(r)["index"]
resp := successResponse{}
err := h.API.DeleteIndex(r.Context(), indexName)
err := h.api.DeleteIndex(r.Context(), indexName)
resp.write(w, err)
}
@ -584,7 +584,7 @@ func (h *Handler) handlePostIndex(w http.ResponseWriter, r *http.Request) {
resp.write(w, err)
return
}
_, err = h.API.CreateIndex(r.Context(), indexName, req.Options)
_, err = h.api.CreateIndex(r.Context(), indexName, req.Options)
resp.write(w, err)
}
@ -604,7 +604,7 @@ func (h *Handler) handlePostIndexAttrDiff(w http.ResponseWriter, r *http.Request
return
}
attrs, err := h.API.IndexAttrDiff(r.Context(), indexName, req.Blocks)
attrs, err := h.api.IndexAttrDiff(r.Context(), indexName, req.Blocks)
if err != nil {
if errors.Cause(err) == pilosa.ErrIndexNotFound {
http.Error(w, err.Error(), http.StatusNotFound)
@ -618,7 +618,7 @@ func (h *Handler) handlePostIndexAttrDiff(w http.ResponseWriter, r *http.Request
if err := json.NewEncoder(w).Encode(postIndexAttrDiffResponse{
Attrs: attrs,
}); err != nil {
h.Logger.Printf("response encoding error: %s", err)
h.logger.Printf("response encoding error: %s", err)
}
}
@ -673,7 +673,7 @@ func (h *Handler) handlePostField(w http.ResponseWriter, r *http.Request) {
}
}
_, err = h.API.CreateField(r.Context(), indexName, fieldName, fos...)
_, err = h.api.CreateField(r.Context(), indexName, fieldName, fos...)
resp.write(w, err)
}
@ -760,7 +760,7 @@ func (h *Handler) handleDeleteField(w http.ResponseWriter, r *http.Request) {
fieldName := mux.Vars(r)["field"]
resp := successResponse{}
err := h.API.DeleteField(r.Context(), indexName, fieldName)
err := h.api.DeleteField(r.Context(), indexName, fieldName)
resp.write(w, err)
}
@ -780,7 +780,7 @@ func (h *Handler) handlePostFieldAttrDiff(w http.ResponseWriter, r *http.Request
return
}
attrs, err := h.API.FieldAttrDiff(r.Context(), indexName, fieldName, req.Blocks)
attrs, err := h.api.FieldAttrDiff(r.Context(), indexName, fieldName, req.Blocks)
if err != nil {
switch errors.Cause(err) {
case pilosa.ErrFragmentNotFound:
@ -795,7 +795,7 @@ func (h *Handler) handlePostFieldAttrDiff(w http.ResponseWriter, r *http.Request
if err := json.NewEncoder(w).Encode(postFieldAttrDiffResponse{
Attrs: attrs,
}); err != nil {
h.Logger.Printf("response encoding error: %s", err)
h.logger.Printf("response encoding error: %s", err)
}
}
@ -826,7 +826,7 @@ func (h *Handler) readProtobufQueryRequest(r *http.Request) (*pilosa.QueryReques
}
qreq := &pilosa.QueryRequest{}
err = h.API.Serializer.Unmarshal(body, qreq)
err = h.api.Serializer.Unmarshal(body, qreq)
if err != nil {
return nil, errors.Wrap(err, "unmarshalling query request")
}
@ -869,7 +869,7 @@ func (h *Handler) writeQueryResponse(w http.ResponseWriter, r *http.Request, res
// writeProtobufQueryResponse writes the response from the executor to w as protobuf.
func (h *Handler) writeProtobufQueryResponse(w http.ResponseWriter, resp *pilosa.QueryResponse) error {
if buf, err := h.API.Serializer.Marshal(resp); err != nil {
if buf, err := h.api.Serializer.Marshal(resp); err != nil {
return errors.Wrap(err, "marshalling")
} else if _, err := w.Write(buf); err != nil {
return errors.Wrap(err, "writing")
@ -897,7 +897,7 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) {
// Get index and field type to determine how to handle the
// import data.
field, err := h.API.Field(r.Context(), indexName, fieldName)
field, err := h.api.Field(r.Context(), indexName, fieldName)
if err != nil {
switch errors.Cause(err) {
case pilosa.ErrIndexNotFound:
@ -922,12 +922,12 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) {
// Field type: Int
// Marshal into request object.
req := &pilosa.ImportValueRequest{}
if err := h.API.Serializer.Unmarshal(body, req); err != nil {
if err := h.api.Serializer.Unmarshal(body, req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if err := h.API.ImportValue(r.Context(), req); err != nil {
if err := h.api.ImportValue(r.Context(), req); err != nil {
switch errors.Cause(err) {
case pilosa.ErrClusterDoesNotOwnShard:
http.Error(w, err.Error(), http.StatusPreconditionFailed)
@ -940,12 +940,12 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) {
// Field type: Set, Time
// Marshal into request object.
req := &pilosa.ImportRequest{}
if err := h.API.Serializer.Unmarshal(body, req); err != nil {
if err := h.api.Serializer.Unmarshal(body, req); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if err := h.API.Import(r.Context(), req); err != nil {
if err := h.api.Import(r.Context(), req); err != nil {
switch errors.Cause(err) {
case pilosa.ErrClusterDoesNotOwnShard:
http.Error(w, err.Error(), http.StatusPreconditionFailed)
@ -957,7 +957,7 @@ func (h *Handler) handlePostImport(w http.ResponseWriter, r *http.Request) {
}
// Marshal response object.
buf, e := h.API.Serializer.Marshal(&pilosa.ImportResponse{Err: ""})
buf, e := h.api.Serializer.Marshal(&pilosa.ImportResponse{Err: ""})
if e != nil {
http.Error(w, fmt.Sprintf("marshal import response"), http.StatusInternalServerError)
return
@ -988,7 +988,7 @@ func (h *Handler) handleGetExportCSV(w http.ResponseWriter, r *http.Request) {
return
}
if err = h.API.ExportCSV(r.Context(), index, field, shard, w); err != nil {
if err = h.api.ExportCSV(r.Context(), index, field, shard, w); err != nil {
switch errors.Cause(err) {
case pilosa.ErrFragmentNotFound:
break
@ -1018,7 +1018,7 @@ func (h *Handler) handleGetFragmentNodes(w http.ResponseWriter, r *http.Request)
}
// Retrieve fragment owner nodes.
nodes, err := h.API.ShardNodes(r.Context(), index, shard)
nodes, err := h.api.ShardNodes(r.Context(), index, shard)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
@ -1026,13 +1026,13 @@ func (h *Handler) handleGetFragmentNodes(w http.ResponseWriter, r *http.Request)
// Write to response.
if err := json.NewEncoder(w).Encode(nodes); err != nil {
h.Logger.Printf("json write error: %s", err)
h.logger.Printf("json write error: %s", err)
}
}
// handleGetFragmentBlockData handles GET /internal/fragment/block/data requests.
func (h *Handler) handleGetFragmentBlockData(w http.ResponseWriter, r *http.Request) {
buf, err := h.API.FragmentBlockData(r.Context(), r.Body)
buf, err := h.api.FragmentBlockData(r.Context(), r.Body)
if err != nil {
if _, ok := err.(pilosa.BadRequestError); ok {
http.Error(w, err.Error(), http.StatusBadRequest)
@ -1064,7 +1064,7 @@ func (h *Handler) handleGetFragmentBlocks(w http.ResponseWriter, r *http.Request
return
}
blocks, err := h.API.FragmentBlocks(r.Context(), q.Get("index"), q.Get("field"), shard)
blocks, err := h.api.FragmentBlocks(r.Context(), q.Get("index"), q.Get("field"), shard)
if err != nil {
if errors.Cause(err) == pilosa.ErrFragmentNotFound {
http.Error(w, err.Error(), http.StatusNotFound)
@ -1078,7 +1078,7 @@ func (h *Handler) handleGetFragmentBlocks(w http.ResponseWriter, r *http.Request
if err := json.NewEncoder(w).Encode(getFragmentBlocksResponse{
Blocks: blocks,
}); err != nil {
h.Logger.Printf("block response encoding error: %s", err)
h.logger.Printf("block response encoding error: %s", err)
}
}
@ -1095,21 +1095,21 @@ func (h *Handler) handleGetVersion(w http.ResponseWriter, r *http.Request) {
err := json.NewEncoder(w).Encode(struct {
Version string `json:"version"`
}{
Version: h.API.Version(),
Version: h.api.Version(),
})
if err != nil {
h.Logger.Printf("write version response error: %s", err)
h.logger.Printf("write version response error: %s", err)
}
}
// QueryResult types.
const (
QueryResultTypeNil uint32 = iota
queryResultTypeNil uint32 = iota
QueryResultTypeRow
QueryResultTypePairs
QueryResultTypeValCount
queryResultTypeValCount
QueryResultTypeUint64
QueryResultTypeBool
queryResultTypeBool
)
// parseUint64Slice returns a slice of uint64s from a comma-delimited string.
@ -1152,7 +1152,7 @@ func (h *Handler) handlePostClusterResizeSetCoordinator(w http.ResponseWriter, r
return
}
oldNode, newNode, err := h.API.SetCoordinator(r.Context(), req.ID)
oldNode, newNode, err := h.api.SetCoordinator(r.Context(), req.ID)
if err != nil {
if errors.Cause(err) == pilosa.ErrNodeIDNotExists {
http.Error(w, "setting new coordinator: "+err.Error(), http.StatusNotFound)
@ -1166,7 +1166,7 @@ func (h *Handler) handlePostClusterResizeSetCoordinator(w http.ResponseWriter, r
Old: oldNode,
New: newNode,
}); err != nil {
h.Logger.Printf("response encoding error: %s", err)
h.logger.Printf("response encoding error: %s", err)
}
}
@ -1193,7 +1193,7 @@ func (h *Handler) handlePostClusterResizeRemoveNode(w http.ResponseWriter, r *ht
return
}
removeNode, err := h.API.RemoveNode(req.ID)
removeNode, err := h.api.RemoveNode(req.ID)
if err != nil {
if errors.Cause(err) == pilosa.ErrNodeIDNotExists {
http.Error(w, "removing node: "+err.Error(), http.StatusNotFound)
@ -1207,7 +1207,7 @@ func (h *Handler) handlePostClusterResizeRemoveNode(w http.ResponseWriter, r *ht
if err := json.NewEncoder(w).Encode(removeNodeResponse{
Remove: removeNode,
}); err != nil {
h.Logger.Printf("response encoding error: %s", err)
h.logger.Printf("response encoding error: %s", err)
}
}
@ -1225,7 +1225,7 @@ func (h *Handler) handlePostClusterResizeAbort(w http.ResponseWriter, r *http.Re
http.Error(w, "JSON only acceptable response", http.StatusNotAcceptable)
return
}
err := h.API.ResizeAbort()
err := h.api.ResizeAbort()
var msg string
if err != nil {
switch errors.Cause(err) {
@ -1243,7 +1243,7 @@ func (h *Handler) handlePostClusterResizeAbort(w http.ResponseWriter, r *http.Re
if err := json.NewEncoder(w).Encode(clusterResizeAbortResponse{
Info: msg,
}); err != nil {
h.Logger.Printf("response encoding error: %s", err)
h.logger.Printf("response encoding error: %s", err)
}
}
@ -1252,7 +1252,7 @@ type clusterResizeAbortResponse struct {
}
func (h *Handler) handleRecalculateCaches(w http.ResponseWriter, r *http.Request) {
err := h.API.RecalculateCaches(r.Context())
err := h.api.RecalculateCaches(r.Context())
if err != nil {
http.Error(w, "recalculating caches: "+err.Error(), http.StatusInternalServerError)
return
@ -1272,14 +1272,14 @@ func (h *Handler) handlePostClusterMessage(w http.ResponseWriter, r *http.Reques
return
}
err := h.API.ClusterMessage(r.Context(), r.Body)
err := h.api.ClusterMessage(r.Context(), r.Body)
if err != nil {
// TODO this was the previous behavior, but perhaps not everything is a bad request
http.Error(w, err.Error(), http.StatusBadRequest)
}
if err := json.NewEncoder(w).Encode(defaultClusterMessageResponse{}); err != nil {
h.Logger.Printf("response encoding error: %s", err)
h.logger.Printf("response encoding error: %s", err)
}
}
@ -1291,7 +1291,7 @@ func (h *Handler) handleGetTranslateData(w http.ResponseWriter, r *http.Request)
pipeR, pipeW := io.Pipe()
err := h.API.GetTranslateData(r.Context(), pipeW, offset)
err := h.api.GetTranslateData(r.Context(), pipeW, offset)
if err != nil {
if errors.Cause(err) == pilosa.ErrNotImplemented {

View file

@ -14,41 +14,41 @@ import (
)
// Ensure implementation implements inteface.
var _ pilosa.TranslateStore = (*TranslateStore)(nil)
var _ pilosa.TranslateStore = (*translateStore)(nil)
// TranslateStore represents an implementation of TranslateStore that
// translateStore represents an implementation of translateStore that
// communicates over HTTP. This is used with the TranslateHandler.
type TranslateStore struct {
type translateStore struct {
URL string
}
// NewTranslateStore returns a new instance of TranslateStore.
func NewTranslateStore(rawurl string) *TranslateStore {
return &TranslateStore{URL: rawurl}
func NewTranslateStore(rawurl string) *translateStore {
return &translateStore{URL: rawurl}
}
// TranslateColumnsToUint64 is not currently implemented.
func (s *TranslateStore) TranslateColumnsToUint64(index string, values []string) ([]uint64, error) {
func (s *translateStore) TranslateColumnsToUint64(index string, values []string) ([]uint64, error) {
return nil, pilosa.ErrNotImplemented
}
// TranslateColumnToString is not currently implemented.
func (s *TranslateStore) TranslateColumnToString(index string, values uint64) (string, error) {
func (s *translateStore) TranslateColumnToString(index string, values uint64) (string, error) {
return "", pilosa.ErrNotImplemented
}
// TranslateRowsToUint64 is not currently implemented.
func (s *TranslateStore) TranslateRowsToUint64(index, frame string, values []string) ([]uint64, error) {
func (s *translateStore) TranslateRowsToUint64(index, frame string, values []string) ([]uint64, error) {
return nil, pilosa.ErrNotImplemented
}
// TranslateRowToString is not currently implemented.
func (s *TranslateStore) TranslateRowToString(index, frame string, values uint64) (string, error) {
func (s *translateStore) TranslateRowToString(index, frame string, values uint64) (string, error) {
return "", pilosa.ErrNotImplemented
}
// Reader returns a reader that can stream data from a remote store.
func (s *TranslateStore) Reader(ctx context.Context, off int64) (io.ReadCloser, error) {
func (s *translateStore) Reader(ctx context.Context, off int64) (io.ReadCloser, error) {
// Generate remote URL.
u, err := url.Parse(s.URL)
if err != nil {

View file

@ -139,7 +139,7 @@ func (i *Index) openFields() error {
continue
}
fld, err := i.newField(i.FieldPath(filepath.Base(fi.Name())), filepath.Base(fi.Name()))
fld, err := i.newField(i.fieldPath(filepath.Base(fi.Name())), filepath.Base(fi.Name()))
if err != nil {
return ErrName
}
@ -220,7 +220,7 @@ func (i *Index) maxShard() uint64 {
max := i.remoteMaxShard
for _, f := range i.fields {
if shard := f.MaxShard(); shard > max {
if shard := f.maxShard(); shard > max {
max = shard
}
}
@ -236,8 +236,8 @@ func (i *Index) setRemoteMaxShard(newmax uint64) {
i.remoteMaxShard = newmax
}
// FieldPath returns the path to a field in the index.
func (i *Index) FieldPath(name string) string { return filepath.Join(i.path, name) }
// fieldPath returns the path to a field in the index.
func (i *Index) fieldPath(name string) string { return filepath.Join(i.path, name) }
// Field returns a field in the index by name.
func (i *Index) Field(name string) *Field {
@ -262,10 +262,10 @@ func (i *Index) Fields() []*Field {
return a
}
// RecalculateCaches recalculates caches on every field in the index.
func (i *Index) RecalculateCaches() {
// recalculateCaches recalculates caches on every field in the index.
func (i *Index) recalculateCaches() {
for _, field := range i.Fields() {
field.RecalculateCaches()
field.recalculateCaches()
}
}
@ -276,7 +276,7 @@ func (i *Index) CreateField(name string, opts ...FieldOption) (*Field, error) {
// Ensure field doesn't already exist.
if i.fields[name] != nil {
return nil, NewConflictError(ErrFieldExists)
return nil, newConflictError(ErrFieldExists)
}
// Apply functional options.
@ -331,7 +331,7 @@ func (i *Index) createField(name string, opt FieldOptions) (*Field, error) {
}
// Initialize field.
f, err := i.newField(i.FieldPath(name), name)
f, err := i.newField(i.fieldPath(name), name)
if err != nil {
return nil, errors.Wrap(err, "initializing")
}
@ -363,7 +363,7 @@ func (i *Index) newField(path, name string) (*Field, error) {
if err != nil {
return nil, err
}
f.Logger = i.logger
f.logger = i.logger
f.Stats = i.Stats.WithTags(fmt.Sprintf("field:%s", name))
f.broadcaster = i.broadcaster
f.rowAttrStore = i.newAttrStore(filepath.Join(f.path, ".data"))
@ -378,7 +378,7 @@ func (i *Index) DeleteField(name string) error {
// Confirm field exists.
f := i.field(name)
if f == nil {
return NewNotFoundError(ErrFieldNotFound)
return newNotFoundError(ErrFieldNotFound)
}
// Close field.
@ -387,7 +387,7 @@ func (i *Index) DeleteField(name string) error {
}
// Delete field directory.
if err := os.RemoveAll(i.FieldPath(name)); err != nil {
if err := os.RemoveAll(i.fieldPath(name)); err != nil {
return errors.Wrap(err, "removing directory")
}
@ -406,7 +406,7 @@ func (p indexSlice) Less(i, j int) bool { return p[i].Name() < p[j].Name() }
// IndexInfo represents schema information for an index.
type IndexInfo struct {
Name string `json:"name"`
Options IndexOptions `json:"options"`
options IndexOptions `json:"options"`
Fields []*FieldInfo `json:"fields"`
}

View file

@ -9,10 +9,10 @@ import (
)
// Ensure type implements interface.
var _ pilosa.TranslateStore = &TranslateStore{}
var _ pilosa.TranslateStore = &translateStore{}
// TranslateStore is an in-memory storage engine for translating string-to-uint64 values.
type TranslateStore struct {
// translateStore is an in-memory storage engine for translating string-to-uint64 values.
type translateStore struct {
mu sync.RWMutex
cols map[string]*translateIndex
@ -20,21 +20,21 @@ type TranslateStore struct {
}
// NewTranslateStore returns a new instance of TranslateStore.
func NewTranslateStore() *TranslateStore {
return &TranslateStore{
func NewTranslateStore() *translateStore {
return &translateStore{
cols: make(map[string]*translateIndex),
rows: make(map[frameKey]*translateIndex),
}
}
// Reader returns an error because it is not supported by the inmem store.
func (s *TranslateStore) Reader(ctx context.Context, offset int64) (io.ReadCloser, error) {
func (s *translateStore) Reader(ctx context.Context, offset int64) (io.ReadCloser, error) {
return nil, pilosa.ErrReplicationNotSupported
}
// TranslateColumnsToUint64 converts value to a uint64 id.
// If value does not have an associated id then one is created.
func (s *TranslateStore) TranslateColumnsToUint64(index string, values []string) ([]uint64, error) {
func (s *translateStore) TranslateColumnsToUint64(index string, values []string) ([]uint64, error) {
ret := make([]uint64, len(values))
// Read value under read lock.
@ -103,7 +103,7 @@ func (s *TranslateStore) TranslateColumnsToUint64(index string, values []string)
// TranslateColumnToString converts a uint64 id to its associated string value.
// If the id is not associated with a string value then a blank string is returned.
func (s *TranslateStore) TranslateColumnToString(index string, value uint64) (string, error) {
func (s *translateStore) TranslateColumnToString(index string, value uint64) (string, error) {
s.mu.RLock()
if idx := s.cols[index]; idx != nil {
if ret, ok := idx.reverse[value]; ok {
@ -115,7 +115,7 @@ func (s *TranslateStore) TranslateColumnToString(index string, value uint64) (st
return "", nil
}
func (s *TranslateStore) TranslateRowsToUint64(index, frame string, values []string) ([]uint64, error) {
func (s *translateStore) TranslateRowsToUint64(index, frame string, values []string) ([]uint64, error) {
key := frameKey{index, frame}
ret := make([]uint64, len(values))
@ -184,7 +184,7 @@ func (s *TranslateStore) TranslateRowsToUint64(index, frame string, values []str
return ret, nil
}
func (s *TranslateStore) TranslateRowToString(index, frame string, value uint64) (string, error) {
func (s *translateStore) TranslateRowToString(index, frame string, value uint64) (string, error) {
s.mu.RLock()
if idx := s.rows[frameKey{index, frame}]; idx != nil {
if ret, ok := idx.reverse[value]; ok {

View file

@ -43,46 +43,46 @@ func (n *nopLogger) Printf(format string, v ...interface{}) {}
// Debugf is a no-op implementation of the Logger Debugf method.
func (n *nopLogger) Debugf(format string, v ...interface{}) {}
// StandardLogger is a basic implementation of pilosa.Logger based on log.Logger.
type StandardLogger struct {
// standardLogger is a basic implementation of pilosa.Logger based on log.Logger.
type standardLogger struct {
logger *log.Logger
}
func NewStandardLogger(w io.Writer) *StandardLogger {
return &StandardLogger{
func NewStandardLogger(w io.Writer) *standardLogger {
return &standardLogger{
logger: log.New(w, "", log.LstdFlags),
}
}
func (s *StandardLogger) Printf(format string, v ...interface{}) {
func (s *standardLogger) Printf(format string, v ...interface{}) {
s.logger.Printf(format, v...)
}
func (s *StandardLogger) Debugf(format string, v ...interface{}) {}
func (s *standardLogger) Debugf(format string, v ...interface{}) {}
func (s *StandardLogger) Logger() *log.Logger {
func (s *standardLogger) Logger() *log.Logger {
return s.logger
}
// VerboseLogger is an implementation of pilosa.Logger which includes debug messages.
type VerboseLogger struct {
// verboseLogger is an implementation of pilosa.Logger which includes debug messages.
type verboseLogger struct {
logger *log.Logger
}
func NewVerboseLogger(w io.Writer) *VerboseLogger {
return &VerboseLogger{
func NewVerboseLogger(w io.Writer) *verboseLogger {
return &verboseLogger{
logger: log.New(w, "", log.LstdFlags),
}
}
func (vb *VerboseLogger) Printf(format string, v ...interface{}) {
func (vb *verboseLogger) Printf(format string, v ...interface{}) {
vb.logger.Printf(format, v...)
}
func (vb *VerboseLogger) Debugf(format string, v ...interface{}) {
func (vb *verboseLogger) Debugf(format string, v ...interface{}) {
vb.logger.Printf(format, v...)
}
func (vb *VerboseLogger) Logger() *log.Logger {
func (vb *verboseLogger) Logger() *log.Logger {
return vb.logger
}

View file

@ -21,9 +21,9 @@ import "container/list"
// Cache is an LRU cache. It is not safe for concurrent access.
type Cache struct {
// MaxEntries is the maximum number of cache entries before
// maxEntries is the maximum number of cache entries before
// an item is evicted. Zero means no limit.
MaxEntries int
maxEntries int
// OnEvicted optionally specificies a callback function to be
// executed when an entry is purged from the cache.
@ -46,7 +46,7 @@ type entry struct {
// that eviction is done by the caller.
func New(maxEntries int) *Cache {
return &Cache{
MaxEntries: maxEntries,
maxEntries: maxEntries,
ll: list.New(),
cache: make(map[interface{}]*list.Element),
}
@ -65,8 +65,8 @@ func (c *Cache) Add(key Key, value interface{}) {
}
ele := c.ll.PushFront(&entry{key, value})
c.cache[key] = ele
if c.MaxEntries != 0 && c.ll.Len() > c.MaxEntries {
c.RemoveOldest()
if c.maxEntries != 0 && c.ll.Len() > c.maxEntries {
c.removeOldest()
}
}
@ -82,8 +82,8 @@ func (c *Cache) Get(key Key) (value interface{}, ok bool) {
return
}
// Remove removes the provided key from the cache.
func (c *Cache) Remove(key Key) {
// remove removes the provided key from the cache.
func (c *Cache) remove(key Key) {
if c.cache == nil {
return
}
@ -92,8 +92,8 @@ func (c *Cache) Remove(key Key) {
}
}
// RemoveOldest removes the oldest item from the cache.
func (c *Cache) RemoveOldest() {
// removeOldest removes the oldest item from the cache.
func (c *Cache) removeOldest() {
if c.cache == nil {
return
}
@ -120,8 +120,8 @@ func (c *Cache) Len() int {
return c.ll.Len()
}
// Clear purges all stored items from the cache.
func (c *Cache) Clear() {
// clear purges all stored items from the cache.
func (c *Cache) clear() {
if c.OnEvicted != nil {
for _, e := range c.cache {
kv := e.Value.(*entry)

View file

@ -63,15 +63,15 @@ var (
ErrNotImplemented = errors.New("not implemented")
)
// ApiMethodNotAllowedError wraps an error value indicating that a particular
// apiMethodNotAllowedError wraps an error value indicating that a particular
// API method is not allowed in the current cluster state.
type ApiMethodNotAllowedError struct {
type apiMethodNotAllowedError struct {
error
}
// NewApiMethodNotAllowedError returns err wrapped in an ApiMethodNotAllowedError.
func NewApiMethodNotAllowedError(err error) ApiMethodNotAllowedError {
return ApiMethodNotAllowedError{err}
// newApiMethodNotAllowedError returns err wrapped in an ApiMethodNotAllowedError.
func newApiMethodNotAllowedError(err error) apiMethodNotAllowedError {
return apiMethodNotAllowedError{err}
}
// BadRequestError wraps an error value to signify that a request could not be
@ -93,8 +93,8 @@ type ConflictError struct {
error
}
// NewConflictError returns err wrapped in a ConflictError.
func NewConflictError(err error) ConflictError {
// newConflictError returns err wrapped in a ConflictError.
func newConflictError(err error) ConflictError {
return ConflictError{err}
}
@ -104,8 +104,8 @@ type NotFoundError struct {
error
}
// NewNotFoundError returns err wrapped in a NotFoundError.
func NewNotFoundError(err error) NotFoundError {
// newNotFoundError returns err wrapped in a NotFoundError.
func newNotFoundError(err error) NotFoundError {
return NotFoundError{err}
}
@ -159,7 +159,7 @@ func stringSlicesAreEqual(a, b []string) bool {
// using defaults when necessary.
func AddressWithDefaults(addr string) (*URI, error) {
if addr == "" {
return DefaultURI(), nil
return defaultURI(), nil
} else {
return NewURIFromAddress(addr)
}

View file

@ -312,8 +312,8 @@ func (c *Call) UintSliceArg(key string) ([]uint64, bool, error) {
}
}
// Keys returns a list of argument keys in sorted order.
func (c *Call) Keys() []string {
// keys returns a list of argument keys in sorted order.
func (c *Call) keys() []string {
a := make([]string, 0, len(c.Args))
for k := range c.Args {
a = append(a, k)
@ -369,7 +369,7 @@ func (c *Call) String() string {
}
// Write arguments in key order.
for i, key := range c.Keys() {
for i, key := range c.keys() {
if i > 0 {
buf.WriteString(", ")
}
@ -379,7 +379,7 @@ func (c *Call) String() string {
case *Condition:
fmt.Fprintf(&buf, "%v %s", key, v.String())
default:
fmt.Fprintf(&buf, "%v=%s", key, FormatValue(v))
fmt.Fprintf(&buf, "%v=%s", key, formatValue(v))
}
}
@ -408,7 +408,7 @@ type Condition struct {
// String returns the string representation of the condition.
func (cond *Condition) String() string {
return fmt.Sprintf("%s %s", cond.Op.String(), FormatValue(cond.Value))
return fmt.Sprintf("%s %s", cond.Op.String(), formatValue(cond.Value))
}
// IntSliceValue reads cond.Value as a slice of uint64.
@ -436,7 +436,7 @@ func (cond *Condition) IntSliceValue() ([]int64, error) {
}
}
func FormatValue(v interface{}) string {
func formatValue(v interface{}) string {
switch v := v.(type) {
case string:
return fmt.Sprintf("%q", v)
@ -445,7 +445,7 @@ func FormatValue(v interface{}) string {
case []uint64:
return fmt.Sprintf("%s", joinUint64Slice(v))
case time.Time:
return fmt.Sprintf("\"%s\"", v.Format(TimeFormat))
return fmt.Sprintf("\"%s\"", v.Format(timeFormat))
case *Condition:
return v.String()
default:

View file

@ -22,19 +22,19 @@ import (
"github.com/pkg/errors"
)
// TimeFormat is the go-style time format used to parse string dates.
const TimeFormat = "2006-01-02T15:04"
// timeFormat is the go-style time format used to parse string dates.
const timeFormat = "2006-01-02T15:04"
// Parser represents a parser for the PQL language.
type Parser struct {
// parser represents a parser for the PQL language.
type parser struct {
r io.Reader
//scanner *bufScanner
PQL
}
// NewParser returns a new instance of Parser.
func NewParser(r io.Reader) *Parser {
return &Parser{
func NewParser(r io.Reader) *parser {
return &parser{
r: r,
// scanner: newBufScanner(r),
}
@ -46,7 +46,7 @@ func ParseString(s string) (*Query, error) {
}
// Parse parses the next node in the query.
func (p *Parser) Parse() (*Query, error) {
func (p *parser) Parse() (*Query, error) {
buf, err := ioutil.ReadAll(p.r)
if err != nil {
return nil, errors.Wrap(err, "reading buffer to parse")

View file

@ -14,18 +14,18 @@
package roaring
type SliceContainers struct {
type sliceContainers struct {
keys []uint64
containers []*Container
lastKey uint64
lastContainer *Container
}
func NewSliceContainers() *SliceContainers {
return &SliceContainers{}
func newSliceContainers() *sliceContainers {
return &sliceContainers{}
}
func (sc *SliceContainers) Get(key uint64) *Container {
func (sc *sliceContainers) Get(key uint64) *Container {
i := search64(sc.keys, key)
if i < 0 {
return nil
@ -33,7 +33,7 @@ func (sc *SliceContainers) Get(key uint64) *Container {
return sc.containers[i]
}
func (sc *SliceContainers) Put(key uint64, c *Container) {
func (sc *sliceContainers) Put(key uint64, c *Container) {
i := search64(sc.keys, key)
// If index is negative then there's not an exact match
@ -46,7 +46,7 @@ func (sc *SliceContainers) Put(key uint64, c *Container) {
}
func (sc *SliceContainers) PutContainerValues(key uint64, containerType byte, n int, mapped bool) {
func (sc *sliceContainers) PutContainerValues(key uint64, containerType byte, n int, mapped bool) {
i := search64(sc.keys, key)
if i < 0 {
c := NewContainer()
@ -63,7 +63,7 @@ func (sc *SliceContainers) PutContainerValues(key uint64, containerType byte, n
}
func (sc *SliceContainers) Remove(key uint64) {
func (sc *sliceContainers) Remove(key uint64) {
i := search64(sc.keys, key)
if i < 0 {
return
@ -72,7 +72,7 @@ func (sc *SliceContainers) Remove(key uint64) {
sc.containers = append(sc.containers[:i], sc.containers[i+1:]...)
}
func (sc *SliceContainers) insertAt(key uint64, c *Container, i int) {
func (sc *sliceContainers) insertAt(key uint64, c *Container, i int) {
sc.keys = append(sc.keys, 0)
copy(sc.keys[i+1:], sc.keys[i:])
sc.keys[i] = key
@ -82,7 +82,7 @@ func (sc *SliceContainers) insertAt(key uint64, c *Container, i int) {
sc.containers[i] = c
}
func (sc *SliceContainers) GetOrCreate(key uint64) *Container {
func (sc *sliceContainers) GetOrCreate(key uint64) *Container {
// Check the last* cache for same container.
if key == sc.lastKey && sc.lastContainer != nil {
return sc.lastContainer
@ -101,8 +101,8 @@ func (sc *SliceContainers) GetOrCreate(key uint64) *Container {
return sc.lastContainer
}
func (sc *SliceContainers) Clone() Containers {
other := NewSliceContainers()
func (sc *sliceContainers) Clone() Containers {
other := newSliceContainers()
other.keys = make([]uint64, len(sc.keys))
other.containers = make([]*Container, len(sc.containers))
copy(other.keys, sc.keys)
@ -112,19 +112,19 @@ func (sc *SliceContainers) Clone() Containers {
return other
}
func (sc *SliceContainers) Last() (key uint64, c *Container) {
func (sc *sliceContainers) Last() (key uint64, c *Container) {
if len(sc.keys) == 0 {
return 0, nil
}
return sc.keys[len(sc.keys)-1], sc.containers[len(sc.keys)-1]
}
func (sc *SliceContainers) Size() int {
func (sc *sliceContainers) Size() int {
return len(sc.keys)
}
func (sc *SliceContainers) Count() uint64 {
func (sc *sliceContainers) Count() uint64 {
n := uint64(0)
for i := range sc.containers {
n += uint64(sc.containers[i].n)
@ -132,14 +132,14 @@ func (sc *SliceContainers) Count() uint64 {
return n
}
func (sc *SliceContainers) Reset() {
func (sc *sliceContainers) Reset() {
sc.keys = sc.keys[:0]
sc.containers = sc.containers[:0]
sc.lastContainer = nil
sc.lastKey = 0
}
func (sc *SliceContainers) seek(key uint64) (int, bool) {
func (sc *sliceContainers) seek(key uint64) (int, bool) {
i := search64(sc.keys, key)
found := true
if i < 0 {
@ -149,19 +149,19 @@ func (sc *SliceContainers) seek(key uint64) (int, bool) {
return i, found
}
func (sc *SliceContainers) Iterator(key uint64) (citer ContainerIterator, found bool) {
func (sc *sliceContainers) Iterator(key uint64) (citer ContainerIterator, found bool) {
i, found := sc.seek(key)
return &SliceIterator{e: sc, i: i}, found
return &sliceIterator{e: sc, i: i}, found
}
type SliceIterator struct {
e *SliceContainers
type sliceIterator struct {
e *sliceContainers
i int
key uint64
value *Container
}
func (si *SliceIterator) Next() bool {
func (si *sliceIterator) Next() bool {
if si.e == nil || si.i > len(si.e.keys)-1 {
return false
}
@ -172,6 +172,6 @@ func (si *SliceIterator) Next() bool {
return true
}
func (si *SliceIterator) Value() (uint64, *Container) {
func (si *sliceIterator) Value() (uint64, *Container) {
return si.key, si.value
}

View file

@ -51,14 +51,14 @@ const (
// bitmapN is the number of values in a container.bitmap.
bitmapN = (1 << 16) / 64
//ContainerArray indicates a container of bit position values
ContainerArray = byte(1)
//containerArray indicates a container of bit position values
containerArray = byte(1)
//ContainerBitmap indicates a container of bits packed in a uint64 array block
ContainerBitmap = byte(2)
//containerBitmap indicates a container of bits packed in a uint64 array block
containerBitmap = byte(2)
//ContainerRun indicates a container of run encoded bits
ContainerRun = byte(3)
//containerRun indicates a container of run encoded bits
containerRun = byte(3)
maxContainerVal = 0xffff
)
@ -117,7 +117,7 @@ type Bitmap struct {
// NewBitmap returns a Bitmap with an initial set of values.
func NewBitmap(a ...uint64) *Bitmap {
b := &Bitmap{
Containers: NewSliceContainers(),
Containers: newSliceContainers(),
}
b.Add(a...)
return b
@ -500,7 +500,7 @@ func (b *Bitmap) Optimize() {
citer, _ := b.Containers.Iterator(0)
for citer.Next() {
_, c := citer.Value()
c.Optimize()
c.optimize()
}
}
@ -657,18 +657,18 @@ func (b *Bitmap) UnmarshalBinary(data []byte) error {
citer.Next()
_, c := citer.Value()
switch c.containerType {
case ContainerRun:
case containerRun:
c.array = nil
c.bitmap = nil
runCount := binary.LittleEndian.Uint16(data[offset : offset+runCountHeaderSize])
c.runs = (*[0xFFFFFFF]interval16)(unsafe.Pointer(&data[offset+runCountHeaderSize]))[:runCount]
opsOffset = int(offset) + runCountHeaderSize + len(c.runs)*interval16Size
case ContainerArray:
case containerArray:
c.runs = nil
c.bitmap = nil
c.array = (*[0xFFFFFFF]uint16)(unsafe.Pointer(&data[offset]))[:c.n]
opsOffset = int(offset) + len(c.array)*2 // sizeof(uint32)
case ContainerBitmap:
case containerBitmap:
c.array = nil
c.runs = nil
c.bitmap = (*[0xFFFFFFF]uint64)(unsafe.Pointer(&data[offset]))[:bitmapN]
@ -725,10 +725,10 @@ func (b *Bitmap) Iterator() *Iterator {
}
// Info returns stats for the bitmap.
func (b *Bitmap) Info() BitmapInfo {
info := BitmapInfo{
func (b *Bitmap) Info() bitmapInfo {
info := bitmapInfo{
OpN: b.opN,
Containers: make([]ContainerInfo, 0, b.Containers.Size()),
Containers: make([]containerInfo, 0, b.Containers.Size()),
}
citer, _ := b.Containers.Iterator(0)
@ -788,10 +788,10 @@ func (b *Bitmap) Flip(start, end uint64) *Bitmap {
return result
}
// BitmapInfo represents a point-in-time snapshot of bitmap stats.
type BitmapInfo struct {
// bitmapInfo represents a point-in-time snapshot of bitmap stats.
type bitmapInfo struct {
OpN int
Containers []ContainerInfo
Containers []containerInfo
}
// Iterator represents an iterator over a Bitmap.
@ -987,8 +987,8 @@ func (itr *Iterator) peek() uint64 {
// ArrayMaxSize represents the maximum size of array containers.
const ArrayMaxSize = 4096
// RunMaxSize represents the maximum size of run length encoded containers.
const RunMaxSize = 2048
// runMaxSize represents the maximum size of run length encoded containers.
const runMaxSize = 2048
// Container represents a Container for uint16 integers.
//
@ -1021,7 +1021,7 @@ func (iv interval16) runlen() int {
// newContainer returns a new instance of container.
func NewContainer() *Container {
return &Container{containerType: ContainerArray}
return &Container{containerType: containerArray}
}
// Mapped returns true if the container is mapped directly to a byte slice
@ -1043,17 +1043,17 @@ func (c *Container) Update(containerType byte, n int, mapped bool) {
// isArray returns true if the container is an array container.
func (c *Container) isArray() bool {
return c.containerType == ContainerArray
return c.containerType == containerArray
}
// isBitmap returns true if the container is a bitmap container.
func (c *Container) isBitmap() bool {
return c.containerType == ContainerBitmap
return c.containerType == containerBitmap
}
// isRun returns true if the container is a run-length-encoded container.
func (c *Container) isRun() bool {
return c.containerType == ContainerRun
return c.containerType == containerRun
}
// unmap creates copies of the containers data in the heap.
@ -1066,15 +1066,15 @@ func (c *Container) unmap() {
}
switch c.containerType {
case ContainerArray:
case containerArray:
tmp := make([]uint16, len(c.array))
copy(tmp, c.array)
c.array = tmp
case ContainerBitmap:
case containerBitmap:
tmp := make([]uint64, len(c.bitmap))
copy(tmp, c.bitmap)
c.bitmap = tmp
case ContainerRun:
case containerRun:
tmp := make([]interval16, len(c.runs))
copy(tmp, c.runs)
c.runs = tmp
@ -1315,40 +1315,40 @@ func (c *Container) countRuns() (r int) {
return 0
}
// Optimize converts the container to the type which will take up the least
// optimize converts the container to the type which will take up the least
// amount of space.
func (c *Container) Optimize() {
func (c *Container) optimize() {
if c.n == 0 {
return
}
runs := c.countRuns()
var newType byte
if runs <= RunMaxSize && runs <= c.n/2 {
newType = ContainerRun
if runs <= runMaxSize && runs <= c.n/2 {
newType = containerRun
} else if c.n < ArrayMaxSize {
newType = ContainerArray
newType = containerArray
} else {
newType = ContainerBitmap
newType = containerBitmap
}
// Then convert accordingly.
if c.isArray() {
if newType == ContainerBitmap {
if newType == containerBitmap {
c.arrayToBitmap()
} else if newType == ContainerRun {
} else if newType == containerRun {
c.arrayToRun()
}
} else if c.isBitmap() {
if newType == ContainerArray {
if newType == containerArray {
c.bitmapToArray()
} else if newType == ContainerRun {
} else if newType == containerRun {
c.bitmapToRun()
}
} else if c.isRun() {
if newType == ContainerBitmap {
if newType == containerBitmap {
c.runToBitmap()
} else if newType == ContainerArray {
} else if newType == containerArray {
c.runToArray()
}
}
@ -1487,7 +1487,7 @@ func (c *Container) runMax() uint16 {
// bitmapToArray converts from bitmap format to array format.
func (c *Container) bitmapToArray() {
c.array = make([]uint16, 0, c.n)
c.containerType = ContainerArray
c.containerType = containerArray
// return early if empty
if c.n == 0 {
@ -1510,7 +1510,7 @@ func (c *Container) bitmapToArray() {
// arrayToBitmap converts from array format to bitmap format.
func (c *Container) arrayToBitmap() {
c.bitmap = make([]uint64, bitmapN)
c.containerType = ContainerBitmap
c.containerType = containerBitmap
// return early if empty
if c.n == 0 {
@ -1529,7 +1529,7 @@ func (c *Container) arrayToBitmap() {
// runToBitmap converts from RLE format to bitmap format.
func (c *Container) runToBitmap() {
c.bitmap = make([]uint64, bitmapN)
c.containerType = ContainerBitmap
c.containerType = containerBitmap
// return early if empty
if c.n == 0 {
@ -1551,7 +1551,7 @@ func (c *Container) runToBitmap() {
// bitmapToRun converts from bitmap format to RLE format.
func (c *Container) bitmapToRun() {
c.containerType = ContainerRun
c.containerType = containerRun
// return early if empty
if c.n == 0 {
c.runs = make([]interval16, 0)
@ -1607,7 +1607,7 @@ func (c *Container) bitmapToRun() {
// arrayToRun converts from array format to RLE format.
func (c *Container) arrayToRun() {
c.containerType = ContainerRun
c.containerType = containerRun
// return early if empty
if c.n == 0 {
c.runs = make([]interval16, 0)
@ -1634,7 +1634,7 @@ func (c *Container) arrayToRun() {
// runToArray converts from RLE format to array format.
func (c *Container) runToArray() {
c.containerType = ContainerArray
c.containerType = containerArray
c.array = make([]uint16, 0, c.n)
// return early if empty
@ -1658,13 +1658,13 @@ func (c *Container) Clone() *Container {
other := &Container{n: c.n, containerType: c.containerType}
switch c.containerType {
case ContainerArray:
case containerArray:
other.array = make([]uint16, len(c.array))
copy(other.array, c.array)
case ContainerBitmap:
case containerBitmap:
other.bitmap = make([]uint64, len(c.bitmap))
copy(other.bitmap, c.bitmap)
case ContainerRun:
case containerRun:
other.runs = make([]interval16, len(c.runs))
copy(other.runs, c.runs)
}
@ -1730,8 +1730,8 @@ func (c *Container) size() int {
}
// info returns the current stats about the container.
func (c *Container) info() ContainerInfo {
info := ContainerInfo{N: c.n}
func (c *Container) info() containerInfo {
info := containerInfo{N: c.n}
if c.isArray() {
info.Type = "array"
@ -1787,8 +1787,8 @@ func (c *Container) check() error {
return a
}
// ContainerInfo represents a point-in-time snapshot of container stats.
type ContainerInfo struct {
// containerInfo represents a point-in-time snapshot of container stats.
type containerInfo struct {
Key uint64 // container key
Type string // container type (array, bitmap, or run)
N int // number of bits
@ -1816,7 +1816,7 @@ func flipArray(b *Container) *Container {
}
func flipBitmap(b *Container) *Container {
other := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
other := &Container{bitmap: make([]uint64, bitmapN), containerType: containerBitmap}
for i, bitmap := range b.bitmap {
other.bitmap[i] = ^bitmap
@ -1977,7 +1977,7 @@ func intersect(a, b *Container) *Container {
}
func intersectArrayArray(a, b *Container) *Container {
output := &Container{containerType: ContainerArray}
output := &Container{containerType: containerArray}
na, nb := len(a.array), len(b.array)
for i, j := 0, 0; i < na && j < nb; {
va, vb := a.array[i], b.array[j]
@ -1998,7 +1998,7 @@ func intersectArrayArray(a, b *Container) *Container {
// container. The return is always an array container (since it's guaranteed to
// be low-cardinality)
func intersectArrayRun(a, b *Container) *Container {
output := &Container{containerType: ContainerArray}
output := &Container{containerType: containerArray}
na, nb := len(a.array), len(b.runs)
for i, j := 0, 0; i < na && j < nb; {
va, vb := a.array[i], b.runs[j]
@ -2017,7 +2017,7 @@ func intersectArrayRun(a, b *Container) *Container {
// intersectRunRun computes the intersect of two run containers.
func intersectRunRun(a, b *Container) *Container {
output := &Container{containerType: ContainerRun}
output := &Container{containerType: containerRun}
na, nb := len(a.runs), len(b.runs)
for i, j := 0, 0; i < na && j < nb; {
va, vb := a.runs[i], b.runs[j]
@ -2047,7 +2047,7 @@ func intersectRunRun(a, b *Container) *Container {
}
if output.n < ArrayMaxSize && len(output.runs) > output.n/2 {
output.runToArray()
} else if len(output.runs) > RunMaxSize {
} else if len(output.runs) > runMaxSize {
output.runToBitmap()
}
return output
@ -2059,7 +2059,7 @@ func intersectBitmapRun(a, b *Container) *Container {
var output *Container
if b.n < ArrayMaxSize {
// output is array container
output = &Container{containerType: ContainerArray}
output = &Container{containerType: containerArray}
for _, iv := range b.runs {
for i := iv.start; i <= iv.last; i++ {
if a.bitmapContains(i) {
@ -2078,7 +2078,7 @@ func intersectBitmapRun(a, b *Container) *Container {
// the bitmap which are between runs.
output = &Container{
bitmap: make([]uint64, bitmapN),
containerType: ContainerBitmap,
containerType: containerBitmap,
}
for j := 0; j < len(b.runs); j++ {
vb := b.runs[j]
@ -2119,7 +2119,7 @@ func intersectBitmapRun(a, b *Container) *Container {
}
func intersectArrayBitmap(a, b *Container) *Container {
output := &Container{containerType: ContainerArray}
output := &Container{containerType: containerArray}
for _, va := range a.array {
bmidx := va / 64
bidx := va % 64
@ -2134,7 +2134,7 @@ func intersectArrayBitmap(a, b *Container) *Container {
}
func intersectBitmapBitmap(a, b *Container) *Container {
output := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
output := &Container{bitmap: make([]uint64, bitmapN), containerType: containerBitmap}
for i := range a.bitmap {
v := a.bitmap[i] & b.bitmap[i]
@ -2142,7 +2142,7 @@ func intersectBitmapBitmap(a, b *Container) *Container {
output.n += int(popcount(v))
}
output.Optimize()
output.optimize()
return output
}
@ -2175,7 +2175,7 @@ func union(a, b *Container) *Container {
}
func unionArrayArray(a, b *Container) *Container {
output := &Container{containerType: ContainerArray}
output := &Container{containerType: containerArray}
na, nb := len(a.array), len(b.array)
for i, j := 0, 0; ; {
if i >= na && j >= nb {
@ -2211,7 +2211,7 @@ func unionArrayRun(a, b *Container) *Container {
if b.n == maxContainerVal+1 {
return b.Clone()
}
output := &Container{containerType: ContainerRun}
output := &Container{containerType: containerRun}
na, nb := len(a.array), len(b.runs)
var vb interval16
var va uint16
@ -2232,7 +2232,7 @@ func unionArrayRun(a, b *Container) *Container {
}
if output.n < ArrayMaxSize {
output.runToArray()
} else if len(output.runs) > RunMaxSize {
} else if len(output.runs) > runMaxSize {
output.runToBitmap()
}
return output
@ -2274,7 +2274,7 @@ func unionRunRun(a, b *Container) *Container {
na, nb := len(a.runs), len(b.runs)
output := &Container{
runs: make([]interval16, 0, na+nb),
containerType: ContainerRun,
containerType: containerRun,
}
var va, vb interval16
for i, j := 0, 0; i < na || j < nb; {
@ -2292,7 +2292,7 @@ func unionRunRun(a, b *Container) *Container {
j++
}
}
if len(output.runs) > RunMaxSize {
if len(output.runs) > runMaxSize {
output.runToBitmap()
}
return output
@ -2387,7 +2387,7 @@ func (c *Container) equals(c2 *Container) bool {
if c.mapped != c2.mapped || c.containerType != c2.containerType || c.n != c2.n {
return false
}
if c.containerType == ContainerArray {
if c.containerType == containerArray {
if len(c.array) != len(c2.array) {
return false
}
@ -2396,7 +2396,7 @@ func (c *Container) equals(c2 *Container) bool {
return false
}
}
} else if c.containerType == ContainerBitmap {
} else if c.containerType == containerBitmap {
if len(c.bitmap) != len(c2.bitmap) {
return false
}
@ -2405,7 +2405,7 @@ func (c *Container) equals(c2 *Container) bool {
return false
}
}
} else if c.containerType == ContainerRun {
} else if c.containerType == containerRun {
if len(c.runs) != len(c2.runs) {
return false
}
@ -2434,7 +2434,7 @@ func unionArrayBitmap(a, b *Container) *Container {
func unionBitmapBitmap(a, b *Container) *Container {
output := &Container{
bitmap: make([]uint64, bitmapN),
containerType: ContainerBitmap,
containerType: containerBitmap,
}
for i := 0; i < bitmapN; i++ {
@ -2476,7 +2476,7 @@ func difference(a, b *Container) *Container {
// differenceArrayArray computes the difference bween two arrays.
func differenceArrayArray(a, b *Container) *Container {
output := &Container{containerType: ContainerArray}
output := &Container{containerType: containerArray}
na, nb := len(a.array), len(b.array)
for i, j := 0, 0; i < na; {
va := a.array[i]
@ -2507,7 +2507,7 @@ func differenceArrayRun(a, b *Container) *Container {
return a.Clone()
}
output := &Container{array: make([]uint16, 0, a.n), containerType: ContainerArray}
output := &Container{array: make([]uint16, 0, a.n), containerType: containerArray}
// cardinality upper bound: card(A)
i := 0 // array index
@ -2542,7 +2542,7 @@ func differenceArrayRun(a, b *Container) *Container {
// keep all array elements after end of runs
// It's possible that output was converted from array to bitmap in output.add()
// so check container type before proceeding.
if output.containerType == ContainerArray {
if output.containerType == containerArray {
output.array = append(output.array, a.array[i:]...)
// TODO: consider handling container.n mutations in one place
// like we do with container.add().
@ -2575,7 +2575,7 @@ func differenceRunArray(a, b *Container) *Container {
if a.n == 0 || b.n == 0 {
return a.Clone()
}
output := &Container{runs: make([]interval16, 0, len(a.runs)), containerType: ContainerRun}
output := &Container{runs: make([]interval16, 0, len(a.runs)), containerType: containerRun}
bidx := 0
vb := b.array[bidx]
@ -2621,7 +2621,7 @@ RUNLOOP:
output.n += int(run.last - start + 1)
}
}
output.Optimize()
output.optimize()
return output
}
@ -2631,7 +2631,7 @@ func differenceRunBitmap(a, b *Container) *Container {
if len(a.runs) > 0 && a.runs[0].start == 0 && a.runs[0].last == 65535 {
return flipBitmap(b)
}
output := &Container{containerType: ContainerRun}
output := &Container{containerType: containerRun}
output.n = a.n
if len(a.runs) == 0 {
return output
@ -2676,7 +2676,7 @@ func differenceRunBitmap(a, b *Container) *Container {
if output.n < ArrayMaxSize && len(output.runs) > output.n/2 {
output.runToArray()
} else if len(output.runs) > RunMaxSize {
} else if len(output.runs) > runMaxSize {
output.runToBitmap()
}
return output
@ -2697,7 +2697,7 @@ func differenceRunRun(a, b *Container) *Container {
alen := len(a.runs)
blen := len(b.runs)
output := &Container{runs: make([]interval16, 0, alen+blen), containerType: ContainerRun} // TODO allocate max then truncate? or something else
output := &Container{runs: make([]interval16, 0, alen+blen), containerType: containerRun} // TODO allocate max then truncate? or something else
// cardinality upper bound: sum of number of runs
// each B-run could split an A-run in two, up to len(b.runs) times
@ -2747,7 +2747,7 @@ func differenceRunRun(a, b *Container) *Container {
}
func differenceArrayBitmap(a, b *Container) *Container {
output := &Container{containerType: ContainerArray}
output := &Container{containerType: containerArray}
for _, va := range a.array {
bmidx := va / 64
bidx := va % 64
@ -2778,7 +2778,7 @@ func differenceBitmapArray(a, b *Container) *Container {
}
func differenceBitmapBitmap(a, b *Container) *Container {
output := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
output := &Container{bitmap: make([]uint64, bitmapN), containerType: containerBitmap}
for i := range a.bitmap {
v := a.bitmap[i] & (^b.bitmap[i])
@ -2821,7 +2821,7 @@ func xor(a, b *Container) *Container {
}
func xorArrayArray(a, b *Container) *Container {
output := &Container{containerType: ContainerArray}
output := &Container{containerType: containerArray}
na, nb := len(a.array), len(b.array)
for i, j := 0, 0; i < na || j < nb; {
if i < na && j >= nb {
@ -2861,7 +2861,7 @@ func xorArrayBitmap(a, b *Container) *Container {
// It's possible that output was converted from bitmap to array in output.remove()
// so we only do this conversion if output is still a bitmap container.
if output.containerType == ContainerBitmap && output.count() < ArrayMaxSize {
if output.containerType == containerBitmap && output.count() < ArrayMaxSize {
output.bitmapToArray()
}
@ -2871,7 +2871,7 @@ func xorArrayBitmap(a, b *Container) *Container {
func xorBitmapBitmap(a, b *Container) *Container {
output := &Container{
bitmap: make([]uint64, bitmapN),
containerType: ContainerBitmap,
containerType: containerBitmap,
}
for i := 0; i < bitmapN; i++ {
v := a.bitmap[i] ^ b.bitmap[i]
@ -3079,7 +3079,7 @@ func (a *ErrorList) AppendWithPrefix(err error, prefix string) {
// xorArrayRun computes the exclusive or of an array and a run container.
func xorArrayRun(a, b *Container) *Container {
output := &Container{containerType: ContainerRun}
output := &Container{containerType: containerRun}
na, nb := len(a.array), len(b.runs)
var vb interval16
var va uint16
@ -3135,7 +3135,7 @@ func xorArrayRun(a, b *Container) *Container {
}
if output.n < ArrayMaxSize {
output.runToArray()
} else if len(output.runs) > RunMaxSize {
} else if len(output.runs) > runMaxSize {
output.runToBitmap()
}
return output
@ -3248,7 +3248,7 @@ func xorRunRun(a, b *Container) *Container {
if nb == 0 {
return a.Clone()
}
output := &Container{containerType: ContainerRun}
output := &Container{containerType: containerRun}
lastI, lastJ := -1, -1
@ -3281,7 +3281,7 @@ func xorRunRun(a, b *Container) *Container {
if output.n < ArrayMaxSize && len(output.runs) > output.n/2 {
output.runToArray()
} else if len(output.runs) > RunMaxSize {
} else if len(output.runs) > runMaxSize {
output.runToBitmap()
}
return output
@ -3296,7 +3296,7 @@ func xorBitmapRun(a, b *Container) *Container {
if output.n < ArrayMaxSize && len(output.runs) > output.n/2 {
output.runToArray()
} else if len(output.runs) > RunMaxSize {
} else if len(output.runs) > runMaxSize {
output.runToBitmap()
}
return output

View file

@ -236,11 +236,11 @@ func doContainer(containerType byte, data interface{}) *Container {
}
switch containerType {
case ContainerArray:
case containerArray:
c.array = data.([]uint16)
case ContainerBitmap:
case containerBitmap:
c.bitmap = data.([]uint64)
case ContainerRun:
case containerRun:
c.runs = data.([]interval16)
}
c.n = c.count()
@ -253,45 +253,45 @@ func setupContainerTests() map[byte]map[string]*Container {
cts := make(map[byte]map[string]*Container)
// array containers
cts[ContainerArray] = map[string]*Container{
"empty": doContainer(ContainerArray, arrayEmpty()),
"full": doContainer(ContainerArray, arrayFull()),
"firstBitSet": doContainer(ContainerArray, arrayFirstBitSet()),
"lastBitSet": doContainer(ContainerArray, arrayLastBitSet()),
"firstBitUnset": doContainer(ContainerArray, arrayFirstBitUnset()),
"lastBitUnset": doContainer(ContainerArray, arrayLastBitUnset()),
"innerBitsSet": doContainer(ContainerArray, arrayInnerBitsSet()),
"outerBitsSet": doContainer(ContainerArray, arrayOuterBitsSet()),
"oddBitsSet": doContainer(ContainerArray, arrayOddBitsSet()),
"evenBitsSet": doContainer(ContainerArray, arrayEvenBitsSet()),
cts[containerArray] = map[string]*Container{
"empty": doContainer(containerArray, arrayEmpty()),
"full": doContainer(containerArray, arrayFull()),
"firstBitSet": doContainer(containerArray, arrayFirstBitSet()),
"lastBitSet": doContainer(containerArray, arrayLastBitSet()),
"firstBitUnset": doContainer(containerArray, arrayFirstBitUnset()),
"lastBitUnset": doContainer(containerArray, arrayLastBitUnset()),
"innerBitsSet": doContainer(containerArray, arrayInnerBitsSet()),
"outerBitsSet": doContainer(containerArray, arrayOuterBitsSet()),
"oddBitsSet": doContainer(containerArray, arrayOddBitsSet()),
"evenBitsSet": doContainer(containerArray, arrayEvenBitsSet()),
}
// bitmap containers
cts[ContainerBitmap] = map[string]*Container{
"empty": doContainer(ContainerBitmap, bitmapEmpty()),
"full": doContainer(ContainerBitmap, bitmapFull()),
"firstBitSet": doContainer(ContainerBitmap, bitmapFirstBitSet()),
"lastBitSet": doContainer(ContainerBitmap, bitmapLastBitSet()),
"firstBitUnset": doContainer(ContainerBitmap, bitmapFirstBitUnset()),
"lastBitUnset": doContainer(ContainerBitmap, bitmapLastBitUnset()),
"innerBitsSet": doContainer(ContainerBitmap, bitmapInnerBitsSet()),
"outerBitsSet": doContainer(ContainerBitmap, bitmapOuterBitsSet()),
"oddBitsSet": doContainer(ContainerBitmap, bitmapOddBitsSet()),
"evenBitsSet": doContainer(ContainerBitmap, bitmapEvenBitsSet()),
cts[containerBitmap] = map[string]*Container{
"empty": doContainer(containerBitmap, bitmapEmpty()),
"full": doContainer(containerBitmap, bitmapFull()),
"firstBitSet": doContainer(containerBitmap, bitmapFirstBitSet()),
"lastBitSet": doContainer(containerBitmap, bitmapLastBitSet()),
"firstBitUnset": doContainer(containerBitmap, bitmapFirstBitUnset()),
"lastBitUnset": doContainer(containerBitmap, bitmapLastBitUnset()),
"innerBitsSet": doContainer(containerBitmap, bitmapInnerBitsSet()),
"outerBitsSet": doContainer(containerBitmap, bitmapOuterBitsSet()),
"oddBitsSet": doContainer(containerBitmap, bitmapOddBitsSet()),
"evenBitsSet": doContainer(containerBitmap, bitmapEvenBitsSet()),
}
// run containers
cts[ContainerRun] = map[string]*Container{
"empty": doContainer(ContainerRun, runEmpty()),
"full": doContainer(ContainerRun, runFull()),
"firstBitSet": doContainer(ContainerRun, runFirstBitSet()),
"lastBitSet": doContainer(ContainerRun, runLastBitSet()),
"firstBitUnset": doContainer(ContainerRun, runFirstBitUnset()),
"lastBitUnset": doContainer(ContainerRun, runLastBitUnset()),
"innerBitsSet": doContainer(ContainerRun, runInnerBitsSet()),
"outerBitsSet": doContainer(ContainerRun, runOuterBitsSet()),
"oddBitsSet": doContainer(ContainerRun, runOddBitsSet()),
"evenBitsSet": doContainer(ContainerRun, runEvenBitsSet()),
cts[containerRun] = map[string]*Container{
"empty": doContainer(containerRun, runEmpty()),
"full": doContainer(containerRun, runFull()),
"firstBitSet": doContainer(containerRun, runFirstBitSet()),
"lastBitSet": doContainer(containerRun, runLastBitSet()),
"firstBitUnset": doContainer(containerRun, runFirstBitUnset()),
"lastBitUnset": doContainer(containerRun, runLastBitUnset()),
"innerBitsSet": doContainer(containerRun, runInnerBitsSet()),
"outerBitsSet": doContainer(containerRun, runOuterBitsSet()),
"oddBitsSet": doContainer(containerRun, runOddBitsSet()),
"evenBitsSet": doContainer(containerRun, runEvenBitsSet()),
}
return cts

View file

@ -33,7 +33,7 @@ func (c *Container) String() string {
}
func TestRunAppendInterval(t *testing.T) {
a := Container{containerType: ContainerRun}
a := Container{containerType: containerRun}
tests := []struct {
base []interval16
app interval16
@ -82,7 +82,7 @@ func TestInterval16RunLen(t *testing.T) {
}
func TestContainerRunAdd(t *testing.T) {
c := Container{runs: make([]interval16, 0), containerType: ContainerRun}
c := Container{runs: make([]interval16, 0), containerType: containerRun}
tests := []struct {
op uint16
exp []interval16
@ -113,7 +113,7 @@ func TestContainerRunAdd(t *testing.T) {
}
func TestContainerRunAdd2(t *testing.T) {
c := Container{runs: make([]interval16, 0), containerType: ContainerRun}
c := Container{runs: make([]interval16, 0), containerType: containerRun}
ret := c.add(0)
if !ret {
t.Fatalf("result of adding new bit should be true: %v", c.runs)
@ -128,7 +128,7 @@ func TestContainerRunAdd2(t *testing.T) {
}
func TestRunCountRange(t *testing.T) {
c := Container{runs: make([]interval16, 0), containerType: ContainerRun}
c := Container{runs: make([]interval16, 0), containerType: containerRun}
cnt := c.runCountRange(2, 9)
if cnt != 0 {
t.Fatalf("should get 0 from empty container, but got: %v", cnt)
@ -181,7 +181,7 @@ func TestRunCountRange(t *testing.T) {
}
func TestRunContains(t *testing.T) {
c := Container{runs: make([]interval16, 0), containerType: ContainerRun}
c := Container{runs: make([]interval16, 0), containerType: containerRun}
if c.runContains(5) {
t.Fatalf("empty run container should not contain 5")
}
@ -203,7 +203,7 @@ func TestRunContains(t *testing.T) {
}
func TestBitmapCountRange(t *testing.T) {
c := Container{containerType: ContainerBitmap}
c := Container{containerType: containerBitmap}
tests := []struct {
start int
end int
@ -229,11 +229,11 @@ func TestBitmapCountRange(t *testing.T) {
func TestIntersectionCountArrayBitmap3(t *testing.T) {
a, b := &Container{}, &Container{}
a.containerType = ContainerBitmap
a.containerType = containerBitmap
a.bitmap = getFullBitmap()
a.n = maxContainerVal + 1
b.containerType = ContainerBitmap
b.containerType = containerBitmap
b.bitmap = getFullBitmap()
b.n = maxContainerVal + 1
res := intersectBitmapBitmap(a, b)
@ -290,9 +290,9 @@ func TestIntersectionCountArrayBitmap2(t *testing.T) {
for i, test := range tests {
a.array = test.array
a.containerType = ContainerArray
a.containerType = containerArray
b.bitmap = test.bitmap
b.containerType = ContainerBitmap
b.containerType = containerBitmap
ret := intersectionCountArrayBitmap(a, b)
if ret != test.exp {
t.Fatalf("test #%v intersectCountArrayBitmap fail received: %v exp: %v", i, ret, test.exp)
@ -301,7 +301,7 @@ func TestIntersectionCountArrayBitmap2(t *testing.T) {
}
func TestRunRemove(t *testing.T) {
c := Container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: ContainerRun}
c := Container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: containerRun}
tests := []struct {
op uint16
exp []interval16
@ -335,7 +335,7 @@ func TestRunRemove(t *testing.T) {
}
func TestRunMax(t *testing.T) {
c := Container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: ContainerRun}
c := Container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: containerRun}
max := c.max()
if max != 16 {
t.Fatalf("max for %v should be 16", c.runs)
@ -349,8 +349,8 @@ func TestRunMax(t *testing.T) {
}
func TestIntersectionCountArrayRun(t *testing.T) {
a := &Container{containerType: ContainerArray, array: []uint16{1, 5, 10, 11, 12}}
b := &Container{containerType: ContainerRun, runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}}
a := &Container{containerType: containerArray, array: []uint16{1, 5, 10, 11, 12}}
b := &Container{containerType: containerRun, runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}}
ret := intersectionCountArrayRun(a, b)
if ret != 3 {
@ -359,16 +359,16 @@ func TestIntersectionCountArrayRun(t *testing.T) {
}
func TestIntersectionCountBitmapRun(t *testing.T) {
a := &Container{containerType: ContainerBitmap, bitmap: []uint64{0x8000000000000000}}
b := &Container{containerType: ContainerRun, runs: []interval16{{start: 63, last: 64}}}
a := &Container{containerType: containerBitmap, bitmap: []uint64{0x8000000000000000}}
b := &Container{containerType: containerRun, runs: []interval16{{start: 63, last: 64}}}
ret := intersectionCountBitmapRun(a, b)
if ret != 1 {
t.Fatalf("count of %v with %v should be 1, but got %v", a.bitmap, b.runs, ret)
}
a = &Container{containerType: ContainerBitmap, bitmap: []uint64{0xF0000001, 0xFF00000000000000, 0xFF000000000000F0, 0x0F0000}}
b = &Container{containerType: ContainerRun, runs: []interval16{{start: 29, last: 31}, {start: 125, last: 134}, {start: 191, last: 197}, {start: 200, last: 300}}}
a = &Container{containerType: containerBitmap, bitmap: []uint64{0xF0000001, 0xFF00000000000000, 0xFF000000000000F0, 0x0F0000}}
b = &Container{containerType: containerRun, runs: []interval16{{start: 29, last: 31}, {start: 125, last: 134}, {start: 191, last: 197}, {start: 200, last: 300}}}
ret = intersectionCountBitmapRun(a, b)
if ret != 14 {
@ -416,8 +416,8 @@ func TestIntersectionCountRunRun(t *testing.T) {
bruns: []interval16{{start: 9, last: 9}, {start: 11, last: 17}}, exp: 6},
}
for i, test := range tests {
a.containerType = ContainerRun
b.containerType = ContainerRun
a.containerType = containerRun
b.containerType = containerRun
a.runs = test.aruns
b.runs = test.bruns
ret := intersectionCountRunRun(a, b)
@ -458,8 +458,8 @@ func TestIntersectArrayRun(t *testing.T) {
}
for i, test := range tests {
a.containerType = ContainerArray
b.containerType = ContainerRun
a.containerType = containerArray
b.containerType = containerRun
a.array = test.array
b.runs = test.runs
ret := intersectArrayRun(a, b)
@ -516,8 +516,8 @@ func TestIntersectRunRun(t *testing.T) {
},
}
for i, test := range tests {
a.containerType = ContainerRun
b.containerType = ContainerRun
a.containerType = containerRun
b.containerType = containerRun
a.runs = test.aruns
b.runs = test.bruns
ret := intersectRunRun(a, b)
@ -581,8 +581,8 @@ func TestIntersectBitmapRunBitmap(t *testing.T) {
for i, v := range test.exp {
exp[i] = v
}
a.containerType = ContainerBitmap
b.containerType = ContainerRun
a.containerType = containerBitmap
b.containerType = containerRun
ret := intersectBitmapRun(a, b)
if ret.isArray() {
ret.arrayToBitmap()
@ -642,8 +642,8 @@ func TestIntersectBitmapRunArray(t *testing.T) {
a.bitmap[i] = v
}
b.runs = test.runs
a.containerType = ContainerBitmap
b.containerType = ContainerRun
a.containerType = containerBitmap
b.containerType = containerRun
ret := intersectBitmapRun(a, b)
if !reflect.DeepEqual(ret.array, test.exp) {
t.Fatalf("test #%v expected %v, but got %v", i, test.exp, ret.array)
@ -660,19 +660,19 @@ func TestUnionMixed(t *testing.T) {
// array container
a := &Container{}
a.array = []uint16{1, 4, 5, 7, 10, 11, 12}
a.containerType = ContainerArray
a.containerType = containerArray
a.n = 7
// bitmap container
b := &Container{bitmap: make([]uint64, bitmapN)}
b.bitmap[0] = uint64(0x3)
b.n = 2
b.containerType = ContainerBitmap
b.containerType = containerBitmap
// run container
r := &Container{}
r.runs = []interval16{{start: 5, last: 10}}
r.containerType = ContainerRun
r.containerType = containerRun
r.n = 6
t.Run("various container Unions", func(t *testing.T) {
@ -713,10 +713,10 @@ func TestIntersectMixed(t *testing.T) {
a.runs = []interval16{{start: 5, last: 10}}
a.n = 6
a.containerType = ContainerRun
a.containerType = containerRun
b.array = []uint16{1, 4, 5, 7, 10, 11, 12}
b.n = 7
b.containerType = ContainerArray
b.containerType = containerArray
res := intersect(a, b)
if !reflect.DeepEqual(res.array, []uint16{5, 7, 10}) {
t.Fatalf("test #1 expected %v, but got %v", []uint16{5, 7, 10}, res.array)
@ -732,7 +732,7 @@ func TestIntersectMixed(t *testing.T) {
}
c.bitmap = []uint64{0x60}
c.n = 2
c.containerType = ContainerBitmap
c.containerType = containerBitmap
res = intersect(c, a)
if !reflect.DeepEqual(res.array, []uint16{5, 6}) {
@ -762,15 +762,15 @@ func TestDifferenceMixed(t *testing.T) {
a.runs = []interval16{{start: 5, last: 10}}
a.n = a.runCountRange(0, 100)
a.containerType = ContainerRun
a.containerType = containerRun
b.array = []uint16{0, 2, 4, 6, 8, 10, 12}
b.n = len(b.array)
b.containerType = ContainerArray
b.containerType = containerArray
d.array = []uint16{1, 3, 5, 7, 9, 11, 12}
d.n = len(d.array)
d.containerType = ContainerArray
d.containerType = containerArray
res := difference(a, b)
@ -790,7 +790,7 @@ func TestDifferenceMixed(t *testing.T) {
c.bitmap = []uint64{0x64}
c.n = c.countRange(0, 100)
c.containerType = ContainerBitmap
c.containerType = containerBitmap
res = difference(c, a)
if !reflect.DeepEqual(res.bitmap, []uint64{0x4}) {
t.Fatalf("test #4 expected %v, but got %v", []uint16{4}, res.bitmap)
@ -885,8 +885,8 @@ func TestUnionRunRun(t *testing.T) {
for i, test := range tests {
a.runs = test.aruns
b.runs = test.bruns
a.containerType = ContainerRun
b.containerType = ContainerRun
a.containerType = containerRun
b.containerType = containerRun
ret := unionRunRun(a, b)
if !reflect.DeepEqual(ret.runs, test.exp) {
t.Fatalf("test #%v expected %v, but got %v", i, test.exp, ret.runs)
@ -927,8 +927,8 @@ func TestUnionArrayRun(t *testing.T) {
for i, test := range tests {
a.array = test.array
b.runs = test.runs
a.containerType = ContainerArray
b.containerType = ContainerRun
a.containerType = containerArray
b.containerType = containerRun
ret := unionArrayRun(a, b)
if !reflect.DeepEqual(ret.array, test.exp) {
t.Fatalf("test #%v expected %v, but got %v", i, test.exp, ret.array)
@ -937,7 +937,7 @@ func TestUnionArrayRun(t *testing.T) {
}
func TestBitmapSetRange(t *testing.T) {
c := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
c := &Container{containerType: containerBitmap, bitmap: make([]uint64, bitmapN)}
tests := []struct {
bitmap []uint64
start uint64
@ -977,7 +977,7 @@ func TestBitmapSetRange(t *testing.T) {
}
func TestArrayToBitmap(t *testing.T) {
a := &Container{containerType: ContainerArray}
a := &Container{containerType: containerArray}
tests := []struct {
array []uint16
exp []uint64
@ -1008,7 +1008,7 @@ func TestArrayToBitmap(t *testing.T) {
}
func TestBitmapToArray(t *testing.T) {
a := &Container{containerType: ContainerBitmap}
a := &Container{containerType: containerBitmap}
tests := []struct {
bitmap []uint64
exp []uint16
@ -1039,7 +1039,7 @@ func TestBitmapToArray(t *testing.T) {
}
func TestRunToBitmap(t *testing.T) {
a := &Container{containerType: ContainerRun}
a := &Container{containerType: containerRun}
tests := []struct {
runs []interval16
exp []uint64
@ -1093,7 +1093,7 @@ func getFullBitmap() []uint64 {
}
func TestBitmapToRun(t *testing.T) {
a := &Container{containerType: ContainerBitmap}
a := &Container{containerType: containerBitmap}
tests := []struct {
bitmap []uint64
exp []interval16
@ -1171,7 +1171,7 @@ func TestBitmapToRun(t *testing.T) {
}
func TestArrayToRun(t *testing.T) {
a := &Container{containerType: ContainerArray}
a := &Container{containerType: containerArray}
tests := []struct {
array []uint16
exp []interval16
@ -1205,7 +1205,7 @@ func TestArrayToRun(t *testing.T) {
}
func TestRunToArray(t *testing.T) {
a := &Container{containerType: ContainerRun}
a := &Container{containerType: containerRun}
tests := []struct {
runs []interval16
exp []uint16
@ -1239,7 +1239,7 @@ func TestRunToArray(t *testing.T) {
}
func TestBitmapZeroRange(t *testing.T) {
c := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
c := &Container{containerType: containerBitmap, bitmap: make([]uint64, bitmapN)}
tests := []struct {
bitmap []uint64
start uint64
@ -1283,8 +1283,8 @@ func TestBitmapZeroRange(t *testing.T) {
}
func TestUnionBitmapRun(t *testing.T) {
a := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
b := &Container{containerType: ContainerRun}
a := &Container{containerType: containerBitmap, bitmap: make([]uint64, bitmapN)}
b := &Container{containerType: containerRun}
tests := []struct {
bitmap []uint64
runs []interval16
@ -1322,7 +1322,7 @@ func TestUnionBitmapRun(t *testing.T) {
}
func TestBitmapCountRuns(t *testing.T) {
c := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
c := &Container{containerType: containerBitmap, bitmap: make([]uint64, bitmapN)}
tests := []struct {
bitmap []uint64
exp int
@ -1372,7 +1372,7 @@ func TestBitmapCountRuns(t *testing.T) {
}
func TestArrayCountRuns(t *testing.T) {
c := &Container{containerType: ContainerArray}
c := &Container{containerType: containerArray}
tests := []struct {
array []uint16
exp int
@ -1413,8 +1413,8 @@ func TestArrayCountRuns(t *testing.T) {
}
func TestDifferenceArrayRun(t *testing.T) {
a := &Container{containerType: ContainerArray}
b := &Container{containerType: ContainerRun}
a := &Container{containerType: containerArray}
b := &Container{containerType: containerRun}
tests := []struct {
array []uint16
runs []interval16
@ -1439,8 +1439,8 @@ func TestDifferenceArrayRun(t *testing.T) {
}
func TestDifferenceRunArray(t *testing.T) {
a := &Container{containerType: ContainerRun}
b := &Container{containerType: ContainerArray}
a := &Container{containerType: containerRun}
b := &Container{containerType: containerArray}
tests := []struct {
runs []interval16
array []uint16
@ -1520,8 +1520,8 @@ func MakeLastBitSet() []uint64 {
}
func TestDifferenceRunBitmap(t *testing.T) {
a := &Container{containerType: ContainerRun}
b := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
a := &Container{containerType: containerRun}
b := &Container{containerType: containerBitmap, bitmap: make([]uint64, bitmapN)}
tests := []struct {
runs []interval16
bitmap []uint64
@ -1583,8 +1583,8 @@ func TestDifferenceRunBitmap(t *testing.T) {
}
func TestDifferenceBitmapRun(t *testing.T) {
a := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
b := &Container{containerType: ContainerRun}
a := &Container{containerType: containerBitmap, bitmap: make([]uint64, bitmapN)}
b := &Container{containerType: containerRun}
tests := []struct {
bitmap []uint64
runs []interval16
@ -1666,8 +1666,8 @@ func TestDifferenceBitmapRun(t *testing.T) {
}
func TestDifferenceBitmapArray(t *testing.T) {
b := &Container{containerType: ContainerBitmap, bitmap: make([]uint64, bitmapN)}
a := &Container{containerType: ContainerArray}
b := &Container{containerType: containerBitmap, bitmap: make([]uint64, bitmapN)}
a := &Container{containerType: containerArray}
tests := []struct {
bitmap []uint64
array []uint16
@ -1716,8 +1716,8 @@ func TestDifferenceBitmapArray(t *testing.T) {
}
func TestDifferenceBitmapBitmap(t *testing.T) {
a := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
b := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
a := &Container{bitmap: make([]uint64, bitmapN), containerType: containerBitmap}
b := &Container{bitmap: make([]uint64, bitmapN), containerType: containerBitmap}
tests := []struct {
abitmap []uint64
bbitmap []uint64
@ -1746,8 +1746,8 @@ func TestDifferenceBitmapBitmap(t *testing.T) {
}
func TestDifferenceRunRun(t *testing.T) {
a := &Container{containerType: ContainerRun}
b := &Container{containerType: ContainerRun}
a := &Container{containerType: containerRun}
b := &Container{containerType: containerRun}
tests := []struct {
aruns []interval16
bruns []interval16
@ -1780,7 +1780,7 @@ func TestDifferenceRunRun(t *testing.T) {
}
func TestWriteReadArray(t *testing.T) {
ca := &Container{array: []uint16{1, 10, 100, 1000}, n: 4, containerType: ContainerArray}
ca := &Container{array: []uint16{1, 10, 100, 1000}, n: 4, containerType: containerArray}
ba := NewFileBitmap()
ba.Containers.Put(0, ca)
ba2 := NewFileBitmap()
@ -1800,7 +1800,7 @@ func TestWriteReadArray(t *testing.T) {
func TestWriteReadBitmap(t *testing.T) {
// create bitmap containing > 4096 bits
cb := &Container{bitmap: make([]uint64, bitmapN), n: 129 * 32, containerType: ContainerBitmap}
cb := &Container{bitmap: make([]uint64, bitmapN), n: 129 * 32, containerType: containerBitmap}
for i := 0; i < 129; i++ {
cb.bitmap[i] = 0x5555555555555555
}
@ -1823,7 +1823,7 @@ func TestWriteReadBitmap(t *testing.T) {
func TestWriteReadFullBitmap(t *testing.T) {
// create bitmap containing > 4096 bits
cb := &Container{bitmap: make([]uint64, bitmapN), n: 65536, containerType: ContainerBitmap}
cb := &Container{bitmap: make([]uint64, bitmapN), n: 65536, containerType: containerBitmap}
for i := 0; i < bitmapN; i++ {
cb.bitmap[i] = 0xffffffffffffffff
}
@ -1852,7 +1852,7 @@ func TestWriteReadFullBitmap(t *testing.T) {
}
func TestWriteReadRun(t *testing.T) {
cr := &Container{runs: []interval16{{start: 3, last: 13}, {start: 100, last: 109}}, n: 21, containerType: ContainerRun}
cr := &Container{runs: []interval16{{start: 3, last: 13}, {start: 100, last: 109}}, n: 21, containerType: containerRun}
br := NewFileBitmap()
br.Containers.Put(0, cr)
br2 := NewFileBitmap()
@ -1877,21 +1877,21 @@ func TestXorArrayRun(t *testing.T) {
exp *Container
}{
{
a: &Container{array: []uint16{1, 5, 10, 11, 12}, containerType: ContainerArray},
b: &Container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: ContainerRun},
exp: &Container{array: []uint16{1, 2, 3, 4, 6, 7, 8, 9, 11, 13, 15, 16}, containerType: ContainerArray, n: 12},
a: &Container{array: []uint16{1, 5, 10, 11, 12}, containerType: containerArray},
b: &Container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: containerRun},
exp: &Container{array: []uint16{1, 2, 3, 4, 6, 7, 8, 9, 11, 13, 15, 16}, containerType: containerArray, n: 12},
}, {
a: &Container{array: []uint16{1, 5, 10, 11, 12, 13, 14}, containerType: ContainerArray},
b: &Container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: ContainerRun},
exp: &Container{array: []uint16{1, 2, 3, 4, 6, 7, 8, 9, 11, 14, 15, 16}, containerType: ContainerArray, n: 12},
a: &Container{array: []uint16{1, 5, 10, 11, 12, 13, 14}, containerType: containerArray},
b: &Container{runs: []interval16{{start: 2, last: 10}, {start: 12, last: 13}, {start: 15, last: 16}}, containerType: containerRun},
exp: &Container{array: []uint16{1, 2, 3, 4, 6, 7, 8, 9, 11, 14, 15, 16}, containerType: containerArray, n: 12},
}, {
a: &Container{array: []uint16{65535}, containerType: ContainerArray},
b: &Container{runs: []interval16{{start: 65534, last: 65535}}, containerType: ContainerRun},
exp: &Container{array: []uint16{65534}, containerType: ContainerArray, n: 1},
a: &Container{array: []uint16{65535}, containerType: containerArray},
b: &Container{runs: []interval16{{start: 65534, last: 65535}}, containerType: containerRun},
exp: &Container{array: []uint16{65534}, containerType: containerArray, n: 1},
}, {
a: &Container{array: []uint16{65535}, containerType: ContainerArray},
b: &Container{runs: []interval16{{start: 65535, last: 65535}}, containerType: ContainerRun},
exp: &Container{array: []uint16{}, containerType: ContainerArray, n: 0},
a: &Container{array: []uint16{65535}, containerType: containerArray},
b: &Container{runs: []interval16{{start: 65535, last: 65535}}, containerType: containerRun},
exp: &Container{array: []uint16{}, containerType: containerArray, n: 0},
},
}
@ -1912,8 +1912,8 @@ func TestXorArrayRun(t *testing.T) {
//special case that didn't fit the xorrunrun table testing below.
func TestXorRunRun1(t *testing.T) {
a := &Container{containerType: ContainerRun}
b := &Container{containerType: ContainerRun}
a := &Container{containerType: containerRun}
b := &Container{containerType: containerRun}
a.runs = []interval16{{start: 4, last: 10}}
b.runs = []interval16{{start: 5, last: 10}}
ret := xorRunRun(a, b)
@ -1927,8 +1927,8 @@ func TestXorRunRun1(t *testing.T) {
}
func TestXorRunRun(t *testing.T) {
a := &Container{containerType: ContainerRun}
b := &Container{containerType: ContainerRun}
a := &Container{containerType: containerRun}
b := &Container{containerType: containerRun}
tests := []struct {
aruns []interval16
bruns []interval16
@ -2025,7 +2025,7 @@ func TestXorRunRun(t *testing.T) {
}
func TestBitmapXorRange(t *testing.T) {
c := &Container{bitmap: make([]uint64, bitmapN), containerType: ContainerBitmap}
c := &Container{bitmap: make([]uint64, bitmapN), containerType: containerBitmap}
tests := []struct {
bitmap []uint64
start uint64
@ -2093,8 +2093,8 @@ func TestBitmapXorRange(t *testing.T) {
}
func TestXorBitmapRun(t *testing.T) {
a := &Container{containerType: ContainerBitmap}
b := &Container{containerType: ContainerRun}
a := &Container{containerType: containerBitmap}
b := &Container{containerType: containerRun}
tests := []struct {
bitmap []uint64
runs []interval16
@ -2546,8 +2546,8 @@ func TestSearch64(t *testing.T) {
}
func TestIntersectArrayBitmap(t *testing.T) {
a, b := &Container{containerType: ContainerArray}, &Container{
containerType: ContainerBitmap,
a, b := &Container{containerType: containerArray}, &Container{
containerType: containerBitmap,
bitmap: make([]uint64, bitmapN),
}
tests := []struct {
@ -2594,11 +2594,11 @@ func TestIntersectArrayBitmap(t *testing.T) {
for i, test := range tests {
a.array = test.array
a.containerType = ContainerArray
a.containerType = containerArray
for i, bmval := range test.bitmap {
b.bitmap[i] = bmval
}
b.containerType = ContainerBitmap
b.containerType = containerBitmap
ret := intersectArrayBitmap(a, b).array
if len(ret) == 0 && len(test.exp) == 0 {
continue
@ -2722,13 +2722,13 @@ func TestContainerCombinations(t *testing.T) {
cts := setupContainerTests()
containerTypes := []byte{ContainerArray, ContainerBitmap, ContainerRun}
containerTypes := []byte{containerArray, containerBitmap, containerRun}
// map used for a more descriptive print
cm := map[byte]string{
ContainerArray: "array",
ContainerBitmap: "bitmap",
ContainerRun: "run",
containerArray: "array",
containerBitmap: "bitmap",
containerRun: "run",
}
testOps := []testOp{
@ -3198,7 +3198,7 @@ func TestContainerCombinations(t *testing.T) {
// Convert to all container types and check result.
for _, ct := range containerTypes {
clone := ret.Clone()
if ct == ContainerArray {
if ct == containerArray {
if clone.isBitmap() {
clone.bitmapToArray()
} else if clone.isRun() {
@ -3212,7 +3212,7 @@ func TestContainerCombinations(t *testing.T) {
if !(len(clone.array) == 0 && len(cts[ct][exp].array) == 0) && !reflect.DeepEqual(clone.array, cts[ct][exp].array) {
t.Fatalf("test %s expected array %X, but got %X", desc, cts[ct][exp].array, clone.array)
}
} else if ct == ContainerBitmap {
} else if ct == containerBitmap {
if clone.isArray() {
clone.arrayToBitmap()
} else if clone.isRun() {
@ -3224,7 +3224,7 @@ func TestContainerCombinations(t *testing.T) {
if !reflect.DeepEqual(clone.bitmap, cts[ct][exp].bitmap) {
t.Fatalf("test %s expected bitmap %X, but got %X", desc, cts[ct][exp].bitmap, clone.bitmap)
}
} else if ct == ContainerRun {
} else if ct == containerRun {
if clone.isArray() {
clone.arrayToRun()
} else if clone.isBitmap() {

82
row.go
View file

@ -24,7 +24,7 @@ import (
// Row is a set of integers (the associated columns), and attributes which are
// arbitrary key/value pairs storing metadata about what the row represents.
type Row struct {
segments []RowSegment
segments []rowSegment
// String keys translated to/from segment columns.
Keys []string
@ -44,7 +44,7 @@ func NewRow(columns ...uint64) *Row {
// Merge merges data from other into r.
func (r *Row) Merge(other *Row) {
var segments []RowSegment
var segments []rowSegment
itr := newMergeSegmentIterator(r.segments, other.segments)
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
@ -63,11 +63,11 @@ func (r *Row) Merge(other *Row) {
}
r.segments = segments
r.InvalidateCount()
r.invalidateCount()
}
// IntersectionCount returns the number of intersections between r and other.
func (r *Row) IntersectionCount(other *Row) uint64 {
// intersectionCount returns the number of intersections between r and other.
func (r *Row) intersectionCount(other *Row) uint64 {
var n uint64
itr := newMergeSegmentIterator(r.segments, other.segments)
@ -82,9 +82,9 @@ func (r *Row) IntersectionCount(other *Row) uint64 {
return n
}
// Intersect returns the itersection of r and other.
func (r *Row) Intersect(other *Row) *Row {
var segments []RowSegment
// intersect returns the itersection of r and other.
func (r *Row) intersect(other *Row) *Row {
var segments []rowSegment
itr := newMergeSegmentIterator(r.segments, other.segments)
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
@ -100,7 +100,7 @@ func (r *Row) Intersect(other *Row) *Row {
// Xor returns the xor of r and other.
func (r *Row) Xor(other *Row) *Row {
var segments []RowSegment
var segments []rowSegment
itr := newMergeSegmentIterator(r.segments, other.segments)
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
@ -120,7 +120,7 @@ func (r *Row) Xor(other *Row) *Row {
// Union returns the bitwise union of r and other.
func (r *Row) Union(other *Row) *Row {
var segments []RowSegment
var segments []rowSegment
itr := newMergeSegmentIterator(r.segments, other.segments)
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
if s1 == nil {
@ -138,7 +138,7 @@ func (r *Row) Union(other *Row) *Row {
// Difference returns the diff of r and other.
func (r *Row) Difference(other *Row) *Row {
var segments []RowSegment
var segments []rowSegment
itr := newMergeSegmentIterator(r.segments, other.segments)
for s0, s1 := itr.next(); s0 != nil || s1 != nil; s0, s1 = itr.next() {
@ -159,8 +159,8 @@ func (r *Row) SetBit(i uint64) (changed bool) {
return r.createSegmentIfNotExists(i / ShardWidth).SetBit(i)
}
// ClearBit clears the i-th column of the row.
func (r *Row) ClearBit(i uint64) (changed bool) {
// clearBit clears the i-th column of the row.
func (r *Row) clearBit(i uint64) (changed bool) {
s := r.segment(i / ShardWidth)
if s == nil {
return false
@ -169,13 +169,13 @@ func (r *Row) ClearBit(i uint64) (changed bool) {
}
// Segments returns a list of all segments in the row.
func (r *Row) Segments() []RowSegment {
func (r *Row) Segments() []rowSegment {
return r.segments
}
// segment returns a segment for a given shard.
// Returns nil if segment does not exist.
func (r *Row) segment(shard uint64) *RowSegment {
func (r *Row) segment(shard uint64) *rowSegment {
if i := sort.Search(len(r.segments), func(i int) bool {
return r.segments[i].shard >= shard
}); i < len(r.segments) && r.segments[i].shard == shard {
@ -184,7 +184,7 @@ func (r *Row) segment(shard uint64) *RowSegment {
return nil
}
func (r *Row) createSegmentIfNotExists(shard uint64) *RowSegment {
func (r *Row) createSegmentIfNotExists(shard uint64) *rowSegment {
i := sort.Search(len(r.segments), func(i int) bool {
return r.segments[i].shard >= shard
})
@ -195,11 +195,11 @@ func (r *Row) createSegmentIfNotExists(shard uint64) *RowSegment {
}
// Insert new segment.
r.segments = append(r.segments, RowSegment{data: *roaring.NewBitmap()})
r.segments = append(r.segments, rowSegment{data: *roaring.NewBitmap()})
if i < len(r.segments) {
copy(r.segments[i+1:], r.segments[i:])
}
r.segments[i] = RowSegment{
r.segments[i] = rowSegment{
data: *roaring.NewBitmap(),
shard: shard,
writable: true,
@ -208,8 +208,8 @@ func (r *Row) createSegmentIfNotExists(shard uint64) *RowSegment {
return &r.segments[i]
}
// InvalidateCount updates the cached count in the row.
func (r *Row) InvalidateCount() {
// invalidateCount updates the cached count in the row.
func (r *Row) invalidateCount() {
for i := range r.segments {
r.segments[i].InvalidateCount()
}
@ -251,10 +251,10 @@ func (r *Row) Columns() []uint64 {
return a
}
// RowSegment holds a subset of a row.
// rowSegment holds a subset of a row.
// This could point to a mmapped roaring bitmap or an in-memory bitmap. The
// width of the segment will always match the shard width.
type RowSegment struct {
type rowSegment struct {
// Shard this segment belongs to
shard uint64
@ -270,7 +270,7 @@ type RowSegment struct {
// Merge adds chunks from other to s.
// Chunks in s are overwritten if they exist in other.
func (s *RowSegment) Merge(other *RowSegment) {
func (s *rowSegment) Merge(other *rowSegment) {
s.ensureWritable()
itr := other.data.Iterator()
@ -280,15 +280,15 @@ func (s *RowSegment) Merge(other *RowSegment) {
}
// IntersectionCount returns the number of intersections between s and other.
func (s *RowSegment) IntersectionCount(other *RowSegment) uint64 {
func (s *rowSegment) IntersectionCount(other *rowSegment) uint64 {
return s.data.IntersectionCount(&other.data)
}
// Intersect returns the itersection of s and other.
func (s *RowSegment) Intersect(other *RowSegment) *RowSegment {
func (s *rowSegment) Intersect(other *rowSegment) *rowSegment {
data := s.data.Intersect(&other.data)
return &RowSegment{
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
@ -296,10 +296,10 @@ func (s *RowSegment) Intersect(other *RowSegment) *RowSegment {
}
// Union returns the bitwise union of s and other.
func (s *RowSegment) Union(other *RowSegment) *RowSegment {
func (s *rowSegment) Union(other *rowSegment) *rowSegment {
data := s.data.Union(&other.data)
return &RowSegment{
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
@ -307,10 +307,10 @@ func (s *RowSegment) Union(other *RowSegment) *RowSegment {
}
// Difference returns the diff of s and other.
func (s *RowSegment) Difference(other *RowSegment) *RowSegment {
func (s *rowSegment) Difference(other *rowSegment) *rowSegment {
data := s.data.Difference(&other.data)
return &RowSegment{
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
@ -318,10 +318,10 @@ func (s *RowSegment) Difference(other *RowSegment) *RowSegment {
}
// Xor returns the xor of s and other.
func (s *RowSegment) Xor(other *RowSegment) *RowSegment {
func (s *rowSegment) Xor(other *rowSegment) *rowSegment {
data := s.data.Xor(&other.data)
return &RowSegment{
return &rowSegment{
data: *data,
shard: s.shard,
n: data.Count(),
@ -329,7 +329,7 @@ func (s *RowSegment) Xor(other *RowSegment) *RowSegment {
}
// SetBit sets the i-th column of the row.
func (s *RowSegment) SetBit(i uint64) (changed bool) {
func (s *rowSegment) SetBit(i uint64) (changed bool) {
s.ensureWritable()
changed, _ = s.data.Add(i)
if changed {
@ -339,7 +339,7 @@ func (s *RowSegment) SetBit(i uint64) (changed bool) {
}
// ClearBit clears the i-th column of the row.
func (s *RowSegment) ClearBit(i uint64) (changed bool) {
func (s *rowSegment) ClearBit(i uint64) (changed bool) {
s.ensureWritable()
changed, _ = s.data.Remove(i)
@ -350,12 +350,12 @@ func (s *RowSegment) ClearBit(i uint64) (changed bool) {
}
// InvalidateCount updates the cached count in the row.
func (s *RowSegment) InvalidateCount() {
func (s *rowSegment) InvalidateCount() {
s.n = s.data.Count()
}
// Columns returns a list of all columns set in the segment.
func (s *RowSegment) Columns() []uint64 {
func (s *rowSegment) Columns() []uint64 {
a := make([]uint64, 0, s.Count())
itr := s.data.Iterator()
for v, eof := itr.Next(); !eof; v, eof = itr.Next() {
@ -365,10 +365,10 @@ func (s *RowSegment) Columns() []uint64 {
}
// Count returns the number of set columns in the row.
func (s *RowSegment) Count() uint64 { return s.n }
func (s *rowSegment) Count() uint64 { return s.n }
// ensureWritable clones the segment if it is pointing to non-writable data.
func (s *RowSegment) ensureWritable() {
func (s *rowSegment) ensureWritable() {
if s.writable {
return
}
@ -379,16 +379,16 @@ func (s *RowSegment) ensureWritable() {
// mergeSegmentIterator produces an iterator that loops through two sets of segments.
type mergeSegmentIterator struct {
a0, a1 []RowSegment
a0, a1 []rowSegment
}
// newMergeSegmentIterator returns a new instance of mergeSegmentIterator.
func newMergeSegmentIterator(a0, a1 []RowSegment) mergeSegmentIterator {
func newMergeSegmentIterator(a0, a1 []rowSegment) mergeSegmentIterator {
return mergeSegmentIterator{a0: a0, a1: a1}
}
// next returns the next set of segments.
func (itr *mergeSegmentIterator) next() (s0, s1 *RowSegment) {
func (itr *mergeSegmentIterator) next() (s0, s1 *rowSegment) {
// Find current segments.
if len(itr.a0) > 0 {
s0 = &itr.a0[0]

View file

@ -50,7 +50,7 @@ type Server struct {
holder *Holder
cluster *cluster
translateFile *TranslateFile
diagnostics *DiagnosticsCollector
diagnostics *diagnosticsCollector
executor *executor
hosts []string
clusterDisabled bool
@ -235,8 +235,8 @@ func NewServer(opts ...ServerOption) (*Server, error) {
closing: make(chan struct{}),
cluster: newCluster(),
holder: NewHolder(),
diagnostics: NewDiagnosticsCollector(defaultDiagnosticServer),
systemInfo: NewNopSystemInfo(),
diagnostics: newDiagnosticsCollector(defaultDiagnosticServer),
systemInfo: newNopSystemInfo(),
gcNotifier: NopGCNotifier,
@ -337,7 +337,7 @@ func (s *Server) Open() error {
if err := s.holder.Open(); err != nil {
return fmt.Errorf("opening Holder: %v", err)
}
if err := s.cluster.setNodeState(NodeStateReady); err != nil {
if err := s.cluster.setNodeState(nodeStateReady); err != nil {
return fmt.Errorf("setting nodeState: %v", err)
}
@ -513,7 +513,7 @@ func (s *Server) receiveMessage(m Message) error {
return err
}
case *RecalculateCaches:
s.holder.RecalculateCaches()
s.holder.recalculateCaches()
case *NodeEvent:
s.cluster.ReceiveEvent(obj)
case *NodeStatus:

View file

@ -20,5 +20,5 @@ package server
import "time"
// DefaultDiagnosticsInterval is the default sync frequency diagnostic metrics. A value of 0 disables diagnostics.
const DefaultDiagnosticsInterval = time.Duration(0)
// defaultDiagnosticsInterval is the default sync frequency diagnostic metrics. A value of 0 disables diagnostics.
const defaultDiagnosticsInterval = time.Duration(0)

View file

@ -20,5 +20,5 @@ package server
import "time"
// DefaultDiagnosticsInterval is the default sync frequency diagnostic metrics.
const DefaultDiagnosticsInterval = 1 * time.Hour
// defaultDiagnosticsInterval is the default sync frequency diagnostic metrics.
const defaultDiagnosticsInterval = 1 * time.Hour

View file

@ -124,7 +124,7 @@ func (m *Command) Start() (err error) {
}
// SetupNetworking
err = m.SetupNetworking()
err = m.setupNetworking()
if err != nil {
return errors.Wrap(err, "setting up networking")
}
@ -222,10 +222,10 @@ func (m *Command) SetupServer() error {
diagnosticsInterval := time.Duration(0)
if m.Config.Metric.Diagnostics {
diagnosticsInterval = time.Duration(DefaultDiagnosticsInterval)
diagnosticsInterval = time.Duration(defaultDiagnosticsInterval)
}
statsClient, err := NewStatsClient(m.Config.Metric.Service, m.Config.Metric.Host)
statsClient, err := newStatsClient(m.Config.Metric.Service, m.Config.Metric.Host)
if err != nil {
return errors.Wrap(err, "new stats client")
}
@ -299,8 +299,8 @@ func (m *Command) SetupServer() error {
}
// SetupNetworking sets up internode communication based on the configuration.
func (m *Command) SetupNetworking() error {
// setupNetworking sets up internode communication based on the configuration.
func (m *Command) setupNetworking() error {
if m.Config.Cluster.Disabled {
return nil
}
@ -351,8 +351,8 @@ func (m *Command) Close() error {
return nil
}
// NewStatsClient creates a stats client from the config
func NewStatsClient(name string, host string) (pilosa.StatsClient, error) {
// newStatsClient creates a stats client from the config
func newStatsClient(name string, host string) (pilosa.StatsClient, error) {
switch name {
case "expvar":
return pilosa.NewExpvarStatsClient(), nil

View file

@ -82,8 +82,8 @@ func (c *nopStatsClient) SetLogger(logger Logger)
func (c *nopStatsClient) Open() {}
func (c *nopStatsClient) Close() error { return nil }
// ExpvarStatsClient writes stats out to expvars.
type ExpvarStatsClient struct {
// expvarStatsClient writes stats out to expvars.
type expvarStatsClient struct {
mu sync.Mutex
m *expvar.Map
tags []string
@ -91,41 +91,41 @@ type ExpvarStatsClient struct {
// NewExpvarStatsClient returns a new instance of ExpvarStatsClient.
// This client points at the root of the expvar index map.
func NewExpvarStatsClient() *ExpvarStatsClient {
return &ExpvarStatsClient{
func NewExpvarStatsClient() *expvarStatsClient {
return &expvarStatsClient{
m: Expvar,
}
}
// Tags returns a sorted list of tags on the client.
func (c *ExpvarStatsClient) Tags() []string {
func (c *expvarStatsClient) Tags() []string {
return nil
}
// WithTags returns a new client with additional tags appended.
func (c *ExpvarStatsClient) WithTags(tags ...string) StatsClient {
func (c *expvarStatsClient) WithTags(tags ...string) StatsClient {
m := &expvar.Map{}
m.Init()
c.m.Set(strings.Join(tags, ","), m)
return &ExpvarStatsClient{
return &expvarStatsClient{
m: m,
tags: unionStringSlice(c.tags, tags),
}
}
// Count tracks the number of times something occurs.
func (c *ExpvarStatsClient) Count(name string, value int64, rate float64) {
func (c *expvarStatsClient) Count(name string, value int64, rate float64) {
c.m.Add(name, value)
}
// CountWithCustomTags Tracks the number of times something occurs per second with custom tags
func (c *ExpvarStatsClient) CountWithCustomTags(name string, value int64, rate float64, tags []string) {
func (c *expvarStatsClient) CountWithCustomTags(name string, value int64, rate float64, tags []string) {
c.m.Add(name, value)
}
// Gauge sets the value of a metric.
func (c *ExpvarStatsClient) Gauge(name string, value float64, rate float64) {
func (c *expvarStatsClient) Gauge(name string, value float64, rate float64) {
var f expvar.Float
f.Set(value)
c.m.Set(name, &f)
@ -133,19 +133,19 @@ func (c *ExpvarStatsClient) Gauge(name string, value float64, rate float64) {
// Histogram tracks statistical distribution of a metric.
// This works the same as gauge for this client.
func (c *ExpvarStatsClient) Histogram(name string, value float64, rate float64) {
func (c *expvarStatsClient) Histogram(name string, value float64, rate float64) {
c.Gauge(name, value, rate)
}
// Set tracks number of unique elements.
func (c *ExpvarStatsClient) Set(name string, value string, rate float64) {
func (c *expvarStatsClient) Set(name string, value string, rate float64) {
var s expvar.String
s.Set(value)
c.m.Set(name, &s)
}
// Timing tracks timing information for a metric.
func (c *ExpvarStatsClient) Timing(name string, value time.Duration, rate float64) {
func (c *expvarStatsClient) Timing(name string, value time.Duration, rate float64) {
c.mu.Lock()
d, _ := c.m.Get(name).(time.Duration)
c.m.Set(name, d+value)
@ -153,14 +153,14 @@ func (c *ExpvarStatsClient) Timing(name string, value time.Duration, rate float6
}
// SetLogger has no logger.
func (c *ExpvarStatsClient) SetLogger(logger Logger) {
func (c *expvarStatsClient) SetLogger(logger Logger) {
}
// Open no-op.
func (c *ExpvarStatsClient) Open() {}
func (c *expvarStatsClient) Open() {}
// Close no-op.
func (c *ExpvarStatsClient) Close() error { return nil }
func (c *expvarStatsClient) Close() error { return nil }
// MultiStatsClient joins multiple stats clients together.
type MultiStatsClient []StatsClient

View file

@ -26,52 +26,52 @@ import (
// statsD defailt host is "127.0.0.1:8125"
const (
// Prefix is appended to each metric event name
Prefix = "pilosa."
// prefix is appended to each metric event name
prefix = "pilosa."
// BufferLen Stats lient buffer size.
BufferLen = 1024
// bufferLen Stats lient buffer size.
bufferLen = 1024
)
// Ensure client implements interface.
var _ pilosa.StatsClient = &StatsClient{}
var _ pilosa.StatsClient = &statsClient{}
// StatsClient represents a StatsD implementation of pilosa.StatsClient.
type StatsClient struct {
// statsClient represents a StatsD implementation of pilosa.statsClient.
type statsClient struct {
client *statsd.Client
tags []string
logger pilosa.Logger
}
// NewStatsClient returns a new instance of StatsClient.
func NewStatsClient(host string) (*StatsClient, error) {
c, err := statsd.NewBuffered(host, BufferLen)
func NewStatsClient(host string) (*statsClient, error) {
c, err := statsd.NewBuffered(host, bufferLen)
if err != nil {
return nil, err
}
return &StatsClient{
return &statsClient{
client: c,
logger: pilosa.NopLogger,
}, nil
}
// Open no-op
func (c *StatsClient) Open() {}
func (c *statsClient) Open() {}
// Close closes the connection to the agent.
func (c *StatsClient) Close() error {
func (c *statsClient) Close() error {
return c.client.Close()
}
// Tags returns a sorted list of tags on the client.
func (c *StatsClient) Tags() []string {
func (c *statsClient) Tags() []string {
return c.tags
}
// WithTags returns a new client with additional tags appended.
func (c *StatsClient) WithTags(tags ...string) pilosa.StatsClient {
return &StatsClient{
func (c *statsClient) WithTags(tags ...string) pilosa.StatsClient {
return &statsClient{
client: c.client,
tags: unionStringSlice(c.tags, tags),
logger: c.logger,
@ -79,50 +79,50 @@ func (c *StatsClient) WithTags(tags ...string) pilosa.StatsClient {
}
// Count tracks the number of times something occurs per second.
func (c *StatsClient) Count(name string, value int64, rate float64) {
if err := c.client.Count(Prefix+name, value, c.tags, rate); err != nil {
func (c *statsClient) Count(name string, value int64, rate float64) {
if err := c.client.Count(prefix+name, value, c.tags, rate); err != nil {
c.logger.Printf("statsd.StatsClient.Count error: %s", err)
}
}
// CountWithCustomTags tracks the number of times something occurs per second with custom tags.
func (c *StatsClient) CountWithCustomTags(name string, value int64, rate float64, t []string) {
func (c *statsClient) CountWithCustomTags(name string, value int64, rate float64, t []string) {
tags := append(c.tags, t...)
if err := c.client.Count(Prefix+name, value, tags, rate); err != nil {
if err := c.client.Count(prefix+name, value, tags, rate); err != nil {
c.logger.Printf("statsd.StatsClient.Count error: %s", err)
}
}
// Gauge sets the value of a metric.
func (c *StatsClient) Gauge(name string, value float64, rate float64) {
if err := c.client.Gauge(Prefix+name, value, c.tags, rate); err != nil {
func (c *statsClient) Gauge(name string, value float64, rate float64) {
if err := c.client.Gauge(prefix+name, value, c.tags, rate); err != nil {
c.logger.Printf("statsd.StatsClient.Gauge error: %s", err)
}
}
// Histogram tracks statistical distribution of a metric.
func (c *StatsClient) Histogram(name string, value float64, rate float64) {
if err := c.client.Histogram(Prefix+name, value, c.tags, rate); err != nil {
func (c *statsClient) Histogram(name string, value float64, rate float64) {
if err := c.client.Histogram(prefix+name, value, c.tags, rate); err != nil {
c.logger.Printf("statsd.StatsClient.Histogram error: %s", err)
}
}
// Set tracks number of unique elements.
func (c *StatsClient) Set(name string, value string, rate float64) {
if err := c.client.Set(Prefix+name, value, c.tags, rate); err != nil {
func (c *statsClient) Set(name string, value string, rate float64) {
if err := c.client.Set(prefix+name, value, c.tags, rate); err != nil {
c.logger.Printf("statsd.StatsClient.Set error: %s", err)
}
}
// Timing tracks timing information for a metric.
func (c *StatsClient) Timing(name string, value time.Duration, rate float64) {
if err := c.client.Timing(Prefix+name, value, c.tags, rate); err != nil {
func (c *statsClient) Timing(name string, value time.Duration, rate float64) {
if err := c.client.Timing(prefix+name, value, c.tags, rate); err != nil {
c.logger.Printf("statsd.StatsClient.Timing error: %s", err)
}
}
// SetLogger sets the logger for client.
func (c *StatsClient) SetLogger(logger pilosa.Logger) {
func (c *statsClient) SetLogger(logger pilosa.Logger) {
c.logger = logger
}

View file

@ -27,8 +27,8 @@ type Field struct {
*pilosa.Field
}
// NewField returns a new instance of Field d/0.
func NewField(opts pilosa.FieldOption) *Field {
// newField returns a new instance of Field d/0.
func newField(opts pilosa.FieldOption) *Field {
path, err := ioutil.TempDir("", "pilosa-field-")
if err != nil {
panic(err)
@ -40,23 +40,23 @@ func NewField(opts pilosa.FieldOption) *Field {
return &Field{Field: field}
}
// MustOpenField returns a new, opened field at a temporary path. Panic on error.
func MustOpenField(opts pilosa.FieldOption) *Field {
f := NewField(opts)
// mustOpenField returns a new, opened field at a temporary path. Panic on error.
func mustOpenField(opts pilosa.FieldOption) *Field {
f := newField(opts)
if err := f.Open(); err != nil {
panic(err)
}
return f
}
// Close closes the field and removes the underlying data.
func (f *Field) Close() error {
// close closes the field and removes the underlying data.
func (f *Field) close() error {
defer os.RemoveAll(f.Path())
return f.Field.Close()
}
// Reopen closes the index and reopens it.
func (f *Field) Reopen() error {
// reopen closes the index and reopens it.
func (f *Field) reopen() error {
var err error
if err := f.Field.Close(); err != nil {
return err
@ -76,8 +76,8 @@ func (f *Field) Reopen() error {
// Ensure field can set its cache
func TestField_SetCacheSize(t *testing.T) {
f := MustOpenField(pilosa.OptFieldTypeDefault())
defer f.Close()
f := mustOpenField(pilosa.OptFieldTypeDefault())
defer f.close()
cacheSize := uint32(100)
// Set & retrieve field cache size.
@ -88,7 +88,7 @@ func TestField_SetCacheSize(t *testing.T) {
}
// Reload field and verify that it is persisted.
if err := f.Reopen(); err != nil {
if err := f.reopen(); err != nil {
t.Fatal(err)
} else if q := f.CacheSize(); q != cacheSize {
t.Fatalf("unexpected field cache size (reopen): %d", q)

View file

@ -26,8 +26,8 @@ type Index struct {
*pilosa.Index
}
// NewIndex returns a new instance of Index.
func NewIndex() *Index {
// newIndex returns a new instance of Index.
func newIndex() *Index {
path, err := ioutil.TempDir("", "pilosa-index-")
if err != nil {
panic(err)
@ -41,7 +41,7 @@ func NewIndex() *Index {
// MustOpenIndex returns a new, opened index at a temporary path. Panic on error.
func MustOpenIndex() *Index {
index := NewIndex()
index := newIndex()
if err := index.Open(); err != nil {
panic(err)
}

View file

@ -20,20 +20,20 @@ import (
"io/ioutil"
)
// BufferLogger represents a test Logger that holds log messages
// bufferLogger represents a test Logger that holds log messages
// in a buffer for review.
type BufferLogger struct {
type bufferLogger struct {
buf *bytes.Buffer
}
// NewBufferLogger returns a new instance of BufferLogger.
func NewBufferLogger() *BufferLogger {
return &BufferLogger{
func NewBufferLogger() *bufferLogger {
return &bufferLogger{
buf: &bytes.Buffer{},
}
}
func (b *BufferLogger) Printf(format string, v ...interface{}) {
func (b *bufferLogger) Printf(format string, v ...interface{}) {
s := fmt.Sprintf(format, v...)
_, err := b.buf.WriteString(s)
if err != nil {
@ -41,8 +41,8 @@ func (b *BufferLogger) Printf(format string, v ...interface{}) {
}
}
func (b *BufferLogger) Debugf(format string, v ...interface{}) {}
func (b *bufferLogger) Debugf(format string, v ...interface{}) {}
func (b *BufferLogger) ReadAll() ([]byte, error) {
func (b *bufferLogger) ReadAll() ([]byte, error) {
return ioutil.ReadAll(b.buf)
}

View file

@ -36,9 +36,9 @@ type Command struct {
commandOptions []server.CommandOption
Stdin bytes.Buffer
Stdout bytes.Buffer
Stderr bytes.Buffer
stdin bytes.Buffer
stdout bytes.Buffer
stderr bytes.Buffer
}
func OptAllowedOrigins(origins []string) server.CommandOption {
@ -48,8 +48,8 @@ func OptAllowedOrigins(origins []string) server.CommandOption {
}
}
// NewCommand returns a new instance of Main with a temporary data directory and random port.
func NewCommand(opts ...server.CommandOption) *Command {
// newCommand returns a new instance of Main with a temporary data directory and random port.
func newCommand(opts ...server.CommandOption) *Command {
path, err := ioutil.TempDir("", "pilosa-")
if err != nil {
panic(err)
@ -59,9 +59,9 @@ func NewCommand(opts ...server.CommandOption) *Command {
m.Config.DataDir = path
m.Config.Bind = "http://localhost:0"
m.Config.Cluster.Disabled = true
m.Command.Stdin = &m.Stdin
m.Command.Stdout = &m.Stdout
m.Command.Stderr = &m.Stderr
m.Command.Stdin = &m.stdin
m.Command.Stdout = &m.stdout
m.Command.Stderr = &m.stderr
if testing.Verbose() {
m.Command.Stdout = io.MultiWriter(os.Stdout, m.Command.Stdout)
@ -73,7 +73,7 @@ func NewCommand(opts ...server.CommandOption) *Command {
// NewCommandNode returns a new instance of Command with clustering enabled.
func NewCommandNode(isCoordinator bool, opts ...server.CommandOption) *Command {
m := NewCommand(opts...)
m := newCommand(opts...)
m.Config.Cluster.Disabled = false
m.Config.Cluster.Coordinator = isCoordinator
return m
@ -81,7 +81,7 @@ func NewCommandNode(isCoordinator bool, opts ...server.CommandOption) *Command {
// MustRunCommand returns a new, running Main. Panic on error.
func MustRunCommand() *Command {
m := NewCommand()
m := newCommand()
m.Config.Metric.Diagnostics = false // Disable diagnostics.
if err := m.Start(); err != nil {
panic(err)

View file

@ -67,13 +67,13 @@ type TranslateFile struct {
rows map[frameKey]*index
Path string
MapSize int
mapSize int
// If non-nil, data is streamed from a primary and this is a read-only store.
PrimaryTranslateStore TranslateStore
// Delay after attempting to connect to a primary that the store will retry.
ReplicationRetryInterval time.Duration
replicationRetryInterval time.Duration
}
// NewTranslateFile returns a new instance of TranslateFile.
@ -84,9 +84,9 @@ func NewTranslateFile() *TranslateFile {
cols: make(map[string]*index),
rows: make(map[frameKey]*index),
MapSize: DefaultMapSize,
mapSize: defaultMapSize,
ReplicationRetryInterval: defaultReplicationRetryInterval,
replicationRetryInterval: defaultReplicationRetryInterval,
}
}
@ -100,7 +100,7 @@ func (s *TranslateFile) Open() (err error) {
s.w = bufio.NewWriter(s.file)
// Memory map data file.
if s.data, err = syscall.Mmap(int(s.file.Fd()), 0, s.MapSize, syscall.PROT_READ, syscall.MAP_SHARED); err != nil {
if s.data, err = syscall.Mmap(int(s.file.Fd()), 0, s.mapSize, syscall.PROT_READ, syscall.MAP_SHARED); err != nil {
return err
}
@ -142,16 +142,16 @@ func (s *TranslateFile) Closing() <-chan struct{} {
return s.closing
}
// Size returns the number of bytes in use in the data file.
func (s *TranslateFile) Size() int64 {
// size returns the number of bytes in use in the data file.
func (s *TranslateFile) size() int64 {
s.mu.RLock()
n := s.n
s.mu.RUnlock()
return n
}
// IsReadOnly returns true if this store is being replicated from a primary store.
func (s *TranslateFile) IsReadOnly() bool {
// isReadOnly returns true if this store is being replicated from a primary store.
func (s *TranslateFile) isReadOnly() bool {
return s.PrimaryTranslateStore != nil
}
@ -193,7 +193,7 @@ func (s *TranslateFile) appendEntry(entry *LogEntry) error {
func (s *TranslateFile) applyEntry(entry *LogEntry, offset int64) error {
// Move offset to the start of the id/key pairs.
offset += entry.HeaderSize()
offset += entry.headerSize()
var idx *index
switch entry.Type {
@ -270,14 +270,14 @@ func (s *TranslateFile) monitorReplication() {
select {
case <-s.closing:
return
case <-time.After(s.ReplicationRetryInterval):
case <-time.After(s.replicationRetryInterval):
log.Printf("pilosa: reconnecting to primary replica")
}
}
}
func (s *TranslateFile) replicate(ctx context.Context) error {
off := s.Size()
off := s.size()
// Connect to remote primary.
log.Printf("pilosa: replicating from offset %d", off)
@ -351,7 +351,7 @@ func (s *TranslateFile) TranslateColumnsToUint64(index string, values []string)
s.mu.RUnlock()
// Return error if not all values could be translated and this store is read-only.
if s.IsReadOnly() {
if s.isReadOnly() {
return ret, ErrTranslateStoreReadOnly
}
@ -457,7 +457,7 @@ func (s *TranslateFile) TranslateRowsToUint64(index, frame string, values []stri
s.mu.RUnlock()
// Return error if not all values could be translated and this store is read-only.
if s.IsReadOnly() {
if s.isReadOnly() {
return ret, ErrTranslateStoreReadOnly
}
@ -538,7 +538,7 @@ func (s *TranslateFile) TranslateRowToString(index, frame string, id uint64) (st
// Reader returns a reader that streams the underlying data file.
func (s *TranslateFile) Reader(ctx context.Context, offset int64) (io.ReadCloser, error) {
rc := NewTranslateFileReader(ctx, s, offset)
rc := newTranslateFileReader(ctx, s, offset)
if err := rc.Open(); err != nil {
return nil, err
}
@ -558,8 +558,8 @@ type LogEntry struct {
Length uint64
}
// HeaderSize returns the number of bytes required for size, type, index, frame, & pair count.
func (e *LogEntry) HeaderSize() int64 {
// headerSize returns the number of bytes required for size, type, index, frame, & pair count.
func (e *LogEntry) headerSize() int64 {
sz := uVarintSize(e.Length) + // total entry length
1 + // type
uVarintSize(uint64(len(e.Index))) + len(e.Index) + // Index length and data
@ -898,8 +898,8 @@ func pow2(v uint64) uint64 {
panic("unreachable")
}
// TranslateFileReader implements a reader that continuously streams data from a store.
type TranslateFileReader struct {
// translateFileReader implements a reader that continuously streams data from a store.
type translateFileReader struct {
ctx context.Context
store *TranslateFile
file *os.File
@ -910,9 +910,9 @@ type TranslateFileReader struct {
closing chan struct{}
}
// NewTranslateFileReader returns a new instance of TranslateFileReader.
func NewTranslateFileReader(ctx context.Context, store *TranslateFile, offset int64) *TranslateFileReader {
return &TranslateFileReader{
// newTranslateFileReader returns a new instance of TranslateFileReader.
func newTranslateFileReader(ctx context.Context, store *TranslateFile, offset int64) *translateFileReader {
return &translateFileReader{
ctx: ctx,
store: store,
offset: offset,
@ -922,7 +922,7 @@ func NewTranslateFileReader(ctx context.Context, store *TranslateFile, offset in
}
// Open initializes the reader.
func (r *TranslateFileReader) Open() (err error) {
func (r *translateFileReader) Open() (err error) {
if r.file, err = os.Open(r.store.Path); err != nil {
return err
}
@ -930,7 +930,7 @@ func (r *TranslateFileReader) Open() (err error) {
}
// Close closes the underlying file reader.
func (r *TranslateFileReader) Close() error {
func (r *translateFileReader) Close() error {
r.once.Do(func() { close(r.closing) })
if r.file != nil {
@ -941,7 +941,7 @@ func (r *TranslateFileReader) Close() error {
// Read reads the next section of the available data to p. This should always
// read from the start of an entry and read n bytes to the end of another entry.
func (r *TranslateFileReader) Read(p []byte) (n int, err error) {
func (r *translateFileReader) Read(p []byte) (n int, err error) {
for {
// Obtain notification channel before we check for new data.
notify := r.store.WriteNotify()
@ -966,8 +966,8 @@ func (r *TranslateFileReader) Read(p []byte) (n int, err error) {
}
// read writes the bytes for zero or more valid entries to p.
func (r *TranslateFileReader) read(p []byte) (n int, err error) {
sz := r.store.Size()
func (r *translateFileReader) read(p []byte) (n int, err error) {
sz := r.store.size()
// Exit if there is no new data.
if sz < r.offset {

View file

@ -2,7 +2,7 @@
package pilosa
// DefaultMapSize is the default size of mapped memory for the translate store.
// defaultMapSize is the default size of mapped memory for the translate store.
// It is passed as an int to syscall.Mmap and so can only be larger than 2^31 on
// 64bit systems.
const DefaultMapSize = 10 * (1 << 30) // 10GB
const defaultMapSize = 10 * (1 << 30) // 10GB

22
uri.go
View file

@ -47,8 +47,8 @@ type URI struct {
Port uint16 `json:"port"`
}
// DefaultURI creates and returns the default URI.
func DefaultURI() *URI {
// defaultURI creates and returns the default URI.
func defaultURI() *URI {
return &URI{
Scheme: "http",
Host: "localhost",
@ -68,8 +68,8 @@ func (u URIs) HostPortStrings() []string {
// NewURIFromHostPort returns a URI with specified host and port.
func NewURIFromHostPort(host string, port uint16) (*URI, error) {
uri := DefaultURI()
err := uri.SetHost(host)
uri := defaultURI()
err := uri.setHost(host)
if err != nil {
return nil, errors.Wrap(err, "setting uri host")
}
@ -82,8 +82,8 @@ func NewURIFromAddress(address string) (*URI, error) {
return parseAddress(address)
}
// SetScheme sets the scheme of this URI.
func (u *URI) SetScheme(scheme string) error {
// setScheme sets the scheme of this URI.
func (u *URI) setScheme(scheme string) error {
m := schemeRegexp.FindStringSubmatch(scheme)
if m == nil {
return errors.New("invalid scheme")
@ -92,8 +92,8 @@ func (u *URI) SetScheme(scheme string) error {
return nil
}
// SetHost sets the host of this URI.
func (u *URI) SetHost(host string) error {
// setHost sets the host of this URI.
func (u *URI) setHost(host string) error {
m := hostRegexp.FindStringSubmatch(host)
if m == nil {
return errors.New("invalid host")
@ -117,8 +117,8 @@ func (u *URI) HostPort() string {
return s
}
// Normalize returns the address in a form usable by a HTTP client.
func (u *URI) Normalize() string {
// normalize returns the address in a form usable by a HTTP client.
func (u *URI) normalize() string {
scheme := u.Scheme
index := strings.Index(scheme, "+")
if index >= 0 {
@ -134,7 +134,7 @@ func (u URI) String() string {
// Path returns URI with path
func (u *URI) Path(path string) string {
return fmt.Sprintf("%s%s", u.Normalize(), path)
return fmt.Sprintf("%s%s", u.normalize(), path)
}
// The following methods are required to implement pflag Value interface.

View file

@ -17,7 +17,7 @@ package pilosa
import "testing"
func TestDefaultURI(t *testing.T) {
uri := DefaultURI()
uri := defaultURI()
compare(t, uri, "http", "localhost", 10101)
}
@ -60,7 +60,7 @@ func TestNormalizedAddress(t *testing.T) {
if err != nil {
t.Fatalf("Can't parse address")
}
if uri.Normalize() != "http://big-data.pilosa.com:6888" {
if uri.normalize() != "http://big-data.pilosa.com:6888" {
t.Fatalf("Normalized address is not normal")
}
}
@ -77,9 +77,9 @@ func TestURIPath(t *testing.T) {
}
func TestSetScheme(t *testing.T) {
uri := DefaultURI()
uri := defaultURI()
target := "fun"
err := uri.SetScheme(target)
err := uri.setScheme(target)
if err != nil {
t.Fatal(err)
}
@ -89,9 +89,9 @@ func TestSetScheme(t *testing.T) {
}
func TestSetHost(t *testing.T) {
uri := DefaultURI()
uri := defaultURI()
target := "10.20.30.40"
err := uri.SetHost(target)
err := uri.setHost(target)
if err != nil {
t.Fatal(err)
}
@ -101,7 +101,7 @@ func TestSetHost(t *testing.T) {
}
func TestSetPort(t *testing.T) {
uri := DefaultURI()
uri := defaultURI()
target := uint16(9999)
uri.SetPort(target)
if uri.Port != target {
@ -110,16 +110,16 @@ func TestSetPort(t *testing.T) {
}
func TestSetInvalidScheme(t *testing.T) {
uri := DefaultURI()
err := uri.SetScheme("?invalid")
uri := defaultURI()
err := uri.setScheme("?invalid")
if err == nil {
t.Fatalf("Should have failed")
}
}
func TestSetInvalidHost(t *testing.T) {
uri := DefaultURI()
err := uri.SetHost("index?.pilosa.com")
uri := defaultURI()
err := uri.setHost("index?.pilosa.com")
if err == nil {
t.Fatalf("Should have failed")
}

View file

@ -37,7 +37,7 @@ func NewTestCluster(n int) *cluster {
c.ReplicaN = 1
c.Hasher = NewTestModHasher()
c.Path = path
c.Topology = NewTopology()
c.Topology = newTopology()
for i := 0; i < n; i++ {
c.Nodes = append(c.Nodes, &Node{
@ -55,16 +55,16 @@ func NewTestCluster(n int) *cluster {
// NewTestURI is a test URI creator that intentionally swallows errors.
func NewTestURI(scheme, host string, port uint16) URI {
uri := DefaultURI()
uri.SetScheme(scheme)
uri.SetHost(host)
uri := defaultURI()
uri.setScheme(scheme)
uri.setHost(host)
uri.SetPort(port)
return *uri
}
func NewTestURIFromHostPort(host string, port uint16) URI {
uri := DefaultURI()
uri.SetHost(host)
uri := defaultURI()
uri.setHost(host)
uri.SetPort(port)
return *uri
}
@ -185,7 +185,7 @@ func (t *ClusterCluster) addNode() error {
// WriteTopology writes the given topology to disk.
func (t *ClusterCluster) WriteTopology(path string, top *Topology) error {
if buf, err := proto.Marshal(top.Encode()); err != nil {
if buf, err := proto.Marshal(top.encode()); err != nil {
return err
} else if err := ioutil.WriteFile(filepath.Join(path, ".topology"), buf, 0666); err != nil {
return err
@ -225,7 +225,7 @@ func (t *ClusterCluster) addCluster(i int, saveTopology bool) (*cluster, error)
c.ReplicaN = 1
c.Hasher = NewTestModHasher()
c.Path = path
c.Topology = NewTopology()
c.Topology = newTopology()
c.holder = h
c.Node = node
c.Coordinator = t.common.Nodes[0].ID // the first node is the coordinator
@ -277,7 +277,7 @@ func (t *ClusterCluster) Open() error {
if err := c.holder.Open(); err != nil {
return err
}
if err := c.setNodeState(NodeStateReady); err != nil {
if err := c.setNodeState(nodeStateReady); err != nil {
return err
}
}