My Project
Public Types | Public Member Functions | Public Attributes
MDL_context Class Reference

#include <mdl.h>

List of all members.

Public Types

typedef I_P_List< MDL_ticket,
I_P_List_adapter< MDL_ticket,&MDL_ticket::next_in_context,&MDL_ticket::prev_in_context > > 
Ticket_list
typedef Ticket_list::Iterator Ticket_iterator

Public Member Functions

 MDL_context ()
void destroy ()
bool try_acquire_lock (MDL_request *mdl_request)
bool acquire_lock (MDL_request *mdl_request, ulong lock_wait_timeout)
bool acquire_locks (MDL_request_list *requests, ulong lock_wait_timeout)
bool upgrade_shared_lock (MDL_ticket *mdl_ticket, enum_mdl_type new_type, ulong lock_wait_timeout)
bool clone_ticket (MDL_request *mdl_request)
void release_all_locks_for_name (MDL_ticket *ticket)
void release_lock (MDL_ticket *ticket)
bool is_lock_owner (MDL_key::enum_mdl_namespace mdl_namespace, const char *db, const char *name, enum_mdl_type mdl_type)
bool has_lock (const MDL_savepoint &mdl_savepoint, MDL_ticket *mdl_ticket)
bool has_locks () const
MDL_savepoint mdl_savepoint ()
void set_explicit_duration_for_all_locks ()
void set_transaction_duration_for_all_locks ()
void set_lock_duration (MDL_ticket *mdl_ticket, enum_mdl_duration duration)
void release_statement_locks ()
void release_transactional_locks ()
void rollback_to_savepoint (const MDL_savepoint &mdl_savepoint)
MDL_context_ownerget_owner ()
uint get_deadlock_weight () const
void init (MDL_context_owner *arg)
void set_needs_thr_lock_abort (bool needs_thr_lock_abort)
bool get_needs_thr_lock_abort () const
void find_deadlock ()
bool visit_subgraph (MDL_wait_for_graph_visitor *dvisitor)
void will_wait_for (MDL_wait_for_subgraph *waiting_for_arg)
void done_waiting_for ()
void lock_deadlock_victim ()
void unlock_deadlock_victim ()

Public Attributes

MDL_wait m_wait

Detailed Description

Context of the owner of metadata locks. I.e. each server connection has such a context.


Constructor & Destructor Documentation

Initialize a metadata locking context.

This is to be called when a new server connection is created.


Member Function Documentation

bool MDL_context::acquire_lock ( MDL_request mdl_request,
ulong  lock_wait_timeout 
)

Acquire one lock with waiting for conflicting locks to go away if needed.

Parameters:
mdl_request[in/out] Lock request object for lock to be acquired
lock_wait_timeout[in] Seconds to wait before timeout.
Return values:
FALSESuccess. MDL_request::ticket points to the ticket for the lock.
TRUEFailure (Out of resources or waiting is aborted),
bool MDL_context::acquire_locks ( MDL_request_list mdl_requests,
ulong  lock_wait_timeout 
)

Acquire exclusive locks. There must be no granted locks in the context.

This is a replacement of lock_table_names(). It is used in RENAME, DROP and other DDL SQL statements.

Parameters:
mdl_requestsList of requests for locks to be acquired.
lock_wait_timeoutSeconds to wait before timeout.
Note:
The list of requests should not contain non-exclusive lock requests. There should not be any acquired locks in the context.
Assumes that one already owns scoped intention exclusive lock.
Return values:
FALSESuccess
TRUEFailure
bool MDL_context::clone_ticket ( MDL_request mdl_request)

Create a copy of a granted ticket. This is used to make sure that HANDLER ticket is never shared with a ticket that belongs to a transaction, so that when we HANDLER CLOSE, we don't release a transactional ticket, and vice versa -- when we COMMIT, we don't mistakenly release a ticket for an open HANDLER.

Return values:
TRUEOut of memory.
FALSESuccess.

Destroy metadata locking context.

Assumes and asserts that there are no active or pending locks associated with this context at the time of the destruction.

Currently does nothing. Asserts that there are no pending or satisfied lock requests. The pending locks must be released prior to destruction. This is a new way to express the assertion that all tables are closed before a connection is destroyed.

void MDL_context::done_waiting_for ( ) [inline]

Remove the wait-for edge from the graph after we're done waiting.

Try to find a deadlock. This function produces no errors.

Note:
If during deadlock resolution context which performs deadlock detection is chosen as a victim it will be informed about the fact by setting VICTIM status to its wait slot.
Return values:
TRUEA deadlock is found.
FALSENo deadlock found.
uint MDL_context::get_deadlock_weight ( ) const [inline]
Precondition:
Only valid if we started waiting for lock.
bool MDL_context::has_lock ( const MDL_savepoint mdl_savepoint,
MDL_ticket mdl_ticket 
)

Does this savepoint have this lock?

Return values:
TRUEThe ticket is older than the savepoint or is an LT, HA or GLR ticket. Thus it belongs to the savepoint or has explicit duration.
FALSEThe ticket is newer than the savepoint. and is not an LT, HA or GLR ticket.
void MDL_context::init ( MDL_context_owner arg) [inline]

Post signal to the context (and wake it up if necessary).

Return values:
FALSE- Success, signal was posted.
TRUE- Failure, signal was not posted since context already has received some signal or closed signal slot.
bool MDL_context::is_lock_owner ( MDL_key::enum_mdl_namespace  mdl_namespace,
const char *  db,
const char *  name,
enum_mdl_type  mdl_type 
)

Auxiliary function which allows to check if we have some kind of lock on a object. Returns TRUE if we have a lock of a given or stronger type.

Parameters:
mdl_namespaceId of object namespace
dbName of the database
nameName of the object
mdl_typeLock type. Pass in the weakest type to find out if there is at least some lock.
Returns:
TRUE if current context contains satisfied lock for the object, FALSE otherwise.

Release all explicit locks in the context which correspond to the same name/object as this lock request.

Parameters:
ticketOne of the locks for the name/object for which all locks should be released.

Release lock with explicit duration.

Parameters:
ticketTicket for lock to be released.

Release locks acquired by normal statements (SELECT, UPDATE, DELETE, etc) in the course of a transaction. Do not release HANDLER locks, if there are any.

This method is used at the end of a transaction, in implementation of COMMIT (implicit or explicit) and ROLLBACK.

void MDL_context::rollback_to_savepoint ( const MDL_savepoint mdl_savepoint)

Releases metadata locks that were acquired after a specific savepoint.

Note:
Used to release tickets acquired during a savepoint unit.
It's safe to iterate and unlock any locks after taken after this savepoint because other statements that take other special locks cause a implicit commit (ie LOCK TABLES).

Set explicit duration for all locks in the context.

void MDL_context::set_lock_duration ( MDL_ticket mdl_ticket,
enum_mdl_duration  duration 
)

Change lock duration for transactional lock.

Parameters:
ticketTicket representing lock.
durationLock duration to be set.
Note:
This method only supports changing duration of transactional lock to some other duration.

Set transactional duration for all locks in the context.

bool MDL_context::try_acquire_lock ( MDL_request mdl_request)

Try to acquire one lock.

Unlike exclusive locks, shared locks are acquired one by one. This is interface is chosen to simplify introduction of the new locking API to the system. MDL_context::try_acquire_lock() is currently used from open_table(), and there we have only one table to work with.

This function may also be used to try to acquire an exclusive lock on a destination table, by ALTER TABLE ... RENAME.

Returns immediately without any side effect if encounters a lock conflict. Otherwise takes the lock.

FIXME: Compared to lock_table_name_if_not_cached() (from 5.1) it gives slightly more false negatives.

Parameters:
mdl_request[in/out] Lock request object for lock to be acquired
Return values:
FALSESuccess. The lock may have not been acquired. Check the ticket, if it's NULL, a conflicting lock exists.
TRUEOut of resources, an error has been reported.
bool MDL_context::upgrade_shared_lock ( MDL_ticket mdl_ticket,
enum_mdl_type  new_type,
ulong  lock_wait_timeout 
)

Upgrade a shared metadata lock.

Used in ALTER TABLE and CREATE TABLE.

Parameters:
mdl_ticketLock to upgrade.
new_typeLock type to upgrade to.
lock_wait_timeoutSeconds to wait before timeout.
Note:
In case of failure to upgrade lock (e.g. because upgrader was killed) leaves lock in its original state (locked in shared mode).
There can be only one upgrader for a lock or we will have deadlock. This invariant is ensured by the fact that upgradeable locks SU, SNW and SNRW are not compatible with each other and themselves in case of ALTER TABLE operation. In case of CREATE TABLE operation there is chance of deadlock as 'S' is compatible with 'S'. But the deadlock is recovered by backoff and retry mechanism.
Return values:
FALSESuccess
TRUEFailure (thread was killed)

A fragment of recursive traversal of the wait-for graph of MDL contexts in the server in search for deadlocks. Assume this MDL context is a node in the wait-for graph, and direct the visitor to all adjacent nodes. As long as the starting node is remembered in the visitor, a deadlock is found when the same node is visited twice. One MDL context is connected to another in the wait-for graph if it waits on a resource that is held by the other context.

Return values:
TRUEA deadlock is found. A pointer to deadlock victim is saved in the visitor.
FALSE
void MDL_context::will_wait_for ( MDL_wait_for_subgraph waiting_for_arg) [inline]

Inform the deadlock detector there is an edge in the wait-for graph.


Member Data Documentation

If our request for a lock is scheduled, or aborted by the deadlock detector, the result is recorded in this class.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines