Skip to content

Commit 8e0440c

Browse files
committed
fix update.path nil pointer
1 parent 6c901c1 commit 8e0440c

15 files changed

+1050
-699
lines changed

pkg/datastore/datastore_rpc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ func (d *Datastore) writeToSyncTreeCandidate(ctx context.Context, updates []*sdc
316316
// fmt.Println(upds.String())
317317
for idx, upd := range upds {
318318
_ = idx
319-
_, err := d.syncTreeCandidate.AddUpdateRecursive(ctx, upd.Path(), upd, treetypes.NewUpdateInsertFlags())
319+
320+
_, err := d.syncTreeCandidate.AddUpdateRecursive(ctx, upd.GetPath(), upd.GetUpdate(), treetypes.NewUpdateInsertFlags())
320321
if err != nil {
321322
return err
322323
}

pkg/datastore/transaction_rpc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ func (d *Datastore) lowlevelTransactionSet(ctx context.Context, transaction *typ
214214
lvs := tree.LeafVariantSlice{}
215215
lvs = root.GetByOwner(intent.GetName(), lvs)
216216

217-
oldIntentContent := lvs.ToUpdateSlice()
217+
oldIntentContent := lvs.ToPathAndUpdateSlice()
218218

219219
marksOwnerDeleteVisitor := tree.NewMarkOwnerDeleteVisitor(intent.GetName(), intent.GetOnlyIntended())
220220
err := root.Walk(ctx, marksOwnerDeleteVisitor)
@@ -225,7 +225,7 @@ func (d *Datastore) lowlevelTransactionSet(ctx context.Context, transaction *typ
225225
oldExplicitDeletes := root.RemoveExplicitDeletes(intent.GetName())
226226

227227
// store the old intent content in the transaction as the old intent.
228-
err = transaction.AddIntentContent(intent.GetName(), types.TransactionIntentOld, oldIntentContent.GetFirstPriorityValue(), oldIntentContent, oldExplicitDeletes)
228+
err = transaction.AddIntentContent(intent.GetName(), types.TransactionIntentOld, oldIntentContent[0].GetUpdate().Priority(), oldIntentContent, oldExplicitDeletes)
229229
if err != nil {
230230
return nil, err
231231
}
@@ -245,7 +245,7 @@ func (d *Datastore) lowlevelTransactionSet(ctx context.Context, transaction *typ
245245
les := tree.LeafVariantSlice{}
246246
les = root.GetByOwner(tree.RunningIntentName, les)
247247

248-
transaction.GetOldRunning().AddUpdates(les.ToUpdateSlice())
248+
transaction.GetOldRunning().AddUpdates(les.ToPathAndUpdateSlice())
249249

250250
log.V(logf.VDebug).Info("transaction finish tree insertion phase")
251251
// FinishInsertion Phase

pkg/datastore/tree_operation_test.go

Lines changed: 548 additions & 370 deletions
Large diffs are not rendered by default.

pkg/datastore/types/transaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (t *Transaction) AddTransactionIntent(ti *TransactionIntent, tit Transactio
140140
}
141141

142142
// AddIntentContent add the content of an intent. If the intent did not exist, add the name of the intent and content == nil.
143-
func (t *Transaction) AddIntentContent(name string, tit TransactionIntentType, priority int32, content treetypes.UpdateSlice, explicitDeletes *sdcpb.PathSet) error {
143+
func (t *Transaction) AddIntentContent(name string, tit TransactionIntentType, priority int32, content []*treetypes.PathAndUpdate, explicitDeletes *sdcpb.PathSet) error {
144144
dstMap := t.getTransactionIntentTypeMap(tit)
145145
_, exists := dstMap[name]
146146
if exists {

pkg/datastore/types/transaction_intent.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
type TransactionIntent struct {
99
name string
1010
// updates is nil if the intent did not exist.
11-
updates treetypes.UpdateSlice
11+
updates []*treetypes.PathAndUpdate
1212
delete bool
1313
// onlyIntended, the orphan flag, delte only from intended store, but keep in device
1414
onlyIntended bool
@@ -23,7 +23,7 @@ type TransactionIntent struct {
2323
func NewTransactionIntent(name string, priority int32) *TransactionIntent {
2424
return &TransactionIntent{
2525
name: name,
26-
updates: make(treetypes.UpdateSlice, 0),
26+
updates: make([]*treetypes.PathAndUpdate, 0),
2727
priority: priority,
2828
explicitDeletes: sdcpb.NewPathSet(),
2929
}
@@ -37,11 +37,11 @@ func (ti *TransactionIntent) GetPriority() int32 {
3737
return ti.priority
3838
}
3939

40-
func (ti *TransactionIntent) AddUpdates(u treetypes.UpdateSlice) {
40+
func (ti *TransactionIntent) AddUpdates(u []*treetypes.PathAndUpdate) {
4141
ti.updates = append(ti.updates, u...)
4242
}
4343

44-
func (ti *TransactionIntent) GetUpdates() treetypes.UpdateSlice {
44+
func (ti *TransactionIntent) GetUpdates() []*treetypes.PathAndUpdate {
4545
return ti.updates
4646
}
4747

@@ -83,10 +83,14 @@ func (ti *TransactionIntent) SetDeleteOnlyIntendedFlag() {
8383
}
8484

8585
func (ti *TransactionIntent) GetPathSet() *sdcpb.PathSet {
86-
return ti.updates.ToSdcpbPathSet()
86+
result := sdcpb.NewPathSet()
87+
for _, upd := range ti.updates {
88+
result.AddPath(upd.GetPath())
89+
}
90+
return result
8791
}
8892

89-
func (ti *TransactionIntent) AddUpdate(u *treetypes.Update) {
93+
func (ti *TransactionIntent) AddUpdate(u *treetypes.PathAndUpdate) {
9094
ti.updates = append(ti.updates, u)
9195
}
9296

0 commit comments

Comments
 (0)