-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor history branch manipulation logic into its own utility
- Loading branch information
Showing
11 changed files
with
121 additions
and
187 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// The MIT License | ||
// | ||
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. | ||
// | ||
// Copyright (c) 2020 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package persistence | ||
|
||
import ( | ||
enumspb "go.temporal.io/api/enums/v1" | ||
persistencespb "go.temporal.io/server/api/persistence/v1" | ||
"go.temporal.io/server/common/persistence/serialization" | ||
"go.temporal.io/server/common/primitives" | ||
) | ||
|
||
type ( | ||
HistoryBranchUtil interface { | ||
// NewHistoryBranchToken initializes a new history branch token | ||
NewHistoryBranchToken(treeID string, branchID *string, ancestors []*persistencespb.HistoryBranchRange) ([]byte, error) | ||
// ParseHistoryBranchInfo parses the history branch for branch information | ||
ParseHistoryBranchInfo(branchToken []byte) (*persistencespb.HistoryBranch, error) | ||
// UpdateHistoryBranchInfo updates the history branch with branch information | ||
UpdateHistoryBranchInfo(branchToken []byte, branchInfo *persistencespb.HistoryBranch) ([]byte, error) | ||
} | ||
|
||
historyBranchUtilImpl struct { | ||
} | ||
) | ||
|
||
// NewHistoryBranchUtil returns a history branch utility | ||
func NewHistoryBranchUtil() HistoryBranchUtil { | ||
return &historyBranchUtilImpl{} | ||
} | ||
|
||
func (u *historyBranchUtilImpl) NewHistoryBranchToken(treeID string, branchID *string, ancestors []*persistencespb.HistoryBranchRange) ([]byte, error) { | ||
var id string | ||
if branchID == nil { | ||
id = primitives.NewUUID().String() | ||
} else { | ||
id = *branchID | ||
} | ||
|
||
bi := &persistencespb.HistoryBranch{ | ||
TreeId: treeID, | ||
BranchId: id, | ||
Ancestors: ancestors, | ||
} | ||
data, err := serialization.HistoryBranchToBlob(bi) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return data.Data, nil | ||
} | ||
|
||
func (u *historyBranchUtilImpl) ParseHistoryBranchInfo(branchToken []byte) (*persistencespb.HistoryBranch, error) { | ||
return serialization.HistoryBranchFromBlob(branchToken, enumspb.ENCODING_TYPE_PROTO3.String()) | ||
} | ||
|
||
func (u *historyBranchUtilImpl) UpdateHistoryBranchInfo(branchToken []byte, branchInfo *persistencespb.HistoryBranch) ([]byte, error) { | ||
bi, err := serialization.HistoryBranchFromBlob(branchToken, enumspb.ENCODING_TYPE_PROTO3.String()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
bi.TreeId = branchInfo.TreeId | ||
bi.BranchId = branchInfo.BranchId | ||
bi.Ancestors = branchInfo.Ancestors | ||
|
||
blob, err := serialization.HistoryBranchToBlob(bi) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return blob.Data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.