<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Toru Maesaka &#187; api</title>
	<atom:link href="http://torum.net/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://torum.net</link>
	<description>Hackaholic and a Web Addict based in Tokyo</description>
	<lastBuildDate>Tue, 28 Feb 2012 10:52:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Extending CREATE TABLE Syntax in Drizzle</title>
		<link>http://torum.net/2010/07/extending-create-table-syntax-in-drizzle/</link>
		<comments>http://torum.net/2010/07/extending-create-table-syntax-in-drizzle/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 17:37:42 +0000</pubDate>
		<dc:creator>Toru Maesaka</dc:creator>
				<category><![CDATA[drizzle]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[api]]></category>

		<guid isPermaLink="false">http://torum.net/?p=2367</guid>
		<description><![CDATA[The flexibility to add table-specific options for things like compression, encryption and optimization can be useful to storage engine developers as this flexibility can open up new possibilities. Here&#8217;s what I&#8217;m talking about: CREATE TABLE t1 &#40; ... &#41; ENGINE = my_engine, MY_OPTION = your_arg; Supporting this is relatively easy in Drizzle and this API [...]]]></description>
			<content:encoded><![CDATA[<p>The flexibility to add table-specific options for things like compression, encryption and optimization can be useful to storage engine developers as this flexibility can open up new possibilities. Here&#8217;s what I&#8217;m talking about:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> t1 <span style="color: #66cc66;">&#40;</span>
  <span style="color: #66cc66;">...</span>
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> my_engine<span style="color: #66cc66;">,</span> MY_OPTION <span style="color: #66cc66;">=</span> your_arg;</pre></div></div>

<p>Supporting this is relatively easy in Drizzle and this API feature (and a bit more) is <a href="http://askmonty.org/wiki/Manual:Extending_CREATE_TABLE">available in MariaDB</a> as well. Unfortunately Drizzle&#8217;s method to do this isn&#8217;t documented in the Wiki yet but it should be added when our Storage Engine API becomes stable (as in, no interface changes).</p>
<h3>Implement StorageEngine::doValidateTableOptions()</h3>
<p>Here&#8217;s the actual interface.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">bool</span> StorageEngine<span style="color: #008080;">::</span><span style="color: #007788;">doValidateTableOptions</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> <span style="color: #000040;">&amp;</span>key,
                                           <span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">string</span> <span style="color: #000040;">&amp;</span>state<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>This function is called for each table options given at CREATE TABLE syntax execution. The first argument, <em>key</em> is a const reference to a string that represents the option name. The second argument, <em>state</em> represents the argument given for that option.</p>
<p>Therefore, given: <em>COMPRESSION = YES_PLEASE</em>, <em>key</em> would be &#8220;COMPRESSION&#8221; and <em>state</em> would be &#8220;YES_PLEASE&#8221;. The objective of this function is to check whether the key/state pair makes sense to your storage engine. If this function returns false, Drizzle will return an error for the CREATE TABLE query. Personally I think this interface can be improved to be a bit more Developer friendly, such as making life easier to validate numeric values without enforcing the developer to play around with the data. Saying that, given the pace that Drizzle is growing, this could be improved before we know it.</p>
<h3>Access Options at StorageEngine::doCreateTable()</h3>
<p>Here&#8217;s the actual interface for doCreateTable().</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> doCreateTable<span style="color: #008000;">&#40;</span>drizzled<span style="color: #008080;">::</span><span style="color: #007788;">Session</span> <span style="color: #000040;">&amp;</span>session,
                  drizzled<span style="color: #008080;">::</span><span style="color: #007788;">Table</span> <span style="color: #000040;">&amp;</span>table_arg,
                  <span style="color: #0000ff;">const</span> drizzled<span style="color: #008080;">::</span><span style="color: #007788;">TableIdentifier</span> <span style="color: #000040;">&amp;</span>identifier,
                  drizzled<span style="color: #008080;">::</span><span style="color: #007788;">message</span><span style="color: #008080;">::</span><span style="color: #007788;">Table</span> <span style="color: #000040;">&amp;</span>table_proto<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Given that the options were successfully validated, doCreateTable() is called next. In Drizzle, all information regarding a table (including options) is represented in a Google Protocol Buffer message. A reference to that message object is passed to doCreateTable() as the fourth argument so all you need to do is loop through the options list in the message object and extract what you need. Here&#8217;s a minimal example that only takes care of one option.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> n_options <span style="color: #000080;">=</span> table_proto.<span style="color: #007788;">engine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">options_size</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> i <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> i <span style="color: #000080;">&lt;</span> n_options<span style="color: #008080;">;</span> i<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">if</span> <span style="color: #008000;">&#40;</span>table_proto.<span style="color: #007788;">engine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">options</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span>.<span style="color: #007788;">name</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">==</span> <span style="color: #FF0000;">&quot;my_option_name&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// Do whatever you like with this stream.</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">istringstream</span> stream<span style="color: #008000;">&#40;</span>table_proto.<span style="color: #007788;">engine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">options</span><span style="color: #008000;">&#40;</span>i<span style="color: #008000;">&#41;</span>.<span style="color: #007788;">state</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>The above example should be simple to extend to handle multiple options. What&#8217;s really important in the above example is that the option name can be accessed with the name() accessor and the state (value) of that option with the state() accessor.</p>
<p>So, that&#8217;s all I have to cover for now. I hope this feature will help storage engine developers create and provide useful table specific features for their engine.</p>
<p>Happy Hacking.</p>
]]></content:encoded>
			<wfw:commentRss>http://torum.net/2010/07/extending-create-table-syntax-in-drizzle/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Storage Engine Tests in Drizzle. Organized!</title>
		<link>http://torum.net/2009/12/storage-engine-tests-in-drizzle-organized/</link>
		<comments>http://torum.net/2009/12/storage-engine-tests-in-drizzle-organized/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 15:33:45 +0000</pubDate>
		<dc:creator>Toru Maesaka</dc:creator>
				<category><![CDATA[drizzle]]></category>
		<category><![CDATA[oss]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://torum.net/?p=2316</guid>
		<description><![CDATA[Good news to storage engine developers. In Drizzle, you can now place your engine specific test files (.test and .result) in your engine&#8217;s directory. Here&#8217;s an example in BlitzDB: First, let&#8217;s look inside BlitzDB&#8217;s directory. $ ls -l blitzdb/ Total 60 -rw-r--r-- 1 maesaka maesaka 649 2009-12-13 20:51 AUTHORS -rw-r--r-- 1 maesaka maesaka 5878 2009-12-13 [...]]]></description>
			<content:encoded><![CDATA[<p>Good news to storage engine developers. In Drizzle, you can now place your engine specific test files (.test and .result) in your engine&#8217;s directory. Here&#8217;s an example in BlitzDB:</p>
<p>First, let&#8217;s look inside BlitzDB&#8217;s directory.</p>

<div class="wp_syntax"><div class="code"><pre class="null" style="font-family:monospace;">$ ls -l blitzdb/
Total 60
-rw-r--r-- 1 maesaka maesaka   649 2009-12-13 20:51 AUTHORS
-rw-r--r-- 1 maesaka maesaka  5878 2009-12-13 20:51 blitzdata.cc
-rw-r--r-- 1 maesaka maesaka  3347 2009-12-13 20:51 blitzlock.cc
-rw-r--r-- 1 maesaka maesaka 18146 2009-12-13 20:51 ha_blitz.cc
-rw-r--r-- 1 maesaka maesaka  8360 2009-12-13 20:51 ha_blitz.h
-rw-r--r-- 1 maesaka maesaka   289 2009-12-13 20:51 plugin.ac
-rw-r--r-- 1 maesaka maesaka   261 2009-12-13 23:51 plugin.ini
drwxr-xr-x 4 maesaka maesaka  4096 2009-12-13 23:51 tests</pre></div></div>

<p>Notice the final line? that&#8217;s where the tests are kept. So, let&#8217;s look inside it.</p>

<div class="wp_syntax"><div class="code"><pre class="null" style="font-family:monospace;">$ ls -l blitzdb/tests/
Total 8
drwxr-xr-x 2 maesaka maesaka 4096 2009-12-13 23:51 r
drwxr-xr-x 2 maesaka maesaka 4096 2009-12-13 23:51 t</pre></div></div>

<p>As you can see, there are two directories. By now, storage engine developers would have caught on to what&#8217;s going on. The r/ directory is where the .result files are kept and t/ is where the .test files are kept. This is exactly the same layout as what we&#8217;re used to working on (&#8220;src/tests/t/&#8221; and &#8220;src/tests/r/&#8221;).</p>

<div class="wp_syntax"><div class="code"><pre class="null" style="font-family:monospace;">$ ls -l blitzdb/tests/t/
Total 8
-rw-r--r-- 1 maesaka maesaka   21 2009-12-13 23:51 blitzdb-master.opt
-rw-r--r-- 1 maesaka maesaka 1964 2009-12-13 23:51 blitzdb.test</pre></div></div>

<p>The .opt file is used to make sure that the server is started with your storage engine enabled. You simply write the startup option inside the .opt file. Here&#8217;s what mine looks like at the moment (there&#8217;s only a single line in it).</p>

<div class="wp_syntax"><div class="code"><pre class="null" style="font-family:monospace;">$ less blitzdb/tests/t/blitzdb-master.opt
--plugin_add=blitzdb
blitzdb/tests/t/blitzdb-master.opt (END)</pre></div></div>

<p>Next step is actually running it. You simply specify your engine name with the &#45;&#45;suite option to dtr and you&#8217;re done! Unfortunately the symlink permission for dtr seems broken on my repository so I&#8217;ll directly call test-run.pl in this example.</p>

<div class="wp_syntax"><div class="code"><pre class="null" style="font-family:monospace;">$ ./test-run.pl --suite=blitzdb
Logging: ./test-run.pl --suite=blitzdb
MySQL Version 2009.12.1245
Use of uninitialized value in scalar assignment at ./test-run.pl line 1416.
Using MTR_BUILD_THREAD      = -69.4
Using MASTER_MYPORT         = 9306
Using MASTER_MYPORT1        = 9307
Using SLAVE_MYPORT          = 9308
Using SLAVE_MYPORT1         = 9309
Using SLAVE_MYPORT2         = 9310
Using MC_PORT               = 9316
Killing Possible Leftover Processes
Removing Stale Files
Creating Directories
=======================================================
DEFAULT STORAGE ENGINE: innodb
TEST                           RESULT         TIME (ms)
-------------------------------------------------------
&nbsp;
blitzdb.blitzdb                [ pass ]             63
-------------------------------------------------------
Stopping All Servers
All 1 tests were successful.
The servers were restarted 1 times
Spent 0.063 of 2 seconds executing testcases</pre></div></div>

<p>That&#8217;s it! I really like this change since it makes sense for engine-specific tests to belong inside the storage engine&#8217;s directory. It makes conceptual sense and it&#8217;s a good step towards differentiating the database kernel and the storage engine, which <a href="http://inaugust.com/">Monty Taylor</a> is actively hacking on. Hopefully he&#8217;ll blog more about these changes soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://torum.net/2009/12/storage-engine-tests-in-drizzle-organized/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drizzle Storage Engine Alias!</title>
		<link>http://torum.net/2009/11/drizzle-storage-engine-alias/</link>
		<comments>http://torum.net/2009/11/drizzle-storage-engine-alias/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 03:34:20 +0000</pubDate>
		<dc:creator>Toru Maesaka</dc:creator>
				<category><![CDATA[drizzle]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[storage]]></category>

		<guid isPermaLink="false">http://torum.net/?p=2302</guid>
		<description><![CDATA[Admittedly I&#8217;m a lazy guy. Due to this nature I&#8217;m a little behind on the updates made to the Drizzle Storage Engine API. From lurking through the source code in the Drizzle trunk, I&#8217;ve noticed these changes. Engines can now have an alias handler class is replaced by the Cursor class Engine handler is now [...]]]></description>
			<content:encoded><![CDATA[<p>Admittedly I&#8217;m a lazy guy. Due to this nature I&#8217;m a little behind on the updates made to the Drizzle Storage Engine API. From lurking through the source code in the Drizzle trunk, I&#8217;ve noticed these changes.</p>
<ul>
<li>Engines can now have an alias</li>
<li>handler class is replaced by the Cursor class</li>
<li>Engine handler is now a subclass of Cursor</li>
<li>Table definitions are handled/stored by the storage engine</li>
<li>doCreateTable(), doDropTable(), doGetTableNames(), doGetTableDefinition()</li>
</ul>
<p>Currently I&#8217;m trying to catch up with the updated Drizzle Storage API and take this opportunity to rewrite most of BlitzDB. The reason is that the more I understand TC internal, the more mistakes I realized that I&#8217;ve made. I&#8217;ll blog more about this soon. Instead, I&#8217;m going to introduce something small but nice today.</p>
<p>A while back I poked folks like<a href="http://inaugust.com/"> Monty Taylor</a> and <a href="http://www.flamingspork.com/blog/">Stewart Smith</a> that it would be cool if engines could have an alias. I mentioned this because <a href="http://www.innodb.com">InnoDB</a> was allowed to use both &#8220;innodb&#8221; and &#8220;innobase&#8221; in the system whereas other engines could only have one name. Another reason I was interested in this issue was that I couldn&#8217;t understand how InnoDB could use two names since there was no way to do this in the old interface. Turns out InnoDB was treated specially in the core, which is obviously not desirable in a microkernel philosophy.</p>
<p>In the current Drizzle Storage Engine API, there is a function called addAlias(). By calling this function inside the storage engine constructor, you can allow your engine to have multiple aliases. For experiment purposes I wrote this to BlitzDB:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">BlitzEngine<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">string</span> <span style="color: #339933;">&amp;</span>name_arg<span style="color: #009900;">&#41;</span>
  <span style="color: #339933;">:</span> drizzled<span style="color: #339933;">::</span><span style="color: #202020;">plugin</span><span style="color: #339933;">::</span><span style="color: #202020;">StorageEngine</span><span style="color: #009900;">&#40;</span>name_arg<span style="color: #339933;">,</span> HTON_CAN_RECREATE<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  table_definition_ext <span style="color: #339933;">=</span> drizzled<span style="color: #339933;">::</span><span style="color: #202020;">plugin</span><span style="color: #339933;">::</span><span style="color: #202020;">DEFAULT_DEFINITION_FILE_EXT</span><span style="color: #339933;">;</span>
  addAlias<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;BLITZ&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  addAlias<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;TCDB&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here, I added aliases BLITZ and TCDB. TCDB is my way of showing respect to <a href="http://1978th.net/">Mikio</a> and <a href="http://1978th.net/tokyocabinet/">Tokyo Cabinet</a>. So given the above, we should now be able to create tables with three names.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;">drizzle<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> t1 <span style="color: #66cc66;">&#40;</span>foo int<span style="color: #66cc66;">&#41;</span> engine<span style="color: #66cc66;">=</span>blitzdb;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span> rows affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
drizzle<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> t2 <span style="color: #66cc66;">&#40;</span>foo int<span style="color: #66cc66;">&#41;</span> engine<span style="color: #66cc66;">=</span>blitz;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span> rows affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span> sec<span style="color: #66cc66;">&#41;</span>
&nbsp;
drizzle<span style="color: #66cc66;">&gt;</span> <span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> t3 <span style="color: #66cc66;">&#40;</span>foo int<span style="color: #66cc66;">&#41;</span> engine<span style="color: #66cc66;">=</span>tcdb;
Query OK<span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">0</span> rows affected <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0.01</span> sec<span style="color: #66cc66;">&#41;</span></pre></div></div>

<p>Success! Yep, this is something so trivial that I think most people wouldn&#8217;t care about but I was happy to see this update in the trunk :)</p>
]]></content:encoded>
			<wfw:commentRss>http://torum.net/2009/11/drizzle-storage-engine-alias/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

