MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / Commit

Method Commit

twopc/twopc_test.go:276–323  ·  view source on GitHub ↗
(ctx context.Context, wb twopc.WriteBatch)

Source from the content-addressed store, hash-verified

274}
275
276func (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
325func (r *RaftNode) Rollback(ctx context.Context, wb twopc.WriteBatch) (err error) {
326 log.Debugf("executing 2pc: addr = %s, phase = rollback", r.addr)

Callers

nothing calls this directly

Calls 9

CallMethod · 0.95
DebugfFunction · 0.92
NewCipherFunction · 0.92
DialFunction · 0.92
NewOneOffMuxConnFunction · 0.92
NewClientFunction · 0.92
SetDeadlineMethod · 0.80
ErrorfMethod · 0.80
NewMethod · 0.65

Tested by

no test coverage detected