-> What is deadlock caused by ? Supposed 2 transactions occurs concurrently in same phrase => Transaction A is trigger update queries, same time transaction B is also triggers a transaction updates -> Transaction B will waiting the update results from transaction A in periods of waiting time till the operation response. <-> Solutions :
- Using update query by order
- Locking mechanisms used within transaction
- Prevent race conditions and ensure data consistency.
- equivalence as (1) query -> but weaker
- selected rows are not modified in ways that affect the non-key columns ============================================================================
- Carry deadlines, Cancellation signals, request-scoped data.
- Helps to propagating cancellation signals throughout the application.
- Initialize context by using:
- context.WithCancel(parent) -> cancel by using cancel()
- context.WithDeadline(parent, deadline) -> automatically canceled when
deadline
is reached. - context.WithTimeOut(parent, timeout) -> similarly to withDeadline
- context.WithValue(parent, key, value) -> [often use with the request-scoped] ============================================================================
Command showing the current isolation levels :
- show transaction isolation level
Command options for setting isolation levels :
- set session transaction isolation level serializable
Dirty Read
: transaction reads data written by other concurrent uncommitted transactionNon-repeated read
: reads the same row twice and sees difference valuePhantom read
: transaction re-executes a query to find rows satisfy the condition and sees the difference set of rowsSerialization anomaly
:
- Read uncommitted -> read committed -> Repeatable read -> Serializable read