-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enhancement] Support Gson subtype rollback #50471
[Enhancement] Support Gson subtype rollback #50471
Conversation
return (T) object.getValue(); | ||
} | ||
return GsonUtils.GSON.fromJson(jsonReader, typeOfT); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
The casting in the readJson
method may lead to a ClassCastException
.
You can modify the code like this:
@Override
public <T> T readJson(Class<T> classOfT) throws IOException, SRMetaBlockEOFException {
Object object = readJson((Type) classOfT);
if(!Primitives.wrap(classOfT).isInstance(object)) {
throw new JsonSyntaxException("Expected type " + classOfT.getName() + " but got "
+ (object == null ? "null" : object.getClass().getName()));
}
return Primitives.wrap(classOfT).cast(object);
}
} | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException, SRMetaBlockException { | ||
if (header == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
Potential ClassCastException
in the readJson(Class<T> classOfT)
method.
You can modify the code like this:
@Override
public <T> T readJson(Class<T> classOfT) throws IOException, SRMetaBlockEOFException {
T object = GsonUtils.GSON.fromJson(genJsonReader(readJsonBytes()), classOfT);
return Primitives.wrap(classOfT).cast(object);
}
|
||
// Initialize the Authorizer class in advance during the loading phase | ||
// to prevent loading errors and lack of permissions. | ||
Authorizer.getInstance(); | ||
} | ||
|
||
public void saveV2(ImageWriter imageWriter) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The most risky bug in this code is:
Potentially throwing IOException
within the lambda functions of readMapEntry
, which may not be adequately handled and could be suppressed.
You can modify the code like this:
public void loadV2(SRMetaBlockReader reader) throws IOException, SRMetaBlockException, SRMetaBlockEOFException {
// 1 json for myself
AuthorizationMgr ret = reader.readJson(AuthorizationMgr.class);
ret.globalStateMgr = globalStateMgr;
ret.provider = Objects.requireNonNullElseGet(provider, DefaultAuthorizationProvider::new);
ret.initBuiltinRolesAndUsers();
try {
LOG.info("loading users");
reader.readMapEntry(UserIdentity.class, UserPrivilegeCollectionV2.class,
(MapEntryConsumer<UserIdentity, UserPrivilegeCollectionV2>) (userIdentity, collection) -> {
if (userIdentity.equals(UserIdentity.ROOT)) {
try {
UserPrivilegeCollectionV2 rootUserPrivCollection =
ret.getUserPrivilegeCollectionUnlocked(UserIdentity.ROOT);
collection.grantRoles(rootUserPrivCollection.getAllRoles());
collection.setDefaultRoleIds(rootUserPrivCollection.getDefaultRoleIds());
collection.typeToPrivilegeEntryList = rootUserPrivCollection.typeToPrivilegeEntryList;
} catch (PrivilegeException e) {
throw new RuntimeException("failed to load users in AuthorizationManager!", e);
}
}
ret.userToPrivilegeCollection.put(userIdentity, collection);
});
LOG.info("loading roles");
reader.readMapEntry(Long.class, RolePrivilegeCollectionV2.class,
(MapEntryConsumer<Long, RolePrivilegeCollectionV2>) (roleId, collection) -> {
// 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 (RuntimeException e) {
throw new IOException("Failed to load AuthorizationManager!", e);
}
}
fe/fe-core/src/main/java/com/starrocks/persist/gson/RuntimeTypeAdapterFactory.java
Outdated
Show resolved
Hide resolved
ab2763a
to
e1f9c28
Compare
fe/fe-core/src/test/java/com/starrocks/persist/metablock/SRMetaBlockV1Test.java
Outdated
Show resolved
Hide resolved
@Mergifyio rebase |
✅ Branch has been successfully rebased |
d29c044
to
e064051
Compare
fe/fe-core/src/main/java/com/starrocks/persist/metablock/SRMetaBlockReader.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/com/starrocks/persist/metablock/SRMetaBlockReaderV1.java
Outdated
Show resolved
Hide resolved
|
yes, ignore the unknown meta data block when rollback |
e064051
to
9e2523b
Compare
@Mergifyio rebase |
✅ Branch has been successfully rebased |
9e2523b
to
8a9fe83
Compare
fe/fe-core/src/main/java/com/starrocks/persist/gson/GsonUtils.java
Outdated
Show resolved
Hide resolved
@Mergifyio rebase |
✅ Branch has been successfully rebased |
9c6a614
to
e0e5f01
Compare
Signed-off-by: gengjun-git <[email protected]>
Signed-off-by: gengjun-git <[email protected]>
e0e5f01
to
94c747a
Compare
Quality Gate passedIssues Measures |
[Java-Extensions Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
[FE Incremental Coverage Report]✅ pass : 266 / 314 (84.71%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
@Mergifyio backport branch-3.3 |
✅ Backports have been created
|
SubtypeNotFoundException will be thrown when there is a undefined class when deserialize a subclass. The `readCollection` and `readMapEntry` will ignore the SubtypeNotFoundException if ignore_unknown_subtype is true. Signed-off-by: gengjun-git <[email protected]> (cherry picked from commit 790a2b0) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/journal/JournalEntity.java # fe/fe-core/src/main/java/com/starrocks/qe/VariableMgr.java # fe/fe-core/src/test/java/com/starrocks/plugin/PluginMgrTest.java
Signed-off-by: gengjun-git <[email protected]> Co-authored-by: gengjun-git <[email protected]>
SubtypeNotFoundException will be thrown when there is a undefined class when deserialize a subclass. The `readCollection` and `readMapEntry` will ignore the SubtypeNotFoundException if ignore_unknown_subtype is true. Signed-off-by: gengjun-git <[email protected]> Signed-off-by: zhiminr.ren <[email protected]>
Why I'm doing:
What I'm doing:
SubtypeNotFoundException will be thrown when there is a undefined class when deserialize a subclass. The
readCollection
andreadMapEntry
will ignore the SubtypeNotFoundException if ignore_unknown_subtype is true.Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: