Skip to content

Commit

Permalink
Merge locking keys into partial loading keys when using locking loadi…
Browse files Browse the repository at this point in the history
…ng types (#341)
  • Loading branch information
longquanzheng committed Sep 18, 2023
1 parent 1fe1b5f commit 5410299
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions integ/workflow/persistence_loading_policy/routers.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func verifyLoadedAttributes(
var expectedSearchAttributes []iwfidl.SearchAttribute
var expectedDataAttributes []iwfidl.KeyValue

if loadingType == iwfidl.ALL_WITHOUT_LOCKING {
if loadingType == iwfidl.ALL_WITHOUT_LOCKING || loadingType == iwfidl.PARTIAL_WITH_EXCLUSIVE_LOCK {
expectedSearchAttributes = []iwfidl.SearchAttribute{
{
Key: iwfidl.PtrString(persistence.TestSearchAttributeKeywordKey),
Expand Down Expand Up @@ -201,7 +201,7 @@ func verifyLoadedAttributes(
},
},
}
} else if loadingType == iwfidl.PARTIAL_WITHOUT_LOCKING || loadingType == iwfidl.PARTIAL_WITH_EXCLUSIVE_LOCK {
} else if loadingType == iwfidl.PARTIAL_WITHOUT_LOCKING {
expectedSearchAttributes = []iwfidl.SearchAttribute{
{
Key: iwfidl.PtrString(persistence.TestSearchAttributeKeywordKey),
Expand Down
18 changes: 18 additions & 0 deletions service/common/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ const (
defaultMaxApiTimeoutSeconds = 60
)

func MergeStringSlice(first, second []string) []string {
exists := map[string]bool{}
var out []string
for _, k := range first {
if !exists[k] {
exists[k] = true
out = append(out, k)
}
}
for _, k := range second {
if !exists[k] {
exists[k] = true
out = append(out, k)
}
}
return out
}

func MergeMap(first map[string]interface{}, second map[string]interface{}) map[string]interface{} {
out := make(map[string]interface{}, len(first))
for k, v := range first {
Expand Down
7 changes: 7 additions & 0 deletions service/interpreter/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/indeedeng/iwf/gen/iwfidl"
"github.com/indeedeng/iwf/service"
"github.com/indeedeng/iwf/service/common/mapper"
"github.com/indeedeng/iwf/service/common/utils"
)

type PersistenceManager struct {
Expand Down Expand Up @@ -85,6 +86,9 @@ func (am *PersistenceManager) LoadSearchAttributes(ctx UnifiedContext, loadingPo
if loadingPolicy != nil {
loadingType = loadingPolicy.GetPersistenceLoadingType()
partialLoadingKeys = loadingPolicy.PartialLoadingKeys
if loadingType == iwfidl.PARTIAL_WITH_EXCLUSIVE_LOCK {
partialLoadingKeys = utils.MergeStringSlice(loadingPolicy.PartialLoadingKeys, loadingPolicy.LockingKeys)
}

if loadingType == iwfidl.PARTIAL_WITH_EXCLUSIVE_LOCK {
am.awaitAndLockForKeys(ctx, am.lockedSearchAttributeKeys, loadingPolicy.GetLockingKeys())
Expand Down Expand Up @@ -118,6 +122,9 @@ func (am *PersistenceManager) LoadDataObjects(ctx UnifiedContext, loadingPolicy
if loadingPolicy != nil {
loadingType = loadingPolicy.GetPersistenceLoadingType()
partialLoadingKeys = loadingPolicy.PartialLoadingKeys
if loadingType == iwfidl.PARTIAL_WITH_EXCLUSIVE_LOCK {
partialLoadingKeys = utils.MergeStringSlice(loadingPolicy.PartialLoadingKeys, loadingPolicy.LockingKeys)
}

if loadingType == iwfidl.PARTIAL_WITH_EXCLUSIVE_LOCK {
am.awaitAndLockForKeys(ctx, am.lockedDataObjectKeys, loadingPolicy.GetLockingKeys())
Expand Down

0 comments on commit 5410299

Please sign in to comment.