-
Notifications
You must be signed in to change notification settings - Fork 0
[fix] 아티스트 수집 API 타임아웃·중복 요청 처리 개선 #115
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3c50043
[fix] 도커 컨테이너 타임존을 KST(Asia/Seoul)로 통일
You-Hyuk 0b45f77
[perf] concert_artist(artist_id) 단일 컬럼 인덱스 추가
You-Hyuk d921afd
[fix] WebClient에 connectTimeout/responseTimeout 명시
You-Hyuk 24d4a77
[fix] PIPELINE_TIMEOUT 예외 신설 및 DataPipelineClient 타임아웃 매핑
You-Hyuk 5e4eba3
[fix] PIPELINE_CONFLICT 응답 메시지 개선
You-Hyuk 695bcb5
[feat] 관리자 아티스트 수집 요청에 Redis mbid 단위 dedup 락 추가
You-Hyuk f8eecc7
[test] #113 신규 테스트 메서드명을 snake_case 컨벤션에 맞게 정리
You-Hyuk a5b14d4
[style] #113 신규 테스트 코드 100자 초과 라인 개행
You-Hyuk 706d6fe
[test] DataPipelineClient.collectArtist의 404/409/500 onStatus 분기 회귀 테…
You-Hyuk 265eea5
[fix] Data 검색 엔드포인트에 504 PIPELINE_TIMEOUT 응답 문서화
You-Hyuk d591c53
[fix] ArtistCollectLockRepository.unlock을 소유권 토큰 기반으로 변경
You-Hyuk 0560839
[fix] 락 해제 실패가 collectArtist의 원래 결과·예외를 가리지 않도록 방어
You-Hyuk 6f2a9bb
[fix] concert_artist(artist_id) 인덱스 생성을 CONCURRENTLY로 전환
You-Hyuk 1c6cb11
[test] CI test job에 timeout-minutes 추가, DB 커넥션에 statement_timeout 임시 주입
You-Hyuk 2cc0137
[fix] V29 마이그레이션의 CREATE INDEX CONCURRENTLY 무기한 대기에 상한 추가
You-Hyuk 67a087c
[test] CI에 pg_stat_activity/pg_locks 실시간 캡처 진단 스텝 추가
You-Hyuk aaf58d9
[fix] V29를 CREATE INDEX CONCURRENTLY에서 평범한 CREATE INDEX로 되돌림
You-Hyuk 0cc8209
[chore] 콘솔 로그 타임스탬프를 KST(Asia/Seoul)로 고정
You-Hyuk 8f1e2f2
[fix] DataPipelineClientTest의 공유 응답 타임아웃으로 인한 flaky 실패 수정
You-Hyuk 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ on: | |
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
|
|
||
| services: | ||
| postgres: | ||
|
|
||
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/Coming/Backend/admin/exception/PipelineTimeoutException.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,11 @@ | ||
| package com.Coming.Backend.admin.exception; | ||
|
|
||
| import com.Coming.Backend.common.exception.BusinessException; | ||
| import com.Coming.Backend.common.exception.ErrorCode; | ||
|
|
||
| public class PipelineTimeoutException extends BusinessException { | ||
|
|
||
| public PipelineTimeoutException() { | ||
| super(ErrorCode.PIPELINE_TIMEOUT); | ||
| } | ||
| } |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/Coming/Backend/admin/repository/ArtistCollectLockRepository.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,51 @@ | ||
| package com.Coming.Backend.admin.repository; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.springframework.data.redis.core.RedisTemplate; | ||
| import org.springframework.data.redis.core.script.DefaultRedisScript; | ||
| import org.springframework.data.redis.core.script.RedisScript; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| @Repository | ||
| public class ArtistCollectLockRepository { | ||
|
|
||
| private static final String KEY_PREFIX = "ARTIST_COLLECT_LOCK:"; | ||
| // WebClient responseTimeout(120s)보다 여유 있게 잡아, 정상 흐름에서는 항상 명시적 unlock으로 | ||
| // 해제되고 TTL은 서버 재시작 등 예외 상황의 안전망 역할만 한다. | ||
| private static final long TTL_SECONDS = 150; | ||
|
|
||
| // 저장된 토큰이 일치할 때만 삭제한다. TTL 만료 후 다른 요청이 같은 키를 선점했다면, | ||
| // 이전 보유자의 unlock이 그 새 락을 실수로 지우지 않도록 막는다. | ||
| private static final RedisScript<Long> UNLOCK_SCRIPT = new DefaultRedisScript<>( | ||
| "if redis.call('get', KEYS[1]) == ARGV[1] then " | ||
| + "return redis.call('del', KEYS[1]) " | ||
| + "else return 0 end", | ||
| Long.class); | ||
|
|
||
| private final RedisTemplate<String, String> redisTemplate; | ||
|
|
||
| public ArtistCollectLockRepository(RedisTemplate<String, String> redisTemplate) { | ||
| this.redisTemplate = redisTemplate; | ||
| } | ||
|
|
||
| /** | ||
| * mbid에 대한 락을 선점한다. | ||
| * | ||
| * @return 선점에 성공하면 이 호출을 식별하는 토큰, 이미 다른 요청이 보유 중이면 null | ||
| */ | ||
| public String tryLock(String mbid) { | ||
| String token = UUID.randomUUID().toString(); | ||
| Boolean acquired = redisTemplate.opsForValue() | ||
| .setIfAbsent(KEY_PREFIX + mbid, token, TTL_SECONDS, TimeUnit.SECONDS); | ||
| return Boolean.TRUE.equals(acquired) ? token : null; | ||
| } | ||
|
|
||
| /** | ||
| * 전달된 토큰이 현재 저장된 값과 일치할 때만 락을 해제한다. | ||
| */ | ||
| public void unlock(String mbid, String token) { | ||
| redisTemplate.execute(UNLOCK_SCRIPT, List.of(KEY_PREFIX + mbid), token); | ||
| } | ||
| } |
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
15 changes: 14 additions & 1 deletion
15
src/main/java/com/Coming/Backend/common/config/WebClientConfig.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 |
|---|---|---|
| @@ -1,14 +1,27 @@ | ||
| package com.Coming.Backend.common.config; | ||
|
|
||
| import io.netty.channel.ChannelOption; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.http.client.reactive.ReactorClientHttpConnector; | ||
| import org.springframework.web.reactive.function.client.WebClient; | ||
| import reactor.netty.http.client.HttpClient; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| @Configuration | ||
| public class WebClientConfig { | ||
|
|
||
| private static final int CONNECT_TIMEOUT_MILLIS = 5000; | ||
| private static final Duration RESPONSE_TIMEOUT = Duration.ofSeconds(120); | ||
|
|
||
| @Bean | ||
| public WebClient.Builder webClientBuilder() { | ||
| return WebClient.builder(); | ||
| HttpClient httpClient = HttpClient.create() | ||
| .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, CONNECT_TIMEOUT_MILLIS) | ||
| .responseTimeout(RESPONSE_TIMEOUT); | ||
|
|
||
| return WebClient.builder() | ||
| .clientConnector(new ReactorClientHttpConnector(httpClient)); | ||
| } | ||
| } |
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
1 change: 1 addition & 0 deletions
1
src/main/resources/db/migration/V29__add_concert_artist_artist_id_index.sql
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 @@ | ||
| CREATE INDEX idx_concert_artist_artist_id ON concert_artist (artist_id); |
Oops, something went wrong.
Oops, something went wrong.
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.