remove lots of unused code

This commit is contained in:
Matt Jaffee 2018-07-05 15:35:32 -05:00
parent e76a90e69b
commit bbb93abd57
No known key found for this signature in database
GPG key ID: 08A3DFFF987B11BF
10 changed files with 11 additions and 644 deletions

4
api.go
View file

@ -770,8 +770,8 @@ func (api *API) SetCoordinator(ctx context.Context, id string) (oldNode, newNode
// Send the set-coordinator message to new node.
err = api.server.SendTo(
newNode,
&internal.SetCoordinatorMessage{
New: EncodeNode(newNode),
&SetCoordinatorMessage{
New: newNode,
})
if err != nil {
return nil, nil, fmt.Errorf("problem sending SetCoordinator message: %s", err)

View file

@ -17,8 +17,6 @@ package pilosa
import (
"fmt"
"github.com/gogo/protobuf/proto"
"github.com/pilosa/pilosa/internal"
"github.com/pkg/errors"
)
@ -165,88 +163,3 @@ func getMessageType(m Message) byte {
panic(fmt.Sprintf("don't have type for message %#v", m))
}
}
// UnmarshalMessage decodes the byte slice into a protobuf message.
func UnmarshalMessage(buf []byte) (proto.Message, error) {
typ, buf := buf[0], buf[1:]
var m proto.Message
switch typ {
case messageTypeCreateShard:
m = &internal.CreateShardMessage{}
case messageTypeCreateIndex:
m = &internal.CreateIndexMessage{}
case messageTypeDeleteIndex:
m = &internal.DeleteIndexMessage{}
case messageTypeCreateField:
m = &internal.CreateFieldMessage{}
case messageTypeDeleteField:
m = &internal.DeleteFieldMessage{}
case messageTypeCreateView:
m = &internal.CreateViewMessage{}
case messageTypeDeleteView:
m = &internal.DeleteViewMessage{}
case messageTypeClusterStatus:
m = &internal.ClusterStatus{}
case messageTypeResizeInstruction:
m = &internal.ResizeInstruction{}
case messageTypeResizeInstructionComplete:
m = &internal.ResizeInstructionComplete{}
case messageTypeSetCoordinator:
m = &internal.SetCoordinatorMessage{}
case messageTypeUpdateCoordinator:
m = &internal.UpdateCoordinatorMessage{}
case messageTypeNodeState:
m = &internal.NodeStateMessage{}
case messageTypeRecalculateCaches:
m = &internal.RecalculateCaches{}
case messageTypeNodeEvent:
m = &internal.NodeEventMessage{}
case messageTypeNodeStatus:
m = &internal.NodeStatus{}
default:
return nil, fmt.Errorf("invalid message type: %d", typ)
}
if err := proto.Unmarshal(buf, m); err != nil {
return nil, errors.Wrap(err, "unmarshalling")
}
return m, nil
}
func decode(m proto.Message) Message {
switch mt := m.(type) {
case *internal.CreateShardMessage:
return decodeCreateShardMessage(mt)
case *internal.CreateIndexMessage:
return decodeCreateIndexMessage(mt)
case *internal.DeleteIndexMessage:
return decodeDeleteIndexMessage(mt)
case *internal.CreateFieldMessage:
return decodeCreateFieldMessage(mt)
case *internal.DeleteFieldMessage:
return decodeDeleteFieldMessage(mt)
case *internal.CreateViewMessage:
return decodeCreateViewMessage(mt)
case *internal.DeleteViewMessage:
return decodeDeleteViewMessage(mt)
case *internal.ClusterStatus:
return decodeClusterStatus(mt)
case *internal.ResizeInstruction:
return decodeResizeInstruction(mt)
case *internal.ResizeInstructionComplete:
return decodeResizeInstructionComplete(mt)
case *internal.SetCoordinatorMessage:
return decodeSetCoordinatorMessage(mt)
case *internal.UpdateCoordinatorMessage:
return decodeUpdateCoordinatorMessage(mt)
case *internal.NodeStateMessage:
return decodeNodeStateMessage(mt)
case *internal.RecalculateCaches:
return decodeRecalculateCaches(mt)
case *internal.NodeEventMessage:
return decodeNodeEventMessage(mt)
case *internal.NodeStatus:
return decodeNodeStatus(mt)
}
return nil
}

View file

@ -1757,28 +1757,6 @@ type ResizeInstruction struct {
ClusterStatus *ClusterStatus
}
func decodeResizeInstruction(ri *internal.ResizeInstruction) *ResizeInstruction {
return &ResizeInstruction{
JobID: ri.JobID,
Node: DecodeNode(ri.Node),
Coordinator: DecodeNode(ri.Coordinator),
Sources: decodeResizeSources(ri.Sources),
Schema: decodeSchema(ri.Schema),
ClusterStatus: decodeClusterStatus(ri.ClusterStatus),
}
}
func encodeResizeInstruction(m *ResizeInstruction) *internal.ResizeInstruction {
return &internal.ResizeInstruction{
JobID: m.JobID,
Node: EncodeNode(m.Node),
Coordinator: EncodeNode(m.Coordinator),
Sources: encodeResizeSources(m.Sources),
Schema: encodeSchema(m.Schema),
ClusterStatus: encodeClusterStatus(m.ClusterStatus),
}
}
type ResizeSource struct {
Node *Node `protobuf:"bytes,1,opt,name=Node" json:"Node,omitempty"`
Index string `protobuf:"bytes,2,opt,name=Index,proto3" json:"Index,omitempty"`
@ -1787,192 +1765,11 @@ type ResizeSource struct {
Shard uint64 `protobuf:"varint,5,opt,name=Shard,proto3" json:"Shard,omitempty"`
}
func decodeResizeSources(srcs []*internal.ResizeSource) []*ResizeSource {
new := make([]*ResizeSource, 0, len(srcs))
for _, src := range srcs {
new = append(new, decodeResizeSource(src))
}
return new
}
func encodeResizeSources(srcs []*ResizeSource) []*internal.ResizeSource {
new := make([]*internal.ResizeSource, 0, len(srcs))
for _, src := range srcs {
new = append(new, encodeResizeSource(src))
}
return new
}
func decodeResizeSource(rs *internal.ResizeSource) *ResizeSource {
return &ResizeSource{
Node: DecodeNode(rs.Node),
Index: rs.Index,
Field: rs.Field,
View: rs.View,
Shard: rs.Shard,
}
}
func encodeResizeSource(m *ResizeSource) *internal.ResizeSource {
return &internal.ResizeSource{
Node: EncodeNode(m.Node),
Index: m.Index,
Field: m.Field,
View: m.View,
Shard: m.Shard,
}
}
// Schema is a schema
type Schema struct {
Indexes []*IndexInfo
}
func decodeSchema(s *internal.Schema) *Schema {
return &Schema{
Indexes: decodeIndexes(s.Indexes),
}
}
func encodeSchema(m *Schema) *internal.Schema {
return &internal.Schema{
Indexes: encodeIndexInfos(m.Indexes),
}
}
func decodeIndexes(idxs []*internal.Index) []*IndexInfo {
new := make([]*IndexInfo, 0, len(idxs))
for _, idx := range idxs {
new = append(new, decodeIndex(idx))
}
return new
}
func encodeIndexInfos(idxs []*IndexInfo) []*internal.Index {
new := make([]*internal.Index, 0, len(idxs))
for _, idx := range idxs {
new = append(new, encodeIndexInfo(idx))
}
return new
}
func decodeIndex(idx *internal.Index) *IndexInfo {
return &IndexInfo{
Name: idx.Name,
Fields: decodeFields(idx.Fields),
}
}
func encodeIndexInfo(idx *IndexInfo) *internal.Index {
return &internal.Index{
Name: idx.Name,
Fields: encodeFieldInfos(idx.Fields),
}
}
func decodeFields(fs []*internal.Field) []*FieldInfo {
new := make([]*FieldInfo, 0, len(fs))
for _, f := range fs {
new = append(new, decodeField(f))
}
return new
}
func encodeFieldInfos(fs []*FieldInfo) []*internal.Field {
new := make([]*internal.Field, 0, len(fs))
for _, f := range fs {
new = append(new, encodeFieldInfo(f))
}
return new
}
func decodeField(f *internal.Field) *FieldInfo {
fi := &FieldInfo{
Name: f.Name,
Options: *decodeFieldOptions(f.Meta),
Views: make([]*ViewInfo, 0, len(f.Views)),
}
for _, viewname := range f.Views {
fi.Views = append(fi.Views, &ViewInfo{Name: viewname})
}
return fi
}
func encodeFieldInfo(f *FieldInfo) *internal.Field {
ifield := &internal.Field{
Name: f.Name,
Meta: encodeFieldOptions(&f.Options),
Views: make([]string, 0, len(f.Views)),
}
for _, viewinfo := range f.Views {
ifield.Views = append(ifield.Views, viewinfo.Name)
}
return ifield
}
// EncodeNodes converts a slice of Nodes into its internal representation.
func EncodeNodes(a []*Node) []*internal.Node {
other := make([]*internal.Node, len(a))
for i := range a {
other[i] = EncodeNode(a[i])
}
return other
}
// EncodeNode converts a Node into its internal representation.
func EncodeNode(n *Node) *internal.Node {
return &internal.Node{
ID: n.ID,
URI: n.URI.Encode(),
IsCoordinator: n.IsCoordinator,
}
}
// DecodeNodes converts a proto message into a slice of Nodes.
func DecodeNodes(a []*internal.Node) []*Node {
if len(a) == 0 {
return nil
}
other := make([]*Node, len(a))
for i := range a {
other[i] = DecodeNode(a[i])
}
return other
}
func decodeClusterStatus(cs *internal.ClusterStatus) *ClusterStatus {
return &ClusterStatus{
State: cs.State,
ClusterID: cs.ClusterID,
Nodes: DecodeNodes(cs.Nodes),
}
}
func encodeClusterStatus(m *ClusterStatus) *internal.ClusterStatus {
return &internal.ClusterStatus{
State: m.State,
ClusterID: m.ClusterID,
Nodes: EncodeNodes(m.Nodes),
}
}
// DecodeNode converts a proto message into a Node.
func DecodeNode(node *internal.Node) *Node {
return &Node{
ID: node.ID,
URI: decodeURI(node.URI),
IsCoordinator: node.IsCoordinator,
}
}
func DecodeNodeEvent(ne *internal.NodeEventMessage) *NodeEvent {
return &NodeEvent{
Event: NodeEventType(ne.Event),
Node: DecodeNode(ne.Node),
}
}
func encodeTopology(topology *Topology) *internal.Topology {
if topology == nil {
return nil
@ -2004,267 +1801,60 @@ type CreateShardMessage struct {
Shard uint64
}
func encodeCreateShardMessage(m *CreateShardMessage) *internal.CreateShardMessage {
return &internal.CreateShardMessage{
Index: m.Index,
Shard: m.Shard,
}
}
func decodeCreateShardMessage(pb *internal.CreateShardMessage) *CreateShardMessage {
return &CreateShardMessage{
Index: pb.Index,
Shard: pb.Shard,
}
}
type CreateIndexMessage struct {
Index string
Meta *IndexOptions
}
func encodeCreateIndexMessage(m *CreateIndexMessage) *internal.CreateIndexMessage {
return &internal.CreateIndexMessage{
Index: m.Index,
Meta: encodeIndexMeta(m.Meta),
}
}
func decodeCreateIndexMessage(pb *internal.CreateIndexMessage) *CreateIndexMessage {
return &CreateIndexMessage{
Index: pb.Index,
Meta: decodeIndexMeta(pb.Meta),
}
}
func encodeIndexMeta(m *IndexOptions) *internal.IndexMeta {
return &internal.IndexMeta{
Keys: m.Keys,
}
}
func decodeIndexMeta(pb *internal.IndexMeta) *IndexOptions {
return &IndexOptions{
Keys: pb.Keys,
}
}
type DeleteIndexMessage struct {
Index string
}
func encodeDeleteIndexMessage(m *DeleteIndexMessage) *internal.DeleteIndexMessage {
return &internal.DeleteIndexMessage{
Index: m.Index,
}
}
func decodeDeleteIndexMessage(pb *internal.DeleteIndexMessage) *DeleteIndexMessage {
return &DeleteIndexMessage{
Index: pb.Index,
}
}
type CreateFieldMessage struct {
Index string
Field string
Meta *FieldOptions
}
func encodeCreateFieldMessage(m *CreateFieldMessage) *internal.CreateFieldMessage {
return &internal.CreateFieldMessage{
Index: m.Index,
Field: m.Field,
Meta: encodeFieldOptions(m.Meta),
}
}
func decodeCreateFieldMessage(pb *internal.CreateFieldMessage) *CreateFieldMessage {
return &CreateFieldMessage{
Index: pb.Index,
Field: pb.Field,
Meta: decodeFieldOptions(pb.Meta),
}
}
type DeleteFieldMessage struct {
Index string
Field string
}
func encodeDeleteFieldMessage(m *DeleteFieldMessage) *internal.DeleteFieldMessage {
return &internal.DeleteFieldMessage{
Index: m.Index,
Field: m.Field,
}
}
func decodeDeleteFieldMessage(pb *internal.DeleteFieldMessage) *DeleteFieldMessage {
return &DeleteFieldMessage{
Index: pb.Index,
Field: pb.Field,
}
}
type CreateViewMessage struct {
Index string
Field string
View string
}
func encodeCreateViewMessage(m *CreateViewMessage) *internal.CreateViewMessage {
return &internal.CreateViewMessage{
Index: m.Index,
Field: m.Field,
View: m.View,
}
}
func decodeCreateViewMessage(pb *internal.CreateViewMessage) *CreateViewMessage {
return &CreateViewMessage{
Index: pb.Index,
Field: pb.Field,
View: pb.View,
}
}
type DeleteViewMessage struct {
Index string
Field string
View string
}
func encodeDeleteViewMessage(m *DeleteViewMessage) *internal.DeleteViewMessage {
return &internal.DeleteViewMessage{
Index: m.Index,
Field: m.Field,
View: m.View,
}
}
func decodeDeleteViewMessage(pb *internal.DeleteViewMessage) *DeleteViewMessage {
return &DeleteViewMessage{
Index: pb.Index,
Field: pb.Field,
View: pb.View,
}
}
type ResizeInstructionComplete struct {
JobID int64
Node *Node
Error string
}
func encodeResizeInstructionComplete(m *ResizeInstructionComplete) *internal.ResizeInstructionComplete {
return &internal.ResizeInstructionComplete{
JobID: m.JobID,
Node: EncodeNode(m.Node),
Error: m.Error,
}
}
func decodeResizeInstructionComplete(pb *internal.ResizeInstructionComplete) *ResizeInstructionComplete {
return &ResizeInstructionComplete{
JobID: pb.JobID,
Node: DecodeNode(pb.Node),
Error: pb.Error,
}
}
type SetCoordinatorMessage struct {
New *Node
}
func encodeSetCoordinatorMessage(m *SetCoordinatorMessage) *internal.SetCoordinatorMessage {
return &internal.SetCoordinatorMessage{
New: EncodeNode(m.New),
}
}
func decodeSetCoordinatorMessage(pb *internal.SetCoordinatorMessage) *SetCoordinatorMessage {
return &SetCoordinatorMessage{
New: DecodeNode(pb.New),
}
}
type UpdateCoordinatorMessage struct {
New *Node
}
func encodeUpdateCoordinatorMessage(m *UpdateCoordinatorMessage) *internal.UpdateCoordinatorMessage {
return &internal.UpdateCoordinatorMessage{
New: EncodeNode(m.New),
}
}
func decodeUpdateCoordinatorMessage(pb *internal.UpdateCoordinatorMessage) *UpdateCoordinatorMessage {
return &UpdateCoordinatorMessage{
New: DecodeNode(pb.New),
}
}
type NodeStateMessage struct {
NodeID string `protobuf:"bytes,1,opt,name=NodeID,proto3" json:"NodeID,omitempty"`
State string `protobuf:"bytes,2,opt,name=State,proto3" json:"State,omitempty"`
}
func encodeNodeStateMessage(m *NodeStateMessage) *internal.NodeStateMessage {
return &internal.NodeStateMessage{
NodeID: m.NodeID,
State: m.State,
}
}
func decodeNodeStateMessage(pb *internal.NodeStateMessage) *NodeStateMessage {
return &NodeStateMessage{
NodeID: pb.NodeID,
State: pb.State,
}
}
func encodeNodeEventMessage(m *NodeEvent) *internal.NodeEventMessage {
return &internal.NodeEventMessage{
Event: uint32(m.Event),
Node: EncodeNode(m.Node),
}
}
func decodeNodeEventMessage(pb *internal.NodeEventMessage) *NodeEvent {
return &NodeEvent{
Event: NodeEventType(pb.Event),
Node: DecodeNode(pb.Node),
}
}
type NodeStatus struct {
Node *Node
MaxShards map[string]uint64
Schema *Schema
}
func encodeNodeStatus(m *NodeStatus) *internal.NodeStatus {
return &internal.NodeStatus{
Node: EncodeNode(m.Node),
MaxShards: &internal.MaxShards{Standard: m.MaxShards},
Schema: encodeSchema(m.Schema),
}
}
func decodeNodeStatus(pb *internal.NodeStatus) *NodeStatus {
return &NodeStatus{
Node: DecodeNode(pb.Node),
MaxShards: pb.MaxShards.Standard,
Schema: decodeSchema(pb.Schema),
}
}
type RecalculateCaches struct{}
func decodeRecalculateCaches(pb *internal.RecalculateCaches) *RecalculateCaches {
return &RecalculateCaches{}
}
func encodeRecalculateCaches(*RecalculateCaches) *internal.RecalculateCaches {
return &internal.RecalculateCaches{}
}

View file

@ -375,11 +375,19 @@ func EncodeNodes(a []*pilosa.Node) []*internal.Node {
func encodeNode(n *pilosa.Node) *internal.Node {
return &internal.Node{
ID: n.ID,
URI: n.URI.Encode(),
URI: encodeURI(n.URI),
IsCoordinator: n.IsCoordinator,
}
}
func encodeURI(u pilosa.URI) *internal.URI {
return &internal.URI{
Scheme: u.Scheme,
Host: u.Host,
Port: uint32(u.Port),
}
}
func encodeClusterStatus(m *pilosa.ClusterStatus) *internal.ClusterStatus {
return &internal.ClusterStatus{
State: m.State,

View file

@ -20,7 +20,6 @@ import (
"sort"
"time"
"github.com/pilosa/pilosa/internal"
"github.com/pilosa/pilosa/pql"
"github.com/pkg/errors"
)
@ -1738,20 +1737,6 @@ func (vc *ValCount) Add(other ValCount) ValCount {
}
}
func EncodeValCount(vc ValCount) *internal.ValCount {
return &internal.ValCount{
Val: vc.Val,
Count: vc.Count,
}
}
func decodeValCount(pb *internal.ValCount) ValCount {
return ValCount{
Val: pb.Val,
Count: pb.Count,
}
}
// 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) {

View file

@ -1088,25 +1088,6 @@ func (f *Field) MarshalJSON() ([]byte, error) {
return json.Marshal(thing)
}
// encodeFields converts a into its internal representation.
func encodeFields(a []*Field) []*internal.Field {
other := make([]*internal.Field, len(a))
for i := range a {
other[i] = encodeField(a[i])
}
return other
}
// encodeField converts f into its internal representation.
func encodeField(f *Field) *internal.Field {
fo := f.options
return &internal.Field{
Name: f.name,
Meta: fo.Encode(),
Views: f.viewNames(),
}
}
type fieldSlice []*Field
func (p fieldSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
@ -1170,21 +1151,6 @@ func encodeFieldOptions(o *FieldOptions) *internal.FieldOptions {
}
}
func decodeFieldOptions(options *internal.FieldOptions) *FieldOptions {
if options == nil {
return nil
}
return &FieldOptions{
Type: options.Type,
CacheType: options.CacheType,
CacheSize: options.CacheSize,
Min: options.Min,
Max: options.Max,
TimeQuantum: TimeQuantum(options.TimeQuantum),
Keys: options.Keys,
}
}
func (o *FieldOptions) MarshalJSON() ([]byte, error) {
switch o.Type {
case FieldTypeSet:

View file

@ -27,7 +27,6 @@ import (
"syscall"
"time"
"github.com/pilosa/pilosa/internal"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
)
@ -256,20 +255,6 @@ func (h *Holder) applySchema(schema *Schema) error {
return nil
}
// encodeMaxShards creates and internal representation of max shards.
func (h *Holder) encodeMaxShards() *internal.MaxShards {
return &internal.MaxShards{
Standard: h.maxShards(),
}
}
// encodeSchema creates an internal representation of schema.
func (h *Holder) encodeSchema() *internal.Schema {
return &internal.Schema{
Indexes: EncodeIndexes(h.Indexes()),
}
}
// IndexPath returns the path where a given index is stored.
func (h *Holder) IndexPath(name string) string { return filepath.Join(h.Path, name) }

View file

@ -403,35 +403,11 @@ func (p indexInfoSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p indexInfoSlice) Len() int { return len(p) }
func (p indexInfoSlice) Less(i, j int) bool { return p[i].Name < p[j].Name }
// EncodeIndexes converts a into its internal representation.
func EncodeIndexes(a []*Index) []*internal.Index {
other := make([]*internal.Index, len(a))
for i := range a {
other[i] = encodeIndex(a[i])
}
return other
}
// encodeIndex converts d into its internal representation.
func encodeIndex(d *Index) *internal.Index {
return &internal.Index{
Name: d.name,
Fields: encodeFields(d.Fields()),
}
}
// IndexOptions represents options to set when initializing an index.
type IndexOptions struct {
Keys bool `json:"keys"`
}
// Encode converts i into its internal representation.
func (i *IndexOptions) Encode() *internal.IndexMeta {
return &internal.IndexMeta{
Keys: i.Keys,
}
}
// hasTime returns true if a contains a non-nil time.
func hasTime(a []*time.Time) bool {
for _, t := range a {

27
row.go
View file

@ -18,7 +18,6 @@ import (
"encoding/json"
"sort"
"github.com/pilosa/pilosa/internal"
"github.com/pilosa/pilosa/roaring"
)
@ -271,32 +270,6 @@ func (r *Row) Columns() []uint64 {
return a
}
// EncodeRow converts r into its internal representation.
func EncodeRow(r *Row) *internal.Row {
if r == nil {
return nil
}
return &internal.Row{
Columns: r.Columns(),
Attrs: encodeAttrs(r.Attrs),
}
}
// DecodeRow converts r from its internal representation.
func DecodeRow(pr *internal.Row) *Row {
if pr == nil {
return nil
}
r := NewRow()
r.Attrs = decodeAttrs(pr.Attrs)
for _, v := range pr.Columns {
r.SetBit(v)
}
return r
}
// Union performs a union on a slice of rows.
func Union(rows []*Row) *Row {
other := rows[0]

29
uri.go
View file

@ -21,7 +21,6 @@ import (
"strconv"
"strings"
"github.com/pilosa/pilosa/internal"
"github.com/pkg/errors"
)
@ -206,34 +205,6 @@ func parseAddress(address string) (uri *URI, err error) {
return uri, nil
}
// Encode converts o into its internal representation.
func (u URI) Encode() *internal.URI {
return encodeURI(u)
}
func encodeURI(u URI) *internal.URI {
return &internal.URI{
Scheme: u.Scheme,
Host: u.Host,
Port: uint32(u.Port),
}
}
func DecodeURI(i *internal.URI) URI {
return decodeURI(i)
}
func decodeURI(i *internal.URI) URI {
if i == nil {
return URI{}
}
return URI{
Scheme: i.Scheme,
Host: i.Host,
Port: uint16(i.Port),
}
}
// MarshalJSON marshals URI into a JSON-encoded byte slice.
func (u *URI) MarshalJSON() ([]byte, error) {
var output struct {