6.17. 在缓存存储间迁移数据
数据网格提供了一个将数据从一个缓存存储迁移到另一个缓存存储的工具。
6.17.1. 缓存存储器 复制链接链接已复制到粘贴板!
Data Grid 提供 StoreMigrator.java 实用程序,用于为最新数据网格缓存存储实施重新创建数据。
StoreMigrator 将之前版本的 Data Grid 的缓存存储用作源,并使用缓存存储实施作为目标。
运行 StoreMigrator 时,它会使用您使用 EmbeddedCacheManager 接口定义的缓存类型创建目标缓存。然后,StoreMigrator 将条目从源代码存储加载到内存中,然后将它们放入目标缓存中。
StoreMigrator 还允许您将数据从一种缓存存储迁移到另一种。例如,您可以将基于 JDBC 字符串的缓存存储迁移到 RocksDB 缓存存储。
StoreMigrator 无法将数据从分段的缓存存储迁移到:
- 非分段缓存存储。
- 有不同数量的片段的分段缓存存储。
6.17.2. 获取缓存存储器 复制链接链接已复制到粘贴板!
StoreMigrator 作为 Data Grid 工具库的一部分提供,infinispan-tools 包含在 Maven 存储库中。
流程
为
StoreMigrator配置pom.xml,如下所示:<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.infinispan.example</groupId> <artifactId>jdbc-migrator-example</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.infinispan</groupId> <artifactId>infinispan-tools</artifactId> </dependency> <!-- Additional dependencies --> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>org.infinispan.tools.store.migrator.StoreMigrator</mainClass> <arguments> <argument>path/to/migrator.properties</argument> </arguments> </configuration> </plugin> </plugins> </build> </project>
6.17.3. 配置缓存存储器 复制链接链接已复制到粘贴板!
在 migrator.properties 文件中设置源和目标缓存存储的属性。
流程
-
创建
migrator.properties文件。 在
migrator.properties中配置源缓存存储。使用
源添加所有配置属性。如下例所示:source.type=SOFT_INDEX_FILE_STORE source.cache_name=myCache source.location=/path/to/source/sifs source.version=<version>
在
migrator.properties中配置目标缓存存储。使用
目标添加所有配置属性。如下例所示:target.type=SINGLE_FILE_STORE target.cache_name=myCache target.location=/path/to/target/sfs.dat
6.17.3.1. 缓存存储器的配置属性 复制链接链接已复制到粘贴板!
配置源和目标缓存存储在 StoreMigrator 属性中。
| 属性 | 描述 | 必填/选填 |
|---|---|---|
|
| 指定源或目标的缓存存储类型。
| 必需 |
| 属性 | 描述 | 值示例 | 必填/选填 |
|---|---|---|---|
|
| 将存储后端的缓存进行命名。 |
| 必需 |
|
| 指定可以使用分段的目标缓存存储位置的片段数量。
片段的数量必须与 Data Grid 配置中的 换句话说,缓存存储的片段数量必须与对应缓存的片段数量匹配。如果片段的数量不同,Data Grid 无法从缓存存储中读取数据。 |
| 选填 |
| 属性 | 描述 | 必填/选填 |
|---|---|---|
|
| 指定底层数据库的数量。 | 必需 |
|
|
指定源缓存存储位置的 marshaller 版本。
*
*
*
*
*
* | 仅限源代码存储需要。 |
|
| 指定自定义 marshaller 类。 | 如果使用自定义 marshallers,则需要此项。 |
|
|
指定以这个格式加载的自定义 | 选填 |
|
| 指定 JDBC 连接 URL。 | 必需 |
|
| 指定 JDBC 驱动程序的类。 | 必需 |
|
| 指定数据库用户名。 | 必需 |
|
| 指定数据库用户名的密码。 | 必需 |
|
| 设置数据库主版本。 | 选填 |
|
| 设置数据库次要版本。 | 选填 |
|
| 禁用数据库。 | 选填 |
|
| 指定是否创建了表索引。 | 选填 |
|
| 指定表名称的额外前缀。 | 选填 |
|
| 指定列名称。 | 必需 |
|
| 指定列类型。 | 必需 |
|
|
指定 | 选填 |
要从旧的 Data Grid 版本中的 Binary 缓存存储,将 table.string.* 改为 table.binary.\*,在以下属性中:
-
source.table.binary.table_name_prefix -
source.table.binary.<id\|data\|timestamp>.name -
source.table.binary.<id\|data\|timestamp>.type
# Example configuration for migrating to a JDBC String-Based cache store
target.type=STRING
target.cache_name=myCache
target.dialect=POSTGRES
target.marshaller.class=org.example.CustomMarshaller
target.marshaller.externalizers=25:Externalizer1,org.example.Externalizer2
target.connection_pool.connection_url=jdbc:postgresql:postgres
target.connection_pool.driver_class=org.postrgesql.Driver
target.connection_pool.username=postgres
target.connection_pool.password=redhat
target.db.major_version=9
target.db.minor_version=5
target.db.disable_upsert=false
target.db.disable_indexing=false
target.table.string.table_name_prefix=tablePrefix
target.table.string.id.name=id_column
target.table.string.data.name=datum_column
target.table.string.timestamp.name=timestamp_column
target.table.string.id.type=VARCHAR
target.table.string.data.type=bytea
target.table.string.timestamp.type=BIGINT
target.key_to_string_mapper=org.infinispan.persistence.keymappers. DefaultTwoWayKey2StringMapper
| 属性 | 描述 | 必填/选填 |
|---|---|---|
|
| 设置数据库目录。 | 必需 |
|
| 指定要使用的压缩类型。 | 选填 |
# Example configuration for migrating from a RocksDB cache store.
source.type=ROCKSDB
source.cache_name=myCache
source.location=/path/to/rocksdb/database
source.compression=SNAPPY
| 属性 | 描述 | 必填/选填 |
|---|---|---|
|
|
设置包含缓存存储 | 必需 |
# Example configuration for migrating to a Single File cache store.
target.type=SINGLE_FILE_STORE
target.cache_name=myCache
target.location=/path/to/sfs.dat
| 属性 | 描述 | 值 |
|---|---|---|
| 必填/选填 |
| 设置数据库目录。 |
| 必需 |
| 设置数据库索引目录。 |
# Example configuration for migrating to a Soft-Index File cache store.
target.type=SOFT_INDEX_FILE_STORE
target.cache_name=myCache
target.location=path/to/sifs/database
target.location=path/to/sifs/index
6.17.4. 迁移 Data Grid 缓存存储 复制链接链接已复制到粘贴板!
运行 StoreMigrator 将数据从一个缓存存储迁移到另一个缓存。
先决条件
-
get
infinispan-tools.jar. -
创建一个
migrator.properties文件来配置源和目标缓存存储。
流程
如果从源构建
infinispan-tools.jar,请执行以下操作:-
将源和目标数据库(如 JDBC 驱动程序)的
infinispan-tools.jar和依赖项添加到您的类路径。 -
指定
migrator.properties文件,作为StoreMigrator的参数。
-
将源和目标数据库(如 JDBC 驱动程序)的
如果从 Maven 存储库拉取
infinispan-tools.jar,请运行以下命令:mvn exec:java