-
Notifications
You must be signed in to change notification settings - Fork 2
[FEAT]: 부하테스트 중 동시성 문제 발생하여 분산락 설정 추가, Feign Client 삭제 #83
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
Open
asd42270
wants to merge
1
commit into
Codeterian:dev
Choose a base branch
from
asd42270:56-feat-대기열-시스템-구현
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "56-feat-\uB300\uAE30\uC5F4-\uC2DC\uC2A4\uD15C-\uAD6C\uD604"
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../src/main/java/com/codeterian/queue/infrastructure/redisson/aspect/AopForTransaction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.codeterian.queue.infrastructure.redisson.aspect; | ||
|
|
||
| import org.aspectj.lang.ProceedingJoinPoint; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Propagation; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Component | ||
| public class AopForTransaction { | ||
|
|
||
| /** | ||
| 부모 트랜잭션에 관계없이 별도의 트랜잭션으로 동작하도록 설정하여 반드시 트랜잭션 커밋 이후 | ||
| 락이 해제되도록 REQUIRES_NEW 옵션 부여 | ||
| */ | ||
| @Transactional(propagation = Propagation.REQUIRES_NEW) | ||
| public Object proceed(final ProceedingJoinPoint joinPoint) throws Throwable { | ||
| return joinPoint.proceed(); | ||
| } | ||
|
|
||
| } |
25 changes: 25 additions & 0 deletions
25
...c/main/java/com/codeterian/queue/infrastructure/redisson/aspect/CustomSpringELParser.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package com.codeterian.queue.infrastructure.redisson.aspect; | ||
|
|
||
| import org.springframework.expression.ExpressionParser; | ||
| import org.springframework.expression.spel.standard.SpelExpressionParser; | ||
| import org.springframework.expression.spel.support.StandardEvaluationContext; | ||
|
|
||
| /** | ||
| * CustomSpringELParser 는 전달받은 락의 이름을 Spring Expression Language 로 파싱하여 읽어옵니다. | ||
| */ | ||
| public class CustomSpringELParser { | ||
|
|
||
| private CustomSpringELParser(){} | ||
|
|
||
| public static Object getDynamicValue(String[] parameterNames, Object[] args, String key) { | ||
| ExpressionParser parser = new SpelExpressionParser(); | ||
| StandardEvaluationContext context = new StandardEvaluationContext(); | ||
|
|
||
| for (int i = 0; i < parameterNames.length; i++) { | ||
| context.setVariable(parameterNames[i], args[i]); | ||
| } | ||
|
|
||
| return parser.parseExpression(key).getValue(context, Object.class); | ||
| } | ||
|
|
||
| } |
54 changes: 54 additions & 0 deletions
54
.../src/main/java/com/codeterian/queue/infrastructure/redisson/aspect/DistributeLockAop.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package com.codeterian.queue.infrastructure.redisson.aspect; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| 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.reflect.MethodSignature; | ||
| import org.redisson.api.RLock; | ||
| import org.redisson.api.RedissonClient; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.lang.reflect.Method; | ||
|
|
||
| @Aspect | ||
| @Component | ||
| @Slf4j | ||
| @RequiredArgsConstructor | ||
| public class DistributeLockAop { | ||
|
|
||
| private static final String REDISSON_LOCK_PREFIX = "LOCK: "; | ||
|
|
||
| private final RedissonClient redissonClient; | ||
| private final AopForTransaction aopForTransaction; | ||
|
|
||
| @Around("@annotation(com.codeterian.queue.infrastructure.redisson.aspect.DistributedLock)") | ||
| public Object redissonLock(ProceedingJoinPoint joinPoint) { | ||
| MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | ||
| Method method = signature.getMethod(); | ||
| DistributedLock distributedLock = method.getAnnotation(DistributedLock.class); | ||
|
|
||
| String key = REDISSON_LOCK_PREFIX + CustomSpringELParser.getDynamicValue(signature.getParameterNames(), joinPoint.getArgs(), distributedLock.key()); | ||
| RLock rLock = redissonClient.getLock(key); | ||
|
|
||
| try { | ||
| boolean lockable = rLock.tryLock(distributedLock.waitTime(), distributedLock.leaseTime(), distributedLock.timeUnit()); | ||
| if (!lockable) { | ||
| log.info("Lock 획득 실패={}", key); | ||
| return false; | ||
| } | ||
|
|
||
| log.info("로직 수행"); | ||
| return aopForTransaction.proceed(joinPoint); | ||
|
|
||
| } catch (Throwable e) { | ||
| log.info("에러 발생!"); | ||
| throw new RuntimeException(e); | ||
| } finally { | ||
| rLock.unlock(); | ||
| log.info("이미 언락 상태 입니다."); | ||
| } | ||
| } | ||
|
|
||
| } |
21 changes: 21 additions & 0 deletions
21
queue/src/main/java/com/codeterian/queue/infrastructure/redisson/aspect/DistributedLock.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.codeterian.queue.infrastructure.redisson.aspect; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| @Target(ElementType.METHOD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| public @interface DistributedLock { | ||
|
|
||
| //락의 이름 | ||
| String key(); | ||
|
|
||
| //락의 시간 단위 | ||
| TimeUnit timeUnit() default TimeUnit.SECONDS; | ||
|
|
||
| long waitTime() default 5000L; // 락 획득을 시도하는 최대 시간 (ms) | ||
| long leaseTime() default 3000L; // 락을 획득한 후, 점유하는 최대 시간 (ms) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.