Skip to content

Commit 0dde273

Browse files
authored
[Fix](user-property) Preserve legacy user properties during desrialization (#65781)
Related PR: #37243 Problem Summary: (Before doris-3.0)Older persisted `CommonUserProperties` JSON uses long field names such as `resourceTags` and `sqlBlockRules`. The current serialized names are `rt` and `sbr`, while the compatibility aliases only covered the singular forms `resourceTag` and `sqlBlockRule`. As a result, legacy user properties may be silently ignored during metadata deserialization, causing resource tags or SQL block rules to be reset to their default values. This change adds compatibility aliases for the legacy plural field names: - `resourceTags` - `sqlBlockRules`
1 parent f70306c commit 0dde273

2 files changed

Lines changed: 88 additions & 2 deletions

File tree

‎fe/fe-core/src/main/java/org/apache/doris/mysql/privilege/CommonUserProperties.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public class CommonUserProperties implements GsonPostProcessable {
4545
private long maxQueryInstances = -1;
4646
@SerializedName(value = "pfei", alternate = {"parallelFragmentExecInstanceNum"})
4747
private int parallelFragmentExecInstanceNum = -1;
48-
@SerializedName(value = "sbr", alternate = {"sqlBlockRule"})
48+
@SerializedName(value = "sbr", alternate = {"sqlBlockRule", "sqlBlockRules"})
4949
private String sqlBlockRules = "";
5050
@SerializedName(value = "crl", alternate = {"cpuResourceLimit"})
5151
private int cpuResourceLimit = -1;
5252
// The tag of the resource that the user is allowed to use
53-
@SerializedName(value = "rt", alternate = {"resourceTag"})
53+
@SerializedName(value = "rt", alternate = {"resourceTag", "resourceTags"})
5454
private Set<Tag> resourceTags = Sets.newHashSet();
5555
// user level exec_mem_limit, if > 0, will overwrite the exec_mem_limit in session variable
5656
@SerializedName(value = "eml", alternate = {"execMemLimit"})
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.mysql.privilege;
19+
20+
import org.apache.doris.persist.gson.GsonUtils;
21+
import org.apache.doris.resource.Tag;
22+
23+
import org.junit.Assert;
24+
import org.junit.Test;
25+
26+
import java.util.Collections;
27+
28+
public class CommonUserPropertiesTest {
29+
private static final String RESOURCE_TAG_JSON = "[{\"type\":\"location\",\"value\":\"group_a\"}]";
30+
31+
@Test
32+
public void testDeserializeResourceTagsFromAllFieldNames() {
33+
for (String fieldName : new String[] {"rt", "resourceTag", "resourceTags"}) {
34+
String json = String.format("{\"%s\":%s}", fieldName, RESOURCE_TAG_JSON);
35+
CommonUserProperties properties = GsonUtils.GSON.fromJson(json, CommonUserProperties.class);
36+
37+
Assert.assertEquals(Collections.singleton(Tag.createNotCheck(Tag.TYPE_LOCATION, "group_a")),
38+
properties.getResourceTags());
39+
}
40+
}
41+
42+
@Test
43+
public void testDeserializeSqlBlockRulesFromAllFieldNames() {
44+
for (String fieldName : new String[] {"sbr", "sqlBlockRule", "sqlBlockRules"}) {
45+
String json = String.format("{\"%s\":\"rule_a, rule_b\"}", fieldName);
46+
CommonUserProperties properties = GsonUtils.GSON.fromJson(json, CommonUserProperties.class);
47+
48+
Assert.assertEquals("rule_a, rule_b", properties.getSqlBlockRules());
49+
Assert.assertArrayEquals(new String[] {"rule_a", "rule_b"}, properties.getSqlBlockRulesSplit());
50+
}
51+
}
52+
53+
@Test
54+
public void testDeserializeLegacyCommonUserProperties() {
55+
String json = "{"
56+
+ "\"maxConn\":101,"
57+
+ "\"maxQueryInstances\":102,"
58+
+ "\"parallelFragmentExecInstanceNum\":103,"
59+
+ "\"sqlBlockRules\":\"rule_a, rule_b\","
60+
+ "\"cpuResourceLimit\":104,"
61+
+ "\"resourceTags\":" + RESOURCE_TAG_JSON + ","
62+
+ "\"execMemLimit\":105,"
63+
+ "\"queryTimeout\":106,"
64+
+ "\"insertTimeout\":107,"
65+
+ "\"workloadGroup\":\"legacy_group\","
66+
+ "\"enablePreferCachedRowset\":true,"
67+
+ "\"queryFreshnessTolerance\":108"
68+
+ "}";
69+
CommonUserProperties properties = GsonUtils.GSON.fromJson(json, CommonUserProperties.class);
70+
71+
Assert.assertEquals(101L, properties.getMaxConn());
72+
Assert.assertEquals(102L, properties.getMaxQueryInstances());
73+
Assert.assertEquals(103, properties.getParallelFragmentExecInstanceNum());
74+
Assert.assertEquals("rule_a, rule_b", properties.getSqlBlockRules());
75+
Assert.assertArrayEquals(new String[] {"rule_a", "rule_b"}, properties.getSqlBlockRulesSplit());
76+
Assert.assertEquals(104, properties.getCpuResourceLimit());
77+
Assert.assertEquals(Collections.singleton(Tag.createNotCheck(Tag.TYPE_LOCATION, "group_a")),
78+
properties.getResourceTags());
79+
Assert.assertEquals(105L, properties.getExecMemLimit());
80+
Assert.assertEquals(106, properties.getQueryTimeout());
81+
Assert.assertEquals(107, properties.getInsertTimeout());
82+
Assert.assertEquals("legacy_group", properties.getWorkloadGroup());
83+
Assert.assertTrue(properties.getEnablePreferCachedRowset());
84+
Assert.assertEquals(108L, properties.getQueryFreshnessToleranceMs());
85+
}
86+
}

0 commit comments

Comments
 (0)