-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow metadata to keyspace topo object. Save it currently only…
… for movetables and use the cached information, if available, to only contact primaries of participating shards for all workflow commands Signed-off-by: Rohit Nayak <[email protected]>
- Loading branch information
1 parent
f4b8361
commit 69527e5
Showing
11 changed files
with
1,489 additions
and
417 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,98 @@ | ||
/* | ||
Copyright 2023 The Vitess Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package topo | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"vitess.io/vitess/go/vt/proto/topodata" | ||
"vitess.io/vitess/go/vt/proto/vtrpc" | ||
"vitess.io/vitess/go/vt/vterrors" | ||
) | ||
|
||
func (ts *Server) SaveWorkflowMetadata(ctx context.Context, targetKeyspace string, wm *topodata.WorkflowMetadata) (err error) { | ||
ctx, unlock, lockErr := ts.LockKeyspace(ctx, targetKeyspace, "GetWorkflowMetadata") | ||
if lockErr != nil { | ||
err = lockErr | ||
return err | ||
} | ||
defer unlock(&err) | ||
|
||
ki, err := ts.GetKeyspace(ctx, targetKeyspace) | ||
for _, w := range ki.Workflows { | ||
if w.Name == wm.Name { | ||
return vterrors.New(vtrpc.Code_ALREADY_EXISTS, | ||
fmt.Sprintf("workflow %s already exists in %s", w.Name, ki.KeyspaceName())) | ||
} | ||
} | ||
ki.Workflows = append(ki.Workflows, &topodata.WorkflowMetadata{ | ||
Name: wm.Name, | ||
Type: wm.Type, | ||
TargetShards: wm.TargetShards, | ||
SourceKeyspace: wm.SourceKeyspace, | ||
SourceShards: wm.SourceShards, | ||
}) | ||
if err := ts.UpdateKeyspace(ctx, ki); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
func (ts *Server) DeleteWorkflowMetadata(ctx context.Context, targetKeyspace, workflowName string) (err error) { | ||
ctx, unlock, lockErr := ts.LockKeyspace(ctx, targetKeyspace, "GetWorkflowMetadata") | ||
if lockErr != nil { | ||
err = lockErr | ||
return err | ||
} | ||
defer unlock(&err) | ||
|
||
ki, err := ts.GetKeyspace(ctx, targetKeyspace) | ||
if err != nil { | ||
return err | ||
} | ||
for i, w := range ki.Workflows { | ||
if w.Name == workflowName { | ||
ki.Workflows = append(ki.Workflows[:i], ki.Workflows[i+1:]...) | ||
if err := ts.UpdateKeyspace(ctx, ki); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (ts *Server) GetWorkflowMetadata(ctx context.Context, targetKeyspace, workflowName string) (wm *topodata.WorkflowMetadata, err error) { | ||
ctx, unlock, lockErr := ts.LockKeyspace(ctx, targetKeyspace, "GetWorkflowMetadata") | ||
if lockErr != nil { | ||
err = lockErr | ||
return nil, err | ||
} | ||
defer unlock(&err) | ||
|
||
ki, err := ts.GetKeyspace(ctx, targetKeyspace) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, w := range ki.Workflows { | ||
if w.Name == workflowName { | ||
return w, nil | ||
} | ||
} | ||
return nil, nil | ||
} |
This file was deleted.
Oops, something went wrong.
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.