-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a replication.DLQWriter interface #5009
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// 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 replication | ||
|
||
import ( | ||
"context" | ||
|
||
persistencespb "go.temporal.io/server/api/persistence/v1" | ||
"go.temporal.io/server/common/persistence" | ||
"go.temporal.io/server/service/history/shard" | ||
) | ||
|
||
type ( | ||
// DLQWriter is an interface that can be implemented easily by the two different queue solutions that we have. | ||
// - Queue V1 implements this interface via [persistence.ExecutionManager]. | ||
// - Queue V2 will implement this interface via [go.temporal.io/server/service/history/queues.DLQWriter]. | ||
// | ||
// We want this interface to make the migration referenced by [persistence.QueueV2] easier. | ||
DLQWriter interface { | ||
WriteTaskToDLQ(ctx context.Context, request WriteRequest) error | ||
} | ||
// WriteRequest is a request to write a task to the DLQ. | ||
WriteRequest struct { | ||
// ShardContext is an argument that we can remove once we migrate to queue V2. | ||
ShardContext shard.Context | ||
SourceCluster string | ||
ReplicationTaskInfo *persistencespb.ReplicationTaskInfo | ||
} | ||
// ExecutionManagerDLQWriter is a [DLQWriter] that uses the shard's [persistence.ExecutionManager]. | ||
// The zero-value is a valid instance. | ||
ExecutionManagerDLQWriter struct{} | ||
) | ||
|
||
// NewExecutionManagerDLQWriter creates a new DLQWriter. | ||
func NewExecutionManagerDLQWriter() DLQWriter { | ||
return &ExecutionManagerDLQWriter{} | ||
} | ||
|
||
// WriteTaskToDLQ implements [DLQWriter.WriteTaskToDLQ] by calling [persistence.ExecutionManager.PutReplicationTaskToDLQ]. | ||
func (e *ExecutionManagerDLQWriter) WriteTaskToDLQ( | ||
ctx context.Context, | ||
request WriteRequest, | ||
) error { | ||
return request.ShardContext.GetExecutionManager().PutReplicationTaskToDLQ( | ||
ctx, &persistence.PutReplicationTaskToDLQRequest{ | ||
SourceClusterName: request.SourceCluster, | ||
ShardID: request.ShardContext.GetShardID(), | ||
TaskInfo: request.ReplicationTaskInfo, | ||
}, | ||
) | ||
} |
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,88 @@ | ||
// 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 replication_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
persistencespb "go.temporal.io/server/api/persistence/v1" | ||
"go.temporal.io/server/common/persistence" | ||
"go.temporal.io/server/service/history/replication" | ||
"go.temporal.io/server/service/history/shard" | ||
) | ||
|
||
type ( | ||
fakeShardContext struct { | ||
shard.Context | ||
requests []*persistence.PutReplicationTaskToDLQRequest | ||
shardID int | ||
} | ||
fakeExecutionManager struct { | ||
persistence.ExecutionManager | ||
requests *[]*persistence.PutReplicationTaskToDLQRequest | ||
} | ||
) | ||
|
||
func TestNewExecutionManagerDLQWriter_ReplicationTask(t *testing.T) { | ||
t.Parallel() | ||
|
||
writer := replication.NewExecutionManagerDLQWriter() | ||
shardContext := &fakeShardContext{ | ||
shardID: 13, | ||
} | ||
replicationTaskInfo := &persistencespb.ReplicationTaskInfo{ | ||
TaskId: 21, | ||
} | ||
err := writer.WriteTaskToDLQ(context.Background(), replication.WriteRequest{ | ||
ShardContext: shardContext, | ||
SourceCluster: "test-source-cluster", | ||
ReplicationTaskInfo: replicationTaskInfo, | ||
}) | ||
require.NoError(t, err) | ||
if assert.Len(t, shardContext.requests, 1) { | ||
assert.Equal(t, 13, int(shardContext.requests[0].ShardID)) | ||
assert.Equal(t, "test-source-cluster", shardContext.requests[0].SourceClusterName) | ||
assert.Equal(t, replicationTaskInfo, shardContext.requests[0].TaskInfo) | ||
} | ||
} | ||
|
||
func (f *fakeShardContext) GetShardID() int32 { | ||
return int32(f.shardID) | ||
} | ||
|
||
func (f *fakeShardContext) GetExecutionManager() persistence.ExecutionManager { | ||
return &fakeExecutionManager{requests: &f.requests} | ||
} | ||
|
||
func (f *fakeExecutionManager) PutReplicationTaskToDLQ( | ||
_ context.Context, | ||
request *persistence.PutReplicationTaskToDLQRequest, | ||
) error { | ||
*f.requests = append(*f.requests, request) | ||
return 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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it feels to me that ideally, this should be part of the DLQWriter itself, not the Request. But I understand that means DLQWriter will be a per shard component and can't be injected from the top. It will be removed in the future anyway, so not worth making the change I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly. I really hated putting this here, and it was a dependency at first. However, it didn't work because that meant it couldn't be injected, especially because the
shard.Context
isn't injected in replication. It's actually fetched from theshard.Controller
, and I can't depend on that because it creates a dependency cycle. In a subsequent PR, I made thisExecutionManager
, which is sliiightly better, but not really. It should still be part of the object, not the request. However, it's just not possible because of the dependency on shard controller, e.g. here, unless we do another lazy-loaded thing, but I think it's just too complicated since it's temporary anyway.