Skip to content

Commit 1043145

Browse files
morningmanpull[bot]
authored andcommitted
[improvement](resource-tag) limit the default user's resource tag to 'default' (#25331)
In previous, if user property `'resource_tags.location'` is not set, the can use Backends with any resource tag. It may confuse that when the DBA set part of Backends to resource group A, then the current existing user should not be able to use this group A util it's `'resource_tags.location'` is set. So in this PR, I change the behavior, that if user property `'resource_tags.location'` is not set, it can only use the Backends with `default` tag.
1 parent 6966231 commit 1043145

7 files changed

Lines changed: 28 additions & 13 deletions

File tree

‎docs/en/docs/admin-manual/multi-tenant.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ Node resource division refers to setting tags for BE nodes in a Doris cluster, a
138138

139139
After the setting is complete, when user1 initiates a query on the UserTable table, it will only access the data copy on the nodes in the `group_a` resource group, and the query will only use the node computing resources in the `group_a` resource group. The query of user3 can use copies and computing resources in any resource group.
140140

141+
> Note: By default, the user's `resource_tags.location` attribute is empty. In versions prior to 2.0.2 (inclusive), by default, users are not restricted by tags and can use any resource group. After version 2.0.3, users can only use the `default` resource group by default.
142+
141143
In this way, we have achieved physical resource isolation for different user queries by dividing nodes and restricting user resource usage. Furthermore, we can create different users for different business departments and restrict each user from using different resource groups. In order to avoid the use of resource interference between different business parts. For example, there is a business table in the cluster that needs to be shared by all 9 business departments, but it is hoped that resource preemption between different departments can be avoided as much as possible. Then we can create 3 copies of this table and store them in 3 resource groups. Next, we create 9 users for 9 business departments, and limit the use of one resource group for every 3 users. In this way, the degree of competition for resources is reduced from 9 to 3.
142144
143145
On the other hand, for the isolation of online and offline tasks. We can use resource groups to achieve this. For example, we can divide nodes into two resource groups, Online and Offline. The table data is still stored in 3 copies, of which 2 copies are stored in the Online resource group, and 1 copy is stored in the Offline resource group. The Online resource group is mainly used for online data services with high concurrency and low latency. Some large queries or offline ETL operations can be executed using nodes in the Offline resource group. So as to realize the ability to provide online and offline services simultaneously in a unified cluster.

‎docs/zh-CN/docs/admin-manual/multi-tenant.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ FE 不参与用户数据的处理计算等工作,因此是一个资源消耗
138138

139139
设置完成后,user1 在发起对 UserTable 表的查询时,只会访问 `group_a` 资源组内节点上的数据副本,并且查询仅会使用 `group_a` 资源组内的节点计算资源。而 user3 的查询可以使用任意资源组内的副本和计算资源。
140140

141+
> 注:默认情况下,用户的 `resource_tags.location` 属性为空,在2.0.2(含)之前的版本中,默认情况下,用户不受 tag 的限制,可以使用任意资源组。在 2.0.3 版本之后,默认情况下,用户只能使用 `default` 资源组。
142+
141143
这样,我们通过对节点的划分,以及对用户的资源使用限制,实现了不同用户查询上的物理资源隔离。更进一步,我们可以给不同的业务部门创建不同的用户,并限制每个用户使用不同的资源组。以避免不同业务部分之间使用资源干扰。比如集群内有一张业务表需要共享给所有9个业务部门使用,但是希望能够尽量避免不同部门之间的资源抢占。则我们可以为这张表创建3个副本,分别存储在3个资源组中。接下来,我们为9个业务部门创建9个用户,每3个用户限制使用一个资源组。这样,资源的竞争程度就由9降低到了3。
142144

143145
另一方面,针对在线和离线任务的隔离。我们可以利用资源组的方式实现。比如我们可以将节点划分为 Online 和 Offline 两个资源组。表数据依然以3副本的方式存储,其中 2 个副本存放在 Online 资源组,1 个副本存放在 Offline 资源组。Online 资源组主要用于高并发低延迟的在线数据服务,而一些大查询或离线ETL操作,则可以使用 Offline 资源组中的节点执行。从而实现在统一集群内同时提供在线和离线服务的能力。

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ public void setResourceTags(Set<Tag> resourceTags) {
110110
}
111111

112112
public Set<Tag> getResourceTags() {
113+
// If resource tags in user properties is empty, use default backend tag.
114+
if (resourceTags.isEmpty()) {
115+
return Sets.newHashSet(Tag.DEFAULT_BACKEND_TAG);
116+
}
113117
return resourceTags;
114118
}
115119

