|
Keeping your MACID data safeIf you are using php, ruby on rails, or one of the other popular web frameworks, your user data is likely in a mysql database. If you have outsourced your server hosting, maybe you have a database administrator that takes backups for you on a regular basis. That probably helps you sleep at night, assuming that you can really trust that your dba is doing their job. As we learned in the previous lesson, if you are using Happstack with MACID, your data is right there on your filesystem, by default in the directory called _local. ~/happs-tutorial>ls _local/happs-tutorial_state/
If there is money on the line, you are going to want to be careful with this directory. When migrating MACID data to a new schema, you are also going to want to be extra cautious. For now, since you don't have any valuable data, the following procedure is probably enough to remind yourself to be careful while learning about Happstack in the tutorial sandbox.
Q: Do you have to shut down the Happstack server every time you migrate data to a new schema? A: No, but online migrations are a topic that will be covered in a future chapter. Q: Is MACID safe? Could I wake up one day with corrupted data under _local and no way to recover from it? A: Let's be realistic. Compared to, say, mysql, Happstack hasn't been stress-tested much in critical high-volume web sites. On the other hand, stress testing is on the docket for the Happstack team and when more data is known I'll be including it in this tutorial. That said, the unix filesystem is pretty good at not losing your data -- a point famously made by startup guru Paul Graham, who created viaweb (now yahoo stores) with all the application state in flat files. If you use Windows or Mac, you probably believe these filesystem are pretty reliable too. Taking a closer look at what is under _local... thartman@thartman-laptop:~/happs-tutorial/_local/happs-tutorial_state>ls -lth
MACID serialization works by writing state change event data one file at a time. At server startup, Happstack "replays" all the information here in the order specified by the file names. This is similar to the database transaction log used by many rdbms systems. So, if I woke up one morning with my Happstack application in a corrupt, non-startable state and my inbox full of angry customer email, probably what I would do is move files, one at a time, out of the serialization directory, last-file created first, and keep trying to restart Happstack. Q: What if my hard drive dies and I can't get my data back? A: Like with any other data storage system, if there's valuable data, you need to be making backups. In the case of Happstack data stored under _local, I would probably be rsyncing the _local directory to a remote server, or maybe multiple remote servers for extra safety. For now I am not worried about securing data, but when that day comes I'm pretty confident I'll be ok. Let's now populate our web application with dummy data. |