This repository has been archived by the owner on Dec 16, 2022. It is now read-only.
forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request vitessio#8321 from tinyspeck/am_additional_backup_…
…info [vtctldserver] Add additional backup info fields
- Loading branch information
Showing
16 changed files
with
1,693 additions
and
428 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Copyright 2021 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 protoutil | ||
|
||
import ( | ||
"time" | ||
|
||
"vitess.io/vitess/go/vt/proto/vttime" | ||
) | ||
|
||
// TimeFromProto converts a vttime.Time proto message into a time.Time object. | ||
func TimeFromProto(tpb *vttime.Time) time.Time { | ||
if tpb == nil { | ||
return time.Time{} | ||
} | ||
|
||
return time.Unix(tpb.Seconds, int64(tpb.Nanoseconds)) | ||
} | ||
|
||
// TimeToProto converts a time.Time object into a vttime.Time proto mesasge. | ||
func TimeToProto(t time.Time) *vttime.Time { | ||
secs, nanos := t.Unix(), t.UnixNano() | ||
|
||
nsecs := secs * 1e9 | ||
extraNanos := nanos - nsecs | ||
return &vttime.Time{ | ||
Seconds: secs, | ||
Nanoseconds: int32(extraNanos), | ||
} | ||
} |
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,52 @@ | ||
/* | ||
Copyright 2021 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 protoutil | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"vitess.io/vitess/go/test/utils" | ||
"vitess.io/vitess/go/vt/proto/vttime" | ||
) | ||
|
||
func TestTimeFromProto(t *testing.T) { | ||
now := time.Date(2021, time.June, 12, 13, 14, 15, 0 /* nanos */, time.UTC) | ||
vtt := TimeToProto(now) | ||
|
||
utils.MustMatch(t, now, TimeFromProto(vtt)) | ||
|
||
vtt.Nanoseconds = 100 | ||
utils.MustMatch(t, now.Add(100*time.Nanosecond), TimeFromProto(vtt)) | ||
|
||
vtt.Nanoseconds = 1e9 | ||
utils.MustMatch(t, now.Add(time.Second), TimeFromProto(vtt)) | ||
|
||
assert.True(t, TimeFromProto(nil).IsZero(), "expected Go time from nil vttime to be Zero") | ||
} | ||
|
||
func TestTimeToProto(t *testing.T) { | ||
now := time.Date(2021, time.June, 12, 13, 14, 15, 0 /* nanos */, time.UTC) | ||
secs := now.Unix() | ||
utils.MustMatch(t, &vttime.Time{Seconds: secs}, TimeToProto(now)) | ||
|
||
// Testing secs/nanos conversions | ||
utils.MustMatch(t, &vttime.Time{Seconds: secs, Nanoseconds: 100}, TimeToProto(now.Add(100*time.Nanosecond))) | ||
utils.MustMatch(t, &vttime.Time{Seconds: secs + 1}, TimeToProto(now.Add(1e9*time.Nanosecond))) // this should rollover to a full second | ||
} |
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,114 @@ | ||
/* | ||
Copyright 2021 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 mysqlctlproto | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
"time" | ||
|
||
"vitess.io/vitess/go/protoutil" | ||
"vitess.io/vitess/go/test/utils" | ||
"vitess.io/vitess/go/vt/mysqlctl/backupstorage" | ||
|
||
mysqlctlpb "vitess.io/vitess/go/vt/proto/mysqlctl" | ||
topodatapb "vitess.io/vitess/go/vt/proto/topodata" | ||
) | ||
|
||
type backupHandle struct { | ||
backupstorage.BackupHandle | ||
name string | ||
directory string | ||
} | ||
|
||
func (bh *backupHandle) Name() string { return bh.name } | ||
func (bh *backupHandle) Directory() string { return bh.directory } | ||
func (bh *backupHandle) testname() string { return path.Join(bh.directory, bh.name) } | ||
|
||
func TestBackupHandleToProto(t *testing.T) { | ||
t.Parallel() | ||
|
||
now := time.Date(2021, time.June, 12, 15, 4, 5, 0, time.UTC) | ||
tests := []struct { | ||
bh *backupHandle | ||
want *mysqlctlpb.BackupInfo | ||
}{ | ||
{ | ||
bh: &backupHandle{ | ||
name: "2021-06-12.150405.zone1-100", | ||
directory: "foo", | ||
}, | ||
want: &mysqlctlpb.BackupInfo{ | ||
Name: "2021-06-12.150405.zone1-100", | ||
Directory: "foo", | ||
TabletAlias: &topodatapb.TabletAlias{ | ||
Cell: "zone1", | ||
Uid: 100, | ||
}, | ||
Time: protoutil.TimeToProto(now), | ||
}, | ||
}, | ||
{ | ||
bh: &backupHandle{ | ||
name: "bar", | ||
directory: "foo", | ||
}, | ||
want: &mysqlctlpb.BackupInfo{ | ||
Name: "bar", | ||
Directory: "foo", | ||
}, | ||
}, | ||
{ | ||
bh: &backupHandle{ | ||
name: "invalid.time.zone1-100", | ||
directory: "foo", | ||
}, | ||
want: &mysqlctlpb.BackupInfo{ | ||
Name: "invalid.time.zone1-100", | ||
Directory: "foo", | ||
TabletAlias: &topodatapb.TabletAlias{ | ||
Cell: "zone1", | ||
Uid: 100, | ||
}, | ||
Time: nil, | ||
}, | ||
}, | ||
{ | ||
bh: &backupHandle{ | ||
name: "2021-06-12.150405.not_an_alias", | ||
directory: "foo", | ||
}, | ||
want: &mysqlctlpb.BackupInfo{ | ||
Name: "2021-06-12.150405.not_an_alias", | ||
Directory: "foo", | ||
TabletAlias: nil, | ||
Time: protoutil.TimeToProto(now), | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
tt := tt | ||
|
||
t.Run(tt.bh.testname(), func(t *testing.T) { | ||
t.Parallel() | ||
|
||
got := BackupHandleToProto(tt.bh) | ||
utils.MustMatch(t, tt.want, got) | ||
}) | ||
} | ||
} |
Oops, something went wrong.