-
Notifications
You must be signed in to change notification settings - Fork 35
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
feat(restore): adds --dc-mapping flag to restore command #4213
Open
VAveryanov8
wants to merge
9
commits into
master
Choose a base branch
from
va/dc-mapping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e3d9b34
feat(restore): adds --dc-mapping flag to restore command
VAveryanov8 532ad04
feat(restore): uses dc mappings for restoring tables
VAveryanov8 4622a83
feat(tests): adds third cluster (dc3) to docker setup
VAveryanov8 f0229b4
chore(test): adds dc-mapping integration tests
VAveryanov8 e03889c
fix: adds copyright :D
VAveryanov8 e30e28a
fix(test): fixes cluster setup
VAveryanov8 d6eb821
refactor(dcmapping): replaces !dc with --skip-dc-mapping-validation
VAveryanov8 09fae57
refactor: deleted third, but adds dc3 to the second
VAveryanov8 a8d900c
refactor(restore): adds LocationInfo which replaces locationHosts
VAveryanov8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (C) 2025 ScyllaDB | ||
|
||
package restore | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
type dcMappings []dcMapping | ||
|
||
type dcMapping struct { | ||
Source []string `json:"source"` | ||
Target []string `json:"target"` | ||
} | ||
|
||
// Set parses --dc-mapping flag, where the syntax is following: | ||
// ; - used to split different mappings | ||
// => - used to split source => target DCs | ||
// , - used to seprate DCs. | ||
func (dcm *dcMappings) Set(v string) error { | ||
mappingParts := strings.Split(v, ";") | ||
for _, dcMapPart := range mappingParts { | ||
sourceTargetParts := strings.Split(dcMapPart, "=>") | ||
if len(sourceTargetParts) != 2 { | ||
return errors.New("invalid syntax, mapping should be in a format of sourceDcs=>targetDcs, but got: " + dcMapPart) | ||
} | ||
if sourceTargetParts[0] == "" || sourceTargetParts[1] == "" { | ||
return errors.New("invalid syntax, mapping should be in a format of sourceDcs=>targetDcs, but got: " + dcMapPart) | ||
} | ||
|
||
var mapping dcMapping | ||
mapping.Source = parseDCList(sourceTargetParts[0]) | ||
mapping.Target = parseDCList(sourceTargetParts[1]) | ||
|
||
*dcm = append(*dcm, mapping) | ||
} | ||
return nil | ||
} | ||
|
||
func parseDCList(raw string) []string { | ||
dcs := strings.Split(raw, ",") | ||
for i, dc := range dcs { | ||
dcs[i] = strings.TrimSpace(dc) | ||
} | ||
return dcs | ||
} | ||
|
||
// String builds --dc-mapping flag back from struct. | ||
func (dcm *dcMappings) String() string { | ||
if dcm == nil { | ||
return "" | ||
} | ||
var res strings.Builder | ||
for i, mapping := range *dcm { | ||
res.WriteString( | ||
strings.Join(mapping.Source, ",") + "=>" + strings.Join(mapping.Target, ","), | ||
) | ||
if i != len(*dcm)-1 { | ||
res.WriteString(";") | ||
} | ||
} | ||
return res.String() | ||
} | ||
|
||
// Type implements pflag.Value interface. | ||
func (dcm *dcMappings) Type() string { | ||
return "dc-mapping" | ||
} |
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,120 @@ | ||
// Copyright (C) 2025 ScyllaDB | ||
package restore | ||
|
||
import ( | ||
"fmt" | ||
"slices" | ||
"testing" | ||
) | ||
|
||
func TestSetDCMapping(t *testing.T) { | ||
testCases := []struct { | ||
input string | ||
expectedErr bool | ||
expectedMappings dcMappings | ||
}{ | ||
{ | ||
input: "dc1=>dc2", | ||
expectedMappings: dcMappings{ | ||
{Source: []string{"dc1"}, Target: []string{"dc2"}}, | ||
}, | ||
}, | ||
{ | ||
input: " dc1, dc2 => dc1, dc2", | ||
expectedMappings: dcMappings{ | ||
{Source: []string{"dc1", "dc2"}, Target: []string{"dc1", "dc2"}}, | ||
}, | ||
}, | ||
{ | ||
input: "dc1=>dc3;dc2=>dc4", | ||
expectedMappings: dcMappings{ | ||
{Source: []string{"dc1"}, Target: []string{"dc3"}}, | ||
{Source: []string{"dc2"}, Target: []string{"dc4"}}, | ||
}, | ||
}, | ||
{ | ||
input: "dc1,dc2=>dc3", | ||
expectedMappings: dcMappings{ | ||
{Source: []string{"dc1", "dc2"}, Target: []string{"dc3"}}, | ||
}, | ||
}, | ||
{ | ||
input: "dc1=>dc3=>dc2=>dc4", | ||
expectedMappings: dcMappings{}, | ||
expectedErr: true, | ||
}, | ||
{ | ||
input: ";", | ||
expectedMappings: dcMappings{}, | ||
expectedErr: true, | ||
}, | ||
{ | ||
input: "=>", | ||
expectedMappings: dcMappings{}, | ||
expectedErr: true, | ||
}, | ||
{ | ||
input: "dc1=>", | ||
expectedMappings: dcMappings{}, | ||
expectedErr: true, | ||
}, | ||
{ | ||
input: "dc1=>;", | ||
expectedMappings: dcMappings{}, | ||
expectedErr: true, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.input, func(t *testing.T) { | ||
var mappings dcMappings | ||
|
||
err := mappings.Set(tc.input) | ||
if tc.expectedErr && err == nil { | ||
t.Fatal("Expected err, but got nil") | ||
} | ||
if !tc.expectedErr && err != nil { | ||
t.Fatalf("Unexpected err: %v", err) | ||
} | ||
equal := slices.EqualFunc(tc.expectedMappings, mappings, func(a, b dcMapping) bool { | ||
return slices.Equal(a.Source, b.Source) && | ||
slices.Equal(a.Target, b.Target) | ||
}) | ||
if !equal { | ||
t.Fatalf("Expected %v, but got %v", tc.expectedMappings, mappings) | ||
} | ||
}) | ||
} | ||
|
||
} | ||
|
||
func TestDCMappingString(t *testing.T) { | ||
testCases := []struct { | ||
mappings dcMappings | ||
expected string | ||
}{ | ||
{ | ||
mappings: dcMappings{ | ||
{Source: []string{"dc1"}, Target: []string{"dc2"}}, | ||
}, | ||
expected: "dc1=>dc2", | ||
}, | ||
{ | ||
mappings: dcMappings{ | ||
{Source: []string{"dc1"}, Target: []string{"dc2"}}, | ||
{Source: []string{"dc3"}, Target: []string{"dc4"}}, | ||
}, | ||
expected: "dc1=>dc2;dc3=>dc4", | ||
}, | ||
{}, | ||
} | ||
|
||
for i, tc := range testCases { | ||
t.Run(fmt.Sprintf("case %d", i), func(t *testing.T) { | ||
actual := tc.mappings.String() | ||
if actual != tc.expected { | ||
t.Fatalf("Expected %q, but got %q", tc.expected, actual) | ||
} | ||
}) | ||
} | ||
} |
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.
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.
The sctool command docs are actually also a part of the regular SM docs.
In order to include those changes in the docs, you should run
make docs
from repo root dir. In order to see how the changes were rendered, you can run
make -C docs preview(or just
make previewfrom
docs` dir).