Collapses the passed operation log returning the final replication task.
(log []replicationTask)
| 418 | |
| 419 | // Collapses the passed operation log returning the final replication task. |
| 420 | func collapseOpLog(log []replicationTask) (replicationTask, error) { |
| 421 | if len(log) == 0 { |
| 422 | return task_DIRTY_VALUE, errors.New("can not collapse empty operation log") |
| 423 | } |
| 424 | |
| 425 | op := log[0] |
| 426 | for _, s := range log[1:] { |
| 427 | switch s { |
| 428 | case task_DELETE: |
| 429 | if op == task_DELETE { |
| 430 | return task_DIRTY_VALUE, errors.New("invalid op log: two deletes in a row") |
| 431 | } |
| 432 | |
| 433 | op = s |
| 434 | case task_DIRTY_VALUE: |
| 435 | op = s |
| 436 | case task_TOUCH: |
| 437 | if op == task_DELETE { |
| 438 | return task_DIRTY_VALUE, errors.New("invalid op log: metadata can not be marked dirty after the key has been deleted") |
| 439 | } |
| 440 | case task_BACKFILL: |
| 441 | op = s |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | return op, nil |
| 446 | } |
no outgoing calls