// Moves data from one server to another // Does the following: // 1. Lock all necessary clients // 2. Move Data // 3. Update router table on servers // 4. Delete partion from origin // 5. Unlock func MovePartition(services *Services, routerTable *shards.RouterTable, partition int, from, to *shards.RouterEntry) error { err := LockPartition(services, routerTable, partition) if err != nil { return err } //Unlock partition no matter what defer UnlockPartition(services, routerTable, partition) //copy the data _, err = CopyData(services, routerTable, partition, from, to) if err != nil { return err } //update the router table. parts := make([]int, 0) for _, p := range from.Partitions { if p != partition { parts = append(parts, p) } } from.Partitions = parts to.Partitions = append(to.Partitions, partition) routerTable, err = routerTable.AddEntries(from, to) routerTable, ok := RouterTableUpdate(services, routerTable, len(routerTable.Entries)) if !ok { services.Logger.Printf("Uh oh, Didnt update any router tables") } //Delete the data on the from server. err = DeletePartition(services, from, partition) if err != nil { return err } return nil }