morningman commented on code in PR #18184:
URL: https://github.com/apache/doris/pull/18184#discussion_r1151941874
##########
fe/fe-common/src/main/java/org/apache/doris/common/FeMetaVersion.java:
##########
@@ -56,9 +56,11 @@ public final class FeMetaVersion {
public static final int VERSION_117 = 117;
// change frontend meta to json, add hostname to MasterInfo
public static final int VERSION_118 = 118;
+ // add resource group
+ public static final int VERSION_119 = 119;
// note: when increment meta version, should assign the latest version to
VERSION_CURRENT
- public static final int VERSION_CURRENT = VERSION_118;
+ public static final int VERSION_CURRENT = VERSION_119;
Review Comment:
VERSION_119 is not used?
##########
gensrc/thrift/PaloInternalService.thrift:
##########
@@ -576,6 +576,15 @@ struct TPipelineInstanceParams {
6: optional i32 backend_num
}
+struct TPipelineResourceGroup {
+ 1: required i64 id
Review Comment:
use `optional` for all fields.
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/ResourceGroupMgr.java:
##########
@@ -0,0 +1,225 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.catalog;
+
+import org.apache.doris.analysis.CreateResourceGroupStmt;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.io.Text;
+import org.apache.doris.common.io.Writable;
+import org.apache.doris.common.proc.BaseProcResult;
+import org.apache.doris.common.proc.ProcNodeInterface;
+import org.apache.doris.common.proc.ProcResult;
+import org.apache.doris.persist.gson.GsonUtils;
+import org.apache.doris.thrift.TPipelineResourceGroup;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.gson.annotations.SerializedName;
+import org.apache.commons.lang.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+public class ResourceGroupMgr implements Writable {
+
+ private static final Logger LOG =
LogManager.getLogger(ResourceGroupMgr.class);
+
+ public static final String DEFAULT_GROUP_NAME = "default";
+
+ private static final String CPU_SCHEDULING_WEIGHT =
"cpu_scheduling_weight";
+
+ private static final String CONCURRENCY_LIMIT = "concurrency_limit";
+
+ public static final ImmutableList<String>
RESOURCE_GROUP_PROC_NODE_TITLE_NAMES = new ImmutableList.Builder<String>()
+ .add("Id").add("Name").add("Item").add("Value")
+ .build();
+
+ private static final ImmutableSet<String> REQUIRED_PROPERTIES_NAME = new
ImmutableSet.Builder<String>().add(
+ CPU_SCHEDULING_WEIGHT).build();
+
+ private static final ImmutableSet<String> ALL_PROPERTIES_NAME = new
ImmutableSet.Builder<String>().add(
+ CPU_SCHEDULING_WEIGHT).add(CONCURRENCY_LIMIT).build();
+
+ @SerializedName(value = "nameToResourceGroup")
+ private final Map<String, PipelineResourceGroup> nameToResourceGroup =
Maps.newHashMap();
Review Comment:
Suggest using `id` as map's key.
So that we can change the group's name more easily
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/ResourceGroupMgr.java:
##########
@@ -0,0 +1,225 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.catalog;
+
+import org.apache.doris.analysis.CreateResourceGroupStmt;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.io.Text;
+import org.apache.doris.common.io.Writable;
+import org.apache.doris.common.proc.BaseProcResult;
+import org.apache.doris.common.proc.ProcNodeInterface;
+import org.apache.doris.common.proc.ProcResult;
+import org.apache.doris.persist.gson.GsonUtils;
+import org.apache.doris.thrift.TPipelineResourceGroup;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.gson.annotations.SerializedName;
+import org.apache.commons.lang.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+public class ResourceGroupMgr implements Writable {
+
+ private static final Logger LOG =
LogManager.getLogger(ResourceGroupMgr.class);
+
+ public static final String DEFAULT_GROUP_NAME = "default";
+
+ private static final String CPU_SCHEDULING_WEIGHT =
"cpu_scheduling_weight";
+
+ private static final String CONCURRENCY_LIMIT = "concurrency_limit";
+
+ public static final ImmutableList<String>
RESOURCE_GROUP_PROC_NODE_TITLE_NAMES = new ImmutableList.Builder<String>()
+ .add("Id").add("Name").add("Item").add("Value")
+ .build();
+
+ private static final ImmutableSet<String> REQUIRED_PROPERTIES_NAME = new
ImmutableSet.Builder<String>().add(
+ CPU_SCHEDULING_WEIGHT).build();
+
+ private static final ImmutableSet<String> ALL_PROPERTIES_NAME = new
ImmutableSet.Builder<String>().add(
+ CPU_SCHEDULING_WEIGHT).add(CONCURRENCY_LIMIT).build();
+
+ @SerializedName(value = "nameToResourceGroup")
+ private final Map<String, PipelineResourceGroup> nameToResourceGroup =
Maps.newHashMap();
+
+ private final ResourceProcNode procNode = new ResourceProcNode();
+
+ private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+
+ public ResourceGroupMgr() {
+ }
+
+ private void readLock() {
+ lock.readLock().lock();
+ }
+
+ private void readUnlock() {
+ lock.readLock().unlock();
+ }
+
+ private void writeLock() {
+ lock.writeLock().lock();
+ }
+
+ private void writeUnlock() {
+ lock.writeLock().unlock();
+ }
+
+ public void init() {
+ checkAndCreateDefaultGroup();
+ }
+
+ public List<TPipelineResourceGroup> getResourceGroup(String groupName)
throws UserException {
+ List<TPipelineResourceGroup> resourceGroups = Lists.newArrayList();
+ readLock();
+ try {
+ if (!nameToResourceGroup.containsKey(groupName)) {
+ throw new UserException("Resource group " + groupName + " does
not exist");
+ }
+ // need to check resource group privs
+ PipelineResourceGroup resourceGroup;
+ do {
+ resourceGroup = nameToResourceGroup.get(groupName);
+ resourceGroups.add(resourceGroup.toThrift());
+ groupName = resourceGroup.getParentName();
+ } while (groupName != null);
+ } finally {
+ readUnlock();
+ }
+ return resourceGroups;
+ }
+
+ private void checkAndCreateDefaultGroup() {
+ PipelineResourceGroup defaultResourceGroup;
+ writeLock();
+ try {
+ if (nameToResourceGroup.containsKey(DEFAULT_GROUP_NAME)) {
+ return;
+ }
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put(CPU_SCHEDULING_WEIGHT, "10");
+ defaultResourceGroup = new
PipelineResourceGroup(Env.getCurrentEnv().getNextId(),
+ DEFAULT_GROUP_NAME, properties, null);
+ nameToResourceGroup.put(DEFAULT_GROUP_NAME, defaultResourceGroup);
+ } finally {
+ writeUnlock();
+ }
+
+
Env.getCurrentEnv().getEditLog().logCreateResourceGroup(defaultResourceGroup);
+ LOG.info("Create resource group success: {}", defaultResourceGroup);
+ }
+
+ public void createResourceGroup(CreateResourceGroupStmt stmt) throws
DdlException {
+ checkProperties(stmt.getProperties());
+ PipelineResourceGroup resourceGroup = new
PipelineResourceGroup(Env.getCurrentEnv().getNextId(),
+ stmt.getResourceGroupName(),
+ stmt.getProperties(), null);
+ String resourceGroupNameName = resourceGroup.getName();
+ writeLock();
+ try {
+ if (nameToResourceGroup.putIfAbsent(resourceGroupNameName,
resourceGroup) != null) {
+ if (stmt.isIfNotExists()) {
+ return;
+ } else {
+ throw new DdlException("Resource group(" +
resourceGroupNameName + ") already exist");
+ }
+ }
+ } finally {
+ writeUnlock();
+ }
+
+ Env.getCurrentEnv().getEditLog().logCreateResourceGroup(resourceGroup);
Review Comment:
this should be done inside write lock
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/ResourceGroupMgr.java:
##########
@@ -0,0 +1,225 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.catalog;
+
+import org.apache.doris.analysis.CreateResourceGroupStmt;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.io.Text;
+import org.apache.doris.common.io.Writable;
+import org.apache.doris.common.proc.BaseProcResult;
+import org.apache.doris.common.proc.ProcNodeInterface;
+import org.apache.doris.common.proc.ProcResult;
+import org.apache.doris.persist.gson.GsonUtils;
+import org.apache.doris.thrift.TPipelineResourceGroup;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.gson.annotations.SerializedName;
+import org.apache.commons.lang.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+public class ResourceGroupMgr implements Writable {
Review Comment:
There is already a package named `org.apache.doris.resource`.
I think you can put this class to that package.
And currently, the class in that package is related to `tag resource`.
For classify, you can create a new package
`org.apache.doris.resource.resourcegroup` for this class
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/PipelineResourceGroup.java:
##########
@@ -0,0 +1,128 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.catalog;
+
+import org.apache.doris.common.FeConstants;
+import org.apache.doris.common.io.DeepCopy;
+import org.apache.doris.common.io.Text;
+import org.apache.doris.common.io.Writable;
+import org.apache.doris.common.proc.BaseProcResult;
+import org.apache.doris.persist.gson.GsonPostProcessable;
+import org.apache.doris.persist.gson.GsonUtils;
+import org.apache.doris.thrift.TPipelineResourceGroup;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import com.google.gson.annotations.SerializedName;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Set;
+
+public class PipelineResourceGroup implements Writable, GsonPostProcessable {
+
+ private static final Logger LOG =
LogManager.getLogger(PipelineResourceGroup.class);
+
+ @SerializedName(value = "id")
+ private long id;
+
+ @SerializedName(value = "name")
+ private String name;
+
+ @SerializedName(value = "properties")
+ private Map<String, String> properties;
+
+ // version update required after alter resource group
+ @SerializedName(value = "version")
+ private long version;
+
+ @SerializedName(value = "parentName")
+ private String parentName;
+
+ @SerializedName(value = "childrenNames")
+ private Set<String> childrenNames;
+
+ public PipelineResourceGroup(long id, String name, Map<String, String>
properties, String parentName) {
+ this.id = id;
+ this.name = name;
+ this.properties = properties;
+ this.parentName = parentName;
+ this.childrenNames = Sets.newHashSet();
+ this.version = 0;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Map<String, String> getProperties() {
+ return properties;
+ }
+
+ public String getParentName() {
+ return parentName;
+ }
+
+ public void getProcNodeData(BaseProcResult result) {
+ for (Map.Entry<String, String> entry : properties.entrySet()) {
+ result.addRow(Lists.newArrayList(String.valueOf(id), name,
entry.getKey(), entry.getValue()));
+ }
+ }
+
+ @Override
+ public String toString() {
+ return GsonUtils.GSON.toJson(this);
+ }
+
+ @Override
+ public PipelineResourceGroup clone() {
+ PipelineResourceGroup copied = DeepCopy.copy(this,
PipelineResourceGroup.class, FeConstants.meta_version);
+ if (copied == null) {
+ LOG.warn("failed to clone resource group: " + getName());
+ return null;
+ }
+ return copied;
+ }
+
+ public TPipelineResourceGroup toThrift() {
+ return new TPipelineResourceGroup(id, name, properties, version);
+ }
+
+ @Override
+ public void write(DataOutput out) throws IOException {
+ String json = GsonUtils.GSON.toJson(this);
+ Text.writeString(out, json);
+ }
+
+ public static PipelineResourceGroup read(DataInput in) throws IOException {
+ String json = Text.readString(in);
+ return GsonUtils.GSON.fromJson(json, PipelineResourceGroup.class);
+ }
+
+ @Override
+ public void gsonPostProcess() throws IOException {
Review Comment:
No need to implements `GsonPostProcessable` if not used
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]