Spring Data GemFire DiskStore [英] Spring Data GemFire DiskStore

查看:52
本文介绍了Spring Data GemFire DiskStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 Spring Data GemFire 将 Region 中的数据保存到磁盘.

使用以下配置(LocatorServer 使用 Gfsh 启动):

@EnablePdx@ClientCacheApplication@EnableDiskStore(name = "disk_store")@EnableClusterConfiguration(useHttp = true)@EnableEntityDefinedRegions(basePackages = "xxx.entity")@EnableGemfireRepositories(basePackages = "xxx.repository")公共类 GeodeClientConfiguration {}

配置如下:

spring.data.gemfire.disk.store.name=disk_storespring.data.gemfire.disk.store.directory.location=C:\\apache-geode-1.9.0\\diskstore

上面的配置创建了一个 DiskStore(一旦运行存储数据的代码).问题是一旦服务器停止,磁盘存储就会被删除.

查看了 John Blum 的文档和示例无济于事.

还尝试使用 Gfsh 创建 DiskStore 但最终得到多个 DiskStores 并且在 中创建的磁盘存储中没有数据Gfsh.

知道我可能遗漏了什么吗?

谢谢

解决方案

即使有了上面的 Java 配置,你的安排对我来说仍然有点不清楚/模棱两可.不过,让我们从我们所知道的开始.

首先,从上面的 Java 配置可以清楚地看出,您正在创建一个 ClientCacheSpring 应用程序来连接到独立的 GemFire 并从其发送/接收数据集群.

您还声明您正在使用 Gfsh 启动定位器服务器.到目前为止一切正常.

然而,你有...

1) 使用 @EnableEntityDefinedRegions(这很好)注释您的客户端应用程序类,而无需使用 clientRegionShortcut 属性指定备用数据策略.默认情况下,clientRegionShortcut 设置为 PROXY(参见 此处),其中 意味着您的客户端应用程序不保持本地状态.

2) 然后,您使用 @EnableDiskStore 注释在客户端上定义一个 DiskStore(即disk_store"),这可能不是您想要的目前没有本地状态保存在客户端区域.

<块引用>

注意:@EnableClusterConfiguration 不会将 DiskStores 的配置元数据从客户端推送到服务器.目前,它只将 RegionIndex 配置元数据推送到服务器,如客户端定义的那样.

否则,Spring 的其余部分(用于 GemFire)配置(使用注解)看起来还不错.

<块引用>

注意:还要记住,@EnableClusterConfiguration 注释很小心,不要踩踏服务器端的现有区域.如果同名 Regions 已经存在,那么服务器在声明 @EnableClusterConfiguration 注释时将不会应用客户端发送的定义(即注释不会nuke-and-pave").这是设计使然,主要是为了防止数据丢失.

注意:我还建议您在 @EnableEntityDefinedRegions@EnableGemfireRepositories 中使用 basePackages 属性的类型安全替代方案注释,basePackageClasses 属性.它可以引用 1 个或多个类,但该类类型仅用于确定从哪个包开始扫描.例如,您可以将 @EnableEntityDefinedRegionsbasePackageClasses 设置为 example.app.customers.model.Customer.classexample.app.products.model.Product.class@EnableEntityDefinedRegions(basePackageClasses = { Customer.class, Product.class }) 和 SDG 将使用这些类的包声明开始扫描实体类(包括子包).您不需要列出包中的所有(或多个)类;您要扫描的每个(顶级)包 1 个就足够了.最好限制扫描.

因此,就您而言,您可能希望执行以下操作:

在客户端:

@EnablePdx@ClientCacheApplication@EnableClusterConfiguration(useHttp = true)@EnableEntityDefinedRegions(basePackageClasses = EntityType.class)@EnableGemfireRepositories(basePackageClasses = RepositoryType.class)公共类 GeodeClientConfiguration {}

然后,在服务器上,要持久化"数据,您需要创建持久化"区域.您可以通过以下两种方式中的一种来实现:

1) 首先,您可以配置客户端,使用 @EnableClusterConfiguration 批注,在创建客户端定义的匹配 Region(按名称)时告诉服务器创建一个持久"区域.默认情况下,客户端 @EnableClusterConfiguration 注释告诉服务器创建一个非持久性 PARTITION 区域(参见 此处).因此,您可以将客户端配置中的 @EnableClusterConfiguration 注释更改为:

@ClientCacheApplication@EnableClusterConfiguration(useHttp = true, serverRegionShortcut = RegionShortcut.PARTITION_PERSISTENT)...类 GeodeClientConfiguration { ... }

您可以使用任何非 LOCAL、PERSISTENT"、RegionShortcut、Region(数据策略)类型(请参阅 此处)...主要是 [PARTITION_PERSISTENT* 和 REPLICATE_PERSISTENT*].

然后,当客户端将 Region 配置元数据推送到服务器时,服务器将创建一个具有相同名称和指定(数据策略)类型(由 @EnableClusterConfiguration 定义)的 Region注解的 serverRegionShortcut 属性).

