Skip to content

Commit

Permalink
Add UTCNow() function. (minio#3931)
Browse files Browse the repository at this point in the history
This patch adds UTCNow() function which returns current UTC time.

This is equivalent of UTCNow() == time.Now().UTC()
  • Loading branch information
balamurugana authored and harshavardhana committed Mar 18, 2017
1 parent 3a6111e commit 1c97dcb
Show file tree
Hide file tree
Showing 52 changed files with 154 additions and 154 deletions.
2 changes: 1 addition & 1 deletion cmd/admin-handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func prepareAdminXLTestBed() (*adminXLTestBed, error) {
}

// Initialize boot time
globalBootTime = time.Now().UTC()
globalBootTime = UTCNow()

// Set globalEndpoints for a single node XL setup.
for _, xlDir := range xlDirs {
Expand Down
6 changes: 3 additions & 3 deletions cmd/admin-rpc-client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2014-2016 Minio, Inc.
* Minio Cloud Storage, (C) 2014, 2015, 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -117,7 +117,7 @@ func (lc localAdminClient) Uptime() (time.Duration, error) {
return time.Duration(0), errServerNotInitialized
}

return time.Now().UTC().Sub(globalBootTime), nil
return UTCNow().Sub(globalBootTime), nil
}

// Uptime - returns the uptime of the server to which the RPC call is made.
Expand Down Expand Up @@ -380,7 +380,7 @@ func getPeerUptimes(peers adminPeers) (time.Duration, error) {
// the setup is the uptime of the single minio server
// instance.
if !globalIsDistXL {
return time.Now().UTC().Sub(globalBootTime), nil
return UTCNow().Sub(globalBootTime), nil
}

uptimes := make(uptimeSlice, len(peers))
Expand Down
4 changes: 2 additions & 2 deletions cmd/admin-rpc-server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2016 Minio, Inc.
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -137,7 +137,7 @@ func (s *adminCmd) Uptime(args *AuthRPCArgs, reply *UptimeReply) error {
// https://github.com/golang/go/issues/12914. This is expected
// to be fixed by go1.9.
*reply = UptimeReply{
Uptime: time.Now().UTC().Sub(globalBootTime),
Uptime: UTCNow().Sub(globalBootTime),
}

return nil
Expand Down
11 changes: 5 additions & 6 deletions cmd/admin-rpc-server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"encoding/json"
"net/url"
"testing"
"time"
)

func testAdminCmd(cmd cmdType, t *testing.T) {
Expand All @@ -40,7 +39,7 @@ func testAdminCmd(cmd cmdType, t *testing.T) {
Username: creds.AccessKey,
Password: creds.SecretKey,
Version: Version,
RequestTime: time.Now().UTC(),
RequestTime: UTCNow(),
}
reply := LoginRPCReply{}
err = adminServer.Login(&args, &reply)
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestReInitDisks(t *testing.T) {
Username: creds.AccessKey,
Password: creds.SecretKey,
Version: Version,
RequestTime: time.Now().UTC(),
RequestTime: UTCNow(),
}
reply := LoginRPCReply{}
err = adminServer.Login(&args, &reply)
Expand All @@ -124,7 +123,7 @@ func TestReInitDisks(t *testing.T) {
Username: creds.AccessKey,
Password: creds.SecretKey,
Version: Version,
RequestTime: time.Now().UTC(),
RequestTime: UTCNow(),
}
fsReply := LoginRPCReply{}
err = fsAdminServer.Login(&fsArgs, &fsReply)
Expand Down Expand Up @@ -161,7 +160,7 @@ func TestGetConfig(t *testing.T) {
Username: creds.AccessKey,
Password: creds.SecretKey,
Version: Version,
RequestTime: time.Now().UTC(),
RequestTime: UTCNow(),
}
reply := LoginRPCReply{}
err = adminServer.Login(&args, &reply)
Expand Down Expand Up @@ -205,7 +204,7 @@ func TestWriteAndCommitConfig(t *testing.T) {
Username: creds.AccessKey,
Password: creds.SecretKey,
Version: Version,
RequestTime: time.Now().UTC(),
RequestTime: UTCNow(),
}
reply := LoginRPCReply{}
err = adminServer.Login(&args, &reply)
Expand Down
4 changes: 2 additions & 2 deletions cmd/api-headers.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2015,2016 Minio, Inc.
* Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,7 +34,7 @@ func mustGetRequestID(t time.Time) string {
// Write http common headers
func setCommonHeaders(w http.ResponseWriter) {
// Set unique request ID for each reply.
w.Header().Set(responseRequestIDKey, mustGetRequestID(time.Now().UTC()))
w.Header().Set(responseRequestIDKey, mustGetRequestID(UTCNow()))
w.Header().Set("Server", globalServerUserAgent)
w.Header().Set("Accept-Ranges", "bytes")
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/api-headers_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2015, 2016 Minio, Inc.
* Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,12 +18,11 @@ package cmd

import (
"testing"
"time"
)

func TestNewRequestID(t *testing.T) {
// Ensure that it returns an alphanumeric result of length 16.
var id = mustGetRequestID(time.Now().UTC())
var id = mustGetRequestID(UTCNow())

if len(id) != 16 {
t.Fail()
Expand Down
4 changes: 2 additions & 2 deletions cmd/auth-rpc-client.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2016 Minio, Inc.
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -93,7 +93,7 @@ func (authClient *AuthRPCClient) Login() (err error) {
Username: authClient.config.accessKey,
Password: authClient.config.secretKey,
Version: Version,
RequestTime: time.Now().UTC(),
RequestTime: UTCNow(),
}

reply := LoginRPCReply{}
Expand Down
6 changes: 3 additions & 3 deletions cmd/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (a AzureObjects) ListMultipartUploads(bucket, prefix, keyMarker, uploadIDMa
// NewMultipartUpload.
return result, nil
}
result.Uploads = []uploadMetadata{{prefix, prefix, time.Now().UTC(), "", nil}}
result.Uploads = []uploadMetadata{{prefix, prefix, UTCNow(), "", nil}}
return result, nil
}

Expand Down Expand Up @@ -439,7 +439,7 @@ func (a AzureObjects) PutObjectPart(bucket, object, uploadID string, partID int,

info.PartNumber = partID
info.ETag = md5Hex
info.LastModified = time.Now().UTC()
info.LastModified = UTCNow()
info.Size = size
return info, nil
}
Expand Down Expand Up @@ -476,7 +476,7 @@ func (a AzureObjects) ListObjectParts(bucket, object, uploadID string, partNumbe
}
result.Parts = append(result.Parts, PartInfo{
partID,
time.Now().UTC(),
UTCNow(),
md5Hex,
part.Size,
})
Expand Down
3 changes: 1 addition & 2 deletions cmd/benchmark-utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"math/rand"
"strconv"
"testing"
"time"

humanize "github.com/dustin/go-humanize"
)
Expand Down Expand Up @@ -245,7 +244,7 @@ func runGetObjectBenchmark(b *testing.B, obj ObjectLayer, objSize int) {
func getRandomByte() []byte {
const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
// seeding the random number generator.
rand.Seed(time.Now().UTC().UnixNano())
rand.Seed(UTCNow().UnixNano())
var b byte
// pick a character randomly.
b = letterBytes[rand.Intn(len(letterBytes))]
Expand Down
7 changes: 3 additions & 4 deletions cmd/browser-peer-rpc_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2016 Minio, Inc.
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,7 +19,6 @@ package cmd
import (
"path"
"testing"
"time"
)

// API suite container common to both FS and XL.
Expand Down Expand Up @@ -96,7 +95,7 @@ func (s *TestRPCBrowserPeerSuite) testBrowserPeerRPC(t *testing.T) {
Username: creds.AccessKey,
Password: creds.SecretKey,
Version: Version,
RequestTime: time.Now().UTC(),
RequestTime: UTCNow(),
}
rreply := &LoginRPCReply{}
err = rclient.Call("BrowserPeer"+loginMethodName, rargs, rreply)
Expand All @@ -111,7 +110,7 @@ func (s *TestRPCBrowserPeerSuite) testBrowserPeerRPC(t *testing.T) {
Username: creds.AccessKey,
Password: creds.SecretKey,
Version: Version,
RequestTime: time.Now().UTC(),
RequestTime: UTCNow(),
}
rreply = &LoginRPCReply{}
err = rclient.Call("BrowserPeer"+loginMethodName, rargs, rreply)
Expand Down
4 changes: 2 additions & 2 deletions cmd/bucket-notification-handlers.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2016 Minio, Inc.
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -285,7 +285,7 @@ func (api objectAPIHandlers) ListenBucketNotificationHandler(w http.ResponseWrit
return
}

accountID := fmt.Sprintf("%d", time.Now().UTC().UnixNano())
accountID := fmt.Sprintf("%d", UTCNow().UnixNano())
accountARN := fmt.Sprintf(
"%s:%s:%s:%s-%s",
minioTopic,
Expand Down
5 changes: 2 additions & 3 deletions cmd/erasure-readfile_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2016 Minio, Inc.
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,7 +20,6 @@ import (
"bytes"
"math/rand"
"testing"
"time"

"reflect"

Expand Down Expand Up @@ -412,7 +411,7 @@ func TestErasureReadFileRandomOffsetLength(t *testing.T) {
}

// To generate random offset/length.
r := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))
r := rand.New(rand.NewSource(UTCNow().UnixNano()))

// create pool buffer which will be used by erasureReadFile for
// reading from disks and erasure decoding.
Expand Down
5 changes: 2 additions & 3 deletions cmd/event-notifier.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2016 Minio, Inc.
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,6 @@ import (
"net/url"
"path"
"sync"
"time"

"github.com/Sirupsen/logrus"
)
Expand Down Expand Up @@ -95,7 +94,7 @@ func newNotificationEvent(event eventData) NotificationEvent {
creds := serverConfig.GetCredential()

// Time when Minio finished processing the request.
eventTime := time.Now().UTC()
eventTime := UTCNow()

// API endpoint is captured here to be returned back
// to the client for it to differentiate from which
Expand Down
2 changes: 1 addition & 1 deletion cmd/event-notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func TestAddRemoveBucketListenerConfig(t *testing.T) {
}

// Add a topicConfig to an empty notificationConfig.
accountID := fmt.Sprintf("%d", time.Now().UTC().UnixNano())
accountID := fmt.Sprintf("%d", UTCNow().UnixNano())
accountARN := fmt.Sprintf(
"arn:minio:sqs:%s:%s:listen-%s",
serverConfig.GetRegion(),
Expand Down
6 changes: 3 additions & 3 deletions cmd/fs-v1-multipart.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2016 Minio, Inc.
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,7 +48,7 @@ func (fs fsObjects) isMultipartUpload(bucket, prefix string) bool {

// Delete uploads.json file wrapper handling a tricky case on windows.
func (fs fsObjects) deleteUploadsJSON(bucket, object, uploadID string) error {
timeID := fmt.Sprintf("%X", time.Now().UTC().UnixNano())
timeID := fmt.Sprintf("%X", UTCNow().UnixNano())
tmpPath := pathJoin(fs.fsPath, minioMetaTmpBucket, fs.fsUUID, uploadID+"+"+timeID)

multipartBucketPath := pathJoin(fs.fsPath, minioMetaMultipartBucket)
Expand Down Expand Up @@ -380,7 +380,7 @@ func (fs fsObjects) newMultipartUpload(bucket string, object string, meta map[st
fsMeta.Meta = meta

uploadID = mustGetUUID()
initiated := time.Now().UTC()
initiated := UTCNow()

// Add upload ID to uploads.json
uploadsPath := pathJoin(bucket, object, uploadsJSONFile)
Expand Down
4 changes: 2 additions & 2 deletions cmd/generic-handlers.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2015, 2016 Minio, Inc.
* Minio Cloud Storage, (C) 2015, 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -238,7 +238,7 @@ func (h timeValidityHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
// Verify if the request date header is shifted by less than globalMaxSkewTime parameter in the past
// or in the future, reject request otherwise.
curTime := time.Now().UTC()
curTime := UTCNow()
if curTime.Sub(amzDate) > globalMaxSkewTime || amzDate.Sub(curTime) > globalMaxSkewTime {
writeErrorResponse(w, ErrRequestTimeTooSkewed, r.URL)
return
Expand Down
2 changes: 1 addition & 1 deletion cmd/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func authenticateJWT(accessKey, secretKey string, expiry time.Duration) (string,
return "", errAuthentication
}

utcNow := time.Now().UTC()
utcNow := UTCNow()
token := jwtgo.NewWithClaims(jwtgo.SigningMethodHS512, jwtgo.MapClaims{
"exp": utcNow.Add(expiry).Unix(),
"iat": utcNow.Unix(),
Expand Down
4 changes: 2 additions & 2 deletions cmd/leak-detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (initialSnapShot LeakDetect) DetectLeak(t TestErrHandler) {
}
// Loop, waiting for goroutines to shut down.
// Wait up to 5 seconds, but finish as quickly as possible.
deadline := time.Now().UTC().Add(leakDetectDeadline * time.Second)
deadline := UTCNow().Add(leakDetectDeadline * time.Second)
for {
// get sack snapshot of relevant go routines.
leaked := initialSnapShot.CompareCurrentSnapshot()
Expand All @@ -63,7 +63,7 @@ func (initialSnapShot LeakDetect) DetectLeak(t TestErrHandler) {
return
}
// wait a test again will deadline.
if time.Now().UTC().Before(deadline) {
if UTCNow().Before(deadline) {
time.Sleep(leakDetectPauseTimeMs * time.Millisecond)
continue
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/lock-instrument.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Minio Cloud Storage, (C) 2016 Minio, Inc.
* Minio Cloud Storage, (C) 2016, 2017 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -157,7 +157,7 @@ func newDebugLockInfo(lockSource string, status statusType, readLock bool) debug
lockSource: lockSource,
lType: lType,
status: status,
since: time.Now().UTC(),
since: UTCNow(),
}
}

Expand Down
Loading

0 comments on commit 1c97dcb

Please sign in to comment.