我应该如何在 Apache Ignite (GridGain) 中执行缓存配置迁移?

How should I perform cache configuration migration in Apache Ignite (GridGain)?

Apache Ignite 要求配置在所有节点中都相同。假设有几个服务器节点,我还有使用 Ignite client(不是 Thin client)做一些工作的微服务。

根据文档,应按以下方式指定缓存:

CacheConfiguration<String, MyCache> cacheConfiguration = 
new CacheConfiguration<String, MyCache>()
                .setName("MyCacheName")
                .setSqlSchema("MySchemaName")
                .setIndexedTypes(String.class, MyCache.class)
                .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
IgniteCache<String, MyCache> cache = igignite.getOrCreateCache(cacheConfiguration);

下面是 MyCache 的样子:

public class MyCache implements Serializable {

    @QuerySqlField(index = true, name = "id")
    private String id;

    @QuerySqlField(name = "user_name")
    private String userName;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName= userName;
    }

}

但是如果我需要修改缓存结构或缓存配置怎么办?

例如添加 backup configuration

CacheConfiguration<String, MyCache> cacheConfiguration = 
new CacheConfiguration<String, MyCache>()
                .setName("MyCacheName")
                .setSqlSchema("MySchemaName")
                .setIndexedTypes(String.class, MyCache.class)
                .setBackups(1)
                .setReadFromBackup(true)
                .setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);

并添加额外字段(例如 email 字段):

public class MyCache implements Serializable {

    @QuerySqlField(index = true, name = "id")
    private String id;

    @QuerySqlField(name = "user_name")
    private String userName;

    @QuerySqlField(name = "user_email")
    private String userEmail;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName= userName;
    }

    public String getUserEmail() {
        return userEmail;
    }

    public void setUserEmail(String userEmail) {
        this.userEmail = userEmail;
    }

}

如何在不停止服务器节点的情况下应用更新? (系统正在生产中)

如何进行迁移?

如果不重新启动服务器节点,则无法调整静态缓存配置。作为解决方法,您可以使用新备份因子定义新缓存,复制数据并销毁旧缓存。

或者,您可以调整底层 table 并动态添加一个带有 ALTER TABLE 的新列,例如:

ALTER TABLE "MyCacheName".MYCACHE ADD UserEmail VARCHAR