Prepare implements prepare method of two-phase commit worker.
(ctx context.Context, wb twopc.WriteBatch)
| 138 | |
| 139 | // Prepare implements prepare method of two-phase commit worker. |
| 140 | func (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. |
| 173 | func (s *Storage) Commit(ctx context.Context, wb twopc.WriteBatch) (result interface{}, err error) { |