Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: move server.TokenLimiter into util #53598

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ go_library(
"rpc_server.go",
"server.go",
"stat.go",
"tokenlimiter.go",
],
importpath = "github.com/pingcap/tidb/pkg/server",
visibility = ["//visibility:public"],
Expand Down
8 changes: 4 additions & 4 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type Server struct {
driver IDriver
listener net.Listener
socket net.Listener
concurrentLimiter *TokenLimiter
concurrentLimiter *util.TokenLimiter

rwlock sync.RWMutex
clients map[uint64]*clientConn
Expand Down Expand Up @@ -201,7 +201,7 @@ func (s *Server) ConnectionCount() int {
return cnt
}

func (s *Server) getToken() *Token {
func (s *Server) getToken() *util.Token {
start := time.Now()
tok := s.concurrentLimiter.Get()
metrics.TokenGauge.Inc()
Expand All @@ -210,7 +210,7 @@ func (s *Server) getToken() *Token {
return tok
}

func (s *Server) releaseToken(token *Token) {
func (s *Server) releaseToken(token *util.Token) {
s.concurrentLimiter.Put(token)
metrics.TokenGauge.Dec()
}
Expand Down Expand Up @@ -242,7 +242,7 @@ func NewServer(cfg *config.Config, driver IDriver) (*Server, error) {
s := &Server{
cfg: cfg,
driver: driver,
concurrentLimiter: NewTokenLimiter(cfg.TokenLimit),
concurrentLimiter: util.NewTokenLimiter(cfg.TokenLimit),
clients: make(map[uint64]*clientConn),
internalSessions: make(map[any]struct{}, 100),
health: uatomic.NewBool(false),
Expand Down
1 change: 1 addition & 0 deletions pkg/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
"rlimit_other.go",
"rlimit_windows.go",
"security.go",
"tokenlimiter.go",
"urls.go",
"util.go",
"wait_group_wrapper.go",
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/tokenlimiter.go → pkg/util/tokenlimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package server
package util

// Token is used as a permission to keep on running.
type Token struct {
Expand Down