context.go ×20

Frontier kind: Code frontier

unlabeled · c_df1b9aeeb30f

130 tests · 4659 LOC · 179 files · introduces 0 tests · 68 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
20 ranges68 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
817 ranges4659 lines · 179 files · Browse complete extent
All tests (intent)
130 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: 68 introduced LOC across 20 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

go.temporal.io/server/service/history/workflow/context.go 68 introduced LOC · 20 ranges

Open complete file

631 ctx context.Context,
632 shardContext historyi.ShardContext,
633 > ) error { context.go
634 >
635 > // We only perform this check on active cluster for the namespace
636 > historySizeForceTerminate, err := c.enforceHistorySizeCheck(ctx, shardContext)
637 > if err != nil {
638 return err
639 }
640 > historyCountForceTerminate := false context.go
641 > if !historySizeForceTerminate {
642 > historyCountForceTerminate, err = c.enforceHistoryCountCheck(ctx, shardContext)
643 > if err != nil {
644 return err
645 }
646 }
647 > msForceTerminate := false context.go
648 > if !historySizeForceTerminate && !historyCountForceTerminate {
649 > msForceTerminate, err = c.enforceMutableStateSizeCheck(ctx, shardContext)
650 > if err != nil {
651 return err
652 }
653 }
654
655 > updateMode, err := c.updateWorkflowMode() context.go
656 > if err != nil {
657 return err
658 }
659
660 > err = c.UpdateWorkflowExecutionWithNew( context.go
661 > ctx,
662 > shardContext,
663 > updateMode,
664 > nil,
665 > nil,
666 > historyi.TransactionPolicyActive,
667 > nil,
668 > )
669 > if err != nil {
670 return err
671 }
1260 ctx context.Context,
1261 shardContext historyi.ShardContext,
1262 > ) (bool, error) { context.go
1263 > // Hard terminate workflow if still running and breached history size limit
1264 > if c.maxHistorySizeExceeded(shardContext) {
1265 if err := c.forceTerminateWorkflow(ctx, shardContext, common.FailureReasonHistorySizeExceedsLimit); err != nil {
1266 return false, err
1269 return true, nil
1270 }
1271 > return false, nil context.go
1272 }
1273
1274 // Returns true if the workflow is running and history size should trigger a forced termination
1275 // Prints a log message if history size is over the error or warn limits
1276 > func (c *ContextImpl) maxHistorySizeExceeded(shardContext historyi.ShardContext) bool { context.go
1277 > namespaceName := c.GetNamespace(shardContext).String()
1278 > historySizeLimitWarn := c.config.HistorySizeLimitWarn(namespaceName)
1279 > historySizeLimitError := c.config.HistorySizeLimitError(namespaceName)
1280 > historySize := int(c.MutableState.GetExecutionInfo().ExecutionStats.HistorySize)
1281 >
1282 > if historySize > historySizeLimitError && c.MutableState.IsWorkflowExecutionRunning() {
1283 c.logger.Warn("history size exceeds error limit.",
1284 tag.WorkflowHistorySize(historySize))
1287 }
1288
1289 > if historySize > historySizeLimitWarn { context.go
1290 c.throttledLogger.Warn("history size exceeds warn limit.",
1291 tag.WorkflowHistorySize(historySize))
1292 }
1293
1294 > return false context.go
1295 }
1296
1298 ctx context.Context,
1299 shardContext historyi.ShardContext,
1300 > ) (bool, error) { context.go
1301 > // Hard terminate workflow if still running and breached history count limit
1302 > if c.maxHistoryCountExceeded(shardContext) {
1303 if err := c.forceTerminateWorkflow(ctx, shardContext, common.FailureReasonHistoryCountExceedsLimit); err != nil {
1304 return false, err
1307 return true, nil
1308 }
1309 > return false, nil context.go
1310 }
1311
1312 // Returns true if the workflow is running and history event count should trigger a forced termination
1313 // Prints a log message if history event count is over the error or warn limits
1314 > func (c *ContextImpl) maxHistoryCountExceeded(shardContext historyi.ShardContext) bool { context.go
1315 > namespaceName := c.GetNamespace(shardContext).String()
1316 > historyCountLimitWarn := c.config.HistoryCountLimitWarn(namespaceName)
1317 > historyCountLimitError := c.config.HistoryCountLimitError(namespaceName)
1318 > historyCount := int(c.MutableState.GetNextEventID() - 1)
1319 >
1320 > if historyCount > historyCountLimitError && c.MutableState.IsWorkflowExecutionRunning() {
1321 c.logger.Warn("history count exceeds error limit.",
1322 tag.WorkflowEventCount(historyCount))
1325 }
1326
1327 > if historyCount > historyCountLimitWarn { context.go
1328 c.throttledLogger.Warn("history count exceeds warn limit.",
1329 tag.WorkflowEventCount(historyCount))
1330 }
1331
1332 > return false context.go
1333 }
1334
1335 // Returns true if execution is forced terminated
1336 // TODO: ideally this check should be after closing mutable state tx, but that would require a large refactor
1337 > func (c *ContextImpl) enforceMutableStateSizeCheck(ctx context.Context, shardContext historyi.ShardContext) (bool, error) { context.go
1338 > if c.maxMutableStateSizeExceeded(shardContext.ChasmRegistry()) {
1339 if err := c.forceTerminateWorkflow(ctx, shardContext, common.FailureReasonMutableStateSizeExceedsLimit); err != nil {
1340 return false, err
1343 return true, nil
1344 }
1345 > return false, nil context.go
1346 }
1347
1348 // Returns true if the workflow is running and mutable state size should trigger a forced termination
1349 // Prints a log message if mutable state size is over the error or warn limits
1350 > func (c *ContextImpl) maxMutableStateSizeExceeded(chasmRegistry *chasm.Registry) bool { context.go
1351 > mutableStateSizeLimitError := c.config.MutableStateSizeLimitError()
1352 > mutableStateSizeLimitWarn := c.config.MutableStateSizeLimitWarn()
1353 >
1354 > mutableStateSize := c.MutableState.GetApproximatePersistedSize()
1355 > metricsHandler := c.metricsHandler
1356 > if archetypeTag, ok := getArchetypeMetricTag(chasmRegistry, c.MutableState.ChasmTree().ArchetypeID()); ok {
1357 > metricsHandler = metricsHandler.WithTags(archetypeTag)
1358 > }
1359 > metrics.PersistedMutableStateSize.With(metricsHandler).Record(int64(mutableStateSize))
1360 >
1361 > if mutableStateSize > mutableStateSizeLimitError {
1362 c.logger.Warn("mutable state size exceeds error limit.",
1363 tag.WorkflowMutableStateSize(mutableStateSize))
1366 }
1367
1368 > if mutableStateSize > mutableStateSizeLimitWarn { context.go
1369 c.throttledLogger.Warn("mutable state size exceeds warn limit.",
1370 tag.WorkflowMutableStateSize(mutableStateSize))
1371 }
1372
1373 > return false context.go
1374 }
1375