事务处理非常非常大的实体组 [英] Transactions over very very large entity group

查看:180
本文介绍了事务处理非常非常大的实体组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设计一个可以容纳大量数据的数据模型,任何有大量数据经验的人都会对此有任何反馈,即:

  //仅用于示例,不用于编译
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.

这篇关于事务处理非常非常大的实体组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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