本文整理汇总了Golang中P3-f12/official/lsplog.Vlogf函数的典型用法代码示例。如果您正苦于以下问题:Golang Vlogf函数的具体用法?Golang Vlogf怎么用?Golang Vlogf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Vlogf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RegisterLoadBalancer
func (m *Monitor) RegisterLoadBalancer(args *commproto.RegisterLoadBalancerArgs, reply *commproto.RegisterLoadBalancerReply) error {
lsplog.Vlogf(3, "[Monitor] A register load balancer received from %s", args.HostPort)
if m.loadBalancers.Len() < m.numberOfLoadBalancers {
<-m.registering
lb := &commproto.LoadBalancerInformation{args.HostPort, m.lbID, "", list.New()}
m.lbID = m.lbID + 1
m.loadBalancers.PushBack(lb)
m.init <- 1
m.registering <- 1
<-m.initDone
reply.Buddy = lb.BuddyHostPort
reply.SwitchAddr = m.switchHostPort
// Fill information for other load balancers
reply.LoadBalancersHostPort = make([]string, m.loadBalancers.Len()-1)
i := 0
for e := m.loadBalancers.Front(); e != nil; e = e.Next() {
lbi := e.Value.(*commproto.LoadBalancerInformation)
if args.HostPort != lbi.Hostport {
reply.LoadBalancersHostPort[i] = lbi.Hostport
i = i + 1
}
}
thisLB := m.getLoadBalancer(args.HostPort)
workersReply := make([]string, thisLB.WorkersList.Len())
i = 0
for e := thisLB.WorkersList.Front(); e != nil; e = e.Next() {
workersReply[i] = *(e.Value.(*string))
}
m.informSwitch <- 1
lsplog.Vlogf(3, "[Monitor] Finished registering load balancer %s", args.HostPort)
}
return nil
}
示例2: broadcast
//Broadcast message to all replicas
func (lp *Libpaxos) broadcast(PacketMsg *Msg) {
if PacketMsg != nil {
//lsplog.Vlogf(6, "[Libpaxos] Broadcast type: %d", PacketMsg.MsgType)
p := Packet{}
p.PacketFrom = lp.self
p.PacketMsg = *PacketMsg
var reply Reply
for _, r := range lp.replicas {
// if r == lp.self {
// continue
// }
//lsplog.Vlogf(6, "[Libpaxos] Broadcast: %s", r)
client, err := rpc.DialHTTP("tcp", r)
if lsplog.CheckReport(6, err) {
lsplog.Vlogf(6, "[Libpaxos] Broadcast to %s failed", r)
//client.Close()
continue
}
err = client.Call("Libpaxos.ReceiveMessage", p, &reply)
if lsplog.CheckReport(1, err) {
lsplog.Vlogf(6, "[Libpaxos] Broadcast call to %s failed", r)
}
client.Close()
}
}
}
示例3: BookingFlights
func (tl *TranLayer) BookingFlights(orderList []tranlayerproto.Order) error {
// find server for each airline company
tranOrderList := make([]*tranOrder, len(orderList))
for i, order := range orderList {
conn, pptID, err := tl.lib_conn.GetServerWithAddress(order.AirlineID)
if lsplog.CheckReport(2, err) {
return err
}
tranOrderList[i] = &tranOrder{order.FlightID, pptID, order.Amount, conn}
}
// get unique transaction id
tranID := fmt.Sprintf("%s:%d", tl.myhostport, time.Now().UnixNano())
lsplog.Vlogf(5, "Begin transaction:"+tranID)
// send request to store handler
req := &reqContent{INIT_TRANS, tranID, tranOrderList}
replyc := make(chan interface{})
tl.reqChan <- &Request{req, replyc}
// wait for response
status := (<-replyc).(bool)
lsplog.Vlogf(5, "End of transaction:"+tranID)
if status {
return nil
}
return lsplog.MakeErr("Transaction Failed")
}
示例4: main
func main() {
lsplog.SetVerbose(3)
lsplog.Vlogf(3, "[Request] Args: %s", os.Args)
var e error
ww := new(Worker)
ww.load = 0
ww.endFailureRecovery = make(chan bool, 1)
ww.startFailureRecovery = make(chan bool, 1)
ww.reqLock = new(sync.Mutex)
monitor := os.Args[1]
port, _ := strconv.Atoi(os.Args[2])
l, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
log.Fatal("listen error:", e)
}
_, _, _ = net.SplitHostPort(l.Addr().String())
//port, _ = strconv.Atoi(listenport)
rpc.Register(ww)
rpc.HandleHTTP()
go http.Serve(l, nil)
// Register to monitor and get load balancer hostport and its buddy
ww.cliM, _ = rpc.DialHTTP("tcp", monitor)
name, _ := os.Hostname()
addrs, _ := net.LookupHost(name)
args := &commproto.RegisterWorkerArgs{fmt.Sprintf("%s:%s", addrs[0], port)}
var reply commproto.RegisterWorkerReply
ww.cliM.Call("MonitorRPC.RegisterWorker", args, &reply)
lsplog.Vlogf(3, "[Worker] Received LoadBalancerHostPort: %s", reply.LoadBalancerHostPort)
// connect to main LB
parts := strings.Split(reply.LoadBalancerHostPort, ":")
fakePort, _ := strconv.Atoi(parts[1])
fakeHostPort := fmt.Sprintf("%s:%d", parts[0], fakePort+10)
ww.cli, e = lsp12.NewLspClient(fakeHostPort, &lsp12.LspParams{5, 2000})
for e != nil || ww.cli == nil {
ww.cli, e = lsp12.NewLspClient(reply.LoadBalancerHostPort, &lsp12.LspParams{5, 2000})
lsplog.Vlogf(3, "[Worker] Connection to load balancer failed. \n")
}
// queue of requests
ww.reqList = list.New()
// lauch the request handler
go requestHandler(ww)
// listen to requests
for {
req, err := ww.cli.Read()
if err != nil {
ww.startFailureRecovery <- true
<-ww.endFailureRecovery
continue
}
lsplog.Vlogf(3, "[Worker] Recieved: %s", string(req))
responseParts := strings.Split(string(req), " ")
i, _ := strconv.Atoi(responseParts[1])
ww.reqLock.Lock()
ww.load += i
ww.reqList.PushBack(i)
ww.reqLock.Unlock()
}
}
示例5: RegisterWorker
func (m *Monitor) RegisterWorker(args *commproto.RegisterWorkerArgs, reply *commproto.RegisterWorkerReply) error {
lsplog.Vlogf(3, "[Monitor] A register worker received from %v", args.HostPort)
if m.workers.Len() != m.numberOfWorkers {
<-m.registering
w := args.HostPort
m.workers.PushBack(&w)
m.init <- 1
m.registering <- 1
<-m.initDone
// Look for the load balancer and buddy for this worker
L:
for e := m.loadBalancers.Front(); e != nil; e = e.Next() {
plb := e.Value.(*commproto.LoadBalancerInformation)
for el := plb.WorkersList.Front(); el != nil; el = el.Next() {
pw := el.Value.(*string)
if *pw == args.HostPort {
reply.LoadBalancerHostPort = plb.Hostport
//reply.Buddy = plb.BuddyHostPort
break L
}
}
}
m.informSwitch <- 1
lsplog.Vlogf(3, "[Monitor] Finished registering worker %v", args.HostPort)
}
return nil
}
示例6: Write
func (con *UDPConn) Write(b []byte) (int, error) {
ncon := con.ncon
if dropit(writeDropPercent) {
lsplog.Vlogf(5, "UDP: DROPPING written packet of length %v\n", len(b))
// Make it look like write was successful
return len(b), nil
} else {
n, err := ncon.Write(b)
lsplog.Vlogf(5, "UDP: Wrote packet of length %v\v", n)
return n, err
}
return 0, nil
}
示例7: WriteToUDP
func (con *UDPConn) WriteToUDP(b []byte, addr *UDPAddr) (int, error) {
ncon := con.ncon
naddr := &net.UDPAddr{addr.IP, addr.Port}
if dropit(writeDropPercent) {
lsplog.Vlogf(5, "UDP: DROPPING written packet of length %v\n", len(b))
// Make it look like write was successful
return len(b), nil
} else {
n, err := ncon.WriteToUDP(b, naddr)
lsplog.Vlogf(5, "UDP: Wrote packet of length %v", n)
return n, err
}
return 0, nil
}
示例8: getServer
// getServer
// parameters:
// - key: the key for entry
// return
// - point of the connection to server
// - error
// function:
// - calculate the correct server id to connect
// - connect to the server and cache the connection
func (ls *Libstore) getServer(key string) (*rpc.Client, error) {
// Use beginning of key to group related keys together
precolon := strings.Split(key, ":")[0]
keyid := Storehash(precolon)
//_ = keyid // use keyid to compile
// Calculate the correct server id
largeHash := false
currentMachine := 0
for i := 0; i < len(ls.nodelist); i++ {
if ls.nodelist[i].NodeID >= keyid {
currentMachine = i
largeHash = true
}
}
if largeHash {
for i := 0; i < len(ls.nodelist); i++ {
if ls.nodelist[i].NodeID >= keyid && ls.nodelist[i].NodeID < ls.nodelist[currentMachine].NodeID {
currentMachine = i
}
}
} else {
for i := 0; i < len(ls.nodelist); i++ {
if ls.nodelist[i].NodeID < ls.nodelist[currentMachine].NodeID {
currentMachine = i
}
}
}
// Connect to the storage server
ls.connLock.Lock()
cli, ok := ls.connMap[currentMachine]
if cli == nil || !ok {
newcli, err := rpc.DialHTTP("tcp", ls.nodelist[currentMachine].HostPort)
if err != nil {
ls.connLock.Unlock()
return nil, err
}
// cache the connection
lsplog.Vlogf(7, "Get new connection to %s", ls.nodelist[currentMachine].HostPort)
lsplog.Vlogf(7, "Cached new connection to %s", ls.nodelist[currentMachine].HostPort)
ls.connMap[currentMachine] = newcli
cli = newcli
} else {
lsplog.Vlogf(7, "Get connection to %s from connection cache", ls.nodelist[currentMachine].HostPort)
}
ls.connLock.Unlock()
return cli, nil
}
示例9: AppendToList
// AppendToList
// function:
// - put key and list value into storage
func (ss *Storageserver) AppendToList(args *storageproto.PutArgs, reply *storageproto.PutReply) error {
req := &cacheReq{APPEND_LIST_VALUE, args.Key, args.Value}
replyc := make(chan interface{})
ss.cacheReqC <- Request{req, replyc}
status := (<-replyc).(bool)
if status {
lsplog.Vlogf(5, "Append key successfully %s %s", args.Key, args.Value)
reply.Status = storageproto.OK
} else {
lsplog.Vlogf(5, "Append key failed %s %s", args.Key, args.Value)
reply.Status = storageproto.EITEMEXISTS
}
return nil
}
示例10: RemoveFromList
// RemoveFromList
// function:
// - remove key and list value from storage
func (ss *Storageserver) RemoveFromList(args *storageproto.PutArgs, reply *storageproto.PutReply) error {
req := &cacheReq{REMOVE_LIST_VALUE, args.Key, args.Value}
replyc := make(chan interface{})
ss.cacheReqC <- Request{req, replyc}
status := (<-replyc).(bool)
if status {
lsplog.Vlogf(5, "Remove key successfully %s %s", args.Key, args.Value)
reply.Status = storageproto.OK
} else {
lsplog.Vlogf(5, "Remove key failed %s %s", args.Key, args.Value)
reply.Status = storageproto.EITEMNOTFOUND
}
return nil
}
示例11: stopGlobalNetwork
// Shut down all network activity
func (srv *LspServer) stopGlobalNetwork() {
srv.stopGlobalNetworkFlag = true
err := srv.udpConn.Close()
if lsplog.CheckReport(4, err) {
lsplog.Vlogf(6, "Server Continuing\n")
}
}
示例12: stopNetwork
// Shutting down network communications
func (cli *LspClient) stopNetwork() {
cli.lspConn.stopNetworkFlag = true
err := cli.udpConn.Close()
if lsplog.CheckReport(4, err) {
lsplog.Vlogf(6, "Client Continuing\n")
}
}
示例13: requestHandler
func (tl *TranLayer) requestHandler() {
for {
// send remain transaction orders
if len(tl.oldTransactionMap) != 0 {
for transID, oldTransaction := range tl.oldTransactionMap {
order := oldTransaction.orderList.Remove().(*tranOrder)
flightID := order.flightID
amount := order.amount
conn := order.conn
pptList := oldTransaction.pptList
args := &airlineproto.TranArgs{transaction.TRANS_INIT, transID, flightID, amount, pptList, 0, tl.myhostport}
var reply airlineproto.TranReply
conn.Call("AirlineRPC.Transaction", args, &reply)
if oldTransaction.orderList.Empty() {
delete(tl.oldTransactionMap, transID)
go tl.transTimer(transID)
}
break
}
continue
}
request := <-tl.reqChan
lsplog.Vlogf(6, "Handling request")
switch request.content.reqType {
case INIT_TRANS, TRANS_RESPONSE, TRANS_EXPIRED, TRANS_OLD:
tl.transactionHandler(request)
}
}
}
示例14: expireTrans
func (tl *TranLayer) expireTrans(request *Request) {
lsplog.Vlogf(5, "Expire transaction...")
transID := request.content.key
activeTrans, exist := tl.activeTransMap[transID]
if exist == false {
return
}
// send decision to all participants that vote commit
// TODO: store log to persistent storage
for transKey, vote := range activeTrans.commitGrp {
if vote == transaction.COMMIT {
conn := activeTrans.pptMap[transKey]
//infos := strings.SplitN(transKey, "#", 2)
//infos := transKey
flightID := transKey
args := &airlineproto.TranArgs{transaction.TRANS_RESPONSE,
transID, flightID, 0, nil, activeTrans.decision, tl.myhostport}
var reply airlineproto.TranReply
conn.Call("AirlineRPC.Transaction", args, &reply)
}
}
replyc, _ := tl.deferTransMap[transID]
if activeTrans.decision == transaction.COMMIT {
replyc <- true
} else {
replyc <- false
}
}
示例15: RegisterServer
// Non-master servers to the master
func (ss *Storageserver) RegisterServer(args *storageproto.RegisterArgs, reply *storageproto.RegisterReply) error {
lsplog.Vlogf(5, "Connected:", args.ServerInfo.NodeID)
ss.serverListLock.Lock()
if ss.cntnodes < ss.numnodes {
ss.servers[ss.cntnodes] = args.ServerInfo
ss.cntnodes += 1
}
if ss.cntnodes == ss.numnodes {
lsplog.Vlogf(5, "Ready")
reply.Ready = true
reply.Servers = ss.servers
}
ss.serverListLock.Unlock()
return nil
}