Skip to content

Commit 4d2c616

Browse files
committed
Make parent entry also an attribute of LeafVariants
1 parent 60710f2 commit 4d2c616

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

pkg/tree/entry_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ func TestLeafVariants_GetHighesPrio(t *testing.T) {
724724
// because thats an update.
725725
t.Run("Delete Non New",
726726
func(t *testing.T) {
727-
lv := newLeafVariants(&TreeContext{})
727+
lv := newLeafVariants(&TreeContext{}, nil)
728728

729729
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 2, owner1, ts), flagsExisting, nil))
730730
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 1, owner2, ts), flagsExisting, nil))
@@ -743,7 +743,7 @@ func TestLeafVariants_GetHighesPrio(t *testing.T) {
743743
// should return nil
744744
t.Run("Single entry thats also marked for deletion",
745745
func(t *testing.T) {
746-
lv := newLeafVariants(&TreeContext{})
746+
lv := newLeafVariants(&TreeContext{}, nil)
747747
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 1, owner1, ts), flagsExisting, nil))
748748
lv.les[0].MarkDelete(false)
749749

@@ -759,7 +759,7 @@ func TestLeafVariants_GetHighesPrio(t *testing.T) {
759759
// on onlyIfPrioChanged == true we do not expect output.
760760
t.Run("New Low Prio IsUpdate OnlyChanged True",
761761
func(t *testing.T) {
762-
lv := newLeafVariants(&TreeContext{})
762+
lv := newLeafVariants(&TreeContext{}, nil)
763763
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 5, owner1, ts), flagsExisting, nil))
764764
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 6, owner2, ts), flagsNew, nil))
765765
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, RunningValuesPrio, RunningIntentName, ts), flagsExisting, nil))
@@ -776,7 +776,7 @@ func TestLeafVariants_GetHighesPrio(t *testing.T) {
776776
// on onlyIfPrioChanged == false we do not expect the highes prio update to be returned.
777777
t.Run("New Low Prio IsUpdate OnlyChanged False",
778778
func(t *testing.T) {
779-
lv := newLeafVariants(&TreeContext{})
779+
lv := newLeafVariants(&TreeContext{}, nil)
780780
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 5, owner1, ts), flagsExisting, nil))
781781
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 6, owner1, ts), flagsNew, nil))
782782

@@ -792,7 +792,7 @@ func TestLeafVariants_GetHighesPrio(t *testing.T) {
792792
// // on onlyIfPrioChanged == true we do not expect output.
793793
t.Run("New Low Prio IsNew OnlyChanged == True",
794794
func(t *testing.T) {
795-
lv := newLeafVariants(&TreeContext{})
795+
lv := newLeafVariants(&TreeContext{}, nil)
796796

797797
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 5, owner1, ts), flagsExisting, nil))
798798
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 6, owner2, ts), flagsNew, nil))
@@ -810,7 +810,7 @@ func TestLeafVariants_GetHighesPrio(t *testing.T) {
810810
// // on onlyIfPrioChanged == true we do not expect output.
811811
t.Run("New Low Prio IsNew OnlyChanged == True, with running not existing",
812812
func(t *testing.T) {
813-
lv := newLeafVariants(&TreeContext{})
813+
lv := newLeafVariants(&TreeContext{}, nil)
814814

815815
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 5, owner1, ts), flagsExisting, nil))
816816
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 6, owner2, ts), flagsNew, nil))
@@ -825,7 +825,7 @@ func TestLeafVariants_GetHighesPrio(t *testing.T) {
825825

826826
t.Run("New Low Prio IsNew OnlyChanged == False",
827827
func(t *testing.T) {
828-
lv := newLeafVariants(&TreeContext{})
828+
lv := newLeafVariants(&TreeContext{}, nil)
829829
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 5, owner1, ts), flagsExisting, nil))
830830
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 6, owner2, ts), flagsNew, nil))
831831

@@ -853,7 +853,7 @@ func TestLeafVariants_GetHighesPrio(t *testing.T) {
853853
// make sure the secondhighes is also populated if the highes was the first entry
854854
t.Run("secondhighes populated if highes was first",
855855
func(t *testing.T) {
856-
lv := newLeafVariants(&TreeContext{})
856+
lv := newLeafVariants(&TreeContext{}, nil)
857857
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 1, owner1, ts), flagsExisting, nil))
858858
lv.les[0].MarkDelete(false)
859859
lv.Add(NewLeafEntry(types.NewUpdate(path, nil, 2, owner2, ts), flagsExisting, nil))

