Lecture 31: Transactions/1 : Serializability
Summary
TLDRThe script discusses database management systems, focusing on the concept of transactions. It explains how data is physically read, modified, and written back to the database. The video emphasizes the importance of ACID properties—atomicity, consistency, isolation, and durability—necessary for maintaining database integrity during concurrent transaction processing. It also explores the potential issues that arise from concurrent transactions and how they can lead to inconsistent database states if not managed properly.
Takeaways
- 📚 The script discusses database management systems and how data is physically written, read, and transformed within the system.
- 🔍 It focuses on the concept of a transaction, which is a series of operations that the database system performs, ensuring that data is consistent and accurate.
- 💡 The importance of transactions is highlighted, with examples given to illustrate how they manipulate data, such as transferring money between accounts.
- 🔑 The ACID properties of transactions are introduced as crucial for maintaining database integrity: Atomicity, Consistency, Isolation, and Durability.
- 🔄 Atomicity ensures that all parts of a transaction are completed successfully or not at all, maintaining data integrity.
- 🔗 Consistency means that a transaction will transition the database from one valid state to another, without corruption.
- 🏭 Isolation deals with the visibility of transaction operations to other transactions, ensuring that concurrent transactions do not affect each other in an undesired way.
- 🔒 Durability ensures that once a transaction has been committed, it remains so, even in the event of a system failure.
- 🤝 The script also touches on the challenges of concurrent transactions, such as ensuring that multiple users operating on the same data do not create conflicts or inconsistencies.
- 💻 The concept of schedules and serializability is discussed, which is a method to ensure that concurrent execution of transactions does not lead to inconsistent results.
Q & A
What is the primary focus of the discussion in the script?
-The primary focus of the discussion is on database management systems, specifically how data is accessed and the concept of transactions within these systems.
What is a transaction in the context of database systems?
-A transaction in database systems refers to a sequence of operations performed as a single logical unit of work. It involves reading, changing, and then writing data, and is crucial for maintaining database consistency and integrity.
Why is it important to focus on what happens during a database transaction?
-Focusing on what happens during a database transaction is important because it helps ensure the accuracy and consistency of data. It also ensures that the database can recover from any errors or failures that may occur during the transaction process.
What are the four key properties of a transaction known as ACID properties?
-The four key properties of a transaction, known as ACID properties, are Atomicity, Consistency, Isolation, and Durability. These properties ensure that the database maintains its integrity and remains consistent even in the event of errors or concurrent access by multiple users.
What does Atomicity in transactions ensure?
-Atomicity ensures that all operations within a transaction are completed successfully; if one operation fails, the entire transaction is rolled back, leaving the database as if the transaction had never occurred.
How is Consistency maintained in database transactions?
-Consistency is maintained by ensuring that a transaction brings the database from one valid state to another while adhering to all defined rules, constraints, and prerequisites.
What is the purpose of Isolation in database transactions?
-Isolation ensures that concurrent transactions are executed in a way that the outcome is the same as if they were executed sequentially, preventing inconsistent states from being seen by other transactions.
Why is Durability important in database transactions?
-Durability ensures that once a transaction has been committed, it remains so, even in the event of power loss, crashes, or errors. The changes made by the transaction become permanent and are not lost.
How do concurrent transactions affect the database?
-Concurrent transactions can lead to issues like data inconsistency if not managed properly. They can interfere with each other, leading to scenarios where the database's state may not reflect the expected outcomes, thus violating ACID properties.
What is the significance of the term 'interleaving' in the context of concurrent transactions?
-Interleaving refers to the execution of instructions from different transactions in an order that is not sequential. This can lead to inconsistent database states if not properly managed, as transactions may depend on the order of operations.
How can database systems ensure that transactions do not violate ACID properties despite concurrent executions?
-Database systems can ensure that transactions do not violate ACID properties by implementing mechanisms such as locks, transaction queues, and write-ahead logging. These techniques help in controlling access to data and maintaining the order and integrity of transactions.
Outlines
💾 Database Management and Transaction Basics
This paragraph introduces the concept of database management systems and how data is physically created. It discusses the process that occurs when data is accessed within a database system, focusing on the read, transform, and write operations. The paragraph then delves into the idea of a transaction, an operation that occurs within the database system, which was previously discussed in the context of indexing. It sets the stage for understanding the concept of transactions and the various issues related to their concurrent execution, such as the need for transactions to be atomic and consistent.
🔄 Challenges of Concurrent Transactions
The paragraph explores the complexities that arise when multiple transactions occur concurrently within a database system. It uses the example of transferring money between accounts to illustrate how transactions must be executed independently yet consistently. The concept of a concurrent execution means that transactions are not happening on separate machines but must be managed within the same database system. The paragraph emphasizes the need for transactions to be executed in a way that ensures database consistency and integrity, despite the potential for hardware or software failures that could affect the execution of a transaction partway through.
🔒 Ensuring Atomicity and Consistency in Transactions
This section delves into the necessity of atomicity and consistency in transaction processing. It explains that once a transaction starts, it must complete fully to ensure that the database remains in a consistent state. The paragraph uses a hypothetical scenario where a system crash occurs partway through a transaction to illustrate the importance of atomicity. It also discusses the need for consistency constraints, such as maintaining the balance of accounts in a transfer, to ensure that the database's integrity is preserved even when transactions are executed concurrently.
🔗 Isolation and Durability in Transaction Processing
The paragraph discusses the importance of isolation and durability in transaction processing. Isolation ensures that the effects of concurrent transactions are properly ordered, preventing inconsistencies that could arise from interleaved execution. Durability, on the other hand, ensures that once a transaction has been successfully completed, its changes persist even in the event of subsequent system failures. The paragraph explains these concepts using the acronym ACID, which stands for Atomicity, Consistency, Isolation, and Durability, and emphasizes that transactions must adhere to these properties to maintain database integrity.
📈 Impact of Concurrent Execution on System Performance
This paragraph examines how concurrent transaction execution can impact system performance. It highlights the potential benefits of increased throughput and reduced response times due to the ability to perform multiple operations simultaneously. The paragraph provides examples of how a transaction might be processing on the CPU while another is reading or writing to the disk, showcasing the efficiency gains from concurrent processing. However, it also notes the need to balance these performance improvements with the maintenance of database consistency and the ACID properties.
🔁 Transaction Scheduling and Interleaving
The final paragraph explores the concept of transaction scheduling and how different interleavings of transaction instructions can lead to various outcomes, including both consistent and inconsistent states. It uses examples to illustrate how the order in which transactions are executed can affect the final state of the database, emphasizing the importance of proper scheduling to maintain consistency. The paragraph concludes by highlighting the challenges of ensuring consistent database states when transactions are executed concurrently and the need for careful management to uphold the ACID properties.
Mindmap
Keywords
💡Database Management
💡Transaction
💡Atomicity
💡Consistency
💡Isolation
💡Durability
💡Concurrency Control
💡Rollback
💡Commit
💡Interleaving of Transactions
💡Schedule
Highlights
Introduction to database management and how data can be physically manipulated within a system.
Explanation of what happens when data is accessed in a database system, focusing on the process of reading, transforming, and writing data.
Definition of a transaction in database systems as a series of operations that must be executed in a certain order.
Discussion on the concept of transactions and the importance of their current execution in relation to consistency.
Example of a transaction involving transferring money between two accounts, illustrating the process of debit and credit.
Clarification of the atomic nature of transactions, ensuring that all parts of a transaction are completed successfully or not at all.
Importance of consistency in database systems and how it is affected by the values of data.
Explanation of the need for isolation in transactions to prevent inconsistencies when multiple transactions occur concurrently.
Discussion on the durability of transactions, ensuring that once a transaction is successfully completed, it remains so even in the event of system failures.
Introduction to the ACID properties of transactions: Atomicity, Consistency, Isolation, and Durability.
Exploration of the states a transaction goes through, from active to partially committed, and the implications for database consistency.
Example of how a transaction can fail and the need for rollback mechanisms to restore the database to a consistent state.
Discussion on the benefits of concurrent execution of transactions, such as increased throughput and reduced response time.
Challenges of concurrent transaction execution, including the potential for interference and the violation of ACID properties.
Explanation of how different schedules of transaction execution can lead to different outcomes, impacting database consistency.
Conclusion on the necessity of maintaining a consistent database state and the challenges that come with concurrent transaction processing.
Transcripts
ডাটাবেস ম্যানেজমেন্ট সিস্টেমের করতে পারি।
আমরা দেখেছি কিভাবে ডেটা ফিজিক্যালি
করা যায়। এখন আমরা যখন একটি ডাটাবেস
সিস্টেমে ডেটা অ্যাক্সেস করা হয়, এটি পড়া
হয়, স্থানীয়ভাবে পরিবর্তিত হয় এবং
তারপরে লেখা হয় তখন কী হয় তার উপর
আমরা ফোকাস করব। খুব সহজভাবে এটি
এমন একটি অপারেশন যা ডাটাবেস সিস্টেমে
ঘটতে থাকে, যা আমরা চিহ্নিত করব যাকে
আমরা ট্রাঞ্জাকসন বলি।
এটাই আমরা গত সপ্তাহে করেছিলাম ইনডেক্স
নিয়ে আলোচনা করেছিলাম।
এবং আমরা এখন ট্রাঞ্জাক্সনের এই ধারণাটি বোঝা
শুরু করি, এবং আমরা ট্রাঞ্জাক্সনের
কঙ্কারেন্ট এক্সিকিউসনের সাথে সম্পর্কিত বিভিন্ন
সমস্যাগুলি দেখব। সুতরাং, আমরা এর অর্থ
কী তা আরও বিশদে ব্যাখ্যা করব।
এবং এই 3টি বিষয় যা আমরা এই মডিউলে ফোকাস
করব।
আসুন প্রথমে একটি ট্রাঞ্জাকসনের অর্থ
কী তা দেখে নেওয়া যাক। আমরা বলি ট্রাঞ্জাকসনের
হল প্রোগ্রাম এক্সিকিউশনের ।
সুতরাং, এটি সম্ভবত কিছু স্থানীয় পরিবর্তন
করে এবং তারপরে এটি আবার লেখে। এখানে
একটি ট্রাঞ্জকসনের একটি উদাহরণ রয়েছে।
সেই অপ্রয়োজনীয় বিশদ বিবরণ ছাড়া
যেটা সেখানে রয়েছে যে দুটি অ্যাকাউন্ট
কত। সুতরাং, যে প্রথম
ইন্সট্রাকশনটা করি। অ্যাকাউন্ট ব্যালেন্সে
যেখানে এটি 200 ডলার ছিল, এখন এই 50 ডলার
ডেবিট করে 100 এবং 50 ডলার হয়ে যাবে।
তারপর আমাদের অ্যাকাউন্ট B-তে ক্রেডিট প্রক্রিয়া
করতে হবে। সুতরাং, চতুর্থ নির্দেশে
আমরা B কে রিড করি। আসুন আমরা ধরি যে
অ্যাকাউন্ট B-এর বর্তমান ব্যালেন্স ছিল 300
ডলার, তারপর B কে রিড করলে B-কে 300 হিসাবে
অস্থায়ী ভেরিয়েবল করবে। ক্রেডিট 300;
অর্থাৎ, আমরা 50 ডলার যোগ করি আর এটি 350 হয়ে
যায়, এবং তারপর আমরা B এর অ্যাকাউন্টে
ব্যালেন্সটা লিখি। অ্যাকাউন্টে ব্যালেন্স
এখন 350 ডলার হবে। সুতরাং, এই ছয়টি ইন্সট্রাকশনের
এই সম্পূর্ণ ক্রমটিকে একটি ট্রাঞ্জাকসন
বলা হয়। এবং আপনি বুঝতেই পারছেন যে
অ্যাকাউন্ট A থেকে B এর একাউন্টে 50 ডলার
স্থানান্তর করাই আমাদের লক্ষ্য ছিল,
এই ছয়টি ইন্সট্রাকশন এই ক্রমে কার্যকর
করতে হবে যাতে আমরা পছন্দসই ফলাফল পেতে
পারি। এখন প্রশ্ন হল; এটি বেশ সহজ, এটি
একটি খুব সাধারণ নিম্ন-স্তরের প্রোগ্রামের
মতো। তবে দুটি প্রধান সমস্যা রয়েছে যা
আমাদের মোকাবেলা করতে হবে। প্রথমত,
একবার প্রথম ইন্সট্রাকসনটি শুরু হলে তার নিশ্চয়তা
কী? কি নিশ্চয়তা রয়েছে যে সেটা ইন্সট্রাকসন
6 পর্যন্ত চলবে? ডিস্কের মধ্যে কিছু
ব্যর্থতা থাকতে পারে হার্ডওয়্যার ব্যর্থ
হতে পারে সিস্টেম -এ কাজ করছি, আমি অন্য
পক্ষের কাছে স্থানান্তর করছি যাকে আমাকে
টাকা দিতে হবে। একই সময়ে, আরও বেশ কয়েকজন
ব্যক্তি তাদের অ্যাকাউন্টে, নিজ নিজ অ্যাকাউন্টে
অপারেশন করছেন। অন্যান্য অনেক অপারেশন
ডাটাবেস থেকেই হতে পারে। উদাহরণস্বরূপ,
যখন আমি একটি স্থানান্তর করছি একই সময়ে ডাটাবেস
আমার অ্যাকাউন্টে কিছু ত্রৈমাসিক সুদ
জমা করতে পারে। এই সমস্ত ট্রাঞ্জাকসনগুলো,
প্রকৃতপক্ষে কঙ্কারেন্টলি এক্সিকিউট হয়, যার
অর্থ হল, তারা সব স্বাধীনভাবে এক্সিকিউট করছে।
তারা একই CPU ব্যবহার করে, কিন্তু তারা
একই সময়ে ফলাফল অর্জন করে। সুতরাং,
ট্রাঞ্জাকসনগুলো আসলে আলাদা মেশিনে
ঘটছে এমন নয়, ট্রাঞ্জাকসনগুলো একই ডাটাবেসে কার্যকর
হতে হবে। তাদের একটি কঙ্কারেন্ট
পদ্ধতিতে ঘটতে হবে, যেটি আমরা দেখতে
পাচ্ছি এটি একটি কঙ্কারেন্ট পদ্ধতি
কারণ তারা একসাথে ঘটে। এবং যখন এটি
চলছে, আমরা কীভাবে নিশ্চিত করব, তবে
একটি সিপিইউ বলি।
সুতরাং, আমরা প্রথমে একটি ট্রাঞ্জাকসনের
কিছু প্রয়োজনীয় বৈশিষ্ট্য রেখে লক্ষ্যমাত্রা
নির্ধারণ করি। প্রথম প্রয়োজন হল এটোমিসিটি
। আবার ধরুন একই ট্রাঞ্জাকশনটি
দেখুন, ধরুন সিস্টেম ক্র্যাশ হয়ে গেল
প্রথম তিনটি ইন্সট্রাকশনের পরে এবং চতুর্থ ইন্সট্রাকশনটি
ঘটতে চলেছে এমন সময়। তো, কি হবে? ইতিমধ্যে
A অ্যাকাউন্ট থেকে 50 ডলার ডেবিট করা
হয়েছে এবং অ্যাকাউন্ট B-তে এখনও সেই 50 ডলার
জমা হয়নি। সুতরাং, এই মুহুর্তে, যদি
ট্রাঞ্জাকশন সিস্টেমে ব্যর্থতা ঘটে তবে
কেবলমাত্র 50 ডলার সিস্টেম থেকে অদৃশ্য
হয়ে যাবে আর এটির কোন অস্তিত্ব থাকবে
না। সুতরাং, মৌলিক প্রয়োজনীয়তা হল
যে একবার একটি ট্রাঞ্জাকশন শুরু হলে এটি সম্পূর্ণরূপে
ঘটতে হবে এই ক্ষেত্রের হিসাবে ছয়টি ইন্সট্রাকশনই
করা উচিত বা এগুলির কোনটিই করা উচিত
নয়৷ তাহলে হয় সবগুলিই
হবে নয়তো কোনটিরই প্রয়োজন নেই যা
আমরা বলি এটির মতো। সুতরাং, একটি উপায়ে
ট্রাঞ্জাকশনগুলি ইনভিসিবল বা এটোমিক
এবং এটিই হল এটোমিসিটির প্রয়োজনীয়তা।
দ্বিতীয় প্রয়োজনীয়তাকে বলা হয় কন্সিস্ট্যান্সি
মানগুলির কন্সিস্ট্যান্সি প্রভাবিত হওয়া উচিত
নয়। সুতরাং, যদি আমাদের
কিছু নির্দিষ্ট ইন্টিগ্রিটি কন্সট্রেইন্ট ইত্যাদির
কথা বলেছি। এবং ইমপ্লিসিট ডোমেন ইন্টিগ্রিটি
কন্সট্রেন্ট থাকতে পারে। উদাহরণ স্বরূপ,
এই অ্যাকাউন্টিং এর ক্ষেত্রে যদি
আমরা ট্রান্সফার করি, তাহলে অ্যাকাউন্ট
A থেকে অ্যাকাউন্ট B-এ ট্রান্সফার করার
সময় অ্যাকাউন্ট A এবং অ্যাকাউন্ট
B-এর ব্যালেন্সের যোগফল ট্রান্সফারের
আগে এবং ট্রান্সফারের পরে একই হতে হবে।
সুতরাং, টাকা অদৃশ্য হওয়া উচিত নয়, তা
তৈরি হওয়াও উচিত নয়। আমরা ধরে নিই
যে একটি ট্রাঞ্জাকসন যখন এটি এক্সিকিউট
করতে শুরু করে। এটি অবশ্যই একটি কন্সিস্ট্যান্স
ডাটাবেসে শুরু হবে যা প্রতিটি ক্ষেত্রে
সঠিক। ট্রাঞ্জাকসনের সময় সাময়িক অসঙ্গতি
হতে পারে। উদাহরণস্বরূপ, আপনি যদি এই সময়ে
ইন্সট্রাকশন 4 বা ইন্সট্রাকশন 5 দেখেন,
A অ্যাকাউন্টটি ইতিমধ্যে 50 ডলার ডেবিট হয়েছে
এবং B অ্যাকাউন্টটিতে সেই 50 ডলার দ্বারা
ক্রেডিট করা হয়নি। সুতরাং, আপনি যদি
ইন্সট্রাকশন 4 যোগ করেন আপনি যদি দেখার
চেষ্টা করেন, A এবং অ্যাকাউন্ট B এ ব্যালেন্সের
যোগফল কত আপনি দেখতে পাবেন যে যোগফল 50
ডলার কম। কিন্তু যখন ট্রাঞ্জাকসন
সম্পূর্ণ হয়, এটি ছয়টি ইন্সট্রাকশন
সম্পূর্ণ হয়, তারপর আবার, যোগফল শুরুতে
যেমন ছিল তেমনই হবে। সুতরাং, এক্সিকিউসনের
শুরুতে, এবং একটি সফল এক্সিকিউসনের
শেষে ডাটাবেসটি অবশ্যই কন্সিস্ট্যান্ট
হতে হবে এর মধ্যে ক্ষণস্থায়ী ইকনন্সিস্ট্যান্সি
থাকতে পারে। সুতরাং, একে বলা হয় কন্সিস্ট্যান্সি
প্রয়োজন।
তৃতীয়টি আবার প্রথমে বাম দিকের উদাহরণটি
দেখুন T1 একটি ট্রাঞ্জাকসন যার কথা আমরা বলছি।
এবং ধরুন আরেকটি ট্রাঞ্জাকসন T2 আছে
যা একই সাথে ঘটে। যদি এটি কঙ্কারেন্টলি
ঘটে তাহলে ট্রাঞ্জাকসন T2 তে ধরুন আমাদের
তিনটি ইন্সট্রাকশন রিড রয়েছে। সুতরাং,
এটি A এবং B এর অ্যাকাউন্টের ব্যালেন্স পড়ার
চেষ্টা করে এবং তাদের যোগফল প্রিন্ট করে।
স্পষ্টতই, যদি ট্রানঞ্জাকসন T2 কে অনুমোদন দেওয়া
হয় ট্রানঞ্জাকসন T2-এর এই তিনটি ইন্সট্রাকশন
যদি তাদের এক্সিকিউট করার অনুমতি দেয়;
ট্রানঞ্জাকসন T1 এর ইন্সট্রাকশন 3 এবং
ইন্সট্রাকশন 4 এর মধ্যে, তাহলে T2 A + B
এর একটি যোগফল প্রিন্ট করবে যা শুরুতে A +
B - 50 ছিল। সুতরাং, এটি এমন হবে যেন কিছু
ইনকন্সিস্ট্যান্সি ঘটেছে।
আইসোলেসন প্রয়োজনীয়তা বলে যে যখন ট্রাঞ্জাকসনগুলি
কঙ্কারেন্টলি ঘটে, তখন ট্রাঞ্জাকসনগুলির
নেট প্রভাব এমন হওয়া উচিত যেন সেগুলিতে
প্রথমে T1 ঘটেছে এবং তারপর T2 ঘটবে৷ প্রথমে
T2 এক্সিকিউট করবে এবং তারপর T1 এক্সিকিউট
করবে। যদিও তারা একযোগে বা মিশ্র
পদ্ধতিতে চালাতে পারে, ডাটাবেসের
এই ধরনের ইনকন্সিস্ট্যান্সির ফলাফল অন্যান্য ট্রাঞ্জাকশনের
জন্য হওয়া উচিত নয়। সুতরাং, একে
বলা হয় আইসোলেসন প্রয়োজনীয়তা।
সুতরাং, ট্রাঞ্জাকশনগুলিকে যথাযথভাবে আইসোলেটেড
, আপনার কর্মক্ষমতা খুব কম হবে। কঙ্কারেন্টলি
ঘটার জন্য আমাদের ট্রাঞ্জাকসন প্রয়োজন,
তবে আইসোলেসন অবশ্যই সিদ্ধ হতে হবে।
চতুর্থটিকে ডিউরেবিলিটি ব্যর্থতা এলেও তা
অব্যাহত থাকতে হবে। A থেকে B তে 50 ডলার স্থানান্তরের
এই ট্রাঞ্জাকসনটি সফলভাবে সম্পন্ন
হয়েছে ছয়টি ইন্সট্রাকশন এক্সিকিউট করা হয়েছে
এবং টাকা স্থানান্তর করা হয়েছে, এটি অব্যাহত
থাকবে যদিও পরবর্তীকালে ডাটাবেসে কিছু ত্রুটি
কিছু ব্যর্থতা ঘটবে। সুতরাং, পরিবর্তনগুলি
অবশ্যই ডিউরেবল হতে হবে।
সুতরাং, এই চারটি বৈশিষ্ট্যকে একত্রে
একটি ট্রাঞ্জাকসন ব্যবস্থার অ্যাসিড
বৈশিষ্ট্য বলা হয়। অ্যাসিড মানে a হল
এটোমিসিটির জন্য এই যে হয় ট্রাঞ্জাকসনের
সমস্ত ক্রিয়াকলাপগুলি ডাটাবেসে সঠিকভাবে
প্রতিফলিত হয় বা তাদের কোনটিই প্রতিফলিত
হয় না কন্সিস্ট্যান্সি c হল ট্রাঞ্জাকসনের
কন্সিস্ট্যান্সি এক্সিকিউসনে আইসোলেসন
ডাটাবেসের ধারাবাহিকতা রক্ষা করে।
আইসোলেসন প্রয়োজন, যদি একাধিক ট্রাঞ্জাকসন
কঙ্কারেন্টলি ঘটা, ট্রাঞ্জাকসন Ti, Tj কঙ্কারেন্টলি
ঘটছে অর্থাৎ Ti-এর কিছু ইন্সট্রাকশন
ঘটবে তারপর Tj-এর কিছু ইন্সট্রাকশন ঘটবে
তারপর Ti-এর কিছু ইন্সট্রাকশন আবার ঘটবে এবং এইভাবে
চলবে। তারপরেও, চূড়ান্ত ফলাফলটি এমন হওয়া
উচিত যেন Ti ঘটেছে তার পরে Tj বা Tj প্রথমে
এক্সিকিউট হয়েছে তারপরে Ti । আইসোলেসন
i হল আইসোলেসনের জন্য এবং পরিশেষে, ডিউরাবিলিটি
একবার সফলভাবে ট্রাঞ্জাকসন সম্পন্ন হলে ডাটাবেসের
পরিবর্তনগুলি অব্যাহত থাকা উচিত। সুতরাং,
A C I D অ্যাসিড বৈশিষ্ট্যগুলি ট্রাঞ্জাকসন ব্যবস্থার
গুরুত্বপূর্ণ বৈশিষ্ট্য এবং সর্বদা সিদ্ধ
হতে হবে। পরবর্তীতে আমরা যা
দেখি তা হল ট্রাঞ্জাকসনের প্রতিটি ইন্সট্রাক্সন
দিয়ে যেতে যেতে।
ট্রাঞ্জাকসনটি বিভিন্ন স্টেটের একটিতে ঘটেছে।
ট্রাঞ্জাকসন শুরু হওয়ার সাথে সাথে
ট্রাঞ্জাকসনটি শুরু হওয়ার সাথে সাথে
এটি একটি সক্রিয় অবস্থায় থাকে। সুতরাং,
বিবেচনা করুন যে এই একই ট্রাঞ্জাকসন
করা হয়েছে পড়ুন এটি সক্রিয় অবস্থায়
রয়েছে এটি A কে 50 দ্বারা হ্রাস করেছে এটি
সক্রিয় অবস্থায় রয়েছে ইত্যাদি।
সুতরাং, যতক্ষণ এটি এক্সিকিউট হচ্ছে,
এটি সক্রিয় অবস্থায় রয়েছে, যদি না এটি
প্রথমে সাফল্যের কথা বলে।
সুতরাং, একবার এটি শেষ কাজটা এক্সিকিউট
করার পরে, শেষ ইন্সট্রাকসনটি যা এখানে ইন্সট্রাকসন
6, এটি এমন অবস্থায় রয়েছে যাকে বলা
হয় পারসিয়ালি কমিটেড । সুতরাং, এটি সফলভাবে
সমস্ত ইন্সট্রাকসন সম্পন্ন করতে পেরেছে।
অথবা এটি এমন ঘটতে পারে যে সক্রিয়
অবস্থায় থাকার সময়, বা পারসিয়ালি কমিটেড
অবস্থায় থাকার সময় কিছু ত্রুটি ঘটেছে
যাতে স্বাভাবিক এক্সিকিউসন আর এগোতে পারে না।
তারপর, ট্রাঞ্জাকসনটি ব্যর্থ অবস্থায়
আসে। ব্যর্থ অবস্থায় থাকা একটি ট্রাঞ্জাকসন
শেষ পর্যন্ত বাতিল হয়ে যাবে, কারণ কখন
ব্যর্থ হয়েছে তা জানা যায় না।
সুতরাং, স্বাভাবিকভাবেই ব্যর্থতার সময় এই
ট্রাঞ্জাকশনের চতুর্থ ইন্সট্রাকশনের একটি
ইনকন্সিস্ট্যান্সি ব্যর্থতা ঘটতে পারে
এবং আপনি ইতিমধ্যেই উল্লেখ করেছেন। যে
A থেকে ইতিমধ্যেই 50 ডলার ডেবিট করা
হয়েছে এবং B তে 50 ডলার ক্রেডিট করা হয়নি,
তাই এটি একটি ইনকন্সিস্ট্যানট স্টেটে রয়েছে। ধরুন
ব্যর্থতা যদি ট্রাঞ্জাকশনটি একটি ব্যর্থ স্টেটে
থাকে তখন এটি আমাদের রোলব্যাক করতে হবে,
আমরা যে পরিবর্তনগুলি করেছি সেগুলি পূর্বাবস্থায়
ফিরিয়ে আনতে হবে৷ A থেকে ডেবিট করা 50
ডলার আমাদের ফেরত দিতে হবে, যাতে আমরা
একটি কন্সিস্ট্যান্ট স্টেটে পৌঁছাতে পারি।
এবং একবার আমরা সফলভাবে এই রোলব্যাকটি সম্পন্ন
করার পরে, ট্রাঞ্জাকসনটি একটি বাতিল স্টেটে
চলে যায় অর্থাৎ এটি ঘটে না, এবং এর
পরে আপনার কাছে দুটি পছন্দ রয়েছে হয়
আপনি ট্রাঞ্জাকসনটি পুনরায় চালু করতে
পারেন, অথবা আপনি ট্রাঞ্জাকসনটি সম্পূর্ণভাবে
বন্ধ করতে পারেন, বিভিন্ন পরিস্থিতির
উপর নির্ভর করে এটা করা হয়। অন্য ক্ষেত্রে
যদি এটি পার্সিয়ালি কমিটেড হয়, তাহলে
সমস্ত ইন্সট্রাকশন সম্পন্ন হয়েছে,
এখন হিসাবরক্ষণ এবং অন্যান্য কাজের প্রয়োজন
ছিল। পার্সিয়ালি কমিটেডে যদি কিছু
ব্যর্থতা থাকে তবে এটি ব্যর্থ স্টেটে
আসে এবং তারপরে আমি ইতিমধ্যেই ব্যাখ্যা
করেছি যে সেটা বাতিল স্টেটে চলে যায়।
অথবা এটি আসলে সমস্ত পরিবর্তনগুলি সঠিকভাবে
কমিট করে এবং এটি সফলভাবে সম্পন্ন
হয়েছে এবং এটি একটি কমিটেড স্টেটে যায়
যেখানে ট্রাঞ্জাকসনটি সফলভাবে শেষ হয়েছে।
সুতরাং, প্রতিটি ট্রাঞ্জাকসনই এই
অবস্থার মধ্য দিয়ে যাবে যেকোন সময়ে
একটি ট্রাঞ্জাকসন স্টেটগুলির একটিতে
হবে এবং এক্সিকিউসন করার উপর নির্ভর
করে এটি সেই স্টেটেই থাকবে বা স্টেটের
পরিবর্তন হবে৷
সুতরাং, ট্রাঞ্জাকসনের জন্য এই স্টেটের
রূপান্তর চিত্রটি খুবই গুরুত্বপূর্ণ,
এবং আপনাকে অবশ্যই ভালভাবে বুঝতে হবে
যে কী ঘটছে এবং এই বিশেষ স্টেটের রূপান্তরটি
ঠিক আছে মনে রাখবেন। এখন আসুন প্রকৃত
বাস্তব এক্সিকিউসন পরিস্থিতিটি দেখি।
সুতরাং, কঙ্কারেন্ট এক্সিকিউসনের পরিস্থিতিতে,
আমাদের কাছে যা আছে আমাদের একাধিক ট্রাঞ্জাকসন
রয়েছে যা একই সময়ে সিস্টেমে চলে। এটির
সুবিধাগুলি হল এটি থ্রুপুট বৃদ্ধি করবে,
এটি প্রসেসর উপলব্ধি বাড়াবে। উদাহরণস্বরূপ,
যখন একটি ট্রাঞ্জাকসন CPU-তে কিছু ক্রিয়াকলাপ
করছে, ডিস্কে কিছু অভ্যন্তরীণ গণনা
চলছে তখনও অন্য ট্রাঞ্জাকসনের মাধ্যমে পড়ার জন্য
সেটা অ্যাক্সেস করা যেতে পারে বা কিছু
মান লেখাও যেতে পারে। সুতরাং, থ্রুপুট
বাড়বে এবং গড় প্রতিক্রিয়ার সময়ও হ্রাস পাবে
কারণ একটি ছোট ট্রাঞ্জাকসন হতে পারে যা যদি সিরিয়ালি
করা হয় তবে এটিকে একটি দীর্ঘ ট্রাঞ্জাকসনের
জন্য অপেক্ষা করতে হবে, যা ইতিমধ্যেই
কার্যকর করা হয়েছে, কিন্তু যদি আমরা
অনুমতি দিই কঙ্কারেন্ট এক্সিকিউসনের তাহলে
সেই দীর্ঘ ট্রাঞ্জাকসনের মধ্যে ছোট ট্রাঞ্জাকসনটি
সম্পাদন করতে কয়েকটি চক্র নেওয়া যেতে
পারে এবং গড় প্রতিক্রিয়া সময় উন্নত হবে।
সুতরাং, এটাই আমাদের মৌলিক চাহিদা। স্বাভাবিকভাবেই
আমাদের এটি একটি নিয়ন্ত্রিত পদ্ধতিতে
করতে হবে যাতে আমরা নিশ্চিত করতে পারি
যে ডাটাবেসের কন্সিস্টেন্সি এবং অ্যাসিড বৈশিষ্ট্যগুলি
বজায় রাখা হয়।
তাহলে, এই কাজ করার জন্য আমরা যাকে বলা
হয় সিডিউল ট্রাঞ্জাকসন সেটের জন্য এটির
একটি সেট সংজ্ঞায়িত করবে। এবং এটি অবশ্যই
সেই ট্রাঞ্জাকসনের সমস্ত নির্দেশাবলী
নিয়ে গঠিত। এবং একটি নির্দিষ্ট ক্রমে,
এবং মৌলিক প্রয়োজনীয়তা হল যে এই ক্রমানুসারে
এই সময়সূচীতে, এই প্রদত্ত ট্রাঞ্জাকসনের
যেকোনো নির্দেশের মূল ক্রম, আপনার একটি
পৃথক ট্রাঞ্জাকসনের সংরক্ষণ করা আবশ্যক।
কিন্তু বিভিন্ন ট্রাঞ্জাসন থেকে ইন্সট্রাকশন
ইন্টারলিভ করব ঠিক আছে।
সুতরাং, আসুন একটি উদাহরণ নেওয়া যাক,
আবার আমরা একই উদাহরণে ফিরে যাচ্ছি। সুতরাং,
আমাদের দুটি ট্রাঞ্জাকসন T1 এবং T2 আছে। T1 A থেকে
B তে 50 ডলার স্থানান্তর করে যেমনটি আমরা
দেখেছি। এবং T2 A থেকে B তে ব্যালেন্সের
10 শতাংশ স্থানান্তর করে। একটি ট্রাঞ্জাকসন
50 ডলার ডেবিট করে একটি ট্রাঞ্জাকসন
A থেকে B এর অ্যাকাউন্ট ব্যালেন্সের 10 শতাংশ
ডেবিট করে। সুতরাং, যদি সেগুলি ক্রমিকভাবে
চালানো হয় যেমন আপনি এখানে দেখতে
পাচ্ছেন আমরা সিরিয়ালি সেগুলিকে কার্যকর
করছি। প্রথমে আপনি আপনার সম্পূর্ণ T1
এক্সিকিউট করছেন, এবং একবার এটি কমিটেড
হয়ে গেলে, এটি সফলভাবে শেষ হয়ে গেলে T2 এক্সিকিউট
করছে। সুতরাং, শুরুতে যদি
আমরা ধরে নিই যে এটি কেবল একটি অনুমান।
আমরা যদি শুরুতে ধরে নিই যে A এর 100 ডলার
এবং B এর 200 ডলার ছিল, তাহলে যোগফল ছিল
300 ডলার। সুতরাং, যদি A রিড হয় 100 ডলার পড়া
হয় তবে এটি 50 হয়ে যায় তারপর আপনি
এই A লিখুন। সুতরাং, আপনি যখন এখানে থাকবেন,
আপনি দেখতে পাচ্ছেন, এটি আপনার কাছে থাকবে
কারণ A 100 থেকে 50 এ পরিবর্তিত হয়েছে কারণ আপনি
B ডেবিট করেছেন B-তে কিছুই ঘটেনি, যোগফল
হল 250। সুতরাং, আপনি দেখতে পাচ্ছেন তাই
আমি বিভিন্ন রঙ দেখিয়েছি যা আপনি 250-এ দেখতে
পাচ্ছেন। ডাটাবেসের এই অবস্থা সাময়িকভাবে
ইনকন্সিস্ট্যান্ট কারণ যোগফল 300 থেকে
আলাদা হয়ে গেছে। তারপর এটি B কে রিড
করে এটি 200 যোগ করে সেই 250 এটি B তে লেখে।
আপনি এই বিন্দুতে আসেন যেখানে এই লেখার
পরে, যখন এই B তে লেখার পরে কমিট হচ্ছে।
তারপর T1 আসলে সম্পূর্ণ হয়েছে, এবং 50 ডলার
B এর অ্যাকাউন্টে স্থানান্তরিত হয়েছে,
এবং যোগফল আবার 300-এ ফিরে আসে তাই, সামঞ্জস্য
রক্ষা করা হয়। তারপর ট্রাঞ্জাকসন 2 শুরু
হয়। তাই, A কে রিড করা হয় 50 ডলার অস্থায়ীভাবে
পড়া হয় আপনি সেই 50 ডলারের 10 শতাংশ গণনা
করেন আপনি a কে 5 ডলার কমিয়ে সেটা আবার
লেখেন। সুতরাং, আপনি যখন
এটি লিখবেন, আপনি 45 ডলার লিখবেন। আবার,
স্বাভাবিকভাবেই যোগফল 5 ডলার কম হয়ে
যায়, আপনি এই টেম্পে ভাবে ইনকন্সিস্ট্যান্ট
হয়ে ওঠে। তারপর আপনি B কে রিড করবেন,
সেই অস্থায়ী 5 ডলারকে B-তে ফেরত দিয়ে লিখবেন
এবং তারপর আপনি শেষ পর্যন্ত, যখন আপনি
এখানে B তে লিখবেন তখন 200 এবং 50 থেকে আপনি
5 ডলার যোগ করেছেন 255, এবং আবার যোগফল
300 হয়ে গেছে আপনি আবার ফিরে এসেছেন
কন্সিস্ট্যান্সি স্টেটে।
সুতরাং, আপনি এই প্রক্রিয়াটির মাধ্যমে দেখতে পাচ্ছেন
যে যখন ট্রাঞ্জাকসনগুলি আসলে সিরিয়াল পদ্ধতিতে
ঘটে, তখন জিনিসগুলি এভাবেই এগিয়ে যাবে,
যেটা বেশ বোধগম্য।
সুতরাং, এটি একটি অন্য সিডিউল যা আপনি
দেখতে পাচ্ছেন, তবে এটি এখানে একটি সিরিয়াল
সিডিউল দেখতে পারেন, কিন্তু শেষ পর্যন্ত
ডাটাবেসটি একটি কন্সিস্ট্যানট স্টেটে রয়েছে।
এবং আপনি লক্ষ্য করতে পারেন যে এখন
A এর শেষ মান 40 ডলার এবং B এর n এর মান 260
ডলার। আগের সিডিউলে মূল্য ছিল 45 ডলার,
আর 255 ডলার এই দুটি আলাদা। কিন্তু তাদের
উভয়ই প্রকৃতপক্ষে সঠিক তাদের উভয়ই
কন্সিস্ট্যান্ট, কারণ যখন জিনিসগুলি
এই বিতরণ পদ্ধতিতে ঘটে, তখন প্রথমে 50
ডলার ডেবিট করা উচিত এবং তারপর 10 ডলার
স্থানান্তর করা উচিত কিনা সে বিষয়ে আমাদের
কোনও নিয়ন্ত্রণ নেই। অথবা প্রথমে
10 ট্রান্সফার করা উচিত নাকি 50 ডলার
এর পরে কোথায় ট্রান্সফার করা হবে, যে কোন একটি
সঠিক কনসিস্ট্যান্ট স্টেট।
সুতরাং, বিভিন্ন সিডিউল আপনাকে বিভিন্ন
ফলাফল দিতে পারে যা কোনও উদ্বেগের
বিষয় নয় কারণ উভয়ই সম্ভাব্য বৈধ ফলাফল।
কিন্তু প্রশ্ন হল অবশেষে, ডাটাবেসের
একটি কন্সিস্ট্যান্ট স্টেট থাকতে হবে
তাই, এই দুটিই কন্সিস্ট্যান্ট।
এখন, একটি আকর্ষণীয় উদাহরণ নিন, যেখানে
সিডিউল 3 যেখানে এখানে আপনি, যদি আপনি মনোযোগ
সহকারে দেখেন তবে T1 এর কয়েকটি ইন্সট্রাকশন
এক্সিকিউট করা হয়েছে। এবং তারপর টেম্পোরাল
অর্ডারে কিছু অন্যান্য ইন্সট্রাকশন, T2 এর
কিছু ইন্সট্রাকশন এক্সিকিউট করা হয়,
তারপর আবার T1 তারপর আবার T2।
সুতরাং, দুটি আলাদা ট্রাঞ্জাকসনের ইন্সট্রাকশন
পরস্পর বিচ্ছিন্ন হয়ে যাচ্ছে। এবং
এটা হল এক্সিকিউসনের অবস্থা। সুতরাং,
আপনি দেখতে পাচ্ছেন যে আপনি যখন T1 এ A কে
লেখেন এখানে আপনি 50 ডলার ডেবিট হয়েছে।
তারপরে যখন T2 পরবর্তীতে A তে লেখে, তখন আরও
5 ডলার ডেবিট করা হয়, তাই এটি 45 হয়ে যায়।
তারপরে আপনার কাছে T1 আবার এক্সিকিউট
করতে হবে এবং এতে B যোগ করতে হবে। এবং
এর দ্বারা এটি কেবলমাত্র যে এটি একটি ইনকন্সিস্ট্যান্ট-এ
চলে গেছে তা নয়, এটি ইতিমধ্যেই একটি ইনকন্সিস্ট্যান্ট
অবস্থায় ছিল, তবে এটি ক্ষণস্থায়ী
ছিল যা অস্থায়ী ছিল। কিন্তু এখন
T1 ট্রাঞ্জাকসন সম্পূর্ণভাবে সম্পন্ন হয়েছে।
এটা তার এক্সিকিউসন সম্পন্ন করেছে এটা
কমিট হয়, কিন্তু আপনার ডাটাবেস একটি
ইনকন্সিস্ট্যান্ট স্টেটে এখনও আছে।
সুতরাং, এটি এমন কিছু যা সম্ভব, কারণ আপনি
সিডিউলে দুটি ট্রাঞ্জাকসনের ইন্সট্রাকশনগুলো
ইন্টারলিভিং করছেন। কিন্তু একবার আপনি
B এর বাকি ট্রাঞ্জাকসনকে অনুমতি দিলে এই অংশটি
B আপডেট হয়ে যায় এবং আপনি এখানে পৌঁছান।
এবং সেটাও কমিটেড হয়। সুতরাং, আপনার
সিডিউল ট্রাঞ্জাকসন 1 এবং ট্রাঞ্জাকসন
2 নিয়ে গঠিত, যখন উভয়ই সম্পূর্ণ হয়ে
গেছে আপনি আবার সেই অবস্থায় পৌঁছেছেন
যা কন্সিস্ট্যান্ট। এবং আপনি যা অর্জন
করেছেন তার ফলাফলগুলি যদি আপনি দেখেন তবে
আপনি অবিলম্বে সনাক্ত করতে পারবেন যে এটি
সিডিউল 3 অনুযায়ী ট্রাঞ্জাকসন করছে,
যা এই পদ্ধতিতে ইন্টারলিভিং করা হচ্ছে এই পদ্ধতিতে
ইন্টারলিভিং এর সমতুল্য এই পদ্ধতিতে যা সিডিউল
1 । সুতরাং, আপনি একটি
সিডিউল পেয়েছেন যা সিডিউল 1 এর সমতুল্য।
এবং এটি তাই, এটি দেখানোর জন্য এটি একটি উদাহরণ
মাত্র যে দুটি ট্রাঞ্জাকশনের ইন্সট্রাকশনকে ইন্টারলিভ
করা সম্ভব, এবং একটি সিডিউল তৈরি করা
যা এখনও ক্ষণস্থায়ী বা এমনকি ডেটাবেসের
ইন্কন্সিস্ট্যান্ট কমিট স্টেটে থাকতে
পারে। কিন্তু অবশেষে, সিডিউল শেষ হলে এটা
সম্ভব যে এটি আপনাকে একটি কন্সিস্ট্যান্ট
অবস্থায় নিয়ে আসবে।
এখন, সেই ট্রাঞ্জাকশনের জন্য আবার দেখুন
একটি ভিন্ন ইন্টারলিভিং, একটি ভিন্ন সিডিউল,
আবার T1, T2 জড়িত। কিন্তু আপনি এখন একটি ভিন্ন
ক্রমে তাদের ইন্টারলিভ করার চেষ্টা করেছেন৷
সুতরাং, আগে ইন্টারলিভিং করা হয়েছিল T1 করার
পরে A লিখতে হবে, এখানে এটি স্থানীয়ভাবে
50 দ্বারা ডেবিট হওয়ার পরে করা হয়েছে।
এবং তারপরে এই অংশটি সম্পন্ন হয়েছে এবং
তারপরে লেখা হচ্ছে। এবং এখন আপনি যদি
ধাপগুলি অতিক্রম করেন তবে আমি এটিকে
আপনার জন্য একটি অনুশীলন হিসাবে সিডিউল
4 এ রেখে দেব। এখন, আপনি যদি স্টেটের
মধ্য দিয়ে যান তবে আপনি দেখতে পাবেন
যে যখন ট্রাঞ্জাকসন T1 এখানে কমিট হয়,
তখন আপনার একটি ইনকন্সিস্ট্যান্ট স্টেট রয়েছে। এবং
অবশেষে, এমনকি যখন সিডিউলটি শেষ হয়
যে T2 কমিটেড হয়। সেখানে A আছে, আপনি একটি ইনকন্সিস্ট্যান্ট
স্টেটে আছেন যে A এবং B এর যোগফল যা 350 ছিল
300 হয়ে গেছে 350 হয়েছে তাহলে, 50 ডলার যা জেনারেট
হয়েছে। সুতরাং, এটি আপনি দেখতে পাচ্ছেন
যে আপনি যদি ট্রাঞ্জাকসনগুলিকে আলাদা করেন, তবে এটি
খুব সম্ভব যে ট্রাঞ্জাকসনগুলি আপনাকে একটি কন্সিস্ট্যান্ট
ডেটাবেস দেবে বা নাও দিতে পারে।
সুতরাং, এখানে এই মডিউলে, আমরা বুঝলাম
যে একটি ডাটাবেস এক্সিকিউট করে থাকে;
যা একটি ট্রাঞ্জাকসনের মত করে হয়। এবং আমরা
দেখেছি যে তাদের অবশ্যই অ্যাসিড বৈশিষ্ট্য
নামে পরিচিত বৈশিষ্ট্যগুলির একটি সেট পূরণ করতে
হবে এবং এটোমিসিটি, কন্সিস্ট্যান্সি,
আইসোলেসন এবং ডিউরাবিলিটি অবশ্যই সিদ্ধ হতে
হবে। এবং যখন ট্রাঞ্জাকসনগুলি কঙ্কারেন্ট পদ্ধতিতে
সম্পাদিত হয়, তখন আমরা থ্রুপুট উন্নত
করি, কিন্তু ট্রাঞ্জাকসনের কঙ্কারেন্ট এক্সিকিউসন
সিরিয়ালাইজিবিলিটির সমস্যাগুলি উত্থাপন
করে; অর্থাৎ, দুই বা ততোধিক ট্রাঞ্জাকসনের
নির্দেশের ইন্টারলিভড সিডিউল কঙ্কারেন্ট
এক্সিকিউসনের ফলে নির্দিষ্ট প্রভাবের
জন্ম দিতে পারে যা অ্যাসিড বৈশিষ্ট্য
লঙ্ঘন করে। এবং অবশ্যই ইনকন্সিস্ট্যান্ট
ডাটাবেস অবশ্যই গ্রহণযোগ্য নয় যেটার সুরাহা
করা প্রয়োজন। এবং তাই এটি মৌলিক সমস্যা
যা আমরা চিহ্নিত করেছি যা আমাদের
আগামী মডিউলগুলিতে সমাধান করতে হবে।
Weitere ähnliche Videos ansehen
ACID Properties in Databases With Examples
Lec-8.0: Integrity Constraints in Database with Examples
How to Build a Streaming Database in Three Challenging Steps | Materialize
Introdução a bancos de dados SQLite com Python e módulo sqlite3
Introduction To DBMS - Database Management System | What Is DBMS? | DBMS Explanation | Simplilearn
Lec-9: What is Primary Key in DBMS | Primary Key with Examples in Hindi
5.0 / 5 (0 votes)