上周我将Fedora升级到全新的28版本,其中mongodb升级到3.6.请参阅升级到Fedora 28后如何修复mongodb服务?因为我设法解决了我的第一个问题,即mongod将不再启动.现在我在使用同一个数据库的Rails应用程序上面临另一个问题.
这很可能与mongodb升级无关,但我认为值得提供上下文并且不要错过没有提供足够的上下文的解决方案.
因此,自系统升级以来,对此Rails项目的任何登录尝试都将失败BCrypt::Errors::InvalidHash in Devise::SessionsController#create
,并在bcrypt (3.1.11) lib/bcrypt/password.rb:60:in
initialize'`处引发错误.在项目的Rails控制台中进一步分析,似乎对此方法的任何调用都将失败:
> BCrypt::Password.create('TestPassword')
BCrypt::Errors::InvalidHash: invalid hash
from /home/psychoslave/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bcrypt-3.1.11/lib/bcrypt/password.rb:60:in `initialize'
Run Code Online (Sandbox Code Playgroud)
我试图bundle
卸载/重新安装bcrypt
,甚至使用bcrypt gem的github存储库版本,但它没有改变任何东西.
看/home/psychoslave/.rbenv/versions/2.4.3/lib/ruby/gems/2.4.0/gems/bcrypt-3.1.11/lib/bcrypt/password.rb:60:in
初始化'`,问题似乎哈希是无效的.
# Initializes a BCrypt::Password instance with the data from a stored hash.
def initialize(raw_hash)
if valid_hash?(raw_hash)
self.replace(raw_hash)
@version, @cost, @salt, @checksum = split_hash(self)
else
raise Errors::InvalidHash.new("invalid hash")
end
end
Run Code Online (Sandbox Code Playgroud)
相应的测试如下:
def valid_hash?(h)
h =~ /^\$[0-9a-z]{2}\$[0-9]{2}\$[A-Za-z0-9\.\/]{53}$/
end
Run Code Online (Sandbox Code Playgroud)
散列本身是通过BCrypt::Engine.hash_secret(secret, BCrypt::Engine.generate_salt(cost))
在我使用调用的平台中 创建的__bc_crypt(secret.to_s, salt)
,它似乎调用了bcrypt-3.1.11/ext/mri/bcrypt_ext.c.
更重要的是binding.pry
,在 …
在当前设置中,有两个 Mongo Docker 容器,在主机 A 和 B 上运行,Mongo 版本为 3.4,并在副本集中运行。我想将它们升级到 3.6 并增加一个成员,以便容器可以在主机 A、B 和 C 上运行。容器有 8GB 内存限制并且没有分配交换(当前),并且在Rancher 中进行管理。所以我的计划是启动三个新容器,为它们初始化一个副本集,从 3.4 容器中进行转储,然后将其恢复为新的副本集 master。
转储很顺利,它的大小约为 16GB。当我尝试将其恢复到新的 3.6 master 时,恢复开始正常,但是在恢复了大约 5GB 的数据后,mongo 进程似乎被 OS/Rancher 杀死,而容器本身没有重新启动,MongoDB 进程只是崩溃并重新加载自己。如果我再次运行 mongorestore 到同一个数据库,它会说所有已经插入的条目的唯一键错误,然后从它停止的地方继续,只在 5GB 左右后再次执行相同的操作。所以看起来 mongorestore 将它恢复的所有条目加载到内存中。
所以我必须为此找到一些解决方案,并且:
MongoDB在其 3.6 版本中引入了变更流。
我想在我的代码中实现 mongo 更改流,并想了解它是如何工作的。我将使用 java 驱动程序来实现,这很清楚。但是我想知道是否有任何方法可以在 mongo shell 中打开更改流?找不到太多资源。
我正在学习 mongodb 大学的课程以学习 3.6 版中的新功能,但我无法解决我的验证器无效的原因。
这就是我创建集合的方式:
db.getSiblingDB("TSA").createCollection("claims", {
validator: {
$jsonSchema: {
bsonType: "object",
properties: {
_id: { },
airportCode: { type: "string", minLength: 3 },
airportName: { type: "string" },
airlineName: { type: "string", minLength: 5 },
claims: {
bsonType: "object",
properties: {
itemCategory: { bsonType: "array", maxItems: 3 },
amount: { type: "string", pattern: "^\$.*" }
}
}
},
required: ["airportCode", "airlineName", "claims"],
additionalProperties: false
}
}
})
Run Code Online (Sandbox Code Playgroud)
然后,我尝试插入这个对象:
db.getSiblingDB("TSA").claims.insertOne({
"airportCode": "ABE",
"airportName": "Lehigh Valley International Airport, Allentown", …
Run Code Online (Sandbox Code Playgroud) mongodb-3.6 ×4
mongodb ×3
bcrypt-ruby ×1
changestream ×1
docker ×1
fedora-28 ×1
jsonschema ×1
mongorestore ×1
rancher ×1