I'm writing an easy application with 24 products inside a hash to become persistent across program accomplishments, so Berkeley DB (DBM) ought to be perfect for this.

Which is for entertainment.

However I question if utilizing it (with Ruby), when the consumer presses Control-C, then your execution is stopped. Within this situation, can't the information be all screwed up?

For instance, when the value in DB is 63, and that i increment it by 1 (to become 64)

63 =  111111 (in binary)  
64 = 1000000 (in binary)

so, is the Control-C occur right once the "Most CriticalInch 1 is written and however the 0s haven't been written? For the reason that situation, the worthiness within the DB is going to be 127 rather than 63 or 64. What if it's not Ruby however in C, and also the user uses "close window" or "kill" to get rid of the process? Arrived at consider it, the hard disk most likely write this byte (or 4-byte) towards the hard disk drive surface all at one time, which means this should not happen.

if Control-C will not cause this to occur, a energy outage or myself kicking the energy plug might cause this to occur? For instance, once the value is first cached in RAM, and even though it is written towards the hard disk drive, I kick the energy plug, and also the hard disk manages to lose energy prior to the 0s are written. I understand one out of millions of occasions, this will not happen, but case an issue appealing.

However, if my script would be to

  1. Decrement the gold coin value
  2. Provide the user a "hamburger" in the inventory

when the consumer presses Control-C, also it happens in between (1) and (2) above, then your user may have less gold coin, and obtain no hamburger.

To avoid each one of these from happening, it would be to make use of the transactional method using SleepyCat, SQLite, or MySQL, and none of those may happen?

Not good database system (a category which includes Berkley DB) might be interrupted in the way you suggest, having a value partly up-to-date. Whenever you press control-c you can't interrupt the CPU mid-instruction. There's always some degree of granularity towards the interruption, and well-written databases make the most of that idea to guard from the database ever having an sporadic condition.

The opportunity of data corruption and loss is available once the energy is out, however the particulars of whether data could be lost or corrupted convey more related to the filesystem which the database files are saved. A great journaling filesystem, for example, creates what it's likely to do inside a "journal" then will it, then creates within the journal it made it happen. Therefore if it looses energy throughout a write operation, for example, it appears at its journal to ascertain if there's anything it must finish before permitting accessibility filesystem. It is really an over-simplification, but you will get the particulars by looking at ext3 on wikipedia, for instance.