为不同用户类型设置路由策略以将他们定向到不同的服务器
问题陈述
有一个因果集群设置,包含 3 个核心和 1 个只读副本。有两个用户组 - OLTP 用户和 OLAP 用户。OLTP 用户查询应该只去 2 个 Follower,而不去只读副本。OLAP 用户查询应该只去只读副本,而不去任何 Follower。原因是 OLTP 用户不应该受到 OLAP 用户的长时间运行的查询的影响。
如何在因果集群设置中实现这一点?
为了帮助实现这一点,需要多数据中心设置,该设置是在 Neo4j 3.2 版本中引入的。首先设置多数据中心许可证。有关更多信息,请参阅 Neo4j 操作手册 - https://neo4j.ac.cn/docs/operations-manual/current/clustering/causal-clustering/multi-data-center/.
按照 Neo4j 文档中的说明,使用 3 个核心和 1 个只读副本配置因果集群 (CC)。然后在 neo4j.conf
文件中进行相应的更改,以配置哪些应用程序/用户应该访问集群的哪些实例。以下配置创建了一个服务器组,名称为 oltp_app
,并且还启用了多数据中心许可证,这对于服务器组是必需的。
causal_clustering.server_groups=oltp_app
causal_clustering.multi_dc_license=true
causal_clustering.load_balancing.plugin=server_policies
causal_clustering.load_balancing.config.server_policies.oltp=groups(oltp_app); halt();
有关上述配置属性的更多文档,请参阅此处:https://neo4j.ac.cn/docs/operations-manual/current/clustering/causal-clustering/multi-data-center/load-balancing/#_prerequisite_configuration
现在,要仅在只读副本上为 OLAP 用户提供服务,请按以下方式配置只读副本。
causal_clustering.server_groups=olap_app
causal_clustering.multi_dc_license=true
causal_clustering.load_balancing.plugin=server_policies
causal_clustering.load_balancing.config.server_policies.olap=groups(olap_app); halt();
如何在应用程序中使用驱动程序?
OLTP 用户使用的应用程序将具有以下驱动程序配置。
客户端应用程序 URL
Driver driver = GraphDatabase.driver( "bolt+routing://127.0.0.1:7687?policy=oltp" , AuthTokens.basic( "neo4j", "password"), Config.build().withMaxTransactionRetryTime( 15, TimeUnit.SECONDS ).toConfig() );
我们在 URI 中指定 server_policy
名称 - bolt+routing://127.0.0.1:7687?policy=oltp
。当使用上述 URI 时,只读查询将仅路由到 2 个 Follower,因为核心服务器组被设置为 oltp_app
。
路由上下文在驱动程序部分的文档链接:https://neo4j.ac.cn/docs/developer-manual/current/drivers/client-applications/#_routing_drivers_with_routing_context
多数据中心功能仅在 Neo4j 3.2 及更高版本中可用。 |
此页面是否有帮助?