transaction meaning

经典文章:https://blog.csdn.net/popvip44/article/details/71487425

Definition - What does Transaction mean?

A transaction, in the context of a database, is a logical unit that is independently executed for data retrieval or updates. In relational databases, database transactions must be atomic, consistent, isolated and durable–summarized as the ACID acronym.

Transactions are completed by COMMIT or ROLLBACK SQL statements.

which indicate a transaction’s beginning or end.
The ACID acronym defines the properties of a database transaction, as follows:

  1. Atomicity: A transaction must be fully complete, saved (committed) or completely undone (rolled back). A sale in a retail store database illustrates a scenario which explains atomicity, e.g., the sale consists of an inventory reduction and a record of incoming cash. Both either happen together or do not happen - it’s all or nothing.

  2. Consistency: The transaction must be fully compliant with the state of the database as it was prior to the transaction. In other words, the transaction cannot break the database’s constraints. For example, if a database table’s Phone Number column can only contain numerals, then consistency dictates that any transaction attempting to enter an alphabetical letter may not commit.

Isolation: Transaction data must not be available to other transactions until the original transaction is committed or rolled back.

Durability: Transaction data changes must be available, even in the event of database failure.

评论要点:
金融类应用非常适用,尤其是要求超高并发的。

不过实际环境下这类应用又要求安全可靠性,所以一般要配合多种数据存储方式。

Mongodb碎片、依赖内存,所以如果出现某些特殊意外可能会出现数据遗失;

关系型数据库虽然具备事务处理,可靠程度高,但性能不占优。
1楼:
例如一个金融股票系统,用mysql存储历史数据,Mongodb临时存储当天分时数据,加快读写。晚上收盘后再把Mongodb数据整理写入mysql。

适合:
楼2: 某种数据提取十分频繁,你又不想在oracle里面join来join去浪费处理时间,然后你就存在mongodb里面把以前在oracle中要join的几个列存成一个列合并在一个列上然后查的时候直接查一个列出来 说白了就是节约时间:eg :{name:leilei,warehouse:beijing, order:23} ,比如这三个字段以前分散在oracle的好几个表里面你要取得时候要join,现在你发现这个信息用户访问十分频繁你存的时候就存着三个j在mongo里面,这样就不用去oracle里join拿了而且又没有事务又没有锁理论上相对快

3楼:不过说白了,其实关系型数据库够用了,那些使用nosql的个人以为没必要。获取他们设计的程序有问题或许不会调优数据库 导致性能低下所以要尝尝新玩意吧

8楼: 适合树型数据,比如无限分类,网易评论盖楼,多级权限 这种用传统关联表做的话要么递归查询,要么要写很多额外的代码, 用mogodb只要拼字符串把键名拼对了就可以了

15楼: 存日志之类的,比方osc的动态,把各类动态组装好直接存,以后就可以直接读出来解析

classic review:

The purpose of a transaction is to make sure that the whole database stays consistent while multiple operations take place. But in contrary to most relational databases, MongoDB isn’t designed to run on a single host. It is designed to be set up as a cluster of multiple shards where each shard is a replica-sets of multiple servers (optionally at different geographical locations).

A transaction can potentially affect lots of hosts of the database. That means that the transaction would have to be synchronized between all of these hosts. This would mean quite a lot of overhead and would scale very badly when increasing the size of the database by adding more servers.

MongoDB does not have support for traditional locking or complex transactions with rollback. MongoDB aims to be lightweight, fast, and predictable in its performance. This is similar to the MySQL MyISAM autocommit model. By keeping transaction support extremely simple, MongoDB can provide greater performance especially for partitioned or replicated systems with a number of database server processes.

CAP定理
维基百科,自由的百科全书
跳到导航跳到搜索
在理论计算机科学中,CAP定理(CAP theorem),又被称作布鲁尔定理(Brewer’s theorem),它指出对于一个分布式计算系统来说,不可能同时满足以下三点:[1][2]

一致性(Consistency) (等同于所有节点访问同一份最新的数据副本)
可用性(Availability)(每次请求都能获取到非错的响应——但是不保证获取的数据为最新数据)
分区容错性(Partition tolerance)(以实际效果而言,分区相当于对通信的时限要求。系统如果不能在时限内达成数据一致性,就意味着发生了分区的情况,必须就当前操作在C和A之间做出选择[3]。)

分布式系统只能满足三项中的两项而不可能满足全部三项[4]。理解CAP理论的最简单方式是想象两个节点分处分区两侧。允许至少一个节点更新状态会导致数据不一致,即丧失了C性质。如果为了保证数据一致性,将分区一侧的节点设置为不可用,那么又丧失了A性质。除非两个节点可以互相通信,才能既保证C又保证A,这又会导致丧失P性质。