首页 > 解决方案 > mongos 从不同应用程序查询时返回空集合

问题描述

我们使用带有 2 个分片的分片 MongoDB 配置。有几个前端应用程序,它们通过mongos服务(安装在每个应用程序服务器上)检索数据。

问题是在某些时候从应用程序服务器#1 运行相同的查询将返回空集合,而从应用程序服务器#3 运行相同的查询将返回正确的结果。

在运行刷新命令之前,应用程序服务器 #1 上的问题仍然存在。正如文件所述:

“您应该只需要在 movePrimary 运行后或手动清除巨型块标志后运行 flushRouterConfig。”

但是,Primary 既没有移动,也没有清除标志。

任何想法为什么会发生这种情况?

配置文件

# mongos.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: false
  logRotate: rename
  path: /var/log/mongos.log

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongos.pid  # location of pidfile

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,94.130.167.133,192.168.0.1  # Listen to local interface only, comment to listen on all interfaces.

security:
  keyFile: /var/lib/database/mongos/.keyfile

sharding:
  configDB: myproject-config/192.168.0.15:27027,192.168.0.16:27017,192.168.0.17:27017

printShardingStatus()

MongoDB shell version: 3.2.8
connecting to: cron0.myproject.smapps.org:27017/test
config.locks collection empty or missing. be sure you are connected to a mongos
--- Sharding Status --- 
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("2c5bc3fd9b2385s9613b0la5")
}
  shards:
    {  "_id" : "myproject0",  "host" : "myproject0/192.168.0.11:27017,192.168.0.12:27017",  "state" : 1,  "tags" : [ ] }
    {  "_id" : "myproject1",  "host" : "myproject1/192.168.0.13:27017,192.168.0.18:27017",  "state" : 1,  "tags" : [ "game" ] }
    {  "_id" : "myproject2",  "host" : "myproject2/192.168.0.26:27017,192.168.0.28:27017",  "state" : 1,  "tags" : [ "game" ] }
  active mongoses:
    "4.0.6" : 14
  balancer:
    Currently enabled:  yes
    Currently running:  no
    Failed balancer rounds in last 5 attempts:  0
    Migration Results for the last 24 hours: 
        8 : Success
  databases:
    {  "_id" : "myproject",  "primary" : "myproject0",  "partitioned" : true,  "version" : {  "uuid" : BinData(4,"+YxjwrKzTuekDlKutwT1IA=="),  "lastMod" : 1 } }
...

标签: mongodbsharding

解决方案


推荐阅读