@@ -29,6 +29,7 @@ import (
29
29
"fmt"
30
30
"reflect"
31
31
"sync"
32
+ "sync/atomic"
32
33
"time"
33
34
34
35
"github.com/opentracing/opentracing-go"
@@ -942,7 +943,7 @@ func (weh *workflowExecutionEventHandlerImpl) ProcessEvent(
942
943
}
943
944
944
945
historySum := weh .estimateHistorySize (event )
945
- weh .workflowInfo .TotalHistoryBytes += int64 (historySum )
946
+ atomic . AddInt64 ( & weh .workflowInfo .TotalHistoryBytes , int64 (historySum ) )
946
947
947
948
// When replaying histories to get stack trace or current state the last event might be not
948
949
// decision started. So always call OnDecisionTaskStarted on the last event.
@@ -1392,9 +1393,9 @@ func (weh *workflowExecutionEventHandlerImpl) estimateHistorySize(event *m.Histo
1392
1393
sum += len (event .WorkflowExecutionStartedEventAttributes .Input )
1393
1394
sum += len (event .WorkflowExecutionStartedEventAttributes .ContinuedFailureDetails )
1394
1395
sum += len (event .WorkflowExecutionStartedEventAttributes .LastCompletionResult )
1395
- sum += len (event .WorkflowExecutionStartedEventAttributes .Memo .GetFields ())
1396
- sum += len (event .WorkflowExecutionStartedEventAttributes .Header .GetFields ())
1397
- sum += len (event .WorkflowExecutionStartedEventAttributes .SearchAttributes .GetIndexedFields ())
1396
+ sum += sizeOf (event .WorkflowExecutionStartedEventAttributes .Memo .GetFields ())
1397
+ sum += sizeOf (event .WorkflowExecutionStartedEventAttributes .Header .GetFields ())
1398
+ sum += sizeOf (event .WorkflowExecutionStartedEventAttributes .SearchAttributes .GetIndexedFields ())
1398
1399
}
1399
1400
case m .EventTypeWorkflowExecutionCompleted :
1400
1401
if event .WorkflowExecutionCompletedEventAttributes != nil {
@@ -1408,9 +1409,15 @@ func (weh *workflowExecutionEventHandlerImpl) estimateHistorySize(event *m.Histo
1408
1409
if event .WorkflowExecutionFailedEventAttributes != nil {
1409
1410
sum += len (event .WorkflowExecutionFailedEventAttributes .Details )
1410
1411
}
1412
+ case m .EventTypeDecisionTaskStarted :
1413
+ if event .DecisionTaskStartedEventAttributes != nil {
1414
+ sum += len (* event .DecisionTaskStartedEventAttributes .Identity )
1415
+ }
1411
1416
case m .EventTypeDecisionTaskCompleted :
1412
1417
if event .DecisionTaskCompletedEventAttributes != nil {
1413
1418
sum += len (event .DecisionTaskCompletedEventAttributes .ExecutionContext )
1419
+ sum += len (* event .DecisionTaskCompletedEventAttributes .Identity )
1420
+ sum += len (* event .DecisionTaskCompletedEventAttributes .BinaryChecksum )
1414
1421
}
1415
1422
case m .EventTypeDecisionTaskFailed :
1416
1423
if event .DecisionTaskFailedEventAttributes != nil {
@@ -1419,7 +1426,7 @@ func (weh *workflowExecutionEventHandlerImpl) estimateHistorySize(event *m.Histo
1419
1426
case m .EventTypeActivityTaskScheduled :
1420
1427
if event .ActivityTaskScheduledEventAttributes != nil {
1421
1428
sum += len (event .ActivityTaskScheduledEventAttributes .Input )
1422
- sum += len (event .ActivityTaskScheduledEventAttributes .Header .GetFields ())
1429
+ sum += sizeOf (event .ActivityTaskScheduledEventAttributes .Header .GetFields ())
1423
1430
}
1424
1431
case m .EventTypeActivityTaskStarted :
1425
1432
if event .ActivityTaskStartedEventAttributes != nil {
@@ -1428,6 +1435,7 @@ func (weh *workflowExecutionEventHandlerImpl) estimateHistorySize(event *m.Histo
1428
1435
case m .EventTypeActivityTaskCompleted :
1429
1436
if event .ActivityTaskCompletedEventAttributes != nil {
1430
1437
sum += len (event .ActivityTaskCompletedEventAttributes .Result )
1438
+ sum += len (* event .ActivityTaskCompletedEventAttributes .Identity )
1431
1439
}
1432
1440
case m .EventTypeActivityTaskFailed :
1433
1441
if event .ActivityTaskFailedEventAttributes != nil {
@@ -1459,17 +1467,17 @@ func (weh *workflowExecutionEventHandlerImpl) estimateHistorySize(event *m.Histo
1459
1467
sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .Input )
1460
1468
sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .FailureDetails )
1461
1469
sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .LastCompletionResult )
1462
- sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .Memo .GetFields ())
1463
- sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .Header .GetFields ())
1464
- sum += len (event .WorkflowExecutionContinuedAsNewEventAttributes .SearchAttributes .GetIndexedFields ())
1470
+ sum += sizeOf (event .WorkflowExecutionContinuedAsNewEventAttributes .Memo .GetFields ())
1471
+ sum += sizeOf (event .WorkflowExecutionContinuedAsNewEventAttributes .Header .GetFields ())
1472
+ sum += sizeOf (event .WorkflowExecutionContinuedAsNewEventAttributes .SearchAttributes .GetIndexedFields ())
1465
1473
}
1466
1474
case m .EventTypeStartChildWorkflowExecutionInitiated :
1467
1475
if event .StartChildWorkflowExecutionInitiatedEventAttributes != nil {
1468
1476
sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .Input )
1469
1477
sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .Control )
1470
- sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .Memo .GetFields ())
1471
- sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .Header .GetFields ())
1472
- sum += len (event .StartChildWorkflowExecutionInitiatedEventAttributes .SearchAttributes .GetIndexedFields ())
1478
+ sum += sizeOf (event .StartChildWorkflowExecutionInitiatedEventAttributes .Memo .GetFields ())
1479
+ sum += sizeOf (event .StartChildWorkflowExecutionInitiatedEventAttributes .Header .GetFields ())
1480
+ sum += sizeOf (event .StartChildWorkflowExecutionInitiatedEventAttributes .SearchAttributes .GetIndexedFields ())
1473
1481
}
1474
1482
case m .EventTypeChildWorkflowExecutionCompleted :
1475
1483
if event .ChildWorkflowExecutionCompletedEventAttributes != nil {
@@ -1478,6 +1486,7 @@ func (weh *workflowExecutionEventHandlerImpl) estimateHistorySize(event *m.Histo
1478
1486
case m .EventTypeChildWorkflowExecutionFailed :
1479
1487
if event .ChildWorkflowExecutionFailedEventAttributes != nil {
1480
1488
sum += len (event .ChildWorkflowExecutionFailedEventAttributes .Details )
1489
+ sum += len (* event .ChildWorkflowExecutionFailedEventAttributes .Reason )
1481
1490
}
1482
1491
case m .EventTypeChildWorkflowExecutionCanceled :
1483
1492
if event .ChildWorkflowExecutionCanceledEventAttributes != nil {
@@ -1488,9 +1497,19 @@ func (weh *workflowExecutionEventHandlerImpl) estimateHistorySize(event *m.Histo
1488
1497
sum += len (event .SignalExternalWorkflowExecutionInitiatedEventAttributes .Control )
1489
1498
sum += len (event .SignalExternalWorkflowExecutionInitiatedEventAttributes .Input )
1490
1499
}
1500
+
1491
1501
default :
1492
1502
weh .logger .Warn ("unknown event type" , zap .String ("Event Type" , event .GetEventType ().String ()))
1493
1503
}
1494
1504
1495
1505
return sum
1496
1506
}
1507
+
1508
+ // simple function to estimate the size of a map[string][]byte
1509
+ func sizeOf (o map [string ][]byte ) int {
1510
+ sum := 0
1511
+ for k , v := range o {
1512
+ sum += len (k ) + len (v )
1513
+ }
1514
+ return sum
1515
+ }
0 commit comments