This document provides an overview of database concurrency and transaction isolation levels in SQL Server. It begins by defining concurrency and how it allows for parallel operations on shared data. It then discusses concurrency conflicts like dirty reads, non-repeatable reads and lost updates. The document proceeds to explain different isolation levels like read committed, repeatable read and serializable, and how they guarantee consistency. It also covers concepts like locking, multi-version concurrency control and snapshot isolation. Overall, the document serves as a good primer on database concurrency fundamentals in SQL Server.
Second "code school lesson" for Eurosport's developers.
1. Refactoring : when? why? how?
2. Single Responsability
3. Practical case : clean architecture.
This document discusses test-driven development (TDD) and strategies for testing Sitecore applications. It covers:
1. The basics of TDD including writing unit tests first, making them pass, and then refactoring code. This helps ensure code always works and allows for safe refactoring.
2. Isolating dependencies by using interfaces, dependency injection with AutoFac, and fake objects with NSubstitute to isolate code from external systems.
3. Strategies for isolating and testing Sitecore code, including using Glass Mapper to map Sitecore items to lightweight objects and the Sitecore.FakeDB library for faking Sitecore data.
4. Tools for testing Sitecore itself
This document introduces Jest, a JavaScript testing framework. It discusses why Jest is useful, including that it runs tests in parallel sandboxed environments, provides a fast feedback loop with rich logging and error outputs, and acts as a one-stop shop for testing. The document also covers anatomy of Jest tests, how to use mocking, tips like resetting modules between tests and snapshot testing, and references for additional Jest resources.
This document summarizes a presentation about connecting to activity streams using Yellow and Blue systems. It discusses OAuth and OpenSocial standards for authorization and social components. The Yellow and Blue system presented pulls information from various sources using XPages, OAuth, and Java and displays it in a unified activity stream. It demonstrates connecting an app to the activity stream on Greenhouse using OAuth and the Social Enabler from OpenNTF to retrieve and display the stream.
Daniel Davis is a software developer with 8 years of experience who now focuses on Python development and DevOps. He discusses his journey learning about unit testing and how mocking strategies can make testing easier. Mocking eliminates dependencies, allows testing of methods without return values, and helps test error handling. Various Python mocking libraries are presented. Examples show how to use mocking to test a matching algorithm in a dating app and to test a JSON reader class. The key benefits of mocking are that it simplifies unit tests by handling dependencies and verifying method behavior.
Ben McCormick gave a presentation on how to save time by testing with Jest. He began with an introduction and explained that Jest is a JavaScript testing framework developed by Facebook that aims to solve common testing problems. He then demonstrated how Jest saves time through fast setup, writing tests quickly using familiar syntax and APIs, running tests in parallel and with a smart watch mode, and providing clear errors to fix tests fast. He concluded with a demo of Jest's features and took questions.
Second "code school lesson" for Eurosport's developers.
1. Refactoring : when? why? how?
2. Single Responsability
3. Practical case : clean architecture.
This document discusses test-driven development (TDD) and strategies for testing Sitecore applications. It covers:
1. The basics of TDD including writing unit tests first, making them pass, and then refactoring code. This helps ensure code always works and allows for safe refactoring.
2. Isolating dependencies by using interfaces, dependency injection with AutoFac, and fake objects with NSubstitute to isolate code from external systems.
3. Strategies for isolating and testing Sitecore code, including using Glass Mapper to map Sitecore items to lightweight objects and the Sitecore.FakeDB library for faking Sitecore data.
4. Tools for testing Sitecore itself
This document introduces Jest, a JavaScript testing framework. It discusses why Jest is useful, including that it runs tests in parallel sandboxed environments, provides a fast feedback loop with rich logging and error outputs, and acts as a one-stop shop for testing. The document also covers anatomy of Jest tests, how to use mocking, tips like resetting modules between tests and snapshot testing, and references for additional Jest resources.
This document summarizes a presentation about connecting to activity streams using Yellow and Blue systems. It discusses OAuth and OpenSocial standards for authorization and social components. The Yellow and Blue system presented pulls information from various sources using XPages, OAuth, and Java and displays it in a unified activity stream. It demonstrates connecting an app to the activity stream on Greenhouse using OAuth and the Social Enabler from OpenNTF to retrieve and display the stream.
Daniel Davis is a software developer with 8 years of experience who now focuses on Python development and DevOps. He discusses his journey learning about unit testing and how mocking strategies can make testing easier. Mocking eliminates dependencies, allows testing of methods without return values, and helps test error handling. Various Python mocking libraries are presented. Examples show how to use mocking to test a matching algorithm in a dating app and to test a JSON reader class. The key benefits of mocking are that it simplifies unit tests by handling dependencies and verifying method behavior.
Ben McCormick gave a presentation on how to save time by testing with Jest. He began with an introduction and explained that Jest is a JavaScript testing framework developed by Facebook that aims to solve common testing problems. He then demonstrated how Jest saves time through fast setup, writing tests quickly using familiar syntax and APIs, running tests in parallel and with a smart watch mode, and providing clear errors to fix tests fast. He concluded with a demo of Jest's features and took questions.
The document discusses problems that arose with scaling a Smalltalk web server called Silt without any initial planning. Key problems included supporting multiple blogs, slow page loads from repetitive file reads, slow category and keyword searches, and spam issues. Solutions involved refactoring code into separate classes, adding caching at various levels, offloading expensive searches to background threads, and updating anti-spam mechanisms. The author notes that problems were only solved reactively as they emerged and that Smalltalk proved capable of handling the scaling needs.
This document discusses using queues to improve performance and scalability of PHP applications. It describes how queues allow asynchronous and distributed processing of tasks to avoid bottlenecks. The document recommends using the Zend Server Job Queue to implement asynchronous tasks by creating job classes that encapsulate tasks and interact with the queue through a manager class. Sample code is presented and explained to illustrate scheduling and executing jobs via the queue.
Automated Testing but like for PowerShell (April 2012)Rob Reynolds
This document discusses automated testing for PowerShell. It covers different types of automated tests like unit tests, integration tests, and behavior driven development. It introduces Pester, a framework for writing BDD-style tests in PowerShell. While Pester allows writing tests, it does not enable mocking or stubbing. The document demonstrates how to perform unit testing, stubbing, and mocking in PowerShell by overwriting functions and setting expectations and behaviors.
The main challenge in growing an ecosystem on the JVM is providing stable interfaces without halting evolution. We look at the most popular dependency management solutions in Java-land and how Scala fits in.
This document discusses scalable ways of doing open source work. It outlines how ClojureWerkz grew from 4 projects and 2 maintainers in 2011 to over 30 projects and 70 contributors by 2015. It emphasizes the importance of maintaining responsibility to users by having good documentation, communication channels, and processes to engage contributors and ensure projects don't become abandonware. Standardizing practices, automating tasks, and writing documentation throughout development can help projects scale sustainably.
The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. Here is an overview of Rx with examples at the end.
Erlang is a programming language designed for writing concurrent programs that run forever. It has a great concurrency model, is network transparent, fault tolerant, and allows replacing running code. Erlang uses processes, immutable variables, recursion, pattern matching, and functional programming. It has built-in support for concurrency through lightweight processes that communicate via message passing. The language philosophy is to "let it crash" and handle errors through recovery in other processes rather than defensive programming.
This document provides an outline for a presentation on concurrency in SQL Server. The presentation introduction discusses sessions, locking, blocking, deadlocks, and pressure. It then covers transactions, isolation levels, and phenomena like dirty reads, non-repeatable reads, and phantom reads. The document discusses the speaker's background and certifications. It concludes with an outline of topics to be covered, including locking basics, advanced locking concepts, controlling locking, pessimistic and optimistic concurrency approaches.
Aim of this presentation is not to make you masters in Java 8 Concurrency, but to help you guide towards that goal. Sometimes it helps just to know that there is some API that might be suitable for a particular situation. Make use of the pointers given to search more and learn more on those topics. Refer to books, Java API Documentation, Blogs etc. to learn more. Examples and demos for all cases discussed will be added to my blog www.javajee.com.
The document discusses asynchronous programming with async and await in C#. It explains that async and await were introduced to address issues with threading like overhead and blocking. Async methods use threads efficiently from the thread pool rather than creating new threads. Await yields threads rather than blocking them. The document demonstrates async programming and best practices like using Task instead of async void. It recommends using async for I/O bound work since it can improve performance over synchronous code.
SQL Server Wait Types Everyone Should KnowDean Richards
Many people use wait types for performance tuning, but do not know what some of the most common ones indicate. This presentation will go into details about the top 8 wait types I see at the customers I work with. It will provide wait descriptions as well as solutions.
Welcome to the nightmare of locking, blocking and isolation levels!Boris Hristov
I am sure you all know that troubleshooting problems related to locking and blocking (hey, sometimes there are deadlocks too) can be a real nightmare! In this session, you will be able to see and understand why and how locking actually works, what problems it causes and how can we use isolation levels and various other techniques to resolve them!
Update locks in SQL Server are used to prevent deadlocks that could occur when multiple transactions try to concurrently update the same resource. Without update locks, transactions would first acquire shared locks before updating data. However, this could lead to deadlocks if two transactions simultaneously tried to convert their shared locks to exclusive locks in order to perform an update. To avoid this, SQL Server uses update locks, which are incompatible with other locks and ensure that only one transaction can update a resource at a time by first acquiring an update lock before converting it to an exclusive lock.
The nightmare of locking, blocking and isolation levelsBoris Hristov
This document discusses transaction locking and isolation levels in SQL Server. It begins with an introduction to locks, their types (shared, update, exclusive), and how they are used for concurrency control. It then covers locking troubleshooting topics like lock escalation, deadlocks, and blocking. The document concludes with an overview of the different transaction isolation levels in SQL Server, including the tradeoffs between pessimistic and optimistic concurrency control approaches.
The nightmare of locking, blocking and isolation levels!Boris Hristov
am sure you all know that troubleshooting problems related to locking and blocking (hey, sometimes there are deadlocks too) can be a real nightmare! In this session, you will be able to see and understand why and how locking actually works, what problems it causes and how can we use isolation levels and various other techniques to resolve them!
The nightmare of locking, blocking and isolation levels!Boris Hristov
I am sure you all know that troubleshooting problems related to locking and blocking (hey, sometimes there are deadlocks too) can be a real nightmare! In this session, you will be able to see and understand why and how locking actually works, what problems it causes and how can we use isolation levels and various other techniques to resolve them!
This document discusses the Circuit Breaker module in Resilience4j. It describes that a circuit breaker prevents cascading failures by allowing a system to gracefully handle unavailable or slow services. It has three states: closed, open, and half-open. In the closed state, requests proceed normally until failures exceed a threshold, triggering the open state where calls fail fast. In half-open, the first call is attempted and the state changes based on its success or failure.
Welcome to the nightmare of locking, blocking and isolation levels!Boris Hristov
I am sure you all know that troubleshooting problems related to locking and blocking (hey, sometimes there are deadlocks too) can be a real nightmare! In this session, you will be able to see and understand why and how locking actually works, what problems it causes and how can we use isolation levels and various other techniques to resolve them!
The Nightmare of Locking, Blocking and Isolation Levels!Boris Hristov
I am sure you all know that troubleshooting problems related to locking and blocking (hey, sometimes there are deadlocks too) can be a real nightmare! In this session, you will be able to see and understand why and how locking actually works, what problems it causes and how can we use isolation levels and various other techniques to resolve them!
The document discusses problems that arose with scaling a Smalltalk web server called Silt without any initial planning. Key problems included supporting multiple blogs, slow page loads from repetitive file reads, slow category and keyword searches, and spam issues. Solutions involved refactoring code into separate classes, adding caching at various levels, offloading expensive searches to background threads, and updating anti-spam mechanisms. The author notes that problems were only solved reactively as they emerged and that Smalltalk proved capable of handling the scaling needs.
This document discusses using queues to improve performance and scalability of PHP applications. It describes how queues allow asynchronous and distributed processing of tasks to avoid bottlenecks. The document recommends using the Zend Server Job Queue to implement asynchronous tasks by creating job classes that encapsulate tasks and interact with the queue through a manager class. Sample code is presented and explained to illustrate scheduling and executing jobs via the queue.
Automated Testing but like for PowerShell (April 2012)Rob Reynolds
This document discusses automated testing for PowerShell. It covers different types of automated tests like unit tests, integration tests, and behavior driven development. It introduces Pester, a framework for writing BDD-style tests in PowerShell. While Pester allows writing tests, it does not enable mocking or stubbing. The document demonstrates how to perform unit testing, stubbing, and mocking in PowerShell by overwriting functions and setting expectations and behaviors.
The main challenge in growing an ecosystem on the JVM is providing stable interfaces without halting evolution. We look at the most popular dependency management solutions in Java-land and how Scala fits in.
This document discusses scalable ways of doing open source work. It outlines how ClojureWerkz grew from 4 projects and 2 maintainers in 2011 to over 30 projects and 70 contributors by 2015. It emphasizes the importance of maintaining responsibility to users by having good documentation, communication channels, and processes to engage contributors and ensure projects don't become abandonware. Standardizing practices, automating tasks, and writing documentation throughout development can help projects scale sustainably.
The Reactive Extensions (Rx) is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. Here is an overview of Rx with examples at the end.
Erlang is a programming language designed for writing concurrent programs that run forever. It has a great concurrency model, is network transparent, fault tolerant, and allows replacing running code. Erlang uses processes, immutable variables, recursion, pattern matching, and functional programming. It has built-in support for concurrency through lightweight processes that communicate via message passing. The language philosophy is to "let it crash" and handle errors through recovery in other processes rather than defensive programming.
This document provides an outline for a presentation on concurrency in SQL Server. The presentation introduction discusses sessions, locking, blocking, deadlocks, and pressure. It then covers transactions, isolation levels, and phenomena like dirty reads, non-repeatable reads, and phantom reads. The document discusses the speaker's background and certifications. It concludes with an outline of topics to be covered, including locking basics, advanced locking concepts, controlling locking, pessimistic and optimistic concurrency approaches.
Aim of this presentation is not to make you masters in Java 8 Concurrency, but to help you guide towards that goal. Sometimes it helps just to know that there is some API that might be suitable for a particular situation. Make use of the pointers given to search more and learn more on those topics. Refer to books, Java API Documentation, Blogs etc. to learn more. Examples and demos for all cases discussed will be added to my blog www.javajee.com.
The document discusses asynchronous programming with async and await in C#. It explains that async and await were introduced to address issues with threading like overhead and blocking. Async methods use threads efficiently from the thread pool rather than creating new threads. Await yields threads rather than blocking them. The document demonstrates async programming and best practices like using Task instead of async void. It recommends using async for I/O bound work since it can improve performance over synchronous code.
SQL Server Wait Types Everyone Should KnowDean Richards
Many people use wait types for performance tuning, but do not know what some of the most common ones indicate. This presentation will go into details about the top 8 wait types I see at the customers I work with. It will provide wait descriptions as well as solutions.
Welcome to the nightmare of locking, blocking and isolation levels!Boris Hristov
I am sure you all know that troubleshooting problems related to locking and blocking (hey, sometimes there are deadlocks too) can be a real nightmare! In this session, you will be able to see and understand why and how locking actually works, what problems it causes and how can we use isolation levels and various other techniques to resolve them!
Update locks in SQL Server are used to prevent deadlocks that could occur when multiple transactions try to concurrently update the same resource. Without update locks, transactions would first acquire shared locks before updating data. However, this could lead to deadlocks if two transactions simultaneously tried to convert their shared locks to exclusive locks in order to perform an update. To avoid this, SQL Server uses update locks, which are incompatible with other locks and ensure that only one transaction can update a resource at a time by first acquiring an update lock before converting it to an exclusive lock.
The nightmare of locking, blocking and isolation levelsBoris Hristov
This document discusses transaction locking and isolation levels in SQL Server. It begins with an introduction to locks, their types (shared, update, exclusive), and how they are used for concurrency control. It then covers locking troubleshooting topics like lock escalation, deadlocks, and blocking. The document concludes with an overview of the different transaction isolation levels in SQL Server, including the tradeoffs between pessimistic and optimistic concurrency control approaches.
The nightmare of locking, blocking and isolation levels!Boris Hristov
am sure you all know that troubleshooting problems related to locking and blocking (hey, sometimes there are deadlocks too) can be a real nightmare! In this session, you will be able to see and understand why and how locking actually works, what problems it causes and how can we use isolation levels and various other techniques to resolve them!
The nightmare of locking, blocking and isolation levels!Boris Hristov
I am sure you all know that troubleshooting problems related to locking and blocking (hey, sometimes there are deadlocks too) can be a real nightmare! In this session, you will be able to see and understand why and how locking actually works, what problems it causes and how can we use isolation levels and various other techniques to resolve them!
This document discusses the Circuit Breaker module in Resilience4j. It describes that a circuit breaker prevents cascading failures by allowing a system to gracefully handle unavailable or slow services. It has three states: closed, open, and half-open. In the closed state, requests proceed normally until failures exceed a threshold, triggering the open state where calls fail fast. In half-open, the first call is attempted and the state changes based on its success or failure.
Welcome to the nightmare of locking, blocking and isolation levels!Boris Hristov
I am sure you all know that troubleshooting problems related to locking and blocking (hey, sometimes there are deadlocks too) can be a real nightmare! In this session, you will be able to see and understand why and how locking actually works, what problems it causes and how can we use isolation levels and various other techniques to resolve them!
The Nightmare of Locking, Blocking and Isolation Levels!Boris Hristov
I am sure you all know that troubleshooting problems related to locking and blocking (hey, sometimes there are deadlocks too) can be a real nightmare! In this session, you will be able to see and understand why and how locking actually works, what problems it causes and how can we use isolation levels and various other techniques to resolve them!
Actors provide a solution to issues with traditional concurrent programming like deadlocks and livelocks by treating all work as message passing between isolated entities called actors. Actors communicate asynchronously by message passing and avoid shared state, which simplifies concurrency. Akka is a toolkit for building applications and systems using the actor model that provides features like routing, supervision, and remote deployment of actors across networks.
What Are Your Servers Doing While You’re Sleeping?Tracy McKibben
You’re the DBA, the guy in charge, the guy who gets pounced on first thing in the morning with complaints of “my report took FOREVER to run last night, why?”, or “customers are saying the web site was really slow at 3:00am this morning, why?”. You’re expected to be able to answer questions like that. Can you? Do you know what your servers are doing when you’re not looking?
This presentation was used in a Redis talk that took place in ALT.NET Melbourne at February 25th, 2014. It is aimed for .Net developers, though almost all of the slides solely discuss Redis as the data store server, without any relation to client libraries in general and .Net in particular.
Yoav Rubin presents on Clojure's approach to concurrency. He discusses the problems with mutability and concurrency, such as race conditions. Clojure uses reference types like atoms, agents, and vars to provide concurrency semantics at the language level rather than relying on locks. Atoms provide shared, atomic changes across threads. Agents perform asynchronous changes in isolation. Vars allow isolated, synchronous changes but share values across threads. This eliminates many concurrency issues due to Clojure's immutable and declarative nature.
Apache Kafka lies at the heart of the largest data pipelines, handling trillions of messages and petabytes of data every day. Learn the right approach for getting the most out of Kafka from the experts at LinkedIn and Confluent. Todd Palino and Gwen Shapira demonstrate how to monitor, optimize, and troubleshoot performance of your data pipelines—from producer to consumer, development to production—as they explore some of the common problems that Kafka developers and administrators encounter when they take Apache Kafka from a proof of concept to production usage. Too often, systems are overprovisioned and underutilized and still have trouble meeting reasonable performance agreements.
Topics include:
- What latencies and throughputs you should expect from Kafka
- How to select hardware and size components
- What you should be monitoring
- Design patterns and antipatterns for client applications
- How to go about diagnosing performance bottlenecks
- Which configurations to examine and which ones to avoid
Semelhante a Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburban SSUG 2018) (20)
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...sameer shah
"Join us for STATATHON, a dynamic 2-day event dedicated to exploring statistical knowledge and its real-world applications. From theory to practice, participants engage in intensive learning sessions, workshops, and challenges, fostering a deeper understanding of statistical methodologies and their significance in various fields."
End-to-end pipeline agility - Berlin Buzzwords 2024Lars Albertsson
We describe how we achieve high change agility in data engineering by eliminating the fear of breaking downstream data pipelines through end-to-end pipeline testing, and by using schema metaprogramming to safely eliminate boilerplate involved in changes that affect whole pipelines.
A quick poll on agility in changing pipelines from end to end indicated a huge span in capabilities. For the question "How long time does it take for all downstream pipelines to be adapted to an upstream change," the median response was 6 months, but some respondents could do it in less than a day. When quantitative data engineering differences between the best and worst are measured, the span is often 100x-1000x, sometimes even more.
A long time ago, we suffered at Spotify from fear of changing pipelines due to not knowing what the impact might be downstream. We made plans for a technical solution to test pipelines end-to-end to mitigate that fear, but the effort failed for cultural reasons. We eventually solved this challenge, but in a different context. In this presentation we will describe how we test full pipelines effectively by manipulating workflow orchestration, which enables us to make changes in pipelines without fear of breaking downstream.
Making schema changes that affect many jobs also involves a lot of toil and boilerplate. Using schema-on-read mitigates some of it, but has drawbacks since it makes it more difficult to detect errors early. We will describe how we have rejected this tradeoff by applying schema metaprogramming, eliminating boilerplate but keeping the protection of static typing, thereby further improving agility to quickly modify data pipelines without fear.
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeWalaa Eldin Moustafa
Dynamic policy enforcement is becoming an increasingly important topic in today’s world where data privacy and compliance is a top priority for companies, individuals, and regulators alike. In these slides, we discuss how LinkedIn implements a powerful dynamic policy enforcement engine, called ViewShift, and integrates it within its data lake. We show the query engine architecture and how catalog implementations can automatically route table resolutions to compliance-enforcing SQL views. Such views have a set of very interesting properties: (1) They are auto-generated from declarative data annotations. (2) They respect user-level consent and preferences (3) They are context-aware, encoding a different set of transformations for different use cases (4) They are portable; while the SQL logic is only implemented in one SQL dialect, it is accessible in all engines.
#SQL #Views #Privacy #Compliance #DataLake
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...Social Samosa
The Modern Marketing Reckoner (MMR) is a comprehensive resource packed with POVs from 60+ industry leaders on how AI is transforming the 4 key pillars of marketing – product, place, price and promotions.
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Aggregage
This webinar will explore cutting-edge, less familiar but powerful experimentation methodologies which address well-known limitations of standard A/B Testing. Designed for data and product leaders, this session aims to inspire the embrace of innovative approaches and provide insights into the frontiers of experimentation!
5. • The ability for an operation to be broken up into multiple parts that can be
worked on independently
• The ability for multiple operations to access or modify a shared resource at
the same time
• More parts/users == more concurrency!
• Until a limiting factor appears…
6. • 5 Philosophers, bowls of spaghetti, and forks
• To eat, 2 forks are required
• Can pick up one fork at a time
• Once finished, both forks must
be returned to the table
• When not eating, a philosopher is thinking
https://en.wikipedia.org/wiki/File:An_illustration_of_the_dining_philosophers_problem.png
7. What if everyone picks up one fork?
https://en.wikipedia.org/wiki/File:An_illustration_of_the_dining_philosophers_problem.png
What if there’s a time limit?
What if someone never gets to eat?
10. • Preventable Read Phenomena (ANSI-defined*)
Dirty Reads
Non-Repeatable Reads
Phantom Reads
• Lost Updates
• Deadlocks
*ANSI specifies which behaviors to allow at each level, but not how to implement them
New Hampshire Dept. of Transportation
11. • Reading data that is not yet committed
• Changes are still “in flight” in another process
• You can read data multiple times or not at all
• “But it’s faster!”
12. • A.K.A. “Inconsistent Analysis”
• Multiple queries in the same transaction get differing results
• Cause: A different transaction commits changes between reads
13. • Only affects queries with a predicate (WHERE clause)
• Membership in the result set changes
• Multiple queries using the same predicate in the same transaction return
differing results https://flic.kr/p/4xqWnG
14. • “Update Conflict”
• One user’s update overwrites another user’s (simultaneous) update
• Appears as though the first update never happened
*SQL Server will not permit lost updates in any isolation level
15. • Two or more tasks block each other
• Each has a lock on a resource that the other task needs a lock on
• SQL Server detects and resolves these by choosing a victim
• Victim is rolled back, releasing all its locks
Process
A
Process
B
Resource 1 Resource 2
16. • Pessimistic Concurrency
Conflicts are expected; locks taken to prevent them
Readers block writers, writers block readers
Only option available pre-2005
• Optimistic Concurrency
Conflicts are considered possible, but unlikely
Row versioning means less locking
18. • How isolated is my transaction from the effects of other transactions?
• Pessimistic Concurrency
Read Committed
Read Uncommitted
Repeatable Read
Serializable
• Optimistic Concurrency
Snapshot
Read Committed Snapshot
https://flic.kr/p/7LjDDL
19. • Can be set at the connection or query level
• Cannot be changed server-wide
• Default isolation level is READ COMMITTED
• To change at connection level:
• Change applies to all queries for the current connection
SET TRANSACTION ISOLATION LEVEL {READ UNCOMMITTED
| READ COMMITTED | REPEATABLE READ | SNAPSHOT
| SERIALIZABLE } [;]
20. • To change at the query level, use table hints
• This is on a per-table basis
SELECT column
FROM table WITH (NOLOCK);
27. • A.K.A “NOLOCK”
• May read rows multiple times
• May read rows zero times
• May return results that were NEVER true!
• Only applies to SELECT queries
Ignored if used for data modification queries
Could cause index corruption if you tried it (since fixed)
Dirty Nonrepeatable Phantom
Yes Yes Yes
29. • “No locks are taken”
WRONG!
No shared locks are taken when reading data
Other locks are still taken as normal
• “It makes this query faster”
WRONG(ish)!
Only true if query had a lot of blocking on SELECT statements
30.
31. • Not a terrible setting, it exists for a reason
• BUT make sure you understand the risks and consequences
32. • The Default Default Isolation level
• Guarantee: Data that is read is guaranteed to be committed.
No Dirty Reads
No other guarantees
Dirty Nonrepeatable Phantom
No Yes Yes
33. • Ensure only committed data is read by locking
• (Locks only last as long as the read, released immediately after)
Rows already read.
Unlocked.
Row currently being
read. Locked.
Rows not yet read.
Unlocked.
SCAN
36. • Unlocked rows can move at any time
Rows already read.
Unlocked.
Row currently being
read. Locked.
Rows not yet read.
Unlocked.
SCAN
37. • Unlocked rows can move at any time
Rows already read.
Unlocked.
Row currently being
read. Locked.
Rows not yet read.
Unlocked.
SCAN
38.
39. • Builds on READ COMMITTED
• If a query is repeated within the same transaction, records read the first
time will not change
• Once a row is read, locks are held for length of the transaction
Even rows that don’t qualify as results
• These locks will not stop additional rows from being added or included in
subsequent queries
Dirty Nonrepeatable Phantom
No No Yes
40.
41. • Once read, rows are locked for duration of transaction
Rows already read.
Locked.
Row currently being
read. Locked.
Rows not yet read.
Unlocked.
SCAN
42. • On a second scan, new rows may enter
Rows already read.
Locked.
Row currently being
read. Locked.
Rows not yet read.
Unlocked.
SCAN
43.
44. • Builds on REPEATABLE READ
• If a query is repeated within the same transaction, results will be the same
• No data seen previously will change; no new results will appear
• We now need to lock data that doesn’t exist!
Dirty Nonrepeatable Phantom
No No No
45. • Key-range locks
• Prevent phantom reads by defining a range that other transactions cannot
insert rows within
• If you select a row/range that doesn’t exist, that gets locked too
46. • Range Locks cover the entire range AND the first row outside it
Rows already read.
Locked.
Row currently being
read. Locked.
Rows not yet read.
Locked.
RANGE BEING SELECTED
First key outside
range. Locked.
47.
48. • Uses row versioning to prevent concurrency conflicts
• Fewer locks are needed, so blocking is reduced
Readers no longer block writers
Writers no longer block readers
Writers still block writers
• Uses a version store to do this
• Version Store lives in tempdb
• Remember, it’s OPTIMISTIC!
49. • Whenever a row is updated, previous version is stored in the version store
• New version of row has a pointer to the previous version
• Versions are stored for as long as operations exist that might need them
All versions of rows modified by a transaction must be kept for as long as that
transaction is open
55. • Same guarantees as READ COMMITTED, just an optimistic implementation
• Statement-level snapshot isolation
Queries will see the most recent committed values as of the beginning of that
statement (not the transaction)
Dirty Nonrepeatable Phantom
No Yes Yes
59. • When enabled, RCSI becomes the default isolation level for this database.
• Command will block if DB has other connections
NO_WAIT will prevent blocking and just fail instead
ROLLBACK_IMMEDIATE will rollback other transactions
Dirty Nonrepeatable Phantom
No Yes Yes
ALTER DATABASE <DB_NAME>
SET READ_COMMITTED_SNAPSHOT ON
[WITH (NO_WAIT | ROLLBACK IMMEDIATE)];
60.
61. • Same guarantees as SERIALIZABLE, just an optimistic implementation
• Transaction-level snapshot isolation
Queries will see the most recent committed values as of the beginning of that
transaction (the first data read in it)
Dirty Nonrepeatable Phantom
No No No
62. • First statement merely allows snapshot isolation
Dirty Nonrepeatable Phantom
No No No
ALTER DATABASE <DB_NAME>
SET ALLOW_SNAPSHOT_ISOLATION ON;
SET TRANSACTION ISOLATION LEVEL SNAPSHOT;
63. • Process 1 reads data in a transaction, does not commit
• Process 2 reads/updates same data,
• Process 1’s snapshot does not see Process 2’s update
• Process 1 tries to update, gets blocked
• As soon as Process 2 commits, Process 1 errors out
• This will raise error 3960 on process 1
https://flic.kr/p/4WHW81
64.
65. • Everything I’ve covered here behaves the same in Azure SQL Database
• Exception: RCSI is enabled by default
67. • This could be its own presentation by itself
• Optimistic multi-version concurrency control
No locks required at any time
(Not even for data modification)
No waiting because of blocking!
No latches or spinlocks either
• Waits can still occur….
(Waiting for log writes to disk following a transaction)
68. • No existing row is ever modified
UPDATE creates a new version of a row
There may be multiple versions in play at once
• Transactions needing to read are presented with the correct version
69. 10 <inf> 1 Red
Begin
Time
End
Time Data Columns
10 <inf> 3 Green
Now at time 20, let’s:
Delete (1, Red)
Update (3, Green) to (3, Blue)
Insert (6, Pink)
10 20 1 Red
10 20 3 Green
20 <inf> 3 Blue
20 <inf> 6 Pink
Begin
Time
End
Time Data Columns
70. • Craig Freedman’s posts on SQL Server Isolation Levels
https://blogs.msdn.microsoft.com/craigfr/tag/isolation-levels/
• SQL Server Concurrency: Locking, Blocking, and Row Versioning
(Kalen Delaney, Simple Talk Publishing)
• Myths and Misconceptions about Transaction Isolation Levels
http://www.sqlpassion.at/archive/2014/01/21/myths-and-misconceptions-about-transaction-isolation-levels/