monetdbd支持使用广播协议进行发现, 同时支持设置数据库的tag, 支持使用通配符连接数据库.
支持通配符有一个好处, 如果通配符匹配多个数据库的话, 会采用round-robin的方式连接, 例如 :
在一个广播域中, 有两个数据库名都是test, 分别设置了tag 221和150
[root@db-172-16-3-221 ~]# monetdb discover
location
mapi:monetdb://150.sky-mobi.com:50000/test/150
mapi:monetdb://db-172-16-3-221:50000/test/221
如果使用通配符, test/* 则匹配test/150 和test/221 .
那么会轮询方式连接, 例如
如果库名不一样的话, 使用*/来匹配, 即用*来替换库名. 例如 :
又或者*/*
[参考]
[root@db-172-16-3-221 ~]# mclient -h 172.16.3.221 test/*
Welcome to mclient, the MonetDB/SQL interactive terminal (Jan2014-SP3)
Database: MonetDB v11.17.21 (Jan2014-SP3), 'mapi:monetdb://150.sky-mobi.com:50000/test'
Type \q to quit, \? for a list of available commands
auto commit mode: on
sql>\q
[root@db-172-16-3-221 ~]# mclient -h 172.16.3.221 test/*
Welcome to mclient, the MonetDB/SQL interactive terminal (Jan2014-SP3)
Database: MonetDB v11.17.21 (Jan2014-SP3), 'mapi:monetdb://db-172-16-3-221:50000/test'
Type \q to quit, \? for a list of available commands
auto commit mode: on
sql>\q
如果库名不一样的话, 使用*/来匹配, 即用*来替换库名. 例如 :
[root@db-172-16-3-221 ~]# mclient -h 172.16.3.221 */221
Welcome to mclient, the MonetDB/SQL interactive terminal (Jan2014-SP3)
Database: MonetDB v11.17.21 (Jan2014-SP3), 'mapi:monetdb://db-172-16-3-221:50000/test'
Type \q to quit, \? for a list of available commands
auto commit mode: on
sql>\q
又或者*/*
[root@db-172-16-3-221 ~]# mclient -h 172.16.3.221 */*
Welcome to mclient, the MonetDB/SQL interactive terminal (Jan2014-SP3)
Database: MonetDB v11.17.21 (Jan2014-SP3), 'mapi:monetdb://db-172-16-3-221:50000/test'
Type \q to quit, \? for a list of available commands
auto commit mode: on
sql>\q
[root@db-172-16-3-221 ~]# mclient -h 172.16.3.221 */*
Welcome to mclient, the MonetDB/SQL interactive terminal (Jan2014-SP3)
Database: MonetDB v11.17.21 (Jan2014-SP3), 'mapi:monetdb://150.sky-mobi.com:50000/test'
Type \q to quit, \? for a list of available commands
auto commit mode: on
sql>\q
如果客户端和数据库可以直接连接, 那么建议网络中的monetdbd, 设置forward=redirect.
如果客户端不能直接和数据库相连, 那么建议设置forward=proxy, 例如处于网络边界的monetdbd, 设置forward=proxy.
因此MonetDB天生就具备了负载均衡的能力, 当然还可以使用其他的方案, 例如常用的haproxy.
3. man monetdbd
REMOTE DATABASES
The neighbor discovery capabilities of monetdbd allow a user to contact a remote database transparently, as if
it were a local database. By default, all local databases are announced in the network, such that neighbors
can pick them up to make them available for their local users. This feature can be disabled globally, or on
database level. For the latter, the monetdb(1) utility can be used to change the share property of a database.
While neighbor discovery in itself is sufficient to locate a database in a cluster, it is limited in expres-
siveness. For instance, database names are assumed to be unique throughout the entire system. This means
local databases overshadow remote ones, and duplicate remote entries cannot be distinguished. To compensate
for this, monetdbd allows to adds a tag to each database that is being shared. This tag is sent in addition to
the database name, and only understood by other monetdbds.
Tags are arbitrary ASCII-strings matching the pattern [A-Za-z0-9./]+. There are no assumed semantics in the
tag, which allows for multiple approaches when using the tag. The tag is always used in combination with the
database name. For this, the ‘/’ character is used as separator, which hence suggests the user to use that
character as separator for multilevel tags. Monetdbd allows common path globbing using ‘*’ on tags, which
allows for many use-cases. Consider for instance the following three databases with their tag:
dbX/master/tableQ
dbY/slave/tableQ
dbZ/slave/tableQ
A default match has implicit ‘/*’ added to the search, making more generic search strings match more specific
ones. Hence, a connect with database dbX is the same as dbX/* and hence matches dbX/master/tableQ. Similar, a
database connect for */master matches the same database as before. Note that the implicit ‘/*’ is not added if
that would cause no matches, such as for */master/tableQ which would return all masters for tableQ, which in
our hypothetical example is only dbX. In contrast, a database connect for */slave/tableQ matches with either
dbY or dbZ. Monetdbd returns the two options to the client in a round-robin fashion, such that subsequent con-
nects for the same pattern result in a load-balanced connect to either of both databases.
With tags in use, one can possibly make distinction between databases, if setup like that. The previous exam-
ple could hence also be setup like this:
tableQ/master
tableQ/slave
tableQ/slave
Connecting to tableQ/slave would now return either of both databases even though they are not unique (apart
from the host they are located on, which is not shown in the example). While being confusing for humans, for
monetdbd it is the same situation as in the previous example. However, because globbing allows to make things
easier to understand, tags for both slaves could be changed to slaveX or slave/X and use the necessary pattern
to match them. It is up to the user to decide how to use the tags.