Service delay method, device, computer equipment and storage medium

文档序号:1963595 发布日期:2021-12-14 浏览:11次 中文

阅读说明:本技术 一种业务延迟方法、装置、计算机设备和存储介质 (Service delay method, device, computer equipment and storage medium ) 是由 王海勇 陈愿 储亮 王泽� 王杰 于 2021-09-17 设计创作,主要内容包括:本申请涉及一种业务延迟方法、装置、计算机设备和存储介质。方法包括:准备延迟容器,初始化容错标识;执行业务逻辑,遍历每个业务,将可延迟业务存放到延迟容器中,形成可延迟列表;遍历延迟容器的可延迟列表,依次执行可延迟业务。本发明在能够解决问题的同时,能够避免对原有业务产生巨大改动,并且通过封装和容错处理,使得业务使用中能做到安枕无忧。(The application relates to a service delay method, a service delay device, computer equipment and a storage medium. The method comprises the following steps: preparing a delay container and initializing a fault-tolerant identifier; executing service logic, traversing each service, and storing the delay-able service into a delay container to form a delay-able list; and traversing the delay container delay list and executing delay service in turn. The invention can solve the problems, avoid great change to the original service, and realize easy rest in service use through packaging and fault-tolerant processing.)

1. A method for traffic delay, the method comprising:

preparing a delay container and initializing a fault-tolerant identifier;

executing service logic, traversing each service, and storing the delay-able service into the delay container to form a delay-able list;

traversing the deferrable list of the deferrable container and executing deferrable traffic in turn.

2. The method of claim 1, wherein initializing fault tolerance flags comprises: and (4) modifying the fault-tolerant identification into initialized fault-tolerant identification, closing a fault-tolerant mechanism and normally executing functions.

3. The method of claim 1, wherein the executing the service logic, traversing each service, depositing deferrable services into the delay container, comprises:

dividing the service into delay service and non-delay service, executing each service in turn without changing the logic sequence of the service, and storing the delay service into the delay container when the delay service is executed until all the non-delay service is executed.

4. The method of claim 3, wherein all non-deferrable transactions are performed before committing the database transaction and then traversing the deferrable list of the deferrable container to perform the deferrable transactions in turn.

5. The method of claim 3, wherein the undelayable traffic belongs to database operations, wherein the undelayable traffic belongs to non-database operations, and wherein the undelayable traffic and the undelayable traffic are associated with each other.

6. The method of claim 1 wherein the add method is invoked to change the original code snippet to an anonymous inner class at the deferrable service location.

7. A traffic delay apparatus, characterized in that the apparatus comprises:

the initialization module is used for preparing a delay container and initializing the fault-tolerant identification;

the first execution module is used for executing the service logic, traversing each service, and storing the delay-able service into the delay container to form a delay-able list;

and the second execution module is used for traversing the delay list of the delay container and sequentially executing the delay service.

8. The apparatus of claim 7, wherein the first execution module divides services into deferrable services and non-deferrable services, executes each service in turn without changing a service logic sequence, and stores the deferrable services into the delay container when the deferrable services are executed until all the non-deferrable services are executed.

9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the method of any of claims 1 to 6 are implemented when the computer program is executed by the processor.

10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 6.

Technical Field

The present application relates to the technical field of service development, and in particular, to a service delay method, apparatus, computer device, and storage medium.

Background

The prior art has problems in the following scenes:

scene one: database and cache data consistency

Taking an order as an example, when the order is created, the order data is often cached in the Redis, and if the table-storing transaction is not submitted and the caching is successful, in the subsequent operation, the problem of inconsistent caching is caused because the whole database transaction is abnormally rolled back.

Scene two: database transaction untimely commit causing dirty data

In a data issuing scene, data is stored in an issuing table and is asynchronously sent to the periphery through a message queue, and the data is deleted after a receipt is received. It is possible that the store table transaction is not committed, and the downstream system is processing fast and immediately feeds back the receipt. Subsequent delete operations do not actually delete the data because the previous transaction did not commit. Thus, when the original database transaction commits, garbage data is generated. This type of data is actually data that has already been sent, and it may appear to maintenance personnel that the data has not been received downstream and needs to be manually resent once.

Scene three: upstream and downstream data inconsistency

