当前位置:网站首页>Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis

Uncover the secrets of Huawei cloud enterprise redis issue 16: acid'true' transactions beyond open source redis

2022-06-24 23:04:00 Huawei cloud developer community

This article is shared from Huawei cloud community 《​ ​ Huawei cloud enterprise class Redis Uncover secrets 16 period : Beyond open source Redis Of ACID" really " Business ​​》, author : gaussian Redis The official blog .


In daily life shopping、 traffic 、 Mobile games are inseparable from high-frequency financial consumption 、 Virtual trading . be familiar with MySQL Readers of , You must know about database transactions (Transaction) Can handle such key scenes , Transaction not only greatly simplifies the programming model of the upper business , Bring convenience to developers , At the same time, it also makes “ transaction ” And other core businesses are correct and reliable .

Actually ,Redis There's business , But the community version is only implemented in a simple version , Unable to meet ACID requirement , Therefore, the application is limited .

This article will introduce Huawei cloud enterprise database GaussDB(for Redis)( Hereinafter referred to as Gauss Redis) The transaction function of , Different from the Community Edition , gaussian Redis Provides satisfaction ACID Enterprise level transaction features .

1. What is business ?

Imagine the following scenario :

On a dark and windy night , A deal is under way . The player B Collection succeeded , but A But I didn't get the equipment .

Okay , a PK Be unavoidable .

 Huawei cloud enterprise class Redis Uncover secrets 16 period : Beyond open source Redis Of ACID" really " Business _ACID

Players can complete the transaction with a few clicks , But inside the underlying database , But at least 4 Key operations :

 Huawei cloud enterprise class Redis Uncover secrets 16 period : Beyond open source Redis Of ACID" really " Business _ Business _02

Just imagine , As in step 4 Failure , And the previous step succeeded , There will be logical confusion , This will lead to a disastrous user experience .

How do transactions solve such scenarios ? It depends on 4 Big characteristic :

  • Atomicity (Atomicity): A set of operations is either all successful , Or it's a total failure .
  • Uniformity (Consistency): That is to meet the established constraints , Ensure that the system does not deviate from the reasonable state . for example , If A、B Each has 50 Gold coins , Then the global total should always remain 100.
  • Isolation, (Isolation): The execution of multiple transactions is isolated from each other , They don't influence each other .
  • persistence (Durability): Committing a successful transaction should result in a permanent state change , Even if the power is off , Data should not be lost .

among , Consistency is the key , And atomicity 、 Isolation, 、 Persistence is all about consistency . Of course , In order to ensure the consistency of the overall system , It also needs the joint design and implementation of the business layer , This paper does not expand in detail .

that , Open source Redis What are the problems with the transaction ,GaussDB(for Redis) What is the enterprise transaction function of ? Let's take a look at it in detail .

2. From the four characteristics Redis The business of

​2.1 Atomicity ​

Community Edition Redis

Open source Redis Transaction is a minimalist design , Rollback operation in case of transaction failure is not supported , Does not satisfy the atomicity of transactions .

In addition, there are the following questions :

  • Incomplete team check : Check only simple syntax , Can't recognize key Wrong type of ;
  • Incomplete error handling : Skip mistakes directly , Continue to execute subsequent commands .

GaussDB(for Redis)

 Huawei cloud enterprise class Redis Uncover secrets 16 period : Beyond open source Redis Of ACID" really " Business _ Business _03

As shown in the figure , Open source Redis The transaction still executes the following command when the first command is wrong , And Gauss Redis This avoids such problems .

  • Each transaction is executed in Wrong judgment will be made before submission , If there is an error, the rollback logic will be triggered , Give up the previous operation , No impact on the original data

gaussian Redis While preserving the logic used by community transactions , At the bottom of the system Roll back Support for , It satisfies the atomicity of transactions .

2.2 Isolation,

Community Edition Redis

When a transaction is executed concurrently , Various isolation issues should be addressed .

