On testing Drupal 4.7 I was saddened to see that 4.7 still requires LOCK TABLE permission - only this time it's harder to fix.

Previously, the sole fix was in db_next_id in database.mysql.inc - of course such fixes are hotly contested and largey unsupported.

Now, two new functions have been added, db_lock_table and db_unlock_table. These are called to lock the variables and the cache tables in bootstrap.inc.

So, where previously, an update to db_next_id in database.mysql.inc such as:

function db_next_id($name) {
  $name = db_prefix_tables($name);
  $id = db_result(db_query("SELECT id FROM {sequences} WHERE name = '%s' FOR UPDATE", $name)) + 1;
  db_query("REPLACE INTO {sequences} VALUES ('%s', %d)", $name, $id);

  return $id;
}

has now to be replicated to bootstrap.inc such as:

function variable_set($name, $value) {
  global $conf;

  db_query("SELECT name FROM {variable} WHERE name = '%s' FOR UPDATE", $name);
  db_query("REPLACE INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
  if (!db_affected_rows()) {
    db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s') FOR UPDATE", $name, serialize($value));
  }

  cache_clear_all('variables');

  $conf[$name] = $value;
}

and

function cache_set($cid, $data, $expire = CACHE_PERMANENT, $headers = NULL) {
  db_query("SELECT cid FROM {cache} WHERE cid = '%s' FOR UPDATE", $cid);
  db_query("REPLACE INTO {cache} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $data, time(), $expire, $headers);
  if (!db_affected_rows()) {
    db_query("INSERT INTO {cache} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s') FOR UPDATE", $cid, $data, time(), $expire, $headers);
  }
}

I am only checking now if these (for want of a better word) fixes work on a restricted environment.

Before anyone asks why don't I change provider - I like the one I have already - the service is great - I don't want to change for a simple 'LOCK TABLES' issue.

Paddy.

Comments

Cvbge’s picture

You can take part in discussion on http://drupal.org/node/39460

--
Polska strona o Drupalu: http://drupal.cvbge.org

Greg J. Smith’s picture

Hey, none of the other fixes worked for me.. but this has. Thanks so much!

,g

--
greg smith
http://www.serialconsign.com
http://www.vagueterrain.net

timtimar’s picture

This also worked for me!!

THANKS!!!!

Treesong’s picture

This fix still seems to be working fine for me so far. BUT... the one site where I'm expecting a ton of users isn't public yet. Going public is still a ways off... at least a couple of months. But I'm concerned that I'll end up with data corruption and have to switch providers on the fly, probably leading to whole days of downtime. Is this still a concern with this fix?

I would just move to another host, but I have half a dozen sites on this one, and it'd take time and energy (and money!) to move them all. So, if the potential errors from this will be minor and infrequent, then I may just deal with it. But if you think this is the sort of thing that could be very serious, then I may have to move. (Or, I can always hope that developers will decide to come up with a fix! I may give it a try myself eventually but I haven't done much with PHP-MySQL relations and don't have too much time to play around with code anymore unless it's something minor/simple...)

paddy_deburca’s picture

This fix ignored table locking completely. Drupal relies on table locking to enforce sequential sequence numbers. Without table locking there is a possibility that two posts, occuring at the same moment in time, will end up with the same ID.

The key to this is "two posts, occuring at the same time" - visitors, no matter how many, will not cause any problems. But, if you will have a ton of users that will all be actively contributing content - there may be an issue.

At least, you can make an informed decision. There is a risk of data corruption - I don't know what the percentages are - but the risk is there. Weigh up the pros and cons of this solution against the pros and cons of moving ISP. If you choose this solution, have at least, a contingency plan in case your site is a overwhelming success and there are tons of users.

Paddy.

http://deburca.org, and http://amadain.net

zacknyc’s picture

I use Godaddy for hosting and testing out drupal on it. I got an error message when using search module. Does this have to do with Lock Tables issue? User denied.

I checked your site http://amadain.net/?q=search and your search doesn't work either.

Cwolly’s picture

Great job with this man. It works perfectly for us little folks that don't get much traffic. You the man.

paddy_deburca’s picture

Please go and have a look at a robust solution to this problem

http://drupal.org/node/77312

Paddy.

http://deburca.org, and http://amadain.net