Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

193 lines (139 sloc) 6.81 kb
Name
drizzle-nginx-module - an upstream module that talks to
mysql, drizzle, and sqlite3 by libdrizzle
Description
This is an nginx module integrating libdrizzle
(https://launchpad.net/libdrizzle) into nginx in an
non-blocking and streamming way.
Essentially it provides a very efficient and flexible way
for nginx internals to access mysql, drizzle, sqlite3,
as well as other RDBMS's that support the drizzle protocol
or mysql protocol. Also it can serve as a direct REST
interface to those RDBMS backends.
Currently it's not in the form of a standard nginx upstream
module, but fiddling with nginx's connection/event API
directly. This will change in the next few days or so.
After this stuff becomes a real upstream module, we can
take full advantage of the per-worker connection pool
mechanism provided by Maxim Dounin's ngx_upstream_keepalive
module:
http://mdounin.ru/hg/ngx_http_upstream_keepalive/
Synopsis
# GET /mysql
location /mysql {
drizzle;
drizzle_host 127.0.0.1;
drizzle_user db_user;
drizzle_pass db_password;
drizzle_db db_name;
drizzle_port 3306;
drizzle_sql 'select name from cats';
}
You'd better use pure IPs for "drizzle_host" like 127.0.0.1
rather than domains like "localhost", or you may observe server
hangs for reasons that we don't know ;)
Status
This module is NOT working yet but we're working hard
on it ;)
Output
This module generates binary query results in a format
that will be shared among the various nginx database
driver modules like ngx_postgresql and ngx_oracle.
For the HTTP response header part, the 200 OK status
code should always be returned.
The X-DBD special header should be set to the database
driver that generates this output. For instance, this
module adds the following output header:
X-DBD: drizzle 0.03
where 0.03 is this module's own version number.
The Content-Type is always set to
"application/octet-stream".
Below is the HTTP response body part:
Header part
u_char endian type (1 means big-endian and little
endian otherwise)
uint32_t format version
(v1.2.3 is represented as 1002003 in
decimal)
u_char result type
(0 means normal SQL result type,
fixed for now)
uint32_t standard error code
uint32_t driver-specific error code
uint32_t driver-specific error string length
u_char* driver-specific error string data
uint64_t database rows affected
uint64_t insert id (if none, 0)
Body part
0*Column (terminated by 32-bit 0)
uint32_t (non-zero) standard column type code
uint32_t driver-specific column type length
u_char* driver-specific column type data
uint32_t column name length
u_char* column name data
0*Row (terminated by 1 byte' zero)
u_char valid row (1 means valid, and 0 means
the row list terminator)
0*Field (count is predetermined by column number)
uint32_t field length
u_char field data (in textual representation)
On the nginx output chain link level, the following
components should be put into a single ngx_buf_t struct:
* the header AND the column list
* each field in each row (if any)
Installation
You should first install libdrizzle which can be obtained
from here:
https://launchpad.net/libdrizzle
Grab the nginx source code from nginx.net (<http://nginx.net/>), for
example, the version 0.8.29 (see nginx compatibility), and then build
the source with this module:
$ wget 'http://sysoev.ru/nginx/nginx-0.8.29.tar.gz'
$ tar -xzvf nginx-0.8.29.tar.gz
$ cd nginx-0.8.29/
# Here we assume you would install you nginx under /opt/nginx/.
$ ./configure --prefix=/opt/nginx \
--add-module=/path/to/drizzle-nginx-module
$ make -j2
$ make install
Download the latest version of the release tarball of this module from
drizzle-nginx-module file list
(<http://github.com/agentzh/drizzle-nginx-module/downloads>).
Compatibility
The following versions of Nginx should work with this module:
* 0.8.x (last tested version is 0.8.29)
* 0.7.x >= 0.7.44 (last tested version is 0.7.64)
Earlier versions of Nginx like 0.6.x and 0.5.x will *not* work.
If you find that any particular version of Nginx above 0.7.21 does not
work with this module, please consider reporting a bug.
Authors
chaoslawful (王晓哲)
agentzh (章亦春)
Copyright & License
This module is licenced under the BSD license.
Copyright (c) 2009, Taobao Inc., Alibaba Group ( http://www.taobao.com ).
Copyright (c) 2009, chaoslawful <chaoslawful@gmail.com>.
Copyright (C) 2009 by agentzh <agentzh@gmail.com>.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Taobao Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Jump to Line
Something went wrong with that request. Please try again.