Skip to content

Commit

Permalink
[nspcc-dev#112] api,app: Timers for caches
Browse files Browse the repository at this point in the history
Add stopTimer and startTimer for caches for ListObjecsV2 to
s3-gw and layer

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
  • Loading branch information
masterSplinter01 committed Jul 26, 2021
1 parent 7455361 commit 3c4c91f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api/layer/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,16 @@ type (
Get(ctx context.Context, address *object.Address) (*object.Object, error)
}

// Timer provides basic interface for timer ¯\_(ツ)_/¯.
Timer interface {
StartTimer()
StopTimer()
}

// Client provides S3 API client interface.
Client interface {
NeoFS
Timer

ListBuckets(ctx context.Context) ([]*BucketInfo, error)
GetBucketInfo(ctx context.Context, name string) (*BucketInfo, error)
Expand Down Expand Up @@ -468,3 +475,12 @@ func (n *layer) ListObjectVersions(ctx context.Context, p *ListObjectVersionsPar
}
return &res, nil
}

func (n *layer) StartTimer() {
n.cache.StartTimer()
}

func (n *layer) StopTimer() {
n.log.Info("stopping timer")
n.cache.StopTimer()
}
4 changes: 4 additions & 0 deletions cmd/s3-gw/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ func (a *App) Server(ctx context.Context) {
srv.Handler = router
srv.ErrorLog = zap.NewStdLog(a.log)

go a.obj.StartTimer()

go func() {
a.log.Info("starting server",
zap.String("bind", addr))
Expand Down Expand Up @@ -202,6 +204,8 @@ func (a *App) Server(ctx context.Context) {
ctx, cancel := context.WithTimeout(context.Background(), defaultShutdownTimeout)
defer cancel()

a.obj.StopTimer()

a.log.Info("stopping server",
zap.Error(srv.Shutdown(ctx)))

Expand Down

0 comments on commit 3c4c91f

Please sign in to comment.