diff --git a/go/cmd/vtctldclient/cli/awk.go b/go/cmd/vtctldclient/cli/awk.go index c68b0fc0627..2916034a3ca 100644 --- a/go/cmd/vtctldclient/cli/awk.go +++ b/go/cmd/vtctldclient/cli/awk.go @@ -22,7 +22,7 @@ import ( "strings" "time" - "vitess.io/vitess/go/vt/logutil" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/topoproto" @@ -66,7 +66,7 @@ func MarshalTabletAWK(t *topodatapb.Tablet) string { // special case for old primary that hasn't been updated in the topo // yet. if t.PrimaryTermStartTime != nil && t.PrimaryTermStartTime.Seconds > 0 { - mtst = logutil.ProtoToTime(t.PrimaryTermStartTime).Format(time.RFC3339) + mtst = protoutil.TimeFromProto(t.PrimaryTermStartTime).UTC().Format(time.RFC3339) } return fmt.Sprintf("%v %v %v %v %v %v %v %v", topoproto.TabletAliasString(t.Alias), keyspace, shard, topoproto.TabletTypeLString(t.Type), ti.Addr(), ti.MysqlAddr(), MarshalMapAWK(t.Tags), mtst) diff --git a/go/cmd/vtctldclient/command/backups.go b/go/cmd/vtctldclient/command/backups.go index f0c30a5f8f9..e6314ed7d6e 100644 --- a/go/cmd/vtctldclient/command/backups.go +++ b/go/cmd/vtctldclient/command/backups.go @@ -26,7 +26,6 @@ import ( "vitess.io/vitess/go/cmd/vtctldclient/cli" "vitess.io/vitess/go/protoutil" - "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/mysqlctl" "vitess.io/vitess/go/vt/topo/topoproto" @@ -246,7 +245,7 @@ func commandRestoreFromBackup(cmd *cobra.Command, args []string) error { req := &vtctldatapb.RestoreFromBackupRequest{ TabletAlias: alias, RestoreToPos: restoreFromBackupOptions.RestoreToPos, - RestoreToTimestamp: logutil.TimeToProto(restoreToTimestamp), + RestoreToTimestamp: protoutil.TimeToProto(restoreToTimestamp), DryRun: restoreFromBackupOptions.DryRun, } diff --git a/go/cmd/vtctldclient/command/keyspaces.go b/go/cmd/vtctldclient/command/keyspaces.go index 8b98e661fb6..420c274ddd5 100644 --- a/go/cmd/vtctldclient/command/keyspaces.go +++ b/go/cmd/vtctldclient/command/keyspaces.go @@ -25,11 +25,11 @@ import ( "github.com/spf13/cobra" "vitess.io/vitess/go/mysql/sqlerror" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/cmd/vtctldclient/cli" "vitess.io/vitess/go/constants/sidecar" "vitess.io/vitess/go/mysql" - "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/topo" topodatapb "vitess.io/vitess/go/vt/proto/topodata" @@ -178,7 +178,7 @@ func commandCreateKeyspace(cmd *cobra.Command, args []string) error { return fmt.Errorf("--snapshot-time cannot be in the future; snapshot = %v, now = %v", t, now) } - snapshotTime = logutil.TimeToProto(t) + snapshotTime = protoutil.TimeToProto(t) } createKeyspaceOptions.SidecarDBName = strings.TrimSpace(createKeyspaceOptions.SidecarDBName) diff --git a/go/cmd/vtctldclient/command/throttler.go b/go/cmd/vtctldclient/command/throttler.go index 2276ba37d62..9783f76720d 100644 --- a/go/cmd/vtctldclient/command/throttler.go +++ b/go/cmd/vtctldclient/command/throttler.go @@ -23,8 +23,8 @@ import ( "github.com/spf13/cobra" "vitess.io/vitess/go/cmd/vtctldclient/cli" + "vitess.io/vitess/go/protoutil" - "vitess.io/vitess/go/vt/logutil" topodatapb "vitess.io/vitess/go/vt/proto/topodata" vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle" @@ -60,10 +60,10 @@ func commandUpdateThrottlerConfig(cmd *cobra.Command, args []string) error { updateThrottlerConfigOptions.Keyspace = keyspace if throttledAppRule.Name != "" { - throttledAppRule.ExpiresAt = logutil.TimeToProto(time.Now().Add(throttledAppDuration)) + throttledAppRule.ExpiresAt = protoutil.TimeToProto(time.Now().Add(throttledAppDuration)) updateThrottlerConfigOptions.ThrottledApp = &throttledAppRule } else if unthrottledAppRule.Name != "" { - unthrottledAppRule.ExpiresAt = logutil.TimeToProto(time.Now()) + unthrottledAppRule.ExpiresAt = protoutil.TimeToProto(time.Now()) updateThrottlerConfigOptions.ThrottledApp = &unthrottledAppRule } diff --git a/go/test/endtoend/tabletmanager/throttler_topo/throttler_test.go b/go/test/endtoend/tabletmanager/throttler_topo/throttler_test.go index 0df79c55d46..7c0f05bdcc2 100644 --- a/go/test/endtoend/tabletmanager/throttler_topo/throttler_test.go +++ b/go/test/endtoend/tabletmanager/throttler_topo/throttler_test.go @@ -27,10 +27,10 @@ import ( "time" "vitess.io/vitess/go/mysql" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/test/endtoend/throttler" - "vitess.io/vitess/go/vt/logutil" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base" @@ -397,7 +397,7 @@ func TestLag(t *testing.T) { t.Run("exempting test app", func(t *testing.T) { appRule := &topodatapb.ThrottledAppRule{ Name: testAppName, - ExpiresAt: logutil.TimeToProto(time.Now().Add(time.Hour)), + ExpiresAt: protoutil.TimeToProto(time.Now().Add(time.Hour)), Exempt: true, } _, err := throttler.UpdateThrottlerTopoConfig(clusterInstance, false, false, throttler.DefaultThreshold.Seconds(), useDefaultQuery, appRule) @@ -407,7 +407,7 @@ func TestLag(t *testing.T) { t.Run("unexempting test app", func(t *testing.T) { appRule := &topodatapb.ThrottledAppRule{ Name: testAppName, - ExpiresAt: logutil.TimeToProto(time.Now()), + ExpiresAt: protoutil.TimeToProto(time.Now()), } _, err := throttler.UpdateThrottlerTopoConfig(clusterInstance, false, false, throttler.DefaultThreshold.Seconds(), useDefaultQuery, appRule) assert.NoError(t, err) diff --git a/go/test/endtoend/throttler/util.go b/go/test/endtoend/throttler/util.go index f938090aafe..8722c283409 100644 --- a/go/test/endtoend/throttler/util.go +++ b/go/test/endtoend/throttler/util.go @@ -30,10 +30,10 @@ import ( "github.com/stretchr/testify/require" "github.com/tidwall/gjson" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/test/endtoend/cluster" "vitess.io/vitess/go/vt/concurrency" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/logutil" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base" "vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/throttlerapp" @@ -79,7 +79,7 @@ func UpdateThrottlerTopoConfigRaw(vtctldProcess *cluster.VtctldClientProcess, ke } if appRule != nil { args = append(args, "--throttle-app", appRule.Name) - args = append(args, "--throttle-app-duration", logutil.ProtoToTime(appRule.ExpiresAt).Sub(time.Now()).String()) + args = append(args, "--throttle-app-duration", protoutil.TimeFromProto(appRule.ExpiresAt).UTC().Sub(time.Now()).String()) args = append(args, "--throttle-app-ratio", fmt.Sprintf("%f", appRule.Ratio)) if appRule.Exempt { args = append(args, "--throttle-app-exempt") diff --git a/go/vt/logutil/logger.go b/go/vt/logutil/logger.go index 8ebf88e085d..524ca4db4d7 100644 --- a/go/vt/logutil/logger.go +++ b/go/vt/logutil/logger.go @@ -25,6 +25,7 @@ import ( "sync" "time" + "vitess.io/vitess/go/protoutil" logutilpb "vitess.io/vitess/go/vt/proto/logutil" ) @@ -73,7 +74,7 @@ func EventToBuffer(event *logutilpb.Event, buf *bytes.Buffer) { return } - t := ProtoToTime(event.Time) + t := protoutil.TimeFromProto(event.Time).UTC() _, month, day := t.Date() hour, minute, second := t.Clock() twoDigits(buf, int(month)) @@ -137,7 +138,7 @@ func NewCallbackLogger(f func(*logutilpb.Event)) *CallbackLogger { func (cl *CallbackLogger) InfoDepth(depth int, s string) { file, line := fileAndLine(2 + depth) cl.f(&logutilpb.Event{ - Time: TimeToProto(time.Now()), + Time: protoutil.TimeToProto(time.Now()), Level: logutilpb.Level_INFO, File: file, Line: line, @@ -149,7 +150,7 @@ func (cl *CallbackLogger) InfoDepth(depth int, s string) { func (cl *CallbackLogger) WarningDepth(depth int, s string) { file, line := fileAndLine(2 + depth) cl.f(&logutilpb.Event{ - Time: TimeToProto(time.Now()), + Time: protoutil.TimeToProto(time.Now()), Level: logutilpb.Level_WARNING, File: file, Line: line, @@ -161,7 +162,7 @@ func (cl *CallbackLogger) WarningDepth(depth int, s string) { func (cl *CallbackLogger) ErrorDepth(depth int, s string) { file, line := fileAndLine(2 + depth) cl.f(&logutilpb.Event{ - Time: TimeToProto(time.Now()), + Time: protoutil.TimeToProto(time.Now()), Level: logutilpb.Level_ERROR, File: file, Line: line, @@ -198,7 +199,7 @@ func (cl *CallbackLogger) Error(err error) { func (cl *CallbackLogger) Printf(format string, v ...any) { file, line := fileAndLine(2) cl.f(&logutilpb.Event{ - Time: TimeToProto(time.Now()), + Time: protoutil.TimeToProto(time.Now()), Level: logutilpb.Level_CONSOLE, File: file, Line: line, diff --git a/go/vt/logutil/logger_test.go b/go/vt/logutil/logger_test.go index c34f8cf8ec3..0eb4edb2b93 100644 --- a/go/vt/logutil/logger_test.go +++ b/go/vt/logutil/logger_test.go @@ -20,6 +20,7 @@ import ( "testing" "time" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/race" logutilpb "vitess.io/vitess/go/vt/proto/logutil" ) @@ -31,7 +32,7 @@ func TestLogEvent(t *testing.T) { }{ { event: &logutilpb.Event{ - Time: TimeToProto(time.Date(2014, time.November, 10, 23, 30, 12, 123456000, time.UTC)), + Time: protoutil.TimeToProto(time.Date(2014, time.November, 10, 23, 30, 12, 123456000, time.UTC)), Level: logutilpb.Level_INFO, File: "file.go", Line: 123, @@ -41,7 +42,7 @@ func TestLogEvent(t *testing.T) { }, { event: &logutilpb.Event{ - Time: TimeToProto(time.Date(2014, time.January, 20, 23, 30, 12, 0, time.UTC)), + Time: protoutil.TimeToProto(time.Date(2014, time.January, 20, 23, 30, 12, 0, time.UTC)), Level: logutilpb.Level_WARNING, File: "file2.go", Line: 567, @@ -51,7 +52,7 @@ func TestLogEvent(t *testing.T) { }, { event: &logutilpb.Event{ - Time: TimeToProto(time.Date(2014, time.January, 20, 23, 30, 12, 0, time.UTC)), + Time: protoutil.TimeToProto(time.Date(2014, time.January, 20, 23, 30, 12, 0, time.UTC)), Level: logutilpb.Level_ERROR, File: "file2.go", Line: 567, @@ -61,7 +62,7 @@ func TestLogEvent(t *testing.T) { }, { event: &logutilpb.Event{ - Time: TimeToProto(time.Date(2014, time.January, 20, 23, 30, 12, 0, time.UTC)), + Time: protoutil.TimeToProto(time.Date(2014, time.January, 20, 23, 30, 12, 0, time.UTC)), Level: logutilpb.Level_CONSOLE, File: "file2.go", Line: 567, diff --git a/go/vt/logutil/proto3.go b/go/vt/logutil/proto3.go index 2bde4656dbd..b62ed8810da 100644 --- a/go/vt/logutil/proto3.go +++ b/go/vt/logutil/proto3.go @@ -17,37 +17,11 @@ limitations under the License. package logutil import ( - "time" - logutilpb "vitess.io/vitess/go/vt/proto/logutil" - vttimepb "vitess.io/vitess/go/vt/proto/vttime" ) // This file contains a few functions to help with proto3. -// ProtoToTime converts a vttimepb.Time to a time.Time. -// proto3 will eventually support timestamps, at which point we'll retire -// this. -// -// A nil pointer is like the empty timestamp. -func ProtoToTime(ts *vttimepb.Time) time.Time { - if ts == nil { - // treat nil like the empty Timestamp - return time.Time{} - } - return time.Unix(ts.Seconds, int64(ts.Nanoseconds)).UTC() -} - -// TimeToProto converts the time.Time to a vttimepb.Time. -func TimeToProto(t time.Time) *vttimepb.Time { - seconds := t.Unix() - nanos := int64(t.Sub(time.Unix(seconds, 0))) - return &vttimepb.Time{ - Seconds: seconds, - Nanoseconds: int32(nanos), - } -} - // EventStream is an interface used by RPC clients when the streaming // RPC returns a stream of log events. type EventStream interface { diff --git a/go/vt/logutil/proto3_test.go b/go/vt/logutil/proto3_test.go deleted file mode 100644 index 58a78dea2ef..00000000000 --- a/go/vt/logutil/proto3_test.go +++ /dev/null @@ -1,99 +0,0 @@ -/* -Copyright 2019 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 logutil - -import ( - "math" - "testing" - "time" - - "google.golang.org/protobuf/proto" - - "vitess.io/vitess/go/vt/proto/vttime" -) - -const ( - // Seconds field of the earliest valid Timestamp. - // This is time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC).Unix(). - minValidSeconds = -62135596800 - // Seconds field just after the latest valid Timestamp. - // This is time.Date(10000, 1, 1, 0, 0, 0, 0, time.UTC).Unix(). - maxValidSeconds = 253402300800 -) - -func utcDate(year, month, day int) time.Time { - return time.Date(year, time.Month(month), day, 0, 0, 0, 0, time.UTC) -} - -var tests = []struct { - pt *vttime.Time - t time.Time -}{ - // The timestamp representing the Unix epoch date. - {pt: &vttime.Time{Seconds: 0, Nanoseconds: 0}, - t: utcDate(1970, 1, 1)}, - - // The smallest representable timestamp with non-negative nanos. - {pt: &vttime.Time{Seconds: math.MinInt64, Nanoseconds: 0}, - t: time.Unix(math.MinInt64, 0).UTC()}, - - // The earliest valid timestamp. - {pt: &vttime.Time{Seconds: minValidSeconds, Nanoseconds: 0}, - t: utcDate(1, 1, 1)}, - - // The largest representable timestamp with nanos in range. - {pt: &vttime.Time{Seconds: math.MaxInt64, Nanoseconds: 1e9 - 1}, - t: time.Unix(math.MaxInt64, 1e9-1).UTC()}, - - // The largest valid timestamp. - {pt: &vttime.Time{Seconds: maxValidSeconds - 1, Nanoseconds: 1e9 - 1}, - t: time.Date(9999, 12, 31, 23, 59, 59, 1e9-1, time.UTC)}, - - // The smallest invalid timestamp that is larger than the valid range. - {pt: &vttime.Time{Seconds: maxValidSeconds, Nanoseconds: 0}, - t: time.Unix(maxValidSeconds, 0).UTC()}, - - // A date before the epoch. - {pt: &vttime.Time{Seconds: -281836800, Nanoseconds: 0}, - t: utcDate(1961, 1, 26)}, - - // A date after the epoch. - {pt: &vttime.Time{Seconds: 1296000000, Nanoseconds: 0}, - t: utcDate(2011, 1, 26)}, - - // A date after the epoch, in the middle of the day. - {pt: &vttime.Time{Seconds: 1296012345, Nanoseconds: 940483}, - t: time.Date(2011, 1, 26, 3, 25, 45, 940483, time.UTC)}, -} - -func TestProtoToTime(t *testing.T) { - for i, s := range tests { - got := ProtoToTime(s.pt) - if got != s.t { - t.Errorf("ProtoToTime[%v](%v) = %v, want %v", i, s.pt, got, s.t) - } - } -} - -func TestTimeToProto(t *testing.T) { - for i, s := range tests { - got := TimeToProto(s.t) - if !proto.Equal(got, s.pt) { - t.Errorf("TimeToProto[%v](%v) = %v, want %v", i, s.t, got, s.pt) - } - } -} diff --git a/go/vt/mysqlctl/builtinbackupengine.go b/go/vt/mysqlctl/builtinbackupengine.go index de1e4ab679b..33d4ce688fd 100644 --- a/go/vt/mysqlctl/builtinbackupengine.go +++ b/go/vt/mysqlctl/builtinbackupengine.go @@ -39,6 +39,7 @@ import ( "vitess.io/vitess/go/ioutil" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/mysql/replication" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/vt/concurrency" "vitess.io/vitess/go/vt/log" "vitess.io/vitess/go/vt/logutil" @@ -348,9 +349,9 @@ func (be *BuiltinBackupEngine) executeIncrementalBackup(ctx context.Context, par return false, vterrors.Errorf(vtrpc.Code_ABORTED, "empty binlog name in response. Request=%v, Response=%v", req, resp) } incrDetails := &IncrementalBackupDetails{ - FirstTimestamp: FormatRFC3339(logutil.ProtoToTime(resp.FirstTimestamp)), + FirstTimestamp: FormatRFC3339(protoutil.TimeFromProto(resp.FirstTimestamp).UTC()), FirstTimestampBinlog: filepath.Base(resp.FirstTimestampBinlog), - LastTimestamp: FormatRFC3339(logutil.ProtoToTime(resp.LastTimestamp)), + LastTimestamp: FormatRFC3339(protoutil.TimeFromProto(resp.LastTimestamp).UTC()), LastTimestampBinlog: filepath.Base(resp.LastTimestampBinlog), } // It's worthwhile we explain the difference between params.IncrementalFromPos and incrementalBackupFromPosition. @@ -917,7 +918,7 @@ func (be *BuiltinBackupEngine) executeRestoreIncrementalBackup(ctx context.Conte } req := &mysqlctlpb.ApplyBinlogFileRequest{ BinlogFileName: binlogFile, - BinlogRestoreDatetime: logutil.TimeToProto(params.RestoreToTimestamp), + BinlogRestoreDatetime: protoutil.TimeToProto(params.RestoreToTimestamp), } if params.RestoreToPos.GTIDSet != nil { req.BinlogRestorePosition = params.RestoreToPos.GTIDSet.String() diff --git a/go/vt/mysqlctl/mysqld.go b/go/vt/mysqlctl/mysqld.go index b1db3ec425a..989963479f4 100644 --- a/go/vt/mysqlctl/mysqld.go +++ b/go/vt/mysqlctl/mysqld.go @@ -43,6 +43,7 @@ import ( "github.com/spf13/pflag" "vitess.io/vitess/go/mysql/sqlerror" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/config" "vitess.io/vitess/go/mysql" @@ -51,7 +52,6 @@ import ( "vitess.io/vitess/go/vt/dbconnpool" "vitess.io/vitess/go/vt/hook" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/mysqlctl/mysqlctlclient" "vitess.io/vitess/go/vt/servenv" "vitess.io/vitess/go/vt/vterrors" @@ -1197,7 +1197,7 @@ func (mysqld *Mysqld) ApplyBinlogFile(ctx context.Context, req *mysqlctlpb.Apply gtids, ) } - if restoreToTimestamp := logutil.ProtoToTime(req.BinlogRestoreDatetime); !restoreToTimestamp.IsZero() { + if restoreToTimestamp := protoutil.TimeFromProto(req.BinlogRestoreDatetime).UTC(); !restoreToTimestamp.IsZero() { args = append(args, "--stop-datetime", restoreToTimestamp.Format(sqltypes.TimestampFormat), @@ -1410,7 +1410,7 @@ func (mysqld *Mysqld) ReadBinlogFilesTimestamps(ctx context.Context, req *mysqlc return nil, err } if found { - resp.FirstTimestamp = logutil.TimeToProto(t) + resp.FirstTimestamp = protoutil.TimeToProto(t) resp.FirstTimestampBinlog = binlogFile break } @@ -1423,7 +1423,7 @@ func (mysqld *Mysqld) ReadBinlogFilesTimestamps(ctx context.Context, req *mysqlc return nil, err } if found { - resp.LastTimestamp = logutil.TimeToProto(t) + resp.LastTimestamp = protoutil.TimeToProto(t) resp.LastTimestampBinlog = binlogFile break } diff --git a/go/vt/topo/shard.go b/go/vt/topo/shard.go index 3f7be3cc676..87d274f60df 100644 --- a/go/vt/topo/shard.go +++ b/go/vt/topo/shard.go @@ -30,7 +30,7 @@ import ( "google.golang.org/protobuf/proto" "vitess.io/vitess/go/constants/sidecar" - "vitess.io/vitess/go/vt/logutil" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/vterrors" @@ -189,12 +189,12 @@ func (si *ShardInfo) HasPrimary() bool { // GetPrimaryTermStartTime returns the shard's primary term start time as a Time value. func (si *ShardInfo) GetPrimaryTermStartTime() time.Time { - return logutil.ProtoToTime(si.Shard.PrimaryTermStartTime) + return protoutil.TimeFromProto(si.Shard.PrimaryTermStartTime).UTC() } // SetPrimaryTermStartTime sets the shard's primary term start time as a Time value. func (si *ShardInfo) SetPrimaryTermStartTime(t time.Time) { - si.Shard.PrimaryTermStartTime = logutil.TimeToProto(t) + si.Shard.PrimaryTermStartTime = protoutil.TimeToProto(t) } // GetShard is a high level function to read shard data. diff --git a/go/vt/topo/tablet.go b/go/vt/topo/tablet.go index b68a48b0223..443ced52686 100644 --- a/go/vt/topo/tablet.go +++ b/go/vt/topo/tablet.go @@ -24,6 +24,7 @@ import ( "sync" "time" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/vt/key" "vitess.io/vitess/go/vt/proto/vtrpc" @@ -35,7 +36,6 @@ import ( "vitess.io/vitess/go/netutil" "vitess.io/vitess/go/trace" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/logutil" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/topo/events" @@ -215,7 +215,7 @@ func (ti *TabletInfo) IsReplicaType() bool { // GetPrimaryTermStartTime returns the tablet's primary term start time as a Time value. func (ti *TabletInfo) GetPrimaryTermStartTime() time.Time { - return logutil.ProtoToTime(ti.Tablet.PrimaryTermStartTime) + return protoutil.TimeFromProto(ti.Tablet.PrimaryTermStartTime).UTC() } // NewTabletInfo returns a TabletInfo basing on tablet with the @@ -586,7 +586,7 @@ func (ts *Server) InitTablet(ctx context.Context, tablet *topodatapb.Tablet, all if tablet.Type == topodatapb.TabletType_PRIMARY { // we update primary_term_start_time even if the primary hasn't changed // because that means a new primary term with the same primary - tablet.PrimaryTermStartTime = logutil.TimeToProto(time.Now()) + tablet.PrimaryTermStartTime = protoutil.TimeToProto(time.Now()) } err = ts.CreateTablet(ctx, tablet) diff --git a/go/vt/vtadmin/cluster/cluster.go b/go/vt/vtadmin/cluster/cluster.go index a0ddc62f5ad..e64dff7e11a 100644 --- a/go/vt/vtadmin/cluster/cluster.go +++ b/go/vt/vtadmin/cluster/cluster.go @@ -39,7 +39,6 @@ import ( "vitess.io/vitess/go/trace" "vitess.io/vitess/go/vt/concurrency" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/topo/topoproto" "vitess.io/vitess/go/vt/vtadmin/cache" "vitess.io/vitess/go/vt/vtadmin/cluster/discovery" @@ -341,7 +340,7 @@ func (c *Cluster) parseTablet(rows *sql.Rows) (*vtadminpb.Tablet, error) { return nil, fmt.Errorf("failed parsing primary_term_start_time %s: %w", mtstStr, err) } - topotablet.PrimaryTermStartTime = logutil.TimeToProto(timeTime) + topotablet.PrimaryTermStartTime = protoutil.TimeToProto(timeTime) } if c.TabletFQDNTmpl != nil { diff --git a/go/vt/vtctl/backup.go b/go/vt/vtctl/backup.go index baf6a267a51..c2f90ec4b14 100644 --- a/go/vt/vtctl/backup.go +++ b/go/vt/vtctl/backup.go @@ -244,7 +244,7 @@ func commandRestoreFromBackup(ctx context.Context, wr *wrangler.Wrangler, subFla req := &vtctldatapb.RestoreFromBackupRequest{ TabletAlias: tabletAlias, RestoreToPos: *restoreToPos, - RestoreToTimestamp: logutil.TimeToProto(restoreToTimestamp), + RestoreToTimestamp: protoutil.TimeToProto(restoreToTimestamp), DryRun: *dryRun, } diff --git a/go/vt/vtctl/fakevtctlclient/fake_loggerevent_streamingclient.go b/go/vt/vtctl/fakevtctlclient/fake_loggerevent_streamingclient.go index a11db6a4952..14147316508 100644 --- a/go/vt/vtctl/fakevtctlclient/fake_loggerevent_streamingclient.go +++ b/go/vt/vtctl/fakevtctlclient/fake_loggerevent_streamingclient.go @@ -23,6 +23,7 @@ import ( "sync" "time" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/vt/logutil" logutilpb "vitess.io/vitess/go/vt/proto/logutil" @@ -111,7 +112,7 @@ type streamResultAdapter struct { func (s *streamResultAdapter) Recv() (*logutilpb.Event, error) { if s.index < len(s.lines) { result := &logutilpb.Event{ - Time: logutil.TimeToProto(time.Now()), + Time: protoutil.TimeToProto(time.Now()), Level: logutilpb.Level_CONSOLE, File: "fakevtctlclient", Line: -1, diff --git a/go/vt/vtctl/grpcvtctldserver/server.go b/go/vt/vtctl/grpcvtctldserver/server.go index a038144cfef..48edeec9dd9 100644 --- a/go/vt/vtctl/grpcvtctldserver/server.go +++ b/go/vt/vtctl/grpcvtctldserver/server.go @@ -3056,7 +3056,7 @@ func (s *VtctldServer) RestoreFromBackup(req *vtctldatapb.RestoreFromBackupReque if mysqlctl.DisableActiveReparents { return nil } - if (req.RestoreToPos != "" || !logutil.ProtoToTime(req.RestoreToTimestamp).IsZero()) && !req.DryRun { + if (req.RestoreToPos != "" || !protoutil.TimeFromProto(req.RestoreToTimestamp).UTC().IsZero()) && !req.DryRun { // point in time recovery. Do not restore replication return nil } diff --git a/go/vt/vtctl/grpcvtctldserver/server_test.go b/go/vt/vtctl/grpcvtctldserver/server_test.go index 3407f22a0d3..9813dada377 100644 --- a/go/vt/vtctl/grpcvtctldserver/server_test.go +++ b/go/vt/vtctl/grpcvtctldserver/server_test.go @@ -39,7 +39,6 @@ import ( "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/test/utils" hk "vitess.io/vitess/go/vt/hook" - "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/mysqlctl/backupstorage" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/memorytopo" @@ -6530,7 +6529,7 @@ func TestGetTablets(t *testing.T) { Keyspace: "ks2", Shard: "-", Type: topodatapb.TabletType_PRIMARY, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)), }, { Alias: &topodatapb.TabletAlias{ @@ -6541,7 +6540,7 @@ func TestGetTablets(t *testing.T) { Shard: "-", Hostname: "stale.primary", Type: topodatapb.TabletType_PRIMARY, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(2006, time.January, 2, 14, 4, 5, 0, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(2006, time.January, 2, 14, 4, 5, 0, time.UTC)), }, }, req: &vtctldatapb.GetTabletsRequest{ @@ -6557,7 +6556,7 @@ func TestGetTablets(t *testing.T) { Keyspace: "ks2", Shard: "-", Type: topodatapb.TabletType_PRIMARY, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)), }, { Alias: &topodatapb.TabletAlias{ @@ -6568,7 +6567,7 @@ func TestGetTablets(t *testing.T) { Shard: "-", Hostname: "stale.primary", Type: topodatapb.TabletType_UNKNOWN, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(2006, time.January, 2, 14, 4, 5, 0, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(2006, time.January, 2, 14, 4, 5, 0, time.UTC)), }, }, shouldErr: false, @@ -6586,7 +6585,7 @@ func TestGetTablets(t *testing.T) { Shard: "-", Hostname: "slightly less stale", Type: topodatapb.TabletType_PRIMARY, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)), }, { Alias: &topodatapb.TabletAlias{ @@ -6597,7 +6596,7 @@ func TestGetTablets(t *testing.T) { Keyspace: "ks1", Shard: "-", Type: topodatapb.TabletType_PRIMARY, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(2006, time.January, 2, 14, 4, 5, 0, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(2006, time.January, 2, 14, 4, 5, 0, time.UTC)), }, { Alias: &topodatapb.TabletAlias{ @@ -6608,7 +6607,7 @@ func TestGetTablets(t *testing.T) { Keyspace: "ks1", Shard: "-", Type: topodatapb.TabletType_PRIMARY, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(2006, time.January, 2, 16, 4, 5, 0, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(2006, time.January, 2, 16, 4, 5, 0, time.UTC)), }, }, req: &vtctldatapb.GetTabletsRequest{}, @@ -6622,7 +6621,7 @@ func TestGetTablets(t *testing.T) { Shard: "-", Hostname: "slightly less stale", Type: topodatapb.TabletType_UNKNOWN, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(2006, time.January, 2, 15, 4, 5, 0, time.UTC)), }, { Alias: &topodatapb.TabletAlias{ @@ -6633,7 +6632,7 @@ func TestGetTablets(t *testing.T) { Keyspace: "ks1", Shard: "-", Type: topodatapb.TabletType_UNKNOWN, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(2006, time.January, 2, 14, 4, 5, 0, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(2006, time.January, 2, 14, 4, 5, 0, time.UTC)), }, { Alias: &topodatapb.TabletAlias{ @@ -6644,7 +6643,7 @@ func TestGetTablets(t *testing.T) { Keyspace: "ks1", Shard: "-", Type: topodatapb.TabletType_PRIMARY, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(2006, time.January, 2, 16, 4, 5, 0, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(2006, time.January, 2, 16, 4, 5, 0, time.UTC)), }, }, shouldErr: false, diff --git a/go/vt/vtctl/vtctl.go b/go/vt/vtctl/vtctl.go index 640e6841bda..333d88a6e8d 100644 --- a/go/vt/vtctl/vtctl.go +++ b/go/vt/vtctl/vtctl.go @@ -800,7 +800,7 @@ func fmtTabletAwkable(ti *topo.TabletInfo) string { mtst := "" // special case for old primary that hasn't updated topo yet if ti.PrimaryTermStartTime != nil && ti.PrimaryTermStartTime.Seconds > 0 { - mtst = logutil.ProtoToTime(ti.PrimaryTermStartTime).Format(time.RFC3339) + mtst = protoutil.TimeFromProto(ti.PrimaryTermStartTime).UTC().Format(time.RFC3339) } return fmt.Sprintf("%v %v %v %v %v %v %v %v", topoproto.TabletAliasString(ti.Alias), keyspace, shard, topoproto.TabletTypeLString(ti.Type), ti.Addr(), ti.MysqlAddr(), fmtMapAwkable(ti.Tags), mtst) } @@ -1861,7 +1861,7 @@ func commandCreateKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags if timeTime.After(time.Now()) { return vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, "snapshot_time can not be more than current time") } - snapshotTime = logutil.TimeToProto(timeTime) + snapshotTime = protoutil.TimeToProto(timeTime) } ki := &topodatapb.Keyspace{ KeyspaceType: ktype, @@ -3625,13 +3625,13 @@ func commandUpdateThrottlerConfig(ctx context.Context, wr *wrangler.Wrangler, su Name: *throttledApp, Ratio: *throttledAppRatio, Exempt: *throttledAppExempt, - ExpiresAt: logutil.TimeToProto(time.Now().Add(*throttledAppDuration)), + ExpiresAt: protoutil.TimeToProto(time.Now().Add(*throttledAppDuration)), } } else if *unthrottledApp != "" { req.ThrottledApp = &topodatapb.ThrottledAppRule{ Name: *unthrottledApp, Ratio: 0, - ExpiresAt: logutil.TimeToProto(time.Now()), + ExpiresAt: protoutil.TimeToProto(time.Now()), } } _, err = wr.VtctldServer().UpdateThrottlerConfig(ctx, req) diff --git a/go/vt/vtctl/vtctlclienttest/client.go b/go/vt/vtctl/vtctlclienttest/client.go index 0bb2739c1b8..8e77bed8f8a 100644 --- a/go/vt/vtctl/vtctlclienttest/client.go +++ b/go/vt/vtctl/vtctlclienttest/client.go @@ -31,6 +31,7 @@ import ( "testing" "time" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/memorytopo" @@ -66,7 +67,7 @@ func TestSuite(t *testing.T, ts *topo.Server, client vtctlclient.VtctlClient) { PortMap: map[string]int32{ "vt": 3333, }, - PrimaryTermStartTime: logutil.TimeToProto(time.Date(1970, 1, 1, 1, 1, 1, 1, time.UTC)), + PrimaryTermStartTime: protoutil.TimeToProto(time.Date(1970, 1, 1, 1, 1, 1, 1, time.UTC)), Tags: map[string]string{"tag": "value"}, Keyspace: "test_keyspace", Type: topodatapb.TabletType_PRIMARY, diff --git a/go/vt/vtgate/planbuilder/migration.go b/go/vt/vtgate/planbuilder/migration.go index 330a71cd982..375d4e97dea 100644 --- a/go/vt/vtgate/planbuilder/migration.go +++ b/go/vt/vtgate/planbuilder/migration.go @@ -20,8 +20,8 @@ import ( "strconv" "time" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/vt/key" - "vitess.io/vitess/go/vt/logutil" topodatapb "vitess.io/vitess/go/vt/proto/topodata" vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/schema" @@ -70,7 +70,7 @@ func buildAlterMigrationThrottleAppPlan(query string, alterMigration *sqlparser. } throttledAppRule := &topodatapb.ThrottledAppRule{ Name: appName, - ExpiresAt: logutil.TimeToProto(expireAt), + ExpiresAt: protoutil.TimeToProto(expireAt), Ratio: ratio, } return newPlanResult(&engine.ThrottleApp{ diff --git a/go/vt/vtorc/inst/shard_dao.go b/go/vt/vtorc/inst/shard_dao.go index 7ead6d722ac..a90eed0f509 100644 --- a/go/vt/vtorc/inst/shard_dao.go +++ b/go/vt/vtorc/inst/shard_dao.go @@ -19,8 +19,8 @@ package inst import ( "errors" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/vt/external/golib/sqlutils" - "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/topoproto" "vitess.io/vitess/go/vt/vtorc/db" @@ -93,5 +93,5 @@ func getShardPrimaryTermStartTimeString(shard *topo.ShardInfo) string { if shard.PrimaryTermStartTime == nil { return "" } - return logutil.ProtoToTime(shard.PrimaryTermStartTime).String() + return protoutil.TimeFromProto(shard.PrimaryTermStartTime).UTC().String() } diff --git a/go/vt/vtorc/inst/shard_dao_test.go b/go/vt/vtorc/inst/shard_dao_test.go index 5b97af846c9..3357bd2ee36 100644 --- a/go/vt/vtorc/inst/shard_dao_test.go +++ b/go/vt/vtorc/inst/shard_dao_test.go @@ -23,7 +23,7 @@ import ( "github.com/stretchr/testify/require" _ "modernc.org/sqlite" - "vitess.io/vitess/go/vt/logutil" + "vitess.io/vitess/go/protoutil" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/vtorc/db" @@ -53,7 +53,7 @@ func TestSaveAndReadShard(t *testing.T) { Cell: "zone1", Uid: 301, }, - PrimaryTermStartTime: logutil.TimeToProto(timeToUse.Add(1 * time.Hour)), + PrimaryTermStartTime: protoutil.TimeToProto(timeToUse.Add(1 * time.Hour)), }, primaryTimestampWanted: "2023-07-24 06:00:05.000001 +0000 UTC", primaryAliasWanted: "zone1-0000000301", @@ -62,7 +62,7 @@ func TestSaveAndReadShard(t *testing.T) { keyspaceName: "ks1", shardName: "-", shard: &topodatapb.Shard{ - PrimaryTermStartTime: logutil.TimeToProto(timeToUse), + PrimaryTermStartTime: protoutil.TimeToProto(timeToUse), }, primaryTimestampWanted: "2023-07-24 05:00:05.000001 +0000 UTC", primaryAliasWanted: "", diff --git a/go/vt/vtorc/inst/tablet_dao.go b/go/vt/vtorc/inst/tablet_dao.go index 1a4c3b859c5..3ee49a75781 100644 --- a/go/vt/vtorc/inst/tablet_dao.go +++ b/go/vt/vtorc/inst/tablet_dao.go @@ -22,9 +22,9 @@ import ( "google.golang.org/protobuf/encoding/prototext" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/vt/external/golib/sqlutils" - "vitess.io/vitess/go/vt/logutil" replicationdatapb "vitess.io/vitess/go/vt/proto/replicationdata" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/topo" @@ -108,7 +108,7 @@ func SaveTablet(tablet *topodatapb.Tablet) error { tablet.Keyspace, tablet.Shard, int(tablet.Type), - logutil.ProtoToTime(tablet.PrimaryTermStartTime), + protoutil.TimeFromProto(tablet.PrimaryTermStartTime).UTC(), tabletp, ) return err diff --git a/go/vt/vttablet/tabletmanager/restore.go b/go/vt/vttablet/tabletmanager/restore.go index 4fa2168cad1..ab1e32a5b5e 100644 --- a/go/vt/vttablet/tabletmanager/restore.go +++ b/go/vt/vttablet/tabletmanager/restore.go @@ -25,6 +25,7 @@ import ( "github.com/spf13/pflag" "vitess.io/vitess/go/mysql/replication" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/stats" @@ -154,7 +155,7 @@ func (tm *TabletManager) RestoreData(ctx context.Context, logger logutil.Logger, startTime = time.Now() req := &tabletmanagerdatapb.RestoreFromBackupRequest{ - BackupTime: logutil.TimeToProto(backupTime), + BackupTime: protoutil.TimeToProto(backupTime), } err = tm.restoreDataLocked(ctx, logger, waitForBackupInterval, deleteBeforeRestore, req) if err != nil { @@ -184,12 +185,12 @@ func (tm *TabletManager) restoreDataLocked(ctx context.Context, logger logutil.L return vterrors.New(vtrpcpb.Code_INVALID_ARGUMENT, fmt.Sprintf("snapshot keyspace %v has no base_keyspace set", tablet.Keyspace)) } keyspace = keyspaceInfo.BaseKeyspace - log.Infof("Using base_keyspace %v to restore keyspace %v using a backup time of %v", keyspace, tablet.Keyspace, logutil.ProtoToTime(request.BackupTime)) + log.Infof("Using base_keyspace %v to restore keyspace %v using a backup time of %v", keyspace, tablet.Keyspace, protoutil.TimeFromProto(request.BackupTime).UTC()) } - startTime := logutil.ProtoToTime(request.BackupTime) + startTime := protoutil.TimeFromProto(request.BackupTime).UTC() if startTime.IsZero() { - startTime = logutil.ProtoToTime(keyspaceInfo.SnapshotTime) + startTime = protoutil.TimeFromProto(keyspaceInfo.SnapshotTime).UTC() } params := mysqlctl.RestoreParams{ @@ -206,7 +207,7 @@ func (tm *TabletManager) restoreDataLocked(ctx context.Context, logger logutil.L DryRun: request.DryRun, Stats: backupstats.RestoreStats(), } - if request.RestoreToPos != "" && !logutil.ProtoToTime(request.RestoreToTimestamp).IsZero() { + if request.RestoreToPos != "" && !protoutil.TimeFromProto(request.RestoreToTimestamp).UTC().IsZero() { return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "--restore_to_pos and --restore_to_timestamp are mutually exclusive") } if request.RestoreToPos != "" { @@ -216,7 +217,7 @@ func (tm *TabletManager) restoreDataLocked(ctx context.Context, logger logutil.L } params.RestoreToPos = pos } - if restoreToTimestamp := logutil.ProtoToTime(request.RestoreToTimestamp); !restoreToTimestamp.IsZero() { + if restoreToTimestamp := protoutil.TimeFromProto(request.RestoreToTimestamp).UTC(); !restoreToTimestamp.IsZero() { // Restore to given timestamp params.RestoreToTimestamp = restoreToTimestamp } diff --git a/go/vt/vttablet/tabletmanager/rpc_replication.go b/go/vt/vttablet/tabletmanager/rpc_replication.go index ea00e46a8fe..7c75b354252 100644 --- a/go/vt/vttablet/tabletmanager/rpc_replication.go +++ b/go/vt/vttablet/tabletmanager/rpc_replication.go @@ -26,10 +26,10 @@ import ( "vitess.io/vitess/go/mysql/replication" "vitess.io/vitess/go/mysql/sqlerror" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/mysqlctl" "vitess.io/vitess/go/vt/proto/vtrpc" "vitess.io/vitess/go/vt/servenv" @@ -484,12 +484,12 @@ func (tm *TabletManager) demotePrimary(ctx context.Context, revertPartialFailure // considered successful. If we are already not serving, this will be // idempotent. log.Infof("DemotePrimary disabling query service") - if err := tm.QueryServiceControl.SetServingType(tablet.Type, logutil.ProtoToTime(tablet.PrimaryTermStartTime), false, "demotion in progress"); err != nil { + if err := tm.QueryServiceControl.SetServingType(tablet.Type, protoutil.TimeFromProto(tablet.PrimaryTermStartTime).UTC(), false, "demotion in progress"); err != nil { return nil, vterrors.Wrap(err, "SetServingType(serving=false) failed") } defer func() { if finalErr != nil && revertPartialFailure && wasServing { - if err := tm.QueryServiceControl.SetServingType(tablet.Type, logutil.ProtoToTime(tablet.PrimaryTermStartTime), true, ""); err != nil { + if err := tm.QueryServiceControl.SetServingType(tablet.Type, protoutil.TimeFromProto(tablet.PrimaryTermStartTime).UTC(), true, ""); err != nil { log.Warningf("SetServingType(serving=true) failed during revert: %v", err) } } @@ -570,7 +570,7 @@ func (tm *TabletManager) UndoDemotePrimary(ctx context.Context, semiSync bool) e // Update serving graph tablet := tm.Tablet() log.Infof("UndoDemotePrimary re-enabling query service") - if err := tm.QueryServiceControl.SetServingType(tablet.Type, logutil.ProtoToTime(tablet.PrimaryTermStartTime), true, ""); err != nil { + if err := tm.QueryServiceControl.SetServingType(tablet.Type, protoutil.TimeFromProto(tablet.PrimaryTermStartTime).UTC(), true, ""); err != nil { return vterrors.Wrap(err, "SetServingType(serving=true) failed") } return nil diff --git a/go/vt/vttablet/tabletmanager/shard_sync.go b/go/vt/vttablet/tabletmanager/shard_sync.go index 7dc8710758e..ab995ec14b1 100644 --- a/go/vt/vttablet/tabletmanager/shard_sync.go +++ b/go/vt/vttablet/tabletmanager/shard_sync.go @@ -22,8 +22,8 @@ import ( "github.com/spf13/pflag" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/mysqlctl" "vitess.io/vitess/go/vt/servenv" "vitess.io/vitess/go/vt/topo" @@ -114,7 +114,7 @@ func (tm *TabletManager) shardSyncLoop(ctx context.Context, notifyChan <-chan st } // If we think we're primary, check if we need to update the shard record. // Fetch the start time from the record we just got, because the tm's tablet can change. - primaryAlias, shouldDemote, err := syncShardPrimary(ctx, tm.TopoServer, tablet, logutil.ProtoToTime(tablet.PrimaryTermStartTime)) + primaryAlias, shouldDemote, err := syncShardPrimary(ctx, tm.TopoServer, tablet, protoutil.TimeFromProto(tablet.PrimaryTermStartTime).UTC()) if err != nil { log.Errorf("Failed to sync shard record: %v", err) // Start retry timer and go back to sleep. @@ -191,7 +191,7 @@ func syncShardPrimary(ctx context.Context, ts *topo.Server, tablet *topodatapb.T aliasStr := topoproto.TabletAliasString(tablet.Alias) log.Infof("Updating shard record: primary_alias=%v, primary_term_start_time=%v", aliasStr, PrimaryTermStartTime) si.PrimaryAlias = tablet.Alias - si.PrimaryTermStartTime = logutil.TimeToProto(PrimaryTermStartTime) + si.PrimaryTermStartTime = protoutil.TimeToProto(PrimaryTermStartTime) return nil }) if err != nil { diff --git a/go/vt/vttablet/tabletmanager/tm_init.go b/go/vt/vttablet/tabletmanager/tm_init.go index 314973e744b..14da1f9483d 100644 --- a/go/vt/vttablet/tabletmanager/tm_init.go +++ b/go/vt/vttablet/tabletmanager/tm_init.go @@ -50,6 +50,7 @@ import ( "vitess.io/vitess/go/flagutil" "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/netutil" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/sets" "vitess.io/vitess/go/stats" "vitess.io/vitess/go/vt/binlog" @@ -633,7 +634,7 @@ func (tm *TabletManager) checkPrimaryShip(ctx context.Context, si *topo.ShardInf // Update the primary term start time (current value is 0) because we // assume that we are actually the PRIMARY and in case of a tiebreak, // vtgate should prefer us. - tablet.PrimaryTermStartTime = logutil.TimeToProto(time.Now()) + tablet.PrimaryTermStartTime = protoutil.TimeToProto(time.Now()) }) case err == nil: if oldTablet.Type == topodatapb.TabletType_PRIMARY { diff --git a/go/vt/vttablet/tabletmanager/tm_init_test.go b/go/vt/vttablet/tabletmanager/tm_init_test.go index d77251e20ab..148042bd6b1 100644 --- a/go/vt/vttablet/tabletmanager/tm_init_test.go +++ b/go/vt/vttablet/tabletmanager/tm_init_test.go @@ -28,6 +28,7 @@ import ( "vitess.io/vitess/go/mysql" "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/mysql/fakesqldb" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/test/utils" "vitess.io/vitess/go/vt/dbconfigs" @@ -275,7 +276,7 @@ func TestCheckPrimaryShip(t *testing.T) { now := time.Now() _, err = ts.UpdateShardFields(ctx, "ks", "0", func(si *topo.ShardInfo) error { si.PrimaryAlias = alias - si.PrimaryTermStartTime = logutil.TimeToProto(now) + si.PrimaryTermStartTime = protoutil.TimeToProto(now) // Reassign to now for easier comparison. now = si.GetPrimaryTermStartTime() return nil @@ -348,7 +349,7 @@ func TestCheckPrimaryShip(t *testing.T) { require.NoError(t, err) _, err = ts.UpdateShardFields(ctx, "ks", "0", func(si *topo.ShardInfo) error { si.PrimaryAlias = otherAlias - si.PrimaryTermStartTime = logutil.TimeToProto(ter1.Add(-10 * time.Second)) + si.PrimaryTermStartTime = protoutil.TimeToProto(ter1.Add(-10 * time.Second)) return nil }) require.NoError(t, err) @@ -365,7 +366,7 @@ func TestCheckPrimaryShip(t *testing.T) { // timestamp, we remain replica. _, err = ts.UpdateShardFields(ctx, "ks", "0", func(si *topo.ShardInfo) error { si.PrimaryAlias = otherAlias - si.PrimaryTermStartTime = logutil.TimeToProto(ter4.Add(10 * time.Second)) + si.PrimaryTermStartTime = protoutil.TimeToProto(ter4.Add(10 * time.Second)) return nil }) require.NoError(t, err) @@ -562,7 +563,7 @@ func TestCheckTabletTypeResets(t *testing.T) { now := time.Now() _, err = ts.UpdateShardFields(ctx, "ks", "0", func(si *topo.ShardInfo) error { si.PrimaryAlias = alias - si.PrimaryTermStartTime = logutil.TimeToProto(now) + si.PrimaryTermStartTime = protoutil.TimeToProto(now) // Reassign to now for easier comparison. now = si.GetPrimaryTermStartTime() return nil diff --git a/go/vt/vttablet/tabletmanager/tm_state.go b/go/vt/vttablet/tabletmanager/tm_state.go index f23e29d8512..9303c64565c 100644 --- a/go/vt/vttablet/tabletmanager/tm_state.go +++ b/go/vt/vttablet/tabletmanager/tm_state.go @@ -27,10 +27,10 @@ import ( "github.com/spf13/pflag" "google.golang.org/protobuf/proto" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/trace" "vitess.io/vitess/go/vt/key" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/mysqlctl" "vitess.io/vitess/go/vt/servenv" "vitess.io/vitess/go/vt/topo" @@ -186,7 +186,7 @@ func (ts *tmState) ChangeTabletType(ctx context.Context, tabletType topodatapb.T log.Infof("Changing Tablet Type: %v for %s", tabletType, ts.tablet.Alias.String()) if tabletType == topodatapb.TabletType_PRIMARY { - PrimaryTermStartTime := logutil.TimeToProto(time.Now()) + PrimaryTermStartTime := protoutil.TimeToProto(time.Now()) // Update the tablet record first. _, err := topotools.ChangeType(ctx, ts.tm.TopoServer, ts.tm.tabletAlias, tabletType, PrimaryTermStartTime) @@ -264,7 +264,7 @@ func (ts *tmState) updateLocked(ctx context.Context) error { return nil } - ptsTime := logutil.ProtoToTime(ts.tablet.PrimaryTermStartTime) + ptsTime := protoutil.TimeFromProto(ts.tablet.PrimaryTermStartTime).UTC() // Disable TabletServer first so the nonserving state gets advertised // before other services are shutdown. diff --git a/go/vt/vttablet/tabletserver/throttle/throttler.go b/go/vt/vttablet/tabletserver/throttle/throttler.go index b0d4918e31c..2b9570a9b6e 100644 --- a/go/vt/vttablet/tabletserver/throttle/throttler.go +++ b/go/vt/vttablet/tabletserver/throttle/throttler.go @@ -25,11 +25,11 @@ import ( "github.com/spf13/pflag" "vitess.io/vitess/go/constants/sidecar" + "vitess.io/vitess/go/protoutil" "vitess.io/vitess/go/textutil" "vitess.io/vitess/go/timer" "vitess.io/vitess/go/vt/log" - "vitess.io/vitess/go/vt/logutil" tabletmanagerdatapb "vitess.io/vitess/go/vt/proto/tabletmanagerdata" topodatapb "vitess.io/vitess/go/vt/proto/topodata" "vitess.io/vitess/go/vt/servenv" @@ -343,7 +343,7 @@ func (throttler *Throttler) applyThrottlerConfig(ctx context.Context, throttlerC throttler.StoreMetricsThreshold(throttlerConfig.Threshold) throttler.checkAsCheckSelf.Store(throttlerConfig.CheckAsCheckSelf) for _, appRule := range throttlerConfig.ThrottledApps { - throttler.ThrottleApp(appRule.Name, logutil.ProtoToTime(appRule.ExpiresAt), appRule.Ratio, appRule.Exempt) + throttler.ThrottleApp(appRule.Name, protoutil.TimeFromProto(appRule.ExpiresAt).UTC(), appRule.Ratio, appRule.Exempt) } if throttlerConfig.Enabled { go throttler.Enable(ctx)