During the business process, interaction with other systems is needed, and the interaction has state notification, data distribution and the like. When data is stored in a database, if a transaction is not submitted, the data is sent to the periphery, at the moment, the peripheral system receives a message, and the self system fails to succeed in business because of the rollback of the database transaction. In such a scenario, a problem of data inconsistency occurs in the entire service link, and a plurality of systems may be affected in a case of a large influence.

In order to solve the above problems, the mainstream method is: in order to ensure the integrity of the rollback of the database transaction, the business logic of the non-transaction is moved outside the database transaction, the operation of the non-database transaction is executed after the database transaction is successful, and if the transaction fails, the execution of the subsequent logic is stopped.

However, the above method has the following disadvantages and shortcomings:

1. and (3) service logic: in business, database operation and business operation are often paired, and for example, storing in a database and storing in a cache should be a pair of operations. If the logic of the storage and the cache is separated, the business logic is likely to be split, and the code is not smooth.

2. Parameter transmission: when a group of data is stored in a database, other business logic is often required to be executed, database operation is separately executed, and a long transmission link may be required for parameter transmission.

3. Service transformation: often, the data consistency between the transaction and the non-transaction is ignored in the normal business process, and the inconsistency is often caused by abnormality or concurrency. Therefore, the scene is not planned in advance in the service development process, and the reconstruction cost is very high after problems occur.

Disclosure of Invention

The present invention is directed to solving the problem of transactional and non-transactional data consistency. In view of the foregoing, it is necessary to provide a service delay method, apparatus, computer device and storage medium from the perspective of back-end service development or architecture.

A method of traffic delay, the method comprising:

and preparing a delay container and initializing fault-tolerant identification.

And executing service logic, traversing each service, and storing the delay-capable services into a delay container to form a delay-capable list.

And traversing the delay container delay list and executing delay service in turn.

In one embodiment, initializing a fault tolerance flag comprises: and modifying the delay fault tolerance mark into initialized state, closing the delay fault tolerance mechanism, and normally executing the function.

In one embodiment, executing the service logic to traverse each service to deposit deferrable services into a delay container comprises:

the service is divided into delay service and non-delay service, the logic sequence of the service is not changed, each service is executed in sequence, and when the delay service is executed, the delay service is stored in a delay container until all the non-delay service is executed.

In one embodiment, after all non-deferrable transactions have been executed, the database transaction is committed and then the deferrable list of deferrable containers is traversed to execute the deferrable transactions in turn.

In one embodiment, the non-deferrable traffic is of a database operation, the deferrable traffic is of a non-database operation, and the deferrable traffic and the non-deferrable traffic are associated with one another.

In one embodiment, the add method is invoked to change the original code snippet to an anonymous inner class at the deferrable service location.

A traffic delay apparatus, the device comprising:

and the initialization module is used for preparing the delay container and initializing the fault-tolerant identification.

And the first execution module is used for executing the service logic, traversing each service, and storing the delay-capable services into the delay container to form a delay-capable list.

And the second execution module is used for traversing the delay list of the delay container and sequentially executing the delay service.

In one embodiment, the first execution module divides services into deferrable services and non-deferrable services, does not change the logic sequence of the services, executes each service in sequence, and stores the deferrable services into the delay container when the deferrable services are executed until all the non-deferrable services are executed.

A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the method of any of the above embodiments when executing the computer program.

A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of any of the above embodiments.

The service delay method, the service delay device, the computer equipment and the storage medium have the following technical effects:

avoiding faults: the problem of inconsistency between the database transaction data and the non-database transaction data can be effectively avoided, and therefore business faults caused by the reasons are avoided.

And (3) reducing abnormality: by reducing the generation of abnormal data, various exceptions caused by data inconsistency of the system and the upstream and downstream are avoided.

Cost reduction and efficiency improvement: the problem of data inconsistency is often caused by harsh conditions and high concurrency, the reason is difficult to locate in production, and once the situation is found, products, tests and developers are often required to check the reason. By using the technical scheme, the occurrence of the situation can be directly avoided, and unnecessary personnel consumption is avoided. .

Drawings

FIG. 1 is a diagram of an exemplary implementation of a traffic delay method;

fig. 2 is a flow chart illustrating a traffic delay method according to an embodiment;

fig. 3 is a schematic service flow diagram of a service delay method in an embodiment;

FIG. 4 is a diagram illustrating data dependency of a traffic delay method according to an embodiment;

FIG. 5 is a diagram illustrating a service logic implementation of a service delay method in one embodiment;

fig. 6 is a schematic diagram of a deferrable service implementation of a service deferral method in one embodiment;

FIG. 7 is a block diagram of a traffic delay apparatus in one embodiment;

FIG. 8 is a diagram illustrating an internal structure of a computer device according to an embodiment.

Detailed Description

In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.

The service delay method provided by the application can be applied to the application environment shown in fig. 1. Wherein the data source terminal 20 communicates with the database device 10 through the network 30 by performing network communication. The data source terminal 20 may be plural in number, and is used to upload various data to the database device 10. The data source terminal 20 may be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices. Further, the data management device 40 is in network communication with the database device 10, for transmitting data processing instructions to the database device 10.

In one embodiment, as shown in fig. 2, a traffic delay method is provided, which is described by taking the example that the method is applied to the database device 10 in fig. 1, and a delay component is adopted, and the method comprises the following steps:

s100, preparing a delay container and initializing a fault-tolerant identifier.

In this embodiment, the delay container is prepared, the fault-tolerant flag of the delay component is modified to be initialized, the fault-tolerant mechanism of the delay component is closed, and the predetermined function is normally executed.

S200, executing service logic, traversing each service, and storing the delay-capable services into a delay container to form a delay-capable list.

In this embodiment, the services are divided into deferrable services and non-deferrable services, the non-deferrable services belong to database operations, the deferrable services belong to non-database operations, and the deferrable services and the non-deferrable services are associated with each other. And sequentially executing each service without changing the original service logic sequence, and storing the delay-capable services into a delay container when the delay-capable services are executed until all the delay-incapable services are executed. And when the original service is executed, submitting the database transaction. While the delayed service logic is not executed.

In this way, for the delay service and the non-delay service which are mutually associated, no change is ensured on the code structure, and the parameters can be used in time, so that the service data is not split. While the delay containers become a traffic bridge.

S300, traversing the delay container delay list, and executing delay service in turn.

In this embodiment, after all the non-deferrable services are executed, the database transaction is committed, and then the deferrable list of the deferrable container is traversed to execute the deferrable services in turn.

In one embodiment, the original code needs to be modified, the delay component defines a uniform entry, and the original code entry is handed to the entry without modification, and can be managed by the delay component. Meanwhile, at the original position of the delay service, the service delay method calls the add () method to change the original code segment into an anonymous internal class.

In one embodiment, the delay component provides only two api's externally: handle () and add (). The handle () method performs the functions of initializing, invoking business logic, and invoking deferred services. add () is then responsible for adding deferrable traffic to the defer list. The two methods are used for realizing external shielding details, and the simplicity of the delay assembly is ensured.

The delay component is internally ensured to be convenient to call through a static method, and parameter transfer and code reference are ensured to be flexible and free by combining with Threadlocal.

In one embodiment, the traffic is executed in handle (). But the function that needs to be delayed is not added to the delay list by the add () method, which is the case when the delay function provided by the component is not used, but has no effect on the original service.

In one embodiment, the traffic is not executed in handle (). But the add () method is called. At this time, since the handle () method is not used up, the component is not initialized, and when the add () method is executed, it is determined according to the initialization flag, and at this time, the original statement is directly executed, instead of being added to the list, so that there is no influence on the original service.

It should be understood that, although the steps in the flowchart are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in the figures may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.

In one embodiment, a specific business process is specifically described. As shown in the service flow of fig. 3, the conventional delay service (deferrabeservice) includes service 1, service 2, service 3, service 4, service 5, service 6, … …, service 2n-1, and service 2 n. Therein, businesses 1, 3, 5, … …, 2n-1 belong to database operations (dboperation), and businesses 2, 4, 6, … …, 2n belong to non-database operations (Deferrable). Preferably, services 1 and 2, services 3 and 4, services 5 and 6, … …, and services 2n-1 and 2n are again associated with each other.

