6.7. 全球持久性位置
数据网格保留全局状态,以便它可以在重启后恢复集群拓扑和缓存的数据。
远程缓存
				Data Grid Server 将集群状态保存到 $RHDG_HOME/server/data 目录。
			
					您不应该删除或修改 server/data 目录或其内容。在重启服务器实例时,Data Grid 将从这个目录中恢复集群状态。
				
					更改默认配置或直接修改 server/data 目录可能会导致意外行为,并导致数据丢失。
				
嵌入缓存
				Data Grid 默认为 user.dir 系统属性,作为全局持久位置。在大多数情况下,这是应用程序启动的目录。
			
对于集群的内嵌缓存,如复制或分布式,您应该始终启用并配置全局持久位置,以恢复集群拓扑。
您不能为位于全局持久位置以外的基于文件的缓存存储配置绝对路径。如果这样做,Data Grid 将以下例外写入日志:
ISPN000558: "The store location 'foo' is not a child of the global persistent location 'bar'"
ISPN000558: "The store location 'foo' is not a child of the global persistent location 'bar'"6.7.1. 配置全局持久位置
启用并配置数据网格为集群嵌入式缓存存储全局状态的位置。
数据网格服务器支持全局持久性并配置默认位置。您不应该禁用全局持久性,或更改远程缓存的默认配置。
先决条件
- 将 Data Grid 添加到您的项目。
流程
- 使用以下方法之一启用全局状态: - 
									将 global-state元素添加到您的 Data Grid 配置中。
- 
									在 GlobalConfigurationBuilderAPI 中调用globalState ().enable ()方法。
 
- 
									将 
- 定义全局持久位置是否与每个节点唯一或在集群间共享。 - Expand - 位置类型 - Configuration - 每个节点唯一 - persistent-location元素或- persistentLocation ()方法- 在集群间共享 - shared-persistent-location元素或- sharedPersistentLocation (String)方法
- 设置数据网格存储集群状态的路径。 - 例如,基于文件的缓存存储路径是主机文件系统中的一个目录。 - 值可以是: - 绝对位置,并包含根用户。
- 相对于根位置.
 
- 如果为路径指定相对值,还必须指定一个解析为根位置的系统属性。 - 例如,在 Linux 主机系统上,您要将 - global/state设置为路径。您还设置解析到- /opt/data根位置的- my.data属性。在这种情况下,Data Grid 使用- /opt/data/global/state作为全局持久位置。
全局持久位置配置
XML
JSON
YAML
cacheContainer:
  globalState:
      persistentLocation:
        path: "global/state"
        relativeTo : "my.data"
cacheContainer:
  globalState:
      persistentLocation:
        path: "global/state"
        relativeTo : "my.data"GlobalConfigurationBuilder
new GlobalConfigurationBuilder().globalState()
                                .enable()
                                .persistentLocation("global/state", "my.data");
new GlobalConfigurationBuilder().globalState()
                                .enable()
                                .persistentLocation("global/state", "my.data");