Skip to content
Open

Merge #350

Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
bb84a68
Change 更改afterBindCallbacks调用位置
urionz Sep 14, 2023
947f0a7
fix conflict
urionz Oct 7, 2023
b9d3956
fix fix session drain loop
urionz Oct 9, 2023
40d5a92
update pb version to v3
urionz Oct 9, 2023
bcd4a1d
fix test
urionz Oct 9, 2023
ac3934c
fix test
urionz Oct 9, 2023
e5a8e59
fix test
urionz Oct 9, 2023
f7a4cf7
fix: skip etcd go leak detection
urionz Oct 10, 2023
8fdff63
fix kick bug
urionz Oct 27, 2023
361be7a
add ectd auth config
urionz Oct 27, 2023
b9cde42
Merge branch 'topfreegames:main' into main
urionz Dec 19, 2023
e0cebc8
Add ws acceptor allow setting path
urionz Feb 29, 2024
77a1802
Fix fix conflict
urionz Feb 29, 2024
8e3e79d
Fix fix etcd auth config
urionz Feb 29, 2024
9e56b32
Fix fix ws_acceptor test
urionz Feb 29, 2024
71c6281
Fix fix test
urionz Feb 29, 2024
ec67971
Fix fix config
urionz Feb 29, 2024
13cff0c
optmize optimize WSAcceptor parameters
urionz Mar 4, 2024
d313780
optmize optimize WSAcceptor parameters
urionz Mar 4, 2024
a54b1f4
fix fix test
urionz Mar 4, 2024
02c2e05
update docs
urionz Mar 11, 2024
136a1cf
update docs
urionz Mar 11, 2024
45180df
update docs
urionz Mar 11, 2024
0298649
Change the route registration method, add rw locks to the route map, …
urionz Mar 22, 2024
af632af
fix test
urionz Mar 22, 2024
e347b58
fix session get number value bug
urionz May 28, 2024
cd1ad62
fix conflict
urionz May 28, 2024
7fe8f5a
update support adding routes at runtime
urionz May 28, 2024
ee04f5b
Add password support for worker config
urionz Jun 13, 2024
4984011
Fix worker redis address configuration mapping bug.
urionz Jun 13, 2024
5fe2982
add session bind callback error log
urionz Jul 12, 2024
fb048ee
Merge remote-tracking branch 'upstream/main'
urionz Jul 12, 2024
9402c58
fix ReportTimingFromCtx method ctx propagate value type assert error
urionz Sep 29, 2024
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
8 changes: 6 additions & 2 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,12 @@ func (a *agentImpl) Kick(ctx context.Context) error {
if err != nil {
return err
}
_, err = a.conn.Write(p)
return err
pWrite := pendingWrite{
ctx: ctx,
data: p,
}
a.chSend <- pWrite
return nil
}

// SetLastAt sets the last at to now
Expand Down
7 changes: 4 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,18 @@ func (app *App) Start() {
case s := <-sg:
logger.Log.Warn("got signal: ", s)
if s == syscall.SIGINT {
logger.Log.Warnf("Bypassing session draing due to SIGINT. %d sessions will be immediately terminated", app.sessionPool.GetSessionCount())
logger.Log.Warnf("Bypassing session draining due to SIGINT. %d sessions will be immediately terminated", app.sessionPool.GetSessionCount())
}
break loop
case <-timeoutTimer.C:
logger.Log.Warnf("Session drain has reached maximum timeout. %d sessions will be immediately terminated", app.sessionPool.GetSessionCount())
case <-time.After(app.config.Session.Drain.Timeout):
break loop
case <-time.After(app.config.Session.Drain.Period):
logger.Log.Infof("Waiting for all sessions to finish: %d sessions remaining...", app.sessionPool.GetSessionCount())
}
}
}
close(app.dieChan)
app.Shutdown()
}

logger.Log.Warn("server is stopping...")
Expand Down
21 changes: 11 additions & 10 deletions cluster/etcd_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ import (
"strings"
"sync"
"time"

"github.com/topfreegames/pitaya/v2/config"
"github.com/topfreegames/pitaya/v2/constants"
"github.com/topfreegames/pitaya/v2/logger"
"github.com/topfreegames/pitaya/v2/util"
clientv3 "go.etcd.io/etcd/client/v3"
logutil "go.etcd.io/etcd/client/pkg/v3/logutil"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/namespace"
"google.golang.org/grpc"
)
Expand Down Expand Up @@ -81,14 +82,14 @@ func NewEtcdServiceDiscovery(
client = cli[0]
}
sd := &etcdServiceDiscovery{
running: false,
server: server,
serverMapByType: make(map[string]map[string]*Server),
listeners: make([]SDListener, 0),
stopChan: make(chan bool),
stopLeaseChan: make(chan bool),
appDieChan: appDieChan,
cli: client,
running: false,
server: server,
serverMapByType: make(map[string]map[string]*Server),
listeners: make([]SDListener, 0),
stopChan: make(chan bool),
stopLeaseChan: make(chan bool),
appDieChan: appDieChan,
cli: client,
syncServersRunning: make(chan bool),
}

Expand Down Expand Up @@ -300,7 +301,7 @@ func (sd *etcdServiceDiscovery) GetServersByType(serverType string) (map[string]
// Create a new map to avoid concurrent read and write access to the
// map, this also prevents accidental changes to the list of servers
// kept by the service discovery.
ret := make(map[string]*Server,len(sd.serverMapByType[serverType]))
ret := make(map[string]*Server, len(sd.serverMapByType[serverType]))
for k, v := range sd.serverMapByType[serverType] {
ret[k] = v
}
Expand Down
2 changes: 1 addition & 1 deletion cluster/nats_rpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ func TestNatsRPCClientCall(t *testing.T) {
ss.EXPECT().SetRequestInFlight(gomock.Any(), gomock.Any(), gomock.Any()).Times(2)

res, err := rpcClient.Call(context.Background(), protos.RPCType_Sys, rt, ss, msg, sv2)
assert.Equal(t, table.expected, res)
assert.Equal(t, table.expected.GetData(), res.GetData())
if table.err != nil {
assert.Error(t, err)
assert.Contains(t, err.Error(), table.err.Error())
Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,8 @@ func NewMemoryGroupConfig(conf *Config) *MemoryGroupConfig {
type EtcdGroupServiceConfig struct {
DialTimeout time.Duration `mapstructure:"dialtimeout"`
Endpoints []string `mapstructure:"endpoints"`
User string `mapstructure:"user"`
Pass string `mapstructure:"pass"`
Prefix string `mapstructure:"prefix"`
TransactionTimeout time.Duration `mapstructure:"transactiontimeout"`
}
Expand All @@ -605,6 +607,8 @@ func NewDefaultEtcdGroupServiceConfig() *EtcdGroupServiceConfig {
return &EtcdGroupServiceConfig{
DialTimeout: time.Duration(5 * time.Second),
Endpoints: []string{"localhost:2379"},
User: "",
Pass: "",
Prefix: "pitaya/",
TransactionTimeout: time.Duration(5 * time.Second),
}
Expand All @@ -623,6 +627,8 @@ func NewEtcdGroupServiceConfig(config *Config) *EtcdGroupServiceConfig {
type ETCDBindingConfig struct {
DialTimeout time.Duration `mapstructure:"dialtimeout"`
Endpoints []string `mapstructure:"endpoints"`
User string `mapstructure:"user"`
Pass string `mapstructure:"pass"`
Prefix string `mapstructure:"prefix"`
LeaseTTL time.Duration `mapstructure:"leasettl"`
}
Expand All @@ -632,6 +638,8 @@ func NewDefaultETCDBindingConfig() *ETCDBindingConfig {
return &ETCDBindingConfig{
DialTimeout: time.Duration(5 * time.Second),
Endpoints: []string{"localhost:2379"},
User: "",
Pass: "",
Prefix: "pitaya/",
LeaseTTL: time.Duration(5 * time.Hour),
}
Expand Down
9 changes: 8 additions & 1 deletion config/viper_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
package config

import (
"github.com/mitchellh/mapstructure"
"reflect"
"strings"
"time"

"github.com/mitchellh/mapstructure"

"github.com/spf13/viper"
)

Expand Down Expand Up @@ -91,6 +92,8 @@ func (c *Config) fillDefaultValues() {
"pitaya.cluster.rpc.server.nats.buffer.push": natsRPCServerConfig.Buffer.Push,
"pitaya.cluster.sd.etcd.dialtimeout": etcdSDConfig.DialTimeout,
"pitaya.cluster.sd.etcd.endpoints": etcdSDConfig.Endpoints,
"pitaya.cluster.sd.etcd.user": etcdSDConfig.User,
"pitaya.cluster.sd.etcd.pass": etcdSDConfig.Pass,
"pitaya.cluster.sd.etcd.prefix": etcdSDConfig.Prefix,
"pitaya.cluster.sd.etcd.grantlease.maxretries": etcdSDConfig.GrantLease.MaxRetries,
"pitaya.cluster.sd.etcd.grantlease.retryinterval": etcdSDConfig.GrantLease.RetryInterval,
Expand All @@ -111,6 +114,8 @@ func (c *Config) fillDefaultValues() {
"pitaya.defaultpipelines.structvalidation.enabled": builderConfig.DefaultPipelines.StructValidation.Enabled,
"pitaya.groups.etcd.dialtimeout": etcdGroupServiceConfig.DialTimeout,
"pitaya.groups.etcd.endpoints": etcdGroupServiceConfig.Endpoints,
"pitaya.groups.etcd.user": etcdGroupServiceConfig.User,
"pitaya.groups.etcd.pass": etcdGroupServiceConfig.Pass,
"pitaya.groups.etcd.prefix": etcdGroupServiceConfig.Prefix,
"pitaya.groups.etcd.transactiontimeout": etcdGroupServiceConfig.TransactionTimeout,
"pitaya.groups.memory.tickduration": groupServiceConfig.TickDuration,
Expand All @@ -128,6 +133,8 @@ func (c *Config) fillDefaultValues() {
"pitaya.metrics.statsd.rate": statsdConfig.Statsd.Rate,
"pitaya.modules.bindingstorage.etcd.dialtimeout": etcdBindingConfig.DialTimeout,
"pitaya.modules.bindingstorage.etcd.endpoints": etcdBindingConfig.Endpoints,
"pitaya.modules.bindingstorage.etcd.user": etcdBindingConfig.User,
"pitaya.modules.bindingstorage.etcd.pass": etcdBindingConfig.Pass,
"pitaya.modules.bindingstorage.etcd.leasettl": etcdBindingConfig.LeaseTTL,
"pitaya.modules.bindingstorage.etcd.prefix": etcdBindingConfig.Prefix,
"pitaya.conn.ratelimiting.limit": rateLimitingConfig.Limit,
Expand Down
8 changes: 5 additions & 3 deletions groups/etcd_group_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"sync"
"time"

clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/namespace"
"go.etcd.io/etcd/api/v3/mvccpb"
"github.com/topfreegames/pitaya/v2/config"
"github.com/topfreegames/pitaya/v2/constants"
"github.com/topfreegames/pitaya/v2/logger"
"go.etcd.io/etcd/api/v3/mvccpb"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/namespace"
)

var (
Expand Down Expand Up @@ -54,6 +54,8 @@ func createBaseClient(config config.EtcdGroupServiceConfig) (*clientv3.Client, e
cli, err := clientv3.New(clientv3.Config{
Endpoints: config.Endpoints,
DialTimeout: config.DialTimeout,
Password: config.Pass,
Username: config.User,
})
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func GetTestNatsServer(t *testing.T) *server.Server {
// GetTestEtcd gets a test in memory etcd server
func GetTestEtcd(t *testing.T) (*integration.ClusterV3, *clientv3.Client) {
t.Helper()
integration.BeforeTest(t)
// skip etcd go leak detection
integration.BeforeTest(t, integration.WithoutGoLeakDetection())
c := integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
cli := c.RandClient()
return c, cli
Expand Down
10 changes: 8 additions & 2 deletions modules/binding_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ import (
"fmt"
"time"

clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/namespace"
"github.com/topfreegames/pitaya/v2/cluster"
"github.com/topfreegames/pitaya/v2/config"
"github.com/topfreegames/pitaya/v2/constants"
"github.com/topfreegames/pitaya/v2/logger"
"github.com/topfreegames/pitaya/v2/session"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/namespace"
)

// ETCDBindingStorage module that uses etcd to keep in which frontend server each user is bound
type ETCDBindingStorage struct {
Base
cli *clientv3.Client
etcdEndpoints []string
etcdPassword string
etcdUsername string
etcdPrefix string
etcdDialTimeout time.Duration
leaseTTL time.Duration
Expand All @@ -57,6 +59,8 @@ func NewETCDBindingStorage(server *cluster.Server, sessionPool session.SessionPo
}
b.etcdDialTimeout = conf.DialTimeout
b.etcdEndpoints = conf.Endpoints
b.etcdPassword = conf.Pass
b.etcdUsername = conf.User
b.etcdPrefix = conf.Prefix
b.leaseTTL = conf.LeaseTTL
return b
Expand Down Expand Up @@ -159,6 +163,8 @@ func (b *ETCDBindingStorage) Init() error {
cli, err = clientv3.New(clientv3.Config{
Endpoints: b.etcdEndpoints,
DialTimeout: b.etcdDialTimeout,
Username: b.etcdUsername,
Password: b.etcdPassword,
})
if err != nil {
return err
Expand Down
Loading