Open source Redis The execution of commands is a single threaded design , Therefore, it can be guaranteed that No two transactions will be executed at the same time , The specific term :

  • Open source Redis There is no isolation problem ;
  • The cost is the reduction of performance and the impact on the overall throughput , Transactions can only be processed in a single thread , High interference with other requests .

GaussDB(for Redis)

gaussian Redis Is a multi-threaded architecture , Automatically slice the data internally , Preserve the isolation level of serialization within the same data fragment , At the same time, it greatly improves the concurrency of the whole instance .

 Huawei cloud enterprise class Redis Uncover secrets 16 period : Beyond open source Redis Of ACID" really " Business _GaussDB(for Redis)_04

2.3 persistence

Community Edition Redis

Open source Redis It's a pure memory design , Does not provide reliable data storage capacity . Data loss after power failure , Even if it turns on RDB or AOF, It can only recover part of the data to a certain extent , The specific term :

  • RDB Some data will be lost in this way , Data can only be restored to the time of the last snapshot
  • Even if it's AOF The way , Persistence is also a problem , From command execution to saving to hard disk , There is still a time difference
  • AOF Slow recovery 、 Maintenance files are huge , The cost of maintenance and management will be very high , Reconstruction takes a long time

Taken together , Community Edition Redis The persistence ability of is limited , Not enough to support the persistence requirements of transactions .

GaussDB(for Redis)

gaussian Redis Adopt the design concept of separation of storage and calculation , The bottom layer uses high-performance distributed storage pool to save the full amount of data , combination RocksDB Storage engine , It can ensure the reliable storage of core data , Architecture diagram :

 Huawei cloud enterprise class Redis Uncover secrets 16 period : Beyond open source Redis Of ACID" really " Business _GaussDB(for Redis)_05

GaussDB(for Redis) Core strengths :

  • Core data storage : Full data down ,3 Replica redundancy , Not afraid to lose data
  • High availability : Second level fault , Even if N-1 Node failure , Full data is also available
  • Low latency : Automatic hot and cold separation , Sub millisecond delay , can Hold Caching scenarios
  • High throughput : All nodes are writable ,QPS Scalable horizontally , It can resist peak flow
  • Strong consistency :3 Replica strong consistent synchronization , No dirty reading , Business is free from stepping on the pit
  • Second expansion : for example ,8G To 64G Expansion only needs 1 second , And for business 0 influence
  • lower the cost : The greater the amount of data, the better the price , Can really help users save costs

gaussian Redis Strong persistence guarantee , Support reliable storage of core data , It also provides a strong guarantee for the execution of transactions .

2.4 Uniformity

From the database level , Database through atomicity 、 Isolation, 、 Persistence to ensure consistency , Can say in ACID Consistency is the purpose of the transaction , Other features are means .

As mentioned above , Open source Redis There are problems with atomicity and persistence , Consistency is naturally not guaranteed . Under the guarantee of the above characteristics , Whether it is normal execution or there is a command failure scenario , gaussian Redis Transactions have reliable consistency .

2.5 conclusion

Through the above introduction, we introduce Gauss in detail from the four characteristics of transactions Redis The business of , Finally, a summary :

 Huawei cloud enterprise class Redis Uncover secrets 16 period : Beyond open source Redis Of ACID" really " Business _ Open source Redis_06

3. Conclusion

In recent years , With Redis As a representative of the KV Databases are gradually playing a role in more and more scenarios , And Gauss Redis As the flagship of Huawei cloud KV database , It can meet the reliable storage requirements of enterprise core data .

gaussian Redis Compared with the community version Redis There's a big boost , stay ACID Under the blessing of affairs , More available in “ stock ”、“ transaction ” And other key scenarios to simplify business design , Bring reliable data storage capacity .

4. appendix

 ​ Click to follow , The first time to learn about Huawei's new cloud technology ~​

原网站

版权声明
本文为[Huawei cloud developer community]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211159271405.html