Home > other >  Golang RPC structure, some values to be lost
Golang RPC structure, some values to be lost

Time:02-14

Everybody is good the first time I used go, wrote a RPC application but when I use RPC to preach and out of a problem, then the parameter is a structure, in the server to reply when assignment is correct, then parameters is only part of the end of the service received is correct, then there is part of the value is the initial value,
Here is my part of the code

 
Type StateEnum uint8
Const (
IDLE StateEnum=iota
INPROGRESS
COMPLETED
The ERROR
)

Type PhaseEnum uint8
Const (
MAP_PAHSE PhaseEnum=iota
REDUCE_PAHSE
)
The type of Task struct {
The state StateEnum
Phase PhaseEnum
NMap int
NReduce int
FileName string
WorkID int
}

Then on the server side is
 
Func (c * Coordinator) ReqOneTask (args * ReqTaskArgs, reply * ReqTaskReply) error {
C. the tx. The Lock ()
Defer c. tx. Unlock ()
T, ok:=& lt; - c.t askCh
If ok {
T.w orkID=args. WorkerID
T.N Map=c.w orkerNum
T.s Tate=INPROGRESS
C.t askStates [t.w orkID]=t
Reply. Task=t
Reply. State=0
FMT. Printf (" ReqOneTask % \ n + v, t)
} else {
If c.p hase==MAP_PAHSE {
Reply. State=1
} else {
Reply. State=1
}
}
Return nil
}

I see the FMT. Printf (" ReqOneTask % \ n + v, t) output is the result of the normal, t state, fileName is the expected value
Then the end of the service is
 
Func (w * worker) getTask () {
The args:=& amp; ReqTaskArgs {}
The args. WorkerID=w.i d
Reply:=& amp; ReqTaskReply {}
If ok:=call (" Coordinator. ReqOneTask ", args, reply); ! Ok {
The Fatal (getTask "fail")
}
The switch reply. State {
Case 0:
W.r unTask (reply. Task)
Case 1:
Case 1:
OS. Exit (1)
}
}

On the client side to see the reply. Task, including the inside of the workID, NMap value is correct, but the state and the fileName is initialized values (0 and the empty string)
To ask you, where I made a mistake!
thank you
  • Related