再次记住,如果该区域已经存在,则不会重新创建该区域.如果您想让客户端在(每个应用程序)重新启动时创建区域,您需要使用 Gfsh 销毁区域.

2) 或者,您可以使用 Gfsh 来创建区域,使用:

gfsh>创建区域 --name=示例 --type=PARTITION_PERSISTENT

最后,当涉及到 DiskStore 时,由于您没有本地状态区域,即使您这样做了,您也可能希望数据持久化"服务器端,然后如果您这样做什么都没有,只需使用上述 2 种方法中的一种声明具有持久"数据策略的服务器端区域,然后 GemFire 默认写入默认"DiskStore.>

如果要将特定"DiskStore(按名称)与区域(例如Example")相关联,则必须首先创建 DiskStore使用 Gfsh:

gfsh>创建磁盘存储 --name=disk_store ...

请参阅此处.

然后,使用 Gfsh 创建区域:

gfsh>创建区域 --name=Example --type=PARTITION_PERSISTENT --disk-store=disk_store ...

请参阅此处.

如果您将驱逐配置为OVERFLOW_TO_DISK"(请参阅​​这里).

从 #2(创建区域)开始(使用 DiskStore 创建),都是服务器端.

无论如何,我希望所有这些都有意义并有所帮助.

如果您有其他问题或问题,请随时在评论中跟进.

谢谢.

I need to persist the data in a Region to disk using Spring Data GemFire.

Using the config below (Locator and Server are started using Gfsh):

@EnablePdx
@ClientCacheApplication
@EnableDiskStore(name = "disk_store")
@EnableClusterConfiguration(useHttp = true)
@EnableEntityDefinedRegions(basePackages = "xxx.entity")
@EnableGemfireRepositories(basePackages = "xxx.repository")
public class GeodeClientConfiguration {

}

The config is below:

spring.data.gemfire.disk.store.name=disk_store
spring.data.gemfire.disk.store.directory.location=C:\\apache-geode-1.9.0\\diskstore

The above config creates a DiskStore (once the code to store the data is run). The issue is that once the server is stopped, the disk store gets deleted.

Looked at the documentation and examples by John Blum to no avail.

Also tried to create the DiskStore using Gfsh but end up with multiple DiskStores and no data in the disk store created in Gfsh.

Any idea what I might be missing?

Thanks

解决方案

Even with your Java configuration above, your arrangement is still a bit unclear/ambiguous to me. However, let's start with what we know.

First, it is clear from your Java configuration above that you are creating a ClientCache, Spring application to connect to and send/receive data to/from a standalone GemFire cluster.

You also state that you are starting the Locator and Server(s) using Gfsh. All fine so far.

However, you have...

1) Annotated your client application class with @EnableEntityDefinedRegions (which is fine) without specifying an alternate data policy using the clientRegionShortcut attribute. By default, the clientRegionShortcut is set to PROXY (see here), which means your client application keeps NO local state.

2) Then, you define a DiskStore (i.e. "disk_store") on the client with the @EnableDiskStore annotation, which is probably not what you want given there is currently NO local state kept on the client Regions.

NOTE: @EnableClusterConfiguration does not push configuration meta-data for DiskStores up to the server from the client. Currently, it only pushes Region and Index configuration meta-data up to the servers, as defined on the client.

Otherwise, the rest of the Spring (for GemFire) configuration (using Annotations) seems just fine.

NOTE: Also keep in mind that the @EnableClusterConfiguration annotation is careful not to stomp on existing Regions on the server-side. If the same Regions by name already exist, then the server will not apply the definition sent by the client when declaring the @EnableClusterConfiguration annotation (i.e. the annotation will not "nuke-and-pave"). That is by design, primarily to protect against data loss.

NOTE: I also recommend that you use the type-safe alternative to the basePackages attribute, in both the @EnableEntityDefinedRegions and @EnableGemfireRepositories annotations, the basePackageClasses attribute. It can refer to 1 or more Classes, but that class type is only used to determine the package from which to begin the scan. For example, you can set the @EnableEntityDefinedRegions, basePackageClasses to example.app.customers.model.Customer.class and example.app.products.model.Product.class as in @EnableEntityDefinedRegions(basePackageClasses = { Customer.class, Product.class }) and SDG will use the package declaration of these classes to begin the Scan for Entity classes (sub-packages included). You do not need to list all (or multiple) classes from the package; 1 per (top-level) package from where you want to scan will suffice. It is good to limit the scan.

So, in your case, you probably want to do the following:

On the client:

@EnablePdx
@ClientCacheApplication
@EnableClusterConfiguration(useHttp = true)
@EnableEntityDefinedRegions(basePackageClasses = EntityType.class)
@EnableGemfireRepositories(basePackageClasses = RepositoryType.class)
public class GeodeClientConfiguration {

}

And then, on the server, to "persist" data, you want to create "PERSISTENT" Regions. You can accomplish this 1 of 2 ways:

1) First, you can configure the client, using the @EnableClusterConfiguration annotation, to tell the server when creating the matching Region (by name), as defined by the client, to create a "PERSISTENT" Region. By default, the client-side @EnableClusterConfiguration annotation tells the server to create a non-persistent PARTITION Region (see here). So you would change the @EnableClusterConfiguration annotation in your client configuration to:

@ClientCacheApplication
@EnableClusterConfiguration(useHttp = true, serverRegionShortcut = RegionShortcut.PARTITION_PERSISTENT)
...
class GeodeClientConfiguration { ... }

You may use any of the non-LOCAL, "PERSISTENT", RegionShortcut, Region (data policy) types (see here)... primarily [PARTITION_PERSISTENT* and REPLICATE_PERSISTENT*].

Then, when the client pushes the Region configuration meta-data to the server, the server will create a Region with the same name and designated (data policy) type (as defined by the @EnableClusterConfiguration annotation's serverRegionShortcut attribute).

Again, keep in mind, that if the Region already exists, it will not re-create the Region. If you want to have the client create the Region on (each application) restart, you need to destroy the Region using Gfsh.

2) Alternatively, you can use Gfsh to create the Region, using:

gfsh> create region --name=Example --type=PARTITION_PERSISTENT

Finally, when it comes to the DiskStore, since you have NO local state Region, and even if you did, you probably want the data "persisted" server-side instead, then if you do nothing and just declare the server-side Region(s) with a "PERSISTENT" data policy using 1 of the 2 methods above, then GemFire, by default, writes to the "DEFAULT" DiskStore.

If you want to associate a "specific" DiskStore (by name) with the Region (e.g. "Example"), then you must, first, create the DiskStore using Gfsh:

gfsh> create disk-store --name=disk_store ...

See here.

And then, create the Region with Gfsh:

gfsh> create region --name=Example --type=PARTITION_PERSISTENT --disk-store=disk_store ...

See here.

The DiskStore is used both to "persist" data as well as overflow data to disk if you have Eviction configured to "OVERFLOW_TO_DISK" (see here).

From #2 (creating a Region) onward (with the DiskStore creation), is all server-side.

Anyway, I hope all of this makes sense and helps.

If you have additional questions or problems, feel free to follow up in the comments.

Thanks.

这篇关于Spring Data GemFire DiskStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