GoRename Frame to Field in cluster.go

This commit is contained in:
Travis Turner 2018-06-05 22:42:21 -05:00
parent bcec20525b
commit bbf3e529dc
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9
2 changed files with 21 additions and 21 deletions

View file

@ -584,7 +584,7 @@ func (c *Cluster) removeNodeBasicSorted(node *Node) bool {
// frag is a struct of basic fragment information.
type frag struct {
frame string
field string
view string
slice uint64
}
@ -617,36 +617,36 @@ func (a fragsByHost) add(b fragsByHost) fragsByHost {
return a
}
type viewsByFrame map[string][]string
type viewsByField map[string][]string
func (a viewsByFrame) addView(frame, view string) {
a[frame] = append(a[frame], view)
func (a viewsByField) addView(field, view string) {
a[field] = append(a[field], view)
}
func (c *Cluster) fragsByHost(idx *Index) fragsByHost {
// frameViews is a map of frame to slice of views.
frameViews := make(viewsByFrame)
// fieldViews is a map of field to slice of views.
fieldViews := make(viewsByField)
for _, frame := range idx.Fields() {
for _, view := range frame.Views() {
frameViews.addView(frame.Name(), view.Name())
for _, field := range idx.Fields() {
for _, view := range field.Views() {
fieldViews.addView(field.Name(), view.Name())
}
}
return c.fragCombos(idx.Name(), idx.MaxSlice(), frameViews)
return c.fragCombos(idx.Name(), idx.MaxSlice(), fieldViews)
}
// fragCombos returns a map (by uri) of lists of fragments for a given index
// by creating every combination of frame/view specified in `frameViews` up to maxSlice.
func (c *Cluster) fragCombos(idx string, maxSlice uint64, frameViews viewsByFrame) fragsByHost {
// by creating every combination of field/view specified in `fieldViews` up to maxSlice.
func (c *Cluster) fragCombos(idx string, maxSlice uint64, fieldViews viewsByField) fragsByHost {
t := make(fragsByHost)
for i := uint64(0); i <= maxSlice; i++ {
nodes := c.SliceNodes(idx, i)
for _, n := range nodes {
// for each frame/view combination:
for frame, views := range frameViews {
// for each field/view combination:
for field, views := range fieldViews {
for _, view := range views {
t[n.ID] = append(t[n.ID], frag{frame, view, i})
t[n.ID] = append(t[n.ID], frag{field, view, i})
}
}
}
@ -770,7 +770,7 @@ func (c *Cluster) fragSources(to *Cluster, idx *Index) (map[string][]*internal.R
src := &internal.ResizeSource{
Node: EncodeNode(c.nodeByID(srcNodeID)),
Index: idx.Name(),
Frame: frag.frame,
Frame: frag.field,
View: frag.view,
Slice: frag.slice,
}
@ -1239,7 +1239,7 @@ func (c *Cluster) FollowResizeInstruction(instr *internal.ResizeInstruction) err
srcURI := decodeURI(src.Node.URI)
// Retrieve frame.
// Retrieve field.
f := c.Holder.Field(src.Index, src.Frame)
if f == nil {
return ErrFieldNotFound
@ -1275,7 +1275,7 @@ func (c *Cluster) FollowResizeInstruction(instr *internal.ResizeInstruction) err
return fmt.Errorf("slice %v doesn't exist on host: %s", src.Slice, src.Node.URI)
}
// Write to local frame and always close reader.
// Write to local field and always close reader.
if err := func() error {
defer rd.Close()
_, err := frag.ReadFrom(rd)

View file

@ -45,13 +45,13 @@ func TestFragCombos(t *testing.T) {
tests := []struct {
idx string
maxSlice uint64
frameViews viewsByFrame
frameViews viewsByField
expected fragsByHost
}{
{
idx: "i",
maxSlice: uint64(2),
frameViews: viewsByFrame{"f": []string{"v1", "v2"}},
frameViews: viewsByField{"f": []string{"v1", "v2"}},
expected: fragsByHost{
"node0": []frag{{"f", "v1", uint64(0)}, {"f", "v2", uint64(0)}},
"node1": []frag{{"f", "v1", uint64(1)}, {"f", "v2", uint64(1)}, {"f", "v1", uint64(2)}, {"f", "v2", uint64(2)}},
@ -60,7 +60,7 @@ func TestFragCombos(t *testing.T) {
{
idx: "foo",
maxSlice: uint64(3),
frameViews: viewsByFrame{"f": []string{"v0"}},
frameViews: viewsByField{"f": []string{"v0"}},
expected: fragsByHost{
"node0": []frag{{"f", "v0", uint64(1)}, {"f", "v0", uint64(2)}},
"node1": []frag{{"f", "v0", uint64(0)}, {"f", "v0", uint64(3)}},