Browse Source

Remove spring cache for dao (#15184)

3.2.1-prepare
Wenjun Ruan 1 year ago committed by GitHub
parent
commit
1d23e4fe5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 42
      docs/docs/en/architecture/cache.md
  2. 42
      docs/docs/zh/architecture/cache.md
  3. 159
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/CacheEvictAspect.java
  4. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java
  5. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java
  6. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java
  7. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.java
  8. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TenantMapper.java
  9. 8
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserMapper.java
  10. 11
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapper.java
  11. 30
      dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/IMasterCacheService.java
  12. 34
      dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/transportor/CacheExpireRequest.java
  13. 52
      dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/rpc/MasterCacheServiceImpl.java

42
docs/docs/en/architecture/cache.md

@ -1,42 +0,0 @@
# Cache
## Purpose
Due to the large database read operations during the master-server scheduling process. Such as read tables like `tenant`, `user`, `processDefinition`, etc. Operations stress read pressure to the DB, and slow down the entire core scheduling process.
By considering this part of the business data is a high-read and low-write scenario, a cache module is introduced to reduce the DB read pressure and speed up the core scheduling process.
## Cache Settings
```yaml
spring:
cache:
# default disable cache, you can enable by `type: caffeine`
type: none
cache-names:
- tenant
- user
- processDefinition
- processTaskRelation
- taskDefinition
caffeine:
spec: maximumSize=100,expireAfterWrite=300s,recordStats
```
The cache module uses [spring-cache](https://spring.io/guides/gs/caching/), so you can set cache config like whether to enable cache (`none` to disable by default), cache types in the spring `application.yaml` directly.
Currently, implements the config of [caffeine](https://github.com/ben-manes/caffeine), you can assign cache configs like cache size, expire time, etc.
## Cache Read
The cache module adopts the `@Cacheable` annotation from spring-cache and you can annotate the annotation in the related mapper layer. Refer to the `TenantMapper`.
## Cache Evict
The business data updates come from the api-server, and the cache side is in the master-server. Then it is necessary to monitor the data updates from the api-server (use aspect point cut interceptor `@CacheEvict`), and notify the master-server of `cacheEvictCommand` when processing a cache eviction.
Note: the final strategy for cache update comes from the expiration strategy configuration in caffeine, therefore configure it under the business scenarios;
The sequence diagram shows below:
<img src="../../../img/cache-evict.png" alt="cache-evict" style="zoom: 67%;" />

42
docs/docs/zh/architecture/cache.md

@ -1,42 +0,0 @@
### 缓存
#### 缓存目的
由于在master-server调度过程中,会产生大量的数据库读取操作,如tenant,user,processDefinition等,一方面对DB产生很大的读压力,另一方面则会使整个核心调度流程变得缓慢;
考虑到这部分业务数据是读多写少的场景,故引入了缓存模块,以减少DB读压力,加快核心调度流程;
#### 缓存设置
```yaml
spring:
cache:
# default enable cache, you can disable by `type: none`
type: none
cache-names:
- tenant
- user
- processDefinition
- processTaskRelation
- taskDefinition
caffeine:
spec: maximumSize=100,expireAfterWrite=300s,recordStats
```
缓存模块采用[spring-cache](https://spring.io/guides/gs/caching/)机制,可直接在spring配置文件中配置是否开启缓存(默认`none`关闭), 缓存类型;
目前采用[caffeine](https://github.com/ben-manes/caffeine)进行缓存管理,可自由设置缓存相关配置,如缓存大小、过期时间等;
#### 缓存读取
缓存采用spring-cache的注解,配置在相关的mapper层,可参考如:`TenantMapper`.
#### 缓存更新
业务数据的更新来自于api-server, 而缓存端在master-server, 故需要对api-server的数据更新做监听(aspect切面拦截`@CacheEvict`),当需要进行缓存驱逐时会通知master-server,master-server接收到cacheEvictCommand后进行缓存驱逐;
需要注意的是:缓存更新的兜底策略来自于用户在caffeine中的过期策略配置,请结合业务进行配置;
时序图如下图所示:
<img src="../../../img/cache-evict.png" alt="cache-evict" style="zoom: 67%;" />

159
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/aspect/CacheEvictAspect.java

@ -1,159 +0,0 @@
/*
* 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.dolphinscheduler.api.aspect;
import org.apache.dolphinscheduler.common.enums.CacheType;
import org.apache.dolphinscheduler.common.model.Server;
import org.apache.dolphinscheduler.extract.base.client.SingletonJdkDynamicRpcClientProxyFactory;
import org.apache.dolphinscheduler.extract.master.IMasterCacheService;
import org.apache.dolphinscheduler.extract.master.transportor.CacheExpireRequest;
import org.apache.dolphinscheduler.registry.api.RegistryClient;
import org.apache.dolphinscheduler.registry.api.enums.RegistryNodeType;
import org.apache.dolphinscheduler.service.cache.impl.CacheKeyGenerator;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.stereotype.Component;
/**
* aspect for cache evict
*/
@Aspect
@Component
@Slf4j
public class CacheEvictAspect {
/**
* symbol of spring el
*/
private static final String EL_SYMBOL = "#";
/**
* prefix of spring el
*/
private static final String P = "p";
@Autowired
private CacheKeyGenerator cacheKeyGenerator;
@Autowired
private RegistryClient registryClient;
@Pointcut("@annotation(org.springframework.cache.annotation.CacheEvict)")
public void cacheEvictPointCut() {
// Do nothing because of it's a pointcut
}
@Around("cacheEvictPointCut()")
public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
MethodSignature sign = (MethodSignature) proceedingJoinPoint.getSignature();
Method method = sign.getMethod();
Object target = proceedingJoinPoint.getTarget();
Object[] args = proceedingJoinPoint.getArgs();
Object result = proceedingJoinPoint.proceed();
CacheConfig cacheConfig = method.getDeclaringClass().getAnnotation(CacheConfig.class);
CacheEvict cacheEvict = method.getAnnotation(CacheEvict.class);
CacheType cacheType = getCacheType(cacheConfig, cacheEvict);
if (cacheType != null) {
String cacheKey;
if (cacheEvict.key().isEmpty()) {
cacheKey = (String) cacheKeyGenerator.generate(target, method, args);
} else {
cacheKey = cacheEvict.key();
if (cacheEvict.key().contains(EL_SYMBOL)) {
cacheKey = parseKey(cacheEvict.key(), Arrays.asList(args));
}
}
if (StringUtils.isNotEmpty(cacheKey)) {
notifyMaster(cacheType, cacheKey);
}
}
return result;
}
private CacheType getCacheType(CacheConfig cacheConfig, CacheEvict cacheEvict) {
String cacheName = null;
if (cacheEvict.cacheNames().length > 0) {
cacheName = cacheEvict.cacheNames()[0];
}
if (cacheConfig.cacheNames().length > 0) {
cacheName = cacheConfig.cacheNames()[0];
}
if (cacheName == null) {
return null;
}
for (CacheType cacheType : CacheType.values()) {
if (cacheType.getCacheName().equals(cacheName)) {
return cacheType;
}
}
return null;
}
private String parseKey(String key, List<Object> paramList) {
SpelExpressionParser spelParser = new SpelExpressionParser();
EvaluationContext ctx = new StandardEvaluationContext();
for (int i = 0; i < paramList.size(); i++) {
ctx.setVariable(P + i, paramList.get(i));
}
Object obj = spelParser.parseExpression(key).getValue(ctx);
if (null == obj) {
throw new RuntimeException("parseKey error");
}
return obj.toString();
}
private void notifyMaster(CacheType cacheType, String cacheKey) {
try {
List<Server> serverList = registryClient.getServerList(RegistryNodeType.MASTER);
if (CollectionUtils.isEmpty(serverList)) {
return;
}
for (Server server : serverList) {
IMasterCacheService masterCacheService = SingletonJdkDynamicRpcClientProxyFactory
.getProxyClient(server.getHost() + ":" + server.getPort(), IMasterCacheService.class);
masterCacheService.cacheExpire(new CacheExpireRequest(cacheType, cacheKey));
}
} catch (Exception e) {
log.error("notify master error", e);
}
}
}

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java

@ -28,17 +28,12 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
/** /**
* process definition mapper interface * process definition mapper interface
*/ */
@CacheConfig(cacheNames = "processDefinition", keyGenerator = "cacheKeyGenerator")
public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> { public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
/** /**
@ -47,13 +42,11 @@ public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
* @param code code * @param code code
* @return process definition * @return process definition
*/ */
@Cacheable(sync = true)
ProcessDefinition queryByCode(@Param("code") long code); ProcessDefinition queryByCode(@Param("code") long code);
/** /**
* update * update
*/ */
@CacheEvict(key = "#p0.code")
int updateById(@Param("et") ProcessDefinition processDefinition); int updateById(@Param("et") ProcessDefinition processDefinition);
/** /**
@ -62,7 +55,6 @@ public interface ProcessDefinitionMapper extends BaseMapper<ProcessDefinition> {
* @param code code * @param code code
* @return delete result * @return delete result
*/ */
@CacheEvict
int deleteByCode(@Param("code") long code); int deleteByCode(@Param("code") long code);
/** /**

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessTaskRelationMapper.java

@ -25,17 +25,12 @@ import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
/** /**
* process task relation mapper interface * process task relation mapper interface
*/ */
@CacheConfig(cacheNames = "processTaskRelation", keyGenerator = "cacheKeyGenerator")
public interface ProcessTaskRelationMapper extends BaseMapper<ProcessTaskRelation> { public interface ProcessTaskRelationMapper extends BaseMapper<ProcessTaskRelation> {
/** /**
@ -44,13 +39,11 @@ public interface ProcessTaskRelationMapper extends BaseMapper<ProcessTaskRelatio
* @param processCode processCode * @param processCode processCode
* @return ProcessTaskRelation list * @return ProcessTaskRelation list
*/ */
@Cacheable(unless = "#result == null || #result.size() == 0")
List<ProcessTaskRelation> queryByProcessCode(@Param("processCode") long processCode); List<ProcessTaskRelation> queryByProcessCode(@Param("processCode") long processCode);
/** /**
* update * update
*/ */
@CacheEvict(key = "#p0.projectCode + '_' + #p0.processDefinitionCode")
int updateById(@Param("et") ProcessTaskRelation processTaskRelation); int updateById(@Param("et") ProcessTaskRelation processTaskRelation);
/** /**
@ -60,7 +53,6 @@ public interface ProcessTaskRelationMapper extends BaseMapper<ProcessTaskRelatio
* @param processCode processCode * @param processCode processCode
* @return int * @return int
*/ */
@CacheEvict
int deleteByCode(@Param("projectCode") long projectCode, @Param("processCode") long processCode); int deleteByCode(@Param("projectCode") long projectCode, @Param("processCode") long processCode);
/** /**

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.java

@ -23,23 +23,16 @@ import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
/** /**
* scheduler mapper interface * scheduler mapper interface
*/ */
@CacheConfig(cacheNames = "schedule", keyGenerator = "cacheKeyGenerator")
public interface ScheduleMapper extends BaseMapper<Schedule> { public interface ScheduleMapper extends BaseMapper<Schedule> {
@CacheEvict(key = "#p0.processDefinitionCode")
int insert(Schedule entity); int insert(Schedule entity);
@CacheEvict(key = "#p0.processDefinitionCode")
int updateById(@Param("et") Schedule entity); int updateById(@Param("et") Schedule entity);
/** /**
@ -48,7 +41,6 @@ public interface ScheduleMapper extends BaseMapper<Schedule> {
* @param processDefinitionCode processDefinitionCode * @param processDefinitionCode processDefinitionCode
* @return schedule list * @return schedule list
*/ */
@Cacheable(sync = true)
List<Schedule> queryReleaseSchedulerListByProcessDefinitionCode(@Param("processDefinitionCode") long processDefinitionCode); List<Schedule> queryReleaseSchedulerListByProcessDefinitionCode(@Param("processDefinitionCode") long processDefinitionCode);
/** /**

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TaskDefinitionLogMapper.java

@ -26,10 +26,6 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -37,7 +33,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/** /**
* task definition log mapper interface * task definition log mapper interface
*/ */
@CacheConfig(cacheNames = "taskDefinition", keyGenerator = "cacheKeyGenerator")
public interface TaskDefinitionLogMapper extends BaseMapper<TaskDefinitionLog> { public interface TaskDefinitionLogMapper extends BaseMapper<TaskDefinitionLog> {
/** /**
@ -47,13 +42,11 @@ public interface TaskDefinitionLogMapper extends BaseMapper<TaskDefinitionLog> {
* @param version version * @param version version
* @return task definition log * @return task definition log
*/ */
@Cacheable(sync = true)
TaskDefinitionLog queryByDefinitionCodeAndVersion(@Param("code") long code, @Param("version") int version); TaskDefinitionLog queryByDefinitionCodeAndVersion(@Param("code") long code, @Param("version") int version);
/** /**
* update * update
*/ */
@CacheEvict(key = "#p0.code + '_' + #p0.version")
int updateById(@Param("et") TaskDefinitionLog taskDefinitionLog); int updateById(@Param("et") TaskDefinitionLog taskDefinitionLog);
/** /**
@ -63,7 +56,6 @@ public interface TaskDefinitionLogMapper extends BaseMapper<TaskDefinitionLog> {
* @param version task definition version * @param version task definition version
* @return delete result * @return delete result
*/ */
@CacheEvict
int deleteByCodeAndVersion(@Param("code") long code, @Param("version") int version); int deleteByCodeAndVersion(@Param("code") long code, @Param("version") int version);
/** /**

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/TenantMapper.java

@ -23,10 +23,6 @@ import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -34,7 +30,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/** /**
* tenant mapper interface * tenant mapper interface
*/ */
@CacheConfig(cacheNames = "tenant", keyGenerator = "cacheKeyGenerator")
public interface TenantMapper extends BaseMapper<Tenant> { public interface TenantMapper extends BaseMapper<Tenant> {
/** /**
@ -43,19 +38,16 @@ public interface TenantMapper extends BaseMapper<Tenant> {
* @param tenantId tenantId * @param tenantId tenantId
* @return tenant * @return tenant
*/ */
@Cacheable(sync = true)
Tenant queryById(@Param("tenantId") int tenantId); Tenant queryById(@Param("tenantId") int tenantId);
/** /**
* delete by id * delete by id
*/ */
@CacheEvict
int deleteById(int id); int deleteById(int id);
/** /**
* update * update
*/ */
@CacheEvict(key = "#p0.id")
int updateById(@Param("et") Tenant tenant); int updateById(@Param("et") Tenant tenant);
/** /**

8
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/UserMapper.java

@ -25,10 +25,6 @@ import org.apache.ibatis.annotations.Param;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -36,25 +32,21 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/** /**
* user mapper interface * user mapper interface
*/ */
@CacheConfig(cacheNames = "user", keyGenerator = "cacheKeyGenerator")
public interface UserMapper extends BaseMapper<User> { public interface UserMapper extends BaseMapper<User> {
/** /**
* select by user id * select by user id
*/ */
@Cacheable(sync = true)
User selectById(int id); User selectById(int id);
/** /**
* delete by id * delete by id
*/ */
@CacheEvict
int deleteById(int id); int deleteById(int id);
/** /**
* update * update
*/ */
@CacheEvict(key = "#p0.id")
int updateById(@Param("et") User user); int updateById(@Param("et") User user);
/** /**

11
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/WorkerGroupMapper.java

@ -17,24 +17,17 @@
package org.apache.dolphinscheduler.dao.mapper; package org.apache.dolphinscheduler.dao.mapper;
import static org.apache.dolphinscheduler.common.constants.Constants.CACHE_KEY_VALUE_ALL;
import org.apache.dolphinscheduler.dao.entity.WorkerGroup; import org.apache.dolphinscheduler.dao.entity.WorkerGroup;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/** /**
* worker group mapper interface * worker group mapper interface
*/ */
@CacheConfig(cacheNames = "workerGroup", keyGenerator = "cacheKeyGenerator")
public interface WorkerGroupMapper extends BaseMapper<WorkerGroup> { public interface WorkerGroupMapper extends BaseMapper<WorkerGroup> {
/** /**
@ -42,16 +35,12 @@ public interface WorkerGroupMapper extends BaseMapper<WorkerGroup> {
* *
* @return worker group list * @return worker group list
*/ */
@Cacheable(sync = true, key = CACHE_KEY_VALUE_ALL)
List<WorkerGroup> queryAllWorkerGroup(); List<WorkerGroup> queryAllWorkerGroup();
@CacheEvict(key = CACHE_KEY_VALUE_ALL)
int deleteById(Integer id); int deleteById(Integer id);
@CacheEvict(key = CACHE_KEY_VALUE_ALL)
int insert(WorkerGroup entity); int insert(WorkerGroup entity);
@CacheEvict(key = CACHE_KEY_VALUE_ALL)
int updateById(@Param("et") WorkerGroup entity); int updateById(@Param("et") WorkerGroup entity);
/** /**

30
dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/IMasterCacheService.java

@ -1,30 +0,0 @@
/*
* 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.dolphinscheduler.extract.master;
import org.apache.dolphinscheduler.extract.base.RpcMethod;
import org.apache.dolphinscheduler.extract.base.RpcService;
import org.apache.dolphinscheduler.extract.master.transportor.CacheExpireRequest;
@RpcService
public interface IMasterCacheService {
@RpcMethod
void cacheExpire(CacheExpireRequest cacheExpireRequest);
}

34
dolphinscheduler-extract/dolphinscheduler-extract-master/src/main/java/org/apache/dolphinscheduler/extract/master/transportor/CacheExpireRequest.java

@ -1,34 +0,0 @@
/*
* 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.dolphinscheduler.extract.master.transportor;
import org.apache.dolphinscheduler.common.enums.CacheType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CacheExpireRequest {
private CacheType cacheType;
private String cacheKey;
}

52
dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/rpc/MasterCacheServiceImpl.java

@ -1,52 +0,0 @@
/*
* 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.dolphinscheduler.server.master.rpc;
import org.apache.dolphinscheduler.common.enums.CacheType;
import org.apache.dolphinscheduler.extract.master.IMasterCacheService;
import org.apache.dolphinscheduler.extract.master.transportor.CacheExpireRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class MasterCacheServiceImpl implements IMasterCacheService {
@Autowired
private CacheManager cacheManager;
@Override
public void cacheExpire(CacheExpireRequest cacheExpireRequest) {
if (cacheExpireRequest.getCacheKey().isEmpty()) {
return;
}
CacheType cacheType = cacheExpireRequest.getCacheType();
Cache cache = cacheManager.getCache(cacheType.getCacheName());
if (cache != null) {
cache.evict(cacheExpireRequest.getCacheKey());
log.info("cache evict, type:{}, key:{}", cacheType.getCacheName(), cacheExpireRequest.getCacheKey());
}
}
}
Loading…
Cancel
Save