Change objecttree to set mode Rebuild if we update the snapshot after current heads
This commit is contained in:
parent
11d50d087a
commit
7a57d7b0c4
@ -185,11 +185,16 @@ func (ot *objectTree) AddContent(ctx context.Context, content SignableChangeCont
|
||||
return
|
||||
}
|
||||
|
||||
mode := Append
|
||||
if content.IsSnapshot {
|
||||
mode = Rebuild
|
||||
}
|
||||
|
||||
res = AddResult{
|
||||
OldHeads: oldHeads,
|
||||
Heads: []string{objChange.Id},
|
||||
Added: []*treechangeproto.RawTreeChangeWithId{rawChange},
|
||||
Mode: Append,
|
||||
Mode: mode,
|
||||
}
|
||||
log.With("treeId", ot.id).With("head", objChange.Id).
|
||||
Debug("finished adding content")
|
||||
@ -234,6 +239,7 @@ func (ot *objectTree) prepareBuilderContent(content SignableChangeContent) (cnt
|
||||
}
|
||||
|
||||
func (ot *objectTree) AddRawChanges(ctx context.Context, changesPayload RawChangesPayload) (addResult AddResult, err error) {
|
||||
lastHeadId := ot.tree.lastIteratedHeadId
|
||||
addResult, err = ot.addRawChanges(ctx, changesPayload)
|
||||
if err != nil {
|
||||
return
|
||||
@ -242,6 +248,11 @@ func (ot *objectTree) AddRawChanges(ctx context.Context, changesPayload RawChang
|
||||
// reducing tree if we have new roots
|
||||
ot.tree.reduceTree()
|
||||
|
||||
// that means that we removed the ids while reducing
|
||||
if _, exists := ot.tree.attached[lastHeadId]; !exists {
|
||||
addResult.Mode = Rebuild
|
||||
}
|
||||
|
||||
// adding to database all the added changes only after they are good
|
||||
for _, ch := range addResult.Added {
|
||||
err = ot.treeStorage.AddRawChange(ch)
|
||||
|
||||
@ -270,7 +270,8 @@ func TestObjectTree(t *testing.T) {
|
||||
assert.Equal(t, []string{"0"}, res.OldHeads)
|
||||
assert.Equal(t, []string{"4"}, res.Heads)
|
||||
assert.Equal(t, len(rawChanges), len(res.Added))
|
||||
assert.Equal(t, Append, res.Mode)
|
||||
// here we have rebuild, because we reduced tree to new snapshot
|
||||
assert.Equal(t, Rebuild, res.Mode)
|
||||
|
||||
// check tree heads
|
||||
assert.Equal(t, []string{"4"}, objTree.Heads())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user