Skip to content

Commit

Permalink
Revert version, add better pre-processing interface
Browse files Browse the repository at this point in the history
  • Loading branch information
radekg committed Dec 10, 2021
1 parent a044cb1 commit 7818b57
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1-alpha.9
0.0.1-alpha.8
3 changes: 2 additions & 1 deletion client/implementation/cli_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ type YBCliClient interface {
SnapshotsDeleteSchedule(*configs.OpSnapshotDeleteScheduleConfig) (*ybApi.DeleteSnapshotScheduleResponsePB, error)
SnapshotsDelete(*configs.OpSnapshotDeleteConfig) (*ybApi.DeleteSnapshotResponsePB, error)
SnapshotsExport(*configs.OpSnapshotExportConfig) (*SnapshotExportData, error)
PreProcessSnapshotsImport(*configs.OpSnapshotImportConfig) (*ybApi.ImportSnapshotMetaRequestPB, error)
PreProcessSnapshotsImportFromBytes(*configs.OpSnapshotImportConfig, []byte) (*ybApi.ImportSnapshotMetaRequestPB, error)
PreProcessSnapshotsImportFromFile(*configs.OpSnapshotImportConfig) (*ybApi.ImportSnapshotMetaRequestPB, error)
SnapshotsImport(*configs.OpSnapshotImportConfig) (*ybApi.ImportSnapshotMetaResponsePB, error)
SnapshotsListSchedules(*configs.OpSnapshotListSchedulesConfig) (*ybApi.ListSnapshotSchedulesResponsePB, error)
SnapshotsListRestorations(*configs.OpSnapshotListRestorationsConfig) (*ybApi.ListSnapshotRestorationsResponsePB, error)
Expand Down
37 changes: 21 additions & 16 deletions client/implementation/op_snapshots_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (tn *ybTableName) hasTable() bool {
return tn.TableName != ""
}

// Pre-process snapshot import metadata file.
func (c *defaultYBCliClient) PreProcessSnapshotsImport(opConfig *configs.OpSnapshotImportConfig) (*ybApi.ImportSnapshotMetaRequestPB, error) {
// Pre-process snapshot import metadata file from input bytes.
func (c *defaultYBCliClient) PreProcessSnapshotsImportFromBytes(opConfig *configs.OpSnapshotImportConfig, rawProtoBytes []byte) (*ybApi.ImportSnapshotMetaRequestPB, error) {

givenKeyspace := ""
if opConfig.Keyspace != "" {
Expand All @@ -57,19 +57,6 @@ func (c *defaultYBCliClient) PreProcessSnapshotsImport(opConfig *configs.OpSnaps
tables = append(tables, newYBTableName(opConfig.Keyspace, tableName))
}

statResult, err := os.Stat(opConfig.FilePath)
if err != nil {
return nil, err
}
if statResult.IsDir() {
return nil, fmt.Errorf("path %s points at a directory", opConfig.FilePath)
}

rawProtoBytes, err := ioutil.ReadFile(opConfig.FilePath)
if err != nil {
return nil, err
}

snapshotInfo := &ybApi.SnapshotInfoPB{}
if err := utils.DeserializeProto(rawProtoBytes, snapshotInfo); err != nil {
return nil, err
Expand Down Expand Up @@ -169,10 +156,28 @@ func (c *defaultYBCliClient) PreProcessSnapshotsImport(opConfig *configs.OpSnaps

}

// Pre-process snapshot import metadata file.
func (c *defaultYBCliClient) PreProcessSnapshotsImportFromFile(opConfig *configs.OpSnapshotImportConfig) (*ybApi.ImportSnapshotMetaRequestPB, error) {
statResult, err := os.Stat(opConfig.FilePath)
if err != nil {
return nil, err
}
if statResult.IsDir() {
return nil, fmt.Errorf("path %s points at a directory", opConfig.FilePath)
}

rawProtoBytes, err := ioutil.ReadFile(opConfig.FilePath)
if err != nil {
return nil, err
}

return c.PreProcessSnapshotsImportFromBytes(opConfig, rawProtoBytes)
}

// Import snapshot.
func (c *defaultYBCliClient) SnapshotsImport(opConfig *configs.OpSnapshotImportConfig) (*ybApi.ImportSnapshotMetaResponsePB, error) {

payload, err := c.PreProcessSnapshotsImport(opConfig)
payload, err := c.PreProcessSnapshotsImportFromFile(opConfig)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 7818b57

Please sign in to comment.