pkg/tree/leaf_variants.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ import (
1111
)
1212

1313
type LeafVariants struct {
14-
les []*LeafEntry
15-
lesMutex sync.RWMutex
16-
tc *TreeContext
14+
les []*LeafEntry
15+
lesMutex sync.RWMutex
16+
tc *TreeContext
17+
parentEntry Entry
1718
}
1819

19-
func newLeafVariants(tc *TreeContext) *LeafVariants {
20+
func newLeafVariants(tc *TreeContext, parentEnty Entry) *LeafVariants {
2021
return &LeafVariants{
21-
les: make([]*LeafEntry, 0, 2),
22-
tc: tc,
22+
les: make([]*LeafEntry, 0, 2),
23+
tc: tc,
24+
parentEntry: parentEnty,
2325
}
2426
}
2527

@@ -153,9 +155,10 @@ func (lv *LeafVariants) GetHighestPrecedenceValue(filter HighestPrecedenceFilter
153155

154156
func (lv *LeafVariants) DeepCopy(tc *TreeContext, parent Entry) *LeafVariants {
155157
result := &LeafVariants{
156-
lesMutex: sync.RWMutex{},
157-
tc: tc,
158-
les: make([]*LeafEntry, 0, len(lv.les)),
158+
lesMutex: sync.RWMutex{},
159+
tc: tc,
160+
les: make([]*LeafEntry, 0, len(lv.les)),
161+
parentEntry: parent,
159162
}
160163

161164
lv.lesMutex.RLock()
@@ -247,6 +250,8 @@ func (lv *LeafVariants) GetHighestPrecedence(onlyNewOrUpdated bool, includeDefau
247250
}
248251

249252
func (lv *LeafVariants) highestIsUnequalRunning(highest *LeafEntry) bool {
253+
lv.lesMutex.RLock()
254+
defer lv.lesMutex.RUnlock()
250255
// if highes is already running or even default, return false
251256
if highest.Update.Owner() == RunningIntentName {
252257
return false
@@ -287,6 +292,8 @@ func (lv *LeafVariants) MarkOwnerForDeletion(owner string, onlyIntended bool) {
287292
}
288293

289294
func (lv *LeafVariants) DeleteByOwner(owner string) (remainsToExist bool) {
295+
lv.lesMutex.Lock()
296+
defer lv.lesMutex.Unlock()
290297
foundOwner := false
291298
for i, l := range lv.les {
292299
// early exit if condition is met
@@ -309,18 +316,21 @@ func (lv *LeafVariants) DeleteByOwner(owner string) (remainsToExist bool) {
309316
}
310317

311318
func (lv *LeafVariants) GetDeviations(ch chan<- *types.DeviationEntry, isActiveCase bool) {
319+
lv.lesMutex.RLock()
320+
defer lv.lesMutex.RUnlock()
321+
312322
if len(lv.les) == 0 {
313323
return
314324
}
315325

316326
// if it is a presence container that contains childs, skip
317-
if lv.les[0].parentEntry.GetSchema().GetContainer().GetIsPresence() && len(lv.les[0].parentEntry.getChildren()) > 0 {
327+
if lv.parentEntry.GetSchema().GetContainer().GetIsPresence() && len(lv.parentEntry.getChildren()) > 0 {
318328
return
319329
}
320330

321331
// get the path via the first LeafEntry
322332
// is valida for all entries
323-
sdcpbPath, err := lv.les[0].parentEntry.SdcpbPath()
333+
sdcpbPath, err := lv.parentEntry.SdcpbPath()
324334
if err != nil {
325335
log.Error(err)
326336
}

pkg/tree/sharedEntryAttributes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ func newSharedEntryAttributes(ctx context.Context, parent Entry, pathElemName st
8787
parent: parent,
8888
pathElemName: pathElemName,
8989
childs: newChildMap(),
90-
leafVariants: newLeafVariants(tc),
9190
treeContext: tc,
9291
}
92+
s.leafVariants = newLeafVariants(tc, s)
9393

9494
// populate the schema
9595
err := s.populateSchema(ctx)

0 commit comments

Comments
 (0)