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

Method followerDoCommit

kayak/commit.go:180–228  ·  view source on GitHub ↗
(req *commitReq)

Source from the content-addressed store, hash-verified

178}
179
180func (r *Runtime) followerDoCommit(req *commitReq) {
181 if req.log == nil {
182 log.Fatal("NO LOG FOR FOLLOWER COMMIT")
183 return
184 }
185
186 waitCommitTask := trace.StartRegion(req.ctx, "waitForLastCommit")
187
188 // check for last commit availability
189 myLastCommit := atomic.LoadUint64(&r.lastCommit)
190 if req.lastCommit != myLastCommit {
191 // TODO(): need counter for retries, infinite commit re-order would cause troubles
192 go func(req *commitReq) {
193 _, _ = r.waitForLog(req.ctx, req.lastCommit)
194 r.commitCh <- req
195 }(req)
196 waitCommitTask.End()
197 return
198 }
199
200 waitCommitTask.End()
201 req.tm.Add("queue")
202
203 defer trace.StartRegion(req.ctx, "commitCycle").End()
204
205 var err error
206
207 // write log first
208 if err = r.writeWAL(req.ctx, req.log); err != nil {
209 return
210 }
211
212 req.tm.Add("write_wal")
213
214 // do commit, not wrapping underlying handler commit error
215 _, storageErr := r.doCommit(req.ctx, req.data, false)
216
217 req.tm.Add("db_write")
218
219 // mark last commit
220 atomic.StoreUint64(&r.lastCommit, req.log.Index)
221
222 req.result.Set(&commitResult{
223 err: err,
224 storageErr: storageErr,
225 })
226
227 return
228}
229
230func (r *Runtime) getPrepareLog(ctx context.Context, l *kt.Log) (lastCommitIndex uint64, pl *kt.Log, err error) {
231 defer trace.StartRegion(ctx, "getPrepareLog").End()

Callers 1

doCommitCycleMethod · 0.95

Calls 8

waitForLogMethod · 0.95
writeWALMethod · 0.95
doCommitMethod · 0.95
FatalFunction · 0.92
StartRegionFunction · 0.92
EndMethod · 0.45
AddMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected