is there a way to block writes to mongodb but allow reads and deletes if mongodb makes it past a certain memory threashold EX: 95%. Reason is if client keeps writing to the db, and db becomes full mongodb replicas start crashing and cluster can be difficult to recover
Hi @Daniel_Bernstein1 welcome to the community!
is there a way to block writes to mongodb but allow reads and deletes if mongodb makes it past a certain memory threashold
This is an intriguing question. What do you mean by memory, exactly? Do you mean disk space, or system RAM?
It’s worth mentioning that to WiredTiger, deletes also mean writes.
Reason is if client keeps writing to the db, and db becomes full mongodb replicas start crashing and cluster can be difficult to recover
So do you have a plan for what to do with the incoming writes? Do you plan to just drop the writes? Sorry I’m a little confused on the use case here: if the database is supposed to be read-only to begin with, why writes were allowed in the first place?
Having said that, since you’re running a replica set, if a replica set do not have a majority of voting nodes online, it will go into read-only mode (no deletes though, since these are also writes), so perhaps you can deliberately shut off some nodes to induce this read-only state? There’s no built-in MongoDB method to determine the disk space remaining in a server though, so you’ll need to craft an external trigger that monitors this event.
Hi @kevinadi , thanks for replying I mean disk space.
Yes I want to drop incoming writes if disk space is about to get full. We ran into an issue where mongodb client kept writing to the db until full and this resulted in replicas crashing and replica set being difficult to recovering.
I can have an external service that monitors the disk usage but how can the service then put the db into a state that allows only reads and deletes
Sounds to me like you need a quota system for MongoDB. Unfortunately I don’t think such a feature exists nor in the works.
Off the top of my head, this is probably best implemented in the application layer at the moment. That is, you may be able to have the application communicate to a service that monitors disk space availability, and stop any inserts when a threshold is reached.
Having said that, if this is an important feature for your use case, please do provide a feedback in the MongoDB Feedback Engine summarizing your idea and use case. Ideas in this feedback engine is constantly being monitored by the development team, and is used to prioritize upcoming work.