WO2016019803A1 - Data processing method, apparatus and system based on distributed memories and databases - Google Patents

Data processing method, apparatus and system based on distributed memories and databases Download PDF

Info

Publication number
WO2016019803A1
WO2016019803A1 PCT/CN2015/084883 CN2015084883W WO2016019803A1 WO 2016019803 A1 WO2016019803 A1 WO 2016019803A1 CN 2015084883 W CN2015084883 W CN 2015084883W WO 2016019803 A1 WO2016019803 A1 WO 2016019803A1
Authority
WO
WIPO (PCT)
Prior art keywords
budget
memory
quota
current
database
Prior art date
Application number
PCT/CN2015/084883
Other languages
French (fr)
Chinese (zh)
Inventor
刘晟东
Original Assignee
阿里巴巴集团控股有限公司
刘晟东
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 阿里巴巴集团控股有限公司, 刘晟东 filed Critical 阿里巴巴集团控股有限公司
Publication of WO2016019803A1 publication Critical patent/WO2016019803A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F12/00Accessing, addressing or allocating within memory systems or architectures
    • G06F12/02Addressing or allocation; Relocation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor

Definitions

  • the present application relates to the field of the Internet, and in particular, to a data processing method, apparatus, and system based on a distributed memory and a database DB.
  • the database uses the database DB (Database) to store and process the budget data
  • the first method is: storing a budget data through a record of a DB, each When deducting the budget data, it can be performed in the same transaction through the DB SQL statement. This method is called single DB mode.
  • the second way is to split the budget data into different DBs of different servers, and load deduction requests can be balanced to different DBs each time the budget data needs to be deducted.
  • a budget of 1000 is stored by 10 records distributed in 10 DBs, each of which records 100; and a deduction of 3 is routed to one of 10 DBs (for example, the second).
  • the budget balance of the second DB becomes 97, and the budget balance of the nine records of the remaining nine DBs is still 100.
  • the inventors have found that the prior art has the following problems: For the data processing method of the first single DB: since the read and write needs to access the DB, the performance of the DB is high, especially the disk which uses the disk as the storage medium. Disk read and write performance is relatively low, so this approach can not meet the needs of high concurrent data processing requests.
  • multi-DB distributed data processing method multi-DB distributed data processing method is solved by increasing the number of DBs. The problem of too low DB performance can meet high concurrency requirements, but the need to use a large number of DBs leads to excessive cost.
  • the present application provides a data processing method based on distributed memory and a database, which is used to solve the problem that the data processing in a prior art is performed by using a single DB for data processing.
  • the problem of high concurrent requests also solves the problem of excessive cost caused by using a large number of DBs, thereby reducing the cost and meeting the actual demand of high concurrent requests. Further, data consistency can be ensured even in the event of a server downtime.
  • the present application also provides a data processing apparatus and system based on distributed memory and database to ensure the implementation and application of the above method in practice.
  • the present application discloses a data processing method based on distributed memory and a database, the method comprising:
  • the data processing request includes: a budget identifier of the current budget data and a budget quota;
  • the present application provides a data compensation method based on distributed memory and a database, the method comprising: a data processing process and a data compensation process;
  • the data processing process includes:
  • the data processing request includes: current Budget identification and budget quota for budget data;
  • the data compensation process includes:
  • a record storing the difference is updated in the target database.
  • the application also provides a data processing device based on a distributed memory and a database, the device comprising:
  • a receiving request unit configured to receive a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota;
  • a first determining unit configured to determine, according to the budget identifier, whether a memory quota in a current memory segment storing the current budget data is greater than the budget quota
  • a first deducting unit configured to deduct the memory quota directly in the current memory segment if the result of the first determining unit is YES;
  • a second determining unit configured to determine, according to the budget identifier, whether a sum of a current database remaining amount and the memory amount stored in the current memory segment is greater than The budget amount
  • a second deduction unit configured to: when the result of the second judging module is yes, The current database remaining amount and the memory quota are deducted from the budget amount;
  • the storage deduction recording unit is configured to store the deduction record of the deduction of the budget quota into the current database, where the current database and the current memory segment correspond to budget data of the same budget identifier.
  • the present application also provides a data processing system, the system comprising: a data processing device and a data compensation device, wherein the data processing device comprises:
  • a receiving request unit configured to receive a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota;
  • a first determining unit configured to determine, according to the budget identifier, whether a memory quota in a current memory segment storing the current budget data is greater than the budget quota
  • a first deducting unit configured to deduct the memory quota directly in the current memory segment if the result of the first determining unit is YES;
  • a second determining unit configured to determine, according to the budget identifier, whether a sum of a current database remaining amount and the memory amount stored in the current memory segment is greater than The budget amount
  • a second deducting unit configured to deduct the budget quota according to the current database remaining amount and the memory quota if the result of the second judging module is YES;
  • a storage deduction record unit configured to store the deduction record deducting the budget amount into the current database, where the current database and the current memory segment correspond to budget data of the same budget identifier;
  • the data compensation device includes:
  • a determining unit configured to determine a target database to be processed according to the budget identifier to be synchronized
  • Obtaining a record unit configured to obtain, from the target database, all the deduction records and transfer records corresponding to the budget identifier, where the transfer record indicates that the quota is transferred from the database to the record with the memory segment;
  • a sixth determining unit configured to determine whether the transfer total value represented by the all transfer records is greater than a deduction total value represented by the deduction record
  • a storage compensation amount unit configured to store, as a database compensation amount, a difference between the transfer total value and the deducted total value in a case where the result of the sixth determining unit is YES Stored in the target database;
  • an update unit configured to update the record storing the difference in the target database.
  • the present application includes the following advantages:
  • the number of accesses to the DB can be greatly reduced, and because the performance of the memory is relatively high relative to the DB, on the one hand, the access to the memory can be utilized to improve the data processing performance, and on the other hand, the number of accesses of the DB can be reduced. This reduces the impact of the DB on data processing requests. Therefore, the distributed memory and the distributed DB adopted by the embodiments of the present application can improve data processing performance, meet high concurrent requests, and save the number of DBs, thereby saving costs.
  • the beneficial effect of the application is that: in the case that the operation of deducting the budget quota is successful, the user may be notified that the budget amount deduction is successful, and otherwise the user budget credit deduction is failed. Therefore, the deduction result is fed back to the user in real time, so that the user can understand the deduction of the budget amount.
  • the beneficial effects of the present application are also that it is convenient to directly inform the user that the quota is insufficient when the total amount of the memory balance and the DB quota is insufficient, so that the access to the DB can be reduced.
  • the utility model also has the beneficial effects of: greatly improving the speed of recovering data in the memory segment after the server is down.
  • FIG. 1 is a flow chart of an embodiment of a distributed memory and database based data processing method of the present application
  • FIG. 2 is a schematic structural diagram of an application scenario of an embodiment of the present application.
  • FIG. 3 is a flow chart of loading a balance from a DB into a memory slice in the embodiment of the present application
  • FIG. 5 is a flow chart of an embodiment of a data compensation method based on distributed memory and database of the present application
  • FIG. 6 is a structural block diagram of an embodiment of a distributed memory and database based data processing apparatus of the present application.
  • FIG. 7 is a schematic diagram of a frame of each unit in the implementation DB of the application for loading a balance to a memory slice;
  • FIG. 8 is a schematic diagram of a frame of each unit for performing split storage of a budget identifier according to an implementation of the present application.
  • FIG. 9 is a schematic diagram of a framework of a distributed memory and database based data processing system of the present application.
  • Distributed memory is a data storage space that stores data on separate memory slices. Each memory slice can be distributed on one server, and the distributed memory data storage mode formed by multiple memory slices on multiple servers can expand the storage space and improve the data storage performance.
  • the budget data is represented by the budget identifier and the budget quota, where the budget identifier is used to uniquely represent a budget data, for example, The only number indicates the quantity of a product being sold, or is used to uniquely indicate an amount specifically for a certain deduction.
  • the budget amount indicates the quantity or amount. For example, the budget with a budget identifier of A001 is 100w.
  • the storage form of the budget data in the first memory fragment can be as shown in Table 1:
  • Table 1 shows that the budget data with the budget identifier A001-A100 is saved in the first memory segment, wherein each budget data corresponds to the DB balance and the memory balance, and the sum of the two is the current budget data. Total amount.
  • the version number can be used to indicate the update of the current budget data. According to the way that each memory segment saves 100 budget data, then 5 memory segments can save the budget data of A001-A500.
  • the distributed DB there are 5 DBs corresponding to each other, and the first DB corresponding to the first memory fragment also corresponds to the budget data of A001-A100.
  • the deduction details of the budget data are also stored in the DB.
  • FIG. 1 a flowchart of an embodiment of a data processing method based on a distributed memory and a database is shown in the present application.
  • the embodiment may include the following steps:
  • Step 101 Receive a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota.
  • FIG. 2 is a schematic structural diagram of an application scenario according to an embodiment of the present application.
  • the application is applied to the memory storage system 202.
  • the data processing request includes a budget identifier and a budget quota of the current budget data
  • the budget routing control system may locate a memory segment that saves the budget data of the budget identifier according to the budget identifier, thereby The budget amount requested by the user is deducted in the memory slice.
  • Step 102 Determine, according to the budget identifier, a current memory that stores the current budget data. Whether the amount of memory in the slice is greater than the budget amount, if yes, proceed to step 103, and if no, proceed to step 104.
  • the memory quota is stored in the memory segment, it is determined whether the memory amount in the current memory segment storing the current budget data is greater than the budget amount. For example, if the budget identifier is A002 and the budget quota is 9w, the corresponding budget data is stored in the first memory fragment, and it is determined whether the budget amount 9w requested by the user is less than or equal to the memory quota of 10w.
  • Step 103 Deduct the memory quota from the current quota in the current memory segment, and proceed to step 106.
  • the memory quota is greater than the budget quota
  • the budget data stored in the memory segment is sufficient to respond to the current data processing request. In this case, the memory quota is directly deducted in the current memory segment. You can reduce the budget amount by 9w.
  • Step 104 Determine, according to the budget identifier, whether the sum of the current DB quota and the memory quota stored in the current memory fragment is greater than the budget quota, and if yes, proceed to step 105.
  • the sum of the current DB quota and the memory credit of the budget data stored in the current memory fragment needs to be used.
  • the sum of the current DB quota and the memory credit is greater than the budget quota, the sum of the memory fragment and the DB amount is sufficient to respond to the current data processing request.
  • Step 105 Deduct the budget quota according to the current DB remaining credit and the memory credit.
  • the current DB amount and the memory quota are simultaneously referred to to deduct the budget amount.
  • the memory quota is 10w
  • the budget quota is 11w
  • the DB balance has 20w
  • the budget quota can be deducted according to the current DB quota and memory quota.
  • step 105 may specifically include:
  • Step A1 Obtain a difference between the budget amount and the memory quota.
  • Step A2 Deduct the credit difference from the current DB quota, and store the deducted credit difference into the current memory fragment.
  • the deducted 1w is stored in the current memory slice.
  • 11w of the memory quota is stored in the memory slice.
  • Step A3 Deduct the memory quota after storing the credit difference in the current memory segment.
  • the 11w budget amount can be deducted from the current memory segment.
  • Step 106 Store the deduction record of the deduction of the budget quota into the current DB, where the current DB and the current memory segment correspond to budget data of the same budget identifier.
  • the record of the deduction budget amount is stored in the current DB, so that it is convenient to use the deduction record saved in the DB in the case of data loss in the memory. Restore balance data.
  • the first is to determine whether the memory balance is sufficient from the memory fragment, and if the memory balance is sufficient, the DB does not need to be accessed directly. Deduct the memory balance from the memory slice, even if the memory balance in the memory slice is not enough, you only need to deduct the part of the DB that is not enough. Therefore, compared with the prior art, the number of accesses to the DB can be greatly reduced, and because the performance of the memory is relatively high relative to the DB, on the one hand, the access to the memory can be utilized to improve the data processing performance, and on the other hand, the DB is reduced. The number of visits thus reduces the impact of the DB on data processing requests. Therefore, the distributed memory and the distributed DB adopted by the embodiments of the present application can improve data processing performance, meet high concurrent requests, and save the number of DBs, thereby saving costs.
  • the method may further include:
  • Step 108 Determine whether the operation of deducting the budget quota is successful. If yes, notify the user that the budget credit deduction is successful, and if not, notify the user that the budget credit deduction fails.
  • the user may be notified that the budget amount deduction is successful, and otherwise the user budget quota deduction is stopped. Therefore, the deduction result is fed back to the user in real time, so that the user can understand the deduction of the budget amount.
  • the process of loading a balance from a DB to a memory slice in the embodiment of the present application may specifically include:
  • Step 301 Obtain a partial quota of a preset proportion of the budget total amount corresponding to the budget identifier as the memory quota.
  • a ratio may be set in advance, and a part of the total budget corresponding to the ratio may be loaded from the DB into the memory each time. For example, for the budget data with the budget identifier A002, the preset ratio is one tenth. If the total amount of the budget data is 100w, then the partial quota corresponding to the preset ratio is 10w.
  • Step 302 Transfer the memory quota from the current DB to the current memory segment corresponding to the budget identifier, where the current memory segment corresponds to a plurality of memory quotas that have preset multiple budget identifiers.
  • the current DB stores a plurality of DB quotas in addition to the memory quota in the budget totality of the plurality of budget identifiers.
  • one memory segment may have multiple budget data identified by multiple budgets and multiple memory quotas of the plurality of budget data, and one DB may also store correspondences of budget totals of multiple budget identifiers except memory quotas. Multiple DB quotas.
  • Step 303 Store the transfer record of transferring the memory quota to the current DB.
  • the above 10w transfer record is stored in the current DB.
  • the DB balance is also stored in the memory segment, so that it is convenient to directly inform the user that the quota is insufficient when the total amount of the memory balance and the DB quota is insufficient, thereby reducing access to the DB.
  • the embodiment of the present application may further include:
  • Step B Determine whether the current quota of the DB corresponding to the memory segment is zero. If not, store a partial quota of the preset proportion of the current quota of the DB to the memory segment.
  • the DB layer balance is not zero, it is assumed to be 100w.
  • the amount of the part to be loaded into the memory fragment needs to be determined according to the preset ratio.
  • the part of the amount that needs to be preloaded into the memory slice is 10w.
  • the total budget balance of the DB is 0, and the status of the budget data for the budget is incomplete (the budget data of each budget identifier can be set correspondingly, after the budget data is completely processed) If you can change its status to complete, it means that the budget data has been processed completely, and all the deduction records and transfer records in the DB will be scanned. However, since the probability of this happening is very low, it can increase the efficiency by at least 1000% compared to the full load mode. For example, in the case of loading 10% of the balance into memory each time, for a budgeted budget data, only 10% of the probability is that the DB balance is zero.
  • the embodiment adopts the method of loading only a partial balance of the preset proportion into the memory segment at a time, which can greatly improve the speed of recovering data in the memory segment after the server is down.
  • the embodiment of the present application stores the budget data in the memory fragment according to the budget identifier, which can solve the problem of insufficient memory of the single machine.
  • the process of splitting and storing the budget identifier in the case that the single-machine memory fragmentation is insufficient may include:
  • Step 401 Determine whether the machine where the memory fragment is located satisfies the response of the data processing request initiated by the plurality of budget identifiers saved by the memory fragment, and if no, proceed to step 402.
  • the current memory fragment may not be enough to withstand this large amount. Data processing request. If the result of the judgment is yes, no processing is performed.
  • Step 402 Divide the plurality of budget identifiers into multiple copies according to the preset splitting rules, and save one of the split budget identifiers to the current memory segment, and save the other budget identifiers correspondingly. To multiple other memory slices.
  • A001-A100 into A001-A050 and A051-A100 respectively, store the budget data with budget as A001-A050 to the first memory segment, and add a memory slice to store A051-A100. Budget data.
  • Step 403 Divide the plurality of budget identifiers in the current DB corresponding to the current memory fragment into multiple shares in the same manner, and retain one of the split multiple budget identifiers in the current DB, and other budget identifiers. Then save to multiple other DBs.
  • the current DB also stores the DB quota in addition to the memory quota in the budget data of the A001-A100, it is also necessary to store the budget data of the A001-A050 to the first DB and add a DB according to the method of step 402. Used to store budget data for the A051-A100.
  • the problem of insufficient memory of the single machine can be solved, and the memory layer and the DB layer can be continuously expanded by increasing the memory and the DB as the amount of access increases.
  • FIG. 5 there is shown a flowchart of an embodiment of a data compensation method based on distributed memory and database, which may include: a data processing process and a data compensation process, wherein the data processing
  • the process can be referred to FIG. 1, and the data compensation process can include the following steps:
  • Step 501 Determine a target DB to be processed according to the budget identifier to be synchronized.
  • the DB storing the budget data of A005 is the target DB to be processed.
  • Step 502 Obtain all deduction records and transfer records corresponding to the budget identifier from the target DB, where the transfer record indicates that the quota is transferred from the DB to the record with the memory segment.
  • All deduction records and transfer records corresponding to A005 are obtained from the target DB, wherein the deduction record indicates a deduction of the budget data, and the transfer record indicates that the quota is transferred from the DB to the details of the memory fragment.
  • Step 503 Determine whether the transfer total value represented by the all transfer records is greater than the deduction total value indicated by the deduction record, and if yes, proceed to step 504.
  • the transfer record it is possible to calculate how much the total amount of transfer from the target DB to the memory slice, and according to the deduction record, it is also possible to calculate how much the deduction is in the memory segment, and determine whether the transfer total value is greater than the deduction total. value.
  • Step 504 Store the difference between the transfer total value and the deducted total value as a DB compensation amount into the target DB.
  • the transfer total value is greater than the deducted total value, indicating that there is still remaining balance, the budget data corresponding to the budget identifier is still valid, and the state of the budget data is also incomplete, then the total value of the transfer and the total amount of the deduction are transferred.
  • the difference of the degree values is stored as a DB compensation amount in the target DB.
  • Step 505 Update the record storing the difference value in the target DB.
  • the record storing the difference is stored in the target DB.
  • the consistency can be achieved through the above-described process of balance compensation, thereby avoiding the situation in which the calculation of the balance of the budget data is incorrect.
  • the memory balance in the memory segment is sufficient in the actual application, it will be deducted from the memory segment and stored in the DB storage debit record, and the DB layer is needed if the memory segment of the memory segment is insufficient.
  • Loading the DB balance to the memory slice and also deducting the record in the DB store so even if the balance data saved in the memory slice is inconsistent with the DB, the memory is deducted, then the balance compensation can be performed through the asynchronous task described above, thereby Ultimately achieve consistency.
  • the process shown in FIG. 5 can be performed by a background asynchronous thread without being triggered by other services or users, thereby exerting less pressure on the DB.
  • the method may further include:
  • Step 506 Read the DB compensation amount from the record of the stored difference value.
  • Step 507 Send the DB compensation quota to the target memory fragment corresponding to the target DB, so that the target memory fragment updates the storage DB remaining credit according to the DB compensation quota.
  • the DB compensation amount is notified to the corresponding memory segment by idempotent, and the target memory segment updates the DB remaining quota stored by itself according to the DB compensation amount.
  • the compensation amount is notified to the memory by asynchronous + and idempotent, and can further reduce the access to the DB, and at the same time, the final consistency of the balance data in the memory and the DB can be achieved.
  • the present application further provides an embodiment of a data processing device based on a distributed memory and a database.
  • the device can include:
  • the receiving request unit 601 is configured to receive a data processing request triggered by the user, where the data processing request includes: a budget identifier of the current budget data and a budget quota.
  • the first determining unit 602 is configured to determine, according to the budget identifier, whether a memory quota in a current memory segment storing the current budget data is greater than the budget quota.
  • the first deduction unit 603 is configured to deduct the memory quota directly from the current memory segment in the current memory segment if the result of the first determining unit is YES.
  • the second determining unit 604 is configured to determine, according to the budget identifier, whether the sum of the current DB remaining amount and the memory quota stored in the current memory segment is determined according to the budget identifier. Greater than the budget amount.
  • the second deduction unit 605 is configured to deduct the budget quota according to the current DB remaining credit and the memory quota if the result of the second judging module is YES.
  • the second deduction unit 605 may include: an obtaining module, configured to acquire a quota difference between the budget quota and the memory quota; and a first deduction module, configured to deduct from the current DB remaining credit a storage module for storing the deducted credit difference into the current memory segment; and a second deduction module for storing the credit in the current memory segment The difference in memory credit deducts the budget amount.
  • the store deduction record unit 606 is configured to store the deduction record of the deduction of the budget amount into the current DB, where the current DB and the current memory segment correspond to budget data of the same budget identifier.
  • the embodiment of the present application can greatly reduce the number of accesses to the DB, and because the performance of the memory is relatively high relative to the DB, on the one hand, the access to the memory can be utilized to improve the data processing performance, and on the other hand, the number of accesses of the DB can be reduced. Reduce the impact of DB on data processing requests. Therefore, the distributed memory and the distributed DB adopted by the embodiments of the present application can improve data processing performance, meet high concurrent requests, and save the number of DBs, thereby saving costs.
  • a schematic diagram of a framework for implementing a unit for loading a balance into a memory slice in a DB may include:
  • the obtaining quota unit 701 is configured to obtain a partial quota of a preset proportion of the budget total amount corresponding to the budget identifier as the memory quota.
  • the transferring unit 702 is configured to transfer the memory quota from the current DB to the current memory fragment corresponding to the budget identifier, where the current memory fragment corresponds to multiple presets that store a plurality of preset budget identifiers. a memory quota, where the current DB stores a plurality of DB quotas in addition to the memory quota in the budget totality of the plurality of budget identifiers.
  • the storage transfer recording unit 703 is configured to store the transfer record that transfers the memory quota to the current DB.
  • the DB balance is also stored in the memory segment, so that it is convenient to directly inform the user that the quota is insufficient when the total amount of the memory balance and the DB quota is insufficient, thereby reducing the DB access.
  • a schematic diagram of a frame of each unit for performing split storage on a budget identifier may include:
  • the third determining unit 801 is configured to determine whether the machine where the memory fragment is located satisfies a response to a data processing request initiated by the plurality of budget identifiers saved by the memory fragment.
  • the memory splitting unit 802 is configured to divide the plurality of budget identifiers into multiple copies according to a preset splitting rule if the result of the third determining unit is negative.
  • the memory saving unit 803 is configured to save one copy of the split budget identifiers to the current memory fragment, and save the other budget identifiers to the plurality of other memory fragments.
  • the DB splitting unit 804 divides the plurality of budget identifiers in the current DB corresponding to the current memory slice into a plurality of shares in the same manner.
  • the DB saving unit 805 is configured to reserve one of the split budget identifiers in the current DB, and save the other budget identifiers in multiple other DBs.
  • the problem of insufficient memory of the single machine can be solved, and the memory layer and the DB layer can be continuously expanded by increasing the memory and the DB as the number of accesses increases.
  • the system may include: a data processing device 90 and a data compensation device 91, wherein the data processing device 90 may specifically include: receiving a requesting unit, configured to receive a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota; the first determining unit is configured to determine, according to the budget identifier, the current budget Whether the memory quota in the current memory segment of the data is greater than the budget quota; the first deduction unit is configured to directly in the current memory segment if the result of the first determining unit is YES The second amount determining unit is configured to determine, according to the budget identifier, a current DB stored in the current memory segment, if the result of the first determining unit is negative Whether the sum of the remaining credit and the memory credit is greater than the budget quota; the second deducting unit is used in the second judging module Fruit is And deduct
  • the data compensation device 91 may specifically include:
  • the determining unit 911 is configured to determine a target DB to be processed according to the budget identifier to be synchronized.
  • the obtaining record unit 912 is configured to obtain, from the target DB, all the deduction records and the transfer records corresponding to the budget identifier, wherein the transfer records indicate that the quota is transferred from the DB to the record with the memory segment.
  • the sixth determining unit 913 is configured to determine whether the transfer total value represented by the all transfer records is greater than the deduction total value indicated by the deduction record.
  • a storage compensation amount unit 914 configured to store, when the result of the sixth determining unit is YES, a difference between the transfer totality value and the deducted total value as a DB compensation amount to the target DB.
  • the updating unit 915 is configured to update the record storing the difference value in the target DB.
  • the consistency of the above balance compensation process can be used to achieve consistency, thereby avoiding the calculation of the balance of the budget data. Since the actual application first deducts from the memory fragment, the memory layer is not enough to deduct the DB layer balance, so even if the balance data stored in the memory fragment is inconsistent with the DB, it is more memory. If the deduction is made, the balance compensation can be performed through the asynchronous task described above, thereby achieving consistency.
  • the data compensation device may further include:
  • the read credit unit 916 is configured to read the DB compensation amount from the record of the stored difference value.
  • the sending unit 917 is configured to send the DB compensation quota to the target memory fragment corresponding to the target DB, so that the target memory fragment updates the storage DB remaining credit according to the DB compensation quota.
  • This embodiment can further reduce the access to the DB, and at the same time, the final consistency of the balance data in the memory and the DB can be achieved.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present application provides a data processing method, apparatus and system based on distributed memories and databases. The method comprises: receiving a data processing request triggered by a user; determining, according to a budget identifier, whether a memory quota in a current memory fragment storing current budget data is greater than a budget quota; if yes, directly deducting the budget quota from the memory quota in the current memory fragment; if not, determining, according to the budget identifier, whether the sum of a remaining quota of a current database (DB) and the memory quota that are stored in the current memory fragment is greater than the budget quota; if yes, deducting the budget quota according to the remaining quota of the current DB and the memory quota; and storing a deduction record of deducting the budget quota in the current DB. By means of embodiments of the present application, data processing performance can be improved to satisfy highly concurrent requests, and the number of DBs can be reduced to save costs.

