cache_set duplicated keys error.

Kars-T - August 2, 2009 - 15:08
Project:Memcache API and Integration
Version:6.x-1.3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

In regards of Issue http://drupal.org/node/426712 which is about D5 I made a patch for D6.

I have the same errors as on a high traffic site there seem to be some INSERTs running between the DELETE and the new INSERT and I get a lot of "Duplicate entry ... for key 1 query: INSERT INTO cache_filter ... in ...memcache.db.inc in Zeile 149." if I flush the cache.

From Line 147

<?php
    
// Save to the database
   
db_query("DELETE FROM {%s} WHERE cid = '%s'", $table, $cid);
   
db_query("INSERT INTO {%s} (cid, data, expire, created, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', '%s')", $table, $cid, $data, $expire, $created, $headers, $serialized);
?>

This patch uses the same syntax as the core function does
http://api.drupal.org/api/function/cache_set/6

<?php
   
// Save to the database
   
db_query("UPDATE {". $table ."} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, $created, $expire, $headers, $serialized, $cid);
    if (!
db_affected_rows()) {
      @
db_query("INSERT INTO {". $table ."} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, $created, $expire, $headers, $serialized);
    }
?>

And from my experience with simpletest {%s} does not always work as the table alias is not rewritten and you have to use {". $table ."}.

AttachmentSize
memcache.db_.inc_.patch1.1 KB

#1

bertboerland@ww... - September 3, 2009 - 00:12

http://drupal.org/node/566832 was marked as a dub. impact can be high for cached pages. please review this patch and apply

 
 

Drupal is a registered trademark of Dries Buytaert.