Skip to content

Commit f3cbbe5

Browse files
Merge pull request #360 from sdcio/updatenilpointer
fix update.path nil pointer
2 parents 705ae8c + 155f885 commit f3cbbe5

16 files changed

+1033
-683
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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"math"
78
"strings"
89
"time"
910

@@ -214,7 +215,7 @@ func (d *Datastore) lowlevelTransactionSet(ctx context.Context, transaction *typ
214215
lvs := tree.LeafVariantSlice{}
215216
lvs = root.GetByOwner(intent.GetName(), lvs)
216217

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

219220
marksOwnerDeleteVisitor := tree.NewMarkOwnerDeleteVisitor(intent.GetName(), intent.GetOnlyIntended())
220221
err := root.Walk(ctx, marksOwnerDeleteVisitor)
@@ -224,8 +225,13 @@ func (d *Datastore) lowlevelTransactionSet(ctx context.Context, transaction *typ
224225
// clear the owners existing explicit delete entries, retrieving the old entries for storing in the transaction for possible rollback
225226
oldExplicitDeletes := root.RemoveExplicitDeletes(intent.GetName())
226227

228+
priority := int32(math.MaxInt32)
229+
if len(oldIntentContent) > 0 {
230+
priority = oldIntentContent[0].GetUpdate().Priority()
231+
}
232+
227233
// store the old intent content in the transaction as the old intent.
228-
err = transaction.AddIntentContent(intent.GetName(), types.TransactionIntentOld, oldIntentContent.GetFirstPriorityValue(), oldIntentContent, oldExplicitDeletes)
234+
err = transaction.AddIntentContent(intent.GetName(), types.TransactionIntentOld, priority, oldIntentContent, oldExplicitDeletes)
229235
if err != nil {
230236
return nil, err
231237
}
@@ -245,7 +251,7 @@ func (d *Datastore) lowlevelTransactionSet(ctx context.Context, transaction *typ
245251
les := tree.LeafVariantSlice{}
246252
les = root.GetByOwner(tree.RunningIntentName, les)
247253

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

250256
log.V(logf.VDebug).Info("transaction finish tree insertion phase")
251257
// 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)