diff --git a/Makefile b/Makefile index 9cc2c6b7..0aaa7a6a 100644 --- a/Makefile +++ b/Makefile @@ -82,7 +82,7 @@ project3b: $(GOTEST) ./kv/test_raftstore -run 3B project3c: - $(GOTEST) ./scheduler/... -run 3C + $(GOTEST) ./scheduler/server ./scheduler/server/schedulers -check.f="3C" project4: project4a project4b project4c diff --git a/scheduler/server/server.go b/scheduler/server/server.go index 440686ad..5cbb1113 100644 --- a/scheduler/server/server.go +++ b/scheduler/server/server.go @@ -297,10 +297,6 @@ func (s *Server) IsClosed() bool { // Run runs the pd server. func (s *Server) Run(ctx context.Context) error { - go StartMonitor(ctx, time.Now, func() { - log.Error("system time jumps backward") - }) - if err := s.startEtcd(ctx); err != nil { return err } diff --git a/scheduler/server/systime_mon.go b/scheduler/server/systime_mon.go deleted file mode 100644 index db39fed2..00000000 --- a/scheduler/server/systime_mon.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2017 PingCAP, Inc. -// -// 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, -// See the License for the specific language governing permissions and -// limitations under the License. - -package server - -import ( - "context" - "time" - - "github.com/pingcap/log" - "go.uber.org/zap" -) - -// StartMonitor calls systimeErrHandler if system time jump backward. -func StartMonitor(ctx context.Context, now func() time.Time, systimeErrHandler func()) { - log.Info("start system time monitor") - tick := time.NewTicker(100 * time.Millisecond) - defer tick.Stop() - for { - last := now().UnixNano() - select { - case <-tick.C: - if now().UnixNano() < last { - log.Error("system time jump backward", zap.Int64("last", last)) - systimeErrHandler() - } - case <-ctx.Done(): - return - } - } -} diff --git a/scheduler/server/systime_mon_test.go b/scheduler/server/systime_mon_test.go deleted file mode 100644 index 4bab0edd..00000000 --- a/scheduler/server/systime_mon_test.go +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2017 PingCAP, Inc. -// -// 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, -// See the License for the specific language governing permissions and -// limitations under the License. - -package server - -import ( - "context" - "sync/atomic" - "testing" - "time" -) - -func TestSystimeMonitor(t *testing.T) { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - var jumpForward int32 - - trigged := false - go StartMonitor(ctx, - func() time.Time { - if !trigged { - trigged = true - return time.Now() - } - - return time.Now().Add(-2 * time.Second) - }, func() { - atomic.StoreInt32(&jumpForward, 1) - }) - - time.Sleep(1 * time.Second) - - if atomic.LoadInt32(&jumpForward) != 1 { - t.Error("should detect time error") - } -}