public void loadV2(SRMetaBlockReader reader) throws IOException, SRMetaBlockException, SRMetaBlockEOFException {
        try {
            // 1 json for myself
            AuthorizationMgr ret = reader.readJson(AuthorizationMgr.class);
            ret.globalStateMgr = globalStateMgr;
            ret.provider = Objects.requireNonNullElseGet(provider, DefaultAuthorizationProvider::new);
            ret.initBuiltinRolesAndUsers();

            // 1 json for num user
            int numUser = reader.readInt();
            LOG.info("loading {} users", numUser);
            for (int i = 0; i != numUser; ++i) {
                // 2 json for each user(kv)
                UserIdentity userIdentity = reader.readJson(UserIdentity.class);
                UserPrivilegeCollectionV2 collection = reader.readJson(UserPrivilegeCollectionV2.class);

                if (userIdentity.equals(UserIdentity.ROOT)) {
                    UserPrivilegeCollectionV2 rootUserPrivCollection =
                            ret.getUserPrivilegeCollectionUnlocked(UserIdentity.ROOT);
                    collection.grantRoles(rootUserPrivCollection.getAllRoles());
                    collection.setDefaultRoleIds(rootUserPrivCollection.getDefaultRoleIds());
                    collection.typeToPrivilegeEntryList = rootUserPrivCollection.typeToPrivilegeEntryList;
                }

                ret.userToPrivilegeCollection.put(userIdentity, collection);
            }
            // 1 json for num roles
            int numRole = reader.readInt();
            LOG.info("loading {} roles", numRole);
            for (int i = 0; i != numRole; ++i) {
                // 2 json for each role(kv)
                Long roleId = reader.readLong();
                RolePrivilegeCollectionV2 collection = reader.readJson(RolePrivilegeCollectionV2.class);

                // Use hard-code PrivilegeCollection in the memory as the built-in role permission.
                // The reason why need to replay from the image here
                // is because the associated information of the role-id is stored in the image.
                if (PrivilegeBuiltinConstants.IMMUTABLE_BUILT_IN_ROLE_IDS.contains(roleId)) {
                    RolePrivilegeCollectionV2 builtInRolePrivilegeCollection =
                            ret.roleIdToPrivilegeCollection.get(roleId);
                    collection.typeToPrivilegeEntryList = builtInRolePrivilegeCollection.typeToPrivilegeEntryList;
                }
                ret.roleIdToPrivilegeCollection.put(roleId, collection);
            }

            LOG.info("loaded {} users, {} roles",
                    ret.userToPrivilegeCollection.size(), ret.roleIdToPrivilegeCollection.size());

            // mark data is loaded
            isLoaded = true;
            roleNameToId = ret.roleNameToId;
            pluginId = ret.pluginId;
            pluginVersion = ret.pluginVersion;
            userToPrivilegeCollection = ret.userToPrivilegeCollection;
            roleIdToPrivilegeCollection = ret.roleIdToPrivilegeCollection;

            // Initialize the Authorizer class in advance during the loading phase
            // to prevent loading errors and lack of permissions.
            Authorizer.getInstance();
        } catch (PrivilegeException e) {
            throw new IOException("failed to load AuthorizationManager!", e);
        }
    }
@Test
    public void testLoadV2() throws Exception {
        GlobalStateMgr masterGlobalStateMgr = ctx.getGlobalStateMgr();
        AuthorizationMgr masterManager = masterGlobalStateMgr.getAuthorizationMgr();
        UtFrameUtils.PseudoJournalReplayer.resetFollowerJournalQueue();

        setCurrentUserAndRoles(ctx, UserIdentity.ROOT);
        for (int i = 0; i != 2; ++i) {
            DDLStmtExecutor.execute(UtFrameUtils.parseStmtWithNewParser(
                    "create role test_persist_role" + i, ctx), ctx);
            Assert.assertTrue(masterManager.checkRoleExists("test_persist_role" + i));
        }

        UtFrameUtils.PseudoImage emptyImage = new UtFrameUtils.PseudoImage();
        masterGlobalStateMgr.getAuthorizationMgr().saveV2(emptyImage.getImageWriter());

        AuthorizationMgr authorizationMgr = new AuthorizationMgr();
        SRMetaBlockReader reader = new SRMetaBlockReaderV2(emptyImage.getJsonReader());
        authorizationMgr.loadV2(reader);

        Assert.assertNotNull(authorizationMgr.getRolePrivilegeCollection("test_persist_role0"));
    }