RavenDB, Unrecoverable Database and Data Loss
Join the DZone community and get the full member experience.Join For Free
that is one scary headline, isn’t it? go into the story and read all about it, there is a plot twist in the end.
this post was written in 05:40 am, and i have spent the entire night up and awake*.
a customer called me in a state of panic, their database is not loading, and anything they tried didn’t work. i worked with him for a while on understanding what is going on, and how to try to recover what was going on.
here is the story as i got it from the customer in question, and only embellished a lot to give the proper context for the story.
it all started with a test failure, in fact, it started with all the tests failing. the underlying reason was soon discovered, the test database disk was completely full, not even enough disk space to put half a byte. the customer took a single look at that, and run a search on the hard disk, to find what is taking so much space. the answer was apparent. the logs directory was full, in fact, the webster dictionary would need to search hard and wide to find a word to express how full it was.
so the customer in question did the natural thing, and hit shift+delete to remove all that useless debug logs that has been cluttering the disk. he then started the server again, and off to the races. except that there was a slight problem, when trying to actually load the database, the server choked, cried and ended up curled to a fetal position, refusing to cooperate even when a big stick was fetch and waved in its direction.
the problem was that the logs files that were deleted were not debug log. those were the database transaction logs . and removing them from the disk has the effect of causing the database to be unable to recover, so it stopped and refused to work.
now, remember that this is a test server, which explains why developers and operations guys are expected to do stuff to it. but the question was raised, what actually caused the issue? can this happen in production as well? if it happens, can we recover from it? and more importantly, how can this be prevented?
the underlying reason for the unbounded transaction logs growth was that the test server was an exact clone of the production system. and one of the configuration settings that was defined was “enable incremental backups”. in order to enable incremental backups, we can’t delete old journal files, we have to wait for a backup to actually happen, at which point we can copy the log files elsewhere, then delete them. if you don’t backup a database marked with enable incremental backups, it can’t free the disk space, and hence, the problem.
in production, regular backups are being run, and there were no tx log files being retained. but no one bothered to do any maintenance work on the test server, and the configuration explicitly forbid us from automatically handling this situation. but in a safe-by-default mindset we would do anything for the operations guy to notice it with enough time to do something about it. that’s why for 3.0 we are taking a proactive step toward this case, and we will alert when the database is about to run out of free space .
now, for the actual corruption issue. any database makes certain assumptions, and chief among them is that when you write to disk, and actually flush the data, it isn’t going away or being modified behind our back. if that happens, which can be because of disk corruption, manual intervention in the files, stupid anti virus software or just someone randomly deleting files by accident. at that point, all bets are off, and there isn’t much that can be done to protect ourselves from this situation.
the customer in question? federico from corvalius .
note that this post is pretty dramatized. this is a test server, not a production system, , so the guarantees, expectations and behavior toward them are vastly different. the reason for making such a big brouhaha from what is effectively a case of fat fingers is that i wanted to discuss high availability story with ravendb.
the general recommendation we are moving toward in 3.0 is that any high availability story in ravendb has to take the shared nothing approach. in effect, this means that you will not using technologies such as windows clustering, because that relies on a common shared resource, such as the san. issues there, which actually creep up on you (out of quota space in the san can happen very easily) and take down the whole system, even though you spent a lot of time and money on a supposedly highly available solution.
a shared nothing approach limit the potential causes for failure by having multiple nodes that can each operate independently. with ravendb, this is done using replication, you define a master/master replication between two nodes, and you can run it with one primary node that your servers connect to usually. at that point, any failure in this node would mean automatic switching over to the secondary, with no downtime. you don’t have to plan for it, you don’t have to configure it, it just works.
now, that is almost true, because you need to be aware that in a split brain situation, you might have conflicts, but you can set a default strategy for that (server x is the authoritative source) or a custom conflict resolution policy.
the two nodes means that you always have a hot spare, which can also handle scale out scenario by handling some of the load from the primary server if needed.
beyond replication, we also need to ensure that the data that we have is kept safe. a common request from admins that we heard is that a hot spare is wonderful, but they don’t trust that they have a backup if they can’t put it on a tape and file it on a shelve somewhere. that also help for issues such as offsite data storage in case you don’t have a secondary data center (if you do, put a replicated node there as well). this may sound paranoid, but having an offline backup means that if something did a batch job that was supposed to delete old customers, but deleted all customers, you won’t be very happy to realize that this batch delete process was actually replicate to your entire cluster and your customer count is set at zero, and then start declining from there. this is the easy case, a bad case is when you had a bug in your code that wrote bad data over time, you really want to be able to go back to the database as it was two weeks ago, and you can only do that from cold storage.
one way to do that is to actually do backups. the problem with doing that is that you usually go for full backups, which means that you might be backing up tens of gb on every backup, and that is very awkward to deal with. incremental backups are easier to work with, certainly. but when building highly available systems, i usually don’t bother with full backups. i already have the data in one or two additional locations, after all. i don’t care for quick restore at this point, because i can do that on one of the replicated nodes. what i do care is that i have an offsite copy of the data that i can use if i ever need to. because time to restore isn’t a factor, but convenience and management is, i would usually go with the periodic export system.
this is how this looks like:
the q drive is a shared network drive, and we do an incremental export to it every 10 minutes and a full export every 3 days.
i am aware that this is pretty paranoid setup, we have multiple nodes holding the data, and exports of the data, sometimes i even have each node export the data independently, for the “no data loss, ever”
oh, and about federico’s issue? while he was trying to see if he could fix the database in the event such a thing happen in production (in the 3 live replicas at once), he was already replicating to the test sandbox from one of the production live replicas. with big databases it will take time, but a high-availability setup allows it. so even if the data file appears to be corrupted beyond repair, everything is good now.
* to be fair, that is because i’m actually at the airport waiting for a plane to take me on vacation, but i thought it was funnier to state it this way.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
How Agile Works at Tesla [Video]
A React Frontend With Go/Gin/Gorm Backend in One Project
Tactics and Strategies on Software Development: How To Reach Successful Software [Video]
What Is Envoy Proxy?