‎fe/fe-core/src/test/java/org/apache/doris/catalog/UserPropertyTest.java‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import org.apache.doris.common.UserException;
2525
import org.apache.doris.load.DppConfig;
2626
import org.apache.doris.mysql.privilege.UserProperty;
27+
import org.apache.doris.resource.Tag;
2728

2829
import com.google.common.collect.Lists;
30+
import com.google.common.collect.Sets;
2931
import mockit.Expectations;
3032
import mockit.Mocked;
3133
import org.junit.Assert;
@@ -116,6 +118,7 @@ public void testUpdate() throws UserException {
116118
Assert.assertEquals(new String[]{"rule1", "rule2"}, userProperty.getSqlBlockRules());
117119
Assert.assertEquals(2, userProperty.getCpuResourceLimit());
118120
Assert.assertEquals(500, userProperty.getQueryTimeout());
121+
Assert.assertEquals(Sets.newHashSet(Tag.DEFAULT_BACKEND_TAG), userProperty.getCopiedResourceTags());
119122

120123
// fetch property
121124
List<List<String>> rows = userProperty.fetchProperty();

‎fe/fe-core/src/test/java/org/apache/doris/planner/ResourceTagQueryTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public void test() throws Exception {
199199
OlapTable tbl = (OlapTable) db.getTableNullable("tbl1");
200200

201201
Set<Tag> userTags = Env.getCurrentEnv().getAuth().getResourceTags(Auth.ROOT_USER);
202-
Assert.assertEquals(0, userTags.size());
202+
Assert.assertEquals(1, userTags.size());
203203

204204
// set default tag for root
205205
String setPropStr = "set property for 'root' 'resource_tags.location' = 'default';";

‎fe/fe-core/src/test/java/org/apache/doris/statistics/CacheTest.java‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,21 @@ public Env getCurrentEnv() {
242242
null, null, false, null, new Date().toString(), null);
243243
}
244244
};
245-
StatisticsCache statisticsCache = new StatisticsCache();
246-
ColumnStatistic columnStatistic = statisticsCache.getColumnStatistics(1, 1, 1, "col");
247-
Thread.sleep(3000);
248-
columnStatistic = statisticsCache.getColumnStatistics(1, 1, 1, "col");
249-
Assertions.assertEquals(1, columnStatistic.count);
250-
Assertions.assertEquals(2, columnStatistic.ndv);
251-
Assertions.assertEquals(3, columnStatistic.avgSizeByte);
252-
Assertions.assertEquals(4, columnStatistic.numNulls);
253-
Assertions.assertEquals(5, columnStatistic.dataSize);
254-
Assertions.assertEquals(6, columnStatistic.minValue);
255-
Assertions.assertEquals(7, columnStatistic.maxValue);
245+
try {
246+
StatisticsCache statisticsCache = new StatisticsCache();
247+
ColumnStatistic columnStatistic = statisticsCache.getColumnStatistics(1, 1, 1, "col");
248+
Thread.sleep(3000);
249+
columnStatistic = statisticsCache.getColumnStatistics(1, 1, 1, "col");
250+
Assertions.assertEquals(1, columnStatistic.count);
251+
Assertions.assertEquals(2, columnStatistic.ndv);
252+
Assertions.assertEquals(3, columnStatistic.avgSizeByte);
253+
Assertions.assertEquals(4, columnStatistic.numNulls);
254+
Assertions.assertEquals(5, columnStatistic.dataSize);
255+
Assertions.assertEquals(6, columnStatistic.minValue);
256+
Assertions.assertEquals(7, columnStatistic.maxValue);
257+
} catch (Throwable t) {
258+
t.printStackTrace();
259+
}
256260
}
257261

258262
@Test

‎regression-test/suites/nereids_p0/outfile/test_outfile_expr.groovy‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ suite("test_outfile_expr") {
105105
SELECT user_id+1, age+sex, repeat(char_col, 10) FROM ${tableName} t ORDER BY user_id INTO OUTFILE "file://${outFile}/";
106106
"""
107107

108-
url = result[0][3]
108+
def url = result[0][3]
109109
urlHost = url.substring(8, url.indexOf("${outFile}"))
110110
def filePrifix = url.split("${outFile}")[1]
111111
csvFiles = "${outFile}${filePrifix}*.csv"

0 commit comments

Comments
 (0)