系统优化

This commit is contained in:
hahwu 2025-03-19 17:24:52 +08:00
parent 29e3061fc7
commit fcb838fa9a
3 changed files with 41 additions and 15 deletions

View File

@ -14,7 +14,7 @@
"AppPath": "./app", "AppPath": "./app",
"TELOGDIR" : "./teLog/", "TELOGDIR" : "./teLog/",
"GameName": "Merge_Pet_Local", "GameName": "pet_home",
"GameID": 1, "GameID": 1,
"ServerType":"node", "ServerType":"node",

View File

@ -213,9 +213,7 @@ func UnitPlayroom(p *Player) error {
} }
func UnitDailyTask(p *Player) error { func UnitDailyTask(p *Player) error {
DailyTaskMod := p.PlayMod.getDailyTaskMod() FT := p.PlayMod.getFriendTreasureMod()
for i := 0; i < 1000; i++ { FT.ZeroUpdate()
DailyTaskMod.WeekUpdate()
}
return nil return nil
} }

View File

@ -15,18 +15,33 @@ var topic string
func init() { func init() {
topic = conf.Server.GameName topic = conf.Server.GameName
// 连接至Kafka集群的Leader节点 // 连接至Kafka集群的Leader节点
conn, err := kafka.DialLeader(context.Background(), "tcp", "kafka-server-3:9096", topic, conf.Server.Partition) conn, err := kafka.DialContext(context.Background(), "tcp", "kafka-server:9092")
if err != nil { if err != nil {
log.Debug("kafka.DialLeader err: %v", err) log.Debug("kafka.DialContext err: %v", err)
go reconnectKafka() go reconnectKafka()
return return
} }
log.Release("Reconnected to Kafka") Partitions, err := conn.ReadPartitions(topic)
KafkaMod = conn if err != nil {
log.Fatal("kafka.DialContext err: %v", err)
return
}
for _, p := range Partitions {
if p.Leader.Host == "kafka-server" {
conn, err := kafka.DialLeader(context.Background(), "tcp", "kafka-server:9092", topic, p.ID)
if err != nil {
log.Fatal("kafka.DialLeader err: %v", err)
return
}
log.Release("Reconnected to Kafka")
KafkaMod = conn
return
}
}
log.Fatal("kafka.DialLeader err: %v", "no leader")
} }
func reconnectKafka() { func reconnectKafka() {
partition := 0
WaitTime := 5 WaitTime := 5
for { for {
WaitTime-- WaitTime--
@ -34,11 +49,24 @@ func reconnectKafka() {
log.Debug("Reconnected to Kafka failed") log.Debug("Reconnected to Kafka failed")
return return
} }
conn, err := kafka.DialLeader(context.Background(), "tcp", "kafka-server:9092", topic, partition) conn, err := kafka.DialContext(context.Background(), "tcp", "kafka-server:9092")
if err == nil { if err != nil {
KafkaMod = conn log.Fatal("kafka.DialContext err: %v", err)
log.Debug("Reconnected to Kafka") return
break }
Partitions, err := conn.ReadPartitions(topic)
for _, p := range Partitions {
if p.Leader.Host == "kafka-server" {
conn, err := kafka.DialLeader(context.Background(), "tcp", "kafka-server:9092", topic, p.ID)
if err != nil {
log.Fatal("kafka.DialLeader err: %v", err)
return
}
log.Release("Reconnected to Kafka")
KafkaMod = conn
return
}
} }
time.Sleep(time.Second) time.Sleep(time.Second)
log.Debug("kafka.DialLeader retry err: %v", err) log.Debug("kafka.DialLeader retry err: %v", err)