| 41 | } |
| 42 | |
| 43 | func (a PlanAttempt) Commit() error { |
| 44 | if a.state == nil { |
| 45 | return nil |
| 46 | } |
| 47 | |
| 48 | a.state.mu.Lock() |
| 49 | if a.state.finished { |
| 50 | a.state.mu.Unlock() |
| 51 | return ErrFinishedPlanAttempt |
| 52 | } |
| 53 | a.state.finished = true |
| 54 | reserved := a.state.reserved |
| 55 | engine := a.state.engine |
| 56 | materialized := a.state.materialized |
| 57 | epoch := a.state.epoch |
| 58 | commitSeq := a.state.commitSeq |
| 59 | attemptID := a.state.attemptID |
| 60 | a.state.mu.Unlock() |
| 61 | |
| 62 | if !reserved { |
| 63 | return nil |
| 64 | } |
| 65 | if engine == nil { |
| 66 | return fmt.Errorf("chartengine: nil engine on commit") |
| 67 | } |
| 68 | return engine.commitAttempt(materialized, epoch, commitSeq, attemptID) |
| 69 | } |
| 70 | |
| 71 | func (a PlanAttempt) Abort() { |
| 72 | if a.state == nil { |