@@ -239,21 +239,9 @@ func NewServer(cfg Config, stopper *stop.Stopper) (serverctl.ServerStartupInterf
239239 panic (errors .New ("no tracer set in AmbientCtx" ))
240240 }
241241
242- maxOffset := time .Duration (cfg .MaxOffset )
243- toleratedOffset := cfg .ToleratedOffset ()
244- var clock * hlc.Clock
245- if cfg .ClockDevicePath != "" {
246- ptpClock , err := ptp .MakeClock (ctx , cfg .ClockDevicePath )
247- if err != nil {
248- return nil , errors .Wrap (err , "instantiating clock source" )
249- }
250- clock = hlc .NewClock (ptpClock , maxOffset , toleratedOffset )
251- } else if cfg .TestingKnobs .Server != nil &&
252- cfg .TestingKnobs .Server .(* TestingKnobs ).WallClock != nil {
253- clock = hlc .NewClock (cfg .TestingKnobs .Server .(* TestingKnobs ).WallClock ,
254- maxOffset , toleratedOffset )
255- } else {
256- clock = hlc .NewClockWithSystemTimeSource (maxOffset , toleratedOffset )
242+ clock , err := newClockFromConfig (ctx , cfg .BaseConfig )
243+ if err != nil {
244+ return nil , err
257245 }
258246 registry := metric .NewRegistry ()
259247 ruleRegistry := metric .NewRuleRegistry ()
@@ -1319,6 +1307,27 @@ func NewServer(cfg Config, stopper *stop.Stopper) (serverctl.ServerStartupInterf
13191307 return lateBoundServer , err
13201308}
13211309
1310+ // newClockFromConfig creates a HLC clock from the server configuration.
1311+ func newClockFromConfig (ctx context.Context , cfg BaseConfig ) (* hlc.Clock , error ) {
1312+ maxOffset := time .Duration (cfg .MaxOffset )
1313+ toleratedOffset := cfg .ToleratedOffset ()
1314+ var clock * hlc.Clock
1315+ if cfg .ClockDevicePath != "" {
1316+ ptpClock , err := ptp .MakeClock (ctx , cfg .ClockDevicePath )
1317+ if err != nil {
1318+ return nil , errors .Wrap (err , "instantiating clock source" )
1319+ }
1320+ clock = hlc .NewClock (ptpClock , maxOffset , toleratedOffset )
1321+ } else if cfg .TestingKnobs .Server != nil &&
1322+ cfg .TestingKnobs .Server .(* TestingKnobs ).WallClock != nil {
1323+ clock = hlc .NewClock (cfg .TestingKnobs .Server .(* TestingKnobs ).WallClock ,
1324+ maxOffset , toleratedOffset )
1325+ } else {
1326+ clock = hlc .NewClockWithSystemTimeSource (maxOffset , toleratedOffset )
1327+ }
1328+ return clock , nil
1329+ }
1330+
13221331// ClusterSettings returns the cluster settings.
13231332func (s * topLevelServer ) ClusterSettings () * cluster.Settings {
13241333 return s .st
0 commit comments