How atomic is the use of Berkeley DB?

I am writing a simple application with 24 hash elements to be consistent across all programs, so Berkeley DB (DBM) should be well suited for this task.

And this is just for fun.

But I am wondering if you are using it (with Ruby), then when the user presses CTRL-C, execution stops. In this case, the data can not be corrupted?

For example, if the value in the database is 63, and I increase it by 1 (up to 64)

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

so, can CTRL-C appear correctly when it says “Most Important” 1, but 0 were not written? In this case, the value in the database will be 127 instead of 63 or 64. What if it is not Ruby, but in C, and the user uses “close the window” or “kill” to kill the process? Think about it, the hard drive probably writes this byte (or 4 bytes) to the surface of the hard drive right away, so this should not be.

if CTRL-C doesn't cause this to happen, will there be a power outage or am I wearing a power plug to cause this to happen? For example, when a value is first cached in RAM, and when it is written to the hard drive, I start the power plug and the hard drive loses power before it is written 0. I know one million times, this will not happen, but it's just a matter of curiosity .

On the other hand, if my script is equal

  • Decrease Coin Value
  • Give the user a "burger" in your inventory.

then when the user presses CTRL-C, and this happens right between (1) and (2) above, then the user will have fewer coins and no hamburger.

To prevent all this, you need to use a transactional method using SleepyCat, SQLite or MySQL, and will none of this happen?

+3
1

(, Berkley DB) , , , . control-c, CPU. , , - .

, , , , , . , , "", , . , , , , -, , . , , , ext3 .

+2

Source: https://habr.com/ru/post/1723837/


All Articles