MVStore map version semantic changes 1.4.199 -> 2.2.224

41 views
Skip to first unread message

Rok Yu

unread,
Jun 18, 2024, 1:47:13 AMJun 18
to H2 Database
Hi,

I'm working on migrating from mvstore 1.4.199 to 2.2.224 and have noticed that the MVMap.openVersion semantics have changed. The 1.4.199 version opens the map with the largest version that is smaller than or equal to the requested version while the 2.2.224 version opens the map with the smallest version greater than or equal to the requested version.

The change appeared to occur with this commit.

This change makes things complicated because in order to open multiple maps for a specific mvstore version, instead of just passing in the version, I need to track the previous version numbers for each map and pass in the exact ones I need.

Is this change intentional? If so, is there a recommended way of opening all maps that correspond to a specific store version? If you cannot revert this behavior, is it possible to add a method to get all available versions stored for a map so I don't need to trrack them externally?

You can reproduce with code below.  On 1.4.199, prints:
---
m1.v0=0  1
m1.v1=1  1
m1.v2=2  3
---
on 2.2.224
m1.v0=0  1
m1.v1=1  3
m1.v2=2  3

Rok
----
package mvstore1;

import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;


public class Mvstore1 {
    public static void main(String[] args) {
        MVStore mvstore=new MVStore.Builder()
                .autoCommitDisabled()
                .open();
        println("mvstore=%d",mvstore.getCurrentVersion());

        MVMap m1=mvstore.openMap("m1");
        m1.put("a",1);
        mvstore.commit();
        println("mvstore=%d m1=%d",mvstore.getCurrentVersion(),m1.getVersion());

        MVMap m2=mvstore.openMap("m2");
        m2.put("b",2);
        mvstore.commit();
        println("mvstore=%d m1=%d m2=%d: ",mvstore.getCurrentVersion(),m1.getVersion(),m2.getVersion());

        m1.put("a",3);
        mvstore.commit();
        println("mvstore=%d m1=%d m2=%d: ",mvstore.getCurrentVersion(),m1.getVersion(),m2.getVersion());

        printMapVersion(m1,0);
        printMapVersion(m1,1);
        printMapVersion(m1,2);
    }

    private static void println(String m,Object...args) {
        System.out.println(m.formatted(args));
    }

    private static void printMapVersion(MVMap map,long version) {
        MVMap mapv=map.openVersion(version);
        println("m1.v%d=%d  %d",version,mapv.getVersion(),mapv.get("a"));
    }
}


Reply all
Reply to author
Forward
0 new messages