-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a replication.DLQWriter interface
- Loading branch information
1 parent
5809a24
commit 10c3ca5
Showing
22 changed files
with
267 additions
and
96 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
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 [shard.Context] and [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 | ||
} | ||
// ShardContextDLQWriter is a [DLQWriter] that uses a [shard.Context]. | ||
// The zero-value is a valid instance. | ||
ShardContextDLQWriter struct{} | ||
) | ||
|
||
// NewShardContextDLQWriter creates a new DLQWriter. | ||
func NewShardContextDLQWriter() DLQWriter { | ||
return &ShardContextDLQWriter{} | ||
} | ||
|
||
// WriteTaskToDLQ implements [DLQWriter.WriteTaskToDLQ] by calling [persistence.ExecutionManager.PutReplicationTaskToDLQ]. | ||
func (e *ShardContextDLQWriter) 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.NewShardContextDLQWriter() | ||
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.