I am working开发者_开发知识库 on a project where I want to have the ability to specify that certain nodes of the replica set can never be primary nodes ie in case of a failure where all primary capable nodes die the system should be reduced to a read-only state till some primary capable node comes up. Is this possible? If yes how? If not what is the best way around it.
This is from the documentation (emphasis mine):
priority
- priority a server has for potential election as primary. The highest priority member which is up will become primary. Default 1.0. Priority zero means server can never be primary.
So setting the priority to zero should achieve what you want.
From what I can tell, mongodb does not completely support what you require yet. If you restart a read-only slave while there is no primary, it will enter STARTUP2 state, not SECONDARY. Trying to query a mongod instance while in STARTUP2 will fail.
So if you had a unrobust setup, e.g. your cluster of masters and cluster of read only servers in the same city and there was a power cut, and you end up with the primary DC down (someone forgot to check the generators & UPS) and the read only servers came back up fine (generator in other DC works fine) then you will be in a situation where the slaves will not work.
精彩评论