4.2.36 · D1 · HinglishOperating Systems

FoundationsJournaling — why, how it works

1,995 words9 min read↑ Read in English

4.2.36 · D1 · Coding › Operating Systems › Journaling — why, how it works

Is page par kuch bhi assume nahi kiya gaya. Main note padhne se pehle, usmein aane wala har word, symbol, aur picture yahan bilkul scratch se build kiya gaya hai. Upar se neeche padho; har block agla block earn karta hai.


0. Disk physically kya hota hai?

"Writes" ki baat karne se pehle hume us cheez ki ek picture chahiye jis par likha ja raha hai.

Figure dekho: shelf chhote boxes ki ek row hai jinke addresses hain (block 9, block 12, block 50…). "Block 50 likhna" matlab box 50 par jaana aur uska poora content replace karna. Ye kyun matter karta hai: topic baar baar "the inode block", "the bitmap block", "the data block" kehta hai — ye sirf is ek shelf par named boxes hain.


1. Atomic write — hardware ki SIRF EK guarantee

Straight rakhne ke liye contrast:

Atomic (guaranteed)
ek sector — all-or-nothing, hamesha.
Atomic (NOT guaranteed)
do ya zyada writes "saath" hoti hain — disk aisi koi promise nahi deta.

2. Filesystem structures — wo boxes jo change hote hain

Ek "create file" ya "append" kai named boxes ko touch karta hai. Tumhe har ek pehchaan aana chahiye.

Figure mein, notes.txt mein ek block append karna teen cheezein ek saath change karta hai: data block (naye bytes), inode (bada size + naye block ka pointer), aur bitmap (naye block ko used mark karo). Topic ko ye kyun chahiye: "ek logical operation = bahut saari writes" literally ye teen arrows alag alag fire hona hai. Crash-consistency problem ek picture mein yahi hai. Zyada poori anatomy ke liye File Systems dekho.


3. Inconsistency — "corrupt" actually kaise dikhta hai

Do contradictions jo main note naam leta hai — ab inhe picture karo:

  • Lost block (left): bitmap kehta hai block 12 used hai, lekin koi inode uski taraf point nahi karta. Space leak ho gaya — hamesha ke liye kisi ke liye reserved. Bitmap likhne ke baad inode likhne se pehle crash hone se hota hai.
  • Dangling pointer (right): directory kehti hai "file → inode 9", lekin inode 9 kabhi likha hi nahi gaya. Usse follow karne par garbage milega — corruption. Inode se pehle directory likhne se hota hai.

Ye concept ki writes ka ek group "all or nothing" hona chahiye iska ek naam hai — Atomicity — aur journaling woh tarika hai jisse filesystem usse manufacture karta hai.


4. Symbol — "strictly pehle khatam hona chahiye"

Main note core rule ko likhta hai. Ye multiplication ya numbers par less-than nahi hai.


5. Symbol — "exactly tab, dono directions mein"

Recovery rule ("if and only if") use karta hai.

Topic ko ye kyun chahiye: ye ek scary "kya crash ne cheezein tod di?" ko ek mechanical yes/no lookup mein badal deta hai — ek block ki presence se.


6. Idempotent — "do baar karna = ek baar karna"


7. Durable vs consistent — trap word

Do promises jinhe log constantly confuse karte hain.


8. Circular log — journal ki shape


Prerequisite map

Disk = numbered boxes

Atomic single-sector write

FS structures: inode bitmap data dir

Inconsistency: lost block, dangling pointer

Symbol happens-before

Write-Ahead Logging rule

Commit block and iff recovery rule

Idempotent replay

Circular log

Consistent vs durable

Journaling topic 4.2.36

Ise aise padho: disk aur uski atomicity guarantee root par hai; structures problem create karti hain (inconsistency); happens-before symbol rule ko power karta hai (WAL); commit block aur idempotency recovery ko correct banate hain — aur ye sab main journaling topic ko feed karta hai.


Equipment checklist

Khud test karo — tum main note ke liye ready ho jab har reveal tumhare apne words se match kare.

Disk kis ek write ki guarantee deta hai jo all-or-nothing ho?
Ek single-sector write — wo ya to poora purana ya poora naya end hota hai, kabhi smeared nahi.
Ek inode kya hai, ek line mein?
Ek index card jo file ke facts (size) aur uske data blocks ke pointers hold karta hai.
Bitmap kya store karta hai?
Har block ke liye ek bit: 1 = in use, 0 = free — poori disk ka used/free map.
Ek inconsistent filesystem ka ek concrete example do.
Lost block (bitmap kehta hai used, koi inode point nahi karta) ya dangling pointer (directory ek unwritten inode ko point karti hai).
Symbol zor se padho aur batao ye kya demand karta hai.
"A happens-before B" — A ko B start hone se pehle durably disk par hona chahiye.
ek ek-taraf se kya zyada deta hai?
Dono directions: present ⇒ replay AUR absent ⇒ discard, isliye har case decide ho jaata hai.
Idempotent define karo aur batao replay ko ye kyun chahiye.
Do baar karna = ek baar karna; recovery doosre crash ke baad blocks re-copy kar sakti hai, isliye repeats harmless hone chahiye.
Consistent vs durable — dono ka difference ek ek line mein?
Consistent = structures contradict nahi karte; durable = ek specific write platter par guaranteed hai.
Journal circular buffer kyun hai aur endless kyun nahi?
Ye ek temporary intent log hai; checkpointed slots free aur reuse ho jaate hain, isse chhota aur recovery fast rehti hai.