6.13. 远程缓存存储
远程缓存存储 RemoteStore 使用 Hot Rod 协议在 Data Grid 集群上存储数据。
如果您将远程缓存存储配置为共享,则无法预加载数据。在您的配置中为 shared="true" 换句话说,您必须设置 preload="false"。
共享远程缓存容器
每个远程缓存存储都会创建一个专用的远程缓存管理器。如果有多个远程存储连接到同一服务器,则这会浪费资源。使用 remote-cache-containers 配置创建共享远程缓存管理器,并使用 remote-store 定义中的名称来引用它们。
如果只有一个 remote-cache-container,则默认在所有远程缓存存储中使用它,但不明确指定一个。
分段
RemoteStore 支持分段,并可按网段发布密钥和证书,从而使批量操作更高效。但是,分段仅适用于 Data Grid Hot Rod 协议版本 2.3 或更高版本。
当您为 RemoteStore 启用分段时,会使用您在 Data Grid 服务器配置中定义的片段数量。
如果源缓存被分段并使用与 RemoteStore 不同的片段数,则为批量操作返回不正确的值。在这种情况下,您应该禁用 RemoteStore 的分段。
使用共享远程容器的远程缓存存储配置
XML
<infinispan>
<remote-cache-containers>
<remote-cache-container uri="hotrod://one,two:12111?max-active=10&exhausted-action=CREATE_NEW"/>
</remote-cache-containers>
<cache-container>
<distributed-cache>
<persistence>
<remote-store xmlns="urn:infinispan:config:store:remote:15.0"
cache="mycache"
raw-values="true"
/>
</persistence>
</distributed-cache>
</cache-container>
</infinispan>
JSON
{
"infinispan": {
"remote-cache-containers": [
{
"uri": "hotrod://one,two:12111?max-active=10&exhausted-action=CREATE_NEW"
}
],
"cache-container": {
"caches": {
"mycache": {
"distributed-cache": {
"remote-store": {
"cache": "mycache",
"raw-values": "true"
}
}
}
}
}
}
}
YAML
infinispan:
remoteCacheContainers:
- uri: "hotrod://one,two:12111?max-active=10&exhausted-action=CREATE_NEW"
cacheContainer:
caches:
mycache:
distributedCache:
remoteStore:
cache: "mycache"
rawValues: "true"
remoteServer:
- host: "one"
port: "12111"
- host: "two"
connectionPool:
maxActive: "10"
exhaustedAction: "CREATE_NEW"
ConfigurationBuilder
ConfigurationBuilder b = new ConfigurationBuilder();
b.persistence().addStore(RemoteStoreConfigurationBuilder.class)
.ignoreModifications(false)
.purgeOnStartup(false)
.remoteCacheName("mycache")
.rawValues(true)
.addServer()
.host("one").port(12111)
.addServer()
.host("two")
.connectionPool()
.maxActive(10)
.exhaustedAction(ExhaustedAction.CREATE_NEW)
.async().enable();
使用私有远程容器的远程缓存存储配置
XML
<distributed-cache>
<persistence>
<remote-store xmlns="urn:infinispan:config:store:remote:15.0"
cache="mycache"
raw-values="true">
<remote-server host="one"
port="12111" />
<remote-server host="two" />
<connection-pool max-active="10"
exhausted-action="CREATE_NEW" />
</remote-store>
</persistence>
</distributed-cache>
JSON
{
"distributed-cache": {
"remote-store": {
"cache": "mycache",
"raw-values": "true",
"remote-server": [
{
"host": "one",
"port": "12111"
},
{
"host": "two"
}
],
"connection-pool": {
"max-active": "10",
"exhausted-action": "CREATE_NEW"
}
}
}
}
YAML
distributedCache:
remoteStore:
cache: "mycache"
rawValues: "true"
remoteServer:
- host: "one"
port: "12111"
- host: "two"
connectionPool:
maxActive: "10"
exhaustedAction: "CREATE_NEW"
ConfigurationBuilder
ConfigurationBuilder b = new ConfigurationBuilder();
b.persistence().addStore(RemoteStoreConfigurationBuilder.class)
.ignoreModifications(false)
.purgeOnStartup(false)
.remoteCacheName("mycache")
.rawValues(true)
.addServer()
.host("one").port(12111)
.addServer()
.host("two")
.connectionPool()
.maxActive(10)
.exhaustedAction(ExhaustedAction.CREATE_NEW)
.async().enable();