As shown in the Data correlation of fig. 4, the services 1 and 2 use the same Data (Data1), the services 3 and 4 use the same Data (Data2), the services 5 and 6 use the same Data (Data3), … …, and the services 2n-1 and 2n use the same Data (Datan).

Therefore, to solve the transactional and non-transactional uniqueness problem, it is necessary to change the execution order, execute the business 1, 3, 5 … …, 2n-1 operations first and commit the transaction. Meanwhile, the database transaction is committed after the database is completed as a whole, and then the transactions 2, 4, 6 … …, 2n are executed.

As shown in the service execution logic of fig. 5, the delayable services 2, 4, 6, … …, and 2n are stored in the delayable list of the delay container (context) without changing the order of the service logic, and when the original service is executed, the database transaction is committed. While the delayed traffic 2, 4, 6, … …, 2n is not performed. In so doing, services 1 and 2, services 3 and 4, services 5 and 6, … …, and services 2n-1 and 2n, which guarantee no change in code structure, parameters can be used in time without traffic data fragmentation, and delay containers become bridges.

As shown in the deferrable service execution logic of fig. 6, services 2, 4, 6, … …, and 2n in the deferrable list of the deferrable container are traversed and executed in sequence.

Preferably, only service 1 (save order), service 2 (cache order), service 3 (save release), and service 4 (release order) may be included in the conventional service, and service 1 and 2 use the same order information Data (Data1), and service 3 and 4 use the same release Data (Data 2).

In one embodiment, the traffic delay method described above may be used in the following scenarios: the data consistency of the database and the cache of the data of orders, commodities, configurations and the like.

In one embodiment, the traffic delay method described above may be used in the following scenarios: the data sending peripheral system succeeds, the data is deleted after the receipt is received, but the transaction for storing the data is not submitted yet, so that the false phenomenon that the data is not sent down is caused, and dirty data is formed.

In one embodiment, the traffic delay method described above may be used in the following scenarios: the data delivery is successful, but the local transaction rolls back.

The business delay method of the invention is an effective, very wide applicable and easy-to-popularize solution for solving the consistency of database affairs and non-database affair data. The problem can be solved, the original service can be prevented from being changed greatly, and the service can be used without worry through packaging and fault-tolerant processing.

In one embodiment, as shown in fig. 7, there is provided a traffic delay apparatus, including: an initialization module 100, a first execution module 200, and a second execution module 300, wherein:

an initialization module 100 is used for preparing a delay container and initializing fault-tolerant identification.

The first execution module 200 is configured to execute the service logic, traverse each service, and store the deferrable service in the deferrable container to form a deferrable list.

A second executing module 300, configured to traverse the deferrable list of the deferrable container and execute the deferrable service in turn.

In one embodiment, the first execution module 200 divides the services into deferrable services and non-deferrable services, executes each service in sequence without changing the logic sequence of the services, and stores the deferrable services into the delay container when the deferrable services are executed until all the non-deferrable services are executed.

For the specific definition of the service delay apparatus, reference may be made to the above definition of the service delay method, which is not described herein again. The modules in the traffic delay apparatus may be implemented in whole or in part by software, hardware, and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.

In one embodiment, a computer device is provided, which may be a data management server, and its internal structure diagram may be as shown in fig. 8. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer equipment is used for communicating with an external data source terminal through network connection so as to receive data uploaded by the data source terminal. The computer program is executed by a processor to implement a traffic delay method.

Those skilled in the art will appreciate that the architecture shown in fig. 8 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.

In one embodiment, a computer device is provided, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, and the processor implements the traffic delay method when executing the computer program.

It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

The invention provides a method for solving the consistency of transaction and non-transaction data, and provides a service delay method, a service delay device, computer equipment and a storage medium. In general, the problems solved by the invention exist in businesses of all industries and are ubiquitous problems. From the aspect of simplicity, if all services are required to be strictly modified, the cost is very high by using the traditional scheme, and the invention can simplify the difficulty of modification to the greatest extent. From the aspect of fault tolerance, when the consistency problem of transactions and non-transactions occurs, the invention can not introduce new problems in the process of transformation, and even if the calling component mode is wrong in the development process, the invention can not cause business problems.

The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.

The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

12页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种分布式存储系统的异常处理方法、系统及装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!