-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
e3d9b34
532ad04
4622a83
f0229b4
e03889c
e30e28a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import ( | |
|
||
"github.com/gocql/gocql" | ||
"github.com/pkg/errors" | ||
"github.com/scylladb/go-set/strset" | ||
"github.com/scylladb/gocqlx/v2" | ||
"github.com/scylladb/scylla-manager/v3/pkg/scyllaclient" | ||
"github.com/scylladb/scylla-manager/v3/pkg/service/repair" | ||
|
@@ -33,9 +34,14 @@ type Target struct { | |
RestoreSchema bool `json:"restore_schema,omitempty"` | ||
RestoreTables bool `json:"restore_tables,omitempty"` | ||
Continue bool `json:"continue"` | ||
DCMappings DCMappings `json:"dc-mapping"` | ||
|
||
// Cache for host with access to remote location | ||
locationHosts map[Location][]string `json:"-"` | ||
// Cache for host and their DC after applying DCMappings | ||
hostDCs map[string][]string | ||
// Cache for dcs that shouldn't be restored from location | ||
ignoredSourceDC []string | ||
Comment on lines
+37
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be way simpler if we just had a single mapping The assumption is that we don't need to care for cases like: what if only a few hosts from this DC have access to this location. Even when making backup, the whole DC needs to be backed up to a single location and all hosts from given DC needs to have access to it. |
||
} | ||
|
||
const ( | ||
|
@@ -82,6 +88,16 @@ func (t Target) validateProperties(dcMap map[string][]string) error { | |
if t.RestoreSchema && t.Keyspace != nil { | ||
return errors.New("restore schema always restores 'system_schema.*' tables only, no need to specify '--keyspace' flag") | ||
} | ||
// Check for duplicates in Location | ||
allLocations := strset.New() | ||
for _, l := range t.Location { | ||
p := l.RemotePath("") | ||
if allLocations.Has(p) { | ||
return errors.Errorf("location %s is specified multiple times", l) | ||
} | ||
allLocations.Add(p) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -289,3 +305,42 @@ type HostInfo struct { | |
Transfers int | ||
RateLimit int | ||
} | ||
|
||
// DCMappings represents how DCs from the backup cluster are mapped to DCs in the restore cluster. | ||
// For details about how DCs can be mapped refer to --dc-mapping documentation. | ||
type DCMappings []DCMapping | ||
|
||
// DCMapping represent single instance of datacenter mappings. See DCMappings for details. | ||
type DCMapping struct { | ||
Source []string `json:"source"` | ||
IgnoreSource []string `json:"ignore_source"` | ||
Target []string `json:"target"` | ||
IgnoreTarget []string `json:"ignore_target"` | ||
} | ||
|
||
func (mappings DCMappings) calculateMappings() (targetMap map[string][]string, ignoreSource, ignoreTarget []string) { | ||
targetMap = map[string][]string{} | ||
for _, mapping := range mappings { | ||
ignoreSource = append(ignoreSource, mapping.IgnoreSource...) | ||
ignoreTarget = append(ignoreTarget, mapping.IgnoreTarget...) | ||
|
||
if len(mapping.Source) == 0 || len(mapping.Target) == 0 { | ||
continue | ||
} | ||
tIdx, sIdx := 0, 0 | ||
for { | ||
target, source := mapping.Target[tIdx], mapping.Source[sIdx] | ||
targetMap[target] = append(targetMap[target], source) | ||
if tIdx == len(mapping.Target)-1 && sIdx == len(mapping.Source)-1 { | ||
break | ||
} | ||
if tIdx < len(mapping.Target)-1 { | ||
tIdx++ | ||
} | ||
if sIdx < len(mapping.Source)-1 { | ||
sIdx++ | ||
} | ||
} | ||
} | ||
return targetMap, ignoreSource, ignoreTarget | ||
} |
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.
I don't think that we should just make an intersection here.
If someone specified that given DC should be restored by given DC, then all hosts from this DC should have access to the appropriate location. This should be done inside the
GetTarget
initial validation.