func testMigrate(t *testing.T, dhashes []*Node) { for _, d := range dhashes { d.Clear() } var item common.Item for i := 0; i < 1000; i++ { item.Key = []byte(fmt.Sprint(i)) item.Value = []byte(fmt.Sprint(i)) item.Timestamp = 1 dhashes[0].Put(item) } common.AssertWithin(t, func() (string, bool) { sum := 0 status := new(bytes.Buffer) ordered := dhashAry(dhashes) sort.Sort(ordered) lastOwned := ordered[len(ordered)-1].Owned() ok := true for _, d := range ordered { sum += d.Owned() fmt.Fprintf(status, "%v %v %v\n", d.node.GetBroadcastAddr(), common.HexEncode(d.node.GetPosition()), d.Owned()) if float64(lastOwned)/float64(d.Owned()) > migrateHysteresis { ok = false } if d.Owned() == 0 { ok = false } lastOwned = d.Owned() } return string(status.Bytes()), ok && sum == 1000 }, time.Second*100) }
func (self *Node) SetExpression(expr setop.SetExpression, items *[]setop.SetOpResult) (err error) { if expr.Dest != nil { if expr.Op.Merge == setop.Append { err = fmt.Errorf("When storing results of Set expressions the Append merge function is not allowed") return } successor := self.node.GetSuccessorFor(expr.Dest) if successor.Addr != self.node.GetBroadcastAddr() { return successor.Call("DHash.SetExpression", expr, items) } } data := common.Item{ Key: expr.Dest, } err = expr.Each(func(b []byte) (result setop.Skipper, err error) { succ := self.node.GetSuccessorFor(b) res := &treeSkipper{ remote: succ, key: b, } if succ.Addr == self.node.GetBroadcastAddr() { res.tree = self.tree } result = res return }, func(res *setop.SetOpResult) { if expr.Dest == nil { *items = append(*items, *res) } else { data.SubKey = res.Key data.Value = res.Values[0] data.TTL = self.node.Redundancy() data.Timestamp = self.timer.ContinuousTime() self.subPut(data) } }) return }