在谈论数据库系统时,事务层由什么构成? [英] What constitutes a transaction layer when talking about database systems?

查看:29
本文介绍了在谈论数据库系统时,事务层由什么构成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,LevelDB 不支持多语句事务.我在某处读到你必须在事务层"中处理那些.

For example, LevelDB doesn't support multi-statement transactions. I read somewhere that you would have to deal with those in a "transactional layer".

这一层需要做什么来向不支持事务的低级库添加事务支持?

What would this layer have to do to add transaction support to a lower-level library that doesn't support transactions?

推荐答案

鉴于您的数据库是单线程的,您可以执行以下操作:

Given your database is single threaded you can do the following:

  1. 使用 leveldb 批处理功能:不是覆盖旧密钥,而是创建一个新密钥.还要记录密钥的旧值和新值.

  1. Using leveldb batch feature: Instead of overriding old key, create a new one. Also log key's old and new value.

如果此时数据库崩溃,请查找日志记录并通过将作为事务一部分的键恢复为旧值来回滚事务.删除日志完成回滚.

If the database crash at this point, lookup the log records and rollback the transaction by restate keys that were part of the transaction to their old value. Delete the log to complete the rollback.

如果事务已提交,则删除旧键并删除日志条目以完成提交.

If the transaction is committed, delete old keys and delete log entries to complete commit.

然后你有一个使用多个版本的单线程键/值存储的事务.

Then you have a transaction for single threaded key/value store using multiple versions.

如果数据库是多线程的,则必须使用 MVCC(请参阅 Yahoo 的 Omid、PostgreSQL、Wiredtiger、bsddb...)以及诸如精确序列化快照隔离 (PSSI) 之类的东西.

If the database is multithread you have to use MVCC (see Yahoo's Omid, PostgreSQL, Wiredtiger, bsddb...) and something like Precisely Serializable Snapshot Isolation (PSSI).

这篇关于在谈论数据库系统时,事务层由什么构成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