func main() { c := runtime.NumCPU() * 2 runtime.GOMAXPROCS(1) conn := client.MustConn("") argsWithoutProg := os.Args[1:] var i info common.MustJSONDecode([]byte(argsWithoutProg[0]), &i) r := everything.RGet(i.rideID) fmt.Println(r.Name) p, _ := everything.GetG(append([]byte{0},[]byte{0}[0],[]byte{0}[0])) count := 0 t := true fmt.Print("[") for i := r.CurTrip; i < len(r.Times); i++ { if r.Capacity - r.Capacities[i] > 2 { a := r.GetTimeRange(i) for j := 0; j < len(p.Times); j++ { if between(a[0], a[1], p.Times[j][0], p.Times[j][1]) { t = false } } if t { conn.Put([]byte(strconv.Itoa(i)),common.MustJSONEncode(p.Times[j])) conn.Put([]byte(strconv.Itoa(i) + "r"),common.MustJSONEncode(r.K) fmt.Print("{" + r.Name + ":" + " [" + getTime(p.Times[j][0]) + "," + getTime(p.Times[j][1]) + "],id:" + strconv.Itoa(i) + "},") count += 1 } } if count == 3 { break } } fmt.Print("]") }
func testGOBClient(t *testing.T, dhashes []*Node) { fmt.Println(" === Run testGOBClient") clearAll(dhashes) c := client.MustConn(dhashes[0].GetBroadcastAddr()) c.Start() testClientInterface(t, dhashes, c) }
func main() { a := (s(3, 30, 50, 20, 27)) fmt.Println(a) fmt.Println(a) conn := client.MustConn("localhost:9191") bytes := common.MustJSONEncode(a) conn.Put(murmur.HashString("hi"), bytes) }
func main() { // connect to the default local server conn := client.MustConn("localhost:9191") // create a user // try to fetch the user again data, _ := conn.Get(murmur.HashString("hi")) var found []int // to unserialize it common.MustJSONDecode(data, &found) fmt.Printf("stored and found ", found) }
// // Puts a lifter (stored in the all lifters tree) together with best competition score, in ranking trees that are relevant // func PutLifterInRankingTrees(lifterItem common.Item) { conn := client.MustConn("localhost:9191") var lifterCompetitionItems []common.Item = conn.SliceIndex(lifterItem.Key, nil, nil) // Get all competitions under given lifter var lifter Lifter if err := json.Unmarshal(lifterItem.Value, &lifter); err != nil { panic(err) } var sinclairScores SinclairScoreByCategory = sortCompetitionRankingsByCategory(lifter, lifterCompetitionItems) if lifter.Sex == "female" { if sinclairScores.Youth != 0.0 { conn.SubPut(youthWomenRankingKey, lifterItem.Key, common.EncodeFloat64(sinclairScores.Youth)) } if sinclairScores.Junior != 0.0 { conn.SubPut(juniorWomenRankingKey, lifterItem.Key, common.EncodeFloat64(sinclairScores.Junior)) } if sinclairScores.Senior != 0.0 { conn.SubPut(seniorWomenRankingKey, lifterItem.Key, common.EncodeFloat64(sinclairScores.Senior)) } if sinclairScores.Veteran != 0.0 { conn.SubPut(veteranWomenRankingKey, lifterItem.Key, common.EncodeFloat64(sinclairScores.Veteran)) } } else { // Mens categories if sinclairScores.Youth != 0.0 { conn.SubPut(youthMenRankingKey, lifterItem.Key, common.EncodeFloat64(sinclairScores.Youth)) } if sinclairScores.Junior != 0.0 { conn.SubPut(juniorMenRankingKey, lifterItem.Key, common.EncodeFloat64(sinclairScores.Junior)) } if sinclairScores.Senior != 0.0 { conn.SubPut(seniorMenRankingKey, lifterItem.Key, common.EncodeFloat64(sinclairScores.Senior)) } if sinclairScores.Veteran != 0.0 { conn.SubPut(veteranMenRankingKey, lifterItem.Key, common.EncodeFloat64(sinclairScores.Veteran)) } } }
func (self *Slave) Prepare(command PrepareCommand, x *Nothing) error { if self.hasState(stopped) { fmt.Printf("Preparing %+v\n", command) self.client = client.MustConn(command.Addr) var kv []byte for i := command.Range[0]; i < command.Range[1]; i++ { kv = murmur.HashInt64(i) self.client.Put(kv, kv) if i%1000 == 0 { fmt.Print(".") } } fmt.Println("done!") } return nil }
func (self *Slave) Spin(command SpinCommand, result *SpinResult) error { if self.switchState(stopped, started) { fmt.Println("Spinning on ", command.Addr) self.wg = new(sync.WaitGroup) self.wg.Add(1) self.maxRps = 0 self.client = client.MustConn(command.Addr) self.maxKey = command.MaxKey go self.run() } else { fmt.Println("Already started on", self.addr) } *result = SpinResult{ Nodes: len(self.client.Nodes()), Keys: self.client.Size(), } return nil }
func main() { runtime.GOMAXPROCS(runtime.NumCPU()) flag.Parse() if *dir == address { *dir = fmt.Sprintf("%v:%v", *broadcastIp, *port) } s := dhash.NewNodeDir(fmt.Sprintf("%v:%v", *listenIp, *port), fmt.Sprintf("%v:%v", *broadcastIp, *port), *dir) s.MustStart() if *joinIp != "" { s.MustJoin(fmt.Sprintf("%v:%v", *joinIp, *joinPort)) } c := client.MustConn(s.GetListenAddr()) c.Start() setupUDPService(c) setupJSONService(c) }
// // Print ranking with only lifter Id and sinclair score // func PrintSimpleRanking() { conn := client.MustConn("localhost:9191") fmt.Println("Womens youth ranking") for _, scoreBox := range conn.MirrorSliceIndex(youthWomenRankingKey, nil, nil) { fmt.Println(string(scoreBox.Value), common.MustDecodeFloat64(scoreBox.Key)) } fmt.Println("\nWomens junior ranking") for _, scoreBox := range conn.MirrorSliceIndex(juniorWomenRankingKey, nil, nil) { fmt.Println(string(scoreBox.Value), common.MustDecodeFloat64(scoreBox.Key)) } fmt.Println("\nWomens senior ranking") for _, scoreBox := range conn.MirrorSliceIndex(seniorWomenRankingKey, nil, nil) { fmt.Println(string(scoreBox.Value), common.MustDecodeFloat64(scoreBox.Key)) } fmt.Println("\nWomens senior ranking") for _, scoreBox := range conn.MirrorSliceIndex(veteranWomenRankingKey, nil, nil) { fmt.Println(string(scoreBox.Value), common.MustDecodeFloat64(scoreBox.Key)) } fmt.Println("\nMens youth ranking") for _, scoreBox := range conn.MirrorSliceIndex(youthMenRankingKey, nil, nil) { fmt.Println(string(scoreBox.Value), common.MustDecodeFloat64(scoreBox.Key)) } fmt.Println("\nMens junior ranking") for _, scoreBox := range conn.MirrorSliceIndex(juniorMenRankingKey, nil, nil) { fmt.Println(string(scoreBox.Value), common.MustDecodeFloat64(scoreBox.Key)) } fmt.Println("\nMens senior ranking") for _, scoreBox := range conn.MirrorSliceIndex(seniorMenRankingKey, nil, nil) { fmt.Println(string(scoreBox.Value), common.MustDecodeFloat64(scoreBox.Key)) } fmt.Println("\nMens senior ranking") for _, scoreBox := range conn.MirrorSliceIndex(veteranMenRankingKey, nil, nil) { fmt.Println(string(scoreBox.Value), common.MustDecodeFloat64(scoreBox.Key)) } }
func BenchmarkClientAndServer(b *testing.B) { oldprocs := runtime.GOMAXPROCS(runtime.NumCPU()) defer runtime.GOMAXPROCS(oldprocs) b.StopTimer() if benchNode == nil { benchNode = NewNode("127.0.0.1:1231", "127.0.0.1:1231") benchNode.MustStart() } c := client.MustConn("127.0.0.1:1231") c.Clear() var bs [][]byte for i := 0; i < b.N; i++ { bs = append(bs, murmur.HashString(fmt.Sprint(i))) } b.StartTimer() for i := 0; i < b.N; i++ { c.Put(bs[i], bs[i]) } }
// // Initial proof of concept // Uses faked data // func ProofOfConcept() { competitionResults, lifters := ReadCsvFile() competitionResults2 := competitionResults conn := client.MustConn("localhost:9191") for index, lifter := range lifters { var lifterKey = []byte(lifter.Id) if _, exists := conn.SubGet(allLiftersKey, lifterKey); !exists { // Check if the lifter exists in the database already if serializedLifter, err := json.Marshal(lifter); err != nil { panic(err) } else { conn.SubPut(allLiftersKey, lifterKey, serializedLifter) // Put lifter in all lifters tree } } if serializedCompetitionResults, err := json.Marshal(competitionResults[index]); err != nil { panic(err) } else { conn.SubPut(lifterKey, []byte(fmt.Sprint(index)), serializedCompetitionResults) // Competition result put in lifter subtree } if serializedCompetitionResults2, err := json.Marshal(competitionResults2[index]); err != nil { panic(err) } else { competitionResults2[index].Snatch = competitionResults[index].Snatch + 1 conn.SubPut(lifterKey, []byte(fmt.Sprint(index*2+1)), serializedCompetitionResults2) // Faking extra competitions per lifter } } // Go through all lifters under the All Lifters tree for _, lifterItem := range conn.SliceIndex(allLiftersKey, nil, nil) { PutLifterInRankingTrees(lifterItem) } PrintSimpleRanking() }
func ExampleTreeMirror() { server := dhash.NewNodeDir("127.0.0.1:3030", "127.0.0.1:3030", "").MustStart() defer server.Stop() conn := client.MustConn("127.0.0.1:3030") conn.SubAddConfiguration([]byte("myfriends"), "mirrored", "yes") conn.SubPut([]byte("myfriends"), []byte("alice"), setop.EncodeFloat64(10)) conn.SubPut([]byte("myfriends"), []byte("bob"), setop.EncodeFloat64(5)) conn.SubPut([]byte("myfriends"), []byte("charlie"), setop.EncodeFloat64(6)) conn.SubPut([]byte("myfriends"), []byte("denise"), setop.EncodeFloat64(4)) fmt.Printf("name score\n") for _, friend := range conn.MirrorReverseSlice([]byte("myfriends"), nil, nil, true, true) { fmt.Printf("%v %v\n", fmt.Sprint(setop.DecodeFloat64(friend.Key)), string(friend.Value)) } // Output: // name score // 10 <nil> alice // 6 <nil> charlie // 5 <nil> bob // 4 <nil> denise }
func ExampleSetExpression() { server := dhash.NewNodeDir("127.0.0.1:2020", "127.0.0.1:2020", "").MustStart() defer server.Stop() conn := client.MustConn("127.0.0.1:2020") conn.SubPut([]byte("myfriends"), []byte("alice"), setop.EncodeFloat64(10)) conn.SubPut([]byte("myfriends"), []byte("bob"), setop.EncodeFloat64(5)) conn.SubPut([]byte("yourfriends"), []byte("bob"), setop.EncodeFloat64(6)) conn.SubPut([]byte("yourfriends"), []byte("charlie"), setop.EncodeFloat64(4)) fmt.Printf("name score\n") for _, friend := range conn.SetExpression(setop.SetExpression{ Code: "(U:FloatSum myfriends yourfriends)", }) { fmt.Printf("%v %v\n", string(friend.Key), fmt.Sprint(setop.DecodeFloat64(friend.Values[0]))) } // Output: // name score // alice 10 <nil> // bob 11 <nil> // charlie 4 <nil> }
func main() { //c := runtime.NumCPU() * 2 runtime.GOMAXPROCS(1) conn := client.MustConn("") argsWithoutProg := os.Args[1:] var i info common.MustJSONDecode([]byte(argsWithoutProg[0]), &i) s := strings.Split(string(i.times), "id:")[1] s = strings.Split(s, "}")[0] var time []int v, _ := conn.Get([]byte(s)) common.MustJSONDecode(v, &time) p, _ := everything.GetG(append([]byte{0}, []byte{0}[0], []byte{0}[0])) p.Times = append(p.Times, time) var ri []byte v, _ = conn.Get([]byte(s + "r")) common.MustJSONDecode(v, &ri) p.AppointRide = append(p.AppointRide, ri) p.Save() }
func main() { flag.Parse() conn := client.MustConn(fmt.Sprintf("%v:%v", *ip, *port)) if len(flag.Args()) == 0 { show(conn) } else { for spec, fun := range actions { if spec.cmd == flag.Args()[0] { matchingParts := true for index, reg := range spec.args { if !reg.MatchString(flag.Args()[index+1]) { matchingParts = false break } } if matchingParts { fun(conn, flag.Args()) return } } } fmt.Println("No command given?") } }
func testGOBClient(t *testing.T, dhashes []*Node) { clearAll(dhashes) c := client.MustConn(dhashes[0].GetAddr()) c.Start() testClientInterface(t, dhashes, c) }
// // Preps database structures // func PrepDatabase() { conn := client.MustConn("localhost:9191") conn.SubAddConfiguration(seniorWomenRankingKey, "mirrored", "yes") conn.SubAddConfiguration(seniorMenRankingKey, "mirrored", "yes") }