(ctx context.Context, wb twopc.WriteBatch)
| 220 | } |
| 221 | |
| 222 | func (r *RaftNode) Prepare(ctx context.Context, wb twopc.WriteBatch) (err error) { |
| 223 | log.WithFields(log.Fields{ |
| 224 | "addr": r.addr, |
| 225 | "phase": "prepare", |
| 226 | }).Debug("executing 2pc") |
| 227 | defer log.WithFields(log.Fields{ |
| 228 | "addr": r.addr, |
| 229 | "phase": "prepare", |
| 230 | }).WithError(err).Debug("2pc result") |
| 231 | |
| 232 | rwb, ok := wb.(*RaftWriteBatchReq) |
| 233 | |
| 234 | if !ok { |
| 235 | err = errors.New("unexpected WriteBatch type") |
| 236 | return err |
| 237 | } |
| 238 | |
| 239 | cipher := etls.NewCipher([]byte(pass)) |
| 240 | conn, err := etls.Dial("tcp", r.addr, cipher) |
| 241 | |
| 242 | if err != nil { |
| 243 | return err |
| 244 | } |
| 245 | |
| 246 | muxconn, err := mux.NewOneOffMuxConn(conn) |
| 247 | if err != nil { |
| 248 | return |
| 249 | } |
| 250 | |
| 251 | client := rpc.NewClient(muxconn) |
| 252 | d, ok := ctx.Deadline() |
| 253 | |
| 254 | if ok { |
| 255 | err = muxconn.SetDeadline(d) |
| 256 | |
| 257 | if err != nil { |
| 258 | return err |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | resp := new(RaftWriteBatchResp) |
| 263 | err = client.Call("Raft.RPCPrepare", &rwb, resp) |
| 264 | |
| 265 | if err != nil { |
| 266 | return err |
| 267 | } |
| 268 | |
| 269 | if resp.ErrCode > 0 { |
| 270 | err = fmt.Errorf(resp.ErrString) |
| 271 | } |
| 272 | |
| 273 | return err |
| 274 | } |
| 275 | |
| 276 | func (r *RaftNode) Commit(ctx context.Context, wb twopc.WriteBatch) (result interface{}, err error) { |
| 277 | log.Debugf("executing 2pc: addr = %s, phase = commit", r.addr) |
nothing calls this directly
no test coverage detected