LightMySky
به انگلیسی

Concurrency Control: Locks and Snapshots

Two-phase locking makes transactions wait for each other and can deadlock. Multi-version concurrency control gives each transaction a consistent snapshot instead, so readers never block writers, at the price of keeping old versions around.

شروع یادگیری این موضوعبه حساب کاربری نیازی نیست. پیشرفت در همین مرورگر ذخیره می‌شود.

کارهایی که یادگیرنده بعد از این درس می‌تواند انجام دهد

  • Explain what the two phases of two-phase locking are and why the order matters
  • Say what a transaction sees under snapshot isolation and when that view was taken
  • Describe a write conflict that a snapshot system has to detect at commit

۱ · بخوان

Isolation says each transaction must behave as if it has the database all to itself, even while transactions overlap. Two strategies keep that promise. Locking makes transactions wait for each other. Snapshots give each transaction a consistent picture instead, so readers never block writers, at the price of keeping old versions around.

Try it together

With two-phase locking, a transaction first grows: it collects every lock it needs and releases none. Then it shrinks: it releases locks and takes no new ones. The order matters. Releasing early and taking another lock later would let a second transaction slip a change in between, and the first would lose its clean private view.

With snapshots, each transaction reads from a picture of the database taken when it started, no matter what others commit meanwhile. A long report can run to the end without ever blocking a writer. The database pays by keeping old row versions around so every open picture stays readable.

Waiting has one danger: deadlock. Two transactions each hold a lock the other wants, and then neither moves, so the system must spot the standstill and cancel one side. Snapshots have their own clash: two transactions changing the same row from the same picture must be caught at commit, and only one wins. Plain snapshots still allow write skew: changes to different rows that together break a rule both read. Serializable catches it.

Locks make transactions wait in two phases, snapshots let them proceed from private pictures, and each path has its own clash.

Reading written for this dataset.

۲ · ببین

به انگلیسی

دور از صفحه‌نمایش

چاپ کاربرگکاغذ A4، با یک صفحهٔ جواب‌ها برای بزرگ‌ترها. بدون صفحه‌نمایش، بدون اینترنت.

جایگاه این موضوع

اول این‌ها را یاد بگیر

پیوندهای اختیاری

این موضوع راه این‌ها را باز می‌کند

سپس تمرین

۸ سؤال پشت این درس منتظرند، هر کدام با پاسخ توضیح‌داده‌شده. هر پاسخ آسمان را پر می‌کند: ستاره‌ها هنگام یادگیری روشن می‌شوند و وقتی زمان برگشتن است کمرنگ می‌شوند.

شروع یادگیری این موضوع