db.go ×11

Frontier kind: Code frontier

unlabeled · c_d938b0fa20f8

464 tests · 3003 LOC · 141 files · introduces 0 tests · 93 LOC · 3 files

Introduces — evidence that enters the hierarchy at this concept

Code
17 ranges93 lines · 3 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
454 ranges3003 lines · 141 files · Browse complete extent
All tests (intent)
464 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.

3 files ranked by introduced lines: 93 introduced LOC across 17 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/matching/db.go 74 introduced LOC · 11 ranges

Open complete file

152 func (db *taskQueueDB) RenewLease(
153 ctx context.Context,
154 > ) (taskQueueState, error) { db.go
155 > db.Lock()
156 > defer db.Unlock()
157 >
158 > if db.rangeID == 0 {
159 > if err := db.takeOverTaskQueueLocked(ctx); err != nil {
160 return taskQueueState{}, err
161 }
165 }
166 }
167 > return taskQueueState{ db.go
168 > rangeID: db.rangeID,
169 > ackLevel: db.subqueues[subqueueZero].AckLevel, // TODO(pri): cleanup, only used by old backlog manager
170 > subqueues: db.cloneSubqueues(),
171 > otherHasTasks: !db.isDraining && db.otherHasTasks,
172 > scaleState: db.scaleState,
173 > }, nil
174 }
175
176 func (db *taskQueueDB) takeOverTaskQueueLocked(
177 ctx context.Context,
178 > ) error { db.go
179 > response, err := db.store.GetTaskQueue(ctx, &persistence.GetTaskQueueRequest{
180 > NamespaceID: db.queue.NamespaceId(),
181 > TaskQueue: db.queue.PersistenceName(),
182 > TaskType: db.queue.TaskType(),
183 > })
184 > switch err.(type) {
185 case nil:
186 db.rangeID = response.RangeID
814 }
815
816 > func (db *taskQueueDB) expiryTime() *timestamppb.Timestamp { db.go
817 > if ttl := db.queue.Partition().PersistenceTTL(); ttl > 0 {
818 return timestamppb.New(time.Now().Add(ttl))
819 }
821 }
822
823 > func (db *taskQueueDB) cachedQueueInfo() *persistencespb.TaskQueueInfo { db.go
824 > infos := make([]*persistencespb.SubqueueInfo, len(db.subqueues))
825 > for i := range db.subqueues {
826 > infos[i] = &db.subqueues[i].SubqueueInfo
827 > }
828 > return &persistencespb.TaskQueueInfo{
829 > NamespaceId: db.queue.NamespaceId(),
830 > Name: db.queue.PersistenceName(),
831 > TaskType: db.queue.TaskType(),
832 > Kind: db.queue.Partition().Kind(),
833 > AckLevel: db.subqueues[subqueueZero].AckLevel, // backwards compatibility
834 > ExpiryTime: db.expiryTime(),
835 > LastUpdateTime: timestamp.TimeNowPtrUtc(),
836 > ApproximateBacklogCount: db.subqueues[subqueueZero].ApproximateBacklogCount, // backwards compatibility
837 > Subqueues: infos,
838 > OtherHasTasks: db.otherHasTasks,
839 > PartitionScaleState: db.scaleState,
840 > }
841 }
842
909 initAckLevel int64,
910 initApproxCount int64,
911 > ) []*dbSubqueue { db.go
912 > // convert+copy protos to []*dbSubqueue
913 > subqueues := make([]*dbSubqueue, len(infos))
914 > for i, info := range infos {
915 subqueues[i] = &dbSubqueue{}
916 proto.Merge(&subqueues[i].SubqueueInfo, info)
918
919 // check for default priority and add if not present (this may be initializing subqueue 0)
920 > defKey := &persistencespb.SubqueueKey{ db.go
921 > Priority: int32(db.config.DefaultPriorityKey),
922 > }
923 > hasDefault := slices.ContainsFunc(subqueues, func(s *dbSubqueue) bool {
924 return proto.Equal(s.Key, defKey)
925 })
926 > if !hasDefault { db.go
927 > subqueues = append(subqueues, db.newSubqueueLocked(defKey))
928 > // If we are transitioning from no-subqueues to subqueues, initialize subqueue 0 with
929 > // the ack level and approx count from TaskQueueInfo.
930 > if len(subqueues) == 1 {
931 > subqueues[subqueueZero].AckLevel = initAckLevel
932 > subqueues[subqueueZero].ApproximateBacklogCount = initApproxCount
933 > }
934 }
935 > return subqueues db.go
936 }
937
938 > func (db *taskQueueDB) newSubqueueLocked(key *persistencespb.SubqueueKey) *dbSubqueue { db.go
939 > // For fifo queues: start ack level + max read level just before the current block.
940 > // For fair queues: ack level and max read level don't matter here.
941 > initAckLevel := rangeIDToTaskIDBlock(db.rangeID, db.config.RangeSize).start - 1
942 > softassert.That(db.logger, initAckLevel >= 0, "initAckLevel should not be negative")
943 >
944 > s := &dbSubqueue{maxReadLevel: initAckLevel}
945 > s.Key = key
946 > s.AckLevel = initAckLevel
947 > return s
948 > }
949
950 // clone db.subqueues so we can return it outside our lock
951 > func (db *taskQueueDB) cloneSubqueues() []persistencespb.SubqueueInfo { db.go
952 > infos := make([]persistencespb.SubqueueInfo, len(db.subqueues))
953 > for i := range db.subqueues {
954 > proto.Merge(&infos[i], &db.subqueues[i].SubqueueInfo)
955 > }
956 > return infos
957 }
958
go.temporal.io/server/api/persistence/v1/tasks.pb.go 13 introduced LOC · 5 ranges

Open complete file

402 mi := &file_temporal_server_api_persistence_v1_tasks_proto_msgTypes[3]
403 if x != nil {
404 > ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) tasks.pb.go
405 > if ms.LoadMessageInfo() == nil {
406 > ms.StoreMessageInfo(mi)
407 > }
408 > return ms
409 }
410 return mi.MessageOf(x)
479 func (*FairnessKeyCount) ProtoMessage() {}
480
481 > func (x *FairnessKeyCount) ProtoReflect() protoreflect.Message { tasks.pb.go
482 > mi := &file_temporal_server_api_persistence_v1_tasks_proto_msgTypes[4]
483 > if x != nil {
484 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
485 if ms.LoadMessageInfo() == nil {
488 return ms
489 }
490 > return mi.MessageOf(x) tasks.pb.go
491 }
492
531 func (*SubqueueKey) ProtoMessage() {}
532
533 > func (x *SubqueueKey) ProtoReflect() protoreflect.Message { tasks.pb.go
534 > mi := &file_temporal_server_api_persistence_v1_tasks_proto_msgTypes[5]
535 > if x != nil {
536 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
537 if ms.LoadMessageInfo() == nil {
540 return ms
541 }
542 > return mi.MessageOf(x) tasks.pb.go
543 }
544
go.temporal.io/server/service/matching/backlog_manager.go 6 introduced LOC · 1 range

Open complete file

272 }
273
274 > func rangeIDToTaskIDBlock(rangeID int64, rangeSize int64) taskIDBlock { backlog_manager.go
275 > return taskIDBlock{
276 > start: (rangeID-1)*rangeSize + 1,
277 > end: rangeID * rangeSize,
278 > }
279 > }
280
281 // Retry operation on transient error.