version_sets_merge.go ×13

Frontier kind: Code frontier

unlabeled · c_59795d71ba94

11 tests · 2732 LOC · 136 files · introduces 0 tests · 82 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
13 ranges82 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
418 ranges2732 lines · 136 files · Browse complete extent
All tests (intent)
11 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 82 introduced LOC across 13 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/matching/version_sets_merge.go 82 introduced LOC · 13 ranges

Open complete file

10
11 // Merge and sort two sets of set IDs
12 > func mergeSetIDs(a []string, b []string) []string { version_sets_merge.go
13 > var mergedSetIDs []string
14 > seenSetIDs := make(map[string]struct{}, len(a))
15 > mergedSetIDs = append(mergedSetIDs, a...)
16 > for _, setID := range a {
17 > seenSetIDs[setID] = struct{}{}
18 > }
19 > for _, setID := range b {
20 > if _, found := seenSetIDs[setID]; !found {
21 mergedSetIDs = append(mergedSetIDs, setID)
22 }
23 }
24 > sort.Strings(mergedSetIDs) version_sets_merge.go
25 > return mergedSetIDs
26 }
27
28 // Check if a set contains any of the given set IDs.
29 > func setContainsSetIDs(set *persistencespb.CompatibleVersionSet, ids []string) bool { version_sets_merge.go
30 > for _, needle := range ids {
31 > if slices.Contains(set.SetIds, needle) {
32 return true
33 }
36 }
37
38 > func findSetWithSetIDs(sets []*persistencespb.CompatibleVersionSet, ids []string) *persistencespb.CompatibleVersionSet { version_sets_merge.go
39 > for _, set := range sets {
40 > if setContainsSetIDs(set, ids) {
41 return set
42 }
43 }
44 > return nil version_sets_merge.go
45 }
46
53 }
54
55 > func collectBuildIdInfo(sets []*persistencespb.CompatibleVersionSet) map[string]buildIDInfo { version_sets_merge.go
56 > buildIDToInfo := make(map[string]buildIDInfo, 0)
57 > for _, set := range sets {
58 > for _, buildID := range set.BuildIds {
59 > if info, found := buildIDToInfo[buildID.Id]; found {
60 > // A build ID appears in more than one source, merge its information, and track it
61 > state := info.state
62 > stateUpdateTimestamp := hlc.Max(buildID.StateUpdateTimestamp, info.stateUpdateTimestamp)
63 > if hlc.Equal(stateUpdateTimestamp, buildID.StateUpdateTimestamp) {
64 > state = buildID.State
65 > }
66 > buildIDToInfo[buildID.Id] = buildIDInfo{
67 > state: state,
68 > stateUpdateTimestamp: stateUpdateTimestamp,
69 > setIDs: mergeSetIDs(info.setIDs, set.SetIds),
70 > madeDefaultAt: hlc.Max(buildID.BecameDefaultTimestamp, info.madeDefaultAt),
71 > setMadeDefaultAt: hlc.Max(set.BecameDefaultTimestamp, info.setMadeDefaultAt),
72 > }
73 > } else {
74 > // A build ID was seen for the first time, track it
75 > buildIDToInfo[buildID.Id] = buildIDInfo{
76 > state: buildID.State,
77 > stateUpdateTimestamp: buildID.StateUpdateTimestamp,
78 > setIDs: set.SetIds,
79 > madeDefaultAt: buildID.BecameDefaultTimestamp,
80 > setMadeDefaultAt: set.BecameDefaultTimestamp,
81 > }
82 > }
83 }
84 }
85 > return buildIDToInfo version_sets_merge.go
86 }
87
88 > func intoVersionSets(buildIDToInfo map[string]buildIDInfo) []*persistencespb.CompatibleVersionSet { version_sets_merge.go
89 > sets := make([]*persistencespb.CompatibleVersionSet, 0)
90 > for id, info := range buildIDToInfo {
91 > set := findSetWithSetIDs(sets, info.setIDs)
92 > if set == nil {
93 > set = &persistencespb.CompatibleVersionSet{
94 > SetIds: info.setIDs,
95 > BuildIds: make([]*persistencespb.BuildId, 0),
96 > BecameDefaultTimestamp: info.setMadeDefaultAt,
97 > }
98 > sets = append(sets, set)
99 > } else {
100 set.SetIds = mergeSetIDs(set.SetIds, info.setIDs)
101 set.BecameDefaultTimestamp = hlc.Max(info.setMadeDefaultAt, set.BecameDefaultTimestamp)
102 }
103 > buildID := &persistencespb.BuildId{ version_sets_merge.go
104 > Id: id,
105 > State: info.state,
106 > StateUpdateTimestamp: info.stateUpdateTimestamp,
107 > BecameDefaultTimestamp: info.madeDefaultAt,
108 > }
109 > set.BuildIds = append(set.BuildIds, buildID)
110 }
111 // Sort the sets based on their default update timestamp, ensuring the default set comes last
112 > sortSets(sets) version_sets_merge.go
113 > for _, set := range sets {
114 > sortBuildIds(set.BuildIds)
115 > }
116 > return sets
117 }
118
119 > func sortSets(sets []*persistencespb.CompatibleVersionSet) { version_sets_merge.go
120 > sort.Slice(sets, func(i, j int) bool {
121 return hlc.Less(sets[i].BecameDefaultTimestamp, sets[j].BecameDefaultTimestamp)
122 })
123 }
124
125 > func sortBuildIds(buildIds []*persistencespb.BuildId) { version_sets_merge.go
126 > sort.Slice(buildIds, func(i, j int) bool {
127 return hlc.Less(buildIds[i].BecameDefaultTimestamp, buildIds[j].BecameDefaultTimestamp)
128 })
142
143 // Collect information about each build ID from both sources
144 > buildIDToInfo := collectBuildIdInfo(append(a.VersionSets, b.VersionSets...)) version_sets_merge.go
145 > // Build the merged compatible sets using collected build ID information
146 > sets := intoVersionSets(buildIDToInfo)
147 >
148 > return &persistencespb.VersioningData{
149 > VersionSets: sets,
150 > }
151 }