-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BE] replica로 업데이트 쿼리 날아가던 오류 수정 (#374)
hotfix: replica로 업데이트 쿼리 날아가던 오류 수정
- Loading branch information
Showing
2 changed files
with
9 additions
and
4 deletions.
There are no files selected for viewing
12 changes: 8 additions & 4 deletions
12
backend/src/main/java/kr/momo/config/RoutingDataSource.java
This file contains 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,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; | ||
} | ||
} |
This file contains 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