π₯ λ§μ£ΌμΉ μ΄μ
- λͺ©ν: μ¬λ¬ μ¬μ©μκ° λμμ ν¬μΈνΈλ₯Ό μ‘κΈν λ λ°μ΄ν° μ ν©μ±μ μ μ§νλ λ‘μ§μ ꡬννκ³ , λ°λλ½ λ°μ μ¬λΆλ₯Ό νμΈ
π§ͺ μνν ν μ€νΈ
- ν
μ€νΈ μλ리μ€
- νλμ μ‘μ κ³μ’(sender)μμ μμ κ³μ’(receiver)λ‘ 50 ν¬μΈνΈμ© μ‘κΈ
- μ΄ 10κ°μ μ°λ λκ° λμμ μ‘κΈ μμ²μ μ€ν
- κ° μ°λ λλ PointService.transferPoints() λ©μλλ₯Ό νΈμΆ
- ν΅μ¬ ν
μ€νΈ μ½λ
ν
μ€νΈ λ‘κ·Έ
2025-04-05T16:38:42.166+09:00 WARN 15836 --- [point-service] [pool-2-thread-9] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1213, SQLState: 40001
2025-04-05T16:38:42.166+09:00 WARN 15836 --- [point-service] [pool-2-thread-5] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1213, SQLState: 40001
2025-04-05T16:38:42.166+09:00 ERROR 15836 --- [point-service] [pool-2-thread-9] o.h.engine.jdbc.spi.SqlExceptionHelper : Deadlock found when trying to get lock; try restarting transaction
2025-04-05T16:38:42.166+09:00 ERROR 15836 --- [point-service] [pool-2-thread-5] o.h.engine.jdbc.spi.SqlExceptionHelper : Deadlock found when trying to get lock; try restarting transaction
2025-04-05T16:38:42.166+09:00 WARN 15836 --- [point-service] [pool-2-thread-3] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1213, SQLState: 40001
2025-04-05T16:38:42.167+09:00 WARN 15836 --- [point-service] [pool-2-thread-7] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1213, SQLState: 40001
2025-04-05T16:38:42.166+09:00 WARN 15836 --- [point-service] [pool-2-thread-4] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1213, SQLState: 40001
2025-04-05T16:38:42.166+09:00 WARN 15836 --- [point-service] [pool-2-thread-6] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1213, SQLState: 40001
2025-04-05T16:38:42.167+09:00 ERROR 15836 --- [point-service] [pool-2-thread-3] o.h.engine.jdbc.spi.SqlExceptionHelper : Deadlock found when trying to get lock; try restarting transaction
2025-04-05T16:38:42.166+09:00 WARN 15836 --- [point-service] [ool-2-thread-10] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1213, SQLState: 40001
2025-04-05T16:38:42.167+09:00 ERROR 15836 --- [point-service] [ool-2-thread-10] o.h.engine.jdbc.spi.SqlExceptionHelper : Deadlock found when trying to get lock; try restarting transaction
2025-04-05T16:38:42.166+09:00 WARN 15836 --- [point-service] [pool-2-thread-2] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1213, SQLState: 40001
2025-04-05T16:38:42.167+09:00 ERROR 15836 --- [point-service] [pool-2-thread-2] o.h.engine.jdbc.spi.SqlExceptionHelper : Deadlock found when trying to get lock; try restarting transaction
2025-04-05T16:38:42.166+09:00 WARN 15836 --- [point-service] [pool-2-thread-8] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1213, SQLState: 40001
2025-04-05T16:38:42.168+09:00 ERROR 15836 --- [point-service] [pool-2-thread-8] o.h.engine.jdbc.spi.SqlExceptionHelper : Deadlock found when trying to get lock; try restarting transaction
2025-04-05T16:38:42.167+09:00 ERROR 15836 --- [point-service] [pool-2-thread-7] o.h.engine.jdbc.spi.SqlExceptionHelper : Deadlock found when trying to get lock; try restarting transaction
2025-04-05T16:38:42.167+09:00 ERROR 15836 --- [point-service] [pool-2-thread-4] o.h.engine.jdbc.spi.SqlExceptionHelper : Deadlock found when trying to get lock; try restarting transaction
2025-04-05T16:38:42.167+09:00 ERROR 15836 --- [point-service] [pool-2-thread-6] o.h.engine.jdbc.spi.SqlExceptionHelper : Deadlock found when trying to get lock; try restarting transaction
μλ¬ λ°μ: could not execute statement [Deadlock found when trying to get lock; try restarting transaction] [update point_accounts set total_points=?,user_id=? where account_id=?]; SQL [update point_accounts set total_points=?,user_id=? where account_id=?]
μλ¬ λ°μ: could not execute statement [Deadlock found when trying to get lock; try restarting transaction] [update point_accounts set total_points=?,user_id=? where account_id=?]; SQL [update point_accounts set total_points=?,user_id=? where account_id=?]
μλ¬ λ°μ: could not execute statement [Deadlock found when trying to get lock; try restarting transaction] [update point_accounts set total_points=?,user_id=? where account_id=?]; SQL [update point_accounts set total_points=?,user_id=? where account_id=?]
μλ¬ λ°μ: could not execute statement [Deadlock found when trying to get lock; try restarting transaction] [update point_accounts set total_points=?,user_id=? where account_id=?]; SQL [update point_accounts set total_points=?,user_id=? where account_id=?]
μλ¬ λ°μ: could not execute statement [Deadlock found when trying to get lock; try restarting transaction] [update point_accounts set total_points=?,user_id=? where account_id=?]; SQL [update point_accounts set total_points=?,user_id=? where account_id=?]
μλ¬ λ°μ: could not execute statement [Deadlock found when trying to get lock; try restarting transaction] [update point_accounts set total_points=?,user_id=? where account_id=?]; SQL [update point_accounts set total_points=?,user_id=? where account_id=?]
μλ¬ λ°μ: could not execute statement [Deadlock found when trying to get lock; try restarting transaction] [update point_accounts set total_points=?,user_id=? where account_id=?]; SQL [update point_accounts set total_points=?,user_id=? where account_id=?]
μλ¬ λ°μ: could not execute statement [Deadlock found when trying to get lock; try restarting transaction] [update point_accounts set total_points=?,user_id=? where account_id=?]; SQL [update point_accounts set total_points=?,user_id=? where account_id=?]
μλ¬ λ°μ: could not execute statement [Deadlock found when trying to get lock; try restarting transaction] [update point_accounts set total_points=?,user_id=? where account_id=?]; SQL [update point_accounts set total_points=?,user_id=? where account_id=?]
Sender μμ‘: 950
Receiver μμ‘: 50
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
2025-04-05T16:38:42.229+09:00 INFO 15836 --- [point-service] [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2025-04-05T16:38:42.232+09:00 INFO 15836 --- [point-service] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2025-04-05T16:38:42.306+09:00 INFO 15836 --- [point-service] [ionShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
> Task :test
BUILD SUCCESSFUL in 6s
4 actionable tasks: 1 executed, 3 up-to-date
μ€ν 4:38:42: Execution finished ':test --tests "com.timebank.pointservice.service.PointServiceTest.λμμ±_ν
μ€νΈ_μ‘κΈ_μΆ©λ"'.
π¨ λ°μν λ¬Έμ : λ°λλ½(Deadlock)
- μλ¬ λ‘κ·Έ μμ½:
-
pgsql볡μ¬νΈμ§SQL Error: 1213, SQLState: 40001 Deadlock found when trying to get lock; try restarting transaction
- μμΈ λΆμ:
- μ¬λ¬ νΈλμμ μ΄ λμμ λμΌν μ‘μ κ³μ’ rowμ λν΄ updateλ₯Ό μλνλ©° κ΅μ°© μν λ°μ
- JPAκ° μλμΌλ‘ μ²λ¦¬νλ SQL update 쿼리μμ λ½ μΆ©λ λ°μ
π§© ν΄κ²° μ κ·Ό λ°©μ
- λ¬Έμ μΈμ:
- λ¨μν λμ νΈμΆμ΄ μλλΌ λμΌ μμμ λν κ²½μ μ κ·Όμ΄ μμΈμμ νμ
- λμ λ°©λ²:
β 1. λΉκ΄μ λ½ + νΈλμμ μ²λ¦¬ (μλΉμ€ λ΄λΆ)
π‘ μ΄λ€ μν©μ μ 리ν΄?
- λμΌν λ°μ΄ν°λ₯Ό λμμ μμ νλ €λ κ²½μ° (ex. ν¬μΈνΈ μ°¨κ°, μκ³ κ°μ λ±)
- μ€μκ° μ ν©μ±μ΄ μμ£Ό μ€μν κ²½μ°
πͺ μ₯μ :
- μΆ©λ μ¦μ μ°¨λ¨ (λ½μ κ±Έμ΄μ λ€λ₯Έ νΈλμμ μ κ·Ό λ§μ)
- λ°μ΄ν° μ ν©μ± λ§€μ° λμ
β οΈ μ£Όμμ :
- λμμ λ€μ΄μ€λ νΈλν½μ΄ λ§μΌλ©΄ λ½ λκΈ° μκ°μ΄ λμ΄λ μ±λ₯ μ ν μ°λ € → κ·Έλμ CQRS + λ©μμ§ ν μ‘°ν©κ³Ό κ°μ΄ μ¨μ€μΌ ν¨.
β 2. Redis λΆμ° λ½ or λ©μμ§ ν (μλΉμ€ κ° μ²λ¦¬)
π‘ μ΄λ€ μν©μ μ 리ν΄?
- μ¬λ¬ μλΉμ€κ° λμμ λμΌ λ¦¬μμ€λ₯Ό μ²λ¦¬ν μ μμ΄μ μμ 보μ₯, μ€λ³΅ λ°©μ§κ° νμν λ
- MSA νκ²½μμ λΉλκΈ° μ‘μμ ν λ (μ: Kafka μ΄λ²€νΈ μλΉ)
πͺ μ₯μ :
- λ©μμ§ ν(Kafka λ±)λ μμ 보μ₯, μ¬μλ, μ₯μ λμ κ°λ₯
- Redis λΆμ° λ½μ κ°λ¨ν μμ°¨ μ μ΄μ©μΌλ‘ λΉ λ₯΄κ³ μ μ©
β οΈ μ£Όμμ :
- Redis λ½μ λ€νΈμν¬ μ₯μ /λ§λ£ λ± μ£μ§ μΌμ΄μ€ μ£Όμ
- Kafka λ± λ©μμ§ νλ μ μ ν consumer μ²λ¦¬ μλμ μ€νμ κ΄λ¦¬ νμ
β 3. μ‘°νλ CQRSλ‘ λΆλ¦¬ (Command/Query λΆλ¦¬)
π‘ μ΄λ€ μν©μ μ 리ν΄?
- νΈλν½μ λλΆλΆμ΄ μ‘°ν μ€μ¬μΌ λ
- μ ν©μ±λ³΄λ€ μλ΅ μλκ° μ€μν νλ©΄ (μ: λ§μ΄νμ΄μ§, λμ보λ λ±)
πͺ μ₯μ :
- μ‘°ν 쿼리λ₯Ό λ³λ DB/Redis μΊμλ‘ λΆλ¦¬νλ©΄ λ©μΈ νΈλμμ μ λΆλ΄ X
- μ½κΈ° μ μ© DBλ Read Replication μ¬μ©νλ©΄ νμ₯μ±λ π
π‘ κ²°λ‘ : μ΄ κ΅¬μ‘°λ λκ·λͺ¨ μλΉμ€μμ μ€μ λ‘ λ§μ΄ μ°μ΄λ ν¨ν΄
- μΉ΄μΉ΄μ€, λ°°λ―Ό, ν μ€, μΏ ν‘ λ±λ μ΄λ° λ°©μμΌλ‘ λ΄λΆ μ ν©μ± + μΈλΆ μ΄λ²€νΈ μ²λ¦¬ + μ‘°ν μ΅μ νλ₯Ό μ‘°ν©ν΄μ μ¬μ©ν΄.
- μ§κΈμ²λΌ MSA + Kafka + DB κΈ°λ° κ΅¬μ‘°μμλ μ΄ μ μ μ‘°ν©μ΄ νμ€μ μΈ λ² μ€νΈ νλν°μ€λΌκ³ 보면 λΌ.
'TIL' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
λ½ μμ κ³ μ (0) | 2025.04.06 |
---|---|
λΉκ΄μ λ½(Pessimistic Lock) λμ (0) | 2025.04.05 |
RabbitMQ κΈ°λ° λΉλκΈ° μν€ν μ² λμ μ±λ₯ κ°μ μ¬λ‘ (0) | 2025.04.02 |
μΊμ±μ ν΅ν μ±λ₯ κ°μ (0) | 2025.04.01 |
QueryDSLμ νμ©ν λμ 쿼리 μ΅μ ν (0) | 2025.03.31 |