在neo4j中有事务性密码端点 。 这允许客户端通过多个REST请求产生数据库事务。 第一个请求会打开一个新的事务,并返回用于后续请求包含事务ID的http Location头中同一事务的URL,例如
Location: http://192.168.0.10:7474/db/data/transaction/24
最后的数字是内部事务ID。 随后的closures事务的请求被发送到http://192.168.0.10:7474/db/data/transaction/24/commit 。
为了实现这一点,我使用haproxy后端configuration的以下片段:
backend neo4j-all option httpchk GET /db/manage/server/ha/available stick-table type integer size 1k expire 10m stick match path,word(4,/) stick store-response hdr(Location),word(6,/) server s1 127.0.0.1:7474 maxconn 32 check server s2 127.0.0.1:7475 maxconn 32 check server s3 127.0.0.1:7476 maxconn 32 check
一个粘性表填充事务ID(位置标题中的第6个字)。 后续的请求path包含事务标识为第4个字。 这部分工作正常。
不过,我想限制stick表使用的path以/db/data/transaction开头,因为Neo4j可能有其他terminal以及不同的行为。
我的第一个天真的做法是简单地将acl添加到后端:
acl tx_cypher_endpoint path_beg /db/data/transaction
然后用一个if tx_cypher_endpoint修改上面的stick match和stick store-response 。 开始时,这会导致以下消息:
parsing[haproxy.cfg:32]:acl'tx_cypher_endpoint'将永远不会匹配,因为它只涉及与'后端stick-store规则'不兼容的关键字
问题1:有人可以解释这个的原因吗?
作为一种解决方法,我已经将acl移到了前端部分,并有条件地存储了一个在后端使用的txn范围的variables:
frontend http-in bind *:8090 acl tx_cypher_endpoint path_beg /db/data/transaction http-request set-var(txn.tx_cypher_endpoint) bool(true) if tx_cypher_endpoint default_backend neo4j-all backend neo4j-all option httpchk GET /db/manage/server/ha/available acl tx_cypher_endpoint var(txn.tx_cypher_endpoint),bool stick-table type integer size 1k expire 10m stick match path,word(4,/) if tx_cypher_endpoint stick store-response hdr(Location),word(6,/) if tx_cypher_endpoint server s1 192.168.0.10:7474 maxconn 32 check server s2 192.168.0.11:7474 maxconn 32 check server s3 192.168.0.12:7474 maxconn 32 check
问题2:上述设置是最优雅的方法还是有更简单的设置可能?
问题3:我怎样才能看到在haproxy内部发生了什么,例如什么值被存储在variables或棍子表中? 是stats socket的路要走吗? 还是有更详细的控制台输出比使用-d ?