(ctx context.Context, wb twopc.WriteBatch)
| 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) |
| 278 | defer log.Debugf("2pc result: addr = %s, phase = commit, result = %v", r.addr, err) |
| 279 | |
| 280 | rwb, ok := wb.(*RaftWriteBatchReq) |
| 281 | |
| 282 | if !ok { |
| 283 | err = errors.New("unexpected WriteBatch type") |
| 284 | return |
| 285 | } |
| 286 | |
| 287 | cipher := etls.NewCipher([]byte(pass)) |
| 288 | conn, err := etls.Dial("tcp", r.addr, cipher) |
| 289 | |
| 290 | if err != nil { |
| 291 | return |
| 292 | } |
| 293 | |
| 294 | muxconn, err := mux.NewOneOffMuxConn(conn) |
| 295 | if err != nil { |
| 296 | return |
| 297 | } |
| 298 | |
| 299 | client := rpc.NewClient(muxconn) |
| 300 | d, ok := ctx.Deadline() |
| 301 | |
| 302 | if ok { |
| 303 | err = muxconn.SetDeadline(d) |
| 304 | |
| 305 | if err != nil { |
| 306 | return |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | resp := new(RaftCommitResp) |
| 311 | err = client.Call("Raft.RPCCommit", &RaftCommitReq{TxID: rwb.TxID, Cmds: rwb.Cmds}, resp) |
| 312 | result = resp.Result |
| 313 | |
| 314 | if err != nil { |
| 315 | return |
| 316 | } |
| 317 | |
| 318 | if resp.ErrCode > 0 { |
| 319 | err = fmt.Errorf(resp.ErrString) |
| 320 | } |
| 321 | |
| 322 | return |
| 323 | } |
| 324 | |
| 325 | func (r *RaftNode) Rollback(ctx context.Context, wb twopc.WriteBatch) (err error) { |
| 326 | log.Debugf("executing 2pc: addr = %s, phase = rollback", r.addr) |
nothing calls this directly
no test coverage detected