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

Method Put

twopc/twopc.go:170–213  ·  view source on GitHub ↗

Put initiates a 2PC process to apply given WriteBatch on all workers.

(workers []Worker, wb WriteBatch)

Source from the content-addressed store, hash-verified

168
169// Put initiates a 2PC process to apply given WriteBatch on all workers.
170func (c *Coordinator) Put(workers []Worker, wb WriteBatch) (result interface{}, err error) {
171 // Initiate phase one: ask nodes to prepare for progress
172 ctx, cancel := context.WithTimeout(context.Background(), c.option.timeout)
173 defer cancel()
174
175 if c.option.beforePrepare != nil {
176 if err = c.option.beforePrepare(ctx); err != nil {
177 log.WithError(err).Debug("before prepared failed")
178 return
179 }
180 }
181
182 // Check prepare results and initiate phase two
183 if err = c.prepare(ctx, workers, wb); err != nil {
184 goto ROLLBACK
185 }
186
187 if c.option.beforeCommit != nil {
188 if err = c.option.beforeCommit(ctx); err != nil {
189 log.WithError(err).Debug("before commit failed")
190 goto ROLLBACK
191 }
192 }
193
194 result, err = c.commit(ctx, workers, wb)
195
196 if c.option.afterCommit != nil {
197 if err = c.option.afterCommit(ctx); err != nil {
198 log.WithError(err).Debug("after commit failed")
199 }
200 }
201
202 return
203
204ROLLBACK:
205 if c.option.beforeRollback != nil {
206 // ignore rollback fail options
207 c.option.beforeRollback(ctx)
208 }
209
210 c.rollback(ctx, workers, wb)
211
212 return
213}

Callers 5

TestTwoPhaseCommitFunction · 0.95
pushBlockMethod · 0.80
pushAckedQueryMethod · 0.80
WriteMethod · 0.80

Calls 5

prepareMethod · 0.95
commitMethod · 0.95
rollbackMethod · 0.95
WithErrorFunction · 0.92
DebugMethod · 0.80

Tested by 2

TestTwoPhaseCommitFunction · 0.76