Merge e2c1bb0eeea43a036d0af05c38313ad01919767d into 6912ad6f332e42b4b729783692e5971fdf00e7da

This commit is contained in:
Monet Lee 2025-06-20 09:33:34 +00:00 committed by GitHub
commit c1d0d7b2c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 89 additions and 13 deletions

View File

@ -1,7 +1,7 @@
# URI for database connection, leave empty if using address and credential settings directly # URI for database connection, leave empty if using address and credential settings directly
uri: uri:
# List of MongoDB server addresses # List of MongoDB server addresses
address: [ localhost:37017 ] address: [localhost:37017]
# Name of the database # Name of the database
database: openim_v3 database: openim_v3
# Username for database authentication # Username for database authentication
@ -14,3 +14,38 @@ authSource: openim_v3
maxPoolSize: 100 maxPoolSize: 100
# Maximum number of retry attempts for a failed database connection # Maximum number of retry attempts for a failed database connection
maxRetry: 10 maxRetry: 10
# MongoDB Mode, including "standalone", "replicaSet"
mongoMode: "standalone"
# The following configurations only take effect when mongoMode is set to "replicaSet"
replicaSet:
name: rs0
hosts: [127.0.0.1:37017, 127.0.0.1:37018, 127.0.0.1:37019]
# Read concern level: "local", "available", "majority", "linearizable", "snapshot"
readConcern: majority
# maximum staleness of data in seconds
maxStaleness: 90s
# The following configurations only take effect when mongoMode is set to "replicaSet"
readPreference:
# Read preference mode, can be "primary", "primaryPreferred", "secondary", "secondaryPreferred", "nearest"
mode: primary
maxStaleness: 90s
# TagSets is an array of maps with priority based on order, empty map must be placed last for fallback tagSets
tagSets:
- datacenter: "cn-east"
rack: "1"
storage: "ssd"
- datacenter: "cn-east"
storage: "ssd"
- datacenter: "cn-east"
- {} # Empty map, indicates any node
# The following configurations only take effect when mongoMode is set to "replicaSet"
writeConcern:
# Write node count or tag (int, "majority", or custom tag)
w: majority
# Whether to wait for journal confirmation
j: true
# Write timeout duration
wtimeout: 30s

2
go.mod
View File

@ -13,7 +13,7 @@ require (
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/mitchellh/mapstructure v1.5.0 github.com/mitchellh/mapstructure v1.5.0
github.com/openimsdk/protocol v0.0.73-alpha.12 github.com/openimsdk/protocol v0.0.73-alpha.12
github.com/openimsdk/tools v0.0.50-alpha.92 github.com/openimsdk/tools v0.0.50-alpha.96
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.18.0 github.com/prometheus/client_golang v1.18.0
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0

4
go.sum
View File

@ -349,8 +349,8 @@ github.com/openimsdk/gomake v0.0.15-alpha.5 h1:eEZCEHm+NsmcO3onXZPIUbGFCYPYbsX5b
github.com/openimsdk/gomake v0.0.15-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI= github.com/openimsdk/gomake v0.0.15-alpha.5/go.mod h1:PndCozNc2IsQIciyn9mvEblYWZwJmAI+06z94EY+csI=
github.com/openimsdk/protocol v0.0.73-alpha.12 h1:2NYawXeHChYUeSme6QJ9pOLh+Empce2WmwEtbP4JvKk= github.com/openimsdk/protocol v0.0.73-alpha.12 h1:2NYawXeHChYUeSme6QJ9pOLh+Empce2WmwEtbP4JvKk=
github.com/openimsdk/protocol v0.0.73-alpha.12/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw= github.com/openimsdk/protocol v0.0.73-alpha.12/go.mod h1:WF7EuE55vQvpyUAzDXcqg+B+446xQyEba0X35lTINmw=
github.com/openimsdk/tools v0.0.50-alpha.92 h1:hWfykMhmi7EQEiwgQccJqbgggIuhun/PrVkBnjmj9Ec= github.com/openimsdk/tools v0.0.50-alpha.96 h1:U44Fq2jHiEvGi9zuYAnTRNx3Xd9T7P/kBAZLHvQ8xg4=
github.com/openimsdk/tools v0.0.50-alpha.92/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo= github.com/openimsdk/tools v0.0.50-alpha.96/go.mod h1:n2poR3asX1e1XZce4O+MOWAp+X02QJRFvhcLCXZdzRo=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ= github.com/pierrec/lz4/v4 v4.1.21 h1:yOVMLb6qSIDP67pl/5F7RepeKYu/VmTyEXvuMI5d9mQ=

View File

@ -71,15 +71,39 @@ type Minio struct {
} }
type Mongo struct { type Mongo struct {
URI string `yaml:"uri"` URI string `yaml:"uri"`
Address []string `yaml:"address"` Address []string `yaml:"address"`
Database string `yaml:"database"` Database string `yaml:"database"`
Username string `yaml:"username"` Username string `yaml:"username"`
Password string `yaml:"password"` Password string `yaml:"password"`
AuthSource string `yaml:"authSource"` AuthSource string `yaml:"authSource"`
MaxPoolSize int `yaml:"maxPoolSize"` MaxPoolSize int `yaml:"maxPoolSize"`
MaxRetry int `yaml:"maxRetry"` MaxRetry int `yaml:"maxRetry"`
MongoMode string `yaml:"mongoMode"`
ReplicaSet ReplicaSetConfig
ReadPreference ReadPrefConfig
WriteConcern WriteConcernConfig
} }
type ReplicaSetConfig struct {
Name string `yaml:"name"`
Hosts []string `yaml:"hosts"`
ReadConcern string `yaml:"readConcern"`
MaxStaleness time.Duration `yaml:"maxStaleness"`
}
type ReadPrefConfig struct {
Mode string `yaml:"mode"`
TagSets []map[string]string `yaml:"tagSets"`
MaxStaleness time.Duration `yaml:"maxStaleness"`
}
type WriteConcernConfig struct {
W any `yaml:"w"`
J bool `yaml:"j"`
WTimeout time.Duration `yaml:"wtimeout"`
}
type Kafka struct { type Kafka struct {
Username string `yaml:"username"` Username string `yaml:"username"`
Password string `yaml:"password"` Password string `yaml:"password"`
@ -490,6 +514,23 @@ func (m *Mongo) Build() *mongoutil.Config {
AuthSource: m.AuthSource, AuthSource: m.AuthSource,
MaxPoolSize: m.MaxPoolSize, MaxPoolSize: m.MaxPoolSize,
MaxRetry: m.MaxRetry, MaxRetry: m.MaxRetry,
MongoMode: m.MongoMode,
ReplicaSet: &mongoutil.ReplicaSetConfig{
Name: m.ReplicaSet.Name,
Hosts: m.ReplicaSet.Hosts,
ReadConcern: m.ReplicaSet.ReadConcern,
MaxStaleness: m.ReplicaSet.MaxStaleness,
},
ReadPreference: &mongoutil.ReadPrefConfig{
Mode: m.ReadPreference.Mode,
TagSets: m.ReadPreference.TagSets,
MaxStaleness: m.ReadPreference.MaxStaleness,
},
WriteConcern: &mongoutil.WriteConcernConfig{
W: m.WriteConcern.W,
J: m.WriteConcern.J,
WTimeout: m.WriteConcern.WTimeout,
},
} }
} }