事务处理非常非常大的实体组

编程入门 行业动态 更新时间:2024-10-26 00:24:30
本文介绍了事务处理非常非常大的实体组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图设计一个可以容纳大量数据的数据模型,任何有大量数据经验的人都会对此有任何反馈,即:

//仅用于示例,不用于编译 public class TransactionAccount { private long balance; 私人列表<交易> transactions = new ArrayList< Transaction>(); .... public long getBalance(){return balance; } } 私人类交易{ public日期日期; 公开长期金额; $

基于我读过的内容,获取插入时事务完整性的唯一方法一个交易和更新余额就是让它成为一个实体组。

然而,随着时间的推移,对于特定的 TransactionAccount 将有数百万笔交易。写入这个实体组的次数会很少,但读取次数会更多。

我知道它可能会被分割,但是读取余额是一个非常频繁的操作,并且分解它会使得最常见的操作之一是最慢的操作 getBalance()。 >

解决方案

你所描述的安排应该可以正常工作。如果您的实体组增长过大(我们在讨论数百兆事务之前就成为问题),那么您可以编写一个过程来滚动旧的事务:事务性地用一个旧事务记录替换一组旧事务记录这些交易的总和,以保持余额等于所有交易总和的不变。如果您仍然需要存储这些旧的卷起交易记录,则可以在执行汇总之前将其复制到单独的实体组中。

I am trying to design a data model which can hold a very large amount of data, does anyone with experience in large volumes of data have any feedback on this, ie:

// example only, not meant to compile public class TransactionAccount { private long balance; private List<Transaction> transactions = new ArrayList<Transaction>(); .... public long getBalance() { return balance; } } private class Transaction { public Date date; public long amount; }

Based on what I have read, the only way to get transactional integrity on inserting a Transaction and updating balance is to make it one entity group.

However over time there would be millions of transactions for a particular TransactionAccount. The number of writes to this entity group would be low, but the reads would be much higher.

I know it could possibly be sharded, however reading the balance is a very frequent operation, and sharding it would make one of the most common operations getBalance() the slowest operation.

解决方案

The arrangement you describe should work fine. If your entity group grows excessively big (we're talking hundreds of megabytes of transactions before this becomes an issue), you could write a procedure to 'roll up' old transactions: transactionally replace a set of old transaction records with a single one for the sum of those transactions, in order to maintain the invariant that the balance is equal to the sum of all transactions. If you still need to store a record of these old, 'rolled up' transactions, you can make a copy of them in a separate entity group before you perform the roll-up.

更多推荐

事务处理非常非常大的实体组

本文发布于:2023-11-11 10:59:20,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:非常大   实体   事务处理

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!