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

Method commit

twopc/twopc.go:134–167  ·  view source on GitHub ↗
(ctx context.Context, workers []Worker, wb WriteBatch)

Source from the content-addressed store, hash-verified

132}
133
134func (c *Coordinator) commit(ctx context.Context, workers []Worker, wb WriteBatch) (result interface{}, err error) {
135 errs := make([]error, len(workers))
136 wg := sync.WaitGroup{}
137 workerFunc := func(n Worker, resPtr *interface{}, e *error, wg *sync.WaitGroup) {
138 defer wg.Done()
139
140 var res interface{}
141 res, *e = n.Commit(ctx, wb)
142 if resPtr != nil {
143 *resPtr = res
144 }
145 }
146
147 for index, worker := range workers {
148 wg.Add(1)
149 if index == 0 {
150 go workerFunc(worker, &result, &errs[index], &wg)
151 } else {
152 go workerFunc(worker, nil, &errs[index], &wg)
153 }
154 }
155
156 wg.Wait()
157
158 var index int
159 for index, err = range errs {
160 if err != nil {
161 log.WithField("worker", workers[index]).WithError(err).Debug("commit failed")
162 return
163 }
164 }
165
166 return
167}
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) {

Callers 1

PutMethod · 0.95

Calls 6

WithFieldFunction · 0.92
WaitMethod · 0.80
DebugMethod · 0.80
WithErrorMethod · 0.80
CommitMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected