Search code examples
javaignitegridgain

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


Apache Ignite requires configuration to be the same in all nodes. Let say there are several server nodes and also I have microservices that use Ignite client (not Thin client) to do some work.

According to the documentation, one should specify caches in the following way:

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);

And here is how MyCache could look like:

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;
    }

}

But what if I need to modify cache structure or cache configuration?

E.g. add 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);

And add extra fields (e.g. email field):

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;
    }

}

How can I apply updates without stopping server nodes? (the system is in production)

How to perform migration?


Solution

  • It's not possible to adjust static cache configuration without restarting server nodes. As a workaround, you might define a new cache with the new backup factor, copy the data and destroy the old cache.

    Alternatively, you can adjust an underlying table instead and add a new column with ALTER TABLE on the fly, like:

    ALTER TABLE "MyCacheName".MYCACHE ADD UserEmail VARCHAR