WO2023245940A1 - 缓存中数据处理方法及装置 - Google Patents

缓存中数据处理方法及装置 Download PDF

Info

Publication number
WO2023245940A1
WO2023245940A1 PCT/CN2022/127576 CN2022127576W WO2023245940A1 WO 2023245940 A1 WO2023245940 A1 WO 2023245940A1 CN 2022127576 W CN2022127576 W CN 2022127576W WO 2023245940 A1 WO2023245940 A1 WO 2023245940A1
Authority
WO
WIPO (PCT)
Prior art keywords
cache
target
thread
data
state
Prior art date
Application number
PCT/CN2022/127576
Other languages
English (en)
French (fr)
Inventor
夏宇
李鸿哲
Original Assignee
深圳前海微众银行股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳前海微众银行股份有限公司 filed Critical 深圳前海微众银行股份有限公司
Publication of WO2023245940A1 publication Critical patent/WO2023245940A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2365Ensuring data consistency and integrity
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management

Definitions

  • the target cache identifier is assigned to the target thread.
  • Optional also includes:
  • the cache identifier is stored in an inheritable variable of the thread, and allocating at least one target thread to the business processing request corresponding to the target business includes:
  • the cache identification is stored in the custom attribute information of the thread, and allocating at least one target thread to the business processing request corresponding to the target business includes:
  • Allocate at least one target thread to the service processing request corresponding to the target service.
  • Optional also includes:
  • the data value corresponding to the data identifier to be updated in the first cache corresponding to the first state is updated to the data value to be updated, and the system state is set to the first state.
  • Optional also includes:
  • the method further includes:
  • this application discloses a cache data processing device, including:
  • a processing module configured to allocate the same target cache identifier to the at least one target thread according to the system state and the association relationship between the target threads, wherein the system state is a first state or a second state, and in the first state
  • the system state is a first state or a second state
  • data is obtained from the first cache
  • the second state data is obtained from the second cache
  • different caches correspond to different cache identifiers.
  • the first cache and the second cache are used to store the same data
  • the first state indicates that the update of the data in the first cache has been completed according to the data update request, but the update of the data in the second cache has not yet been completed.
  • the second state indicates that the update of the data in the first cache has been completed according to the data update request. Update the data in the second cache;
  • the processing module is also configured to obtain target data from the cache corresponding to the target cache identifier through the at least one target thread, and implement the target service according to the target data.
  • Embodiments of the present application provide a method and device for processing data in cache.
  • the business processing request corresponding to the target business can be obtained first, and at least one target thread can be allocated to the business processing request corresponding to the target business, and then the business processing request corresponding to the target business can be allocated according to
  • the association between the system state and the target thread assigns the same target cache identifier to at least one target thread corresponding to the same business, where the system state can be the first state or the second state, and is obtained from the first cache in the first state
  • Data is obtained from the second cache in the second state, and different caches correspond to different cache identifiers.
  • the first cache and the second cache are used to store the same data.
  • the first state indicates that the pairing has been completed according to the data update request.
  • the data in the first cache is updated, but the update of the data in the second cache has not yet been completed.
  • the second state indicates that the update of the data in the second cache has been completed according to the data update request.
  • the data is fixed, and then the cache identifier of the same cache is assigned to at least one target thread in an interaction process corresponding to a business processing request based on the system status and the correlation between threads, so that the same business can be processed in an interaction process corresponding to
  • the data obtained by the thread is always consistent, which avoids the inconsistency or non-correspondence of the data read by the thread due to data update, improves the accuracy of data acquisition and update, and ensures the normal realization of the business.
  • Figure 1 is a schematic architectural diagram of an application system for the data processing method in cache provided by an embodiment of the present application
  • Figure 2 is a schematic flowchart of a data processing method in cache provided by an embodiment of the present application
  • Figure 3 is a schematic flowchart of a data processing method in cache provided by another embodiment of the present application.
  • FIG. 4 is a schematic flowchart of the cache switching process provided by the embodiment of the present application.
  • Figure 5 is a schematic structural diagram of a data processing device in a cache provided by an embodiment of the present application.
  • FIG. 6 is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present application.
  • the same thread reads the same data cache value before and after the update process, and gets different results. For example, data key1 needs to be updated from v1 to v2. The thread reads key1 before loading the cache to get v1, and reads key1 again after loading the cache to get v2. This situation can be called non-repeatable readability of the parameter cache.
  • the same thread may get incorrect results when reading the associated data cache value before and after the update process.
  • the server regularly loads the latest parameters into the writable cache. After the writing is completed, the cache is switched.
  • the original writable cache becomes a read-only cache
  • the original read-only cache becomes a writable cache.
  • the latest parameters in the switched read-only cache can be read.
  • the thread is the smallest execution unit of the application system, and each interaction (or Business) are processed by multiple associated threads, and the application system can clearly know the start and end of the thread, simplifying the allocation process and maintenance difficulty of cache identifiers, thereby ensuring the normal implementation of the business.
  • Figure 1 is a schematic architectural diagram of an application system for a data processing method in a cache provided by an embodiment of the present application.
  • the application system may include a server, and caches corresponding to different system states are deployed in the server, for example, There may be a first cache corresponding to when the system state is the first state, and a second cache corresponding to the system state being the second state.
  • the first state is the system state when the data in the cache is updated
  • the second state is the system state when the data in the cache is read normally.
  • the service processing request corresponding to the target service can be triggered regularly or in real time.
  • a service processing request can be triggered every preset time period according to a predefined scheduled task to realize the target service (for example, server inspection service, scheduled notification service, etc.).
  • the business processing request can also be triggered in real time according to the user's touch operation, which will not be limited in detail here.
  • S201 Obtain the business processing request corresponding to the target business, and allocate at least one target thread to the business processing request corresponding to the target business.
  • At least one target thread can be allocated to the business processing request corresponding to the target business.
  • the number of target threads can be one or more, and can be allocated according to the actual number of thread requirements of the target task.
  • S202 Assign the same target cache identifier to at least one target thread according to the system state and the association relationship between the target threads, where the system state is the first state or the second state, and data is obtained from the first cache in the first state, In the second state, data is obtained from the second cache, and different caches correspond to different cache identifiers.
  • the first cache and the second cache are used to store the same data.
  • the first state indicates that the first cache has been processed according to the data update request.
  • the data in the cache is updated, but the update of the data in the second cache has not yet been completed.
  • the second state indicates that the update of the data in the second cache has been completed according to the data update request.
  • the value of the same data during one execution of the same target task should be guaranteed to be the same (for example, during one execution of the same target task, the number of ports is always 8888). Since during an execution of the target task, the value of the same data in the cache corresponding to the same system state is the same, therefore, the same system can be allocated to at least one target thread during an execution of the target task.
  • the cache ID corresponding to the state is the cache ID corresponding to the same cache
  • the same system state is the system state determined when the cache ID is assigned to the first target thread.
  • all the cache identifiers corresponding to the first state or the cache identifiers corresponding to the second state are allocated to at least one target thread in an interaction process, so that at least one target thread allocated to the target task can be used during an execution process of the target task.
  • data is always obtained from the same cache, and the data in the cache is fixed in the corresponding current state. For example, in the first state, the data in the first cache corresponding to the first state is fixed, In the second state, the data in the second cache corresponding to the second state is fixed, ensuring the consistency of data reading.
  • the system state can be a first state or a second state.
  • first state data can be obtained from the first cache
  • second state data can be obtained from the second cache
  • different caches correspond to different caches. logo.
  • the first cache and the second cache are used to store the same data.
  • the first state indicates that the update of the data in the first cache has been completed according to the data update request, but the update of the data in the second cache has not yet been completed.
  • the second state indicates that The update of the data in the second cache has been completed according to the data update request.
  • the data in the cache can be updated by receiving a data update request.
  • the data update request can change, delete or add the data in the cache.
  • the data update request can be obtained before receiving the business processing request, can be obtained after receiving the business processing request, and can also be obtained at the same time as the business processing request, which will not be limited in detail here.
  • the target service may be implemented according to the target thread assigned the target cache identifier.
  • the target data can be obtained from the corresponding cache by assigning a target thread with a target cache identifier, and then the target business can be implemented based on the obtained target data.
  • the target business can be account application business, transfer business, limit change business, etc.
  • implementing the target business based on the acquired target data can be implemented using existing methods, which will not be discussed in detail here.
  • the data in the cache is always fixed, that is, in the first state, the data in the first cache corresponding to the first state is always is unchanged; in the second state, the data in the second cache corresponding to the second state is always unchanged, so as to avoid reading the same data from the cache during an interaction process and reading the results before and after. Inconsistency.
  • the target threads with the same target cache identifier can be stored in the same queue, that is, the queue corresponding to the target cache identifier.
  • the target cache identifier can be directly obtained from the target thread.
  • the target thread is obtained from the corresponding queue, and the cache is directly determined based on the target cache identifier corresponding to the queue. There is no need to determine the cache separately for each target thread, which improves the efficiency of data acquisition.
  • allocating the same target cache identifier to the at least one target thread according to the system status and the association between the target threads may specifically include:
  • the target cache identifier is assigned to the target thread.
  • the system status may be determined first, and then the target cache identifier to be allocated may be determined based on the determined system status.
  • the target cache identifier to be allocated may be determined based on the determined system status.
  • the first target thread allocated for the business processing request of the target business is created by the operating system and has no associated thread, so there is no cache identifier allocated by the associated thread. If a target thread does not complete the target business later, it can continue Create a target thread to realize the target business.
  • the target thread created subsequently to continue to realize the target business can be an associated thread of the first target thread, and the target thread can be associated with the association by assigning the cache identifier of the associated thread to the target thread. thread.
  • the target thread may include an associated thread, that is, the associated thread is the first target thread.
  • the target cache identifier is determined to be the cache identifier of the first cache corresponding to the first state.
  • the cache of data to be obtained may be determined based on the determined system status.
  • there can be two caches one is the second cache corresponding to when the system is running normally, when the system state is the second state, and the other is the first cache when the system is updated, when the system state is the first state. state. If it is determined that the system state is the first state, it indicates that data needs to be obtained from the first cache. Therefore, the target cache identifier can be determined as the cache identifier of the first cache; if it is determined that the system state is the second state, it indicates that data needs to be obtained from the first cache. The data is obtained from the second cache. Therefore, the target cache identifier can be determined as the cache identifier of the second cache.
  • the method may further include:
  • the cache identifier assigned by the associated thread is determined as the target cache identifier.
  • the target thread has a cache identifier assigned by an associated thread, it means that the target thread has an associated thread. Then the cache identifier of the associated thread can be obtained directly, and then the cache identifier assigned by the associated thread is determined as the target cache identifier. That is, both the target thread and the target thread's associated threads can obtain data from the cache corresponding to the same cache identifier, ensuring data consistency.
  • the target thread is created for the associated thread, that is, the associated thread is the parent thread of the target thread, and the target thread is the child thread of the associated thread; the other is that the target thread
  • the thread allocated to the thread pool, and the target thread and the associated thread belong to the same interaction process, that is, in the process of the associated thread executing the target business, the thread pool also needs to allocate a new target thread to achieve the complete target business.
  • the cache identification is stored in an inheritable variable of the thread, and allocating at least one target thread to the business processing request corresponding to the target business includes:
  • Allocate at least one target thread to the service processing request corresponding to the target service.
  • the child thread when creating a child thread of an associated thread, you can directly assign values to the inheritable thread variables of the child thread (i.e., the newly created target thread). Therefore, the child thread can also obtain the thread variables of the parent thread and maintain the inheritable thread variables of the parent thread. The values of inherited variables are consistent. Subsequently, if the target thread has a cache ID allocated by the associated thread, the cache ID allocated by the associated thread can be directly determined as the target cache ID.
  • a child thread may be created or a thread pool may allocate threads. If you create a child thread (that is, there is an inheritance relationship between threads), when creating the child thread (that is, the target thread), the parent thread (that is, the associated thread) needs to first determine whether it has an inheritable thread variable InheritableThreadLocal. If it exists, then create the child thread. When threading, assign the inheritable thread variables of the child thread, so that the child thread can also obtain the thread variables of the parent thread, thereby keeping the values of the parent and child threads consistent.
  • the cache ID into the inheritable thread variable of the parent thread, so that the ID can be passed between threads with an inheritance relationship, and the cache ID of the threads in the interaction is guaranteed to be consistent. For example, assuming that a child thread T1 is created in the associated thread T, the cache ID of the associated thread T will be passed to the child thread T1:
  • the cache identification is stored in the custom attribute information of the thread, and allocating at least one target thread for the business processing request corresponding to the target business includes:
  • Allocate at least one target thread to the service processing request corresponding to the target service.
  • the target thread is a thread allocated by the thread pool
  • the inheritance relationship can no longer be passed through the characteristics of the inheritable variable InheritableThreadLocal to ensure the cache identification consistency of the parent and child threads.
  • the inheritance relationship can no longer be passed through the characteristics of the inheritable variable InheritableThreadLocal to ensure the cache identity consistency of the parent and child threads.
  • you can create a new thread modification class RunnableWrapper add a custom attribute information to the modified thread object, and save the cache identification of the associated thread.
  • RunnableWrapper Although the problem of value transfer between threads without inheritance relationships in the thread pool can be solved, this forces the user to use the RunnableWrapper class when creating a thread, which is very intrusive to the user. Therefore, the function of the thread pool can also be enhanced. The user still uses the native Runnable class when creating a thread.
  • the Runnable class can be automatically converted into the RunnableWrapper class, so that there is no intrusion on the user. For example, a new thread Y needs to be created in thread T, and the thread pool allocates thread Y_Wrapper to it:
  • the target data from the cache corresponding to the cache identifier through the at least one target thread it also includes:
  • the inheritable variable of the target thread is set according to the target cache ID (the cache ID of the first cache); similarly , if the target cache identifier is the cache identifier of the second cache corresponding to the second state, the inheritable variable of the target thread can also be set according to the target cache identifier (the cache identifier of the second cache), and the target thread can be added to the corresponding cache read Take the queue. Then the target business can be executed through the thread in the cache queue, the parameter ID to be read and the target cache ID are determined through the business processing request, and then the target parameter corresponding to the parameter ID is obtained from the corresponding cache queue according to the target cache ID.
  • a new target thread is allocated, and the new target thread is allocated a cache identifier of an associated thread, and then a new target thread is allocated to continue executing the aforementioned process.
  • the previous target thread that is, the associated thread of the newly allocated target thread
  • the inheritable thread variable of the thread is cleared. If there is no need for other threads to continue executing, the previous target thread (that is, the associated thread of the newly allocated target thread) will also be deleted from the corresponding cache queue, and the inheritable thread variables of the thread will be cleared to achieve the target business.
  • the global cache block GlobalThreadFlagCache can be initialized first. At this time:
  • Cache read queue B cacheReadQueueB is empty.
  • the parameters can be loaded into cache A and cache B.
  • the application system can receive the business processing request. If it is the first target thread that starts processing, the target thread is created by the application system, and is assumed to be thread T at this time. In addition, if the target business is not processed in one target thread, another new thread needs to be created to continue processing. At this time, there may be a situation where a child thread of the target thread is created or a thread pool allocates threads.
  • the user still uses the native Runnable class when creating a thread.
  • the thread is submitted to the thread pool, we automatically convert the Runnable class into the RunnableWrapper class to ensure no intrusion on the user. For example, assume that a new thread Y needs to be created in thread T, and the thread pool allocates thread Y_Wrapper to it:
  • the function of the target thread executing the target business can be enhanced.
  • the processing logic of assigning the target cache identifier to the target thread is first executed; after the target thread executes the target service, the target thread's recycling process is executed. Because the target threads allocated in the thread pool are of the RunnableWrapper class, these target threads will automatically execute the enhanced code.
  • system status machineStatus NVMAL.
  • the target thread is automatically dyed, and then the process of executing the target business can be entered. If the parameter cache needs to be read, the target cache ID of the current thread can be determined first. If the target cache ID is A, then the Read parameters from cache A, otherwise read parameters from cache B. Assume that thread T needs to read the parameter cache port at this time:
  • Cache read queue B cacheReadQueueB is empty.
  • the inheritable thread variable InheritableThreadLocal of thread T1 is empty.
  • the inheritable thread variable InheritableThreadLocal of thread Y is empty.
  • the target business does not require other threads to continue executing, it indicates that the execution of the target business is completed and the process can be ended.
  • this application has no intrusion into the business logic, so that the application can achieve consistent and repeatable reading of parameter configurations without the user being aware of it. Moreover, the application can safely modify the cache parameters while it is running, and it ensures that when the program uses parameters in an interactive process, the problems of inconsistent reading of parameters and associated parameter errors will not occur, improving the accuracy of data reading.
  • the method may further include:
  • the data update request is received, wherein the data update request includes a data identifier to be updated and a corresponding data value to be updated.
  • the data value corresponding to the data identifier to be updated in the first cache corresponding to the first state is updated to the data value to be updated, and the system state is set to the first state.
  • the data value corresponding to the data identifier to be updated in the second cache corresponding to the second state is updated to the data value to be updated.
  • the data in the cache may be updated.
  • the data value corresponding to the data identifier to be updated in the first cache corresponding to the first state is first updated to the data value to be updated.
  • the data update of the first cache corresponding to the first state has been implemented. Then the system state can be set to the first state, ensuring that in the current state, the corresponding data in the cache is fixed. Then the data needs to be updated in the second cache corresponding to the second state.
  • the method may also include:
  • the next step of switching caches can be performed. Because after the system state is in the first state, the new target thread will read the first cache corresponding to the first state, so you can only determine whether the queue corresponding to the second cache is empty to know whether all threads are reading Get the first cache. If the thread assigned to read the cache identifier of the second cache corresponding to the second state has not completed processing, it can wait for the target duration at random, and then make a new judgment after the target duration.
  • the target duration can be any value from 0 to 60 seconds.
  • Figure 4 is a schematic flow chart of a cache switching process provided by an embodiment of the present application.
  • the data in the first cache corresponding to the first state can be updated first.
  • the system state can be set to the first state, and then the target time can be randomly waited, and then it is determined whether the second cache corresponding to the second state can be updated. If so, the second cache corresponding to the second state can be updated directly. The second cache is updated. Otherwise, wait for the randomly generated target time again and make a judgment again until the second cache corresponding to the second state can be updated, and then directly update the second cache corresponding to the second state.
  • For each target thread determine whether the target thread has a cache identifier assigned by an associated thread.
  • the target cache identifier is assigned to the target thread.
  • processing module 502 is also used to:
  • the target cache identifier is determined to be the cache identifier of the second cache corresponding to the second state.
  • Allocate at least one target thread to the service processing request corresponding to the target service.
  • processing module 502 is also used to:
  • the device provided by the embodiment of the present application can implement the method of the embodiment shown in Figure 2.
  • the implementation principles and technical effects are similar and will not be described again here.
  • FIG. 6 is a schematic diagram of the hardware structure of an electronic device provided by an embodiment of the present application.
  • a device 600 provided by this embodiment includes a processor 601 and a memory communicatively connected to the processor. Among them, the processor 601 and the memory 602 are connected through a bus 603.
  • the processor 601 executes the computer execution instructions stored in the memory 602, so that the processor 601 executes the method in the above method embodiment.
  • the processor may be a central processing unit (English: Central Processing Unit, referred to as: CPU), or other general-purpose processors, digital signal processors (English: Digital Signal Processor, referred to as: DSP), application specific integrated circuit (English: Application Specific Integrated Circuit, referred to as: ASIC), etc.
  • a general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc. The steps of the method disclosed in conjunction with the invention can be directly embodied and executed by a hardware processor, or executed by a combination of hardware and software modules in the processor.
  • the memory may include high-speed RAM memory and may also include non-volatile storage NVM, such as at least one disk memory.
  • the bus can be an Industry Standard Architecture (Industry Standard Architecture, ISA) bus, a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc.
  • ISA Industry Standard Architecture
  • PCI Peripheral Component Interconnect
  • EISA Extended Industry Standard Architecture
  • the bus can be divided into address bus, data bus, control bus, etc.
  • the bus in the drawings of this application is not limited to only one bus or one type of bus.
  • Embodiments of the present application also provide a computer-readable storage medium.
  • Computer-executable instructions are stored in the computer-readable storage medium.
  • the processor executes the computer-executable instructions, the cached data processing method of the above method embodiment is implemented. .
  • An embodiment of the present application also provides a computer program product, which includes a computer program.
  • the computer program When the computer program is executed by a processor, the computer program implements the above-mentioned data processing method in the cache.
  • the above-mentioned computer-readable storage medium can be implemented by any type of volatile or non-volatile storage device or their combination, such as static random access memory (SRAM), electrically erasable memory.
  • SRAM static random access memory
  • EEPROM Programmable read-only memory
  • EPROM erasable programmable read-only memory
  • PROM programmable read-only memory
  • ROM read-only memory
  • Readable storage media can be any available media that can be accessed by a general purpose or special purpose computer.
  • An exemplary readable storage medium is coupled to the processor such that the processor can read information from the readable storage medium and write information to the readable storage medium.
  • the readable storage medium may also be an integral part of the processor.
  • the processor and readable storage medium may be located in Application Specific Integrated Circuits (ASICs for short).
  • ASICs Application Specific Integrated Circuits
  • the processor and the readable storage medium may also exist as discrete components in the device.
  • the aforementioned program can be stored in a computer-readable storage medium.
  • the steps including the above-mentioned method embodiments are executed; and the aforementioned storage media include: ROM, RAM, magnetic disks, optical disks and other media that can store program codes.

Landscapes

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

Abstract

本申请提供了一种缓存中数据处理方法及装置,所述方法包括:获取业务处理请求,并分配至少一目标线程,根据系统状态以及目标线程间的关联关系为至少一目标线程分配相同的目标缓存标识,系统状态为第一状态或第二状态,在第一状态时从第一缓存中获取数据,在第二状态时从第二缓存中获取数据,且不同的缓存对应不同的缓存标识,第一缓存和第二缓存用于存储相同的数据,第一状态表示已根据数据更新请求完成对第一缓存中数据的更新,但第二缓存中数据的更新尚未完成,第二状态表示已根据数据更新请求完成对第二缓存中数据的更新,通过至少一目标线程从与目标缓存标识对应的缓存中获取目标数据来实现目标业务。本申请提高了数据获取与更新的准确性。

Description

缓存中数据处理方法及装置
本申请要求于2022年06月24日提交中国专利局、申请号为202210725664.9、申请名称为“缓存中数据处理方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及数据处理技术领域,尤其涉及一种缓存中数据处理方法及装置。
背景技术
随着计算机技术的发展,越来越多的技术应用在金融领域,传统金融业正在逐步向金融科技(Fintech)转变,数据处理技术也不例外,但由于金融行业的安全性、实时性要求,也对数据处理技术提出了更高的要求。为了满足各金融业务增长的需求,缓存的应用变的越来越普遍。
现有技术中,在实现相关业务时,可以通过线程从缓存中获取数据,然后通过获取的数据来实现相关业务。
然而,由于缓存中的数据可能涉及到更新的情况,且在数据更新时,也需要一定的时间逐一对数据进行更新,可能导致线程在更新前后读取同一数据时,数据值不一致的情况,或者相关联的数据的对应关系存在问题的情况,降低了数据获取与更新的准确性,进而影响了业务的正常实现。
发明内容
本申请的目的在于提供一种缓存中数据处理方法及装置,以提高数据获取与更新的准确性。
第一方面,本申请公开了一种缓存中数据处理方法,包括:
获取目标业务对应的业务处理请求,并为所述目标业务对应的业务处理请求分配至少一目标线程;
根据系统状态以及目标线程间的关联关系为所述至少一目标线程分配相同的目标缓存标识,其中,所述系统状态为第一状态或第二状态,在所述第一状态时从第一缓存中获取数据,在第二状态时从第二缓存中获取数据,且不同的缓存对应不同的缓存标识,所述第一缓存和所述第二缓存用于存储相同的数据,所述第一状态表示已根据数据更新请求完成对所述第一缓存中数据的更新,但所述第二缓存中数据的更新尚未完成,所述第二状态表示已根据所述数据更新请求完成对所述第二缓存中数据的更新;
通过所述至少一目标线程从与所述目标缓存标识对应的缓存中获取目标数据,并根据所述目标数据实现所述目标业务。
可选的,所述根据系统状态以及线程间的关联关系为所述至少一目标线程分配相同的目标缓存标识,包括:
确定系统状态,并根据所述系统状态确定目标缓存标识;
针对每个目标线程,判断所述目标线程是否有关联线程分配的缓存标识;
若所述目标线程没有关联线程分配的缓存标识,则为所述目标线程分配所述目标缓存标识。
可选的,所述根据所述系统状态确定目标缓存标识,包括:
若所述系统状态为第一状态,则确定目标缓存标识为所述第一状态对应的第一缓存的缓存标识;
若所述系统状态为第二状态,则确定目标缓存标识为所述第二状态对应的第二缓存的缓存标识。
可选的,还包括:
若所述目标线程有关联线程分配的缓存标识,则将所述关联线程分配的缓存标识确定为所述目标缓存标识。
可选的,所述缓存标识存储于线程的可继承变量中,所述为所述目标业务对应的业务处理请求分配至少一目标线程,包括:
创建所述关联线程的子线程,得到至少一初始目标线程;
将所述至少一初始目标线程的可继承线程变量设置为所述关联线程的可继承线程变量,得到至少一目标线程;
为所述目标业务对应的业务处理请求分配至少一目标线程。
可选的,所述缓存标识存储于线程的自定义属性信息中,所述为所述目标业务对应的业务处理请求分配至少一目标线程,包括:
从线程池中获取至少一初始目标线程;
将所述至少一初始目标线程的自定义属性信息设置为所述关联线程的自定义属性信息,得到至少一目标线程;
为所述目标业务对应的业务处理请求分配至少一目标线程。
可选的,还包括:
接收所述数据更新请求,其中,所述数据更新请求中包含待更新数据标识以及对应的待更新数据值;
根据所述数据更新请求将所述第一状态对应的第一缓存中所述待更新数据标识对应的数据值更新为所述待更新数据值,并将所述系统状态设置为所述第一状态;
判断已分配所述第二状态对应的缓存标识的线程是否处理完成;
若已处理完成,则将所述第二状态对应的第二缓存中所述待更新数据标识对应的数据值更新为所述待更新数据值;
将所述系统状态更新为所述第二状态。
可选的,还包括:
若未处理完成,则随机等待目标时长;
等待所述目标时长之后,重新执行所述判断已分配所述第二状态对应的缓存标识的线程是否处理完成及之后的步骤。
可选的,在所述通过所述至少一目标线程从与所述目标缓存标识对应的缓存中获取目标数据之后,还包括:
清空所述至少一目标线程的目标缓存标识。
第二方面,本申请公开了一种缓存中数据处理装置,包括:
获取模块,用于获取目标业务对应的业务处理请求,并为所述目标业务对应的业务处理请求分配至少一目标线程;
处理模块,用于根据系统状态以及目标线程间的关联关系为所述至少一目标线程分配相同的目标缓存标识,其中,所述系统状态为第一状态或第二状态,在所述第一状态时从第一缓存中获取数据,在第二状态时从第二缓存中获取数据,且不同的缓存对应不同的缓存标识,所述第一缓存和所述第二缓存用于存储相同的数据,所述第一状态表示已根据数据更新请求完成对所述第一缓存中数据的更新,但所述第二缓存中数据的更新尚未完成,所述第二状态表示已根据所述数据更新请求完成对所述第二缓存中数据的更新;
所述处理模块,还用于通过所述至少一目标线程从与所述目标缓存标识对应的缓存中获取目标数据,并根据所述目标数据实现所述目标业务。
本申请实施例提供了一种缓存中数据处理方法及装置,采用上述方案后,可以先获取目标业务对应的业务处理请求,并为目标业务对应的业务处理请求分配至少一目标线程,然后可以根据系统状态以及目标线程间的关联关系为相同业务对应的至少一目标线程分配相同的目标缓存标识,其中,系统状态可以为第一状态或第二状态,在第一状态时从第一缓存中获取数据,在第二状态时从第二缓存中获取数据,且不同的缓存对应不同的缓存标识,第一缓存和第二缓存用于存储相同的数据,第一状态表示已根据数据更新请求完成对第一缓存中数据的更新,但第二缓存中数据的更新尚未完成,第二状态表示已根据数据更新请求完成对第二缓存中数据的更新,在为相同业务对应的至少一目标线程分配相同的目标缓存标识之后,可以通过至少一目标线程从与目标缓存标识对应的缓存中获取目标数据来实现目标业务,通过先为不同系统状态分配不同的缓存,且在该系统状态下对应的缓存中数据是固定的,然后根据系统状态以及线程间的关联关系为一个业务处理请求对应的一个交互过程中的至少一目标线程分配同一缓存的缓存标识的方式,使得同一业务在一个交互过程中对应的线程获取的数据始终是一致的,避免了由于数据更新导致的线程读取数据不一致或不对应的情况,提高了数据获取与更新的准确性,进而保证了业务的正常实现。
附图说明
图1为本申请实施例提供的缓存中数据处理方法的应用系统的架构示意图;
图2为本申请实施例提供的缓存中数据处理方法的流程示意图;
图3为本申请另一实施例提供的缓存中数据处理方法的流程示意图;
图4为本申请实施例提供的缓存切换过程的流程示意图;
图5为本申请实施例提供的缓存中数据处理装置的结构示意图;
图6为本申请实施例提供的电子设备的硬件结构示意图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本 申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”、“第三”“第四”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本申请的实施例还能够包括除了图示或描述的那些实例以外的其他顺序实例。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。
在实现相关业务(例如,申请账户、转账、购买相关的产品)时,可能涉及到通过线程从缓存中获取数据,然后通过获取的数据来实现相关业务的情况。当缓存中的数据需要更新时,可以通过重新加载数据到缓存中的方式来对缓存中的数据进行更新。然而,由于存储数据的缓存只有一个,即使更新逻辑运行的很快,但仍然是挨个数据进行更新的,可能会导致以下问题:
第一,同一个线程在更新过程前后读取同一个数据缓存值,得到的是不同的结果。例如,数据key1需要从v1更新为v2,线程在缓存加载前读取key1得到v1,在缓存加载后再次读取key1得到v2,可以将该种情况称之为参数缓存的不可重复读性。
第二,同一个线程在更新过程前后读取相关联的数据缓存值时,可能得到错误的结果。例如,有两个相关联的数据,用户名userName和密码password,只有两者相互匹配时才能够认为数据是正确的。现在需要将userName=aaa,password=bbb更新为userName=kkk,password=vvv。因为数据在缓存中更新是一个个进行更新的,可以先将userName从aaa更新为kkk,再将password从bbb更新为vvv,那就可能出现,某线程在这两个参数更新的过程中读取到userName=kkk,而password=bbb,导致实际读取的数据缓存值是错误的,可以将该种情况称之为参数缓存的不一致读性。
上述两种情况降低了数据获取与更新的准确性,进而影响了业务的正常实现。
现有技术中有涉及到通过两个缓存来解决前述问题的情况,具体过程为:服务端启动时初始化两块缓存,其中一块只读,另一块可写。在交互请求开始前,客户端先请求服务端获取sessionId,服务端分配sessionId并维护sessionId和只读缓存的对应关系。客户端在获取参数缓存时,带上sessionId,服务端根据sessionId返回对应参数缓存内的值,在一个交互内,sessionId相同,所以读取的参数缓存块也相同。交互请求完成前,客户端通知服务器,删除sessionId和只读缓存的对应关系。服务器定期将最新的参数加载到可写缓存中,等写入完成后,进行缓存切换,原可写缓存变为只读缓存,原只读缓存变为可写缓存。后续新进交互请求时,可以读取切换后的只读缓存中的最新参数。
然而,上述方案是否能有效实现参数的实时一致性及可重复读的更新,需要依赖业务系统能够准确"向服务端申请sessionId(用于服务端分配正确的缓存)"和"向服务端申请删除sessionId(服务端在更新缓存时需要判断该缓存已没有客户端在使用)",存在接入成本高和可靠性差的问题。即使用方在接入上述方案时,需要在每个交互请求入口申请sessionId,在交互请求出口删除sessionId,即使此步骤对实际的业务处理逻辑来说无意义。且由于应用系统通常有多个交互入口,例如分布式系统有多个监听入口、定时任务执行入口等,使 用该方案时需要使用方分析找到系统内所有可能的交互入口,在入口处增加"向服务端申请sessionId"的逻辑。另外,因为一个交互流程中,不止存在预期中的交互结果出口,例如交互成功、交互失败、交互超时等;还存在不可预测的异常结束出口,例如代码缺陷异常、网络异常、机器故障等。对于预期中的出口,使用方可以手动调用删除sessionId操作,但是对于不可预测的异常结束出口,使用方很难对其所有情况都保证调用了删除sessionId的操作。为了保证不遗漏交互出口删除sessionId的操作,使用方需要大量的分析和验证。如果业务系统某些交互入口处遗漏"向服务端申请sessionId"的逻辑,那么该交互内部多次获取参数缓存,仍然存在前述所述的问题。
基于上述技术问题,本申请通过先为不同系统状态分配不同的缓存,且在该系统状态下对应的缓存中数据是固定的,然后根据系统状态以及线程间的关联关系为一个业务处理请求对应的一个交互过程中的至少一目标线程分配同一缓存的缓存标识的方式,使得同一业务在一个交互过程中对应的线程获取的数据始终是一致的,避免了由于数据更新导致的线程读取数据不一致或不对应的情况,提高了数据获取与更新的准确性,进而保证了业务的正常实现,且本申请以线程为维度来分配缓存标识的,线程是应用系统的最小执行单位,每个交互(或业务)都是由多个相关联的线程进行处理的,而应用系统可以明确知道线程的开始和结束的,简化了缓存标识的分配过程与维护难度,进而保证了业务的正常实现。
图1为本申请实施例提供的缓存中数据处理方法的应用系统的架构示意图,如图1所示,在该应用系统中,可以包括服务器,服务器中部署有不同系统状态对应的缓存,例如,可以有系统状态为第一状态时对应的第一缓存,以及系统状态为第二状态时对应的第二缓存。其中,第一状态为为缓存中的数据被更新时的系统状态,第二状态为缓存中的数据正常读取时的系统状态。
服务器在获取到目标业务对应的业务处理请求(其中,一个业务处理请求可以对应一个交互过程)之后,可以为目标业务对应的业务处理请求分配至少一目标线程,然后根据系统状态以及目标线程间的关联关系为至少一目标线程分配相同的目标缓存标识,并通过至少一目标线程从与目标缓存标识对应的缓存中获取目标数据,然后可以根据目标数据实现目标业务。示例性的,目标缓存标识可以为第二状态对应的第二缓存的缓存标识,则可以从第二状态对应的第二缓存中获取目标数据。
可选的,目标业务对应的业务处理请求可以为定时触发的,也可以为实时触发的。对应的,可以根据预先定义的定时任务每隔预设时长触发一业务处理请求来实现目标业务(例如,服务器巡检业务,定时通知业务等)。还可以根据用户的触控操作来实时触发业务处理请求,在此不再详细进行限定。
下面以具体地实施例对本申请的技术方案进行详细说明。下面这几个具体的实施例可以相互结合,对于相同或相似的概念或过程可能在某些实施例不再赘述。
图2为本申请实施例提供的缓存中数据处理方法的流程示意图,本实施例的方法可以由服务器执行。如图2所示,本实施例的方法,可以包括:
S201:获取目标业务对应的业务处理请求,并为目标业务对应的业务处理请求分配至少一目标线程。
在本实施例中,在实现目标业务时,可以通过触发业务处理请求的方式来实现。可选的,可以定时触发业务处理请求,也可以基于用户的触控操作实时触发业务处理请求。此 外,可以在服务器本地直接获取目标业务对应的业务处理请求,也可以获取终端设备发送的目标业务对应的业务处理请求,在此不再详细进行限定。
此外,在获取到业务处理请求之后,可以为目标业务对应的业务处理请求分配至少一目标线程。其中,目标线程的数量可以为一个或多个,具体可以根据目标任务的实际线程需求数量进行分配。
S202:根据系统状态以及目标线程间的关联关系为至少一目标线程分配相同的目标缓存标识,其中,系统状态为第一状态或第二状态,在第一状态时从第一缓存中获取数据,在第二状态时从第二缓存中获取数据,且不同的缓存对应不同的缓存标识,第一缓存和第二缓存用于存储相同的数据,第一状态表示已根据数据更新请求完成对第一缓存中数据的更新,但第二缓存中数据的更新尚未完成,第二状态表示已根据数据更新请求完成对第二缓存中数据的更新。
在本实施例中,为了避免出现数据读取不一致或不对应的情况,同一目标任务在一次执行过程中同一数据的数值应保证是相同的(例如,同一目标任务在一次执行过程中,端口数始终为8888),由于在目标任务的一次执行过程中,同一系统状态对应的缓存中同一数据的数值是相同的,因此,可以在目标任务的一次执行过程中,为至少一目标线程分配同一系统状态对应的缓存标识,即同一缓存对应的缓存标识,且同一系统状态是为第一个目标线程分配缓存标识时确定的系统状态。即可以为一个交互过程中的至少一目标线程均分配第一状态对应的缓存标识或均分配第二状态对应的缓存标识,使得为目标任务分配的至少一目标线程,在目标任务的一次执行过程中,始终从同一个缓存中获取数据,且该缓存中的数据在对应的当前状态下数据是固定的,如在第一状态下,第一状态对应的第一缓存中的数据是固定的,在第二状态下,第二状态对应的第二缓存中的数据是固定的,保证了数据读取的一致性。
此外,系统状态可以为第一状态或第二状态,在第一状态时可以从第一缓存中获取数据,在第二状态时可以从第二缓存中获取数据,且不同的缓存对应不同的缓存标识。其中,第一缓存和第二缓存用于存储相同的数据,第一状态表示已根据数据更新请求完成对第一缓存中数据的更新,但第二缓存中数据的更新尚未完成,第二状态表示已根据数据更新请求完成对第二缓存中数据的更新。可选的,在需要对缓存中数据进行更新时,可以通过接收数据更新请求的方式来实现对缓存中数据的更新。在接收数据更新请求时,系统状态为第二状态,即此时线程为从第二状态对应的第二缓存中获取数据的,因此,可以先对第一状态对应的第一缓存中的数据进行更新,第一缓存中的数据更新完成之后,可以将系统状态更新为第一状态,此时线程需要从第一状态对应的第一缓存中获取数据,因此,可以在此时对第二状态对应的第二缓存中的数据进行更新,避免了由于数据更新造成的线程读取数据不一致的情况。此外,在对第二状态对应的第二缓存中的数据进行更新时,为了保证同一交互过程对应的线程从缓存中获取到的数据是一致的,可以在确定读取第二缓存的线程均执行完毕之后,再对第二状态对应的第二缓存中的数据进行更新。
可选的,目标线程可以为一个或多个。在接收到业务处理请求之后,可以先为目标业务对应的业务处理请求分配一个目标线程,然后根据系统状态为该目标线程分配一目标缓存标识,该目标线程可以通过分配的目标缓存标识从对应的缓存中获取目标数据。在目标线程执行完之后,还可以判断目标业务是否还需要其他的线程来继续实现目标业务。即可 以判断目标业务是否已完成,若已完成,则可以结束流程;若没有完成,则可以继续分配目标线程,并根据新分配的目标线程与前述目标线程之间的关联关系确定目标缓存标识,新分配的目标线程可以通过分配的目标缓存标识从对应的缓存中获取目标数据,直至目标任务完成。其中,新分配的目标线程与前述目标线程的目标缓存标识相同,即新分配的目标线程与前述目标线程均从同一缓存中获取数据,且该缓存中的数据在当前系统状态下是不变的,保证了数据读取的一致性。
其中,数据更新请求可以对缓存中的数据进行更改操作、删除操作或增加操作。且数据更新请求可以在接收业务处理请求之前获取,可以在接收业务处理请求之后获取,还可以与业务处理请求同时获取,在此不再详细进行限定。
S203:通过至少一目标线程从与目标缓存标识对应的缓存中获取目标数据,并根据目标数据实现目标业务。
在本实施例中,目标线程可以为一个或多个,在为目标线程分配了目标缓存标识之后,可以根据分配目标缓存标识的目标线程实现目标业务。对应的,可以通过分配目标缓存标识的目标线程从对应的缓存中获取目标数据,然后根据获取的目标数据来实现目标业务。示例性的,目标业务可以为账号申请业务、转账业务、额度变更业务等。另外,根据获取的目标数据来实现目标业务可以采用现有的方式实现,在此不再详细进行论述。
此外,还可以通过保证在同一交互过程中的线程读取缓存中数据时,该缓存中数据始终是固定不变的方式,即在第一状态时,第一状态对应的第一缓存中数据始终是不变的;在第二状态时,第二状态对应的第二缓存中数据始终是不变的,以此来避免出现在一个交互过程中,从缓存中读取同一数据出现前后读取结果不一致的情况。
此外,在为目标线程分配目标缓存标识之后,可以将目标缓存标识相同的目标线程存储至同一队列中,即目标缓存标识对应的队列,后续在通过目标线程获取数据时,可以直接从目标缓存标识对应的队列中来获取目标线程,并根据队列对应的目标缓存标识直接确定缓存,无需再针对每个目标线程分别确定一次缓存,提高了数据获取的效率。
采用上述方案后,可以先获取目标业务对应的业务处理请求,并为目标业务对应的业务处理请求分配至少一目标线程,然后可以根据系统状态以及目标线程间的关联关系为相同业务对应的至少一目标线程分配相同的目标缓存标识,其中,系统状态可以为第一状态或第二状态,在第一状态时从第一缓存中获取数据,在第二状态时从第二缓存中获取数据,且不同的缓存对应不同的缓存标识,第一缓存和第二缓存用于存储相同的数据,第一状态表示已根据数据更新请求完成对第一缓存中数据的更新,但第二缓存中数据的更新尚未完成,第二状态表示已根据数据更新请求完成对第二缓存中数据的更新,在为相同业务对应的至少一目标线程分配相同的目标缓存标识之后,可以通过至少一目标线程从与目标缓存标识对应的缓存中获取目标数据来实现目标业务,通过先为不同系统状态分配不同的缓存,且在该系统状态下对应的缓存中数据是固定的,然后根据系统状态以及线程间的关联关系为一个业务处理请求对应的一个交互过程中的至少一目标线程分配同一缓存的缓存标识的方式,使得同一业务在一个交互过程中对应的线程获取的数据始终是一致的,避免了由于数据更新导致的线程读取数据不一致或不对应的情况,提高了数据获取与更新的准确性,进而保证了业务的正常实现。
基于图2的方法,本说明书实施例还提供了该方法的一些具体实施方案,下面进行说 明。
在另一实施例中,所述根据系统状态以及目标线程间的关联关系为所述至少一目标线程分配相同的目标缓存标识,具体可以包括:
确定系统状态,并根据所述系统状态确定目标缓存标识。
针对每个目标线程,判断所述目标线程是否有关联线程分配的缓存标识。
若所述目标线程没有关联线程分配的缓存标识,则为所述目标线程分配所述目标缓存标识。
在本实施例中,在为目标业务的业务处理请求分配至少一目标线程之后,可以先确定系统状态,然后根据确定的系统状态确定待分配的目标缓存标识。此外,在确定系统状态之后,针对每个目标线程,可以先判断目标线程是否有关联线程分配的缓存标识。一般来说,为目标业务的业务处理请求分配的第一个目标线程为操作系统创建的,没有关联线程,因此也没有关系线程分配的缓存标识,后续若一个目标线程没有完成目标业务,可以继续创建目标线程来实现目标业务,后续创建的继续实现该目标业务的目标线程可以为第一个目标线程的关联线程,且可以通过为目标线程分配关联线程的缓存标识的方式来关联目标线程与关联线程。其中,目标线程可以包含关联线程,即关联线程为第一个目标线程。
进一步的,所述根据所述系统状态确定目标缓存标识,具体可以包括:
若所述系统状态为第一状态,则确定目标缓存标识为所述第一状态对应的第一缓存的缓存标识。
若所述系统状态为第二状态,则确定目标缓存标识为所述第二状态对应的第二缓存的缓存标识。
在本实施例中,在确定系统状态之后,可以根据确定的系统状态来确定待获取数据的缓存。对应的,缓存可以有两个,一个为系统正常运行时对应的第二缓存,此时系统状态为第二状态,另一个为系统被更新时对应的第一缓存,此时系统状态为第一状态。若确定系统状态为第一状态,则表明需要从第一缓存中获取数据,因此,可以将目标缓存标识确定为第一缓存的缓存标识;若确定系统状态为第二状态,则表明需要从第二缓存中获取数据,因此,可以将目标缓存标识确定为第二缓存的缓存标识。
在另一实施例中,所述方法还可以包括:
若所述目标线程有关联线程分配的缓存标识,则将所述关联线程分配的缓存标识确定为所述目标缓存标识。
在本实施例中,若目标线程有关联线程分配的缓存标识,则表明该目标线程有关联线程,则可以直接获取关联线程的缓存标识,然后将关联线程分配的缓存标识确定为目标缓存标识,即目标线程与目标线程的关联线程均可以从同一缓存标识对应的缓存中获取数据,保证了数据的一致性。
此外,目标线程与关联线程的关系可以有两种,一种是目标线程为关联线程创建的,即关联线程为目标线程的父线程,目标线程为关联线程的子线程;另一种为目标线程为线程池分配的线程,且目标线程与关联线程均属于同一交互过程,即在关联线程执行目标业务的过程中,还需要线程池分配新的目标线程才能实现完整的目标业务。
进一步的,在一种实现方式中,所述缓存标识存储于线程的可继承变量中,所述为所述目标业务对应的业务处理请求分配至少一目标线程,包括:
创建所述关联线程的子线程,得到至少一初始目标线程。
将所述至少一初始目标线程的可继承线程变量设置为所述关联线程的可继承线程变量,得到至少一目标线程。
为所述目标业务对应的业务处理请求分配至少一目标线程。
具体的,在创建关联线程的子线程时,可以直接对子线程(即新创建的目标线程)的可继承线程变量进行赋值,子线程因此也可以获取父线程的线程变量并保持父子线程的可继承变量的值一致。后续若目标线程有关联线程分配的缓存标识,则可以直接将关联线程分配的缓存标识确定为目标缓存标识。
示例性的,若目标业务没有在一个线程内处理完毕,则需要另外新建线程来继续处理,此时会存在创建子线程或线程池分配线程的情况。若是创建子线程(即线程间有继承关系),在创建子线程(即目标线程)时,父线程(即关联线程)需要先判断自己是否存在可继承线程变量InheritableThreadLocal,如果存在,则在创建子线程时,将子线程的可继承线程变量进行赋值,这样子线程也可以获得父线程的线程变量,进而保持父子线程的值一致。对应的,可以将缓存标识放入父线程的可继承线程变量中,这样在有继承关系的线程之间,此标识可以一直传递,并保证交互内的线程的缓存标识是一致的。例如,假设关联线程T中创建了子线程T1,那么关联线程T的缓存标识会传递给子线程T1:
线程T的可继承线程变量InheritableThreadLocal={readCacheFlag=A};
子线程T1的可继承线程变量InheritableThreadLocal={readCacheFlag=A}。
进一步的,在另一种实现方式中,所述缓存标识存储于线程的自定义属性信息中,所述为所述目标业务对应的业务处理请求分配至少一目标线程,包括:
从线程池中获取至少一初始目标线程。
将所述至少一初始目标线程的自定义属性信息设置为所述关联线程的自定义属性信息,得到至少一目标线程。
为所述目标业务对应的业务处理请求分配至少一目标线程。
具体的,若目标线程为线程池分配的线程,因为线程池分配的线程之间无继承关系,因此不能再通过可继承变量InheritableThreadLocal的特性来传递继承关系,保证父子线程的缓存标识一致性。为了解决这个问题,可以新建一个线程修饰类RunnableWrapper,为被修饰的线程对象增加一个自定义属性信息,并通过该自定义属性信息来保存关联线程的缓存标识。
示例性的,因为线程池分配的线程之间无继承关系,因此,无法再通过可继承变量InheritableThreadLocal的特性来传递继承关系,保证父子线程的缓存标识一致性。为了解决这个问题,可以新建一个线程修饰类RunnableWrapper,为被修饰的线程对象增加一个自定义属性信息,保存关联线程的缓存标识。在使用RunnableWrapper类时,虽然可以解决线程池中无继承关系的线程间传值问题,但这强制要求使用方在创建线程时使用RunnableWrapper类,对使用方的侵入性很大。所以还可以对线程池做功能增强,使用方仍然在创建线程时使用原生的Runnable类,在线程提交到线程池时,可以自动将Runnable类转换为RunnableWrapper类,做到对使用方的无侵入。例如,线程T中需要新建线程Y,线程池为其分配了线程Y_Wrapper:
线程T的可继承线程变量InheritableThreadLocal={readCacheFlag=A};
Y_Wrapper对象{parentReadCacheFlag=A;runnable=线程Y}。
综上,通过采用不同方式的方式为线程分配目标缓存标识,实现了对线程的自动染色,且保证了同一交互过程中的线程分配的目标缓存标识是相同的,进而使得同一交互过程中的线程获取的数据是相同的,保证了数据读取的一致性与准确性。
此外,在所述通过所述至少一目标线程从与所述缓存标识对应的缓存中获取目标数据之后,还包括:
清空所述至少一目标线程的目标缓存标识。
综上,通过清空目标线程的目标缓存标识,可以直接对目标线程进行回收处理,增加了目标线程的回收效率,进而节省了设备的计算资源。
图3为本申请另一实施例提供的缓存中数据处理方法的流程示意图,如图3所示,在该实施例中,可以先接收目标业务的业务处理请求,然后为目标业务的业务处理请求创建一目标线程,创建完成之后,线程执行开始。可以进行缓存决策,确定目标缓存标识,若目标缓存标识为第一状态对应的第一缓存的缓存标识,则根据目标缓存标识(第一缓存的缓存标识)设置目标线程的可继承变量;同理,若目标缓存标识为第二状态对应的第二缓存的缓存标识,则也可以根据目标缓存标识(第二缓存的缓存标识)设置目标线程的可继承变量,并将目标线程加入对应的缓存读取队列中。然后可以通过缓存队列中的线程执行目标业务,通过业务处理请求确定待读取的参数标识,以及目标缓存标识,然后根据目标缓存标识从对应的缓存队列中获取与参数标识对应的目标参数。然后判断是否需要其他线程继续执行,若是,则分配新的目标线程,同时为新的目标线程分配关联线程的缓存标识,然后分配新的目标线程继续执行前述过程。同时将之前的目标线程(即新分配的目标线程的关联线程)从对应的缓存队列中删除,并清空该线程的可继承线程变量。若不需要其他线程继续执行,也将之前的目标线程(即新分配的目标线程的关联线程)从对应的缓存队列中删除,并清空该线程的可继承线程变量,进而实现目标业务。
在本实施例中,操作系统启动时,可以先初始化全局缓存块GlobalThreadFlagCache,此时:
系统状态machineStatus=NORMAL(正常)。
缓存读取队列A cacheReadQueueA为空。
缓存读取队列B cacheReadQueueB为空。
然后可以将参数加载到缓存A和缓存B中,使用方可以自定义将想要的参数加载到缓存A和缓存B中,可以假设加载了一个参数键值对port=8888,此时:
缓存A cacheA={port=8888}。
缓存B cacheB={port=8888}。
当启动目标业务之后,此时应用系统可以接收到业务处理请求,如果是开始处理的第一个目标线程,则该目标线程是由应用系统创建的,此时假设为线程T。此外,若目标业务没有在一个目标线程内处理完毕,需要另外新建线程来继续处理,此时会存在创建该目标线程的子线程或线程池分配线程的情况。
可选的,若为创建子线程,父线程需要判断自己是否存在可继承线程变量InheritableThreadLocal,如果存在,则在创建子线程时,将子线程的可继承线程变量进行赋值,这样子线程也能获得父线程的线程变量并保持父子线程的值一致。然后可以将缓存标 识放入线程的可继承线程变量中,这样在有继承关系的线程之间,此标识可以一直传递,并保证交易内的线程的缓存标识是一致的。
假设线程T中创建了子线程T1,那么线程T的缓存读取标识会传递给子线程T1:
线程T的可继承线程变量InheritableThreadLocal={readCacheFlag=A}。
子线程T1的可继承线程变量InheritableThreadLocal={readCacheFlag=A}。
可选的,若为线程池分配线程的情况,因为线程池分配的线程之间,无继承关系,所以不能再通过可继承变量InheritableThreadLocal的特性来传递继承关系,保证父子线程的缓存标识一致性。为了解决这个问题,可以新建一个线程修饰类RunnableWrapper,为被修饰的线程对象增加一个属性,保存关联线程的缓存读取标识。此外,虽然使用RunnableWrapper类可以解决线程池中无继承关系的线程间传值问题,但这强制要求使用方在创建线程时使用RunnableWrapper类,对使用方的侵入性很大。所以可以对线程池做功能增强处理,使用方仍然在创建线程时使用原生的Runnable类,在线程提交到线程池时,我们自动将Runnable类转换为RunnableWrapper类,做到对使用方的无侵入。示例性的,假设线程T中需要新建线程Y,线程池为其分配了线程Y_Wrapper:
线程T的可继承线程变量InheritableThreadLocal={readCacheFlag=A}。
Y_Wrapper对象{parentReadCacheFlag=A;runnable=线程Y}。
然后可以进入线程执行开始流程,可以分为创建的目标线程和分配的目标线程两种情况来描述:
可选的,若为创建的目标线程,可以为创建的线程进行自动染色和褪色,示例性的,可以使用AOP(Aspect Oriented Programming,面向切面编程)技术,在目标线程执行目标业务之前,可以自动进入为目标线程分配目标缓存标识的处理逻辑,在执行目标业务之后,可以自动进入回收目标线程的处理逻辑。具体处理过程可以为:定义一个切点,对所有实现了java.lang.Runnable.run()方法的类进行功能增强,即执行目标业务的过程。然后可以定义切点环绕方法,在执行目标业务前后做增强处理。然后可以执行静态编译,将增强处理代码自动加入到所有目标线程的执行代码中,不需要使用方额外增加处理。
在分配目标线程时,在RunnableWrapper类中,可以对目标线程执行目标业务的过程进行功能增强。在目标线程执行目标业务之前,先执行为目标线程分配目标缓存标识的处理逻辑;在执行目标业务之后,再执行目标线程的回收过程。因为线程池中分配的目标线程都是RunnableWrapper类,所以这些目标线程都会自动执行增强代码。
另外,在进行缓存决策时,可以调用GlobalThreadFlagCache的judgeUseWhichCache方法。此方法的默认实现方式为:根据当前系统状态确定当前的目标线程应使用的缓存,如果系统状态为NOMAL(即第二状态),则读取正常状态对应的缓存的缓存标识(示例性的,可以为A),否则读取更新状态对应的缓存的缓存标识缓存(示例性的,可以为B)。
示例性的,系统状态machineStatus=NORMAL。
缓存读取标识readCacheFlag=A。
此外,在设置目标线程的可继承线程变量时,可以调用GlobalThreadFlagCache的markThread方法。具体的,可以先判断是否有关联线程,如果有则使用关联线程的缓存读取标识为自己的可继承变量赋值,如果没有关联线程,则使用上一步骤决策出的缓存读取标识为自己的可继承线程变量赋值。
示例性的,若是第一次进入目标业务的处理过程的目标线程T,所以目标线程T没有关联线程,则使用上一步骤决策出的目标缓存标识为自己的可继承线程变量赋值。即目标线程T的可继承线程变量InheritableThreadLocal={readCacheFlag=A}。
若是目标线程T中创建的子线程T1,因为子线程T1和目标线程T有继承关系,所以子线程T1直接使用目标线程T的目标缓存标识为自己的可继承线程变量赋值。即子线程T1的可继承线程变量InheritableThreadLocal={readCacheFlag=A}。
若是线程池为目标线程T分配的线程Y_Wrapper,线程Y_Wrapper可以根据自己的parentReadCacheFlag属性判断自己存在关联线程,所以可以使用关联线程的缓存标识为其修饰的线程Y的可继承线程变量赋值。即Y_Wrapper对象{parentReadCacheFlag=A;runnable=线程Y},线程Y的可继承线程变量InheritableThreadLocal={readCacheFlag=A}。
此外,还可以将目标线程加入对应的缓存读取队列中,实际可以调用GlobalThreadFlagCache的markThread方法。如果目标线程的目标缓存标识为A,则可以将目标线程放入缓存队列A中,否则放入缓存队列B中。在后续切换缓存时,我们可以根据缓存队列中是否还存在目标线程的方式来获知系统中线程使用缓存的情况,进而判断是否可以切换缓存。此时:
缓存读取队列A cacheReadQueueA=[线程T的线程id]。
缓存读取队列B cacheReadQueueB为空。
经过前述过程,实现了对目标线程的自动染色,然后可以进入执行目标业务的过程,如果在其中需要读取参数缓存,可以先判断当前线程的目标缓存标识,如果目标缓存标识为A,则从缓存A中读取参数,否则从缓存B中读取参数。假设线程T此时需要读取参数缓存port:
因为线程T的InheritableThreadLocal={readCacheFlag=A},所以我们从缓存A中读取port的值,结果返回8888。
然后可以判断是否还需要其他目标线程,若需要,则可以根据前述目标线程的可继承线程变量来为新的目标线程赋值。然后可以调用GlobalThreadFlagCache的clearThreadFlag方法,将目标线程从对应的缓存队列中删除,表示该目标线程不再去读对应的缓存,此时:
缓存读取队列A cacheReadQueueA为空。
缓存读取队列B cacheReadQueueB为空。
另外,还可以调用GlobalThreadFlagCache的clearThreadFlag方法,将目标线程的可继承线程变量置空。因此,创建的线程会被系统回收,不会再次使用,但是线程池分配的线程不会被回收,可能存在重复使用的情况,为了避免线程再次使用时还在使用上次赋值的缓存读取标识,造成参数读取错误,所以需要在此步骤中对线程的可继承线程变量置空,此时:
线程T的可继承线程变量InheritableThreadLocal为空。
线程T1的可继承线程变量InheritableThreadLocal为空。
线程Y的可继承线程变量InheritableThreadLocal为空。
另外,如果目标业务不需要其他线程继续执行,则表明目标业务执行完成,可以结束流程。
综上,本申请对业务逻辑无侵入,使得在使用方无感知的情况下,应用程序即可实现 参数配置的一致读和可重复读。且应用程序在运行时可安全修改缓存参数,并且保证了程序是一个交互流程内使用参数时,不会发生参数两次读取不一致和关联参数错误的问题,提高了数据读取的准确性。
在另一实施例中,所述方法还可以包括:
接收所述数据更新请求,其中,所述数据更新请求中包含待更新数据标识以及对应的待更新数据值。
根据所述数据更新请求将所述第一状态对应的第一缓存中所述待更新数据标识对应的数据值更新为所述待更新数据值,并将所述系统状态设置为所述第一状态。
判断已分配所述第二状态对应的缓存标识的线程是否处理完成。
若已处理完成,则将所述第二状态对应的第二缓存中所述待更新数据标识对应的数据值更新为所述待更新数据值。
将所述系统状态更新为所述第二状态。
在本实施例中,缓存中的数据可能涉及到更新的情况,在对缓存中的数据进行更新时,为了避免出现同一交互过程中线程读取缓存中数据前后不一致或不对应的情况,可以在接收到数据更新请求时,先将第一状态对应的第一缓存中待更新数据标识对应的数据值更新为待更新数据值,至此,已经实现了第一状态对应的第一缓存的数据更新,然后可以将系统状态设置为第一状态,保证了在当前状态下,对应的缓存中数据是固定的。然后还需要对第二状态对应的第二缓存进行数据更新,由于需要保证同一交互过程中线程从缓存中读取的数据一致,因此,需要等到读取第二缓存的线程读取数据完成之后,在对第二状态对应的第二缓存进行数据更新。具体的,可以先判断已分配第二状态对应的缓存标识的线程是否处理完成,若已处理完成,则将第二状态对应的第二缓存中待更新数据标识对应的数据值更新为待更新数据值,并将系统状态更新为第二状态。
此外,所述方法还可以包括:
若未处理完成,则随机等待目标时长。
等待所述目标时长之后,重新执行所述判断已分配所述第二状态对应的缓存标识的线程是否处理完成及之后的步骤。
具体的,只有当应用系统中所有的线程都在读取第一缓存时,才能进行下一步的切换缓存的过程。因为系统状态处在第一状态后,新的目标线程都会读取第一状态对应的第一缓存,所以可以只判断第二缓存对应的队列是否为空,即可知道是否所有的线程都在读取第一缓存。若已分配读取第二状态对应的第二缓存的缓存标识的线程未处理完成,则可以随机等待目标时长,目标时长之后再重新进行判断。其中,目标时长可以为0-60秒中的任意值。
综上,通过等待随机设置的目标时长,可以提高切换缓存的成功率,进而保证了数据读取的一致性。
图4为本申请实施例提供的缓存切换过程的流程示意图,如图4所示,在该实施例中,可以先对第一状态对应的第一缓存中的数据进行更新,第一缓存中的数据更新完成之后,可以将系统状态设置为第一状态,然后可以随机等待目标时长,然后判断是否可以对第二状态对应的第二缓存进行更新,若可以,则可以直接对第二状态对应的第二缓存进行更新,否则,重新等待随机生成的目标时长,再次进行判断,直至可以对第二状态对应的第二缓 存进行更新,然后直接对第二状态对应的第二缓存进行更新。
综上,通过在读取第二缓存的线程处理完成之后,再对第二缓存进行更新的方式,保证了同一交易过程中线程读取缓存数据的一致性,提高了数据读取的准确性。
基于同样的思路,本说明书实施例还提供了上述方法对应的装置,图5为本申请实施例提供的缓存中数据处理装置的结构示意图,如图5所示,
本实施例提供的装置,可以包括:
获取模块501,用于获取目标业务对应的业务处理请求,并为所述目标业务对应的业务处理请求分配至少一目标线程;
处理模块502,用于根据系统状态以及目标线程间的关联关系为所述至少一目标线程分配相同的目标缓存标识,其中,所述系统状态为第一状态或第二状态,在所述第一状态时从第一缓存中获取数据,在第二状态时从第二缓存中获取数据,且不同的缓存对应不同的缓存标识,所述第一缓存和所述第二缓存用于存储相同的数据,所述第一状态表示已根据数据更新请求完成对所述第一缓存中数据的更新,但所述第二缓存中数据的更新尚未完成,所述第二状态表示已根据所述数据更新请求完成对所述第二缓存中数据的更新;
所述处理模块502,还用于通过所述至少一目标线程从与所述目标缓存标识对应的缓存中获取目标数据,并根据所述目标数据实现所述目标业务。
在另一实施例中,所述处理模块502,还用于:
确定系统状态,并根据所述系统状态确定目标缓存标识。
针对每个目标线程,判断所述目标线程是否有关联线程分配的缓存标识。
若所述目标线程没有关联线程分配的缓存标识,则为所述目标线程分配所述目标缓存标识。
在本实施例中,所述处理模块502,还用于:
若所述系统状态为第一状态,则确定目标缓存标识为所述第一状态对应的第一缓存的缓存标识。
若所述系统状态为第二状态,则确定目标缓存标识为所述第二状态对应的第二缓存的缓存标识。
在本实施例中,所述处理模块502,还用于:
若所述目标线程有关联线程分配的缓存标识,则将所述关联线程分配的缓存标识确定为所述目标缓存标识。
在本实施例中,所述处理模块502,所述缓存标识存储于线程的可继承变量中,还用于:
创建所述关联线程的子线程,得到至少一初始目标线程。
将所述至少一初始目标线程的可继承线程变量设置为所述关联线程的可继承线程变量,得到至少一目标线程。
为所述目标业务对应的业务处理请求分配至少一目标线程。
在本实施例中,所述处理模块502,所述缓存标识存储于线程的自定义属性信息中,还用于:
从线程池中获取至少一初始目标线程。
将所述至少一初始目标线程的自定义属性信息设置为所述关联线程的自定义属性信 息,得到至少一目标线程。
为所述目标业务对应的业务处理请求分配至少一目标线程。
在本实施例中,所述处理模块502,还用于:
清空所述至少一目标线程的目标缓存标识。
在另一实施例中,所述处理模块502,还用于:
接收数据更新请求,其中,所述数据更新请求中包含待更新数据标识以及对应的待更新数据值。
根据所述数据更新请求将所述第一状态对应的第一缓存中所述待更新数据标识对应的数据值更新为所述待更新数据值,并将所述系统状态设置为所述第一状态。
判断已分配所述第二状态对应的缓存标识的线程是否处理完成。
若已处理完成,则将所述第二状态对应的第二缓存中所述待更新数据标识对应的数据值更新为所述待更新数据值。
将所述系统状态更新为所述第二状态。
在本实施例中,所述处理模块502,还用于:
若未处理完成,则随机等待目标时长。
等待所述目标时长之后,重新执行所述判断已分配所述第二状态对应的缓存标识的线程是否处理完成及之后的步骤。
本申请实施例提供的装置,可以实现上述如图2所示的实施例的方法,其实现原理和技术效果类似,此处不再赘述。
图6为本申请实施例提供的电子设备的硬件结构示意图,如图6所示,本实施例提供的设备600包括:处理器601,以及与所述处理器通信连接的存储器。其中,处理器601、存储器602通过总线603连接。
在具体实现过程中,处理器601执行所述存储器602存储的计算机执行指令,使得处理器601执行上述方法实施例中的方法。
处理器601的具体实现过程可参见上述方法实施例,其实现原理和技术效果类似,本实施例此处不再赘述。
在上述的图6所示的实施例中,应理解,处理器可以是中央处理单元(英文:Central Processing Unit,简称:CPU),还可以是其他通用处理器、数字信号处理器(英文:Digital Signal Processor,简称:DSP)、专用集成电路(英文:Application Specific Integrated Circuit,简称:ASIC)等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。结合发明所公开的方法的步骤可以直接体现为硬件处理器执行完成,或者用处理器中的硬件及软件模块组合执行完成。
存储器可能包含高速RAM存储器,也可能还包括非易失性存储NVM,例如至少一个磁盘存储器。
总线可以是工业标准体系结构(Industry Standard Architecture,ISA)总线、外部设备互连(Peripheral Component Interconnect,PCI)总线或扩展工业标准体系结构(Extended Industry Standard Architecture,EISA)总线等。总线可以分为地址总线、数据总线、控制总线等。为便于表示,本申请附图中的总线并不限定仅有一根总线或一种类型的总线。
本申请实施例还提供一种计算机可读存储介质,所述计算机可读存储介质中存储有计 算机执行指令,当处理器执行所述计算机执行指令时,实现上述方法实施例的缓存中数据处理方法。
本申请实施例还提供一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时,实现如上所述的缓存中数据处理方法。
上述的计算机可读存储介质,上述可读存储介质可以是由任何类型的易失性或非易失性存储设备或者它们的组合实现,如静态随机存取存储器(SRAM),电可擦除可编程只读存储器(EEPROM),可擦除可编程只读存储器(EPROM),可编程只读存储器(PROM),只读存储器(ROM),磁存储器,快闪存储器,磁盘或光盘。可读存储介质可以是通用或专用计算机能够存取的任何可用介质。
一种示例性的可读存储介质耦合至处理器,从而使处理器能够从该可读存储介质读取信息,且可向该可读存储介质写入信息。当然,可读存储介质也可以是处理器的组成部分。处理器和可读存储介质可以位于专用集成电路(Application Specific Integrated Circuits,简称:ASIC)中。当然,处理器和可读存储介质也可以作为分立组件存在于设备中。
本领域普通技术人员可以理解:实现上述各方法实施例的全部或部分步骤可以通过程序指令相关的硬件来完成。前述的程序可以存储于一计算机可读取存储介质中。该程序在执行时,执行包括上述各方法实施例的步骤;而前述的存储介质包括:ROM、RAM、磁碟或者光盘等各种可以存储程序代码的介质。
最后应说明的是:以上各实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述各实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分或者全部技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的范围。

