繁体   English   中英

Spark rdd.count() 产生不一致的结果

[英]Spark rdd.count() yields inconsistent results

我有点困惑。

多次运行时,简单的 rdd.count() 会给出不同的结果。

这是我运行的代码:

val inputRdd = sc.newAPIHadoopRDD(inputConfig,
classOf[com.mongodb.hadoop.MongoInputFormat],
classOf[Long],
classOf[org.bson.BSONObject])

println(inputRdd.count())

它打开与 MondoDb 服务器的连接并简单地计算对象。 对我来说似乎很直接

根据 MongoDb,有 3,349,495 个条目

这是我的 spark 输出,都运行同一个 jar:

spark1 :    3.257.048  
spark2 :    3.303.272  
spark3 :    3.303.272  
spark4 :    3.303.272  
spark5 :    3.303.271   
spark6 :    3.303.271  
spark7 :    3.303.272  
spark8 :    3.303.272  
spark9 :    3.306.300  
spark10:    3.303.272  
spark11:    3.303.271  

Spark 和 MongoDb 运行在同一个集群上。
我们正在运行:

Spark version 1.5.0-cdh5.6.1  
Scala version 2.10.4  
MongoDb version 2.6.12  

不幸的是,我们无法更新这些

Spark 是非确定性的吗?
有没有人可以启发我?

提前致谢

编辑/更多信息
我刚刚注意到我们的 mongod.log 中有一个错误。 这个错误会导致不一致的行为吗?

[rsBackgroundSync] replSet not trying to sync from hadoop04:27017, it is vetoed for 333 more seconds
[rsBackgroundSync] replSet syncing to: hadoop05:27017
[rsBackgroundSync] replSet not trying to sync from hadoop05:27017, it is vetoed for 600 more seconds
[rsBackgroundSync] replSet not trying to sync from hadoop04:27017, it is vetoed for 333 more seconds
[rsBackgroundSync] replSet not trying to sync from hadoop05:27017, it is vetoed for 600 more seconds
[rsBackgroundSync] replSet not trying to sync from hadoop04:27017, it is vetoed for 333 more seconds
[rsBackgroundSync] replSet error RS102 too stale to catch up, at least from hadoop05:27017
[rsBackgroundSync] replSet our last optime : Jul  2 10:19:44 57777920:111
[rsBackgroundSync] replSet oldest at hadoop05:27017 : Jul  5 15:17:58 577bb386:59
[rsBackgroundSync] replSet See http://dochub.mongodb.org/core/resyncingaverystalereplicasetmember
[rsBackgroundSync] replSet error RS102 too stale to catch up

正如您已经发现的,问题似乎不在于 spark(或 scala),而在于 MongoDB。

因此,关于差异的问题似乎得到了解决。

您仍然需要对实际的 MongoDB 错误进行故障排除,提供的链接可能是一个很好的起点: http : //dochub.mongodb.org/core/resyncingaverystalereplicasetmember

count返回估计的计数。 因此,即使文档数量没有改变,返回的值也会改变。

countDocuments已添加到 MongoDB 4.0 以提供准确的计数(这也适用于多文档事务)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM