Let Me Finish... Isolating Write Operations

Slides:



Advertisements
Similar presentations
Chapter 16 Concurrency. Topics in this Chapter Three Concurrency Problems Locking Deadlock Serializability Isolation Levels Intent Locking Dropping ACID.
Advertisements

1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Transaction Management: Concurrency Control CS634 Class 17, Apr 7, 2014 Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Database Administration Part 1 Chapter Six CSCI260 Database Applications.
Transactions and Locks Lesson 22. Skills Matrix Transaction A transaction is a series of steps that perform a logical unit of work. Transactions must.
Managing Transaction and Lock Vu Tuyet Trinh Hanoi University of Technology 1.
Monday, 13 October 2003 The Anatomy of a Data Modification Subset of: What everyone should know about Performance, Recovery & Logging Monday, 13 October.
Transactions and Exception Handling Eric Allsop SQLBits 6 th October 2007.
Designing for Performance General Database Optimizations Presentation Highlight: The Anatomy of a Data Modification Wednesday, 12 November 2003 – 16:30-18:00.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
1099 Why Use InterBase? Bill Todd The Database Group, Inc.
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
Transaction processing Book, chapter 6.6. Problem: With a single user…. you run a query, you get the results, you run the next, etc. But database life.
Concurrency and Transaction Processing. Concurrency models 1. Pessimistic –avoids conflicts by acquiring locks on data that is being read, so no other.
Unit 9 Transaction Processing. Key Concepts Distributed databases and DDBMS Distributed database advantages. Distributed database disadvantages Using.
1 CS 430 Database Theory Winter 2005 Lecture 16: Inside a DBMS.
Module 11 Creating Highly Concurrent SQL Server® 2008 R2 Applications.
Transactions and Locks A Quick Reference and Summary BIT 275.
Random Logic l Forum.NET l Transaction Isolation Levels Forum.NET Meeting ● Nov
SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant 26 th.
Giovanni Chierico | May 2012 | Дубна Data Concurrency, Consistency and Integrity.
SQLintersection Understanding Transaction Isolation Levels Randy Knight Wednesday, 3:45-5:00.
Module 11: Managing Transactions and Locks
Module 14: Managing Transactions and Locks. Overview Introducing Transactions and Locks Managing Transactions Understanding SQL Server Locking Architecture.
In this session, you will learn to: Implement triggers Implement transactions Objectives.
Deadlocks 3.0. Final Edition. Everything that developer needs to know Denis Reznik Microsoft SQL Server MVP Director of R&D at Intapp Kyiv.
Does the Optimistic Concurrency resolve your blocking problems Margarita Naumova, SQL Master Academy.
Locks, Blocks & Isolation Oh My!. About Me Keith Tate Data Professional for over 14 Years MCITP in both DBA and Dev tracks
Read Dirty to Me: SQL Server Isolation Levels Wendy Pastrick Arrow IT Consulting.
SQLintersection Locks, Blocks, and Deadlocks Oh My! Randy Knight Wednesday, 2:15-3:15.
Memory-Optimized Tables Querying at the speed of light.
In-Memory Capabilities
Locks, Blocks, and Deadlocks; Tame the Sibling Rivalry SQL Server Family Management ~ Wolf ~ This template can be used as a starter file for presenting.
Antonio Abalos Castillo
How In-Memory Affects Database Design
Let Me Finish... Isolating Write Operations
LAB: Web-scale Data Management on a Cloud
A Technical Overview of Microsoft® SQL Server™ 2005 High Availability Beta 2 Matthew Stephen IT Pro Evangelist (SQL Server)
Database Systems (資料庫系統)
Isolation Levels Understanding Transaction Temper Tantrums
Let Me Finish... Isolating Write Operations
Let Me Finish... Isolating Write Operations
Locks, Blocks, and Deadlocks; Tame the Sibling Rivalry SQL Server Family Management ~ Wolf ~ This template can be used as a starter file for presenting.
On transactions, and Atomic Operations
Batches, Transactions, & Errors
Optimistic Concurrency Internals
Everything you ever wanted to ask but were too shy
March 9th – Transactions
මොඩියුල විශ්ලේෂණය Transactions කළමනාකරණය.
Transactions, Locking and Query Optimisation
Essbase Data Integrity
When I Use NOLOCK AND OTHER HINTS
Understanding Transaction Isolation Levels
On transactions, and Atomic Operations
Batches, Transactions, & Errors
Let Me Finish... Isolating Write Operations
When I Use NOLOCK AND OTHER HINTS
Locks, Blocks, Deadlocks
Transactions and Concurrency
Concurrency Control E0 261 Prasad Deshpande, Jayant Haritsa
Deadlocks Everything you ever wanted to ask but were too shy
Sioux Falls, SD | Hosted by (605) SQL
A Masters view on Locking and blocking
About Wolf DBA for over 19 years At RDX for nearly 9
Isolation Levels Understanding Transaction Temper Tantrums
Module 13: Creating Highly Concurrent SQL Server 2012 Applications
-Transactions in SQL -Constraints and Triggers
A Masters view on Locking and blocking
A Masters view on Locking and blocking
Presentation transcript:

Let Me Finish... Isolating Write Operations Louis Davidson drsql.org nerd

Who am I? Been in IT for 20-some years Microsoft MVP For 12 Years Corporate Data Architect Written 5.65482 books on database design They were technically all versions of the same book. They at least had slightly different titles each time Super Brief Contact Info: DRSQL Twitter, Website (.org), Email (@hotmail.com) Change it to planning the next version

Topics of Discussion Transactions Connection/Transaction Isolation Matters of Timing Methods of Enforcement

Transactions Demo 1 – Cut for time Purpose Durability Nested Transactions Autonomous Transactions – Identity, Sequences Demo 1 – Cut for time

Connection/Transaction Isolation When executing a transaction, how can other connections affect your query results on a second connection? Types of Issues Phantom rows - Seeing new rows Non-repeatable reads – Rows vanishes or changes Dirty reads – Seeing data that never may actually exist in a specific form Expired/Older data – Seeing data that no longer exists in the same form, but was consistent at a point in time Isolation Levels – Settings to determine which anomalies we will accept Coming up next…the list!

Isolation Levels and Anomalies Allowed READ UNCOMMITTED –Dirty Reads, Phantom Rows, Non-Repeatable Reads READ COMMITTED (Typical SQL Server Default) – Phantom Rows, Non-Repeatable Reads SNAPSHOT – Older data, though a consistent view to a point in time REPEATABLE READ –Phantom Rows SERIALIZABLE

Matters of Timing Synchronous access Asynchronous access

Synchronous Access - Methods of Enforcement Locks Versions

Locks Tags to tell others you are using a resource Note: The following is simplified, will include a list of resources for more detailed information at the end of the presentation What Can Be Locked: Database, Table, Page, Row, Key, Range of Data, Schema, etc Compatibility Lock types must be compatible to be placed simultaneously Full matrix: https://technet.microsoft.com/en-us/library/ms172925(v=sql.110).aspx Types: Shared – Just looking, not modifying Exclusive – (Typically) Used when modifying data Update – A type of shared lock that says the connection may modify the underlying data. Must be changed to Exclusive to perform modification. Compatible with shared locks, not other update locks. http://www.sqlpassion.at/archive/2014/07/28/why-do-we-need-update-locks-in-sql-server/ Stability – Placed to keep you from changing or dropping an object that is in use Subtype: Intent – Placed at higher levels in the resource hierarchy to tell other connections they can’t place an incompatible type Deadlocks – Resource stalemate

Big Demo – Synchronous Concurrency Collisions With Locks Using: SQL Server 2016 RC0 in a Hyper-V VM

Multi-Valued Concurrency Controls (MVCC) Every modification to a row results in a new physical resource There are two versions currently implemented in SQL Server On Disk Tables (2005+) – Makes copies of rows in tempdb for read versions, still uses locks for write concurrency. Supported in SNAPSHOT Isolation Level and READ COMMITTED w/ READ_COMMITTED_SNAPSHOT DB Setting In Memory Tables (2014+) – Physical structures completely based on versions Supports SNAPSHOT, REPEATABLE READ, SERIALIZABLE Isolation Levels True Version Based Concurrency Controls are often referred to as Optimistic Concurrency Controls It is considered “optimistic” because it is assumed that there will rarely be collisions, and optimizes that way Locking is often referred to as “pessimistic”

Hash Index Simplified With Row Versions TableNameId Country OtherColumns 1 USA Values 2 3 Canada

Hash Index – After Row Update TableNameId Country OtherColumns 1 USA Values 2 Canada 3

Big Demo – Synchronous Concurrency Collisions with MVCC Using: SQL Server 2016 RC0 in a Hyper-V VM

Asynchronous Considerations Typical Flow Two Users Fetch Data One User Updates Data Second User Updates Data Based on Their Expectations Time separation may be a few microseconds or many hours Scenarios Chaos – Last writer wins Optimistic Locking – Check cached data to see if it is still the data you had originally Compare All (Or Some) Data Compare some automatically maintained data (Rowversion (aka Timestamp), Row Last Modified Time controlled by Trigger, Client Managed Value) A little bit of both – Example: How to deal with updating 100s (of thousands?) of rows?

Wrapup - The problems are complex Mostly the issue is one of proper design, testing, and probability Your designs must consider: Cost of Integrity Fail Throughput Likelihood of collisions Hopefully it is clear what is most important

Cost of Integrity Fail – “What if?” 1. Two people are travelling to Nashville via train, and both order hot chicken from two different wait persons, but there is only one order of chicken still available Verdict: Annoying but not life threatening 2. If Train A is given access to Location L on Track 1 at 11:30 AM, and Train B is given access to the same Location at the same time going in a different direction. Verdict: Time to learn some Johnny Cash Prison songs so you will fit in Note: The “what if?” test ought to be applied to all of your designs

Questions? Comments?

Contact info Louis Davidson - louis@drsql.org Website – http://drsql.org <-- Get slides here Twitter – http://twitter.com/drsql (@drsql) SQL Blog http://sqlblog.com/blogs/louis_davidson Simple Talk Blog – What Counts for a DBA http://www.simple-talk.com/community/blogs/drsql/default.aspx [twitter] Slides will be on drsql.org in the presentations area for this and the keynote as soon as I can get them out there. @rmtechtrifecta [/twitter]

Thank You!