Skip to content

Commit

Permalink
unistore: use location cache to reduce the syscall (#54098)
Browse files Browse the repository at this point in the history
close #54097
  • Loading branch information
hawkingrei authored Jun 19, 2024
1 parent a8de589 commit e41a47c
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions pkg/store/mockstore/unistore/cophandler/cop_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"strings"
"sync"
"time"

"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -50,6 +51,32 @@ import (
"github.com/pingcap/tipb/go-tipb"
)

var globalLocationMap *locationMap = newLocationMap()

type locationMap struct {
lmap map[string]*time.Location
mu sync.RWMutex
}

func newLocationMap() *locationMap {
return &locationMap{
lmap: make(map[string]*time.Location),
}
}

func (l *locationMap) getLocation(name string) (*time.Location, bool) {
l.mu.RLock()
defer l.mu.RUnlock()
result, ok := l.lmap[name]
return result, ok
}

func (l *locationMap) setLocation(name string, value *time.Location) {
l.mu.Lock()
defer l.mu.Unlock()
l.lmap[name] = value
}

// MPPCtx is the mpp execution context
type MPPCtx struct {
RPCClient client.Client
Expand Down Expand Up @@ -309,9 +336,14 @@ func buildDAG(reader *dbreader.DBReader, lockStore *lockstore.MemStore, req *cop
case "System":
tz = time.Local
default:
tz, err = time.LoadLocation(dagReq.TimeZoneName)
if err != nil {
return nil, nil, errors.Trace(err)
var ok bool
tz, ok = globalLocationMap.getLocation(dagReq.TimeZoneName)
if !ok {
tz, err = time.LoadLocation(dagReq.TimeZoneName)
if err != nil {
return nil, nil, errors.Trace(err)
}
globalLocationMap.setLocation(dagReq.TimeZoneName, tz)
}
}
sctx := flagsAndTzToSessionContext(dagReq.Flags, tz)
Expand Down

0 comments on commit e41a47c

Please sign in to comment.