Skip to content
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

Fix multiple Bugs with high concurrency in RM module #1214

Merged
merged 2 commits into from Dec 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -17,8 +17,6 @@

package org.apache.linkis.manager.label.service.impl

import java.util

import org.apache.linkis.common.ServiceInstance
import org.apache.linkis.common.utils.{Logging, Utils}
import org.apache.linkis.manager.common.entity.node.ScoreServiceInstance
Expand All @@ -27,8 +25,7 @@ import org.apache.linkis.manager.common.utils.ManagerUtils
import org.apache.linkis.manager.label.LabelManagerUtils
import org.apache.linkis.manager.label.builder.factory.LabelBuilderFactoryContext
import org.apache.linkis.manager.label.conf.LabelManagerConf
import org.apache.linkis.manager.label.entity.Label.ValueRelation
import org.apache.linkis.manager.label.entity.{Feature, Label, UserModifiable}
import org.apache.linkis.manager.label.entity.{Feature, Label}
import org.apache.linkis.manager.label.score.NodeLabelScorer
import org.apache.linkis.manager.label.service.NodeLabelService
import org.apache.linkis.manager.label.utils.LabelUtils
Expand All @@ -38,6 +35,7 @@ import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import org.springframework.util.CollectionUtils

import java.util
import scala.collection.JavaConversions._
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
Expand Down Expand Up @@ -179,13 +177,6 @@ class DefaultNodeLabelService extends NodeLabelService with Logging {
labelManagerPersistence.removeNodeLabels(instance, removeLabels.map(_.getId))
}

@Transactional(rollbackFor = Array(classOf[Exception]))
override def removeLabelsFromNodeWithoutPermanent(instance: ServiceInstance, permanentLabel: Array[String] = Array()): Unit = {
val labels = labelManagerPersistence.getLabelByServiceInstance(instance)
val lowerCasePermanentLabels = permanentLabel.map(_.toLowerCase())
val withoutPermanentLabel = labels.filterNot(label => lowerCasePermanentLabels.contains(label.getLabelKey.toLowerCase)).map(_.getId)
labelManagerPersistence.removeNodeLabels(instance, withoutPermanentLabel)
}

/**
* Get node instances by labels
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -31,7 +31,7 @@ public interface NodeMetricManagerMapper {
void addNodeMetrics(@Param("nodeMetrics") PersistenceNodeMetrics nodeMetrics);

@Select("select count(id) from linkis_cg_manager_service_instance_metrics met inner join linkis_cg_manager_service_instance ins" +
" on met.instance = #{instance} and ins.instance = #{instance} and met.instance = ins.instance")
" on met.instance = #{instance} and ins.instance = #{instance} and met.instance = ins.instance")
int checkInstanceExist(@Param("instance") String instance);


Expand Down Expand Up @@ -69,7 +69,6 @@ public interface NodeMetricManagerMapper {
"<if test=\"nodeMetrics.heartBeatMsg != null\"> heartbeat_msg = #{nodeMetrics.heartBeatMsg},</if>" +
"<if test=\"nodeMetrics.healthy != null\"> healthy_status=#{nodeMetrics.healthy}, </if>" +
"<if test=\"nodeMetrics.updateTime != null\"> update_time=#{nodeMetrics.updateTime},</if>" +
"<if test=\"nodeMetrics.createTime != null\"> create_time=#{nodeMetrics.createTime},</if>" +
"</trim> where instance = #{instance}" +
"</script>"})
void updateNodeMetrics(@Param("nodeMetrics") PersistenceNodeMetrics nodeMetrics, @Param("instance") String instance);
Expand Down
Expand Up @@ -34,39 +34,19 @@ public interface ResourceManagerMapper {

@Update({ "update linkis_cg_manager_linkis_resources set max_resource = #{persistenceResource.maxResource},min_resource = #{persistenceResource.minResource}, " +
"used_resource=#{persistenceResource.usedResource},left_resource=#{persistenceResource.leftResource},expected_resource=#{persistenceResource.expectedResource}," +
"locked_resource=#{persistenceResource.lockedResource},resourceType=#{persistenceResource.resourceType}," +
"update_time=#{persistenceResource.updateTime},create_time=#{persistenceResource.createTime} where ticketId = #{ticketId}"})
"locked_resource=#{persistenceResource.lockedResource}," +
"update_time=#{persistenceResource.updateTime} where ticketId = #{ticketId}"})
void nodeResourceUpdate(@Param("ticketId") String ticketId,@Param("persistenceResource") PersistenceResource persistenceResource);

@Update({"update linkis_cg_manager_linkis_resources set max_resource = #{persistenceResource.maxResource},min_resource = #{persistenceResource.minResource}," +
"used_resource=#{persistenceResource.usedResource},left_resource=#{persistenceResource.leftResource},expected_resource=#{persistenceResource.expectedResource}," +
"locked_resource=#{persistenceResource.lockedResource},resourceType=#{persistenceResource.resourceType},ticketId=#{persistenceResource.ticketId}," +
"update_time=#{persistenceResource.updateTime},create_time=#{persistenceResource.createTime} where id = #{resourceId}"})
"locked_resource=#{persistenceResource.lockedResource}," +
"update_time=#{persistenceResource.updateTime} where id = #{resourceId}"})
void nodeResourceUpdateByResourceId(@Param("resourceId") int resourceId,@Param("persistenceResource") PersistenceResource persistenceResource);

@Select("select id from linkis_cg_manager_linkis_resources where ticketId is null and id in ( select resource_id from linkis_cg_manager_label_resource A join linkis_cg_manager_label_service_instance B on A.label_id=B.label_id and B.service_instance=#{instance})")
int getNodeResourceUpdateResourceId(@Param("instance") String instance);

// @Select("select * from linkis_cg_manager_linkis_resources where id in \n" +
// "(select resource_id from linkis_cg_manager_label_resource A join linkis_cg_manager_label_service_instance B on A.label_id=B.label_id and B.service_instance_id=#{serviceInstanceId})")
// @Results({
// @Result(property = "maxResource", column = "max_resource"),
// @Result(property = "minResource", column = "min_resource"),
// @Result(property = "usedResource", column = "used_resource"),
// @Result(property = "leftResource", column = "left_resource"),
// @Result(property = "expectedResource", column = "expected_resource"),
// @Result(property = "lockedResource", column = "locked_resource"),
// @Result(property = "updateTime", column = "update_time"),
// @Result(property = "createTime", column = "create_time"),
//
// })
// List<PersistenceResource> getResourceByServiceInstanceId(@Param("serviceInstanceId") int serviceInstanceId);
//
// @Select("select * from linkis_cg_manager_linkis_resources where id = #{id}")
// PersistenceResource getResourceById(@Param("id") int id);
//
// @Delete("delete from linkis_cg_manager_linkis_resources where id = #{id}")
// void deleteResourceById(@Param("id") int id);

@Delete("delete from linkis_cg_manager_label_resource where label_id in (select label_id from linkis_cg_manager_label_service_instance where service_instance=#{instance})")
void deleteResourceAndLabelId(@Param("instance") String instance);
Expand Down Expand Up @@ -97,4 +77,10 @@ public interface ResourceManagerMapper {

@Select("select * from linkis_cg_manager_label where id in (select label_id from linkis_cg_manager_label_resource A join linkis_cg_manager_linkis_resources B on A.resource_id=B.id and B.ticketId=#{ticketId})")
List<PersistenceLabel> getLabelsByTicketId(@Param("ticketId") String ticketId);

void deleteResourceById(@Param("ids") List<Integer> ids);

void deleteResourceRelByResourceId(@Param("ids") List<Integer> ids);

PersistenceResource getResourceById(@Param("id") Integer id);
}