100800 items (193 unread) in 22 feeds
CNN
(2 unread)
MSNBC
(6 unread)
PHP
(62 unread)
Deals
(86 unread)
Web Development
(35 unread)
CNN Money
(1 unread)
Frugal Blogs
(1 unread)
The MySQL administration SQL command SHOW PROCESSLIST may read "Waiting for table metadata lock" in its "State" column for a statement. The statement in question is waiting for another transaction to release a metadata lock. Its a state that may appear when using the global transaction ID injection feature of PECL/mysqlnd_ms 1.2.0-alpha. But only in case of errors and if not using default settings of the plugin. In the worst case, during testing only, I experienced a deadlock with MySQL 5.5.3 or higher which never got resolved automatically.
Let a transaction update a record in a table. In my specific case it was an failing UPDATE. It failed because the table did not exist. Let a second transaction run a DDL statement, for example, DROP TABLE on the same table. The second transaction is now in waiting for the first transaction to release a metadata lock. Yes, the second transaction is waiting for a lock hold on a non-existing table, if you are using MySQL 5.5.3 or higher… The SQL is syntactically correct, thus the lock is acquired.
$link = new mysqli($host, $user, $passwd, $db, $port, $socket);
$link->autocommit(false);
$link->query(\"UPDATE foo SET bar = bar + 1\");
$link2 = new mysqli($host, $user, $passwd, $db, $port, $socket);
$link2->query(\"DROP TABLE IF EXISTS foo\");
mysql> show processlist; +------+------+--------------------+------+---------+------+---------------------------------+--------------------------+ | Id | User | Host | db | Command | Time | State | Info | +------+------+--------------------+------+---------+------+---------------------------------+--------------------------+ | 5754 | root | 192.168.78.1:44307 | test | Sleep | 160 | | NULL | | 5755 | root | 192.168.78.1:44308 | test | Query | 160 | Waiting for table metadata lock | DROP TABLE IF EXISTS foo | | 5756 | root | localhost:60751 | test | Query | 0 | NULL | show processlist | +------+------+--------------------+------+---------+------+---------------------------------+--------------------------+
This behaviour is different from previous MySQL versions and it is documented in the MySQL 5.5.3 Changes as an incompatible change: A table that is being used by a transaction within one session cannot be used in DDL statements by other sessions until the transaction ends. . The change fixed issues with the binary log. So far, so good - though surprising.
Under normal circumstances the server will release the lock when the clients commit their transactions or disconnect. If they don’t end their transactions nicely but die, the wait_timeout should detect failing TCP/IP clients and solve the deadlock.
How its related to the plugin
What I was doing here was simlating a failure of the plugin to inject a global transaction ID because the transaction table was not set up. The injection, the UPDATE fails, when the client is not in autocommit mode. My initial idea was that the plugin would then report and error to the application and the application could create the transaction id table, if it wanted. In my test I tried catching the error and did DROP TABLE IF EXISTS trx_table, CREATE TABLE trx_table to recreate the table. My test timed out. And, that day it was time for me to call it a day.
The other day, I checked the processlist and saw the deadlock. My PHP test had stopped and disconnected but the deadlock still existed and borked numerous other test runs. It was necessary to KILL the sleeping lock holder manually.
The plugin offers two ways of dealing with injection errors. By default the injection error is ignored and the function called by the application is executed nonetheless. If, for example, we are running in transaction mode (auto commit off), the user calls the commit() function and injection of the UPDATE statement for increasing the transaction counter fails, the plugin commits anyway. The transaction ends. Other transactions should not be blocked because the metadata lock on the transaction table is released by ending the transaction. No matter if using MySQL 5.5.3 or earlier.
user_commit()
if (!inject_trx_id() && report_error)
return false;
return commit()
Optionally, users can tell the plugin to bubble up the injection error. If so, users should roll back the current transaction calling rollback() to prevent the metadata lock issue. Alternatively, you can check for the error code and try to detect cases when its required to recreate the transaction id table.
MoralAs said, if you go for plugin default settings, no locking issue but possibly gaps and holes in your transaction id table. If you know what you do, if you can adapt your application and code changes are possible, you can manually handle the error and recreate the transaction id table on demand.
One of the biggest challenges I’ve run into in being a “remotee” is the daily interaction with other team members. When you are just a cube, an office, or a desk away, there’s always that common water cooler or coffee pot that provides a natural place to interact with others. Or, if you have a question, you can always just stop and ask. Being able to physically get together without having to make much effort is a real bonus for people working in the same office, but can be a bit more challenging if you are remote team member. But this can also be a blessing in disguise, allowing you to concentrate on projects more and be interrupted less often.
What many people don’t realize is that every interaction with fellow team member or collegue is a meeting, and having that meeting is taking he or she away from thier normal duties. Organizations don’t hire people to be in meetings all day, they hire them to be productive contributors to making the organzation as a whole successful. This is where being remote has it’s advantage, as it’s easier to turn off the outside world by turning off your virtual links where in an office you have to hide somewhere to when you need some heads down time.
I recently read the book “Read This Before Our Next Meeting“, which talks about how to improve the quality of the meetings you hold, and at the same time eliminate those pointless meetings that drag your team down. The big takeaway I had from the book is that you need to be respectful of other people’s time. How do you best do this in the context of meetings? Here’s some good starting points:
What are your pointers for effective meetings and finding ways to be respectful of people’s time? Let me know in comments.
Truncated by Planet PHP, read more at the original (another 658 bytes)
One of the biggest challenges I’ve run into in being a “remotee” is the daily interaction with other team members. When you are just a cube, an office, or a desk away, there’s always that common water cooler or coffee pot that provides a natural place to interact with others. Or, if you have a question, you can always just stop and ask. Being able to physically get together without having to make much effort is a real bonus for people working in the same office, but can be a bit more challenging if you are remote team member. But this can also be a blessing in disguise, allowing you to concentrate on projects more and be interrupted less often.
What many people don’t realize is that every interaction with fellow team member or collegue is a meeting, and having that meeting is taking he or she away from thier normal duties. Organizations don’t hire people to be in meetings all day, they hire them to be productive contributors to making the organzation as a whole successful. This is where being remote has it’s advantage, as it’s easier to turn off the outside world by turning off your virtual links where in an office you have to hide somewhere to when you need some heads down time.
I recently read the book “Read This Before Our Next Meeting“, which talks about how to improve the quality of the meetings you hold, and at the same time eliminate those pointless meetings that drag your team down. The big takeaway I had from the book is that you need to be respectful of other people’s time. How do you best do this in the context of meetings? Here’s some good starting points:
What are your pointers for effective meetings and finding ways to be respectful of people’s time? Let me know in comments.
Truncated by Planet PHP, read more at the original (another 658 bytes)
If you develop web apps, I encourage you to check out The Twelve-Factor App. This is an excellent resource for anyone building and deploying software-as-a-service. PHP has great support for many of the twelve-factors. I want to take a look at specifically how each factor may be applied to a PHP application.
I. Codebase“One codebase tracked in revision control, many deploys”
There’s really not much here that would be different in PHP versus any other language. Who isn’t using some form of revision control these days?
II. Dependencies“Explicitly declare and isolate dependencies”
There are a few tools available to PHP developers to help manage dependencies. The PEAR package manager may help here, but has its flaws. Pyrus, the PEAR2 package manager, looks promising. There’s also Composer. I’ve heard of people using their operating system’s package manager (e.g. RPM) to deploy their PHP applications and manage dependencies. I’m not sure if there any tools in PHP to enforce dependency isolation.
III. Config“Store config in the environment”
The simplest option here is to use environment variables. Many frameworks, including Zend Framework, allow you to have environment-specific configuration such as development, test, and production. This is not recommended for twelve-factor apps as it doesn’t scale as new environments are added.
“Treat backing services as attached resources”
There’s not really anything to say here that’s specific to PHP.
V. Build, release, run“Strictly separate build and run stages”
Phing or the more general-purpose Ant could work here. Even though it’s not written in PHP, there’s no reason why you couldn’t use Capistrano for this. I don’t think the run stage typically applies to PHP, as it happens implicitly as part of the release stage. However, there are tasks such as flushing the APC cache (if apc.stat=0) that might be considered part of the run stage.
“Execute the app as one or more stateless processes”
PHP processes are already stateless and shared-nothing. This makes PHP a great fit for twelve-factor apps. Memory space or the filesystem should be used as a short-lived, single-process cache. If you’re using an asset manager, such as Assetic, then any assets should be compiled and cached during the build stage.
VII. Port binding“Export services via port binding”
I don’t think port binding applies to PHP applications—at least not in the way it’s meant in twelve-factor. PHP relies on a web server and uses something like FastCGI or PHP-FPM to communicate with the web server. PHP 5.4 will have its own built-in web server, but this is intended for development use only. It’s really the combination of PHP and its web server that will be bound to a port. This brings up challenges when it comes to dependency management, as the web server itself is now a dependency.
VIII. Concurrency“Scale out via the process model”
I’m not sure how processes would become first-class citizens in a PHP web application. However, each individual request/response cycle is handled by its own process. In that regard, PHP already uses the process model.
IX. Disposability“Maximize robustness with fast startup and graceful shutdown”
PHP processes are
Truncated by Planet PHP, read more at the original (another 1526 bytes)
While profiling SabreDAV, I noticed a few times more than half of the request time was spent in the autoloader.
So instead of autoloading, now I prefer to unconditionally include every file for each package (there are 5 packages). For a while I manually maintained these files manually, but a while back I automated this process.
This is how you run it:
- phpincludes . includes.php
This will generate a file such as:
- <?php
- // Begin includes
- include __DIR__ . '/Interface1.php';
- include __DIR__ . '/Class1.php';
- include __DIR__ . '/Class2.php';
- include __DIR__ . '/Class3.php';
- // End includes
You can edit everything before "// Begin includes" and after "// End includes". Subsequent edits will only replace the lines in between those comments.
The script will automatically expand classes and interface dependencies and load them in the correct order. It also has support for a PHP 5.2-compatible syntax (dirname(__FILE__) instead of __DIR__).
If you like it, head over to github, or install it with:
- pear channel-discover pear.sabredav.org
- pear install sabredav/PHPIncludes