当前位置:网站首页>Error reporting using dynamic multiple data sources under the same transaction
Error reporting using dynamic multiple data sources under the same transaction
2022-06-21 10:47:00 【Code knower】
Due to the recent project, the database will be divided into multiple databases , From the database of Dangyi , Divide multiple databases according to business , So use dynamic routing +aop To achieve dynamic database switching , When there is an important problem , Is how to solve the problem , Like in one service Query other business databases in , modify , add to , The data source will not be switched , This problem is caused by transactions , As long as you are service Open transaction in ,service Database operations on other businesses in the only use the data source when the transaction is started , Because the data source will be cached after the transaction is started ,service The principal will fetch the data source from the cache , Therefore, the switching of other business data sources fails .
terms of settlement :
Method 1 :
Because this problem is caused by transactions , So start from the business ,spring The propagation level in the transaction annotation can solve this problem ,spring The default propagation level is required Only the current transaction will be used , So in service You have to service Make changes 、 When adding , Need to be in another service Open another new transaction to use required_new Create a new transaction , The data source will be switched , When you're going to talk to another service Start another transaction to use when querying not_supported Master service Hang the transaction in , This will switch the data source .
spring The transaction propagation level of :
REQUIRED: Support current transaction , If there is no current transaction , Just create a new transaction . This is the most common choice .
SUPPORTS: Support current transaction , If there is no current transaction , Just in a non transactional way .
MANDATORY: Support current transaction , If there is no current transaction , Throw an exception .
REQUIRES_NEW: New transaction , If there are currently transactions , Suspend current transaction .
NOT_SUPPORTED: Perform operations in a non transactional way , If there are currently transactions , Suspend the current transaction .
NEVER: To execute in a non transactional manner , If there are currently transactions , Throw an exception .
NESTED: Support current transaction , If the current transaction exists , A nested transaction is executed , If there is no current transaction , Just create a new transaction .
Method 2 :
Business moves to control layer . Do not call different data sources in one implementation method
边栏推荐
- 燎原之势 阿里云数据库“百城聚力”助中小企业数智化转型
- Optimisation des performances - compression, chargement et formatage des images
- Three elements of basic concepts and methods of machine learning
- Starting a prairie fire, Alibaba cloud database "hundred cities gather together" to help small and medium-sized enterprises' digital intelligence transformation
- Are you still using localstorage directly? The thinnest in the whole network: secondary encapsulation of local storage (including encryption, decryption and expiration processing)
- Summary of embedded development -- General Catalog
- Es composite query workload evaluation
- Ccs7.3 how to erase only part of the flash sector when burning DSP on-chip flash (two projects of on-chip flash burning of a DSP chip)
- AI越进化越跟人类大脑像!Meta找到了机器的“前额叶皮层”,AI学者和神经科学家都惊了...
- NLog自定义Target之MQTT
猜你喜欢

High concurrency - personal notes

Celsius 的暴雷,会是加密领域的“雷曼时刻”吗?

程序員新人周一優化一行代碼,周三被勸退?

DSP gossip: how to save the compiled variables on the chip when the variables are defined in the code

基因型填充前的质控条件简介

字符串

Mqtt of NLog custom target

Introduction to ground plane in unity

The more AI evolves, the more it resembles the human brain! Meta found the "prefrontal cortex" of the machine. AI scholars and neuroscientists were surprised

香农的信息论究竟牛在哪里?
随机推荐
Revenue of Fortinet will increase by 29% in 2021 founder Xieqing talks about the future of network security industry
Talk about the multimodal project of fire
Regression analysis - basic content
Positive results of enx-101 clinical 1b study published by English topics
About Alipay - my savings plan - interest rate calculation instructions
On the problem of class member variable pollution in the context of one-time concurrence
程序员新人周一优化一行代码,周三被劝退?
Les nouveaux programmeurs optimisent une ligne de code lundi et sont exhortés à se retirer mercredi?
How to be an interesting person
JWT与Session的比较
Financial institutions scramble for "digital employees"; Release of aging service evaluation framework for insurance app
Performance optimization - image compression, loading and format selection
Mythical games announced its cooperation with kakao games, a leading Korean game publisher, to promote business expansion in the Asia Pacific Region
西电AI专业排名超清北,南大蝉联全国第一 | 2022软科中国大学专业排名
What USB driver needs to know
多态&Class对象&注册工厂&反射&动态代理
leetcode-94-二叉树的中序遍历
内部类
Dapr advanced-01-debug dapr
China international e-commerce center and Analysys jointly released: the national online retail development index in the fourth quarter of 2021 increased by 0.6% year on year