aboutsummaryrefslogtreecommitdiffstats
path: root/entity/dag
diff options
context:
space:
mode:
Diffstat (limited to 'entity/dag')
-rw-r--r--entity/dag/entity.go32
-rw-r--r--entity/dag/entity_actions.go13
-rw-r--r--entity/dag/entity_test.go60
-rw-r--r--entity/dag/operation_pack.go17
4 files changed, 4 insertions, 118 deletions
diff --git a/entity/dag/entity.go b/entity/dag/entity.go
index 273e6ad1..3f4dfcb4 100644
--- a/entity/dag/entity.go
+++ b/entity/dag/entity.go
@@ -44,9 +44,6 @@ type Entity struct {
// TODO: add here createTime and editTime
- // // TODO: doesn't seems to actually be useful over the topological sort ? Timestamp can be generated from graph depth
- // // TODO: maybe EditTime is better because it could spread ops in consecutive groups on the logical timeline --> avoid interleaving
- // packClock lamport.Clock
lastCommit repository.Hash
}
@@ -54,7 +51,6 @@ type Entity struct {
func New(definition Definition) *Entity {
return &Entity{
Definition: definition,
- // packClock: lamport.NewMemClock(),
}
}
@@ -127,7 +123,6 @@ func read(def Definition, repo repository.ClockedRepo, ref string) (*Entity, err
oppMap := make(map[repository.Hash]*operationPack)
var opsCount int
- // var packClock = lamport.NewMemClock()
for i := len(BFSOrder) - 1; i >= 0; i-- {
commit := BFSOrder[i]
@@ -174,8 +169,6 @@ func read(def Definition, repo repository.ClockedRepo, ref string) (*Entity, err
if !isMerge && opp.EditTime-parentPack.EditTime > 1_000_000 {
return nil, fmt.Errorf("lamport clock jumping too far in the future, likely an attack")
}
-
- // TODO: PackTime is not checked
}
oppMap[commit.Hash] = opp
@@ -192,10 +185,6 @@ func read(def Definition, repo repository.ClockedRepo, ref string) (*Entity, err
if err != nil {
return nil, err
}
- // err = packClock.Witness(opp.PackTime)
- // if err != nil {
- // return nil, err
- // }
}
// Now that we know that the topological order and clocks are fine, we order the operationPacks
@@ -206,19 +195,13 @@ func read(def Definition, repo repository.ClockedRepo, ref string) (*Entity, err
oppSlice = append(oppSlice, pack)
}
sort.Slice(oppSlice, func(i, j int) bool {
- // Primary ordering with the dedicated "pack" Lamport time that encode causality
- // within the entity
- // if oppSlice[i].PackTime != oppSlice[j].PackTime {
- // return oppSlice[i].PackTime < oppSlice[i].PackTime
- // }
- // We have equal PackTime, which means we had a concurrent edition. We can't tell which exactly
- // came first. As a secondary arbitrary ordering, we can use the EditTime. It's unlikely to be
- // enough but it can give us an edge to approach what really happened.
+ // Primary ordering with the EditTime.
if oppSlice[i].EditTime != oppSlice[j].EditTime {
return oppSlice[i].EditTime < oppSlice[j].EditTime
}
- // Well, what now? We still need a total ordering and the most stable possible.
- // As a last resort, we can order based on a hash of the serialized Operations in the
+ // We have equal EditTime, which means we have concurrent edition over different machines and we
+ // can't tell which one came first. So, what now? We still need a total ordering and the most stable possible.
+ // As a secondary ordering, we can order based on a hash of the serialized Operations in the
// operationPack. It doesn't carry much meaning but it's unbiased and hard to abuse.
// This is a lexicographic ordering on the stringified ID.
return oppSlice[i].Id() < oppSlice[j].Id()
@@ -236,7 +219,6 @@ func read(def Definition, repo repository.ClockedRepo, ref string) (*Entity, err
return &Entity{
Definition: def,
ops: ops,
- // packClock: packClock,
lastCommit: rootHash,
}, nil
}
@@ -379,11 +361,6 @@ func (e *Entity) Commit(repo repository.ClockedRepo) error {
author = op.Author()
}
- // increment the various clocks for this new operationPack
- // packTime, err := e.packClock.Increment()
- // if err != nil {
- // return err
- // }
editTime, err := repo.Increment(fmt.Sprintf(editClockPattern, e.namespace))
if err != nil {
return err
@@ -401,7 +378,6 @@ func (e *Entity) Commit(repo repository.ClockedRepo) error {
Operations: e.staging,
CreateTime: creationTime,
EditTime: editTime,
- // PackTime: packTime,
}
var commitHash repository.Hash
diff --git a/entity/dag/entity_actions.go b/entity/dag/entity_actions.go
index fe912557..6f6fe45c 100644
--- a/entity/dag/entity_actions.go
+++ b/entity/dag/entity_actions.go
@@ -199,17 +199,6 @@ func merge(def Definition, repo repository.ClockedRepo, remoteRef string, author
return entity.NewMergeError(err, id)
}
- // TODO: pack clock
- // err = localEntity.packClock.Witness(remoteEntity.packClock.Time())
- // if err != nil {
- // return entity.NewMergeError(err, id)
- // }
- //
- // packTime, err := localEntity.packClock.Increment()
- // if err != nil {
- // return entity.NewMergeError(err, id)
- // }
-
editTime, err := repo.Increment(fmt.Sprintf(editClockPattern, def.namespace))
if err != nil {
return entity.NewMergeError(err, id)
@@ -220,8 +209,6 @@ func merge(def Definition, repo repository.ClockedRepo, remoteRef string, author
Operations: nil,
CreateTime: 0,
EditTime: editTime,
- // TODO: pack clock
- // PackTime: packTime,
}
commitHash, err := opp.Write(def, repo, localCommit, remoteCommit)
diff --git a/entity/dag/entity_test.go b/entity/dag/entity_test.go
index c5c83567..012c87aa 100644
--- a/entity/dag/entity_test.go
+++ b/entity/dag/entity_test.go
@@ -55,63 +55,3 @@ func assertEqualEntities(t *testing.T, a, b *Entity) {
require.Equal(t, a, b)
}
-
-// // Merge
-//
-// merge1 := makeCommit(t, repo)
-// merge1 = makeCommit(t, repo, merge1)
-// err = repo.UpdateRef("merge1", merge1)
-// require.NoError(t, err)
-//
-// err = repo.UpdateRef("merge2", merge1)
-// require.NoError(t, err)
-//
-// // identical merge
-// err = repo.MergeRef("merge1", "merge2")
-// require.NoError(t, err)
-//
-// refMerge1, err := repo.ResolveRef("merge1")
-// require.NoError(t, err)
-// require.Equal(t, merge1, refMerge1)
-// refMerge2, err := repo.ResolveRef("merge2")
-// require.NoError(t, err)
-// require.Equal(t, merge1, refMerge2)
-//
-// // fast-forward merge
-// merge2 := makeCommit(t, repo, merge1)
-// merge2 = makeCommit(t, repo, merge2)
-//
-// err = repo.UpdateRef("merge2", merge2)
-// require.NoError(t, err)
-//
-// err = repo.MergeRef("merge1", "merge2")
-// require.NoError(t, err)
-//
-// refMerge1, err = repo.ResolveRef("merge1")
-// require.NoError(t, err)
-// require.Equal(t, merge2, refMerge1)
-// refMerge2, err = repo.ResolveRef("merge2")
-// require.NoError(t, err)
-// require.Equal(t, merge2, refMerge2)
-//
-// // merge commit
-// merge1 = makeCommit(t, repo, merge1)
-// err = repo.UpdateRef("merge1", merge1)
-// require.NoError(t, err)
-//
-// merge2 = makeCommit(t, repo, merge2)
-// err = repo.UpdateRef("merge2", merge2)
-// require.NoError(t, err)
-//
-// err = repo.MergeRef("merge1", "merge2")
-// require.NoError(t, err)
-//
-// refMerge1, err = repo.ResolveRef("merge1")
-// require.NoError(t, err)
-// require.NotEqual(t, merge1, refMerge1)
-// commitRefMerge1, err := repo.ReadCommit(refMerge1)
-// require.NoError(t, err)
-// require.ElementsMatch(t, commitRefMerge1.Parents, []Hash{merge1, merge2})
-// refMerge2, err = repo.ResolveRef("merge2")
-// require.NoError(t, err)
-// require.Equal(t, merge2, refMerge2)
diff --git a/entity/dag/operation_pack.go b/entity/dag/operation_pack.go
index ebacdbd9..959b1ae0 100644
--- a/entity/dag/operation_pack.go
+++ b/entity/dag/operation_pack.go
@@ -22,7 +22,6 @@ const opsEntryName = "ops"
const versionEntryPrefix = "version-"
const createClockEntryPrefix = "create-clock-"
const editClockEntryPrefix = "edit-clock-"
-const packClockEntryPrefix = "pack-clock-"
// operationPack is a wrapper structure to store multiple operations in a single git blob.
// Additionally, it holds and store the metadata for those operations.
@@ -40,9 +39,6 @@ type operationPack struct {
// Encode the entity's logical time of last edition across all entities of the same type.
// Exist on all operationPack
EditTime lamport.Time
- // // Encode the operationPack's logical time of creation withing this entity.
- // // Exist on all operationPack
- // PackTime lamport.Time
}
func (opp *operationPack) Id() entity.Id {
@@ -129,8 +125,6 @@ func (opp *operationPack) Write(def Definition, repo repository.Repo, parentComm
Name: opsEntryName},
{ObjectType: repository.Blob, Hash: emptyBlobHash,
Name: fmt.Sprintf(editClockEntryPrefix+"%d", opp.EditTime)},
- // {ObjectType: repository.Blob, Hash: emptyBlobHash,
- // Name: fmt.Sprintf(packClockEntryPrefix+"%d", opp.PackTime)},
}
if opp.CreateTime > 0 {
tree = append(tree, repository.TreeEntry{
@@ -205,7 +199,6 @@ func readOperationPack(def Definition, repo repository.RepoData, commit reposito
var ops []Operation
var createTime lamport.Time
var editTime lamport.Time
- // var packTime lamport.Time
for _, entry := range entries {
switch {
@@ -233,15 +226,6 @@ func readOperationPack(def Definition, repo repository.RepoData, commit reposito
return nil, errors.Wrap(err, "can't read edit lamport time")
}
editTime = lamport.Time(v)
-
- // case strings.HasPrefix(entry.Name, packClockEntryPrefix):
- // found &= 1 << 3
- //
- // v, err := strconv.ParseUint(strings.TrimPrefix(entry.Name, packClockEntryPrefix), 10, 64)
- // if err != nil {
- // return nil, errors.Wrap(err, "can't read pack lamport time")
- // }
- // packTime = lamport.Time(v)
}
}
@@ -261,7 +245,6 @@ func readOperationPack(def Definition, repo repository.RepoData, commit reposito
Operations: ops,
CreateTime: createTime,
EditTime: editTime,
- // PackTime: packTime,
}, nil
}