我可以在Tarantool中进行交易时屈服吗? [英] Can I yield during an transaction in Tarantool?

查看:75
本文介绍了我可以在Tarantool中进行交易时屈服吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对交易期间的收益感到好奇.会立即被打断吗?还是其他光纤能够读取尚未提交的更改?

I'm curious about yielding during a transaction. Will it be interrupted immediately? Or will other fibers be able to read changes that have not yet been committed?

我忽略了文档,但没有看到它.

I've overlooked the documentation but didn't see it.

推荐答案

当前,有一种在交易中产生收益的方法.这是因为现在有一个用于memtx和Vinyl引擎的全功能事务管理器.

Currently, there is a way to yield in a transaction. This is because there is now a fully functional transaction manager for both memtx and vinyl engines.

这是一个可行的示例:

local fiber = require('fiber')

-- If you just use box.cfg{}, this app will fail
box.cfg{memtx_use_mvcc_engine=true}
--box.cfg{}

box.schema.space.create('account', {if_not_exists=true})
box.space.account:format({ {name='id',type='unsigned'},
      {name='first_name',type='string'},
      {name='last_name',type='string'},
})

box.begin()
box.space.account:put({2, "John", "Doe"})

print("sleeping")
fiber.sleep(1)
print("woke up")

box.space.account:put({3, "Ivan", "Ivanov"})

box.commit()

os.exit(0)

请注意 memtx_use_mvcc_engine 选项.它启用了交易引擎.如果没有此选项,则交易内部的收益将导致立即回滚.

Note the memtx_use_mvcc_engine option. It enables the transaction engine. Without this option, a yield inside the transaction will result in immediate rollback.

新事务管理器还将在事务内部进行更改,以使其在提交之前对其他光纤和事务不可见.并且如果发生冲突(对相同数据进行并行更改),则事务将回滚.

The new transaction manager will also make changes inside the transaction to be invisible to other fibers and transactions before it is committed. And in case of conflict (parallel changes to the same data), the transaction will be rolled back.

这篇关于我可以在Tarantool中进行交易时屈服吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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