Skip to content

Commit

Permalink
fix: move distributed lock to contribution service
Browse files Browse the repository at this point in the history
  • Loading branch information
ohksj77 committed Apr 6, 2024
1 parent b8ea0ee commit bab571f
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import com.dragonguard.backend.domain.member.entity.Member;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.QueryHints;

import java.util.Optional;

import javax.persistence.LockModeType;
import javax.persistence.QueryHint;

/**
Expand All @@ -19,12 +17,10 @@
*/
public interface JpaBlockchainRepository
extends JpaRepository<Blockchain, Long>, BlockchainRepository {
@Lock(LockModeType.PESSIMISTIC_READ)
@QueryHints({@QueryHint(name = "javax.persistence.lock.timeout", value = "3000")})
Optional<Blockchain> findByMemberAndContributeType(
final Member member, final ContributeType contributeType);

@Lock(LockModeType.PESSIMISTIC_READ)
@QueryHints({@QueryHint(name = "javax.persistence.lock.timeout", value = "3000")})
Optional<Blockchain> findById(final Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface JpaGitOrganizationRepository
"SELECT DISTINCT go FROM GitOrganization go JOIN FETCH go.gitOrganizationMembers gom JOIN FETCH gom.member m WHERE m = :member")
List<GitOrganization> findAllByMember(final Member member);

@Lock(LockModeType.PESSIMISTIC_WRITE)
@Lock(LockModeType.PESSIMISTIC_READ)
@QueryHints({@QueryHint(name = "javax.persistence.lock.timeout", value = "1500")})
boolean existsByName(final String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.dragonguard.backend.domain.member.dto.client.MemberClientRequest;
import com.dragonguard.backend.domain.member.dto.client.MemberCodeReviewResponse;
import com.dragonguard.backend.global.annotation.DistributedLock;
import com.dragonguard.backend.global.exception.WebClientException;
import com.dragonguard.backend.global.template.client.GithubClient;

Expand All @@ -28,7 +27,6 @@ public class MemberCodeReviewClient
private final WebClient webClient;

@Override
@DistributedLock(name = "#request.getGithubId().concat('memberCodeReviewClient')")
public MemberCodeReviewResponse requestToGithub(final MemberClientRequest request) {
return webClient
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import com.dragonguard.backend.domain.member.dto.client.MemberClientRequest;
import com.dragonguard.backend.domain.member.dto.client.MemberCommitResponse;
import com.dragonguard.backend.global.annotation.DistributedLock;
import com.dragonguard.backend.global.exception.WebClientException;
import com.dragonguard.backend.global.template.client.GithubClient;
import java.nio.charset.StandardCharsets;

import lombok.RequiredArgsConstructor;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;

import java.nio.charset.StandardCharsets;

/**
* @author 김승진
* @description WebClient로 멤버의 커밋을 가져오는 클라이언트
Expand All @@ -23,7 +25,6 @@ public class MemberCommitClient implements GithubClient<MemberClientRequest, Mem
private final WebClient webClient;

@Override
@DistributedLock(name = "#request.getGithubId().concat('memberCommitClient')")
public MemberCommitResponse requestToGithub(final MemberClientRequest request) {
return webClient
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.dragonguard.backend.domain.member.dto.client.MemberClientRequest;
import com.dragonguard.backend.domain.member.dto.client.MemberIssueResponse;
import com.dragonguard.backend.global.annotation.DistributedLock;
import com.dragonguard.backend.global.exception.WebClientException;
import com.dragonguard.backend.global.template.client.GithubClient;

Expand All @@ -27,7 +26,6 @@ public class MemberIssueClient implements GithubClient<MemberClientRequest, Memb
private final WebClient webClient;

@Override
@DistributedLock(name = "#request.getGithubId().concat('memberIssueClient')")
public MemberIssueResponse requestToGithub(final MemberClientRequest request) {
return webClient
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.dragonguard.backend.domain.member.dto.client.MemberClientRequest;
import com.dragonguard.backend.domain.member.dto.client.MemberPullRequestResponse;
import com.dragonguard.backend.global.annotation.DistributedLock;
import com.dragonguard.backend.global.exception.WebClientException;
import com.dragonguard.backend.global.template.client.GithubClient;

Expand All @@ -28,7 +27,6 @@ public class MemberPullRequestClient
private final WebClient webClient;

@Override
@DistributedLock(name = "#request.getGithubId().concat('memberPullRequestClient')")
public MemberPullRequestResponse requestToGithub(final MemberClientRequest request) {
return webClient
.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.dragonguard.backend.domain.blockchain.entity.ContributeType;
import com.dragonguard.backend.domain.blockchain.service.BlockchainService;
import com.dragonguard.backend.domain.member.entity.Member;
import com.dragonguard.backend.global.annotation.DistributedLock;
import com.dragonguard.backend.global.exception.EntityNotFoundException;
import com.dragonguard.backend.global.template.entity.Contribution;
import com.dragonguard.backend.global.template.kafka.KafkaProducer;
Expand All @@ -26,6 +27,7 @@ public abstract class ContributionService<T extends Contribution, ID>
private final KafkaProducer<BlockchainKafkaRequest> blockchainKafkaProducer;
private final BlockchainService blockchainService;

@DistributedLock(name = "#member.getGithubId().concat(#contributeType.name())")
public void saveContribution(
final Member member,
final Integer contributionNum,
Expand Down

0 comments on commit bab571f

Please sign in to comment.