Description

基于分布式内存和数据库的数据处理方法、装置和***Data processing method, device and system based on distributed memory and database 技术领域Technical field
本申请涉及互联网领域,特别涉及一种基于分布式内存和数据库DB的数据处理方法、装置和***。The present application relates to the field of the Internet, and in particular, to a data processing method, apparatus, and system based on a distributed memory and a database DB.
背景技术Background technique
在互联网越来越发达的现在,越来越多的用户借助于互联网处理数据,例如,企业报表或者word文档等。再例如,也有很多用户通过服务器来对一些数据进行存储、管理或者更新等。如果数据量大,可以将数据存储到多个服务器的数据库中。例如,在电子商务中,假设对于在售产品的数量,其总量为100,那么如果每次对总量扣减1的话,在扣减100次之后,总量为零,将不再允许对该在售产品的数量的扣减。其中,在售产品的总量叫做“预算”。Now that the Internet is becoming more and more developed, more and more users are using the Internet to process data, such as corporate reports or word documents. For another example, there are many users who store, manage, or update some data through the server. If the amount of data is large, you can store the data in a database of multiple servers. For example, in e-commerce, assuming that the total amount of products sold is 100, then if the total amount is deducted by 1 each time, after deducting 100 times, the total amount is zero, and the pair will no longer be allowed. The deduction of the quantity of the product being sold. Among them, the total amount of products sold is called “budget”.
在现有技术中,服务器在采用数据库DB(Database)来存储预算数据并对其进行处理时,一般分为两种方式,第一种方式为:通过一个DB的一条记录来存放预算数据,每次对该预算数据进行扣减时可以通过DB的SQL语句在同一个事务中进行,这种方式称为单DB方式。第二种方式为:将预算数据拆分到不同服务器的不同的DB中,每次对预算数据需要扣减时可以将扣减请求负载均衡到不同的DB上。例如,数量为1000的预算数据由分布在10个DB的10条记录存放,每条记录100;而一次数量为3的扣减操作会被路由到10个DB的其中一个(例如第二个)上,扣减后,第二个DB的预算余额变为97,剩余的9个DB中的9条记录的预算余额仍为100。In the prior art, when the database uses the database DB (Database) to store and process the budget data, it is generally divided into two ways. The first method is: storing a budget data through a record of a DB, each When deducting the budget data, it can be performed in the same transaction through the DB SQL statement. This method is called single DB mode. The second way is to split the budget data into different DBs of different servers, and load deduction requests can be balanced to different DBs each time the budget data needs to be deducted. For example, a budget of 1000 is stored by 10 records distributed in 10 DBs, each of which records 100; and a deduction of 3 is routed to one of 10 DBs (for example, the second). Onwards, after the deduction, the budget balance of the second DB becomes 97, and the budget balance of the nine records of the remaining nine DBs is still 100.
但是发明人发现现有技术存在以下问题:对于第一种单个DB的数据处理方式来说:由于读写都需要访问DB,所以对DB性能要求较高,特别是以磁盘作为存储介质的DB,而磁盘的读写性能相对较低,因此这种方式不能满足高并发的数据处理请求的需求。对于第二种多DB的分布式数据处理方式来说:多DB的分布式数据处理方式通过增加DB的数量解决了 单DB性能过低的问题,可以满足高并发需求,但是需要使用大量的DB,就造成成本过高的现象。However, the inventors have found that the prior art has the following problems: For the data processing method of the first single DB: since the read and write needs to access the DB, the performance of the DB is high, especially the disk which uses the disk as the storage medium. Disk read and write performance is relatively low, so this approach can not meet the needs of high concurrent data processing requests. For the second multi-DB distributed data processing method: multi-DB distributed data processing method is solved by increasing the number of DBs. The problem of too low DB performance can meet high concurrency requirements, but the need to use a large number of DBs leads to excessive cost.
发明内容Summary of the invention
基于发明人发现的目前数据处理中存在的问题,本申请提供一种基于分布式内存和数据库的数据处理方法,用以解决现有技术中进行数据处理时采用单个DB进行数据处理导致的不能满足高并发请求的问题,同时也解决了采用大量的DB导致的成本过高的问题,从而在降低成本的同时,满足高并发请求的实际需求。进一步的,还能在服务器发生宕机的情况下,也能保证数据的一致性。Based on the problems existing in the current data processing discovered by the inventors, the present application provides a data processing method based on distributed memory and a database, which is used to solve the problem that the data processing in a prior art is performed by using a single DB for data processing. The problem of high concurrent requests also solves the problem of excessive cost caused by using a large number of DBs, thereby reducing the cost and meeting the actual demand of high concurrent requests. Further, data consistency can be ensured even in the event of a server downtime.
本申请还提供了基于分布式内存和数据库的数据处理装置及***,用以保证上述方法在实际中的实现及应用。The present application also provides a data processing apparatus and system based on distributed memory and database to ensure the implementation and application of the above method in practice.
为了解决上述问题,本申请公开了一种基于分布式内存和数据库的数据处理方法,该方法包括:In order to solve the above problems, the present application discloses a data processing method based on distributed memory and a database, the method comprising:
接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前预算数据的预算标识和预算额度;Receiving a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota;
依据所述预算标识判断存储所述当前预算数据的当前内存分片中的内存额度是否大于所述预算额度,如果是,则直接在所述当前内存分片中将所述内存额度扣减所述预算额度;Determining, according to the budget identifier, whether a memory credit in a current memory segment storing the current budget data is greater than the budget quota, and if so, directly deducting the memory credit in the current memory segment Budget amount;
如果否,则依据所述预算标识判断所述当前内存分片中存储的当前数据库剩余额度和所述内存额度之和是否大于所述预算额度,如果是,则依据所述当前数据库剩余额度和内存额度扣减所述预算额度;If yes, determining, according to the budget identifier, whether a sum of a current database remaining amount and the memory quota stored in the current memory segment is greater than the budget quota, and if so, according to the current database remaining credit and memory The amount of the budget is deducted;
将所述扣减所述预算额度的扣减记录存储至所述当前数据库中,所述当前数据库与所述当前内存分片对应保存相同预算标识的预算数据。And deducting the deduction record of the budget amount into the current database, where the current database and the current memory segment correspond to budget data of the same budget identifier.
本申请提供一种基于分布式内存和数据库的数据补偿方法,该方法包括:数据处理过程和数据补偿过程;The present application provides a data compensation method based on distributed memory and a database, the method comprising: a data processing process and a data compensation process;
其中,所述数据处理过程包括:The data processing process includes:
接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前 预算数据的预算标识和预算额度;Receiving a data processing request triggered by a user, wherein the data processing request includes: current Budget identification and budget quota for budget data;
依据所述预算标识判断存储所述当前预算数据的当前内存分片中的内存额度是否大于所述预算额度,如果是,则直接在所述当前内存分片中将所述内存额度扣减所述预算额度;Determining, according to the budget identifier, whether a memory credit in a current memory segment storing the current budget data is greater than the budget quota, and if so, directly deducting the memory credit in the current memory segment Budget amount;
如果否,则依据所述预算标识判断存储所述当前内存分片中存储的当前数据库剩余额度和所述内存额度之和是否大于所述预算额度,如果是,则从所述当前数据库剩余额度和内存额度中扣减所述预算额度;If not, determining, according to the budget identifier, whether the sum of the current database remaining amount and the memory quota stored in the current memory fragment is greater than the budget quota, and if so, from the current database remaining credit and Deducting the budget amount from the memory quota;
将所述扣减所述预算额度的记录存储至所述当前数据库中,所述当前数据库与所述当前内存分片对应保存相同预算标识的预算数据;And storing, in the current database, the record of the deduction of the budget quota, where the current database and the current memory segment correspond to budget data of the same budget identifier;
其中,所述数据补偿过程包括:The data compensation process includes:
依据待同步的预算标识确定待处理的目标数据库;Determining a target database to be processed according to the budget identifier to be synchronized;
从所述目标数据库中获取该预算标识对应的所有扣减记录和转移记录,其中,所述转移记录表示将额度从数据库转移至与内存分片的记录;Obtaining, from the target database, all the deduction records and the transfer records corresponding to the budget identifier, wherein the transfer records indicate that the quota is transferred from the database to the records with the memory fragments;
判断所述所有转移记录所表示的转移总额度值是否大于所述扣减记录所表示的扣减总额度值,如果是,则将所述转移总额度值与所述扣减总额度值的差值作为数据库补偿额度存储至所述目标数据库中;Determining whether the transfer total value represented by the all transfer records is greater than a deduction total value indicated by the deduction record, and if yes, comparing the difference between the transfer total value and the deducted total value The value is stored as a database compensation amount in the target database;
将存储所述差值的记录更新在所述目标数据库中。A record storing the difference is updated in the target database.
本申请还提供一种基于分布式内存和数据库的数据处理装置,所述装置包括:The application also provides a data processing device based on a distributed memory and a database, the device comprising:
接收请求单元,用于接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前预算数据的预算标识和预算额度;a receiving request unit, configured to receive a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota;
第一判断单元,用于依据所述预算标识判断存储所述当前预算数据的当前内存分片中的内存额度是否大于所述预算额度;a first determining unit, configured to determine, according to the budget identifier, whether a memory quota in a current memory segment storing the current budget data is greater than the budget quota;
第一扣减单元,用于在所述第一判断单元的结果为是的情况下,直接在所述当前内存分片中将所述内存额度扣减所述预算额度;a first deducting unit, configured to deduct the memory quota directly in the current memory segment if the result of the first determining unit is YES;
第二判断单元,用于在所述第一判断单元的结果为否的情况下,依据所述预算标识判断所述当前内存分片中存储的当前数据库剩余额度和所述内存额度之和是否大于所述预算额度;a second determining unit, configured to determine, according to the budget identifier, whether a sum of a current database remaining amount and the memory amount stored in the current memory segment is greater than The budget amount;
第二扣减单元,用于在所述第二判断模块的结果为是的情况下,依据 所述当前数据库剩余额度和内存额度扣减所述预算额度;a second deduction unit, configured to: when the result of the second judging module is yes, The current database remaining amount and the memory quota are deducted from the budget amount;
存储扣减记录单元,用于将所述扣减所述预算额度的扣减记录存储至所述当前数据库中,所述当前数据库与所述当前内存分片对应保存相同预算标识的预算数据。The storage deduction recording unit is configured to store the deduction record of the deduction of the budget quota into the current database, where the current database and the current memory segment correspond to budget data of the same budget identifier.
本申请还提供了一种数据处理***,该***包括:数据处理装置和数据补偿装置,其中,所述数据处理装置包括:The present application also provides a data processing system, the system comprising: a data processing device and a data compensation device, wherein the data processing device comprises:
接收请求单元,用于接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前预算数据的预算标识和预算额度;a receiving request unit, configured to receive a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota;
第一判断单元,用于依据所述预算标识判断存储所述当前预算数据的当前内存分片中的内存额度是否大于所述预算额度;a first determining unit, configured to determine, according to the budget identifier, whether a memory quota in a current memory segment storing the current budget data is greater than the budget quota;
第一扣减单元,用于在所述第一判断单元的结果为是的情况下,直接在所述当前内存分片中将所述内存额度扣减所述预算额度;a first deducting unit, configured to deduct the memory quota directly in the current memory segment if the result of the first determining unit is YES;
第二判断单元,用于在所述第一判断单元的结果为否的情况下,依据所述预算标识判断所述当前内存分片中存储的当前数据库剩余额度和所述内存额度之和是否大于所述预算额度;a second determining unit, configured to determine, according to the budget identifier, whether a sum of a current database remaining amount and the memory amount stored in the current memory segment is greater than The budget amount;
第二扣减单元,用于在所述第二判断模块的结果为是的情况下,依据所述当前数据库剩余额度和内存额度扣减所述预算额度;a second deducting unit, configured to deduct the budget quota according to the current database remaining amount and the memory quota if the result of the second judging module is YES;
存储扣减记录单元,用于将所述扣减所述预算额度的扣减记录存储至所述当前数据库中,所述当前数据库与所述当前内存分片对应保存相同预算标识的预算数据;a storage deduction record unit, configured to store the deduction record deducting the budget amount into the current database, where the current database and the current memory segment correspond to budget data of the same budget identifier;
所述数据补偿装置包括:The data compensation device includes:
确定单元,用于依据待同步的预算标识确定待处理的目标数据库;a determining unit, configured to determine a target database to be processed according to the budget identifier to be synchronized;
获取记录单元,用于从所述目标数据库中获取该预算标识对应的所有扣减记录和转移记录,其中,所述转移记录表示将额度从数据库转移至与内存分片的记录;Obtaining a record unit, configured to obtain, from the target database, all the deduction records and transfer records corresponding to the budget identifier, where the transfer record indicates that the quota is transferred from the database to the record with the memory segment;
第六判断单元,用于判断所述所有转移记录所表示的转移总额度值是否大于所述扣减记录所表示的扣减总额度值;a sixth determining unit, configured to determine whether the transfer total value represented by the all transfer records is greater than a deduction total value represented by the deduction record;
存储补偿额度单元,用于在所述第六判断单元的结果为是的情况下,将所述转移总额度值与所述扣减总额度值的差值作为数据库补偿额度存 储至所述目标数据库中;a storage compensation amount unit, configured to store, as a database compensation amount, a difference between the transfer total value and the deducted total value in a case where the result of the sixth determining unit is YES Stored in the target database;
更新单元,用于将存储所述差值的记录更新在所述目标数据库中。And an update unit, configured to update the record storing the difference in the target database.
与现有技术相比,本申请包括以下优点:Compared with the prior art, the present application includes the following advantages:
采用本申请实施例,可以大大减少对DB的访问次数,而因为内存相对于DB的性能较高,一方面可以利用对内存的访问提升数据处理性能,一方面也会因为减少了DB的访问次数从而降低DB对于数据处理请求的影响。因此,本申请实施例采用的分布式内存和分布式DB的方式,既能提升数据处理性能,满足高并发请求,并且也能节省DB的数量,从而节省成本。With the embodiment of the present application, the number of accesses to the DB can be greatly reduced, and because the performance of the memory is relatively high relative to the DB, on the one hand, the access to the memory can be utilized to improve the data processing performance, and on the other hand, the number of accesses of the DB can be reduced. This reduces the impact of the DB on data processing requests. Therefore, the distributed memory and the distributed DB adopted by the embodiments of the present application can improve data processing performance, meet high concurrent requests, and save the number of DBs, thereby saving costs.
本申请的有益效果还在于:在扣减预算额度的操作成功的情况下,可以通知用户预算额度扣减成功,反之则用户预算额度扣减失败。从而将扣减结果实时反馈给用户,方便用户了解预算额度的扣减情况。The beneficial effect of the application is that: in the case that the operation of deducting the budget quota is successful, the user may be notified that the budget amount deduction is successful, and otherwise the user budget credit deduction is failed. Therefore, the deduction result is fed back to the user in real time, so that the user can understand the deduction of the budget amount.
本申请的有益效果还在于:方便在内存余额和DB额度的总额度不足时直接告知用户额度不足,从而可以减少对DB的访问。The beneficial effects of the present application are also that it is convenient to directly inform the user that the quota is insufficient when the total amount of the memory balance and the DB quota is insufficient, so that the access to the DB can be reduced.
本申请的有益效果还在于:大幅提升服务器宕机后在内存分片中恢复数据的速度。The utility model also has the beneficial effects of: greatly improving the speed of recovering data in the memory segment after the server is down.
当然,实施本申请的任一产品并不一定需要同时达到以上所述的所有优点。Of course, implementing any of the products of the present application does not necessarily require all of the advantages described above to be achieved at the same time.
附图说明DRAWINGS
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings used in the description of the embodiments will be briefly described below. It is obvious that the drawings in the following description are only some embodiments of the present application. Other drawings may also be obtained from those of ordinary skill in the art in light of the inventive work.
图1是本申请的基于分布式内存和数据库的数据处理方法实施例的流程图;1 is a flow chart of an embodiment of a distributed memory and database based data processing method of the present application;
图2是本申请实施例的一个应用场景的架构示意图;2 is a schematic structural diagram of an application scenario of an embodiment of the present application;
图3是本申请实施例中从DB中加载余额到内存分片的流程图;3 is a flow chart of loading a balance from a DB into a memory slice in the embodiment of the present application;
图4是本申请的单机内存分片不足的情况下对预算标识进行拆分存储的流程图; 4 is a flowchart of splitting and storing a budget identifier in the case where the single-machine memory fragmentation of the present application is insufficient;
图5是本申请的基于分布式内存和数据库的数据补偿方法实施例的流程图;5 is a flow chart of an embodiment of a data compensation method based on distributed memory and database of the present application;
图6是本申请的基于分布式内存和数据库的数据处理装置实施例的结构框图;6 is a structural block diagram of an embodiment of a distributed memory and database based data processing apparatus of the present application;
图7是本申请的实现DB中加载余额到内存分片的各单元的框架示意图;7 is a schematic diagram of a frame of each unit in the implementation DB of the application for loading a balance to a memory slice;
图8是本申请的实现对预算标识进行拆分存储的各单元的框架示意图;FIG. 8 is a schematic diagram of a frame of each unit for performing split storage of a budget identifier according to an implementation of the present application; FIG.
图9是本申请的基于分布式内存和数据库的数据处理***的框架示意图。9 is a schematic diagram of a framework of a distributed memory and database based data processing system of the present application.
这里描述的附图仅仅是一些例子。在不脱离本申请精神的情况下,这里所述的图可以有不同的变化。所有上述变化被认为是要求保护的本申请的一部分。The drawings described herein are just a few examples. The figures described herein may vary from one to the other without departing from the spirit of the application. All such variations are considered to be part of the claimed application.
具体实施方式detailed description
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The technical solutions in the embodiments of the present application are clearly and completely described in the following with reference to the drawings in the embodiments of the present application. It is obvious that the described embodiments are only a part of the embodiments of the present application, and not all of the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments of the present application without departing from the inventive scope are the scope of the present application.
在介绍本申请实施例之前,为了方便本领域技术人员更好的理解本申请,首先对本申请中的预算数据在分布式内存和分布式DB中的存储方式进行介绍。Before introducing the embodiments of the present application, in order to facilitate the understanding of the present application by those skilled in the art, the storage method of the budget data in the distributed memory and the distributed DB in the present application is first introduced.
分布式内存是将数据分别存储在不同的内存分片上的数据存储空间。每个内存分片可以分布在一个服务器上,多个服务器上的多个内存分片形成的分布式内存的数据存储方式可以扩充存储空间,也能提升数据存储性能。假设在实际应用中有10个内存分片,而预算数据由预算标识和预算额度来表示,其中预算标识用于唯一表示一条预算数据,例如, 唯一表示一个在售产品的数量,或者用于唯一标示一个专门进行某种扣费的金额。预算额度则表示数量大小或者金额多少。例如,预算标识为A001的预算额度为100w。Distributed memory is a data storage space that stores data on separate memory slices. Each memory slice can be distributed on one server, and the distributed memory data storage mode formed by multiple memory slices on multiple servers can expand the storage space and improve the data storage performance. Suppose there are 10 memory slices in the actual application, and the budget data is represented by the budget identifier and the budget quota, where the budget identifier is used to uniquely represent a budget data, for example, The only number indicates the quantity of a product being sold, or is used to uniquely indicate an amount specifically for a certain deduction. The budget amount indicates the quantity or amount. For example, the budget with a budget identifier of A001 is 100w.
在分布式内存中,假设有5个内存分片,第1个内存分片中预算数据的存放形式可以如表1所示:In distributed memory, assuming five memory fragments, the storage form of the budget data in the first memory fragment can be as shown in Table 1:
表1Table 1
预算IDBudget ID DB余额DB balance 版本号version number 内存余额Memory balance
A001A001 90w90w 11 10w10w
……...... ……...... ……...... ……......
A100A100 10w10w 22 1w1w
表1表示在第1个内存分片中保存了预算标识为A001-A100的预算数据,其中,每一个预算数据都对应保存有DB余额和内存余额,两者的和则是该预算数据当前的总量。其中版本号可以用于表示当前预算数据的更新情况。按照每个内存分片都保存100个预算数据的方式,那么5个内存分片分别可以保存A001-A500的预算数据。Table 1 shows that the budget data with the budget identifier A001-A100 is saved in the first memory segment, wherein each budget data corresponds to the DB balance and the memory balance, and the sum of the two is the current budget data. Total amount. The version number can be used to indicate the update of the current budget data. According to the way that each memory segment saves 100 budget data, then 5 memory segments can save the budget data of A001-A500.
相应的,在分布式DB中,对应存在5个DB,与第一个内存分片对应的第一个DB也对应保存有A001-A100的预算数据。此外,在DB中还保存有预算数据的扣减明细。Correspondingly, in the distributed DB, there are 5 DBs corresponding to each other, and the first DB corresponding to the first memory fragment also corresponds to the budget data of A001-A100. In addition, the deduction details of the budget data are also stored in the DB.
参考图1,示出了本申请一种基于分布式内存和数据库的数据处理方法实施例的流程图,本实施例可以包括以下步骤:Referring to FIG. 1, a flowchart of an embodiment of a data processing method based on a distributed memory and a database is shown in the present application. The embodiment may include the following steps:
步骤101:接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前预算数据的预算标识和预算额度。Step 101: Receive a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota.
参考图2所示,为本申请实施例的一个应用场景的架构示意图。其中,本申请是应用于内存存储***202中的。当有用户触发数据处理请求的时候,数据处理请求中包括了当前预算数据的预算标识和预算额度,预算路由控制***可以根据预算标识来定位到保存该预算标识的预算数据的内存分片,从而在该内存分片中将用户请求的预算额度进行扣减。FIG. 2 is a schematic structural diagram of an application scenario according to an embodiment of the present application. The application is applied to the memory storage system 202. When a user triggers a data processing request, the data processing request includes a budget identifier and a budget quota of the current budget data, and the budget routing control system may locate a memory segment that saves the budget data of the budget identifier according to the budget identifier, thereby The budget amount requested by the user is deducted in the memory slice.
步骤102:依据所述预算标识判断存储所述当前预算数据的当前内存 分片中的内存额度是否大于所述预算额度,如果是,则进入步骤103,如果否,则进入步骤104。Step 102: Determine, according to the budget identifier, a current memory that stores the current budget data. Whether the amount of memory in the slice is greater than the budget amount, if yes, proceed to step 103, and if no, proceed to step 104.
因为内存分片中保存有内存额度,所以判断保存当前预算数据的当前内存分片中的内存额度是否大于该预算额度。例如,如果预算标识为A002,预算额度为9w,那么对应的预算数据就保存在第一个内存分片中,判断用户请求的预算额度9w是否小于或等于内存额度10w。Because the memory quota is stored in the memory segment, it is determined whether the memory amount in the current memory segment storing the current budget data is greater than the budget amount. For example, if the budget identifier is A002 and the budget quota is 9w, the corresponding budget data is stored in the first memory fragment, and it is determined whether the budget amount 9w requested by the user is less than or equal to the memory quota of 10w.
步骤103:直接在所述当前内存分片中将所述内存额度扣减所述预算额度,进入步骤106。Step 103: Deduct the memory quota from the current quota in the current memory segment, and proceed to step 106.
如果判断结果为肯定的,即内存额度大于预算额度,说明内存分片中存储的预算数据就足以响应当前的数据处理请求,在这种情况下,直接在当前内存分片中将内存额度10w扣减掉预算额度9w即可。If the judgment result is affirmative, that is, the memory quota is greater than the budget quota, the budget data stored in the memory segment is sufficient to respond to the current data processing request. In this case, the memory quota is directly deducted in the current memory segment. You can reduce the budget amount by 9w.
步骤104:依据所述预算标识判断所述当前内存分片中存储的当前DB额度和所述内存额度之和是否大于所述预算额度,如果是,则进入步骤105。Step 104: Determine, according to the budget identifier, whether the sum of the current DB quota and the memory quota stored in the current memory fragment is greater than the budget quota, and if yes, proceed to step 105.
而如果判断结果为否定的,即内存额度小于预算额度,说明内存额度不足以响应当前的数据处理请求,因此,需要将当前内存分片中存储的该预算数据的当前DB额度和内存额度之和与预算额度进行比较,如果当前DB额度和内存额度之和大于预算额度,则说明内存分片和DB的额度之和足以响应当前的数据处理请求。If the judgment result is negative, that is, the memory quota is less than the budget quota, indicating that the memory credit is insufficient to respond to the current data processing request, therefore, the sum of the current DB quota and the memory credit of the budget data stored in the current memory fragment needs to be used. Compared with the budget quota, if the sum of the current DB quota and the memory credit is greater than the budget quota, the sum of the memory fragment and the DB amount is sufficient to respond to the current data processing request.
步骤105:依据所述当前DB剩余额度和内存额度扣减所述预算额度。Step 105: Deduct the budget quota according to the current DB remaining credit and the memory credit.
在内存分片和DB的额度之和足够扣减预算额度的情况下,同时参考当前DB额度和内存额度来扣减预算额度。例如,内存额度为10w,而预算额度为11w,但是DB余额有20w,就可以依据当前DB额度和内存额度来扣减预算额度。In the case where the sum of the memory fragment and the DB amount is sufficient to deduct the budget amount, the current DB amount and the memory quota are simultaneously referred to to deduct the budget amount. For example, the memory quota is 10w, and the budget quota is 11w, but the DB balance has 20w, and the budget quota can be deducted according to the current DB quota and memory quota.
在具体实现时,步骤105具体可以包括:In a specific implementation, step 105 may specifically include:
步骤A1:获取所述预算额度和内存额度的额度差。Step A1: Obtain a difference between the budget amount and the memory quota.
接着前面的例子克制,预算额度11w和内存额度10w的额度差为1w。Then the previous example is restrained, and the difference between the budget quota 11w and the memory quota 10w is 1w.
步骤A2:从所述当前DB额度中扣减所述额度差,并将所述扣减的额度差存储至所述当前内存分片中。 Step A2: Deduct the credit difference from the current DB quota, and store the deducted credit difference into the current memory fragment.
在从DB的额度中扣减1w之后,将该扣减的1w存储至当前内存分片中,在这种情况下,内存分片中就存储有11w的内存额度。After deducting 1w from the DB's quota, the deducted 1w is stored in the current memory slice. In this case, 11w of the memory quota is stored in the memory slice.
步骤A3:在所述当前内存分片中将存储所述额度差后的内存额度扣减所述预算额度。Step A3: Deduct the memory quota after storing the credit difference in the current memory segment.
在从当前内存分片中将11w的预算额度进行扣减即可。The 11w budget amount can be deducted from the current memory segment.
步骤106:将所述扣减所述预算额度的扣减记录存储至所述当前DB中,所述当前DB与所述当前内存分片对应保存相同预算标识的预算数据。Step 106: Store the deduction record of the deduction of the budget quota into the current DB, where the current DB and the current memory segment correspond to budget data of the same budget identifier.
在当前内存分片中对预算额度进行扣减之后,要将本次扣减预算额度的记录存储在当前DB中,这样就方便在内存丢失数据的情况下可以根据DB中保存的扣减记录来恢复余额数据。After the budget amount is deducted in the current memory segment, the record of the deduction budget amount is stored in the current DB, so that it is convenient to use the deduction record saved in the DB in the case of data loss in the memory. Restore balance data.
在本申请实施例中,需要响应用户的数据处理请求从而对预算数据进行余额扣减时,首先是从内存分片中判断内存余额是否足够,在内存余额足够的情况下,无需访问DB,直接从内存分片中扣减内存余额即可,即便内存分片中的内存余额不够,也只需从DB中扣减内存余额不够的那一部分。因此,与现有技术相比,可以大大减少对DB的访问次数,而因为内存相对于DB的性能较高,一方面可以利用对内存的访问提升数据处理性能,一方面也会因为减少了DB的访问次数从而降低DB对于数据处理请求的影响。因此,本申请实施例采用的分布式内存和分布式DB的方式,既能提升数据处理性能,满足高并发请求,并且也能节省DB的数量,从而节省成本。In the embodiment of the present application, when the user needs to respond to the data processing request of the user and the balance of the budget data is deducted, the first is to determine whether the memory balance is sufficient from the memory fragment, and if the memory balance is sufficient, the DB does not need to be accessed directly. Deduct the memory balance from the memory slice, even if the memory balance in the memory slice is not enough, you only need to deduct the part of the DB that is not enough. Therefore, compared with the prior art, the number of accesses to the DB can be greatly reduced, and because the performance of the memory is relatively high relative to the DB, on the one hand, the access to the memory can be utilized to improve the data processing performance, and on the other hand, the DB is reduced. The number of visits thus reduces the impact of the DB on data processing requests. Therefore, the distributed memory and the distributed DB adopted by the embodiments of the present application can improve data processing performance, meet high concurrent requests, and save the number of DBs, thereby saving costs.
可以理解的是,在步骤107之后,还可以包括:It can be understood that after step 107, the method may further include:
步骤108:判断所述扣减预算额度的操作是否成功,如果是,则通知用户所述预算额度扣减成功,如果否,则通知用户所述预算额度扣减失败。Step 108: Determine whether the operation of deducting the budget quota is successful. If yes, notify the user that the budget credit deduction is successful, and if not, notify the user that the budget credit deduction fails.
在扣减预算额度的操作成功的情况下,可以通知用户预算额度扣减成功,反之则停止用户预算额度扣减失败。从而将扣减结果实时反馈给用户,方便用户了解预算额度的扣减情况。 In the case that the operation of deducting the budget quota is successful, the user may be notified that the budget amount deduction is successful, and otherwise the user budget quota deduction is stopped. Therefore, the deduction result is fed back to the user in real time, so that the user can understand the deduction of the budget amount.
此外,在本申请实施例中,每一个内存分片中只保存预算数据中的一小部分余额,预算数据的剩余大部分余额还是保存在对应的DB中,在需要的时候分别从DB中获取即可。参考图3所示,为本申请实施例中从DB中加载余额到内存分片的流程,具体可以包括:In addition, in the embodiment of the present application, only a small portion of the budget data is saved in each memory segment, and most of the remaining balance of the budget data is saved in the corresponding DB, and is obtained from the DB when needed. Just fine. Referring to FIG. 3, the process of loading a balance from a DB to a memory slice in the embodiment of the present application may specifically include:
步骤301:获取所述预算标识对应的预算总额度的预设比例的部分额度作为所述内存额度。Step 301: Obtain a partial quota of a preset proportion of the budget total amount corresponding to the budget identifier as the memory quota.
在本实施例中,可以预先设置一个比例,每次将该比例对应的预算总额的一部分从DB加载到内存即可。例如,对于预算标识为A002的预算数据来说,预设比例为十分之一,那么假设该预算数据的总额度为100w,那么该预设比例对应的部分额度即为10w。In this embodiment, a ratio may be set in advance, and a part of the total budget corresponding to the ratio may be loaded from the DB into the memory each time. For example, for the budget data with the budget identifier A002, the preset ratio is one tenth. If the total amount of the budget data is 100w, then the partial quota corresponding to the preset ratio is 10w.
步骤302:将所述内存额度从当前DB转移至与所述预算标识对应的当前内存分片,其中,所述当前内存分片对应保存有预先设定的多个预算标识的多个内存额度,所述当前DB保存有所述多个预算标识的预算总额度中除了所述内存额度之外的多个DB额度。Step 302: Transfer the memory quota from the current DB to the current memory segment corresponding to the budget identifier, where the current memory segment corresponds to a plurality of memory quotas that have preset multiple budget identifiers. The current DB stores a plurality of DB quotas in addition to the memory quota in the budget totality of the plurality of budget identifiers.
再将确定的10w的内存额度从当前DB转移至保存A002的预算数据的那个内存分片中,而当前DB中则又90w的DB余额。其中,一个内存分片可以多个预算标识的多个预算数据以及该多个预算数据的多个内存额度,而一个DB也可以保存多个预算标识的预算总额度中除了内存额度之外的对应的多个DB额度。Then, the determined 10w memory quota is transferred from the current DB to the memory segment in which the budget data of A002 is saved, and the DB balance of the current DB is 90w. Wherein, one memory segment may have multiple budget data identified by multiple budgets and multiple memory quotas of the plurality of budget data, and one DB may also store correspondences of budget totals of multiple budget identifiers except memory quotas. Multiple DB quotas.
步骤303:将转移所述内存额度的转移记录存储至所述当前DB。Step 303: Store the transfer record of transferring the memory quota to the current DB.
在将上述10w的转移记录存储至当前DB中。The above 10w transfer record is stored in the current DB.
因为在本实施例中,内存分片中还会存放DB余额,这样就方便在内存余额和DB额度的总额度不足时直接告知用户额度不足,从而可以减少对DB的访问。Because in this embodiment, the DB balance is also stored in the memory segment, so that it is convenient to directly inform the user that the quota is insufficient when the total amount of the memory balance and the DB quota is insufficient, thereby reducing access to the DB.
还可以理解的是,因为内存分片在服务器宕机并重新启动的情况下,其中,保存的预算数据的相关信息会全部丢失,所以在这种情况下,如果全量加载余额到内存分片,就需要针对该内存分片对应的DB进行全表扫描,读取该DB中所有的扣减明细来计算出内存余额的值。 It can also be understood that, because the memory shards are all down and the server is restarted, the information about the saved budget data will be completely lost, so in this case, if the balance is fully loaded into the memory shard, It is necessary to perform a full table scan for the DB corresponding to the memory slice, and read all the deduction details in the DB to calculate the value of the memory balance.
因此,本申请实施例还可以包括:Therefore, the embodiment of the present application may further include:
步骤B:判断所述内存分片对应的DB当前额度是否为零,如果否,则将所述DB当前额度的预设比例的部分额度存储至所述内存分片。Step B: Determine whether the current quota of the DB corresponding to the memory segment is zero. If not, store a partial quota of the preset proportion of the current quota of the DB to the memory segment.
在服务器宕机恢复时,在DB层余额不为零的情况下,假设为100w,这时需要按照预设比例的大小,确定将要加载到内存分片中的部分额度,假设预设比例仍为十分之一,则需要预加载到内存分片中的部分额度就为10w。在这种情况下,将DB中的当前额度中扣减10w到内存分片中即可。此外,还需要在DB中将该转移记录进行保存。When the server is down, if the DB layer balance is not zero, it is assumed to be 100w. In this case, the amount of the part to be loaded into the memory fragment needs to be determined according to the preset ratio. One tenth, the part of the amount that needs to be preloaded into the memory slice is 10w. In this case, deduct 10w from the current quota in the DB into the memory slice. In addition, you need to save the transfer record in the DB.
可以理解的是,如果DB的总预算余额为0,并且针对该预算标识的预算数据的状态为非完成态(每一条预算标识的预算数据可以对应设置其状态,在该预算数据全部处理完之后可以将其状态修改为完成,则表示该预算数据已经全部处理完毕),才会扫描DB中所有的扣减记录和转移记录。但由于这种情况发生的概率很低,所以可以比全量加载方式提升最少1000%的效率。例如,按照每次加载10%的余额到内存为例,针对一个预算标识的预算数据,只有10%的概率是DB余额为零的情况。It can be understood that if the total budget balance of the DB is 0, and the status of the budget data for the budget is incomplete (the budget data of each budget identifier can be set correspondingly, after the budget data is completely processed) If you can change its status to complete, it means that the budget data has been processed completely, and all the deduction records and transfer records in the DB will be scanned. However, since the probability of this happening is very low, it can increase the efficiency by at least 1000% compared to the full load mode. For example, in the case of loading 10% of the balance into memory each time, for a budgeted budget data, only 10% of the probability is that the DB balance is zero.
可见本实施例采用每次只将预设比例的部分余额加载到内存分片中的方式,可以大幅提升服务器宕机后在内存分片中恢复数据的速度。It can be seen that the embodiment adopts the method of loading only a partial balance of the preset proportion into the memory segment at a time, which can greatly improve the speed of recovering data in the memory segment after the server is down.
此外,本申请实施例按照预算标识来将预算数据存放在内存分片中,可以解决单机内存不足的问题。具体的,参考图4所示,为单机内存分片不足的情况下对预算标识进行拆分存储的流程,可以包括:In addition, the embodiment of the present application stores the budget data in the memory fragment according to the budget identifier, which can solve the problem of insufficient memory of the single machine. Specifically, referring to FIG. 4, the process of splitting and storing the budget identifier in the case that the single-machine memory fragmentation is insufficient may include:
步骤401:判断所述内存分片所在的机器是否满足针对其保存的多个预算标识而发起的数据处理请求的响应,如果否,则进入步骤402。Step 401: Determine whether the machine where the memory fragment is located satisfies the response of the data processing request initiated by the plurality of budget identifiers saved by the memory fragment, and if no, proceed to step 402.
首先,假设第一个内存分片存在预算标识为A001-A100的预算数据,而针对这100个预算标识的预算数据产生了大量的数据处理请求,那么当前内存分片可能不足以顶住这大量的数据处理请求。如果判断结果为是的话,则不作任何处理。First, assuming that the first memory fragment has budget data with the budget identifier A001-A100, and the budget data for the 100 budget identifiers generates a large number of data processing requests, the current memory fragment may not be enough to withstand this large amount. Data processing request. If the result of the judgment is yes, no processing is performed.
步骤402:将多个预算标识按预设拆分规则分成多份,并将拆分后的多份预算标识中一份保存至当前内存分片,其他份预算标识则对应保存 至多个其他内存分片中。Step 402: Divide the plurality of budget identifiers into multiple copies according to the preset splitting rules, and save one of the split budget identifiers to the current memory segment, and save the other budget identifiers correspondingly. To multiple other memory slices.
则将A001-A100分别拆分为A001-A050,以及A051-A100,将预算标识为A001-A050的预算数据存储至第一个内存分片,再增加一个内存分片用来存储A051-A100的预算数据。Then divide A001-A100 into A001-A050 and A051-A100 respectively, store the budget data with budget as A001-A050 to the first memory segment, and add a memory slice to store A051-A100. Budget data.
步骤403:将与当前内存分片对应的当前DB中的多个预算标识按照同样的方式分成多份,并将拆分后的多份预算标识中的一份保留在当前DB,其他份预算标识则对应保存至多个其他DB中。Step 403: Divide the plurality of budget identifiers in the current DB corresponding to the current memory fragment into multiple shares in the same manner, and retain one of the split multiple budget identifiers in the current DB, and other budget identifiers. Then save to multiple other DBs.
并且,由于当前DB也存储A001-A100的预算数据中除了内存额度之外的DB额度,因此,也需要按照步骤402的方式,将A001-A050的预算数据存储至第一个DB,增加一个DB用来存储A051-A100的预算数据。Moreover, since the current DB also stores the DB quota in addition to the memory quota in the budget data of the A001-A100, it is also necessary to store the budget data of the A001-A050 to the first DB and add a DB according to the method of step 402. Used to store budget data for the A051-A100.
可见,在本申请实施例中,由于采用的分布式内存的方式,可以解决单机内存不足问题,并且随着访问量的增大可以通过增加内存和DB的方式,不断扩容内存层和DB层。It can be seen that, in the embodiment of the present application, due to the distributed memory mode, the problem of insufficient memory of the single machine can be solved, and the memory layer and the DB layer can be continuously expanded by increasing the memory and the DB as the amount of access increases.
在本申请实施例中,有可能会出现内存分片中保存的DB余额与DB中实际的余额不匹配的情况,因此DB中实际的余额可以通过异步的方式来同步到内存分配中,因此,可能出现内存分片中的DB余额与实际DB余额暂时不一致的情况,但最终通过同步会一致。In the embodiment of the present application, there may be a case where the DB balance saved in the memory fragment does not match the actual balance in the DB, so the actual balance in the DB can be synchronized to the memory allocation in an asynchronous manner, therefore, There may be cases where the DB balance in the memory slice is temporarily inconsistent with the actual DB balance, but it will eventually be consistent by synchronization.
因此,参考图5,示出了本申请一种基于分布式内存和数据库的数据补偿方法实施例的流程图,该数据补偿方法可以包括:数据处理过程和数据补偿过程,其中,所述数据处理流程可以参考图1所示,而数据补偿过程则可以包括以下步骤:Therefore, referring to FIG. 5, there is shown a flowchart of an embodiment of a data compensation method based on distributed memory and database, which may include: a data processing process and a data compensation process, wherein the data processing The process can be referred to FIG. 1, and the data compensation process can include the following steps:
步骤501:依据待同步的预算标识确定待处理的目标DB。Step 501: Determine a target DB to be processed according to the budget identifier to be synchronized.
首先,假设当前触发了对A005的预算标识对应的预算数据的数据补偿任务,那么存储A005的预算数据的DB即是待处理的目标DB。First, assuming that the data compensation task of the budget data corresponding to the budget identifier of A005 is currently triggered, the DB storing the budget data of A005 is the target DB to be processed.
步骤502:从所述目标DB中获取该预算标识对应的所有扣减记录和转移记录,其中,所述转移记录表示将额度从DB转移至与内存分片的记录。 Step 502: Obtain all deduction records and transfer records corresponding to the budget identifier from the target DB, where the transfer record indicates that the quota is transferred from the DB to the record with the memory segment.
从目标DB中获取到A005下对应的所有的扣减记录和转移记录,其中扣减记录表示对预算数据进行扣减的明细,而转移记录表示将额度从DB转移至与内存分片的明细。All deduction records and transfer records corresponding to A005 are obtained from the target DB, wherein the deduction record indicates a deduction of the budget data, and the transfer record indicates that the quota is transferred from the DB to the details of the memory fragment.
步骤503:判断所述所有转移记录所表示的转移总额度值是否大于所述扣减记录所表示的扣减总额度值,如果是,则进入步骤504。Step 503: Determine whether the transfer total value represented by the all transfer records is greater than the deduction total value indicated by the deduction record, and if yes, proceed to step 504.
依据转移记录可以计算出从目标DB向内存分片一共转移了多少额度,依据扣减记录也可以计算出一共在内存分片中扣减了多少额度,判断转移总额度值是否大于扣减总额度值。According to the transfer record, it is possible to calculate how much the total amount of transfer from the target DB to the memory slice, and according to the deduction record, it is also possible to calculate how much the deduction is in the memory segment, and determine whether the transfer total value is greater than the deduction total. value.
步骤504:将所述转移总额度值与所述扣减总额度值的差值作为DB补偿额度存储至所述目标DB中。Step 504: Store the difference between the transfer total value and the deducted total value as a DB compensation amount into the target DB.
如果转移总额度值大于扣减总额度值,说明当前还有余额剩余,该预算标识对应的预算数据还有效,预算数据的状态也是非完成态,则将转移总额度值与所述扣减总额度值的差值作为DB补偿额度存储至目标DB中。If the transfer total value is greater than the deducted total value, indicating that there is still remaining balance, the budget data corresponding to the budget identifier is still valid, and the state of the budget data is also incomplete, then the total value of the transfer and the total amount of the deduction are transferred. The difference of the degree values is stored as a DB compensation amount in the target DB.
步骤505:将存储所述差值的记录更新在所述目标DB中。Step 505: Update the record storing the difference value in the target DB.
再将存储该差值的记录存储在目标DB中。The record storing the difference is stored in the target DB.
在本实施例中,如果出现余额不一致的情况,可以通过上述余额补偿的流程来实现一致性,从而避免了预算数据的余额计算错误的情况。由于实际应用中内存分片中的内存余额如果足够,将会先从内存分片中进行扣减同时在DB存储扣费记录,而在内存分片的内存余额不够的情况下才需要从DB层的加载DB余额到内存分片同时也在DB存储扣减记录,所以就算内存分片中保存的余额数据与DB不一致也是内存多扣减了,那么可以通过上述的异步任务来进行余额补偿,从而最终实现一致性。在实际应用中,图5所示的流程可以由后台异步线程来做,而无需靠其他业务或者用户触发,从而对DB压力较小。In the present embodiment, if there is a situation in which the balances are inconsistent, the consistency can be achieved through the above-described process of balance compensation, thereby avoiding the situation in which the calculation of the balance of the budget data is incorrect. If the memory balance in the memory segment is sufficient in the actual application, it will be deducted from the memory segment and stored in the DB storage debit record, and the DB layer is needed if the memory segment of the memory segment is insufficient. Loading the DB balance to the memory slice and also deducting the record in the DB store, so even if the balance data saved in the memory slice is inconsistent with the DB, the memory is deducted, then the balance compensation can be performed through the asynchronous task described above, thereby Ultimately achieve consistency. In practical applications, the process shown in FIG. 5 can be performed by a background asynchronous thread without being triggered by other services or users, thereby exerting less pressure on the DB.
可选的,在实际应用中,进行了余额补偿之后,如果当前触发了异步任务,那么还可以包括:Optionally, in the actual application, after the balance compensation is performed, if the asynchronous task is currently triggered, the method may further include:
步骤506:从所述存储差值的记录读取DB补偿额度。 Step 506: Read the DB compensation amount from the record of the stored difference value.
再从DB中存储差值的记录中读取到DB的补偿额度是多少。Then, what is the compensation amount of the DB read from the record in which the difference value is stored in the DB.
步骤507:将DB补偿额度发送至与所述目标DB对应的目标内存分片,以便所述目标内存分片依据所述DB补偿额度更新存储DB剩余额度。Step 507: Send the DB compensation quota to the target memory fragment corresponding to the target DB, so that the target memory fragment updates the storage DB remaining credit according to the DB compensation quota.
再将DB补偿额度通过幂等通知给对应的内存分片,目标内存分片再依据DB补偿额度更新自身存储的DB剩余额度。Then, the DB compensation amount is notified to the corresponding memory segment by idempotent, and the target memory segment updates the DB remaining quota stored by itself according to the DB compensation amount.
此外,每次向内存分片发送的余额变更幂等通知消息都有一个唯一自增版本号,如果同一个余额变更幂等通知消息收到两次或者旧的消息比新的消息先到,则内存分片都会以最新的版本号对应的消息为准。In addition, each time the balance change idempotent notification message sent to the memory slice has a unique self-increment version number, if the same balance change idempotent notification message is received twice or the old message arrives earlier than the new message, then The memory fragment will be based on the message corresponding to the latest version number.
可见,补偿额度是通过异步+和幂等通知到内存分配的,也能进一步降低对DB的访问,同时可以使内存和DB中的余额数据达到最终一致性。It can be seen that the compensation amount is notified to the memory by asynchronous + and idempotent, and can further reduce the access to the DB, and at the same time, the final consistency of the balance data in the memory and the DB can be achieved.
对于前述的方法实施例,为了简单描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请并不受所描述的动作顺序的限制,因为依据本申请,某些步骤可以采用其他顺序或者同时进行。其次,本领域技术人员也应该知悉,说明书中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定是本申请所必须的。For the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations, but those skilled in the art should understand that the present application is not limited by the described action sequence, because according to the present application, These steps can be performed in other orders or simultaneously. In the following, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
与上述本申请一种基于分布式内存和数据库的数据处理方法实施例所提供的方法相对应,参见图6,本申请还提供了一种基于分布式内存和数据库的数据处理装置实施例,该装置可以包括:Corresponding to the method provided by the embodiment of the data processing method based on the distributed memory and the database in the above application, referring to FIG. 6, the present application further provides an embodiment of a data processing device based on a distributed memory and a database. The device can include:
接收请求单元601,用于接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前预算数据的预算标识和预算额度。The receiving request unit 601 is configured to receive a data processing request triggered by the user, where the data processing request includes: a budget identifier of the current budget data and a budget quota.
第一判断单元602,用于依据所述预算标识判断存储所述当前预算数据的当前内存分片中的内存额度是否大于所述预算额度。The first determining unit 602 is configured to determine, according to the budget identifier, whether a memory quota in a current memory segment storing the current budget data is greater than the budget quota.
第一扣减单元603,用于在所述第一判断单元的结果为是的情况下,直接在所述当前内存分片中将所述内存额度扣减所述预算额度。The first deduction unit 603 is configured to deduct the memory quota directly from the current memory segment in the current memory segment if the result of the first determining unit is YES.
第二判断单元604,用于在所述第一判断单元的结果为否的情况下,依据所述预算标识判断所述当前内存分片中存储的当前DB剩余额度和所述内存额度之和是否大于所述预算额度。 The second determining unit 604 is configured to determine, according to the budget identifier, whether the sum of the current DB remaining amount and the memory quota stored in the current memory segment is determined according to the budget identifier. Greater than the budget amount.
第二扣减单元605,用于在所述第二判断模块的结果为是的情况下,依据所述当前DB剩余额度和内存额度扣减所述预算额度。The second deduction unit 605 is configured to deduct the budget quota according to the current DB remaining credit and the memory quota if the result of the second judging module is YES.
其中,所述第二扣减单元605具体可以包括:获取模块,用于获取所述预算额度和内存额度的额度差;第一扣减模块,用于从所述当前DB剩余额度中扣减所述额度差;存储模块,用于将所述扣减的额度差存储至所述当前内存分片中;和,第二扣减模块,用于在所述当前内存分片中将存储所述额度差后的内存额度扣减所述预算额度。The second deduction unit 605 may include: an obtaining module, configured to acquire a quota difference between the budget quota and the memory quota; and a first deduction module, configured to deduct from the current DB remaining credit a storage module for storing the deducted credit difference into the current memory segment; and a second deduction module for storing the credit in the current memory segment The difference in memory credit deducts the budget amount.
存储扣减记录单元606,用于将所述扣减所述预算额度的扣减记录存储至所述当前DB中,所述当前DB与所述当前内存分片对应保存相同预算标识的预算数据。The store deduction record unit 606 is configured to store the deduction record of the deduction of the budget amount into the current DB, where the current DB and the current memory segment correspond to budget data of the same budget identifier.
采用本申请实施例可以大大减少对DB的访问次数,而因为内存相对于DB的性能较高,一方面可以利用对内存的访问提升数据处理性能,一方面也会因为减少了DB的访问次数从而降低DB对于数据处理请求的影响。因此,本申请实施例采用的分布式内存和分布式DB的方式,既能提升数据处理性能,满足高并发请求,并且也能节省DB的数量,从而节省成本。The embodiment of the present application can greatly reduce the number of accesses to the DB, and because the performance of the memory is relatively high relative to the DB, on the one hand, the access to the memory can be utilized to improve the data processing performance, and on the other hand, the number of accesses of the DB can be reduced. Reduce the impact of DB on data processing requests. Therefore, the distributed memory and the distributed DB adopted by the embodiments of the present application can improve data processing performance, meet high concurrent requests, and save the number of DBs, thereby saving costs.
参考图7所示,为实现DB中加载余额到内存分片的各单元的框架示意图,具体可以包括:Referring to FIG. 7 , a schematic diagram of a framework for implementing a unit for loading a balance into a memory slice in a DB may include:
获取额度单元701,用于获取所述预算标识对应的预算总额度的预设比例的部分额度作为所述内存额度。The obtaining quota unit 701 is configured to obtain a partial quota of a preset proportion of the budget total amount corresponding to the budget identifier as the memory quota.
转移单元702,用于将所述内存额度从当前DB转移至与所述预算标识对应的当前内存分片,其中,所述当前内存分片对应保存有预先设定的多个预算标识的多个内存额度,所述当前DB保存有所述多个预算标识的预算总额度中除了所述内存额度之外的多个DB额度。The transferring unit 702 is configured to transfer the memory quota from the current DB to the current memory fragment corresponding to the budget identifier, where the current memory fragment corresponds to multiple presets that store a plurality of preset budget identifiers. a memory quota, where the current DB stores a plurality of DB quotas in addition to the memory quota in the budget totality of the plurality of budget identifiers.
存储转移记录单元703,用于将转移所述内存额度的转移记录存储至所述当前DB。The storage transfer recording unit 703 is configured to store the transfer record that transfers the memory quota to the current DB.
在本实施例中,内存分片中还会存放DB余额,这样就方便在内存余额和DB额度的总额度不足时直接告知用户额度不足,从而可以减少对 DB的访问。In this embodiment, the DB balance is also stored in the memory segment, so that it is convenient to directly inform the user that the quota is insufficient when the total amount of the memory balance and the DB quota is insufficient, thereby reducing the DB access.
参考图8所示,为实现对预算标识进行拆分存储的各单元的框架示意图,具体可以包括:Referring to FIG. 8 , a schematic diagram of a frame of each unit for performing split storage on a budget identifier may include:
第三判断单元801,用于判断所述内存分片所在的机器是否满足针对其保存的多个预算标识而发起的数据处理请求的响应。The third determining unit 801 is configured to determine whether the machine where the memory fragment is located satisfies a response to a data processing request initiated by the plurality of budget identifiers saved by the memory fragment.
内存拆分单元802,用于在所述第三判断单元的结果为否的情况下,将多个预算标识按预设拆分规则分成多份。The memory splitting unit 802 is configured to divide the plurality of budget identifiers into multiple copies according to a preset splitting rule if the result of the third determining unit is negative.
内存保存单元803,用于并将拆分后的多份预算标识中一份保存至当前内存分片,其他份预算标识则对应保存至多个其他内存分片中。The memory saving unit 803 is configured to save one copy of the split budget identifiers to the current memory fragment, and save the other budget identifiers to the plurality of other memory fragments.
DB拆分单元804,将与当前内存分片对应的当前DB中的多个预算标识按照同样的方式分成多份。The DB splitting unit 804 divides the plurality of budget identifiers in the current DB corresponding to the current memory slice into a plurality of shares in the same manner.
DB保存单元805,用于将拆分后的多份预算标识中的一份保留在当前DB,其他份预算标识则对应保存至多个其他DB中。The DB saving unit 805 is configured to reserve one of the split budget identifiers in the current DB, and save the other budget identifiers in multiple other DBs.
在本实施例中,由于采用的分布式内存的方式,可以解决单机内存不足问题,并且随着访问量的增大可以通过增加内存和DB的方式,不断扩容内存层和DB层。In this embodiment, due to the distributed memory mode, the problem of insufficient memory of the single machine can be solved, and the memory layer and the DB layer can be continuously expanded by increasing the memory and the DB as the number of accesses increases.
本申请还提供了一种基于分布式内存和数据库的数据处理***,参考图9,该***可以包括:数据处理装置90和数据补偿装置91,其中,所述数据处理装置90具体可以包括:接收请求单元,用于接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前预算数据的预算标识和预算额度;第一判断单元,用于依据所述预算标识判断存储所述当前预算数据的当前内存分片中的内存额度是否大于所述预算额度;第一扣减单元,用于在所述第一判断单元的结果为是的情况下,直接在所述当前内存分片中将所述内存额度扣减所述预算额度;第二判断单元,用于在所述第一判断单元的结果为否的情况下,依据所述预算标识判断所述当前内存分片中存储的当前DB剩余额度和所述内存额度之和是否大于所述预算额度;第二扣减单元,用于在所述第二判断模块的结果为是 的情况下,依据所述当前DB剩余额度和内存额度扣减所述预算额度;存储扣减记录单元,用于将所述扣减所述预算额度的扣减记录存储至所述当前DB中,所述当前DB与所述当前内存分片对应保存相同预算标识的预算数据。The present application also provides a data processing system based on distributed memory and database. Referring to FIG. 9, the system may include: a data processing device 90 and a data compensation device 91, wherein the data processing device 90 may specifically include: receiving a requesting unit, configured to receive a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota; the first determining unit is configured to determine, according to the budget identifier, the current budget Whether the memory quota in the current memory segment of the data is greater than the budget quota; the first deduction unit is configured to directly in the current memory segment if the result of the first determining unit is YES The second amount determining unit is configured to determine, according to the budget identifier, a current DB stored in the current memory segment, if the result of the first determining unit is negative Whether the sum of the remaining credit and the memory credit is greater than the budget quota; the second deducting unit is used in the second judging module Fruit is And deducting the budget quota according to the current DB remaining credit and the memory quota; storing a deduction record unit, configured to store the deduction record deducting the budget quota into the current DB, The current DB corresponds to the current memory fragment to save budget data of the same budget identifier.
其中,所述数据补偿装置91具体可以包括:The data compensation device 91 may specifically include:
确定单元911,用于依据待同步的预算标识确定待处理的目标DB。The determining unit 911 is configured to determine a target DB to be processed according to the budget identifier to be synchronized.
获取记录单元912,用于从所述目标DB中获取该预算标识对应的所有扣减记录和转移记录,其中,所述转移记录表示将额度从DB转移至与内存分片的记录。The obtaining record unit 912 is configured to obtain, from the target DB, all the deduction records and the transfer records corresponding to the budget identifier, wherein the transfer records indicate that the quota is transferred from the DB to the record with the memory segment.
第六判断单元913,用于判断所述所有转移记录所表示的转移总额度值是否大于所述扣减记录所表示的扣减总额度值。The sixth determining unit 913 is configured to determine whether the transfer total value represented by the all transfer records is greater than the deduction total value indicated by the deduction record.
存储补偿额度单元914,用于在所述第六判断单元的结果为是的情况下,将所述转移总额度值与所述扣减总额度值的差值作为DB补偿额度存储至所述目标DB中。a storage compensation amount unit 914, configured to store, when the result of the sixth determining unit is YES, a difference between the transfer totality value and the deducted total value as a DB compensation amount to the target DB.
更新单元915,用于将存储所述差值的记录更新在所述目标DB中。The updating unit 915 is configured to update the record storing the difference value in the target DB.
如果出现余额不一致的情况,可以通过上述余额补偿的流程来实现一致性,从而避免了预算数据的余额计算错误的情况。由于实际应用中每次都是先从内存分片中进行扣减,内存分片不够的情况下才会扣减DB层的余额,所以就算内存分片中保存的余额数据与DB不一致也是内存多扣减了,那么可以通过上述的异步任务来进行余额补偿,从而最终实现一致性。If there is a situation in which the balances are inconsistent, the consistency of the above balance compensation process can be used to achieve consistency, thereby avoiding the calculation of the balance of the budget data. Since the actual application first deducts from the memory fragment, the memory layer is not enough to deduct the DB layer balance, so even if the balance data stored in the memory fragment is inconsistent with the DB, it is more memory. If the deduction is made, the balance compensation can be performed through the asynchronous task described above, thereby achieving consistency.
其中,所述数据补偿装置还可以包括:The data compensation device may further include:
读取额度单元916,用于从所述存储差值的记录读取DB补偿额度。The read credit unit 916 is configured to read the DB compensation amount from the record of the stored difference value.
发送单元917,用于将DB补偿额度发送至与所述目标DB对应的目标内存分片,以便所述目标内存分片依据所述DB补偿额度更新存储DB剩余额度。The sending unit 917 is configured to send the DB compensation quota to the target memory fragment corresponding to the target DB, so that the target memory fragment updates the storage DB remaining credit according to the DB compensation quota.
本实施例可以进一步降低对DB的访问,同时可以使内存和DB中的余额数据达到最终一致性。This embodiment can further reduce the access to the DB, and at the same time, the final consistency of the balance data in the memory and the DB can be achieved.
需要说明的是,本说明书中的各个实施例均采用递进的方式描述, 每个实施例重点说明的都是与其他实施例的不同之处,各个实施例之间相同相似的部分互相参见即可。对于***类实施例而言,由于其与方法实施例基本相似,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。It should be noted that each embodiment in this specification is described in a progressive manner. Each embodiment is mainly described as being different from the other embodiments, and the same similar parts between the respective embodiments can be referred to each other. For the system class embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.
最后,还需要说明的是,在本文中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。Finally, it should also be noted that in this context, relational terms such as first and second are used merely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply these entities. There is any such actual relationship or order between operations. Furthermore, the term "comprises" or "comprises" or "comprises" or any other variations thereof is intended to encompass a non-exclusive inclusion, such that a process, method, article, or device that comprises a plurality of elements includes not only those elements but also Other elements, or elements that are inherent to such a process, method, item, or device. An element that is defined by the phrase "comprising a ..." does not exclude the presence of additional equivalent elements in the process, method, item, or device that comprises the element.
尽管本申请中描述的各个部件均为计算机程序,本申请中的任何部分均可以在软件、固件、硬件或者其结合中实现。Although the various components described in this application are all computer programs, any portion of the application can be implemented in software, firmware, hardware or a combination thereof.
尽管这里详细描述了优选的实施例,但是对于本领域熟练的技术人员来说,很显然在不脱离本申请精神的情况下可以作出不同的改变、增加、替换或者类似操作,并且这些均被认为是在权力要求中所定义的本申请的保护范围之内。Although the preferred embodiment has been described in detail herein, it will be apparent to those skilled in the art that various changes, additions, substitutions It is within the scope of the present application as defined in the claims.
以上对本申请所提供的一种基于分布式内存和数据库的数据处理方法、装置及***进行了详细介绍,本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。 The data processing method, device and system based on distributed memory and database provided by the present application are described in detail above. The principle and implementation manner of the present application are described in the specific examples, and the description of the above embodiments is described. It is only used to help understand the method of the present application and its core ideas; at the same time, for those of ordinary skill in the art, according to the idea of the present application, there will be changes in specific implementation manners and application scopes. The contents of this specification are not to be construed as limiting the application.

Claims (16)

  1. 一种基于分布式内存和数据库的数据处理方法,其特征在于,该方法包括:A data processing method based on distributed memory and database, characterized in that the method comprises:
    接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前预算数据的预算标识和预算额度;Receiving a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota;
    依据所述预算标识判断存储所述当前预算数据的当前内存分片中的内存额度是否大于所述预算额度,如果是,则直接在所述当前内存分片中将所述内存额度扣减所述预算额度;Determining, according to the budget identifier, whether a memory credit in a current memory segment storing the current budget data is greater than the budget quota, and if so, directly deducting the memory credit in the current memory segment Budget amount;
    如果否,则依据所述预算标识判断所述当前内存分片中存储的当前数据库剩余额度和所述内存额度之和是否大于所述预算额度,如果是,则依据所述当前数据库剩余额度和内存额度扣减所述预算额度;If yes, determining, according to the budget identifier, whether a sum of a current database remaining amount and the memory quota stored in the current memory segment is greater than the budget quota, and if so, according to the current database remaining credit and memory The amount of the budget is deducted;
    将所述扣减所述预算额度的扣减记录存储至所述当前数据库中,所述当前数据库与所述当前内存分片对应保存相同预算标识的预算数据。And deducting the deduction record of the budget amount into the current database, where the current database and the current memory segment correspond to budget data of the same budget identifier.
  2. 根据权利要求1所述的方法,其特征在于,所述依据所述当前数据库剩余额度和内存额度扣减所述预算额度,具体包括:The method according to claim 1, wherein the deducting the budget amount according to the current database remaining amount and the memory quota includes:
    获取所述预算额度和内存额度的额度差;Obtaining the difference between the budget amount and the memory quota;
    从所述当前数据库剩余额度中扣减所述额度差,并将所述扣减的额度差存储至所述当前内存分片中;Deducting the credit difference from the current database remaining amount, and storing the deducted credit difference into the current memory segment;
    在所述当前内存分片中将存储所述额度差后的内存额度扣减所述预算额度。And deducting the budget amount from the memory credit amount stored in the current memory segment.
  3. 根据权利要求1所述的方法,其特征在于,还包括:The method of claim 1 further comprising:
    获取所述预算标识对应的预算总额度的预设比例的部分额度作为所述内存额度;Obtaining, as the memory quota, a partial quota of a preset proportion of the budget total amount corresponding to the budget identifier;
    将所述内存额度从当前数据库转移至与所述预算标识对应的当前内存分片,其中,所述当前内存分片对应保存有预先设定的多个预算标识的多个内存额度,所述当前数据库保存有所述多个预算标识的预算总额度中除了所述内存额度之外的多个数据库额度;The current memory fragment is transferred from the current database to the current memory fragment corresponding to the budget identifier, where the current memory fragment corresponds to a plurality of memory quotas that are saved with a plurality of preset budget identifiers, where the current The database stores a plurality of database quotas in addition to the memory quota in the budget totality of the plurality of budget identifiers;
    将转移所述内存额度的转移记录存储至所述当前数据库。A transfer record that transfers the memory credit is stored to the current database.
  4. 根据权利要求1所述的方法,其特征在于,还包括: The method of claim 1 further comprising:
    判断所述内存分片所在的机器是否满足针对其保存的多个预算标识而发起的数据处理请求的响应,如果否,则将多个预算标识按预设拆分规则分成多份,并将拆分后的多份预算标识中一份保存至当前内存分片,其他份预算标识则对应保存至多个其他内存分片中;Determining whether the machine where the memory fragment is located satisfies a response to a data processing request initiated by the plurality of budget identifiers saved by the memory fragment, and if not, dividing the plurality of budget identifiers into multiple copies according to a preset splitting rule, and splitting One of the remaining budget identifiers is saved to the current memory segment, and the other budget identifiers are saved to multiple other memory segments;
    将与当前内存分片对应的当前数据库中的多个预算标识按照同样的方式分成多份,并将拆分后的多份预算标识中的一份保留在当前DB,其他份预算标识则对应保存至多个其他数据库中。Multiple budget identifiers in the current database corresponding to the current memory segment are divided into multiple shares in the same manner, and one of the split budget identifiers is retained in the current DB, and other budget identifiers are saved. To multiple other databases.
  5. 根据权利要求1所述的方法,其特征在于,在所述内存分片宕机并重新启动的情况下,还包括:The method according to claim 1, wherein in the case that the memory fragment is down and restarted, the method further includes:
    判断所述内存分片对应的数据库当前额度是否为零,如果否,则将所述数据库当前额度的预设比例的部分额度存储至所述内存分片。Determining whether the current quota of the database corresponding to the memory segment is zero, and if not, storing a partial quota of the preset proportion of the current quota of the database to the memory segment.
  6. 根据权利要求1所述的方法,其特征在于,还包括:The method of claim 1 further comprising:
    判断所述扣减预算额度的操作是否成功,如果是,则通知用户所述预算额度扣减成功;如果否,则通知用户所述预算额度扣减失败。Determining whether the operation of deducting the budget amount is successful, and if yes, notifying the user that the budget amount deduction is successful; if not, notifying the user that the budget amount deduction is failed.
  7. 一种基于分布式内存和数据库的数据补偿方法,其特征在于,该方法包括:数据处理过程和数据补偿过程;A data compensation method based on distributed memory and database, characterized in that the method comprises: a data processing process and a data compensation process;
    其中,所述数据处理过程包括:The data processing process includes:
    接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前预算数据的预算标识和预算额度;Receiving a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota;
    依据所述预算标识判断存储所述当前预算数据的当前内存分片中的内存额度是否大于所述预算额度,如果是,则直接在所述当前内存分片中将所述内存额度扣减所述预算额度;Determining, according to the budget identifier, whether a memory credit in a current memory segment storing the current budget data is greater than the budget quota, and if so, directly deducting the memory credit in the current memory segment Budget amount;
    如果否,则依据所述预算标识判断存储所述当前内存分片中存储的当前数据库剩余额度和所述内存额度之和是否大于所述预算额度,如果是,则从所述当前数据库剩余额度和内存额度中扣减所述预算额度;If not, determining, according to the budget identifier, whether the sum of the current database remaining amount and the memory quota stored in the current memory fragment is greater than the budget quota, and if so, from the current database remaining credit and Deducting the budget amount from the memory quota;
    将所述扣减所述预算额度的记录存储至所述当前数据库中,所述当前数据库与所述当前内存分片对应保存相同预算标识的预算数据;And storing, in the current database, the record of the deduction of the budget quota, where the current database and the current memory segment correspond to budget data of the same budget identifier;
    其中,所述数据补偿过程包括:The data compensation process includes:
    依据待同步的预算标识确定待处理的目标数据库; Determining a target database to be processed according to the budget identifier to be synchronized;
    从所述目标数据库中获取该预算标识对应的所有扣减记录和转移记录,其中,所述转移记录表示将额度从数据库转移至与内存分片的记录;Obtaining, from the target database, all the deduction records and the transfer records corresponding to the budget identifier, wherein the transfer records indicate that the quota is transferred from the database to the records with the memory fragments;
    判断所述所有转移记录所表示的转移总额度值是否大于所述扣减记录所表示的扣减总额度值,如果是,则将所述转移总额度值与所述扣减总额度值的差值作为数据库补偿额度存储至所述目标数据库中;Determining whether the transfer total value represented by the all transfer records is greater than a deduction total value indicated by the deduction record, and if yes, comparing the difference between the transfer total value and the deducted total value The value is stored as a database compensation amount in the target database;
    将存储所述差值的记录更新在所述目标数据库中。A record storing the difference is updated in the target database.
  8. 根据权利要求7所述的方法,其特征在于,还包括:The method of claim 7 further comprising:
    从所述存储差值的记录读取数据库补偿额度;Reading a database compensation quota from the record of the stored difference value;
    将数据库补偿额度发送至与所述目标数据库对应的目标内存分片,以便所述目标内存分片依据所述数据库补偿额度更新存储数据库剩余额度。The database compensation quota is sent to the target memory fragment corresponding to the target database, so that the target memory fragment updates the storage database remaining quota according to the database compensation quota.
  9. 一种基于分布式内存和数据库的数据处理装置,其特征在于,所述装置包括:A data processing device based on a distributed memory and a database, characterized in that the device comprises:
    接收请求单元,用于接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前预算数据的预算标识和预算额度;a receiving request unit, configured to receive a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota;
    第一判断单元,用于依据所述预算标识判断存储所述当前预算数据的当前内存分片中的内存额度是否大于所述预算额度;a first determining unit, configured to determine, according to the budget identifier, whether a memory quota in a current memory segment storing the current budget data is greater than the budget quota;
    第一扣减单元,用于在所述第一判断单元的结果为是的情况下,直接在所述当前内存分片中将所述内存额度扣减所述预算额度;a first deducting unit, configured to deduct the memory quota directly in the current memory segment if the result of the first determining unit is YES;
    第二判断单元,用于在所述第一判断单元的结果为否的情况下,依据所述预算标识判断所述当前内存分片中存储的当前数据库剩余额度和所述内存额度之和是否大于所述预算额度;a second determining unit, configured to determine, according to the budget identifier, whether a sum of a current database remaining amount and the memory amount stored in the current memory segment is greater than The budget amount;
    第二扣减单元,用于在所述第二判断模块的结果为是的情况下,依据所述当前数据库剩余额度和内存额度扣减所述预算额度;a second deducting unit, configured to deduct the budget quota according to the current database remaining amount and the memory quota if the result of the second judging module is YES;
    存储扣减记录单元,用于将所述扣减所述预算额度的扣减记录存储至所述当前数据库中,所述当前数据库与所述当前内存分片对应保存相同预算标识的预算数据。The storage deduction recording unit is configured to store the deduction record of the deduction of the budget quota into the current database, where the current database and the current memory segment correspond to budget data of the same budget identifier.
  10. 根据权利要求9所述的装置,其特征在于,所述第二扣减单元具体包括: The device according to claim 9, wherein the second deduction unit comprises:
    获取模块,用于获取所述预算额度和内存额度的额度差;An obtaining module, configured to obtain a quota difference between the budget quota and the memory quota;
    第一扣减模块,用于从所述当前数据库剩余额度中扣减所述额度差;a first deduction module, configured to deduct the credit difference from the current database remaining credit;
    存储模块,用于将所述扣减的额度差存储至所述当前内存分片中;a storage module, configured to store the deducted credit difference into the current memory segment;
    第二扣减模块,用于在所述当前内存分片中将存储所述额度差后的内存额度扣减所述预算额度。And a second deduction module, configured to deduct the memory quota after storing the credit difference in the current memory segment.
  11. 根据权利要求9所述的装置,其特征在于,还包括:The device according to claim 9, further comprising:
    获取额度单元,用于获取所述预算标识对应的预算总额度的预设比例的部分额度作为所述内存额度;Obtaining a quota unit, configured to obtain a partial quota of a preset proportion of the budget total amount corresponding to the budget identifier as the memory quota;
    转移单元,用于将所述内存额度从当前数据库转移至与所述预算标识对应的当前内存分片,其中,所述当前内存分片对应保存有预先设定的多个预算标识的多个内存额度,所述当前数据库保存有所述多个预算标识的预算总额度中除了所述内存额度之外的多个数据库额度;a transfer unit, configured to transfer the memory quota from a current database to a current memory slice corresponding to the budget identifier, where the current memory slice corresponds to a plurality of memory that stores a plurality of preset budget identifiers a quota, the current database stores a plurality of database quotas in addition to the memory quota in the budget totality of the plurality of budget identifiers;
    存储转移记录单元,用于将转移所述内存额度的转移记录存储至所述当前数据库。And a storage transfer recording unit, configured to store a transfer record that transfers the memory quota to the current database.
  12. 根据权利要求9所述的装置,其特征在于,还包括:The device according to claim 9, further comprising:
    第三判断单元,用于判断所述内存分片所在的机器是否满足针对其保存的多个预算标识而发起的数据处理请求的响应;a third determining unit, configured to determine whether the machine where the memory fragment is located meets a response of a data processing request initiated by the plurality of budget identifiers saved by the memory fragment;
    内存拆分单元,用于在所述第三判断单元的结果为否的情况下,将多个预算标识按预设拆分规则分成多份;a memory splitting unit, configured to divide the plurality of budget identifiers into multiple copies according to a preset splitting rule if the result of the third determining unit is negative;
    内存保存单元,用于并将拆分后的多份预算标识中一份保存至当前内存分片,其他份预算标识则对应保存至多个其他内存分片中;The memory storage unit is configured to save one of the split budget identifiers to the current memory segment, and the other budget identifiers are saved to multiple other memory segments;
    数据库拆分单元,将与当前内存分片对应的当前数据库中的多个预算标识按照同样的方式分成多份;The database splitting unit divides the plurality of budget identifiers in the current database corresponding to the current memory fragment into multiple shares in the same manner;
    数据库保存单元,用于将拆分后的多份预算标识中的一份保留在当前数据库,其他份预算标识则对应保存至多个其他数据库中。A database storage unit is used to keep one of the split budget identifiers in the current database, and other budget identifiers are saved in multiple other databases.
  13. 根据权利要求9所述的装置,其特征在于,在所述内存分片宕机并重新启动的情况下,还包括:The device according to claim 9, wherein in the case that the memory fragment is down and restarted, the method further includes:
    第四判断单元,用于判断所述内存分片对应的数据库当前额度是否为零; a fourth determining unit, configured to determine whether a current quota of the database corresponding to the memory segment is zero;
    加载单元,用于在所述第四判断单元的结果为否的情况下,将所述数据库当前额度的预设比例的部分额度存储至所述内存分片。And a loading unit, configured to store, in the case that the result of the fourth determining unit is no, a partial quota of a preset proportion of the current quota of the database to the memory segment.
  14. 根据权利要求9所述的装置,其特征在于,还包括:The device according to claim 9, further comprising:
    第五判断单元,用于判断所述扣减预算额度的操作是否成功;a fifth determining unit, configured to determine whether the operation of deducting the budget quota is successful;
    第一通知单元,用于在所述第五判断单元的结果为是的情况下,通知用户所述预算额度扣减成功;a first notification unit, configured to notify the user that the budget amount deduction is successful if the result of the fifth determining unit is YES;
    第二通知单元,用于在所述第五判断单元的结果为否的情况下,通知用户所述预算额度扣减失败。The second notification unit is configured to notify the user that the budget amount deduction fails if the result of the fifth determining unit is negative.
  15. 一种数据处理***,其特征在于,该***包括:数据处理装置和数据补偿装置,其中,所述数据处理装置包括:A data processing system, comprising: a data processing device and a data compensation device, wherein the data processing device comprises:
    接收请求单元,用于接收用户触发的数据处理请求,其中,所述数据处理请求包括:当前预算数据的预算标识和预算额度;a receiving request unit, configured to receive a user-triggered data processing request, where the data processing request includes: a budget identifier of the current budget data and a budget quota;
    第一判断单元,用于依据所述预算标识判断存储所述当前预算数据的当前内存分片中的内存额度是否大于所述预算额度;a first determining unit, configured to determine, according to the budget identifier, whether a memory quota in a current memory segment storing the current budget data is greater than the budget quota;
    第一扣减单元,用于在所述第一判断单元的结果为是的情况下,直接在所述当前内存分片中将所述内存额度扣减所述预算额度;a first deducting unit, configured to deduct the memory quota directly in the current memory segment if the result of the first determining unit is YES;
    第二判断单元,用于在所述第一判断单元的结果为否的情况下,依据所述预算标识判断所述当前内存分片中存储的当前数据库剩余额度和所述内存额度之和是否大于所述预算额度;a second determining unit, configured to determine, according to the budget identifier, whether a sum of a current database remaining amount and the memory amount stored in the current memory segment is greater than The budget amount;
    第二扣减单元,用于在所述第二判断模块的结果为是的情况下,依据所述当前数据库剩余额度和内存额度扣减所述预算额度;a second deducting unit, configured to deduct the budget quota according to the current database remaining amount and the memory quota if the result of the second judging module is YES;
    存储扣减记录单元,用于将所述扣减所述预算额度的扣减记录存储至所述当前数据库中,所述当前数据库与所述当前内存分片对应保存相同预算标识的预算数据;a storage deduction record unit, configured to store the deduction record deducting the budget amount into the current database, where the current database and the current memory segment correspond to budget data of the same budget identifier;
    所述数据补偿装置包括:The data compensation device includes:
    确定单元,用于依据待同步的预算标识确定待处理的目标数据库;a determining unit, configured to determine a target database to be processed according to the budget identifier to be synchronized;
    获取记录单元,用于从所述目标数据库中获取该预算标识对应的所有扣减记录和转移记录,其中,所述转移记录表示将额度从数据库转移至与内存分片的记录; Obtaining a record unit, configured to obtain, from the target database, all the deduction records and transfer records corresponding to the budget identifier, where the transfer record indicates that the quota is transferred from the database to the record with the memory segment;
    第六判断单元,用于判断所述所有转移记录所表示的转移总额度值是否大于所述扣减记录所表示的扣减总额度值;a sixth determining unit, configured to determine whether the transfer total value represented by the all transfer records is greater than a deduction total value represented by the deduction record;
    存储补偿额度单元,用于在所述第六判断单元的结果为是的情况下,将所述转移总额度值与所述扣减总额度值的差值作为数据库补偿额度存储至所述目标数据库中;a storage compensation amount unit, configured to store, when the result of the sixth determining unit is YES, a difference between the transfer totality value and the deducted total value as a database compensation amount to the target database in;
    更新单元,用于将存储所述差值的记录更新在所述目标数据库中。And an update unit, configured to update the record storing the difference in the target database.
  16. 根据权利要求15所述的***,其特征在于,所述数据补偿装置还包括:The system of claim 15 wherein said data compensation means further comprises:
    读取额度单元,用于从所述存储差值的记录读取数据库补偿额度;Reading a credit unit for reading a database compensation quota from the record of the stored difference value;
    发送单元,用于将数据库补偿额度发送至与所述目标数据库对应的目标内存分片,以便所述目标内存分片依据所述数据库补偿额度更新存储数据库剩余额度。 And a sending unit, configured to send the database compensation quota to the target memory fragment corresponding to the target database, so that the target memory fragment updates the storage database remaining quota according to the database compensation quota.
PCT/CN2015/084883 2014-08-06 2015-07-23 Data processing method, apparatus and system based on distributed memories and databases WO2016019803A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410384269.4A CN105335297B (en) 2014-08-06 2014-08-06 Data processing method, device and system based on distributed memory and database
CN201410384269.4 2014-08-06

Publications (1)

Publication Number Publication Date
WO2016019803A1 true WO2016019803A1 (en) 2016-02-11

Family

ID=55263129

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2015/084883 WO2016019803A1 (en) 2014-08-06 2015-07-23 Data processing method, apparatus and system based on distributed memories and databases

Country Status (2)

Country Link
CN (1) CN105335297B (en)
WO (1) WO2016019803A1 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109614388A (en) * 2018-11-14 2019-04-12 阿里巴巴集团控股有限公司 Method and apparatus are reduced in a kind of budget
CN109697209A (en) * 2018-12-25 2019-04-30 广东亿迅科技有限公司 A kind of report processing method and device of Based on Distributed database
CN114598649A (en) * 2022-03-17 2022-06-07 苏州浪潮智能科技有限公司 Kernel bandwidth management method and device, storage equipment and storage medium

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106302702B (en) * 2016-08-10 2020-03-20 华为技术有限公司 Data fragment storage method, device and system
CN107463593A (en) * 2016-12-13 2017-12-12 阿里巴巴集团控股有限公司 Stock reduces method and its equipment
CN106850849A (en) * 2017-03-15 2017-06-13 联想(北京)有限公司 A kind of data processing method, device and server
CN108874809A (en) * 2017-05-10 2018-11-23 北京京东尚科信息技术有限公司 Data processing method and device, electronic equipment, storage medium
CN109118361B (en) * 2018-07-20 2022-01-28 创新先进技术有限公司 Method, device and system for managing limit
CN110310060B (en) * 2019-05-27 2023-10-24 创新先进技术有限公司 Inventory management method and device based on fragments
CN110648232A (en) * 2019-08-20 2020-01-03 上海数据交易中心有限公司 Method and device for controlling limit of processing node, storage medium and terminal
CN111143386A (en) * 2019-12-25 2020-05-12 中国建设银行股份有限公司 Method and device for processing bond line data
CN111221912A (en) * 2020-01-06 2020-06-02 中科驭数(北京)科技有限公司 Data synchronization method and device between database and hardware
CN111899088B (en) * 2020-06-23 2023-04-18 四川新网银行股份有限公司 Accurate asset limit calculation method under high-concurrency data flow field scene
CN112069253A (en) * 2020-08-20 2020-12-11 上海钧正网络科技有限公司 Inventory item management method, system, terminal and storage medium suitable for multiple scenes
CN113139004B (en) * 2021-04-25 2024-03-01 中国工商银行股份有限公司 Method and device for controlling credit, computer equipment and computer readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070143248A1 (en) * 2005-12-19 2007-06-21 Yahoo! Inc. Method using query processing servers for query processing of column chunks in a distributed column chunk data store
CN101122885A (en) * 2007-09-11 2008-02-13 腾讯科技(深圳)有限公司 Data cache processing method, system and data cache device
CN102222107A (en) * 2011-06-28 2011-10-19 中国联合网络通信集团有限公司 Data access system and method
CN103544153A (en) * 2012-07-10 2014-01-29 阿里巴巴集团控股有限公司 Data updating method and system based on database

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20070143248A1 (en) * 2005-12-19 2007-06-21 Yahoo! Inc. Method using query processing servers for query processing of column chunks in a distributed column chunk data store
CN101122885A (en) * 2007-09-11 2008-02-13 腾讯科技(深圳)有限公司 Data cache processing method, system and data cache device
CN102222107A (en) * 2011-06-28 2011-10-19 中国联合网络通信集团有限公司 Data access system and method
CN103544153A (en) * 2012-07-10 2014-01-29 阿里巴巴集团控股有限公司 Data updating method and system based on database

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109614388A (en) * 2018-11-14 2019-04-12 阿里巴巴集团控股有限公司 Method and apparatus are reduced in a kind of budget
CN109697209A (en) * 2018-12-25 2019-04-30 广东亿迅科技有限公司 A kind of report processing method and device of Based on Distributed database
CN114598649A (en) * 2022-03-17 2022-06-07 苏州浪潮智能科技有限公司 Kernel bandwidth management method and device, storage equipment and storage medium
CN114598649B (en) * 2022-03-17 2023-08-04 苏州浪潮智能科技有限公司 Kernel bandwidth management method, device, storage equipment and storage medium

Also Published As

Publication number Publication date
CN105335297B (en) 2018-05-08
CN105335297A (en) 2016-02-17

Similar Documents

Publication Publication Date Title
WO2016019803A1 (en) Data processing method, apparatus and system based on distributed memories and databases
US10872066B2 (en) Systems and methods of database tenant migration
US8694733B2 (en) Slave consistency in a synchronous replication environment
US20230100223A1 (en) Transaction processing method and apparatus, computer device, and storage medium
US9031910B2 (en) System and method for maintaining a cluster setup
US20230259528A1 (en) Synchronization cache seeding
CN106802932B (en) Routing method and device of database and database system
US20160212206A1 (en) Deterministic database system and data transferring method thereof
US20150032695A1 (en) Client and server integration for replicating data
US10489378B2 (en) Detection and resolution of conflicts in data synchronization
US8494888B2 (en) Offline modification of business data
WO2016074370A1 (en) Keyvalue database data table updating method and data table updating device
WO2022111188A1 (en) Transaction processing method, system, apparatus, device, storage medium, and program product
CN110633378A (en) Graph database construction method supporting super-large scale relational network
WO2022095366A1 (en) Redis-based data reading method and apparatus, device, and readable storage medium
WO2018006723A1 (en) Database data modification request processing method and apparatus
EP4307137A1 (en) Transaction processing method, distributed database system, cluster, and medium
WO2019033741A1 (en) Investment commodity resource processing method, device, storage medium and computer apparatus
Arrieta-Salinas et al. Classic replication techniques on the cloud
US11196806B2 (en) Method and apparatus for replicating data between storage systems
US20210263919A1 (en) Centralized Storage for Search Servers
US11625503B2 (en) Data integrity procedure
US10671482B2 (en) Providing consistency in a distributed data store
CN114579559A (en) Data synchronization method and device, computer equipment and storage medium
WO2023066222A1 (en) Data processing method and apparatus, and electronic device, storage medium and program product

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 15829241

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 15829241

Country of ref document: EP

Kind code of ref document: A1