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

Method Prepare

storage/storage.go:140–170  ·  view source on GitHub ↗

Prepare implements prepare method of two-phase commit worker.

(ctx context.Context, wb twopc.WriteBatch)

Source from the content-addressed store, hash-verified

138
139// Prepare implements prepare method of two-phase commit worker.
140func (s *Storage) Prepare(ctx context.Context, wb twopc.WriteBatch) (err error) {
141 el, ok := wb.(*ExecLog)
142
143 if !ok {
144 return errors.New("unexpected WriteBatch type")
145 }
146
147 s.Lock()
148 defer s.Unlock()
149
150 if s.tx != nil {
151 if equalTxID(&s.id, &TxID{el.ConnectionID, el.SeqNo, el.Timestamp}) {
152 s.queries = el.Queries
153 return nil
154 }
155
156 return fmt.Errorf("twopc: inconsistent state, currently in tx: "+
157 "conn = %d, seq = %d, time = %d", s.id.ConnectionID, s.id.SeqNo, s.id.Timestamp)
158 }
159
160 s.tx, err = s.db.BeginTx(ctx, nil)
161
162 if err != nil {
163 return
164 }
165
166 s.id = TxID{el.ConnectionID, el.SeqNo, el.Timestamp}
167 s.queries = el.Queries
168
169 return nil
170}
171
172// Commit implements commit method of two-phase commit worker.
173func (s *Storage) Commit(ctx context.Context, wb twopc.WriteBatch) (result interface{}, err error) {

Callers

nothing calls this directly

Calls 4

equalTxIDFunction · 0.85
ErrorfMethod · 0.80
BeginTxMethod · 0.80
NewMethod · 0.65

Tested by

no test coverage detected