MCPcopy Create free account
hub / github.com/dadgar/onecache / collapseOpLog

Function collapseOpLog

onecache/replicator.go:420–446  ·  view source on GitHub ↗

Collapses the passed operation log returning the final replication task.

(log []replicationTask)

Source from the content-addressed store, hash-verified

418
419// Collapses the passed operation log returning the final replication task.
420func 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}

Callers 6

replicateMethod · 0.85

Calls

no outgoing calls

Tested by 5