My Project
|
#include <mdl.h>
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_owner * | get_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 |
Context of the owner of metadata locks. I.e. each server connection has such a context.
Initialize a metadata locking context.
This is to be called when a new server connection is created.
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.
mdl_request | [in/out] Lock request object for lock to be acquired |
lock_wait_timeout | [in] Seconds to wait before timeout. |
FALSE | Success. MDL_request::ticket points to the ticket for the lock. |
TRUE | Failure (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.
mdl_requests | List of requests for locks to be acquired. |
lock_wait_timeout | Seconds to wait before timeout. |
FALSE | Success |
TRUE | Failure |
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.
TRUE | Out of memory. |
FALSE | Success. |
void MDL_context::destroy | ( | ) |
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.
void MDL_context::find_deadlock | ( | ) |
Try to find a deadlock. This function produces no errors.
TRUE | A deadlock is found. |
FALSE | No deadlock found. |
uint MDL_context::get_deadlock_weight | ( | ) | const [inline] |
bool MDL_context::has_lock | ( | const MDL_savepoint & | mdl_savepoint, |
MDL_ticket * | mdl_ticket | ||
) |
Does this savepoint have this lock?
TRUE | The ticket is older than the savepoint or is an LT, HA or GLR ticket. Thus it belongs to the savepoint or has explicit duration. |
FALSE | The 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).
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.
mdl_namespace | Id of object namespace |
db | Name of the database |
name | Name of the object |
mdl_type | Lock type. Pass in the weakest type to find out if there is at least some lock. |
void MDL_context::release_all_locks_for_name | ( | MDL_ticket * | name | ) |
Release all explicit locks in the context which correspond to the same name/object as this lock request.
ticket | One of the locks for the name/object for which all locks should be released. |
void MDL_context::release_lock | ( | MDL_ticket * | ticket | ) |
Release lock with explicit duration.
ticket | Ticket 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.
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.
ticket | Ticket representing lock. |
duration | Lock duration to be set. |
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.
mdl_request | [in/out] Lock request object for lock to be acquired |
FALSE | Success. The lock may have not been acquired. Check the ticket, if it's NULL, a conflicting lock exists. |
TRUE | Out 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.
mdl_ticket | Lock to upgrade. |
new_type | Lock type to upgrade to. |
lock_wait_timeout | Seconds to wait before timeout. |
FALSE | Success |
TRUE | Failure (thread was killed) |
bool MDL_context::visit_subgraph | ( | MDL_wait_for_graph_visitor * | gvisitor | ) |
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.
TRUE | A 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.
If our request for a lock is scheduled, or aborted by the deadlock detector, the result is recorded in this class.