Sqlite3 config handler
- From:
- William Martin
- Date:
- 2011-11-10 @ 13:14
Hi,
I have just read the code of the default config loader, and i have a
question about it.
What do you need the "server_id" parameter in the function
"tns_value_t *default_load_routes(int host_id, int server_id)" ?
Or if you want : Can you explain me the SQL request into this function :
SELECT route.id, route.path, route.target_id, route.target_type FROM
route, host WHERE host_id=%d AND host.server_id=%d AND host.id =
route.host_id
We are searching all route for a specified host for a server.
CREATE TABLE server (id INTEGER PRIMARY KEY,
uuid TEXT,
access_log TEXT,
error_log TEXT,
chroot TEXT DEFAULT '/var/www',
pid_file TEXT,
default_host TEXT,
name TEXT DEFAULT '',
bind_addr TEXT DEFAULT "0.0.0.0",
port INTEGER,
use_ssl INTEGER default 0);
INSERT INTO "server"
VALUES(1,'971e0536-a92d-41e2-bea3-9af54bfd6fd9','/mongrel2/logs/access.log','/mongrel2/logs/error.log','./','/mongrel2/run/mongrel2.pid','localhost','main','0.0.0.0',6767,0);
INSERT INTO "server"
VALUES(2,'971d0536-a92d-41e2-bea3-9af54bfd6fd9','/mongrel2/logs/access.log','/mongrel2/logs/error.log','./','/mongrel2/run/mongrel2.pid','localhost','main','0.0.0.0',6763,0);
Here we can see that, each server match a row in the database, and
each server have an unique id (primary key).
A server can handle multiple host which have uid too.
The most important point is if you are sharing host between many
servers, m2sh will create one host row per server with different id
because host.id is an primary key too.
CREATE TABLE host (id INTEGER PRIMARY KEY,
server_id INTEGER,
maintenance BOOLEAN DEFAULT 0,
name TEXT,
matching TEXT);
INSERT INTO "host" VALUES(1,1,0,'localhost','localhost');
INSERT INTO "host" VALUES(2,1,0,'localhost','localhost');
INSERT INTO "host" VALUES(3,2,0,'localhost','localhost');
INSERT INTO "host" VALUES(4,2,0,'localhost','localhost');
After the loading of the host, we want to load all route for the
previously host loaded with the function "tns_value_t
*default_load_routes(int host_id, int server_id)".
We can't have multiple entry into host table with the same id and server_id.
So in the route table those where clause are equals :
- WHERE host_id=%d AND host.server_id=%d AND host.id = route.host_id
- WHERE host_id=%d
CREATE TABLE route (id INTEGER PRIMARY KEY,
path TEXT,
reversed BOOLEAN DEFAULT 0,
host_id INTEGER,
target_id INTEGER,
target_type TEXT);
INSERT INTO "route" VALUES(1,'/',0,1,1,'handler'); ->
route 1 for host 1, server 1
INSERT INTO "route" VALUES(2,'/a',0,1,2,'handler'); ->
route 2 for host 1, server 1
INSERT INTO "route" VALUES(3,'/eee',0,2,1,'handler'); ->
route 1 for host 2, server 1
INSERT INTO "route" VALUES(4,'/aeee',0,2,2,'handler'); ->
route 2 for host 2, server 1
INSERT INTO "route" VALUES(5,'/',0,3,1,'handler'); ->
route 1 for host 3, server 2
INSERT INTO "route" VALUES(6,'/a',0,3,2,'handler'); ->
route 2 for host 3, server 2
INSERT INTO "route" VALUES(7,'/eee',0,4,1,'handler'); ->
route 1 for host 4, server 2
INSERT INTO "route" VALUES(8,'/aeee',0,4,2,'handler'); ->
route 2 for host 4, server 2
I have attach the mongrel2.conf file, i use for the example.
Maybe I not aware of a special config, i really need some one help me
to fix that.
Thanks,
William MARTIN