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

Method Prepare

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

Source from the content-addressed store, hash-verified

220}
221
222func (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
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)

Callers

nothing calls this directly

Calls 11

CallMethod · 0.95
WithFieldsFunction · 0.92
NewCipherFunction · 0.92
DialFunction · 0.92
NewOneOffMuxConnFunction · 0.92
NewClientFunction · 0.92
DebugMethod · 0.80
WithErrorMethod · 0.80
SetDeadlineMethod · 0.80
ErrorfMethod · 0.80
NewMethod · 0.65

Tested by

no test coverage detected