Using Akiban Server with Drupal 6
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.
<span class="x">if ($this->use_akiban) {</span><span class="x"> db_set_active('akiban');</span><span class="x"> $result = db_query_range($query, </span><span class="x"> $args, </span><span class="x"> $offset, </span><span class="x"> $this->pager['items_per_page']);</span><span class="x">}</span><span class="x">db_set_active('default')</span><span class="x">if (! $result) { /* if Akiban failed go to regular MySQL */</span><span class="x"> $result = db_query_range($query, </span><span class="x"> $args, </span><span class="x"> $offset, </span><span class="x"> $this->pager['items_per_page']);</span><span class="x">}</span>
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.
<span class="x">$db_url = array(</span><span class="x"> "default" => "mysql://drupal:drupal@mysql_hostname/drupal_schema",</span><span class="x"> "akiban" => "pgsql://drupal:drupal@akiban_hostname:15432/drupal_schema"</span><span class="x">);</span>
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.