View Source

by 陈思儒
1、添加规则函数case、range、增加表达式   (boolean表达式 ? 表达式1: 表达式2)
range函数:
&nbsp; id in range(12,16,0,1) 表示 id>12 and id<=16
&nbsp; id in range(12,16,0,0) 表示 id>12 and id<16
&nbsp; id in range(12,16,1,0) 表示 id>=12 and id<16
&nbsp; id in range(12,16,1,1) 表示 id>=12 and id<=16
case 函数
&nbsp; &nbsp;case &nbsp;(abs(hash(SDID)) % 32) &nbsp;when range(0,8,1,0) then (isReadStatment ? ’server1′ : ’server1_write’);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when range(8,16,1,0) then (isReadStatment ? ’server2′ : ’server2_write’);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when range(16,24,1,0) then ‘(isReadStatment ? ’server3′ : ’server3_write’)';
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else ’server4′
&nbsp; &nbsp;END CASE;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
2、增加bool 类型的规则内置变量 isReadStatment
&nbsp;用户可以在规则的表达式中使用比如 : &nbsp;isReadStatment? ‘pool1′ : ‘pool2′
3、稳定性增强,解决了在大并发下需要多个数据库聚合结果集的时候出现数据异常而无法返回给客户端的问题
4、规则属性新增加ruleResult属性,有3种类型(BOOLEAN、POOLNAME、INDEX)
&nbsp;BOOLEAN --- 默认值、结果一定是布尔值,表示执行的sql是否匹配当前的规则
&nbsp;POOLNAME --- 结果是字符串,是由dbpool名字组成的字符串,多个pool以分号间隔(rule中的defaultPools、readPools、writePools无效)
&nbsp;INDEX --- 结果是数字 ,如果>=0 则表示当前规则匹配,并且将相关index的pool返回
&nbsp;
&nbsp; &nbsp; <tableRule name=”LIST_FRIEND_GROUP,RELATION_FOLLOW” schema=”sd_relation”
&nbsp; &nbsp; &nbsp; defaultPools=”server1,server2,server3,server4″>
&nbsp; &nbsp; &nbsp;<rule name=”rule1″ ruleResult=”POOLNAME”>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<parameters>SDID</parameters>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<expression><\!\[CDATA\[
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var hashid = abs(hash(SDID)) % 32;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &nbsp;hashid &nbsp;when range(0,8,1,0) then (isReadStatment ? ’server1′ : ’server1_write’);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when range(8,16,1,0) then (isReadStatment ? ’server2′ : ’server2_write’);
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when range(16,24,1,0) then ‘(isReadStatment ? ’server3′ : ’server3_write’)';
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else ’server4′
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END CASE;
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\]\]></expression>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</rule>
&nbsp; &nbsp; </tableRule>
&nbsp; &nbsp; </tableRule>
&nbsp;下载地址 [https://sourceforge.net/projects/amoeba/]
by 陈思儒

1、添加规则函数case、range、增加表达式 &nbsp; (boolean表达式 ? 表达式1: 表达式2)

range函数:

&nbsp; id in range(12,16,0,1) 表示 id>12 and id<=16

&nbsp; id in range(12,16,0,0) 表示 id>12 and id<16

&nbsp; id in range(12,16,1,0) 表示 id>=12 and id<16

&nbsp; id in range(12,16,1,1) 表示 id>=12 and id<=16

case 函数

&nbsp; &nbsp;case &nbsp;(abs(hash(SDID)) % 32) &nbsp;when range(0,8,1,0) then (isReadStatment ? ’server1′ : ’server1_write’);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when range(8,16,1,0) then (isReadStatment ? ’server2′ : ’server2_write’);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when range(16,24,1,0) then ‘(isReadStatment ? ’server3′ : ’server3_write’)';

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else ’server4′

&nbsp; &nbsp;END CASE;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;

2、增加bool 类型的规则内置变量 isReadStatment

&nbsp;用户可以在规则的表达式中使用比如 : &nbsp;isReadStatment? ‘pool1′ : ‘pool2′

3、稳定性增强,解决了在大并发下需要多个数据库聚合结果集的时候出现数据异常而无法返回给客户端的问题

4、规则属性新增加ruleResult属性,有3种类型(BOOLEAN、POOLNAME、INDEX)

&nbsp;BOOLEAN --- 默认值、结果一定是布尔值,表示执行的sql是否匹配当前的规则

&nbsp;POOLNAME --- 结果是字符串,是由dbpool名字组成的字符串,多个pool以分号间隔(rule中的defaultPools、readPools、writePools无效)

&nbsp;INDEX --- 结果是数字 ,如果>=0 则表示当前规则匹配,并且将相关index的pool返回
\\

&nbsp; &nbsp; <tableRule name=”LIST_FRIEND_GROUP,RELATION_FOLLOW” schema=”sd_relation”

&nbsp; &nbsp; &nbsp; defaultPools=”server1,server2,server3,server4″>

&nbsp; &nbsp; &nbsp;<rule name=”rule1″ ruleResult=”POOLNAME”>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<parameters>SDID</parameters>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<expression><\!\[CDATA\[

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var hashid = abs(hash(SDID)) % 32;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case &nbsp;hashid &nbsp;when range(0,8,1,0) then (isReadStatment ? ’server1′ : ’server1_write’);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when range(8,16,1,0) then (isReadStatment ? ’server2′ : ’server2_write’);

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;when range(16,24,1,0) then ‘(isReadStatment ? ’server3′ : ’server3_write’)';

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else ’server4′

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;END CASE;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\]\]></expression>

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</rule>

&nbsp; &nbsp; </tableRule>

&nbsp; &nbsp; </tableRule>

&nbsp;下载地址 [https://sourceforge.net/projects/amoeba/]