Example #1
0
func GetRouterTable(request *cheshire.Request, conn cheshire.Connection) {
	tble, err := partitioner.RouterTable()
	if err != nil {
		conn.Write(request.NewError(506, fmt.Sprintf("Error: %s", err)))
		return
	}
	response := request.NewResponse()
	response.Put("router_table", tble.ToDynMap())
	conn.Write(response)
}
Example #2
0
func Checkin(request *cheshire.Request, conn cheshire.Connection) {
	table, err := partitioner.RouterTable()
	revision := int64(0)
	if err == nil {
		revision = table.Revision
	}
	response := request.NewResponse()
	response.Put("router_table_revision", revision)
	response.Put("ts", time.Now())
	conn.Write(response)
}
Example #3
0
func Data(request *cheshire.Request, conn cheshire.Connection) {
	part, ok := request.Params().GetInt("partition")
	if !ok {
		conn.Write(request.NewError(406, fmt.Sprintf("partition param is manditory")))
		return
	}

	remove := request.Params().MustBool("remove", false)
	dataChan := make(chan *dynmap.DynMap, 10)
	finishedChan := make(chan int)
	errorChan := make(chan error)
	go func() {
		for {
			select {
			case data := <-dataChan:
				//send a data packet
				res := request.NewResponse()
				res.SetTxnStatus("continue")
				res.Put("data", data)
				conn.Write(res)
			case <-finishedChan:
				res := request.NewResponse()
				res.SetTxnStatus("complete")
				conn.Write(res)
				return
			case err := <-errorChan:
				conn.Write(request.NewError(406, fmt.Sprintf("Unable to unlock (%s)", err)))
				return
			}
		}
	}()
	partitioner.Data(part, remove, dataChan, finishedChan, errorChan)
}
Example #4
0
func SetRouterTable(request *cheshire.Request, conn cheshire.Connection) {
	rtmap, ok := request.Params().GetDynMap("router_table")
	if !ok {
		conn.Write(request.NewError(406, "No router_table"))
		return
	}

	rt, err := ToRouterTable(rtmap)
	if err != nil {
		conn.Write(request.NewError(406, fmt.Sprintf("Unparsable router table (%s)", err)))
		return
	}

	err = partitioner.SetRouterTable(rt)
	if err != nil {
		conn.Write(request.NewError(406, fmt.Sprintf("Unable to set router table (%s)", err)))
		return
	}
	conn.Write(request.NewResponse())
}
Example #5
0
func Unlock(request *cheshire.Request, conn cheshire.Connection) {
	partitions, ok := request.Params().GetIntSliceSplit("partitions", ",")
	if !ok {
		conn.Write(request.NewError(406, fmt.Sprintf("partitions param missing")))
		return
	}
	err := partitioner.Unlock(partitions)
	if err != nil {
		conn.Write(request.NewError(406, fmt.Sprintf("Unable to unlock (%s)", err)))
		return
	}
	conn.Write(request.NewResponse())
}