7.3. 在缓存存储之间迁移


Data Grid 提供了一个实用程序,用于将数据从一个缓存存储迁移到另一个缓存存储。

7.3.1. 缓存存储 Migrator

Data Grid 提供 StoreMigrator.java 工具,它为最新的数据网格缓存存储实施重新创建数据。

StoreMigrator 从以前的 Data Grid 版本获取缓存存储作为源,并使用缓存存储实施作为目标。

运行 StoreMigrator 时,它会使用您使用 EmbeddedCacheManager 接口定义的缓存存储类型创建目标缓存。StoreMigrator 然后从源存储加载条目到内存中,然后将其放入目标缓存中。

StoreMigrator 还允许您将数据从一种类型的缓存存储迁移到另一种缓存存储。例如,您可以从基于 JDBC 字符串的缓存存储迁移到单文件缓存存储。

重要

StoreMigrator 无法将数据从分段缓存存储迁移到:

  • 非分段缓存存储。
  • 分段缓存存储,它们具有不同的片段数。

7.3.2. 获取 Store Migrator

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>
    Copy to Clipboard Toggle word wrap

7.3.3. 配置 Store Migrator

migrator.properties 文件中为源和目标缓存存储设置属性。

流程

  1. 创建 migrator.properties 文件。
  2. migrator.properties 中配置源缓存存储。

    1. 使用 source 预先填充所有配置属性,如下例所示:

      source.type=SOFT_INDEX_FILE_STORE
      source.cache_name=myCache
      source.location=/path/to/source/sifs
      Copy to Clipboard Toggle word wrap
  3. migrator.properties 中配置目标缓存存储。

    1. 使用 target 预先填充所有配置属性,如下例所示:

      target.type=SINGLE_FILE_STORE
      target.cache_name=myCache
      target.location=/path/to/target/sfs.dat
      Copy to Clipboard Toggle word wrap

7.3.3.1. 存储 Migrator 属性

StoreMigrator 属性中配置源和目标缓存存储。

Expand
表 7.2. 缓存存储类型属性
属性描述必填/选填

type

指定源或目标的缓存存储类型类型。

.type=JDBC_STRING

.type=JDBC_BINARY

.type=JDBC_MIXED

.type=LEVELDB

.type=ROCKSDB

.type=SINGLE_FILE_STORE

.type=SOFT_INDEX_FILE_STORE

.type=JDBC_MIXED

必填

Expand
表 7.3. 常见属性
属性描述值示例必填/选填

cache_name

命名存储后端的缓存。

.cache_name=myCache

必填

segment_count

指定可以使用分段的目标缓存存储的片段数量。

片段数量必须与 Data Grid 配置中的 cluster.hash.numSegments 匹配。

换句话说,缓存存储的片段数量必须与对应缓存的片段数匹配。如果片段数量不相同,则数据网格无法从缓存存储中读取数据。

.segment_count=256

选填

Expand
表 7.4. JDBC 属性
属性描述必填/选填

dialect

指定底层数据库的 dialect。

必填

version

指定源缓存存储的 marshaller 版本。设置以下值之一:

* 8 用于 Data Grid 7.2.x

* 9 用于 Data Grid 7.3.x

* 10 Data Grid 8.x

仅用于源存储。

例如: source.version=9

marshaller.class

指定自定义 marshaller 类。

使用自定义 marshallers 时需要此项。

marshaller.externalizers

指定以逗号分隔的自定义 AdvancedExternalizer 实现列表,以便以以下格式进行加载: [id]:<Externalizer class>

选填

connection_pool.connection_url

指定 JDBC 连接 URL。

必填

connection_pool.driver_class

指定 JDBC 驱动程序的类。

必填

connection_pool.username

指定数据库用户名。

必填

connection_pool.password

指定数据库用户名的密码。

必填

db.major_version

设置数据库主版本。

选填

db.minor_version

设置数据库次版本。

选填

db.disable_upsert

禁用数据库 upsert。

选填

db.disable_indexing

指定是否创建表索引。

选填

table.string.table_name_prefix

指定表名称的额外前缀。

选填

table.string.<id|data|timestamp>.name

指定列名称。

必填

table.string.<id|data|timestamp>.type

指定列类型。

必填

key_to_string_mapper

指定 TwoWayKey2StringMapper 类。

选填

注意

要从旧的 Data Grid 版本中迁移 Binary 缓存存储,请在以下属性中将 table.string view 改为 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
Copy to Clipboard Toggle word wrap
Expand
表 7.5. RocksDB Properties
属性描述必填/选填

位置

设置数据库目录。

必填

compression

指定要使用的压缩类型。

选填

# 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
Copy to Clipboard Toggle word wrap
Expand
表 7.6. SingleFileStore 属性
属性描述必填/选填

位置

设置包含缓存存储 .dat 文件的目录。

必填

# 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
Copy to Clipboard Toggle word wrap
Expand
表 7.7. SoftIndexFileStore Properties
属性描述

必填/选填

位置

设置数据库目录。

必填

index_location

设置数据库索引目录。

# 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
Copy to Clipboard Toggle word wrap

7.3.4. 迁移缓存存储

运行 StoreMigrator 将数据从一个缓存存储迁移到另一个缓存存储。

先决条件

  • 获取 infinispan-tools.jar.
  • 创建 migrator.properties 文件,以配置源和目标缓存存储。

流程

  • 如果从源构建 infinispan-tools.jar,请执行以下操作:

    1. 将源和目标数据库(如 JDBC 驱动程序)的 infinispan-tools.jar 和依赖项添加到您的类路径。
    2. migrator.properties 文件指定为 StoreMigrator 的参数。
  • 如果您从 Maven 存储库拉取 infinispan-tools.jar,请运行以下命令:

    mvn exec:java

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat