Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions chasm/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ type (

// NodesMutation is a set of mutations for all nodes rooted at a given node n,
// including the node n itself.
//
// TODO: Return tree size changes in NodesMutation as well. MutateState needs to
// track the overall size of itself and terminate workflow if it exceeds the limit.
NodesMutation struct {
UpdatedNodes map[string]*persistencespb.ChasmNode // encoded node path -> chasm node
DeletedNodes map[string]struct{}
Expand Down
17 changes: 14 additions & 3 deletions service/history/workflow/mutable_state_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ type (
// Running approximate total size of mutable state fields (except buffered events) when written to DB in bytes.
// Buffered events are added to this value when calling GetApproximatePersistedSize.
approximateSize int
chasmNodeSizes map[string]int // chasm node path -> size in bytes
// Total number of tomestones tracked in mutable state
totalTombstones int
// Buffer events from DB
Expand Down Expand Up @@ -302,6 +303,7 @@ func NewMutableState(
chasmTree: &noopChasmTree{},

approximateSize: 0,
chasmNodeSizes: make(map[string]int),
totalTombstones: 0,
currentVersion: namespaceEntry.FailoverVersion(),
bufferEventsInDB: nil,
Expand Down Expand Up @@ -528,7 +530,9 @@ func NewMutableStateFromDB(
return nil, err
}
for key, node := range dbRecord.ChasmNodes {
mutableState.approximateSize += len(key) + node.Size()
nodeSize := node.Size()
mutableState.approximateSize += len(key) + nodeSize
mutableState.chasmNodeSizes[key] = nodeSize
}
}

Expand Down Expand Up @@ -6445,12 +6449,19 @@ func (ms *MutableStateImpl) closeTransaction(

// CloseTransaction() on chasmTree may update execution state & status,
// so must be called before closeTransactionUpdateTransitionHistory().
//
// TODO: update approximateSize once chasm.NodesMutation returns size change as well.
chasmNodesMutation, err := ms.chasmTree.CloseTransaction()
if err != nil {
return closeTransactionResult{}, err
}
for nodePath := range chasmNodesMutation.DeletedNodes {
ms.approximateSize -= ms.chasmNodeSizes[nodePath]
delete(ms.chasmNodeSizes, nodePath)
}
for nodePath, node := range chasmNodesMutation.UpdatedNodes {
newSize := node.Size()
ms.approximateSize += newSize - ms.chasmNodeSizes[nodePath]
ms.chasmNodeSizes[nodePath] = newSize
}

if isStateDirty {
if err := ms.closeTransactionUpdateTransitionHistory(
Expand Down
Loading