简体   繁体   English

Postgresql SERIALIZABLE 事务制作队列

[英]Postgresql SERIALIZABLE transaction make queue

I am using typeorm with database postgresql .我正在将typeorm与数据库postgresql
The specific route, needs transactions on high-load web app:具体路线,需要在高负载 web 应用程序上进行交易:

import { Router, Request, Response } from 'express';
import { getManager } from 'typeorm';

const router = Router();

router.post('/apply', async (request: Request, response: Response) => {
    await getManager().transaction('SERIALIZABLE', async (txManager) => {
        /* Many selects, inserts here */
    });
});

But if there is two simultaneous requests, the one request will errored with the message could not serialize access due to read/write dependencies among transactions .但是如果同时有两个请求,一个请求会报错, could not serialize access due to read/write dependencies among transactions

How to prevent this?如何防止这种情况? Maybe handle every request one-by one?也许一一处理每个请求? But I don't know how to do this.但我不知道如何做到这一点。 Maybe there is some other ways to do transactions, but I have read documentation and didn't find anything for this.也许还有其他一些方法可以进行交易,但我已阅读文档并没有找到任何相关信息。

使用SERIALIZABLE隔离级别,您不能防止序列化错误,但如果发生此类错误,您将重复事务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM