I’m using MongoDB as denormalized storage which state is completely rebuilds every 15 minutes. Rebuild process takes many time and resources. Is there any way to organize table “hotswap” process, to avoid db locks and perfomance down during rebuild. Lets suppose that I’m building new version of DB on another server, make all needed indexes etc, then copy db file on main server and “swap” tables so users getting refreshed data immediately after swapping?
I’m using MongoDB as denormalized storage which state is completely rebuilds every 15 minutes.
Share
MongoDB uses pre-allocated data files so if you are frequently dropping and rebuilding databases you’re probably going to be churning the disk. The data files are opened using memory-mapped I/O and there is no provision to “hot swap” or rename databases.
The space from deleted collections can be re-used, so a better approach might be to generate temporary collection names based on your 15 minute intervals so your program can predictably “swap” to the next collection and older collections can be dropped.
If you are using MongoDB 2.2 or newer, you have some additional options:
use the new
usePowerOf2Sizescollection option to improve re-use of deleted spaceuse the Time-To-Live (TTL) function to automatically expire documents after 15 minutes.