Claims (13)

  1. 一种缓存中数据处理方法,其特征在于,包括:
    获取目标业务对应的业务处理请求,并为所述目标业务对应的业务处理请求分配至少一目标线程;
    根据系统状态以及目标线程间的关联关系为所述至少一目标线程分配相同的目标缓存标识,其中,所述系统状态为第一状态或第二状态,在所述第一状态时从第一缓存中获取数据,在所述第二状态时从第二缓存中获取数据,且不同的缓存对应不同的缓存标识,所述第一缓存和所述第二缓存用于存储相同的数据,所述第一状态表示已根据数据更新请求完成对所述第一缓存中数据的更新,但所述第二缓存中数据的更新尚未完成,所述第二状态表示已根据所述数据更新请求完成对所述第二缓存中数据的更新;
    通过所述至少一目标线程从与所述目标缓存标识对应的缓存中获取目标数据,并根据所述目标数据实现所述目标业务。
  2. 根据权利要求1所述的方法,其特征在于,所述根据系统状态以及目标线程间的关联关系为所述至少一目标线程分配相同的目标缓存标识,包括:
    确定系统状态,并根据所述系统状态确定目标缓存标识;
    针对每个目标线程,判断所述目标线程是否有关联线程分配的缓存标识;
    若所述目标线程没有关联线程分配的缓存标识,则为所述目标线程分配所述目标缓存标识。
  3. 根据权利要求2所述的方法,其特征在于,所述根据所述系统状态确定目标缓存标识,包括:
    若所述系统状态为第一状态,则确定目标缓存标识为所述第一状态对应的第一缓存的缓存标识;
    若所述系统状态为第二状态,则确定目标缓存标识为所述第二状态对应的第二缓存的缓存标识。
  4. 根据权利要求2或3所述的方法,其特征在于,还包括:
    若所述目标线程有关联线程分配的缓存标识,则将所述关联线程分配的缓存标识确定为所述目标缓存标识。
  5. 根据权利要求4所述的方法,其特征在于,所述缓存标识存储于线程的可继承变量中,所述为所述目标业务对应的业务处理请求分配至少一目标线程,包括:
    创建所述关联线程的子线程,得到至少一初始目标线程;
    将所述至少一初始目标线程的可继承线程变量设置为所述关联线程的可继承线程变量,得到至少一目标线程;
    为所述目标业务对应的业务处理请求分配至少一目标线程。
  6. 根据权利要求4或5所述的方法,其特征在于,所述缓存标识存储于线程的自定义属性信息中,所述为所述目标业务对应的业务处理请求分配至少一目标线程,包括:
    从线程池中获取至少一初始目标线程;
    将所述至少一初始目标线程的自定义属性信息设置为所述关联线程的自定义属性信息,得到至少一目标线程;
    为所述目标业务对应的业务处理请求分配至少一目标线程。
  7. 根据权利要求1-6任一项所述的方法,其特征在于,还包括:
    接收所述数据更新请求,其中,所述数据更新请求中包含待更新数据标识以及对 应的待更新数据值;
    根据所述数据更新请求将所述第一状态对应的第一缓存中所述待更新数据标识对应的数据值更新为所述待更新数据值,并将所述系统状态设置为所述第一状态;
    判断已分配所述第二状态对应的缓存标识的线程是否处理完成;
    若已处理完成,则将所述第二状态对应的第二缓存中所述待更新数据标识对应的数据值更新为所述待更新数据值;
    将所述系统状态更新为所述第二状态。
  8. 根据权利要求7所述的方法,其特征在于,还包括:
    若未处理完成,则随机等待目标时长;
    等待所述目标时长之后,重新执行所述判断已分配所述第二状态对应的缓存标识的线程是否处理完成及之后的步骤。
  9. 根据权利要求1-8任一项所述的方法,其特征在于,在所述通过所述至少一目标线程从与所述目标缓存标识对应的缓存中获取目标数据之后,还包括:
    清空所述至少一目标线程的目标缓存标识。
  10. 一种缓存中数据处理装置,其特征在于,包括:
    获取模块,用于获取目标业务对应的业务处理请求,并为所述目标业务对应的业务处理请求分配至少一目标线程;
    处理模块,用于根据系统状态以及目标线程间的关联关系为所述至少一目标线程分配相同的目标缓存标识,其中,所述系统状态为第一状态或第二状态,在所述第一状态时从第一缓存中获取数据,在第二状态时从第二缓存中获取数据,且不同的缓存对应不同的缓存标识,所述第一缓存和所述第二缓存用于存储相同的数据,所述第一状态表示已根据数据更新请求完成对所述第一缓存中数据的更新,但所述第二缓存中数据的更新尚未完成,所述第二状态表示已根据所述数据更新请求完成对所述第二缓存中数据的更新;
    所述处理模块,还用于通过所述至少一目标线程从与所述目标缓存标识对应的缓存中获取目标数据,并根据所述目标数据实现所述目标业务。
  11. 一种电子设备,其特征在于,包括处理器和存储器;其中,
    所述存储器,用于存储程序代码;
    所述处理器,用于调用所述存储器中所存储的程度代码,执行权利要求1~9中任一项所述的方法。
  12. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有指令,当该指令在计算机上运行时,使得计算机执行权利要求1~9中任一项所述的方法。
  13. 一种计算机程序,其特征在于,包括程序代码,当计算机运行所述计算机程序时,所述程序代码执行如权利要求1~9中任一项所述的方法。
PCT/CN2022/127576 2022-06-24 2022-10-26 缓存中数据处理方法及装置 WO2023245940A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210725664.9 2022-06-24
CN202210725664.9A CN115061816A (zh) 2022-06-24 2022-06-24 缓存中数据处理方法及装置

Publications (1)

Publication Number Publication Date
WO2023245940A1 true WO2023245940A1 (zh) 2023-12-28

Family

ID=83201833

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/127576 WO2023245940A1 (zh) 2022-06-24 2022-10-26 缓存中数据处理方法及装置

Country Status (2)

Country Link
CN (1) CN115061816A (zh)
WO (1) WO2023245940A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115061816A (zh) * 2022-06-24 2022-09-16 深圳前海微众银行股份有限公司 缓存中数据处理方法及装置

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2011086230A (ja) * 2009-10-19 2011-04-28 Ntt Comware Corp キャッシュシステム及びキャッシュアクセス方法
US20110138129A1 (en) * 2009-12-09 2011-06-09 International Business Machines Corporation Cache management for a number of threads
JP2011164919A (ja) * 2010-02-09 2011-08-25 Ntt Comware Corp キャッシュシステム及びキャッシュアクセス方法
CN113094430A (zh) * 2021-03-25 2021-07-09 北京达佳互联信息技术有限公司 一种数据处理方法、装置、设备以及存储介质
CN113343088A (zh) * 2021-06-09 2021-09-03 北京奇艺世纪科技有限公司 数据处理方法、系统、装置、设备及存储介质
CN115061816A (zh) * 2022-06-24 2022-09-16 深圳前海微众银行股份有限公司 缓存中数据处理方法及装置

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2011086230A (ja) * 2009-10-19 2011-04-28 Ntt Comware Corp キャッシュシステム及びキャッシュアクセス方法
US20110138129A1 (en) * 2009-12-09 2011-06-09 International Business Machines Corporation Cache management for a number of threads
JP2011164919A (ja) * 2010-02-09 2011-08-25 Ntt Comware Corp キャッシュシステム及びキャッシュアクセス方法
CN113094430A (zh) * 2021-03-25 2021-07-09 北京达佳互联信息技术有限公司 一种数据处理方法、装置、设备以及存储介质
CN113343088A (zh) * 2021-06-09 2021-09-03 北京奇艺世纪科技有限公司 数据处理方法、系统、装置、设备及存储介质
CN115061816A (zh) * 2022-06-24 2022-09-16 深圳前海微众银行股份有限公司 缓存中数据处理方法及装置

Also Published As

Publication number Publication date
CN115061816A (zh) 2022-09-16

Similar Documents

Publication Publication Date Title
CN107766101B (zh) App启动事件的处理方法、装置和设备
US20200120082A1 (en) Techniques for securing credentials used by functions
US8607200B2 (en) Executing a web application at different stages in the application life cycle
US7908521B2 (en) Process reflection
US9904585B1 (en) Error handling in executing workflow state machines
US9003412B1 (en) Performing identified repeatable computations in a changing computing environment
US9766927B1 (en) Data flow management in processing workflows
US20230036357A1 (en) Method and apparatus for authority control, computer device and storage medium
US11924117B2 (en) Automated local scaling of compute instances
US10063644B1 (en) Managing operation of instances
WO2023245940A1 (zh) 缓存中数据处理方法及装置
US11113186B1 (en) Testing and publishing of resource handlers in a cloud environment
US20230205561A1 (en) Managing containers across multiple operating systems
WO2022267179A1 (zh) 动态限流熔断配置方法、装置、设备及存储介质
US10761863B2 (en) Mobile application management by run-time insertion of a replacement instrumentation object into a mobile application process
CN109634569B (zh) 基于注解的流程实现方法、装置、设备及可读存储介质
US11681520B2 (en) Software upgrading using dynamic link library injection
US11431795B2 (en) Method, apparatus and storage medium for resource configuration
CN110489576B (zh) 图片资源处理方法和系统、客户端、服务器、处理器及介质
CN112835639A (zh) 一种Hook实现方法、装置、设备、介质及产品
US10698703B2 (en) Mobile application management by run-time insertion of a substitute application class loader into a mobile application process
CN108628620B (zh) Pos应用开发的实现方法、装置、计算机设备和存储介质
CN116346728A (zh) 低代码平台限流方法及装置
US11327824B2 (en) Using a web server to obtain service data for a failed software application
US20220376992A1 (en) Network Function Management

Legal Events

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

Ref document number: 22947677

Country of ref document: EP

Kind code of ref document: A1