In my previous post, I mentioned I’m working on a database driver for Drupal 7 for the Akiban Server. However, we have some clients who use Drupal 6 so I wanted to talk about how we work with those clients in this post.

Drupal 6 does not have a database abstraction layer so it is not as easy to integrate Akiban in this case. With Drupal 6, we do not attempt to run all of Drupal on Akiban. What we have done with our existing customers who use Drupal 6 is to send certain problem queries to Akiban (running in our MySQL replication configuration) and everything else to MySQL. The Akiban Server speaks the PostgreSQL protocol as I discussed before. Hence, for Drupal 6, we use the PostgreSQL database driver to talk to Akiban.

Since Drupal 6 does not support speaking to multiple different database backends at the same time, we apply a patch to get started. Basically, this patch allows connections to be open to both an existing MySQL server and the Akiban Server at the same time. It could be used to do the same with a PostgreSQL database as well.

Once that patch is applied, to send a query to Akiban, the active database connection is set to Akiban and a query is fired off for the Akiban Server to execute. The following code snippet shows an example.

if ($this->use_akiban) {
   db_set_active('akiban');
   $result = db_query_range($query, 
                            $args, 
                            $offset, 
                            $this->pager['items_per_page']);
}
db_set_active('default')
if (! $result) { /* if Akiban failed go to regular MySQL */
   $result = db_query_range($query, 
                            $args, 
                            $offset, 
                            $this->pager['items_per_page']);
}

As can be seen in the code above, its also possible to detect if the query failed against Akiban and re-issue it against MySQL.

When deployed in this configuration, connection details for the Akiban Server is specified in the settings.php file for a Drupal site.

$db_url = array(
  "default" => "mysql://drupal:drupal@mysql_hostname/drupal_schema",
  "akiban"  => "pgsql://drupal:drupal@akiban_hostname:15432/drupal_schema"
);

We’ve also done some work with clients where we have made patches to the Views module for Drupal. These patches allow a client to send the queries generated by a specific view to an Akiban Server.

Taken together, this makes it quite easy for us to work with Drupal 6 and send problematic queries to Akiban.



blog comments powered by Disqus

Published

18 May 2012

Category

planet drupal