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

[BE] replica로 업데이트 쿼리 날아가던 오류 수정 #374

Merged
merged 1 commit into from
Sep 27, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions backend/src/main/java/kr/momo/config/RoutingDataSource.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package kr.momo.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
import org.springframework.transaction.support.TransactionSynchronizationManager;

public class RoutingDataSource extends AbstractRoutingDataSource {

private static final Logger log = LoggerFactory.getLogger(RoutingDataSource.class);

@Override
protected Object determineCurrentLookupKey() {
if (TransactionSynchronizationManager.isCurrentTransactionReadOnly()) {
return DataSourceConfig.REPLICA_SERVER;
}
return DataSourceConfig.SOURCE_SERVER;
boolean currentTransactionReadOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly();
String key = currentTransactionReadOnly ? DataSourceConfig.REPLICA_SERVER : DataSourceConfig.SOURCE_SERVER;
log.info("Activated Datasource: {}", key);
return key;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public List<String> findAll(String uuid) {
/**
* TEMP: 비밀번호 마이그레이션 이후 삭제될 메서드입니다.
*/
@Transactional
public Integer updateAllPassword() {
List<Attendee> attendees = attendeeRepository.findAll();
List<Attendee> rawAttendees = attendees.stream()
Expand Down