Skip to content

Commit

Permalink
Introduce service engine implementation for history branch operations
Browse files Browse the repository at this point in the history
For the following soon to be introduced history branch related RPC:
- ReadHistoryBranch
- ReadHistoryBranchReverse
- ReadRawHistoryBranch
- TrimHistoryBranch
- DeleteHistoryBranch
  • Loading branch information
norberthu committed May 2, 2023
1 parent 1617015 commit f261029
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 0 deletions.
48 changes: 48 additions & 0 deletions service/history/api/deletehistorybranch/api.go
@@ -0,0 +1,48 @@
// 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 deletehistorybranch

import (
"context"

"go.temporal.io/server/api/historyservice/v1"
"go.temporal.io/server/common/persistence"
"go.temporal.io/server/service/history/shard"
)

func Invoke(
ctx context.Context,
req *historyservice.DeleteHistoryBranchRequest,
shardCtx shard.Context,
) (_ *historyservice.DeleteHistoryBranchResponse, retErr error) {
err := shardCtx.GetExecutionManager().DeleteHistoryBranch(ctx, &persistence.DeleteHistoryBranchRequest{
ShardID: req.ShardId,
BranchToken: req.BranchToken,
})
if err != nil {
return nil, err
}
return &historyservice.DeleteHistoryBranchResponse{}, nil
}
56 changes: 56 additions & 0 deletions service/history/api/readhistorybranch/api.go
@@ -0,0 +1,56 @@
// 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 readhistorybranch

import (
"context"

"go.temporal.io/server/api/historyservice/v1"
"go.temporal.io/server/common/persistence"
"go.temporal.io/server/service/history/shard"
)

func Invoke(
ctx context.Context,
req *historyservice.ReadHistoryBranchRequest,
shardCtx shard.Context,
) (_ *historyservice.ReadHistoryBranchResponse, retErr error) {
res, err := shardCtx.GetExecutionManager().ReadHistoryBranch(ctx, &persistence.ReadHistoryBranchRequest{
ShardID: req.ShardId,
BranchToken: req.BranchToken,
MinEventID: req.MinEventId,
MaxEventID: req.MaxEventId,
PageSize: int(req.PageSize),
NextPageToken: req.NextPageToken,
})
if err != nil {
return nil, err
}
return &historyservice.ReadHistoryBranchResponse{
HistoryEvents: res.HistoryEvents,
NextPageToken: res.NextPageToken,
Size_: int64(res.Size), // total byte size across all retrieved history events
}, nil
}
56 changes: 56 additions & 0 deletions service/history/api/readhistorybranchreverse/api.go
@@ -0,0 +1,56 @@
// 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 readhistorybranchreverse

import (
"context"

"go.temporal.io/server/api/historyservice/v1"
"go.temporal.io/server/common/persistence"
"go.temporal.io/server/service/history/shard"
)

func Invoke(
ctx context.Context,
req *historyservice.ReadHistoryBranchReverseRequest,
shardCtx shard.Context,
) (_ *historyservice.ReadHistoryBranchReverseResponse, retErr error) {
res, err := shardCtx.GetExecutionManager().ReadHistoryBranchReverse(ctx, &persistence.ReadHistoryBranchReverseRequest{
ShardID: req.ShardId,
BranchToken: req.BranchToken,
MaxEventID: req.MaxEventId,
PageSize: int(req.PageSize),
LastFirstTransactionID: req.LastFirstTransactionId, // transaction id for the original write
NextPageToken: req.NextPageToken,
})
if err != nil {
return nil, err
}
return &historyservice.ReadHistoryBranchReverseResponse{
HistoryEvents: res.HistoryEvents,
NextPageToken: res.NextPageToken,
Size_: int64(res.Size), // total byte size across all retrieved history events
}, nil
}
65 changes: 65 additions & 0 deletions service/history/api/readrawhistorybranch/api.go
@@ -0,0 +1,65 @@
// 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 readrawhistorybranch

import (
"context"

"go.temporal.io/api/common/v1"
"go.temporal.io/server/api/historyservice/v1"
"go.temporal.io/server/common/persistence"
"go.temporal.io/server/service/history/shard"
)

func Invoke(
ctx context.Context,
req *historyservice.ReadRawHistoryBranchRequest,
shardCtx shard.Context,
) (_ *historyservice.ReadRawHistoryBranchResponse, retErr error) {
res, err := shardCtx.GetExecutionManager().ReadRawHistoryBranch(ctx, &persistence.ReadHistoryBranchRequest{
ShardID: req.ShardId,
BranchToken: req.BranchToken,
MinEventID: req.MinEventId,
MaxEventID: req.MaxEventId,
PageSize: int(req.PageSize),
NextPageToken: req.NextPageToken,
})
if err != nil {
return nil, err
}
var blobs []*common.DataBlob
for _, blob := range res.HistoryEventBlobs {
blobs = append(blobs, &common.DataBlob{
EncodingType: blob.EncodingType,
Data: blob.Data,
})
}
return &historyservice.ReadRawHistoryBranchResponse{
HistoryEventBlobs: blobs,
NodeIds: res.NodeIDs,
NextPageToken: res.NextPageToken,
Size_: int64(res.Size), // total byte size across all retrieved history events
}, nil
}
50 changes: 50 additions & 0 deletions service/history/api/trimhistorybranch/api.go
@@ -0,0 +1,50 @@
// 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 trimhistorybranch

import (
"context"

"go.temporal.io/server/api/historyservice/v1"
"go.temporal.io/server/common/persistence"
"go.temporal.io/server/service/history/shard"
)

func Invoke(
ctx context.Context,
req *historyservice.TrimHistoryBranchRequest,
shardCtx shard.Context,
) (_ *historyservice.TrimHistoryBranchResponse, retErr error) {
_, err := shardCtx.GetExecutionManager().TrimHistoryBranch(ctx, &persistence.TrimHistoryBranchRequest{
ShardID: req.ShardId,
BranchToken: req.BranchToken,
NodeID: req.NodeId,
TransactionID: req.TransactionId,
})
if err != nil {
return nil, err
}
return &historyservice.TrimHistoryBranchResponse{}, nil
}
40 changes: 40 additions & 0 deletions service/history/historyEngine.go
Expand Up @@ -54,10 +54,14 @@ import (
"go.temporal.io/server/common/sdk"
"go.temporal.io/server/common/searchattribute"
"go.temporal.io/server/service/history/api"
"go.temporal.io/server/service/history/api/deletehistorybranch"
"go.temporal.io/server/service/history/api/deleteworkflow"
"go.temporal.io/server/service/history/api/describemutablestate"
"go.temporal.io/server/service/history/api/describeworkflow"
"go.temporal.io/server/service/history/api/queryworkflow"
"go.temporal.io/server/service/history/api/readhistorybranch"
"go.temporal.io/server/service/history/api/readhistorybranchreverse"
"go.temporal.io/server/service/history/api/readrawhistorybranch"
"go.temporal.io/server/service/history/api/reapplyevents"
"go.temporal.io/server/service/history/api/recordactivitytaskheartbeat"
"go.temporal.io/server/service/history/api/recordactivitytaskstarted"
Expand All @@ -76,6 +80,7 @@ import (
"go.temporal.io/server/service/history/api/signalworkflow"
"go.temporal.io/server/service/history/api/startworkflow"
"go.temporal.io/server/service/history/api/terminateworkflow"
"go.temporal.io/server/service/history/api/trimhistorybranch"
"go.temporal.io/server/service/history/api/updateworkflow"
"go.temporal.io/server/service/history/api/verifychildworkflowcompletionrecorded"
"go.temporal.io/server/service/history/configs"
Expand Down Expand Up @@ -773,3 +778,38 @@ func (e *historyEngineImpl) GetReplicationStatus(
) (_ *historyservice.ShardReplicationStatus, retError error) {
return replicationapi.GetStatus(ctx, request, e.shard, e.replicationAckMgr)
}

func (e *historyEngineImpl) ReadHistoryBranch(
ctx context.Context,
request *historyservice.ReadHistoryBranchRequest,
) (_ *historyservice.ReadHistoryBranchResponse, retError error) {
return readhistorybranch.Invoke(ctx, request, e.shard)
}

func (e *historyEngineImpl) ReadHistoryBranchReverse(
ctx context.Context,
request *historyservice.ReadHistoryBranchReverseRequest,
) (_ *historyservice.ReadHistoryBranchReverseResponse, retError error) {
return readhistorybranchreverse.Invoke(ctx, request, e.shard)
}

func (e *historyEngineImpl) ReadRawHistoryBranch(
ctx context.Context,
request *historyservice.ReadRawHistoryBranchRequest,
) (_ *historyservice.ReadRawHistoryBranchResponse, retError error) {
return readrawhistorybranch.Invoke(ctx, request, e.shard)
}

func (e *historyEngineImpl) TrimHistoryBranch(
ctx context.Context,
request *historyservice.TrimHistoryBranchRequest,
) (_ *historyservice.TrimHistoryBranchResponse, retError error) {
return trimhistorybranch.Invoke(ctx, request, e.shard)
}

func (e *historyEngineImpl) DeleteHistoryBranch(
ctx context.Context,
request *historyservice.DeleteHistoryBranchRequest,
) (_ *historyservice.DeleteHistoryBranchResponse, retError error) {
return deletehistorybranch.Invoke(ctx, request, e.shard)
}

0 comments on commit f261029

Please sign in to comment.