Skip to content
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

Ut conflict resolver #806

Merged
merged 9 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/logging/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const (
TagOffset = "offset"
TagScope = "scope"
TagFailover = "failover"
TagVersion = "version"
TagFirstEventID = "first-event-id"
TagNextEventID = "next-event-id"

// workflow logging tag values
// TagWorkflowComponent Values
Expand All @@ -63,6 +66,7 @@ const (
TagValueMatchingEngineComponent = "matching-engine"
TagValueReplicatorComponent = "replicator"
TagValueReplicationTaskProcessorComponent = "replication-task-processor"
TagValueHistoryReplicatorComponent = "history-replicator"

// TagHistoryBuilderAction values
TagValueActionWorkflowStarted = "add-workflowexecution-started-event"
Expand Down
18 changes: 12 additions & 6 deletions service/history/conflictResolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ package history
import (
"time"

"github.com/pborman/uuid"
"github.com/uber-common/bark"
"github.com/uber/cadence/.gen/go/shared"
"github.com/uber/cadence/common"
"github.com/uber/cadence/common/cluster"
"github.com/uber/cadence/common/persistence"
)

type (
conflictResolver struct {
shard ShardContext
clusterMetadata cluster.Metadata
context *workflowExecutionContext
historyMgr persistence.HistoryManager
hSerializerFactory persistence.HistorySerializerFactory
Expand All @@ -45,14 +46,15 @@ func newConflictResolver(shard ShardContext, context *workflowExecutionContext,

return &conflictResolver{
shard: shard,
clusterMetadata: shard.GetService().GetClusterMetadata(),
context: context,
historyMgr: historyMgr,
hSerializerFactory: persistence.NewHistorySerializerFactory(),
logger: logger,
}
}

func (r *conflictResolver) reset(replayEventID int64, startTime time.Time) (*mutableStateBuilder, error) {
func (r *conflictResolver) reset(requestID string, replayEventID int64, startTime time.Time) (*mutableStateBuilder, error) {
domainID := r.context.domainID
execution := r.context.workflowExecution
replayNextEventID := replayEventID + 1
Expand All @@ -62,8 +64,8 @@ func (r *conflictResolver) reset(replayEventID int64, startTime time.Time) (*mut
var resetMutableStateBuilder *mutableStateBuilder
var sBuilder *stateBuilder
var lastFirstEventID int64
var lastEvent *shared.HistoryEvent
eventsToApply := replayNextEventID - common.FirstEventID
requestID := uuid.New()
for hasMore := true; hasMore; hasMore = len(nextPageToken) > 0 {
history, nextPageToken, lastFirstEventID, err = r.getHistory(domainID, execution, common.FirstEventID,
replayNextEventID, nextPageToken)
Expand All @@ -80,21 +82,22 @@ func (r *conflictResolver) reset(replayEventID int64, startTime time.Time) (*mut
history.Events = history.Events[0:eventsToApply]
}

eventsToApply -= batchSize
eventsToApply -= int64(len(history.Events))

if len(history.Events) == 0 {
break
}

firstEvent := history.Events[0]
lastEvent = history.Events[len(history.Events)-1]
if firstEvent.GetEventId() == common.FirstEventID {
resetMutableStateBuilder = newMutableStateBuilderWithReplicationState(r.shard.GetConfig(), r.logger,
firstEvent.GetVersion())

sBuilder = newStateBuilder(r.shard, resetMutableStateBuilder, r.logger)
}

_, _, _, err = sBuilder.applyEvents(common.EmptyVersion, "", domainID, requestID, execution, history, nil)
_, _, _, err = sBuilder.applyEvents(domainID, requestID, execution, history, nil)
if err != nil {
return nil, err
}
Expand All @@ -107,6 +110,9 @@ func (r *conflictResolver) reset(replayEventID int64, startTime time.Time) (*mut
// the last updated time is not important here, since this should be updated with event time afterwards
resetMutableStateBuilder.executionInfo.LastUpdatedTimestamp = startTime

sourceCluster := r.clusterMetadata.ClusterNameForFailoverVersion(resetMutableStateBuilder.GetCurrentVersion())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should read the version from last event rather than rely on CurrentVersion.

resetMutableStateBuilder.updateReplicationStateLastEventID(sourceCluster, lastEvent.GetVersion(), replayEventID)

r.logger.Infof("All events applied for execution. WorkflowID: %v, RunID: %v, NextEventID: %v",
execution.GetWorkflowId(), execution.GetRunId(), resetMutableStateBuilder.GetNextEventID())

Expand Down Expand Up @@ -146,5 +152,5 @@ func (r *conflictResolver) getHistory(domainID string, execution shared.Workflow

executionHistory := &shared.History{}
executionHistory.Events = historyEvents
return executionHistory, nextPageToken, lastFirstEventID, nil
return executionHistory, response.NextPageToken, lastFirstEventID, nil
}
Loading