CN116775669A - Data processing method, device, electronic equipment and computer storage medium - Google Patents
Data processing method, device, electronic equipment and computer storage medium Download PDFInfo
- Publication number
- CN116775669A CN116775669A CN202211430884.5A CN202211430884A CN116775669A CN 116775669 A CN116775669 A CN 116775669A CN 202211430884 A CN202211430884 A CN 202211430884A CN 116775669 A CN116775669 A CN 116775669A
- Authority
- CN
- China
- Prior art keywords
- data
- lock
- target
- release time
- time period
- Prior art date
- Legal status (The legal status 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 status listed.)
- Pending
Links
Landscapes
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本申请实施例提供一种数据处理方法、装置、电子设备和计算机存储介质,该方法包括:拦截当前时间段内服务端接收的多个数据操作请求;所述数据操作请求用于对操作数据进行写入操作或删除操作;统计所述当前时间段内完成多个操作数据对应的数据流入速率;所述数据流入速率包括数据写入速率和数据删除速率中的至少一种;基于所述数据流入速率,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间;如此,根据数据流入速率实现锁的释放时间的弹性伸缩,提高高并发场景下的数据处理效率。
Embodiments of the present application provide a data processing method, device, electronic equipment and computer storage medium. The method includes: intercepting multiple data operation requests received by the server within the current time period; the data operation requests are used to perform operation data Write operation or deletion operation; count the data inflow rate corresponding to multiple operation data completed in the current time period; the data inflow rate includes at least one of the data write rate and the data deletion rate; based on the data inflow rate to determine the lock release time corresponding to each target data operation request received in the next time period; in this way, the lock release time can be elastically scaled according to the data inflow rate, improving data processing efficiency in high concurrency scenarios.
Description
技术领域Technical field
本申请涉及计算机技术领域,尤其涉及一种数据处理方法、装置、电子设备和计算机存储介质。The present application relates to the field of computer technology, and in particular, to a data processing method, device, electronic equipment and computer storage medium.
背景技术Background technique
数据的存储往往会存在这样的问题:如何保持数据删写的一致性;关系型数据库管理系统(MYSQL,My Structured Query Language)、结构化查询语言(Structured QueryLanguage Sever,SqlSever)、Oracle等关系类型数据库可以通过键关联的操作方式进行解决;但当用户对数据的读写速度有严格的要求时,就需要用到非关系类型数据库,首先想到的就是Redis数据库。There are often problems in data storage: how to maintain the consistency of data deletion and writing; relational database management systems (MYSQL, My Structured Query Language), Structured Query Language Sever (SqlSever), Oracle and other relational databases It can be solved through key association operation; but when users have strict requirements on data reading and writing speed, they need to use a non-relational database. The first thing that comes to mind is the Redis database.
Redis数据库通常使用锁机制的操作方式,即,Redis锁,简称锁,当某一线程对某一对象数据进行操作时,获取该对象数据的锁,当另一线程访问该对象数据时如果拿不到锁,则等待执行。这一操作方式虽然能够确保层级关联数据删写的一致性,但存在线程等待等问题,导致高并发场景下的数据处理效率较低。Redis database usually uses the lock mechanism to operate, that is, Redis lock, referred to as lock. When a thread operates on a certain object data, it acquires the lock of the object data. When another thread accesses the object data, if it cannot If the lock is reached, wait for execution. Although this operation method can ensure the consistency of deletion and writing of hierarchical associated data, there are problems such as thread waiting, resulting in low data processing efficiency in high concurrency scenarios.
发明内容Contents of the invention
本申请实施例提供一种数据处理方法、装置、电子设备和计算机存储介质,能够提高高并发场景下的数据处理效率。Embodiments of the present application provide a data processing method, device, electronic device, and computer storage medium, which can improve data processing efficiency in high concurrency scenarios.
本申请实施例的技术方案是这样实现的:The technical solution of the embodiment of this application is implemented as follows:
本申请实施例提供了一种数据处理方法,所述方法包括:The embodiment of the present application provides a data processing method, which method includes:
拦截当前时间段内服务端接收的多个数据操作请求;所述数据操作请求用于对操作数据进行写入操作或删除操作;Intercept multiple data operation requests received by the server within the current time period; the data operation requests are used to write or delete operation data;
统计所述当前时间段内完成多个操作数据对应的数据流入速率;所述数据流入速率包括数据写入速率和数据删除速率中的至少一种;Count the data inflow rate corresponding to multiple operation data completed within the current time period; the data inflow rate includes at least one of a data writing rate and a data deletion rate;
基于所述数据流入速率,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间;Based on the data inflow rate, determine the release time of the lock corresponding to each target data operation request received within the next time period;
基于确定后的所述锁的释放时间,执行与所述每个目标数据操作请求对应的操作。Based on the determined release time of the lock, an operation corresponding to each target data operation request is performed.
在一些实施例中,在所述数据流入速率包括数据写入速率和数据删除速率的情况下,所述基于所述数据流入速率,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间,包括:In some embodiments, in the case where the data inflow rate includes a data write rate and a data deletion rate, based on the data inflow rate, it is determined that each target data operation request received in the next time period corresponds to The lock release time includes:
获取所述当前时间段内锁的写入释放时间和删除释放时间;Obtain the write release time and delete release time of the lock within the current time period;
确定所述数据写入速率和所述当前时间段内锁的写入释放时间的第一比值,以及所述数据删除速率和所述当前时间段内锁的删除释放时间的第二比值;Determine a first ratio between the data writing rate and the write release time of the lock in the current time period, and a second ratio between the data deletion rate and the deletion release time of the lock in the current time period;
基于所述第一比值和所述第二比值,确定所述下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间。Based on the first ratio and the second ratio, the release time of the lock corresponding to each target data operation request received within the next time period is determined.
在一些实施例中,所述基于所述第一比值和所述第二比值,确定所述下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间,包括:In some embodiments, determining the release time of the lock corresponding to each target data operation request received within the next time period based on the first ratio and the second ratio includes:
对所述第一比值和所述第二比值进行调整,使得所述第一比值和所述第二比值相等;Adjust the first ratio and the second ratio so that the first ratio and the second ratio are equal;
基于调整后的所述第一比值和所述第二比值,确定所述下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间。Based on the adjusted first ratio and the second ratio, the release time of the lock corresponding to each target data operation request received within the next time period is determined.
在一些实施例中,所述基于确定后的所述锁的释放时间,执行与所述每个目标数据操作请求对应的操作,包括:In some embodiments, performing an operation corresponding to each target data operation request based on the determined release time of the lock includes:
对于所述每个目标数据操作请求,获取目标操作数据的锁;所述目标数据操作请求用于对所述目标操作数据进行写入操作或删除操作;For each target data operation request, obtain the lock of the target operation data; the target data operation request is used to perform a write operation or delete operation on the target operation data;
基于确定后的所述锁的释放时间,对所述目标操作数据进行加锁操作,并根据所述目标数据操作请求对所述目标操作数据执行相应操作。Based on the determined release time of the lock, a locking operation is performed on the target operation data, and corresponding operations are performed on the target operation data according to the target data operation request.
在一些实施例中,所述获取目标操作数据的锁,包括:In some embodiments, obtaining the lock of target operation data includes:
从Redis数据库中获取所述目标操作数据的锁;所述目标操作数据的锁为key-value形式的锁,所述key值为所述目标操作数据的标识,所述value值为所述目标操作数据的锁的释放时间。Obtain the lock of the target operation data from the Redis database; the lock of the target operation data is a lock in the form of key-value, the key value is the identification of the target operation data, and the value value is the target operation The release time of the data lock.
在一些实施例中,所述方法还包括:In some embodiments, the method further includes:
对所述每个目标数据操作请求对应的执行过程进行监听,直至监听时长达到所述确定后的所述锁的释放时间,对所述目标操作数据的锁进行释放操作。The execution process corresponding to each target data operation request is monitored until the monitoring time reaches the determined release time of the lock, and the lock of the target operation data is released.
在一些实施例中,所述方法还包括:In some embodiments, the method further includes:
在所述监听时长达到所述确定后的所述锁的释放时间,且检测到所述目标操作数据的锁未被释放的情况下,对所述目标操作数据的执行进行回滚操作。When the listening duration reaches the determined release time of the lock and it is detected that the lock of the target operation data has not been released, a rollback operation is performed on the execution of the target operation data.
本申请实施例提供一种数据处理装置,所述装置包括拦截模块、统计模块、确定模块和执行模块,其中,Embodiments of the present application provide a data processing device, which includes an interception module, a statistics module, a determination module and an execution module, wherein,
拦截模块,用于拦截当前时间段内服务端接收的多个数据操作请求;所述数据操作请求用于对操作数据进行写入操作或删除操作;The interception module is used to intercept multiple data operation requests received by the server within the current time period; the data operation requests are used to write or delete operation data;
统计模块,用于统计所述当前时间段内完成多个操作数据对应的数据流入速率;所述数据流入速率包括数据写入速率和数据删除速率中的至少一种;A statistics module, used to count the data inflow rate corresponding to multiple operation data completed within the current time period; the data inflow rate includes at least one of a data writing rate and a data deletion rate;
确定模块,用于基于所述数据流入速率,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间;A determination module configured to determine, based on the data inflow rate, the release time of the lock corresponding to each target data operation request received within the next time period;
执行模块,用于基于确定后的所述锁的释放时间,执行与所述每个目标数据操作请求对应的操作。An execution module, configured to execute an operation corresponding to each target data operation request based on the determined release time of the lock.
本申请实施例提供一种电子设备,所述设备包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现前述一个或多个技术方案提供的数据处理方法。Embodiments of the present application provide an electronic device. The device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, one or more of the aforementioned technologies are implemented. The data processing method provided by the plan.
本申请实施例提供一种计算机存储介质,所述计算机存储介质存储有计算机程序;所述计算机程序被执行后能够实现前述一个或多个技术方案提供的数据处理方法。Embodiments of the present application provide a computer storage medium that stores a computer program; after being executed, the computer program can implement the data processing method provided by one or more of the foregoing technical solutions.
本申请实施例提供一种数据处理方法、装置、电子设备和计算机存储介质,该方法包括:拦截当前时间段内服务端接收的多个数据操作请求;所述数据操作请求用于对操作数据进行写入操作或删除操作;统计所述当前时间段内完成多个操作数据对应的数据流入速率;所述数据流入速率包括数据写入速率和数据删除速率中的至少一种;基于所述数据流入速率,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间;基于确定后的所述锁的释放时间,执行与所述每个目标数据操作请求对应的操作。Embodiments of the present application provide a data processing method, device, electronic equipment and computer storage medium. The method includes: intercepting multiple data operation requests received by the server within the current time period; the data operation requests are used to perform operation data Write operation or deletion operation; count the data inflow rate corresponding to multiple operation data completed in the current time period; the data inflow rate includes at least one of the data write rate and the data deletion rate; based on the data inflow rate, determine the release time of the lock corresponding to each target data operation request received within the next time period; based on the determined release time of the lock, perform the operation corresponding to each target data operation request.
可以看出,本申请实施例中,通过拦截当前时间段内的每个数据操作请求,以统计该时间段内的数据流入速率,进而动态调整下一时间段内各个目标数据操作请求对应的锁的释放时间,即,能够实现锁的释放时间的弹性伸缩;对于高并发场景,因为锁的释放时间是根据数据流入速率动态调整的,即,不同的数据流入速率对应不同的锁的释放时间,因而,可以确保在锁的释放时间内尽可能地完成数据的删写操作,保证数据删写操作一致性的同时优化线程等待的问题,提高高并发场景下的数据处理效率。It can be seen that in the embodiment of the present application, each data operation request in the current time period is intercepted to count the data inflow rate in the time period, and then dynamically adjust the lock corresponding to each target data operation request in the next time period. The release time of the lock, that is, can achieve elastic expansion and contraction of the lock release time; for high concurrency scenarios, because the lock release time is dynamically adjusted according to the data inflow rate, that is, different data inflow rates correspond to different lock release times, Therefore, it is possible to ensure that data deletion and writing operations are completed as much as possible within the lock release time, ensuring the consistency of data deletion and writing operations while optimizing the thread waiting problem and improving data processing efficiency in high concurrency scenarios.
附图说明Description of drawings
图1为本申请实施例提供的一种数据处理方法的流程示意图;Figure 1 is a schematic flow chart of a data processing method provided by an embodiment of the present application;
图2为本申请实施例提供的一种对操作数据进行写入和删除操作的流程示意图;Figure 2 is a schematic flow chart of writing and deleting operation data provided by an embodiment of the present application;
图3为本申请实施例提供的另一种数据处理方法的流程示意图;Figure 3 is a schematic flow chart of another data processing method provided by an embodiment of the present application;
图4为本申请实施例提供的一种数据处理装置的结构示意图;Figure 4 is a schematic structural diagram of a data processing device provided by an embodiment of the present application;
图5为本申请实施例提供的电子设备的结构示意图。FIG. 5 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
具体实施方式Detailed ways
下面将结合本申请中的附图,对本申请中的技术方案进行清楚、完整地描述。The technical solution in this application will be clearly and completely described below in conjunction with the accompanying drawings in this application.
以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所提供的实施例仅仅用以解释本申请,并不用于限定本申请。另外,以下所提供的实施例是用于实施本申请的部分实施例,而非提供实施本申请的全部实施例,在不冲突的情况下,本申请记载的技术方案可以任意组合的方式实施。The present application will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the embodiments provided here are only used to explain the present application and are not used to limit the present application. In addition, the embodiments provided below are partial embodiments for implementing the present application, rather than providing all the embodiments for implementing the present application. The technical solutions described in the present application can be implemented in any combination as long as there is no conflict.
需要说明的是,在本申请中,术语“包括”、“包含”或者其任何其它变体意在涵盖非排他性的包含,从而使得包括一系列要素的方法或者装置不仅包括所明确记载的要素,而且还包括没有明确列出的其它要素,或者是还包括为实施方法或者装置所固有的要素。在没有更多限制的情况下,由语句“包括一个......”限定的要素,并不排除在包括该要素的方法或者装置中还存在另外的相关要素(例如方法中的步骤或者装置中的单元,例如的单元可以是部分处理器、部分程序或软件等等)。It should be noted that in this application, the terms "comprising", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a method or device including a series of elements not only includes the explicitly stated elements, It also includes other elements that are not explicitly listed or that are intrinsic to the implementation of the method or apparatus. Without further limitation, an element defined by the statement "comprises a..." does not exclude the presence of other related elements (such as steps in the method or devices) in the method or device including the element. A unit in the device, for example, a unit may be part of a processor, part of a program or software, etc.).
本文中术语“和/或”,仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,C和/或D,可以表示:单独存在C,同时存在C和D,单独存在D这三种情况。另外,本文中术语“至少一种”表示多种中的任意一种或多种中的至少两种的任意组合,例如,包括C、D、E中的至少一种,可以表示包括从C、D和E构成的集合中选择的任意一个或多个元素。The term "and/or" in this article is just an association relationship that describes related objects, indicating that three relationships can exist. For example, C and/or D can mean: C exists alone, C and D exist simultaneously, and they exist alone. D these three situations. In addition, the term "at least one" herein means any one of a plurality or any combination of at least two of a plurality, for example, including at least one of C, D, and E, which can mean including from C, Any one or more elements selected from the set composed of D and E.
例如,本申请提供的数据处理方法包含了一系列的步骤,但是本申请提供的数据处理方法不限于所记载的步骤,同样地,本申请提供的数据处理装置包括了一系列模块,但是本申请提供的数据处理装置不限于包括所明确记载的模块,还可以包括为获取相关信息、或基于信息进行处理时所需要设置的模块。For example, the data processing method provided by this application includes a series of steps, but the data processing method provided by this application is not limited to the steps described. Similarly, the data processing device provided by this application includes a series of modules, but this application The provided data processing device is not limited to include explicitly stated modules, but may also include modules that are required to obtain relevant information or perform processing based on the information.
相关技术中,对于锁的含义,简单来说,用户存储在Redis数据库中的每一个对象数据都有一个锁,这个锁只能被单个线程获取消费;当锁已经被获取,其他线程就只能挂起等待。通常情况下,锁的释放时间是固定的,且为了确保每一线程进行任务操作的准确性,锁的释放时间会设置的比较长,这样,当需要处理的对象数据较多时,会存在线程等待的问题,导致高并发场景下的数据处理效率较低;此外,当第一时间段内需要处理的对象数据较少,而第二时间段内处理的对象数据较多,若第二时间段内继续采用第一时间段内设置的锁的释放时间,则会导致有些对象数据在超过锁的释放时间后还未被操作完成,进而,存在数据丢失的风险,难以满足高并发场景下的数据处理要求。In related technology, regarding the meaning of locks, simply speaking, each object data stored by the user in the Redis database has a lock. This lock can only be acquired and consumed by a single thread; when the lock has been acquired, other threads can only Suspended waiting. Normally, the lock release time is fixed, and in order to ensure the accuracy of each thread's task operation, the lock release time is set relatively long. In this way, when there is a lot of object data that needs to be processed, there will be threads waiting. problem, resulting in low data processing efficiency in high concurrency scenarios; in addition, when there is less object data to be processed in the first time period, and more object data is processed in the second time period, if in the second time period Continuing to use the lock release time set in the first time period will result in some object data not being completed after the lock release time is exceeded. Furthermore, there is a risk of data loss and it is difficult to meet the data processing in high concurrency scenarios. Require.
其中,Redis锁的实现与Redis本身的原子性特性相关,Redis是单线程的;Redis锁相当于一个对象数据的一个标签,通常用键值对key-value进行表示,key值通常是对象的通用唯一识别码(universally unique identifier,uuid),而value值通常用1表示该对象数据的Redis锁已被获取,0表示该对象数据的Redis锁可被获取。这种Redis锁带来的好处则是能够完美的保证对单一数据操作的原子性,但是,当存储的对象数据是多个且具有层级即依赖关系的数据时,这种方法难以保证数据删写的一致性。Among them, the implementation of Redis lock is related to the atomicity characteristics of Redis itself. Redis is single-threaded; Redis lock is equivalent to a label of an object data, which is usually represented by key-value. The key value is usually the universal value of the object. Unique identification code (universally unique identifier, uuid), and the value value usually indicates that the Redis lock of the object data has been acquired, and 0 indicates that the Redis lock of the object data can be acquired. The benefit of this Redis lock is that it can perfectly guarantee the atomicity of a single data operation. However, when the stored object data is multiple and has hierarchical or dependency relationships, this method is difficult to guarantee data deletion. consistency.
针对上述问题,提出以下各实施例。In view of the above problems, the following embodiments are proposed.
在本申请的一些实施例中,数据处理方法可以利用数据处理装置中的处理器实现,上述处理器可以为特定用途集成电路(Application Specific Integrated Circuit,ASIC)、数字信号处理器(Digital Signal Processor,DSP)、数字信号处理装置(DigitalSignal Processing Device,DSPD)、可编程逻辑装置(Programmable Logic Device,PLD)、现场可编程逻辑门阵列(Field Programmable Gate Array,FPGA)、中央处理器(CentralProcessing Unit,CPU)、控制器、微控制器、微处理器中的至少一种。In some embodiments of the present application, the data processing method can be implemented using a processor in a data processing device. The processor can be an Application Specific Integrated Circuit (ASIC) or a Digital Signal Processor (Digital Signal Processor, DSP), Digital Signal Processing Device (DSPD), Programmable Logic Device (PLD), Field Programmable Gate Array (FPGA), Central Processing Unit (CPU) ), at least one of a controller, a microcontroller, and a microprocessor.
图1为本申请实施例提供的一种数据处理方法的流程示意图,如图1所示,该流程可以包括:Figure 1 is a schematic flow chart of a data processing method provided by an embodiment of the present application. As shown in Figure 1, the process may include:
步骤100:拦截当前时间段内服务端接收的多个数据操作请求。Step 100: Intercept multiple data operation requests received by the server within the current time period.
示例性地,用户可以在客户端发起数据操作请求,客户端将用户发起的数据操作请求发送给服务端,服务端可以接收到客户端发送的数据操作请求;这里,对于服务端接收到的每个数据操作请求,可以通过拦截器进行拦截操作,进而,拦截到当前时间段内服务端接收的多个数据操作请求。For example, the user can initiate a data operation request on the client, the client sends the data operation request initiated by the user to the server, and the server can receive the data operation request sent by the client; here, for each data operation request received by the server A data operation request can be intercepted through an interceptor, thereby intercepting multiple data operation requests received by the server within the current time period.
这里,当前时间段可以为拦截器进行拦截操作的第一个时间段;对于当前时间段的时间长度可以根据实际场景进行确定,本申请实施例对此不作限定;例如,在高并发场景下,当前时间段的时间长度通常小于1秒。Here, the current time period may be the first time period in which the interceptor performs the interception operation; the length of the current time period may be determined according to the actual scenario, and the embodiments of this application do not limit this; for example, in a high concurrency scenario, The length of the current period is usually less than 1 second.
本申请实施例中,数据操作请求用于对操作数据进行写入操作或删除操作;其中,操作数据可以为具有层级关联关系的数据,操作数据具有对应的标识信息,该标识信息可以是操作数据的uuid。In the embodiment of the present application, the data operation request is used to perform a write operation or a deletion operation on the operation data; wherein the operation data can be data with a hierarchical association relationship, and the operation data has corresponding identification information, and the identification information can be operation data uuid.
示例性地,对操作数据进行写入操作或删除操作均是针对数据库的操作;即,将操作数据写入某一数据库中,或者将某一数据库中的操作数据进行删除;这里,对于数据库的类型不作限定,例如,可以是Redis数据库,也可以是其他类型的数据库。For example, writing or deleting operation data are operations on the database; that is, writing operation data into a certain database or deleting operation data in a certain database; here, for the database The type is not limited. For example, it can be a Redis database or other types of databases.
这里,以Redis数据库为例,结合图2对具有层级关联关系的操作数据的含义进行说明,假设当前需要向Redis数据库中写入一个操作数据b,该数据的写入分两部分:第一部分,向Redis数据库中写入一个操作数据b(对应图中步骤(2));第二部分,将操作数据b的标识(例如uuid)放入对象数据a(对应图中步骤(1),对象数据a是一个列表,可以包含多个类似于操作数据b的uuid)。同样的,假设需要从Redis数据库中删除一个操作数据b,该数据的删除也分两部分:第一部分,从Redis数据库中删除一个操作数据b(对应图中步骤(4));第二部分,将操作数据b的uuid从对象数据a中删除(对应图中步骤(3))。此时,操作数据b与对象数据a是具有层级关联关系的,即,操作数据b为具有层级关联关系的数据。Here, taking the Redis database as an example, the meaning of operation data with hierarchical relationships is explained in conjunction with Figure 2. Assume that it is currently necessary to write an operation data b into the Redis database. The writing of this data is divided into two parts: the first part, Write an operation data b to the Redis database (corresponding to step (2) in the figure); in the second part, put the identification of the operation data b (such as uuid) into the object data a (corresponding to step (1) in the figure, object data a is a list that can contain multiple uuid similar to operation data b). Similarly, assuming that an operation data b needs to be deleted from the Redis database, the deletion of the data is also divided into two parts: the first part, deleting an operation data b from the Redis database (corresponding to step (4) in the figure); the second part, Delete the uuid of operation data b from object data a (corresponding to step (3) in the figure). At this time, the operation data b and the object data a have a hierarchical association relationship, that is, the operation data b is data with a hierarchical association relationship.
需要说明的是,多个数据操作请求对应多个操作数据,不同数据操作请求对应的操作数据可以相同,也可以不同。例如,在某一数据操作请求用于写入操作数据b的情况下,另一数据操作请求可以用于删除操作数据b,也可以用于删除操作数据c。It should be noted that multiple data operation requests correspond to multiple operation data, and the operation data corresponding to different data operation requests may be the same or different. For example, when a certain data operation request is used to write operation data b, another data operation request may be used to delete operation data b or may be used to delete operation data c.
步骤101:统计当前时间段内完成多个操作数据对应的数据流入速率。Step 101: Count the data inflow rate corresponding to multiple operation data completed within the current time period.
本申请实施例中,在根据上述步骤拦截到当前时间段内针对多个操作数据的多个数据操作请求后,进一步统计该时间段内完成多个操作数据对应的数据流入速率;这里,数据流入速率可以包括数据写入速率和数据删除速率中的至少一种。In the embodiment of this application, after intercepting multiple data operation requests for multiple operation data in the current time period according to the above steps, the data inflow rate corresponding to the multiple operation data completed in the time period is further calculated; here, the data inflow rate The rate may include at least one of a data writing rate and a data deletion rate.
示例性地,对于拦截到的多个数据操作请求,可以包括以下三种情况:1)多个数据操作请求均是对多个操作数据进行写入操作的请求;2)多个数据操作请求均是对多个操作数据进行删除操作的请求;3)多个数据操作请求中既包括对若干个操作数据进行写入操作的请求,也包括对若干个操作数据进行删除操作的请求。For example, the intercepted multiple data operation requests may include the following three situations: 1) The multiple data operation requests are requests to write multiple operation data; 2) The multiple data operation requests are all requests to write multiple operation data; It is a request to delete multiple operation data; 3) Multiple data operation requests include both requests to write several operation data and requests to delete several operation data.
可以理解地,对上述第1种情况对应的多个操作数据进行统计时,得到的数据流入速率仅包括数据写入速率;对上述第2种情况对应的多个操作数据进行统计时,得到的数据流入速率仅包括数据删除速率;对于上述第3种情况对应的多个操作数据进行统计时,得到的数据流入速率则包括数据写入速率和数据删除速率。It can be understood that when counting the multiple operation data corresponding to the above-mentioned first situation, the obtained data inflow rate only includes the data writing rate; when counting the multiple operation data corresponding to the above-mentioned second situation, the obtained The data inflow rate only includes the data deletion rate; when counting the multiple operation data corresponding to the third case above, the obtained data inflow rate includes the data write rate and the data deletion rate.
步骤102:基于数据流入速率,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间。Step 102: Based on the data inflow rate, determine the release time of the lock corresponding to each target data operation request received in the next time period.
这里,下一时间段表示在当前时间段之后的某一时间段,且该时间段与当前时间段的时间长度相同。Here, the next time period represents a certain time period after the current time period, and the time period is the same as the current time period.
示例性地,目标数据操作请求用于对目标操作数据进行写入操作或删除操作,目标操作数据为具有层级关联关系的数据;需要说明的是,目标数据操作请求与上述数据操作请求均是服务端接收到的请求,两者作用相同,区别仅在于服务端接收的时间段不同,目标操作数据与上述操作数据也是类似地,此处不再赘述。For example, the target data operation request is used to write or delete the target operation data, and the target operation data is data with a hierarchical association relationship; it should be noted that the target data operation request and the above data operation request are both services. The request received by the server has the same effect. The only difference is that the time period received by the server is different. The target operation data is similar to the above operation data and will not be described again here.
本申请实施例中,锁的释放时间也称锁的锁定时间,其可以包括锁的写入释放时间和删除释放时间中的至少一种;可以理解地,锁的释放时间包括的内容是根据数据流入速率包括的内容对应确定的。In the embodiment of the present application, the release time of the lock is also called the lock time of the lock, which may include at least one of the write release time and the delete release time of the lock; it can be understood that the content included in the lock release time is based on the data The content included in the inflow rate is determined accordingly.
示例性,若数据流入速率仅包括数据写入速率,则基于数据写入速率,可以确定下一时间段内接收到的用于进行写入操作的各目标数据操作请求对应的锁的写入释放时间。若数据流入速率仅包括数据删除速率,则基于数据删除速率,可以确定下一时间段内接收到的用于进行删除操作的各目标数据操作请求对应的锁的删除释放时间。若数据流入速率包括数据写入速率和数据删除速率,则基于数据写入速率和数据删除速率,可以确定下一时间段内接收到的用于进行写入操作的各目标数据操作请求对应的锁的写入释放时间,以及用于进行删除操作的各目标数据操作请求对应的锁的删除释放时间。因为在数据流入速率包括数据写入速率和数据删除速率的情况下,能够同时确定下一时间段对应的锁的写入释放时间和删除释放时间;下面,以该情况为例,对锁的写入释放时间和删除释放时间的确定方式进行说明。For example, if the data inflow rate only includes the data write rate, based on the data write rate, the write release of the lock corresponding to each target data operation request received for the write operation in the next time period can be determined time. If the data inflow rate only includes the data deletion rate, based on the data deletion rate, the deletion release time of the lock corresponding to each target data operation request received for the deletion operation in the next time period can be determined. If the data inflow rate includes the data writing rate and the data deletion rate, based on the data writing rate and the data deletion rate, the lock corresponding to each target data operation request for the write operation received in the next time period can be determined. The write release time, and the delete release time of the lock corresponding to each target data operation request for the delete operation. Because when the data inflow rate includes the data writing rate and the data deletion rate, the write release time and delete release time of the lock corresponding to the next time period can be determined at the same time; below, taking this situation as an example, the write release time of the lock Describe how to determine the entry release time and delete release time.
在一种实施方式中,在数据流入速率包括数据写入速率和数据删除速率的情况下,基于数据流入速率,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间,可以包括:获取当前时间段内锁的写入释放时间和删除释放时间;确定数据写入速率和当前时间段内锁的写入释放时间的第一比值,以及数据删除速率和当前时间段内锁的删除释放时间的第二比值;基于第一比值和第二比值,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间。In one embodiment, when the data inflow rate includes a data writing rate and a data deletion rate, the release time of the lock corresponding to each target data operation request received in the next time period is determined based on the data inflow rate. , may include: obtaining the write release time and deletion release time of the lock in the current time period; determining the first ratio of the data write rate and the write release time of the lock in the current time period, and the data deletion rate and the current time period The second ratio of the lock deletion release time; based on the first ratio and the second ratio, determine the lock release time corresponding to each target data operation request received in the next time period.
这里,当前时间段内锁的写入释放时间和删除释放时间可以是根据实际情况预先设置的,两者的取值可以相同,也可以不同;本申请实施例对此不作限定,例如,可以将两者的取值均设置为5分钟,或者将其中一个设置为3分钟,另一个设置为5分钟。Here, the write release time and delete release time of the lock in the current time period can be preset according to the actual situation, and their values can be the same or different; the embodiment of the present application does not limit this. For example, it can be Set both values to 5 minutes, or set one to 3 minutes and the other to 5 minutes.
示例性地,在获取到当前时间段内锁的写入释放时间twrite和删除释放时间tdelete后,进一步确定数据写入速率vwrite和当前时间段内锁的写入释放时间tdelete的第一比值以及数据删除速率vdelete和当前时间段内锁的删除释放时间tdelete的第二比值之后,基于这两个比值,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间。For example, after obtaining the write release time t write and the delete release time t delete of the lock in the current time period, further determine the data write rate v write and the write release time t delete of the lock in the current time period. a ratio And the second ratio of the data deletion rate v delete and the lock deletion and release time t delete in the current time period Then, based on these two ratios, the lock release time corresponding to each target data operation request received in the next time period is determined.
在一些实施例中,基于第一比值和第二比值,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间,可以包括:对第一比值和第二比值进行调整,使得第一比值和第二比值相等;基于调整后的第一比值和第二比值,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间。In some embodiments, determining the release time of the lock corresponding to each target data operation request received within the next time period based on the first ratio and the second ratio may include: adjusting the first ratio and the second ratio. , making the first ratio and the second ratio equal; based on the adjusted first ratio and the second ratio, determine the release time of the lock corresponding to each target data operation request received in the next time period.
本申请实施例中,通过调整第一比值和第二比值,使得第一比值和第二比值相等,即,满足如公式(1)所示的关系:In the embodiment of the present application, by adjusting the first ratio and the second ratio, the first ratio and the second ratio are equal, that is, the relationship shown in formula (1) is satisfied:
这里,数据写入速率vwrite和数据删除速率vdelete的单位为千字节/秒(KB/s);锁的写入释放时间twrite和删除释放时间tdelete的单位为秒(s)。Here, the unit of data writing rate v write and data deletion rate v delete is kilobytes per second (KB/s); the unit of lock writing release time t write and deletion release time t delete is seconds (s).
示例性地,在公式(1)的调整过程中,需满足以下条件:第一比值和第二比值的取值均大于1,且调整后的锁的写入释放时间和锁的删除释放时间均大于设定值;这里,设定值的取值可以根据实际情况进行设置,例如,可以设置为30s。For example, during the adjustment process of formula (1), the following conditions need to be met: the values of the first ratio and the second ratio are both greater than 1, and the adjusted lock write release time and lock delete release time are both Greater than the set value; here, the set value can be set according to the actual situation, for example, it can be set to 30s.
示例性地,根据公式(1)可知,若当前时间段内的数据写入速率vwrite增大,则锁的写入释放时间twrite等比例增大,即,可以得到调整后的锁的写入释放时间;同理,若当前时间段内的数据删除速率vdelete增大,则锁的删除释放时间tdelete等比例增大,即,可以得到调整后的锁的删除释放时间;之后,将调整后的锁的写入释放时间确定为下一时间段内接收到的用于进行写入操作的各目标数据操作请求对应的锁的写入释放时间,同时,将调整后的锁的删除释放时间确定为下一时间段内接收到的用于进行删除操作的各目标数据操作请求对应的锁的删除释放时间。For example, according to formula (1), if the data write rate v write in the current time period increases, the write release time t write of the lock increases proportionally, that is, the adjusted write write rate of the lock can be obtained Enter the release time; similarly, if the data deletion rate vdelete in the current time period increases, the lock deletion and release time tdelete increases proportionally, that is, the adjusted lock deletion and release time can be obtained; after that, The adjusted write release time of the lock is determined as the write release time of the lock corresponding to each target data operation request received for the write operation in the next time period. At the same time, the adjusted lock deletion time is released. The time is determined as the deletion release time of the lock corresponding to each target data operation request received for deletion operation in the next time period.
需要说明的是,在拦截到下一时间段内的多个目标数据操作请求后,继续统计多个目标操作数据对应的数据流入速率,以确定下下时间段内的数据操作请求对应的锁的释放时间,依次类推,直至服务端不再接收到客户端发送的数据操作请求。It should be noted that after intercepting multiple target data operation requests in the next time period, continue to count the data inflow rate corresponding to the multiple target operation data to determine the lock value corresponding to the data operation request in the next time period. Release time, and so on, until the server no longer receives data operation requests from the client.
可以看出,本申请实施例通过统计某一时间段内的数据流入速率,以控制该时间段的下一时间段内各目标数据操作请求对应的锁释放时间的动态伸缩;具体地,当某一时间段内的数据流入速度较大时,通过对该时间段内锁的释放时间进行调整,使得下一时间段内锁的释放时间被相对延长,确保每个操作数据能够在锁的释放时间内完成写入或删除操作,从而极大地降低数据丢失的风险,进而,满足高并发场景下的数据处理要求。反之,当某一时间段内的数据流入速度较小时,通过对该时间段内锁的释放时间进行调整,使得下一时间段内锁的释放时间被相对缩短,这样,不仅能够确保每个操作数据都尽可能地在锁的释放时间内完成写入或删除操作,还可以解决线程等待问题,提高高并发场景下的数据处理效率。It can be seen that the embodiment of the present application counts the data inflow rate in a certain time period to control the dynamic expansion and contraction of the lock release time corresponding to each target data operation request in the next time period of the time period; specifically, when a certain time period When the data inflow speed in a period of time is relatively high, the lock release time in the period is adjusted so that the lock release time in the next period of time is relatively extended to ensure that each operation data can be processed within the lock release time. Complete writing or deleting operations within 1 hour, thereby greatly reducing the risk of data loss and thus meeting the data processing requirements in high concurrency scenarios. On the contrary, when the data inflow speed in a certain period of time is small, by adjusting the lock release time in this period of time, the lock release time in the next period of time is relatively shortened. In this way, not only can each operation be ensured The data is written or deleted as much as possible within the lock release time. It can also solve the thread waiting problem and improve the data processing efficiency in high concurrency scenarios.
步骤103:基于确定后的锁的释放时间,执行与每个目标数据操作请求对应的操作。Step 103: Based on the determined release time of the lock, perform an operation corresponding to each target data operation request.
在一些实施例中,基于确定后的锁的释放时间,执行与每个目标数据操作请求对应的操作,可以包括:对于每个目标数据操作请求,获取目标操作数据的锁;基于确定后的锁的释放时间,对目标操作数据进行加锁操作,并根据每个目标数据操作请求对目标操作数据执行相应操作。In some embodiments, based on the determined release time of the lock, performing operations corresponding to each target data operation request may include: for each target data operation request, acquiring a lock on the target operation data; based on the determined lock Within the release time, the target operation data is locked, and corresponding operations are performed on the target operation data according to each target data operation request.
示例性地,获取目标操作数据的锁,可以包括:从Redis数据库中获取目标操作数据的锁;需要说明的是,本申请实施例中涉及到的锁均为key-value形式的锁;其中,对于操作数据的锁,其key值为操作数据的标识,value值为操作数据的锁的释放时间;对于目标操作数据的锁,其key值为目标操作数据的标识,value值为目标操作数据的锁的释放时间。For example, obtaining the lock of the target operation data may include: obtaining the lock of the target operation data from the Redis database; it should be noted that the locks involved in the embodiments of this application are all locks in the form of key-value; wherein, For a lock on operation data, the key value is the identification of the operation data, and the value is the release time of the lock on the operation data; for a lock on target operation data, the key value is the identification of the target operation data, and the value is the release time of the lock on the operation data. Lock release time.
示例性地,在获取到目标操作数据的锁后,可以根据上述步骤确定的锁的释放时间,对目标操作数据进行加锁操作,并在锁的释放时间内根据目标数据操作请求对目标操作数据执行相应的写入或删除操作。For example, after acquiring the lock of the target operation data, the target operation data can be locked according to the lock release time determined in the above steps, and the target operation data can be locked according to the target data operation request within the lock release time. Perform the corresponding write or delete operation.
在一些实施例中,上述方法还包括:对每个目标数据操作请求对应的执行过程进行监听,直至监听时长达到确定后的锁的释放时间,对目标操作数据的锁进行释放操作。In some embodiments, the above method further includes: monitoring the execution process corresponding to each target data operation request until the monitoring time reaches the determined lock release time, and then releasing the lock on the target operation data.
示例性地,可以通过监听函数或监听程序等,对每个目标数据操作请求对应的执行过程进行监听,当监听时长达到确定后的锁的释放时间,会对目标操作数据的锁进行释放操作;一般来说,若目标操作数据的执行过程没有出现异常或者中断,锁都会被主动释放。For example, the execution process corresponding to each target data operation request can be monitored through a listening function or a listening program. When the listening time reaches the determined lock release time, the lock on the target operation data will be released; Generally speaking, if there are no exceptions or interruptions in the execution of the target operation data, the lock will be actively released.
这里,在对目标操作数据的锁进行释放操作后,释放后的锁将回归至Redis数据库中。Here, after the lock on the target operation data is released, the released lock will be returned to the Redis database.
在一些实施例中,上述方法还可以包括:在监听时长达到确定后的锁的释放时间,且检测到目标操作数据的锁未被释放的情况下,对目标操作数据的执行进行回滚操作。In some embodiments, the above method may further include: performing a rollback operation on the execution of the target operation data when the listening duration reaches the determined lock release time and it is detected that the lock on the target operation data has not been released.
示例性地,若监听时长达到确定后的锁的释放时间,而目标操作数据的锁未被释放,则说明针对目标操作数据的执行过程可能存在某种异常,此时,可以通过对目标操作数据的执行进行回滚操作,即,对目标操作数据的执行回滚到执行前的状态后再次执行相关操作,可以确保执行过程的准确性。这里,回滚操作可以通过对数据执行过程加入事务操作的方式实现,也可以通过其他方式实现。For example, if the listening time reaches the determined lock release time, but the lock of the target operation data is not released, it means that there may be some abnormality in the execution process of the target operation data. At this time, you can pass the target operation data The execution is rolled back, that is, the execution of the target operation data is rolled back to the state before execution and then the relevant operations are performed again, which can ensure the accuracy of the execution process. Here, the rollback operation can be implemented by adding transaction operations to the data execution process, or by other methods.
需要说明的是,若经过回滚操作后,还是检测到目标操作数据的锁未被释放,此时,则需要捕获该异常并打印日志,以提醒用户及时处理该异常。It should be noted that if after the rollback operation, it is still detected that the lock of the target operation data has not been released, at this time, the exception needs to be captured and a log printed to remind the user to handle the exception in a timely manner.
本申请实施例提供一种数据处理方法,该方法包括:拦截当前时间段内服务端接收的多个数据操作请求;数据操作请求用于对操作数据进行写入操作或删除操作;统计当前时间段内完成多个操作数据对应的数据流入速率;数据流入速率包括数据写入速率和数据删除速率中的至少一种;基于数据流入速率,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间;基于确定后的锁的释放时间,执行与每个目标数据操作请求对应的操作。可以看出,本申请实施例中,通过拦截当前时间段内的每个数据操作请求,以统计该时间段内的数据流入速率,进而动态调整下一时间段内各个目标数据操作请求对应的锁的释放时间,即,能够实现锁的释放时间的弹性伸缩;对于高并发场景,因为锁的释放时间是根据数据流入速率动态调整的,即,不同的数据流入速率对应不同的锁的释放时间,因而,可以确保在锁的释放时间内尽可能地完成数据的删写操作,保证数据删写操作一致性的同时优化线程等待的问题,提高高并发场景下的数据处理效率。Embodiments of the present application provide a data processing method, which method includes: intercepting multiple data operation requests received by the server within the current time period; the data operation requests are used to write or delete operation data; and counting the current time period. The data inflow rate corresponding to multiple operation data completed within the period; the data inflow rate includes at least one of the data writing rate and the data deletion rate; based on the data inflow rate, determine each target data operation request received in the next time period The release time of the corresponding lock; based on the determined release time of the lock, perform the operation corresponding to each target data operation request. It can be seen that in the embodiment of the present application, each data operation request in the current time period is intercepted to count the data inflow rate in the time period, and then dynamically adjust the lock corresponding to each target data operation request in the next time period. The release time of the lock, that is, can achieve elastic expansion and contraction of the lock release time; for high concurrency scenarios, because the lock release time is dynamically adjusted according to the data inflow rate, that is, different data inflow rates correspond to different lock release times, Therefore, it is possible to ensure that data deletion and writing operations are completed as much as possible within the lock release time, ensuring the consistency of data deletion and writing operations while optimizing the thread waiting problem and improving data processing efficiency in high concurrency scenarios.
为了能够更加体现本申请的目的,本申请实施例在上述实施例的基础上,作进一步的说明。In order to better reflect the purpose of this application, the embodiments of this application are further described based on the above embodiments.
在高并发场景下,通常会接收到大量的访问请求(对应上述数据操作请求或目标数据操作请求),需要不停地对数据库进行数据的写入操作和删除操作;这里,以上述图2为例进行说明,关于图2所示的步骤(1)(2)(3)(4)的执行顺序可能有多种,理想情况下,当同时接收到针对操作数据的一个写入操作和删除操作时(假设步骤(1)的执行优先于步骤(2),步骤(3)的执行优先于步骤(4)),最优的步骤执行顺序是(1)(2)(3)(4)或者(3)(4)(1)(2),这样当用户在任意步骤执行期间进行读操作时,不会看到脏数据;然而在实际场景下,会出现这样的步骤执行顺序(1)(3)(4)(2)或者(3)(1)(2)(4)等;可以看到,在这些情况下,会出现需要写入的操作数据被删了,或者需要删除的操作数据没删掉等异常情况,并且这些情况在线上很难排查与修改,经常会造成现网事故。In high-concurrency scenarios, a large number of access requests (corresponding to the above-mentioned data operation requests or target data operation requests) are usually received, and data writing operations and deletion operations need to be continuously performed on the database; here, take the above Figure 2 as To illustrate, there may be multiple execution orders for steps (1)(2)(3)(4) shown in Figure 2. Ideally, when a write operation and a delete operation for the operation data are received at the same time, When (assuming that the execution of step (1) takes precedence over step (2), and the execution of step (3) takes precedence over step (4)), the optimal step execution order is (1)(2)(3)(4) or (3)(4)(1)(2), so that when the user performs a read operation during the execution of any step, he will not see dirty data; however, in actual scenarios, such step execution sequence (1)( 3)(4)(2) or (3)(1)(2)(4), etc.; it can be seen that in these cases, the operation data that needs to be written is deleted, or the operation data that needs to be deleted Abnormal situations such as not deleting data, and these situations are difficult to troubleshoot and modify online, often causing accidents on the live network.
为了克服上述问题,本申请实施例使用拦截器获取当前时间段内服务端接收的多个数据操作请求,并基于拦截到的这些数据操作请求,对相关技术中的Redis锁机制进行优化。In order to overcome the above problems, the embodiment of the present application uses an interceptor to obtain multiple data operation requests received by the server within the current time period, and optimizes the Redis lock mechanism in related technologies based on these intercepted data operation requests.
示例性地,对于Redis锁机制的优化过程如下,同样使用key-value维护对象数据(对应上述操作数据或目标操作数据)的锁,与相关技术不同的是value值存储的不是0和1,而是对象数据的锁的释放时间。普通的Redis锁存在一个重大隐患就是锁可能不会被释放,那么该对象数据就永远无法被获取。这里,之所以优化Redis锁,就是为了防止锁没有主动被释放。For example, the optimization process of the Redis lock mechanism is as follows. Key-value is also used to maintain locks on object data (corresponding to the above operation data or target operation data). The difference from related technologies is that the value value is not stored as 0 and 1, but Is the release time of the object data lock. A major hidden danger in ordinary Redis locks is that the lock may not be released, and then the object data can never be obtained. Here, the reason why the Redis lock is optimized is to prevent the lock from being actively released.
示例性地,锁没有主动被释放的情形可以包括以下两种:一种是在执行中间步骤(1)(2)(3)(4)的过程中,出现异常而没有被捕获,导致锁释放程序没有执行;另外一种是执行中间步骤(1)(2)(3)(4)耗时过长,导致大量任务堆积溢出内存。所以,在这里使用时间来实现对象数据的锁的自动释放,又称被动释放。下面结合图3对锁进行释放操作的过程进行说明。For example, the situation in which the lock is not actively released may include the following two situations: one is that during the execution of intermediate steps (1)(2)(3)(4), an exception occurs but is not caught, causing the lock to be released. The program is not executed; the other is that the execution of intermediate steps (1)(2)(3)(4) takes too long, causing a large number of tasks to accumulate and overflow the memory. Therefore, time is used here to realize the automatic release of the object data lock, also known as passive release. The process of releasing the lock will be described below with reference to Figure 3.
图3为本申请实施例提供的另一种数据处理方法的流程示意图,如图3所示,该图包括拦截器和Redis数据库,流程可以包括:每当服务端接收到一个对象数据的删除操作或者写入操作,都会自动从Redis数据库读取该对象数据的锁,若获取到对象数据的锁,则对该对象数据进行加锁操作,即,将该对象数据锁住,并将对象数据的锁的value值设置为System.currentTimeMillis()+t,其中,System.currentTimeMillis()表示当前时间,t表示锁的释放时间;当锁的释放时间t设为5分钟,即表示该锁将在5分钟后自动释放。若在5分钟后没有获取到锁,则等待t时长并再次请求获取锁。当步骤(1)(2)(3)(4)顺利执行完成后,系统会对锁进行释放操作,即主动释放当前锁,一般来说,程序执行过程没有出现异常或者中断,锁都会被主动释放,锁被释放后会回归Redis数据库。Figure 3 is a schematic flow chart of another data processing method provided by the embodiment of the present application. As shown in Figure 3, the figure includes an interceptor and a Redis database. The process may include: whenever the server receives a deletion operation of object data or write operation, the lock of the object data will be automatically read from the Redis database. If the lock of the object data is obtained, the object data will be locked, that is, the object data will be locked, and the object data will be locked. The value of the lock is set to System.currentTimeMillis()+t, where System.currentTimeMillis() represents the current time and t represents the lock release time; when the lock release time t is set to 5 minutes, it means that the lock will be released in 5 minutes. Release automatically after minutes. If the lock is not obtained after 5 minutes, wait for t time and request the lock again. When steps (1)(2)(3)(4) are successfully executed, the system will release the lock, that is, actively releasing the current lock. Generally speaking, if there are no exceptions or interruptions during program execution, the lock will be automatically released. Release, the lock will return to the Redis database after it is released.
示例性地,对于上述两种锁无法主动被释放的情形,可以进行以下针对性的处理。针对第一种情形可以捕获异常并打印日志;针对第二种情形则监听中间执行步骤(1)(2)(3)(4)的时长,超过锁的释放时间t则抛出异常并捕获。这里,还可以同时将步骤(1)(2)和步骤(3)(4)分别加入了事务操作,当出现异常时,对该对象数据进行的写删等操作进行回滚。For example, for the above two situations where the lock cannot be actively released, the following targeted processing can be performed. For the first case, you can catch the exception and print the log; for the second case, monitor the duration of the intermediate execution steps (1) (2) (3) (4). If the lock release time t is exceeded, an exception will be thrown and captured. Here, steps (1) (2) and steps (3) (4) can also be added to the transaction operation at the same time. When an exception occurs, operations such as writing and deleting the object data are rolled back.
可以看出,本申请实施例提供的数据处理方法优化了参数设置,实现动态调整锁的释放时间,节约了人工干预的成本,降低了调参的冗余工作。此外,基于动态锁实现Redis层级关联数据的存储流程,能为更多的业务场景提供普适性的存储方案,具有一定的使用前景。It can be seen that the data processing method provided by the embodiment of the present application optimizes parameter settings, realizes dynamic adjustment of the lock release time, saves the cost of manual intervention, and reduces redundant work of parameter adjustment. In addition, the storage process of Redis-level associated data based on dynamic locks can provide a universal storage solution for more business scenarios and has certain usage prospects.
图4为本申请实施例提供的一种数据处理装置的结构示意图,如图4所示,该装置包括:拦截模块400、统计模块401、确定模块402和执行模块403,其中:Figure 4 is a schematic structural diagram of a data processing device provided by an embodiment of the present application. As shown in Figure 4, the device includes: an interception module 400, a statistics module 401, a determination module 402 and an execution module 403, wherein:
拦截模块400,用于拦截当前时间段内服务端接收的多个数据操作请求;所述数据操作请求用于对操作数据进行写入操作或删除操作;The interception module 400 is used to intercept multiple data operation requests received by the server within the current time period; the data operation requests are used to write or delete operation data;
统计模块401,用于统计所述当前时间段内完成多个操作数据对应的数据流入速率;所述数据流入速率包括数据写入速率和数据删除速率中的至少一种;The statistics module 401 is used to count the data inflow rate corresponding to multiple operation data completed within the current time period; the data inflow rate includes at least one of a data writing rate and a data deletion rate;
确定模块402,用于基于所述数据流入速率,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间;Determining module 402, configured to determine the release time of the lock corresponding to each target data operation request received in the next time period based on the data inflow rate;
执行模块403,用于基于确定后的所述锁的释放时间,执行与所述每个目标数据操作请求对应的操作。The execution module 403 is configured to execute an operation corresponding to each target data operation request based on the determined release time of the lock.
在一些实施例中,在所述数据流入速率包括数据写入速率和数据删除速率的情况下,所述确定模块402,用于基于所述数据流入速率,确定下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间,包括:In some embodiments, when the data inflow rate includes a data writing rate and a data deletion rate, the determining module 402 is configured to determine, based on the data inflow rate, each data rate received in the next time period. The release time of the lock corresponding to each target data operation request, including:
获取所述当前时间段内锁的写入释放时间和删除释放时间;Obtain the write release time and delete release time of the lock within the current time period;
确定所述数据写入速率和所述当前时间段内锁的写入释放时间的第一比值,以及所述数据删除速率和所述当前时间段内锁的删除释放时间的第二比值;Determine a first ratio between the data writing rate and the write release time of the lock in the current time period, and a second ratio between the data deletion rate and the deletion release time of the lock in the current time period;
基于所述第一比值和所述第二比值,确定所述下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间。Based on the first ratio and the second ratio, the release time of the lock corresponding to each target data operation request received within the next time period is determined.
在一些实施例中,所述确定模块402,用于基于所述第一比值和所述第二比值,确定所述下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间,包括:In some embodiments, the determining module 402 is configured to determine the release time of the lock corresponding to each target data operation request received in the next time period based on the first ratio and the second ratio. ,include:
对所述第一比值和所述第二比值进行调整,使得所述第一比值和所述第二比值相等;Adjust the first ratio and the second ratio so that the first ratio and the second ratio are equal;
基于调整后的所述第一比值和所述第二比值,确定所述下一时间段内接收到的每个目标数据操作请求对应的锁的释放时间。Based on the adjusted first ratio and the second ratio, the release time of the lock corresponding to each target data operation request received within the next time period is determined.
在一些实施例中,所述执行模块403,用于基于确定后的所述锁的释放时间,执行与所述每个目标数据操作请求对应的操作,包括:In some embodiments, the execution module 403 is configured to execute operations corresponding to each target data operation request based on the determined release time of the lock, including:
对于所述每个目标数据操作请求,获取目标操作数据的锁;所述目标数据操作请求用于对所述目标操作数据进行写入操作或删除操作;For each target data operation request, obtain the lock of the target operation data; the target data operation request is used to perform a write operation or delete operation on the target operation data;
基于确定后的所述锁的释放时间,对所述目标操作数据进行加锁操作,并根据所述目标数据操作请求对所述目标操作数据执行相应操作。Based on the determined release time of the lock, a locking operation is performed on the target operation data, and corresponding operations are performed on the target operation data according to the target data operation request.
在一些实施例中,所述执行模块403,用于获取目标操作数据的锁,包括:In some embodiments, the execution module 403 is used to obtain the lock of target operation data, including:
从Redis数据库中获取所述目标操作数据的锁;所述目标操作数据的锁为key-value形式的锁,所述key值为所述目标操作数据的标识,所述value值为所述目标操作数据的锁的释放时间。Obtain the lock of the target operation data from the Redis database; the lock of the target operation data is a lock in the form of key-value, the key value is the identification of the target operation data, and the value value is the target operation The release time of the data lock.
在一些实施例中,所述装置还包括监听模块,所述监听模块,用于:In some embodiments, the device further includes a listening module, and the listening module is used to:
对所述每个目标数据操作请求对应的执行过程进行监听,直至监听时长达到所述确定后的所述锁的释放时间,对所述目标操作数据的锁进行释放操作。The execution process corresponding to each target data operation request is monitored until the monitoring time reaches the determined release time of the lock, and the lock of the target operation data is released.
在一些实施例中,所述装置还包括回滚模块,所述回滚模块,用于:In some embodiments, the device further includes a rollback module, and the rollback module is used to:
在所述监听时长达到所述确定后的所述锁的释放时间,且检测到所述目标操作数据的锁未被释放的情况下,对所述目标操作数据的执行进行回滚操作。When the listening duration reaches the determined release time of the lock and it is detected that the lock of the target operation data has not been released, a rollback operation is performed on the execution of the target operation data.
在实际应用中,上述拦截模块400、统计模块401、确定模块402、执行模块403、监听模块和回滚模块均可以由位于电子设备中的处理器实现,该处理器可以为ASIC、DSP、DSPD、PLD、FPGA、CPU、控制器、微控制器、微处理器中的至少一种。In practical applications, the above-mentioned interception module 400, statistics module 401, determination module 402, execution module 403, monitoring module and rollback module can all be implemented by a processor located in an electronic device. The processor can be an ASIC, DSP, or DSPD. , at least one of PLD, FPGA, CPU, controller, microcontroller, and microprocessor.
另外,在本实施例中的各功能模块可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。In addition, each functional module in this embodiment can be integrated into one processing unit, or each unit can exist physically alone, or two or more units can be integrated into one unit. The above integrated units can be implemented in the form of hardware or software function modules.
集成的单元如果以软件功能模块的形式实现并非作为独立的产品进行销售或使用时,可以存储在一个计算机可读取存储介质中,基于这样的理解,本实施例的技术方案本质上或者说对相关技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机、服务器、或者网络设备等)或processor(处理器)执行本实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(Read OnlyMemory,ROM)、随机存取存储器(Random Access Memory,RAM)、磁碟或者光盘等多种可以存储程序代码的介质。If the integrated unit is implemented in the form of a software function module and is not sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this embodiment is essentially The part that contributes to the relevant technology or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions to make a computer device (which can be a personal computer , server, or network equipment, etc.) or processor (processor) executes all or part of the steps of the method of this embodiment. The aforementioned storage media include: U disk, mobile hard disk, read-only memory (Read Only Memory, ROM), random access memory (Random Access Memory, RAM), magnetic disk or optical disk and other media that can store program codes.
具体来讲,本实施例中的一种数据处理方法对应的计算机程序指令可以被存储在光盘、硬盘、U盘等存储介质上,当存储介质中的与一种数据处理方法对应的计算机程序指令被一电子设备读取或被执行时,实现前述实施例的任意一种数据处理方法。Specifically, the computer program instructions corresponding to a data processing method in this embodiment can be stored on storage media such as optical disks, hard disks, and U disks. When the computer program instructions corresponding to a data processing method in the storage medium When read or executed by an electronic device, any data processing method in the aforementioned embodiments is implemented.
基于前述实施例相同的技术构思,参见图5,其示出了本申请实施例提供的电子设备500,可以包括:存储器501和处理器502;其中,Based on the same technical concept of the previous embodiment, see Figure 5, which shows an electronic device 500 provided by an embodiment of the present application, which may include: a memory 501 and a processor 502; wherein,
存储器501,用于存储计算机程序和数据;Memory 501, used to store computer programs and data;
处理器502,用于执行存储器中存储的计算机程序,以实现前述实施例的任意一种数据处理方法。The processor 502 is used to execute the computer program stored in the memory to implement any of the data processing methods in the aforementioned embodiments.
在实际应用中,上述存储器501可以是易失性存储器(volatile memory),例如RAM;或者非易失性存储器(non-volatile memory),例如ROM、快闪存储器(flash memory)、硬盘(Hard Disk Drive,HDD)或固态硬盘(Solid-State Drive,SSD);或者上述种类的存储器的组合,并向处理器502提供指令和数据。In practical applications, the above-mentioned memory 501 can be a volatile memory (volatile memory), such as RAM; or a non-volatile memory (non-volatile memory), such as ROM, flash memory (flash memory), hard disk (Hard Disk). Drive, HDD) or solid-state drive (Solid-State Drive, SSD); or a combination of the above types of memories, and provides instructions and data to the processor 502.
上述处理器502可以为ASIC、DSP、DSPD、PLD、FPGA、CPU、控制器、微控制器、微处理器中的至少一种。可以理解地,对于不同的数据处理系统,用于实现上述处理器功能的电子器件还可以为其它,本申请实施例不作具体限定。The above-mentioned processor 502 may be at least one of ASIC, DSP, DSPD, PLD, FPGA, CPU, controller, microcontroller, and microprocessor. It can be understood that for different data processing systems, the electronic device used to implement the above processor function can also be other, which is not specifically limited in the embodiment of the present application.
在一些实施例中,本申请实施例提供的装置具有的功能或包含的模块可以用于执行上文方法实施例描述的方法,其具体实现可以参照上文方法实施例的描述,为了简洁,这里不再赘述。In some embodiments, the functions or modules provided by the device provided by the embodiments of the present application can be used to execute the methods described in the above method embodiments. For specific implementation, refer to the description of the above method embodiments. For the sake of brevity, here No longer.
上文对各个实施例的描述倾向于强调各个实施例之间的不同之处,其相同或相似之处可以互相参考,为了简洁,本文不再赘述。The above description of various embodiments tends to emphasize the differences between the various embodiments, and the similarities or similarities can be referred to each other. For the sake of brevity, they will not be described again here.
本申请所提供的各方法实施例中所揭露的方法,在不冲突的情况下可以任意组合,得到新的方法实施例。The methods disclosed in each method embodiment provided in this application can be combined arbitrarily to obtain a new method embodiment if there is no conflict.
本申请所提供的各产品实施例中所揭露的特征,在不冲突的情况下可以任意组合,得到新的产品实施例。The features disclosed in each product embodiment provided in this application can be arbitrarily combined to obtain a new product embodiment if there is no conflict.
本申请所提供的各方法或设备实施例中所揭露的特征,在不冲突的情况下可以任意组合,得到新的方法实施例或设备实施例。The features disclosed in each method or device embodiment provided in this application can be combined arbitrarily without conflict to obtain a new method embodiment or device embodiment.
本领域内的技术人员应明白,本申请的实施例可提供为方法、系统、或计算机程序产品。因此,本申请可采用硬件实施例、软件实施例、或结合软件和硬件方面的实施例的形式。而且,本申请可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器和光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art will understand that embodiments of the present application may be provided as methods, systems, or computer program products. Accordingly, the present application may take the form of a hardware embodiment, a software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, magnetic disk storage and optical storage, etc.) embodying computer-usable program code therein.
本申请是参照根据本申请实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其它可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其它可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each process and/or block in the flowchart illustrations and/or block diagrams, and combinations of processes and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing device to produce a machine, such that the instructions executed by the processor of the computer or other programmable data processing device produce a A device for realizing the functions specified in one process or multiple processes of the flowchart and/or one block or multiple blocks of the block diagram.
这些计算机程序指令也可装载到计算机或其它可编程数据处理设备上,使得在计算机或其它可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其它可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。These computer program instructions may also be loaded onto a computer or other programmable data processing device, causing a series of operating steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby executing on the computer or other programmable device. Instructions provide steps for implementing the functions specified in a process or processes of a flowchart diagram and/or a block or blocks of a block diagram.
以上,仅为本申请的较佳实施例而已,并非用于限定本申请的保护范围。The above are only preferred embodiments of the present application and are not used to limit the protection scope of the present application.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211430884.5A CN116775669A (en) | 2022-11-15 | 2022-11-15 | Data processing method, device, electronic equipment and computer storage medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211430884.5A CN116775669A (en) | 2022-11-15 | 2022-11-15 | Data processing method, device, electronic equipment and computer storage medium |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116775669A true CN116775669A (en) | 2023-09-19 |
Family
ID=87986638
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211430884.5A Pending CN116775669A (en) | 2022-11-15 | 2022-11-15 | Data processing method, device, electronic equipment and computer storage medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116775669A (en) |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5615373A (en) * | 1993-08-26 | 1997-03-25 | International Business Machines Corporation | Data lock management in a distributed file server system determines variable lock lifetime in response to request to access data object |
US20180109617A1 (en) * | 2015-02-27 | 2018-04-19 | International Business Machines Corporation | Write intent messaging in a dispersed storage network |
CN108073684A (en) * | 2017-11-16 | 2018-05-25 | 深圳市买买提信息科技有限公司 | A kind of data processing method, server and computer readable storage medium |
CN113742293A (en) * | 2021-01-21 | 2021-12-03 | 北京沃东天骏信息技术有限公司 | Data deleting method and device, electronic equipment and storage medium |
-
2022
- 2022-11-15 CN CN202211430884.5A patent/CN116775669A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5615373A (en) * | 1993-08-26 | 1997-03-25 | International Business Machines Corporation | Data lock management in a distributed file server system determines variable lock lifetime in response to request to access data object |
US20180109617A1 (en) * | 2015-02-27 | 2018-04-19 | International Business Machines Corporation | Write intent messaging in a dispersed storage network |
CN108073684A (en) * | 2017-11-16 | 2018-05-25 | 深圳市买买提信息科技有限公司 | A kind of data processing method, server and computer readable storage medium |
CN113742293A (en) * | 2021-01-21 | 2021-12-03 | 北京沃东天骏信息技术有限公司 | Data deleting method and device, electronic equipment and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US11429559B2 (en) | Compliance recycling algorithm for scheduled targetless snapshots | |
US11157370B2 (en) | Consistent backup of a distributed database system | |
US10585874B2 (en) | Locking concurrent commands in a database management system | |
US9104471B2 (en) | Transaction log management | |
US9274798B2 (en) | Multi-threaded logging | |
US20160086260A1 (en) | Lifecycle transitions in log-coordinated data stores | |
WO2019109854A1 (en) | Data processing method and device for distributed database, storage medium, and electronic device | |
US8020046B2 (en) | Transaction log management | |
CN104793988A (en) | Cross-database distributed transaction implementation method and device | |
US8583608B2 (en) | Maximum allowable runtime query governor | |
US20210073198A1 (en) | Using persistent memory and remote direct memory access to reduce write latency for database logging | |
US11449241B2 (en) | Customizable lock management for distributed resources | |
US11720607B2 (en) | System for lightweight objects | |
US20200026428A1 (en) | Smart auto-backup of virtual machines using a virtual proxy | |
US9251149B2 (en) | Data set size tracking and management | |
US8336053B2 (en) | Transaction management | |
CN118585376A (en) | Dynamic adjustment of backup strategies | |
US10642745B2 (en) | Key invalidation in cache systems | |
US11093290B1 (en) | Backup server resource-aware discovery of client application resources | |
US10282371B1 (en) | Object storage device with probabilistic data structure | |
CN114706836A (en) | A Data Lifecycle Management Method Based on Airborne Embedded Database | |
US11068375B2 (en) | System and method for providing machine learning based memory resiliency | |
CN116775669A (en) | Data processing method, device, electronic equipment and computer storage medium | |
US20210294816A1 (en) | Method and system for workload aware storage replication | |
US20180046691A1 (en) | Query governor rules for data replication |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |