简体   繁体   English

如何在Liferay 7.1上启用缓存复制。 DXP 1.0 GA?

[英]How to enable cache replication on Liferay 7.1. DXP 1.0 GA?

I have the next environment: 我有下一个环境:

  1. Liferay 7.1 DXP with a clustered license (bundle with wildfly 16.0) 具有群集许可证的Liferay 7.1 DXP(与wildfly 16.0捆绑在一起)
  2. This bundles running in the same machine (2 nodes) on the localhost but different ports 该捆绑包在本地主机的同一台计算机(2个节点)上运行,但端口不同
  3. Each node have the same database (postgresql) 每个节点具有相同的数据库(PostgreSQL)
  4. Separate running elasticsearch on the machine 在机器上单独运行elasticsearch
  5. Shared folder for documents and media 文件和媒体的共享文件夹
  6. In the portal-setup-wizard.properties i added "cluster.link.enabled=true" and "ehcache.replicator.properties.com.liferay.portal.kernel.webserver.WebServerServletToken=replicatePuts=true" in order to replicate cache 7.Deployed sample portlet in order to test cache replication 我在portal-setup-wizard.properties中添加了“ cluster.link.enabled = true”和“ ehcache.replicator.properties.com.liferay.portal.kernel.webserver.WebServerServletToken = replicatePuts = true”,以便复制缓存7部署示例Portlet以测试缓存复制

I tried the next steps to test cache replication: 我尝试了以下步骤来测试缓存复制:

  1. Run the first node. 运行第一个节点。
  2. After that run the second node. 之后,运行第二个节点。
  3. Go to localhost for the fist node 转到localhost作为第一个节点
  4. Go to localhost for the second node 转到localhost作为第二个节点
  5. See next message in the logs: 请参阅日志中的下一条消息:

[Incoming-2,liferay-channel-control,WS-5459-64327][JGroupsReceiver:91] Accepted view MergeView::[WS-5459-18884|3] (2) [WS-5459-18884, WS-5459-64327], 2 subgroups: [WS-5459-64327|1] (2) [WS-5459-64327, WS-5459-18884], [WS-5459-18884|2] (1) [WS-5459-18884] [Incoming-2,liferay-channel-control,WS-5459-64327] [JGroupsReceiver:91]接受的视图MergeView :: [WS-5459-18884 | 3](2)[WS-5459-18884,WS-5459- 64327],两个子组:[WS-5459-64327 | 1](2)[WS-5459-64327,WS-5459-18884],[WS-5459-18884 | 2](1)[WS-5459-18884 ]

  1. In the test portlet on the first node, through debug mode, I added cache through MultiVMPoolUtil: 在第一个节点上的测试portlet中,通过调试模式,我通过MultiVMPoolUtil添加了缓存:

MultiVMPoolUtil.getPortalCache("com.liferay.portal.kernel.webserver.WebServerServletToken").put("1","1") MultiVMPoolUtil.getPortalCache( “com.liferay.portal.kernel.webserver.WebServerServletToken”)。把( “1”, “1”)

  1. And in the second node I tried to get value from this cache: 在第二个节点中,我尝试从此缓存中获取价值:

MultiVMPoolUtil.getPortalCache("com.liferay.portal.kernel.webserver.WebServerServletToken").getKeys() MultiVMPoolUtil.getPortalCache( “com.liferay.portal.kernel.webserver.WebServerServletToken”)。getKeys()

But there is no key "1" on this cache on the second node, but if I tried to remove using the same API, .remove("1"), on the first node this value will be removed. 但是在第二个节点上的此缓存上没有键“ 1”,但是如果我尝试使用相同的API .remove(“ 1”)进行删除,则在第一个节点上将删除该值。

The question is how to configure cache replication for put operation? 问题是如何配置缓存复制以进行放置操作?

ClusterLink doesn't work like this, it's rather "invalidating" caches, not "replicating" them: ClusterLink不能像这样工作,而是“使”缓存无效,而不是“复制”它们:

If you modify object "1" on node1, node2 will get a notification that "1" was changed and - if it has this object cached - will simply drop it from its own cache. 如果您在节点1上修改对象“ 1”,则节点2将收到有关“ 1”已更改的通知,并且-如果该对象已被缓存-则将其从其自身的缓存中删除。 Only in the event of "1" being required subsequently will the cache-miss be detected and the object retrieved from the database (or other persistent storage). 仅在随后需要“ 1”的情况下,才会检测到缓存丢失并从数据库(或其他持久性存储)中检索对象。

In case nobody on node2 ever asks for the object, nothing is being retrieved on node2. 如果node2上没有人要该对象,则node2上不会检索任何内容。

Further, if the cache on node1 overflows (cache is not unlimited, in fact, it might be configured to size 0) you can't even assume that you'll be able to retrieve this object from the cache on node1 forever. 此外,如果节点1上的缓存溢出(缓存不是无限的,实际上,它的大小可能配置为0),您甚至无法假设您将能够永远从节点1的缓存中检索此对象。

So, your observation is correct: Changes or removals in one node will remove the object with the given key from all caches. 因此,您的观察是正确的:在一个节点中进行更改或删除会将具有给定键的对象从所有缓存中删除。 That's how it's implemented, and it's quite useful: No need to cache something that you might never be accessing on a given machine. 这就是它的实现方式,它非常有用:无需缓存您可能永远无法在给定计算机上访问的内容。

I believe I've heard of actual cache replication a long time ago, eg it might be configurable. 我相信很久以前就听说过实际的缓存复制,例如,它可能是可配置的。 But I've never attempted it, as it's just not required, and invalidation doesn't impose a huge burden. 但是我从未尝试过,因为它不是必需的,并且无效也不会带来很大的负担。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM