Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save CajuCLC/f9e3cb54c378f67c5d5ac1c193f05454 to your computer and use it in GitHub Desktop.
Save CajuCLC/f9e3cb54c378f67c5d5ac1c193f05454 to your computer and use it in GitHub Desktop.
Useful Mysql Commands for Debugging Magento Reindex Locks

Sometimes you may have a run away reindex process that aborted due to a MySQL connection error of some sorts. It may be useful to use the following MySQL commands to aid in debugging.

Determining if a lock exists

Magento Enterprise labels the reindex lock via the constant REINDEX_FULL_LOCK in app/code/core/Enterprise/Index/Model/Observer.php

SELECT IS_FREE_LOCK('mydatabase_name.reindex_full')

Returns 1 is specified lock is free and can be acquired, 0 if it’s in use, NULL if an error occurs.

Determing the thread that is holding the lock

SELECT IS_USED_LOCK('mydatabase_name.reindex_full')

This function is useful if you need to know which thread is holding a certain lock. It returns the connection id of that thread, or NULL if the specified lock is free.

Releasing a lock

RELEASE_LOCK('mydatabase_name.reindex_full')

RELEASE_LOCK() should return 1. If it returns 0, that lock has been acquired by someone else, and can’t be release by you. If the specified lock does not currently exist, returns NULL. In both cases, your code is likely to be buggy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment