Tomcat 6 集群配置是否有 useDirtyFlag 选项?
在 Tomcat 5.0.x 中,您可以设置 useDirtyFlag="false" 来在每次请求后强制复制会话,而不是检查 set/removeAttribute 调用。
<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
managerClassName="org.apache.catalina.cluster.session.SimpleTcpReplicationManager"
expireSessionsOnShutdown="false"
**useDirtyFlag="false"**
doClusterLog="true"
clusterLogName="clusterLog"> ...
server.xml 中的注释指出这可用于执行以下工作:
<%
HashMap map = (HashMap)session.getAttribute("map");
map.put("key","value");
%>
即更改已放入会话中的对象的状态,并且您可以确定该对象仍然是复制到集群中的其他节点。
根据 Tomcat 6 文档,您只有两个“管理器”选项 - DeltaManager 和 DeltaManager。 BackupManager ...这两个似乎都不允许此选项或类似的选项。在我测试默认设置时:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
默认情况下获得 DeltaManager 的地方,它的行为肯定是 useDirtyFlag="true" (正如我所期望的)。
所以我的问题是 - Tomcat 6 中有等效的吗?
查看源代码,我可以看到一个管理器实现“org.apache.catalina.ha.session.SimpleTcpReplicationManager”,它确实具有 useDirtyFlag,但 javadoc 在这种状态下注释它是“Tomcat Session Replication for Tomcat 4.0”...我不知道不知道这是否可以使用 - 我猜不行,因为主集群配置文档中没有提到它。
In Tomcat 5.0.x you had the ability to set useDirtyFlag="false" to force replication of the session after every request rather than checking for set/removeAttribute calls.
<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
managerClassName="org.apache.catalina.cluster.session.SimpleTcpReplicationManager"
expireSessionsOnShutdown="false"
**useDirtyFlag="false"**
doClusterLog="true"
clusterLogName="clusterLog"> ...
The comments in the server.xml stated this may be used to make the following work:
<%
HashMap map = (HashMap)session.getAttribute("map");
map.put("key","value");
%>
i.e. change the state of an object that has already been put in the session and you can be sure that this object still be replicated to the other nodes in the cluster.
According to the Tomcat 6 documentation you only have two "Manager" options - DeltaManager & BackupManager ... neither of these seem to allow this option or anything like it. In my testing the default setup:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
where you get the DeltaManager by default, it's definitely behaving as useDirtyFlag="true" (as I'd expect).
So my question is - is there an equivalent in Tomcat 6?
Looking at the source I can see a manager implementation "org.apache.catalina.ha.session.SimpleTcpReplicationManager" which does have the useDirtyFlag but the javadoc comments in this state it's "Tomcat Session Replication for Tomcat 4.0" ... I don't know if this is ok to use - I'm guessing not as it's not mentioned in the main cluster configuration documentation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在 tomcat-users 邮件列表上发布了本质上相同的问题,对此问题的响应以及 tomcat bugzilla ([43866]) 中的一些信息使我得出以下结论:
第 1 步:编写
ForceReplicationValve
(扩展ValveBase
实现ClusterValve
)我不会包含整个类,但会包含关键逻辑部分(删除日志记录和实例检查):
第 2 步:更改集群配置(在
conf/server.xml
中)将会话复制到所有集群现在,节点将在每个请求之后发生。
另外:请注意
channelSendOptions
设置。这取代了 Tomcat 5.0.x 中的replicationMode=asynchronous/synchronous/pooled
。有关可能的 int 值,请参阅集群文档。附录:按要求提供完整阀门源
I posted essentially the same question on the tomcat-users mailing list and the responses to this along with some information in the tomcat bugzilla ([43866]) led me to the following conclusions:
Step 1: Write the
ForceReplicationValve
(extendsValveBase
implementsClusterValve
)I won't include the whole class but the key bit of logic (taking out the logging and instanceof checking):
Step 2: Alter the cluster config (in
conf/server.xml
)Replication of the session to all cluster nodes will now happen after every request.
Aside: Note the
channelSendOptions
setting. This replaces thereplicationMode=asynchronous/synchronous/pooled
from Tomcat 5.0.x. See the cluster documentation for the possible int values.Appendix: Full Valve source as requested
非常感谢 kevinjansz 提供 ForceReplicationValve 的源代码。
我针对Tomcat7进行了调整,如果有人需要的话,这里是:
Many thanks to kevinjansz for providing the source for ForceReplicationValve.
I adjusted it for Tomcat7, here it is if anyone needs it: