[go: up one dir, main page]

CN114647625A - A method, device and storage medium for data caching - Google Patents

A method, device and storage medium for data caching Download PDF

Info

Publication number
CN114647625A
CN114647625A CN202011496893.5A CN202011496893A CN114647625A CN 114647625 A CN114647625 A CN 114647625A CN 202011496893 A CN202011496893 A CN 202011496893A CN 114647625 A CN114647625 A CN 114647625A
Authority
CN
China
Prior art keywords
node
service
general
cache
data
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
Application number
CN202011496893.5A
Other languages
Chinese (zh)
Inventor
李愿波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Uniview Technologies Co Ltd
Original Assignee
Zhejiang Uniview Technologies Co Ltd
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 Zhejiang Uniview Technologies Co Ltd filed Critical Zhejiang Uniview Technologies Co Ltd
Priority to CN202011496893.5A priority Critical patent/CN114647625A/en
Publication of CN114647625A publication Critical patent/CN114647625A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/172Caching, prefetching or hoarding of files
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • G06F16/182Distributed file systems

Landscapes

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

Abstract

The embodiment of the application discloses a data caching method, a data caching device and a storage medium, which are applied to a caching node comprising a general node and a service node, wherein the method comprises the following steps: when the service operates the data of the bottom layer, judging whether the cache node is hit; when the cache node is hit, if the periodic service hits the universal node, selecting the service node, copying the content of the hit universal node into the selected service node, and releasing the hit universal node; when the cache node is not hit, if the service is a general service, selecting the general node, and copying the data targeted by the operation to the selected general node; and if the service is a periodic service, selecting a service node, and copying data needing to be cached by the periodic service to the selected service node. By the scheme, the cache data of the periodic service can be maximally persisted.

Description

一种进行数据缓存的方法、装置和存储介质A method, device and storage medium for data caching

技术领域technical field

本申请实施例涉及但不限于缓存领域,尤其涉及一种进行数据缓存的方法、装置和存储介质。The embodiments of the present application relate to, but are not limited to, the field of caching, and in particular, relate to a method, an apparatus, and a storage medium for data caching.

背景技术Background technique

缓存节点类型一般分为文件类型和目录类型,从实际使用场景中出发,对于文件和目录的访问是最频繁的。监控领域的数据有一个很显著的特点,数据量大,且稳定增长。由于空间有限,因此都会制定满覆盖策略进行录像留存期的保护,同时还穿插着检索回放等业务操作,对于缓存节点而言,检索回放等业务是不定时的,访问的数据随机性也比较大;但是周期性业务比如满覆盖业务,作为持久运行的业务,该业务访问数据区域相对是比较固定的,也就是说当访问数据时,删除最老的用户目录和文件。正常的业务逻辑中,扫描底层获取出最老文件和目录并存储在缓存信息中,后续被检索或回放等业务占用掉,导致下一次满覆盖时,缓存节点中已经没有上一次扫描出的结果,需要重新扫描底层文件,缓存无法结合实际业务需要持久化缓存部分业务所需节点信息。Cache node types are generally divided into file types and directory types. From the actual usage scenario, access to files and directories is the most frequent. The data in the monitoring field has a very significant feature, the amount of data is large and growing steadily. Due to the limited space, a full coverage strategy will be formulated to protect the recording retention period, and at the same time, business operations such as retrieval and playback are also interspersed. For cache nodes, services such as retrieval and playback are irregular, and the data accessed is also relatively random. ; However, for periodic services such as full coverage services, as a persistently running service, the access data area of this service is relatively fixed, that is to say, when accessing data, the oldest user directory and file are deleted. In normal business logic, scan the bottom layer to obtain the oldest files and directories and store them in the cache information, which will be occupied by services such as retrieval or playback later. As a result, when the next full coverage occurs, there will be no results from the previous scan in the cache node. , the underlying files need to be rescanned, and the cache cannot combine the actual business needs to persist the node information required by some businesses.

发明内容SUMMARY OF THE INVENTION

以下是对本文详细描述的主题的概述。本概述并非是为了限制权利要求的保护范围。The following is an overview of the topics detailed in this article. This summary is not intended to limit the scope of protection of the claims.

本公开实施例公开了一种进行数据缓存的方法、装置和存储介质,可以实现对周期性业务的缓存数据能够最大持久化。The embodiments of the present disclosure disclose a method, an apparatus and a storage medium for data caching, which can achieve maximum persistence of cached data for periodic services.

本公开提供了一种进行数据缓存的方法,应用于对包括通用节点和业务节点的缓存节点进行数据缓存,方法包括:The present disclosure provides a method for data caching, which is applied to data caching for a cache node including a general node and a service node. The method includes:

当业务对底层的数据进行操作时,判断是否命中缓存节点;When the business operates on the underlying data, determine whether the cache node is hit;

当命中缓存节点时,如果是周期性业务命中通用节点,则选取业务节点,将所命中的通用节点中的内容复制到所选取的业务节点中,释放所命中的通用节点;When hitting the cache node, if the periodic service hits the general node, select the business node, copy the content of the hit general node to the selected business node, and release the hit general node;

当未命中缓存节点时,如果所述业务为通用业务,则选取通用节点,将操作针对的数据复制到选取的通用节点中;如果所述业务为周期性业务,则选取业务节点,将该周期性业务需要缓存的数据复制到选取的业务节点中。When the cache node is not hit, if the service is a general service, a general node is selected, and the data targeted by the operation is copied to the selected general node; if the service is a periodic service, a service node is selected, and the periodic service is selected. Sexual business needs to copy the cached data to the selected business node.

一种示例性的实施例中,多个通用节点依次相连构成通用节点段,多个业务节点依次相连构成业务节点段;其中,所述通用节点段和业务节点段中的缓存节点分别遵循先进先出原则;In an exemplary embodiment, a plurality of general nodes are connected in sequence to form a general node segment, and a plurality of service nodes are connected in sequence to form a service node segment; wherein, the cache nodes in the general node segment and the service node segment respectively follow a first-in-first-out order. out the principle;

所述缓存节点还包括头节点,用于保存缓存节点的地址信息。The cache node further includes a head node for storing address information of the cache node.

一种示例性的实施例中,所述缓存节点形成节点链表;In an exemplary embodiment, the cache nodes form a linked list of nodes;

所述头节点包括链表头和业务头节点,所述地址信息为业务头节点的地址;所述链表头用于保存业务头节点的地址;所述节点链表中依次包括链表头、通用节点段、业务头节点及业务节点段。The head node includes a linked list header and a service head node, and the address information is the address of the service head node; the linked list header is used to store the address of the service head node; the node linked list sequentially includes a linked list header, a general node segment, Service head node and service node segment.

一种示例性的实施例中,所述选取业务节点包括:In an exemplary embodiment, the selecting a service node includes:

根据所述头节点中的地址信息,选取位于业务节点段开头的一个或多个业务节点;According to the address information in the head node, select one or more service nodes located at the beginning of the service node segment;

所述选取通用节点包括:The selection of general nodes includes:

根据所述头节点中的地址信息,选取位于通用节点段开头的一个或多个通用节点。According to the address information in the head node, one or more general nodes located at the beginning of the general node segment are selected.

一种示例性的实施例中,所述将所命中的通用节点中的内容复制到所选取的业务节点中,释放所命中的通用节点包括:In an exemplary embodiment, copying the content in the hit general node to the selected service node, and releasing the hit general node includes:

使用所命中的通用节点中的内容更新所选取的业务节点,将所选取的业务节点移动到所述业务节点段的最后;Use the content in the hit general node to update the selected service node, and move the selected service node to the end of the service node segment;

清空所命中的通用节点的内容,将所命中的通用节点移动到所述通用节点段的开头。The contents of the hit general node are cleared, and the hit general node is moved to the beginning of the general node segment.

一种示例性的实施例中,所述将操作针对的数据复制到选取的通用节点中包括:In an exemplary embodiment, the copying of the data targeted by the operation to the selected general node includes:

使用操作针对的数据更新该通用节点的内容,将该通用节点移动到所述通用节点段的最后;updating the content of the generic node with the data targeted by the operation, moving the generic node to the end of the generic node segment;

所述将该周期性业务需要缓存的数据复制到选取的业务节点中包括:The copying of the data that needs to be cached for the periodic service to the selected service node includes:

使用该周期性业务需要缓存的数据更新该业务节点,将该业务节点移动到所述业务节点段的最后。The service node is updated using the data that the periodic service needs to cache, and the service node is moved to the end of the service node segment.

一种示例性的实施例中,当命中缓存节点时,所述方法还包括:In an exemplary embodiment, when the cache node is hit, the method further includes:

如果是通用业务命中通用节点或业务节点,则判断通用业务的类型,如果是写操作则更新所命中的缓存节点的内容;如果是删除操作则清空所命中的缓存节点的内容;如果是读操作则访问所命中的缓存节点的内容;If the general service hits the general node or service node, then judge the type of the general service, if it is a write operation, update the content of the hit cache node; if it is a delete operation, clear the content of the hit cache node; if it is a read operation Then access the content of the hit cache node;

如果是周期性业务命中业务节点,则访问所命中的业务节点的内容。If the periodic service hits the service node, the content of the hit service node is accessed.

一种示例性的实施例中,所述缓存节点按照不同的数据类型划分为多个节点链表;每个节点链表中均包含通用节点和业务节点;In an exemplary embodiment, the cache node is divided into multiple node linked lists according to different data types; each node linked list includes a general node and a service node;

所述当业务对底层的数据进行操作时,判断是否命中缓存节点包括:When the business operates on the underlying data, determining whether to hit the cache node includes:

当业务对底层的数据进行操作时,根据待操作数据的数据类型选择相应的节点链表,遍历所选择的节点链表,判断是否命中缓存节点;When the business operates the underlying data, select the corresponding node list according to the data type of the data to be operated, traverse the selected node list, and determine whether the cache node is hit;

所述选取业务节点包括:在所选择的节点链表中选取业务节点;The selecting a service node includes: selecting a service node in the selected node linked list;

所述选取通用节点包括:在所选择的节点链表中选取通用节点。The selecting a general node includes: selecting a general node in the selected node linked list.

本公开还提供了一种装置,包括存储器和处理器;应用于对包括通用节点和业务节点的缓存节点进行数据缓存,所述存储器用于保存用于进行数据缓存的程序,所述处理器用于读取执行所述用于进行数据缓存的程序,执行上述实施例中任一项所述的方法。The present disclosure also provides an apparatus including a memory and a processor; it is applied to data caching for a cache node including a general node and a service node, the memory is used for storing a program for data caching, and the processor is used for data caching The program for data caching is read and executed, and the method described in any one of the foregoing embodiments is executed.

本公开还提供了一种存储介质,所述存储介质中存储有用于基于包括通用节点和业务节点的缓存节点进行数据缓存的程序,所述程序被设置为在运行时执行上述实施例中任一项所述的方法。The present disclosure also provides a storage medium, where a program for data caching based on a cache node including a general node and a service node is stored in the storage medium, and the program is configured to execute any one of the foregoing embodiments at runtime method described in item.

本公开实施例公开了一种数据缓存的方法、装置和存储介质,应用在包括通用节点和业务节点的缓存节点上,所述方法包括:当业务对底层的数据进行操作时,判断是否命中缓存节点;当命中缓存节点时,如果是周期性业务命中通用节点,则选取业务节点,将所命中的通用节点中的内容复制到所选取的业务节点中,释放所命中的通用节点;当未命中缓存节点时,如果所述业务为通用业务,则选取通用节点,将操作针对的数据复制到选取的通用节点中;如果所述业务为周期性业务,则选取业务节点,将该周期性业务需要缓存的数据复制到选取的业务节点中。通过本公开的方案,无需占用更多缓存即可保障周期性业务的缓存数据不被通用业务覆盖,从而保证周期性业务的缓存数据能够最大持久化。The embodiment of the present disclosure discloses a data cache method, device and storage medium, which are applied to a cache node including a general node and a service node. The method includes: when a service operates on underlying data, judging whether the cache is hit or not node; when hitting the cache node, if the periodic business hits the general node, select the business node, copy the content of the hit general node to the selected business node, and release the hit general node; When caching a node, if the business is a general business, select a general node, and copy the data for the operation to the selected general node; if the business is a periodic business, select a business node, and the periodic business needs The cached data is copied to the selected business node. With the solution of the present disclosure, it is possible to ensure that the cached data of the periodic service is not covered by the general service without occupying more caches, thereby ensuring that the cached data of the periodic service can be persisted to the greatest extent.

在阅读并理解了附图和详细描述后,可以明白其他方面。Other aspects will become apparent upon reading and understanding of the drawings and detailed description.

附图说明Description of drawings

图1为本申请实施例的进行数据缓存的方法流程图;1 is a flowchart of a method for data caching according to an embodiment of the present application;

图2为一些示例性实施例中的缓存节点分层结构示意图;FIG. 2 is a schematic diagram of a hierarchical structure of cache nodes in some exemplary embodiments;

图3为一些示例性实施例中单链表分段组织示意图;FIG. 3 is a schematic diagram of a segmented organization of a singly linked list in some exemplary embodiments;

图4a为一些示例性实施例中所使用的节点在节点链表中移动的示意图;Figure 4a is a schematic diagram of a node moving in a linked list of nodes used in some exemplary embodiments;

图4b为一些示例性实施例中所使用的节点移动后该节点链表的示意图;4b is a schematic diagram of the node linked list after the node used in some exemplary embodiments is moved;

图5为一些示例性实施例中周期性业务进行数据缓存的处理流程图;5 is a process flow diagram of data caching performed by periodic services in some exemplary embodiments;

图6为一些示例性实施例中通用业务进行数据缓存的处理流程图;FIG. 6 is a process flow diagram of data caching performed by a general service in some exemplary embodiments;

图7为一些示例性实施例中初始化分层和分段后缓存节点示意图;FIG. 7 is a schematic diagram of a cache node after initialization layering and segmentation in some exemplary embodiments;

图8为一些示例性实施例中目录节点链表示意图;FIG. 8 is a schematic diagram of a directory node linked list in some exemplary embodiments;

图9为一些示例性实施例中文件节点链表示意图;9 is a schematic diagram of a file node linked list in some exemplary embodiments;

图10为一些示例性实施例中变化后的目录节点链表示意图;FIG. 10 is a schematic diagram of a changed directory node linked list in some exemplary embodiments;

图11为一些示例性实施例中变化后的文件节点链表示意图;11 is a schematic diagram of a changed file node linked list in some exemplary embodiments;

图12为本申请实施例的装置示意图。FIG. 12 is a schematic diagram of an apparatus according to an embodiment of the present application.

具体实施方式Detailed ways

下文中将结合附图对本申请实施例进行详细说明。需要说明的是,在不冲突的情况下,本申请实施例及实施例中的特征可以相互任意组合。Hereinafter, the embodiments of the present application will be described in detail with reference to the accompanying drawings. It should be noted that, in the case of no conflict, the embodiments of the present application and the features in the embodiments may be arbitrarily combined with each other.

在附图的流程图示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行。并且,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。The steps shown in the flowcharts of the figures may be performed in a computer system, such as a set of computer-executable instructions. Also, although a logical order is shown in the flowcharts, in some cases the steps shown or described may be performed in an order different from that herein.

一种解决方案中,针对周期性业务专门分配一片缓存,新开辟的缓存专门服务于周期性业务,而不提供给通用业务使用。但是,由于该新开辟的缓存空间不提供给通用业务使用,这样通用业务访问时,即使该新开辟的缓存空间中已缓存有通用业务要访问的数据,通用业务仍需要去查底层数据,然后再占用通用缓存,即,相同的底层数据会存在两份缓存,因此造成了缓存空间的资源浪费;而且当通用业务需要对新开辟的缓存对应的底层数据进行写操作时,需要同时更新通用缓存和新开辟的缓存中相应的内容,否则会造成缓存和底层不一致的问题,流程上做保护较复杂。In one solution, a cache is specially allocated for periodic services, and the newly developed cache is dedicated to serving periodic services and not provided for general services. However, since the newly opened cache space is not provided for general services, when accessing the general services, even if the data to be accessed by the general services is already cached in the newly opened cache space, the general services still need to check the underlying data, and then The general cache is then occupied, that is, there will be two caches for the same underlying data, resulting in a waste of cache space resources; and when the general business needs to write the underlying data corresponding to the newly opened cache, the general cache needs to be updated at the same time. and the corresponding content in the newly developed cache, otherwise the cache and the bottom layer will be inconsistent, and the process of protection is more complicated.

本公开实施例提供了一种进行数据缓存的方法,应用在包括通用节点和业务节点的缓存节点上,如图1所示,所述方法包括:An embodiment of the present disclosure provides a method for data caching, which is applied to a cache node including a general node and a service node. As shown in FIG. 1 , the method includes:

S100、当业务对底层的数据进行操作时,判断是否命中缓存节点;S100, when the business operates on the underlying data, determine whether the cache node is hit;

当命中缓存节点时进行步骤S210,未命中缓存节点时进行步骤S220。Step S210 is performed when the cache node is hit, and step S220 is performed when the cache node is not hit.

S210、如果是周期性业务命中通用节点,则选取业务节点,将所命中的通用节点中的内容复制到所选取的业务节点中,释放所命中的通用节点;S210, if the periodic service hits the general node, then select the service node, copy the content in the hit general node to the selected service node, and release the hit general node;

S220、如果所述业务为通用业务,则选取通用节点,将操作针对的数据复制到选取的通用节点中;如果所述业务为周期性业务,则选取业务节点,将该周期性业务需要缓存的数据复制到选取的业务节点中。S220. If the service is a general service, select a general node, and copy the data targeted by the operation to the selected general node; if the service is a periodic service, select a service node, and the periodic service needs to be cached The data is copied to the selected business node.

本实施例中,命中缓存节点可以是指通用业务操作所针对的数据,或周期性业务需要缓存的数据已保存在缓存节点中,这个用来保存通用业务操作所针对的数据,或周期性业务需要缓存的数据的缓存节点,即所命中的缓存节点。In this embodiment, the hit cache node may refer to the data targeted by the general service operation, or the data that needs to be cached for the periodic service has been stored in the cache node, which is used to save the data targeted by the general service operation, or the periodic service The cache node of the data that needs to be cached, that is, the hit cache node.

本实施例中,底层数据可以但不限于是指硬盘上的数据。In this embodiment, the underlying data may, but is not limited to, refer to data on a hard disk.

本实施例中,由于将缓存节点划分为通用节点和业务节点,而且在需要新增缓存(即未命中缓存节点)时,通用业务和周期性业务各自选用相应的缓存节点,因此可以避免通用业务使用缓存时覆盖掉周期性业务已有的缓存数据,可以保证周期性业务的缓存数据最大持久化;当周期性业务命中通用节点时,则将通用节点中的内容置换到业务节点中,这样可以避免相同数据存在两份缓存,节省了缓存资源的同时还能更易于保障缓存和底层数据的一致性。In this embodiment, since the cache nodes are divided into general nodes and service nodes, and when a new cache needs to be added (ie, the cache node is not hit), the corresponding cache nodes are selected for the general service and the periodic service respectively, so the general service can be avoided. When using the cache, the existing cached data of the periodic service is overwritten, which can ensure the maximum persistence of the cached data of the periodic service; when the periodic service hits the general node, the content in the general node is replaced with the service node, which can Avoiding the existence of two caches for the same data saves cache resources and makes it easier to ensure the consistency of cache and underlying data.

本实施例中,业务操作时,是在全部缓存节点中进行查找,即通用业务和周期性业务都可以访问彼此的缓存节点,因此增加了周期性业务缓存命中率,同时也保障了通用业务的缓存命中率。In this embodiment, during the service operation, search is performed in all the cache nodes, that is, both the general service and the periodic service can access each other's cache nodes, so the cache hit rate of the periodic service is increased, and the general service is also guaranteed. Cache hit rate.

本实施例中,业务节点和通用节点在总的缓存节点中各自的占比可以根据需求自行设置。In this embodiment, the respective proportions of service nodes and general-purpose nodes in the total cache nodes can be set by themselves according to requirements.

一种示例性实施例中,多个通用节点依次相连构成通用节点段,多个业务节点依次相连构成业务节点段;其中,所述通用节点段和业务节点段中的缓存节点分别遵循先进先出原则;In an exemplary embodiment, a plurality of general nodes are connected in sequence to form a general node segment, and a plurality of service nodes are connected in sequence to form a service node segment; wherein, the cache nodes in the general node segment and the service node segment follow a first-in-first-out sequence, respectively. in principle;

所述缓存节点还包括头节点,用于保存缓存节点的地址信息。The cache node further includes a head node for storing address information of the cache node.

其中,所述头节点可以包括两部分,分别位于通用节点段和业务节点段的开头。或者所述头节点只有一个,位于通用节点段和业务节点段中任一个节点段的开头,并用地址信息指示另一个节点段的地址。Wherein, the head node may include two parts, which are respectively located at the beginning of the general node segment and the service node segment. Or there is only one head node, which is located at the beginning of any node segment in the general node segment and the service node segment, and uses address information to indicate the address of the other node segment.

本实施例中,比如可以将缓存节点放在一个节点链表中,则头节点可以包括链表头和业务头节点,节点链表中依次包括:链表头、通用节点段、业务头节点和业务节点段。或者,可以业务节点段放在通用节点段的前面,头节点相应包括链表头和位于业务节点段与通用节点段之间的通用头节点。In this embodiment, for example, the cache node may be placed in a node linked list, and the head node may include a linked list header and a service header node, and the node linked list sequentially includes: a linked list header, a general node segment, a service header node, and a service node segment. Alternatively, the service node segment can be placed in front of the general node segment, and the head node correspondingly includes a linked list header and a general head node located between the service node segment and the general node segment.

本实施例中,所述通用节点段和业务节点段中的缓存节点分别遵循先进先出原则可以是指:In this embodiment, the cache nodes in the general node segment and the service node segment respectively follow the first-in-first-out principle may refer to:

当访问一通用节点或更新一通用节点的内容后,将该通用节点移动到该通用节点所在的通用节点段的最后;当清空一通用节点的内容后,将该通用节点移动到该通用节点所在的通用节点段的开头;当需要选取通用节点时,从通用节点段的开头选取;After accessing a general node or updating the content of a general node, move the general node to the end of the general node segment where the general node is located; after clearing the content of a general node, move the general node to the location where the general node is located The beginning of the general node segment; when the general node needs to be selected, it is selected from the beginning of the general node segment;

当访问一业务节点或更新一业务节点的内容后,将该业务节点移动到该业务节点所在的业务节点段的最后;当清空一业务节点的内容后,将该业务节点移动到该业务节点所在的业务节点段的开头;当需要选取业务节点时,从业务节点段的开头选取。After accessing a service node or updating the content of a service node, move the service node to the end of the service node segment where the service node is located; after clearing the content of a service node, move the service node to where the service node is located The beginning of the business node segment; when the business node needs to be selected, it is selected from the beginning of the business node segment.

其它实施例中,多个通用节点/业务节点不一定彼此相邻形成节点段,只要记录有每个通用节点/业务节点的地址即可;如果要满足FIFO(First In First Out,先进先出)原则,则可以记录每个通用节点/业务节点的最近一次的使用(包括访问和更新)时间,根据该时间来执行FIFO。In other embodiments, multiple general-purpose nodes/service nodes are not necessarily adjacent to each other to form a node segment, as long as the address of each general-purpose node/service node is recorded; if FIFO (First In First Out, first in first out) is to be satisfied In principle, the latest usage (including access and update) time of each general node/service node can be recorded, and the FIFO is executed according to the time.

本实施例中,所述缓存节点可以形成节点链表;或可以按照其它存储结构组织缓存节点。In this embodiment, the cache nodes may form a node linked list; or the cache nodes may be organized according to other storage structures.

当形成节点链表时,所述头节点包括链表头和业务头节点,所述地址信息为业务头节点的地址;所述链表头用于保存业务头节点的地址;所述节点链表中依次包括链表头、通用节点段、业务头节点及业务节点段。When a node linked list is formed, the head node includes a linked list header and a service head node, and the address information is the address of the service head node; the linked list header is used to store the address of the service head node; the node linked list sequentially includes a linked list Header, general node segment, service header node, and service node segment.

本实施例中,所述选取业务节点可以包括:In this embodiment, the selecting a service node may include:

根据所述头节点中的地址信息,选取位于业务节点段开头的一个或多个业务节点;According to the address information in the head node, select one or more service nodes located at the beginning of the service node segment;

所述选取通用节点包括:The selection of general nodes includes:

根据所述头节点中的地址信息,选取位于通用节点段开头的一个或多个通用节点。According to the address information in the head node, one or more general nodes located at the beginning of the general node segment are selected.

本实施例中,所述将所命中的通用节点中的内容复制到所选取的业务节点中,释放所命中的通用节点可以包括:In this embodiment, copying the content of the hit general node to the selected service node, and releasing the hit general node may include:

使用所命中的通用节点中的内容更新所选取的业务节点,将所选取的业务节点移动到所述业务节点段的最后;Use the content in the hit general node to update the selected service node, and move the selected service node to the end of the service node segment;

清空所命中的通用节点的内容,将所命中的通用节点移动到所述通用节点段的开头。The contents of the hit general node are cleared, and the hit general node is moved to the beginning of the general node segment.

本实施例中,所述将操作针对的数据复制到选取的通用节点中可以包括:In this embodiment, the copying of the data targeted by the operation to the selected general node may include:

使用操作针对的数据更新该通用节点的内容,将该通用节点移动到所述通用节点段的最后;updating the content of the generic node with the data targeted by the operation, moving the generic node to the end of the generic node segment;

所述将该周期性业务需要缓存的数据复制到选取的业务节点中包括:The copying of the data that needs to be cached for the periodic service to the selected service node includes:

使用该周期性业务需要缓存的数据更新该业务节点,将该业务节点移动到所述业务节点段的最后。The service node is updated using the data that the periodic service needs to cache, and the service node is moved to the end of the service node segment.

其中,当更新一个缓存节点(通用节点或业务节点)的内容中,如果该缓存节点空闲(即其中没有内容),则可以直接将相应数据复制到该缓存节点中;如果该缓存节点不空闲,则需要清空该缓存节点的内容后再将相应数据复制到该缓存节点中。Among them, when updating the content of a cache node (general node or service node), if the cache node is idle (that is, there is no content in it), the corresponding data can be directly copied to the cache node; if the cache node is not idle, Then, it is necessary to clear the content of the cache node and then copy the corresponding data to the cache node.

一种示例性实施例中,所述步骤S210还包括:In an exemplary embodiment, the step S210 further includes:

如果是通用业务命中通用节点或业务节点,则判断通用业务的类型,如果是写操作则更新所命中的缓存节点的内容;如果是删除操作则清空所命中的缓存节点的内容;如果是读操作则访问所命中的缓存节点的内容;If the general service hits the general node or service node, then judge the type of the general service, if it is a write operation, update the content of the hit cache node; if it is a delete operation, clear the content of the hit cache node; if it is a read operation Then access the content of the hit cache node;

如果是周期性业务命中业务节点,则访问所命中的缓存节点的内容。If the periodic service hits the service node, the content of the hit cache node is accessed.

本实施例中,如果通用节点和业务节点分别构成通用节点段和业务节点段,则在更新或访问后,可以将所更新或访问的缓存节点移动到相应节点段的最后;清空缓存节点后可以将缓存节点放到相应节点段的开头。In this embodiment, if the general node and the service node respectively constitute the general node segment and the service node segment, after updating or accessing, the updated or accessed cache node can be moved to the end of the corresponding node segment; after clearing the cache node, the Place the cache node at the beginning of the corresponding node segment.

一种示例性实施例中,所述缓存节点按照不同的数据类型划分为多个节点链表;每个节点链表中均包含通用节点和业务节点;In an exemplary embodiment, the cache node is divided into multiple node linked lists according to different data types; each node linked list includes a general node and a service node;

所述当业务对底层的数据进行操作时,判断是否命中缓存节点包括:When the business operates on the underlying data, determining whether to hit the cache node includes:

当业务对底层的数据进行操作时,根据待操作数据的数据类型选择相应的节点链表,遍历所选择的节点链表,判断是否命中缓存节点;When the business operates the underlying data, select the corresponding node list according to the data type of the data to be operated, traverse the selected node list, and determine whether the cache node is hit;

所述选取业务节点包括:在所选择的节点链表中选取业务节点;The selecting a service node includes: selecting a service node in the selected node linked list;

所述选取通用节点包括:在所选择的节点链表中选取通用节点。The selecting a general node includes: selecting a general node from the selected node linked list.

本实施例中,所述数据类型可以但不限于包括:格式、目录、文件;相应地,节点链表可以包括格式节点链表、目录节点链表、文件节点链表。实际应用时,可以根据需求自行设置节点链表的个数。In this embodiment, the data types may include, but are not limited to, formats, directories, and files; correspondingly, the node linked list may include a format node linked list, a directory node linked list, and a file node linked list. In practical applications, you can set the number of node linked lists according to your needs.

本实施例中,每个节点链表中的通用节点和业务节点可以各自构成通用节点段和通用节点段,并各自遵循FIFO原则;当选取缓存节点或移动缓存节点在节点段中的位置时,是在相应节点链表中的相应节点段中进行。比如通用业务要对文件进行写操作,则是在文件节点链表中查找是否命中缓存节点,如果没有命中则是在文件节点链表的通用节点段的开头选取通用节点;如果命中了通用节点,则更新所命中的通用节点后,将所命中的通用节点放到文件节点链表的通用节点段的最后;如果命中了业务节点,则更新所命中的通用节点后,将所命中的通用节点放到文件节点链表的业务节点段的最后。In this embodiment, the general node and the service node in each node linked list can respectively form a general node segment and a general node segment, and each follow the FIFO principle; when selecting the location of the cache node or mobile cache node in the node segment, it is In the corresponding node segment in the corresponding node linked list. For example, if a general business wants to write a file, it is to check whether the cache node is hit in the file node linked list. If there is no hit, the general node is selected at the beginning of the general node segment of the file node linked list; if the general node is hit, it is updated. After the hit common node, put the hit common node at the end of the common node segment of the file node linked list; if the business node is hit, update the hit common node and put the hit common node in the file node The last of the business node segment of the linked list.

本实施例中,缓存节点中还可以包括缓存节点头,用于保存不同数据类型对应的节点链表的地址。In this embodiment, the cache node may further include a cache node header, which is used to store addresses of node linked lists corresponding to different data types.

下面用三个示例说明上述实施例。The above-described embodiments are described below with three examples.

示例一Example 1

本示例给出一种按照数据类型和业务类型对缓存节点进行划分的方案,对缓存节点采用分层+分段的模式进行组织。This example presents a solution for dividing cache nodes according to data types and service types, and organizes cache nodes in a hierarchical + segmented mode.

其中,分层如图2所示,是指按照数据类型将缓存节点划分为多个节点链表,如图2中的文件节点链表和目录节点链表,每个节点链表中有多个缓存节点。缓存节点头中分层存储不同节点链表的头部,当收到业务请求时,根据请求针对的数据类型,到数据类型对应的节点列表中查找缓存节点。Among them, the layering is shown in Figure 2, which means that the cache nodes are divided into multiple node linked lists according to data types, such as the file node linked list and the directory node linked list in Figure 2, and each node linked list has multiple cache nodes. The headers of different node linked lists are stored hierarchically in the cache node header. When a service request is received, according to the data type for which the request is directed, the cache node is searched in the node list corresponding to the data type.

分段是指在每个节点链表中,根据对应的业务类型将缓存节点划分为通用节点段和业务节点段;以一个节点链表中包含3个通用节点,2个业务节点为例,该节点链表如图3所示,首先是链表头head,然后依次为通用节点1、通用节点2、通用节点3、业务头节点、业务节点1、业务节点2和链表尾部。Segmentation means that in each node linked list, the cache nodes are divided into general node segments and service node segments according to the corresponding service type; for example, a node linked list contains 3 general nodes and 2 service nodes, the node linked list As shown in Figure 3, the first is the head of the linked list, followed by the general node 1, the general node 2, the general node 3, the service head node, the service node 1, the service node 2 and the tail of the linked list.

其中,链表头head用于记录业务头节点地址,便于通用节点和业务节点的释放。缓存节点中的不同节点段各自满足FIFO(first in first out)原则,这里的尾不是指整个链表的尾部,而是指节点段的尾部(比如图3中,通用节点段的尾部即业务头节点,业务节点的尾部即链表尾部),通用节点段和业务节点段均遵循此规则,满足软件局部访问原则。Among them, the head of the linked list is used to record the address of the service head node, which is convenient for the release of the general node and the service node. The different node segments in the cache node each satisfy the FIFO (first in first out) principle. The tail here does not refer to the tail of the entire linked list, but to the tail of the node segment (for example, in Figure 3, the tail of the general node segment is the service head node. , the tail of the business node is the tail of the linked list), the general node segment and the business node segment follow this rule, which satisfies the principle of software local access.

FIFO原则的示意图如图4a和图4b所示。图4a是所使用的节点在节点链表中移动的示意图,图4b是移动后该节点链表的示意图。A schematic diagram of the FIFO principle is shown in Figure 4a and Figure 4b. Fig. 4a is a schematic diagram of the used node moving in the node linked list, and Fig. 4b is a schematic diagram of the node linked list after the movement.

对于业务节点,申请一个业务节点时,根据head中记录的业务头节点的地址,去获取业务头节点之后的一个业务节点(比如图4a中的节点5);使用(更新或访问)完成后,需要把业务节点释放到整体链表的尾部,即放到业务节点段的最后,比如按照图4a中的箭头所示,要将节点5移动到业务节点段的尾部,移动之后如图4b所示。For a service node, when applying for a service node, obtain a service node (such as node 5 in Figure 4a) after the service head node according to the address of the service head node recorded in the head; after the use (update or access) is completed, The business node needs to be released to the end of the overall linked list, that is, at the end of the business node segment. For example, as shown by the arrow in Figure 4a, node 5 needs to be moved to the end of the business node segment, as shown in Figure 4b.

对于通用节点,申请一个通用节点时,则是从head后取一个通用节点(比如图4a中的节点1),使用完成后,需要把通用节点释放到业务头节点之前,也就是通用节点段的尾部,比如按照图4a中的箭头所示,要将节点1移动到通用节点段的尾部,移动之后如图4b所示。For a general node, when applying for a general node, a general node (such as node 1 in Figure 4a) is taken from the head. After the use is completed, the general node needs to be released before the service head node, that is, the general node segment. The tail, for example, as shown by the arrow in Figure 4a, needs to move node 1 to the tail of the general node segment, as shown in Figure 4b after the movement.

本示例中,所有涉及到缓存的业务均需要遍历整个链表,以此提高缓存的复用性,同时保障缓存和底层的一致性;当命中缓存节点时,如果是写操作则更新所命中的缓存节点的内容,并将该缓存节点置到相应链表对应节点段的尾部;如果是删除操作,则清空所命中的缓存节点的内容,将缓存节点置到相应链表对应节点段的头部;如果是读操作,则不修改所命中的缓存节点的内容,访问后将缓存节点放到相应链表对应节点段的尾部。In this example, all services involving the cache need to traverse the entire linked list, so as to improve the reusability of the cache and ensure the consistency between the cache and the underlying layer; when a cache node is hit, if it is a write operation, the hit cache is updated The content of the node, and the cache node is placed at the end of the corresponding node segment of the corresponding linked list; if it is a delete operation, the content of the hit cache node is cleared, and the cache node is placed at the head of the corresponding node segment of the corresponding linked list; if it is For read operations, the content of the hit cache node is not modified, and after access, the cache node is placed at the end of the corresponding node segment of the corresponding linked list.

本示例中,针对实际业务需求,层加段怎么设计可由用户指定,比如可通过用户指定的计算方式计算得出,缓存大小的计算方式也可由用户指定算法,一种示例性的计算方式可以为:(容量(字节数)>>40)*1MB。In this example, according to the actual business requirements, how to design the layer and segment can be specified by the user. For example, it can be calculated by the calculation method specified by the user. The calculation method of the cache size can also be calculated by the user specified algorithm. An exemplary calculation method can be : (capacity (bytes)>>40)*1MB.

示例二Example 2

本示例给出不同类型的业务进行数据缓存的处理流程,基于示例一中分层+分段的结构实现。This example presents the processing flow of data caching for different types of services, which is implemented based on the layered + segmented structure in Example 1.

周期性业务进行数据缓存的处理流程如图5所示,包括:The processing flow of data caching for periodic services is shown in Figure 5, including:

501、根据业务涉及的数据类型获取对应的节点链表的head。501. Acquire the head of the corresponding node linked list according to the data type involved in the business.

后续步骤都在该对应的节点链表中进行,所提及的通用节点段和业务节点段均为该节点链表中的节点段。The subsequent steps are all performed in the corresponding node linked list, and the general node segment and the service node segment mentioned are both node segments in the node linked list.

502、判断是否命中缓存节点;如果没有命中,则进行步骤503,如果命中则进行步骤504。502. Determine whether the cache node is hit; if there is no hit, go to step 503, and if it hits, go to step 504.

503、从业务节点段的开头选取一个业务节点,使用周期性业务需要缓存的数据(扫描硬盘得到的数据)更新该业务节点,然后将该业务节点放到业务节点段的最后。503. Select a service node from the beginning of the service node segment, update the service node with data that needs to be cached for the periodic service (data obtained by scanning the hard disk), and then place the service node at the end of the service node segment.

504、判断命中的是否为通用节点;如果是则进行505,不是则进行506。504. Determine whether the hit is a general node; if so, go to 505, and if not, go to 506.

505、从业务节点段的开头选取一个业务节点,使用命中的通用节点中的内容更新所选取的业务节点中,然后将所选中的业务节点放到业务节点段的最后;将所命中的通用节点清空后放到通用节点段的开头。505. Select a business node from the beginning of the business node segment, update the selected business node with the content in the hit general node, and then place the selected business node at the end of the business node segment; put the hit general node After emptying, put it at the beginning of the general node segment.

506、将命中的业务节点放到业务节点段的最后。506. Put the hit service node at the end of the service node segment.

通用业务进行数据缓存的处理流程如图6所示,包括:The processing flow of data caching for general services is shown in Figure 6, including:

601、根据业务涉及的数据类型获取对应的节点链表。601. Acquire a corresponding node linked list according to the data type involved in the service.

后续步骤都在该对应的节点链表中进行,所提及的通用节点段和业务节点段均为该节点链表中的节点段。The subsequent steps are all performed in the corresponding node linked list, and the general node segment and the service node segment mentioned are both node segments in the node linked list.

602、判断是否命中缓存节点;如果没有命中,则进行步骤603,如果命中(无论是通用节点还是业务节点均可)则进行步骤604。602. Determine whether the cache node is hit; if there is no hit, go to step 603, and if it hits (whether it is a general node or a service node), go to step 604.

603、从通用节点段的开头选取一个通用节点,使用通用业务针对的数据(扫描硬盘得到的数据)更新该通用节点,然后将该通用节点放到通用节点段的最后。603. Select a general node from the beginning of the general node segment, update the general node with the data targeted by the general service (data obtained by scanning the hard disk), and then place the general node at the end of the general node segment.

604、判断通用业务的操作类型,如果是写操作则进行605,是删除操作则进行606,如果是读操作则进行607。604. Determine the operation type of the general service, if it is a write operation, go to 605, if it is a delete operation, go to 606, and if it is a read operation, go to 607.

605、根据写操作针对的数据更新所命中的缓存节点,然后将该缓存节点放到相应节点段的最后。605. Update the hit cache node according to the data targeted by the write operation, and then place the cache node at the end of the corresponding node segment.

606、清空所命中的缓存节点的内容,然后将该缓存节点放到相应节点段的开头。606. Clear the content of the hit cache node, and then place the cache node at the beginning of the corresponding node segment.

607、访问所命中的缓存节点后,将该缓存节点放到相应节点段的最后。607. After accessing the hit cache node, place the cache node at the end of the corresponding node segment.

示例三Example three

本示例用一个相机的实际存储过程为例,说明进行数据缓存的过程。This example uses the actual stored procedure of a camera as an example to illustrate the process of data caching.

在云存储系统中,假定某一路相机名称为Tmpipc123,文件存储目录规则为Tmpipc123作为根目录,下面建立以年份为名的第一子目录(比如2020),第一子目录下建立以月份为名的第二子目录(比如10),第二子目录下建立以日为名的第三子目录(比如01、02、……、30),将每天采集的文件按照年月日放入相应目录,取名file X,X为从1开始的序号。比如2020年10月1日所采集的第一个文件为Tmpipc123/2020/10/01/file1,平均每2小时一个文件,每天12个文件。In the cloud storage system, assume that a certain camera name is Tmpipc123, the file storage directory rule is Tmpipc123 as the root directory, and the first subdirectory named after the year (such as 2020) is established below, and the first subdirectory is established under the name of the month In the second subdirectory (such as 10), a third subdirectory named after the day (such as 01, 02, . , named file X, where X is the serial number starting from 1. For example, the first file collected on October 1, 2020 is Tmpipc123/2020/10/01/file1, with an average of one file every 2 hours and 12 files per day.

首先,根据给定的业务类型将云存储系统中所分配的缓存节点进行分层设置,不同的层缓存不同的数据类型的数据;本示例中,该数据类型包括:文件、目录、格式;First, the cache nodes allocated in the cloud storage system are hierarchically set according to a given business type, and different layers cache data of different data types; in this example, the data types include: files, directories, and formats;

在进行分层设置时,将云存储系统中所分配的缓存节点按照不同的数据类型划分为多层节点链表,包括:文件节点链表、目录节点链表和格式节点链表。When performing hierarchical setting, the cache nodes allocated in the cloud storage system are divided into multi-layer node linked lists according to different data types, including: file node linked list, directory node linked list and format node linked list.

在分层时根据不同数据类型所占用的缓存大小设置缓存空间的分配比例;Set the allocation ratio of cache space according to the cache size occupied by different data types during layering;

可以根据需求设置,比如:该相机配置留存期为30天,缓存大小指定为1MB,单个缓存节点为4KB;文件类型的缓存节点访问最多,因此设置文件类型的缓存节点占整体缓存空间比50%,目录类型和格式类型的缓存节点在剩余的缓存空间中按照3:1分配,缓存大小由用户指定计算方式进行计算,本示例中采用的缓存大小计算策略为:It can be set according to requirements, for example: the camera configuration retention period is 30 days, the cache size is specified as 1MB, and a single cache node is 4KB; the cache node of the file type is accessed the most, so the cache node of the file type is set to account for 50% of the overall cache space. , the cache nodes of directory type and format type are allocated 3:1 in the remaining cache space, and the cache size is calculated by the calculation method specified by the user. The cache size calculation strategy adopted in this example is:

(相机容量(字节数)>>40)*1MB。(Camera capacity (bytes)>>40)*1MB.

缓存节点分层后的情况如下:After the cache nodes are layered, the situation is as follows:

格式层:32个节点,用于缓存文件系统索引格式信息;Format layer: 32 nodes for caching file system index format information;

目录层:96个节点,用于缓存目录节点信息;Directory layer: 96 nodes for caching directory node information;

文件层:128个节点,用于缓存文件索引信息;File layer: 128 nodes for caching file index information;

分层后将每层节点进行分段,每个节点链表中的节点段均包括:通用节点段和业务节点段;After layering, each layer of nodes is segmented, and the node segments in each node linked list include: general node segments and business node segments;

在本示例中,通用节点用于缓存通用业务的相关数据;业务节点用于缓存专门服务于特定业务的周期性业务的相关数据;在本示例中,该周期业务指定为满覆盖业务。根据用户的需求可以设置,通用节点段设置为占比75%;业务节点段设置占比25%;即设置为:格式节点链表中业务节点为8个节点,目录节点链表中业务节点为24个节点,文件节点链表中业务节点为32个节点。In this example, the general node is used to cache the relevant data of the general service; the service node is used to cache the relevant data of the periodic service specially serving a specific service; in this example, the periodic service is designated as a full coverage service. It can be set according to the user's needs. The general node segment is set to account for 75%; the business node segment is set to account for 25%; that is, the business nodes in the format node list are 8 nodes, and the directory node list is 24. There are 32 business nodes in the file node linked list.

经过包括以上分层和分段的初始化过程后,缓存节点如图7所示。After the initialization process including the above layering and segmentation, the cache node is shown in Figure 7.

相机开始工作后,存储预置时间段内的数据;After the camera starts to work, the data within the preset time period is stored;

在本示例中,假设从2020/10/1开始工作,在2020/10/30缓存节点已经存储相机一个月的照片,即当前该相机已从2020/10/01存至2020/10/30,共计文件12*30=360个,目录3(根目录、第一子目录、第二子目录各一)+30(30个第三子目录)=33个;In this example, it is assumed that the work starts from 2020/10/1, and the cache node has stored the camera's photos for one month on 2020/10/30, that is, the current camera has been stored from 2020/10/01 to 2020/10/30, A total of 12*30=360 files, directory 3 (one for each of the root directory, the first subdirectory, and the second subdirectory)+30 (30 third subdirectories)=33;

2020/10/30时各层节点链表的存储情况如下(格式数据可用于记录当前相机整体容量,时间等基础信息,可用于业务查询,为了简化说明,后文不展示格式节点链表的情况):On 2020/10/30, the storage of the node list of each layer is as follows (the format data can be used to record the basic information such as the overall capacity and time of the current camera, and can be used for business query. In order to simplify the description, the format node list will not be shown later):

目录节点链表如图8所示,目前业务节点段中没有数据,通用节点段中:使用了33个通用节点,从前到后依次存储的是对应日期1-29的第三子目录、(由于在更新2020/10/30的文件时也访问到,因此和对应日期30的第三子目录都放在通用节点段的末尾)、对应日期30的第三子目录。The list of directory nodes is shown in Figure 8. Currently, there is no data in the business node segment. In the general node segment: 33 general nodes are used. It is also accessed when the file of 2020/10/30 is updated, so the third subdirectory corresponding to date 30 is placed at the end of the general node segment) and the third subdirectory corresponding to date 30.

文件节点链表如图9所示,目前业务节点段中没有数据,通用节点段中:使用了全部的通用节点,保存了2020/10/23-2020/10/30共8天的96个文件。The file node list is shown in Figure 9. Currently, there is no data in the business node segment. In the general node segment, all general nodes are used, and 96 files for 8 days from 2020/10/23-2020/10/30 are saved.

当继续存入一个文件,触发满覆盖业务执行,满覆盖业务删除一个文件后,缓存分布情况变化,目录节点链表变化后的情况如图10所示,对于目录类型的数据来说,由于执行了满覆盖任务,需要扫描最古老的目录放入业务节点,即,需要将Tmpipc123、2020、10、01这四个目录都放入业务节点;扫描会发现这四个目录都在通用节点中,则选取四个业务节点,将通用节点中这四个目录分别复制到四个业务节点中,然后释放原来用于保存这四个目录的四个通用节点。When a file is continued to be stored, the execution of the full coverage service is triggered, and after the full coverage service deletes a file, the cache distribution changes, and the situation after the directory node linked list changes is shown in Figure 10. For the full coverage task, you need to scan the oldest directory and put it into the business node, that is, you need to put the four directories of Tmpipc123, 2020, 10, and 01 into the business node; the scan will find that these four directories are in the general node, then Four business nodes are selected, the four directories in the general node are copied to the four business nodes respectively, and then the four general nodes originally used to save the four directories are released.

文件节点链表变化后的情况如图11所示,对于文件类型的数据来说,由于执行了满覆盖任务,需要扫描最古老的文件(即2020/10/01的12个文件)放入业务节点,由于文件节点链表的缓存节点中没有这些文件,因此可以从底层扫描后放入业务节点。The situation after the file node linked list changes is shown in Figure 11. For file type data, since the full coverage task is performed, the oldest files (ie, 12 files of 2020/10/01) need to be scanned and put into the business node , because these files are not in the cache node of the file node linked list, they can be scanned from the bottom and put into the business node.

在本示例中,仅以满覆盖业务只扫描出一天录像为例,若业务节点空间足够,可设置成一次缓存最老几天的录像供满覆盖使用。In this example, only one day's video is scanned for the full coverage service as an example. If the service node has enough space, it can be set to cache the oldest several days of video at a time for full coverage.

另外,如果是执行满覆盖业务以外的业务时,触发了删除最老的文件和目录的操作,则判断该删除被触发是因为业务要执行写操作还是删除操作,如果判断是执行写操作(比如修改或替换最老文件和目录),并且命中了目录节点链表和文件节点链表中的业务节点,则更新所命中的业务节点的内容后将该业务节点放到业务节点段的最后;如果判断是执行删除操作且命中了目录节点链表和文件节点链表中的业务节点,则清空所命中的业务节点的内容后将该业务节点放到业务节点段的开头。In addition, if the operation of deleting the oldest file and directory is triggered when a service other than the full coverage service is executed, it is determined whether the deletion is triggered because the service needs to perform a write operation or a delete operation, and if it is determined to perform a write operation (such as Modify or replace the oldest file and directory), and hit the business node in the directory node linked list and the file node linked list, then update the content of the hit business node and place the business node at the end of the business node segment; if the judgment is yes When the delete operation is performed and the service node in the directory node list and the file node list is hit, the content of the hit service node is cleared and the service node is placed at the beginning of the service node segment.

本示例中,当执行满覆盖业务后,最老的目录和文件都缓存到了相应节点链表的业务节点中,在图10、11所示的情况下,如果触发检索回放业务,则分不同情况进行处理,具体如下:In this example, after the full coverage service is executed, the oldest directory and file are cached in the service node of the corresponding node list. In the cases shown in Figures 10 and 11, if the retrieval and playback service is triggered, it will be carried out in different situations. processing, as follows:

如果是检索最新的录像则会命中目录节点链表和文件节点链表中的通用节点,直接访问所命中的通用节点即可得到要检索结果,访问后将所命中的通用节点放到通用节点段的最后;If it is to retrieve the latest video, it will hit the general node in the directory node linked list and the file node linked list. You can directly access the hit general node to get the search result. After accessing, put the hit general node at the end of the general node segment. ;

如果是检索最老的录像则会命中目录节点链表和文件节点链表中的业务节点,直接访问所命中的通用节点即可得到要检索结果,访问后将所命中的业务节点放到业务节点段的最后;If it is to retrieve the oldest video, it will hit the business node in the directory node list and file node list, and directly access the hit general node to get the search result. After accessing, the hit business node will be placed in the business node segment at last;

如果检索的录像(包括目录和文件)不在任何缓存节点中,且通用节点已经都被占用,则分别在目录节点链表和文件节点链表的通用节点段中进行通用节点的选取操作,选取距离当前操作时间最远的通用节点(即通用节点段开头的通用节点),将所检索到的数据复制到所选中的通用节点中。If the retrieved video (including directories and files) is not in any cache node, and the common nodes are already occupied, select the common nodes in the common node segments of the directory node linked list and the file node linked list respectively, and select the distance from the current operation. The most distant general node (ie, the general node at the beginning of the general node segment) copies the retrieved data to the selected general node.

可以看出,任何对最老数据的非删除访问都不会造成业务节点中内容的删除,不涉及写操作不会更新业务节点的内容,但访问业务节点会重置该业务节点的位置,会被移动到业务节点段的最后(即最新访问的业务节点置尾持久化)。对于检索和回放业务,如果需要新增缓存节点,则新增的缓存节点是在通用节点段中选择的,不会占用到满覆盖业务所使用的业务节点;这样等到下次满覆盖业务执行时,缓存中仍保存有最老文件和目录,每天结束时等到当天的数据清理完全,重新扫描一次,再继续进行下一次满覆盖业务,业务节点不会受到检索回放等业务的冲击,能够在内存中最持久化保存。It can be seen that any non-deleted access to the oldest data will not cause the content in the business node to be deleted, and the content of the business node will not be updated without involving a write operation, but accessing the business node will reset the location of the business node, which will It is moved to the end of the business node segment (ie, the most recently accessed business node is persisted at the end). For retrieval and playback services, if a new cache node needs to be added, the newly added cache node is selected in the general node segment and will not occupy the service node used by the full coverage service; this will wait until the next time the full coverage service is executed. , the oldest files and directories are still stored in the cache. At the end of each day, wait until the data of the day is completely cleaned up, scan it again, and then continue with the next full coverage service. Most persistent save.

本公开实施例还提供了一种装置,如图12所示,包括存储器1210和处理器1220;应用于对包括通用节点和业务节点的缓存节点进行数据缓存,所述存储器用于保存用于进行数据缓存的程序,所述处理器用于读取执行所述用于数据缓存的程序,执行上述任一实施例所述的进行数据缓存的方法。An embodiment of the present disclosure also provides an apparatus, as shown in FIG. 12 , including a memory 1210 and a processor 1220; it is applied to data caching for a cache node including a general node and a service node, and the memory is used for storing data for performing data caching. A program for data caching, where the processor is configured to read and execute the program for data caching, and execute the data caching method described in any of the foregoing embodiments.

本公开实施例还提供了一种存储介质,所述存储介质中存储有用于基于包括通用节点和业务节点的缓存节点进行数据缓存的程序,所述程序被设置为在运行时执行上述任一实施例所述的进行数据缓存的方法。An embodiment of the present disclosure further provides a storage medium, where a program for data caching based on a cache node including a general node and a service node is stored in the storage medium, and the program is configured to execute any one of the above implementations at runtime The method for data caching described in the example.

本领域普通技术人员可以理解,上文中所公开方法中的全部或某些步骤、系统、装置中的功能模块/单元可以被实施为软件、固件、硬件及其适当的组合。在硬件实施方式中,在以上描述中提及的功能模块/单元之间的划分不一定对应于物理组件的划分;例如,一个物理组件可以具有多个功能,或者一个功能或步骤可以由若干物理组件合作执行。某些组件或所有组件可以被实施为由处理器,如数字信号处理器或微处理器执行的软件,或者被实施为硬件,或者被实施为集成电路,如专用集成电路。这样的软件可以分布在计算机可读介质上,计算机可读介质可以包括计算机存储介质(或非暂时性介质)和通信介质(或暂时性介质)。如本领域普通技术人员公知的,术语计算机存储介质包括在用于存储信息(诸如计算机可读指令、数据结构、程序模块或其他数据)的任何方法或技术中实施的易失性和非易失性、可移除和不可移除介质。计算机存储介质包括但不限于RAM、ROM、EEPROM、闪存或其他存储器技术、CD-ROM、数字多功能盘(DVD)或其他光盘存储、磁盒、磁带、磁盘存储或其他磁存储装置、或者可以用于存储期望的信息并且可以被计算机访问的任何其他的介质。此外,本领域普通技术人员公知的是,通信介质通常包含计算机可读指令、数据结构、程序模块或者诸如载波或其他传输机制之类的调制数据信号中的其他数据,并且可包括任何信息递送介质。Those of ordinary skill in the art can understand that all or some of the steps in the methods disclosed above, functional modules/units in the systems, and devices can be implemented as software, firmware, hardware, and appropriate combinations thereof. In a hardware implementation, the division between functional modules/units mentioned in the above description does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be composed of several physical components Components execute cooperatively. Some or all of the components may be implemented as software executed by a processor, such as a digital signal processor or microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on computer-readable media, which may include computer storage media (or non-transitory media) and communication media (or transitory media). As is known to those of ordinary skill in the art, the term computer storage media includes both volatile and nonvolatile implemented in any method or technology for storage of information such as computer readable instructions, data structures, program modules or other data flexible, removable and non-removable media. Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cartridges, magnetic tape, magnetic disk storage or other magnetic storage devices, or may Any other medium used to store desired information and which can be accessed by a computer. In addition, communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and can include any information delivery media, as is well known to those of ordinary skill in the art .

Claims (10)

1.一种进行数据缓存的方法,其特征在于,应用在包括通用节点和业务节点的缓存节点上,所述方法包括:1. a method for carrying out data cache, is characterized in that, is applied on the cache node comprising general node and service node, and described method comprises: 当业务对底层的数据进行操作时,判断是否命中缓存节点;When the business operates on the underlying data, determine whether the cache node is hit; 当命中缓存节点时,如果是周期性业务命中通用节点,则选取业务节点,将所命中的通用节点中的内容复制到所选取的业务节点中,释放所命中的通用节点;When hitting the cache node, if the periodic service hits the general node, select the business node, copy the content of the hit general node to the selected business node, and release the hit general node; 当未命中缓存节点时,如果所述业务为通用业务,则选取通用节点,将操作针对的数据复制到选取的通用节点中;如果所述业务为周期性业务,则选取业务节点,将该周期性业务需要缓存的数据复制到选取的业务节点中。When the cache node is not hit, if the service is a general service, a general node is selected, and the data targeted by the operation is copied to the selected general node; if the service is a periodic service, a service node is selected, and the periodic service is selected. Sexual business needs to copy the cached data to the selected business node. 2.根据权利要求1所述进行数据缓存的方法,其特征在于:2. the method for carrying out data cache according to claim 1 is characterized in that: 多个通用节点依次相连构成通用节点段,多个业务节点依次相连构成业务节点段;其中,所述通用节点段和业务节点段中的缓存节点分别遵循先进先出原则;A plurality of general nodes are connected in sequence to form a general node segment, and a plurality of service nodes are connected in sequence to form a service node segment; wherein, the general node segment and the cache nodes in the service node segment respectively follow the first-in-first-out principle; 所述缓存节点还包括头节点,用于保存缓存节点的地址信息。The cache node further includes a head node for storing address information of the cache node. 3.根据权利要求2所述的进行数据缓存的方法,其特征在于:3. the method for carrying out data cache according to claim 2, is characterized in that: 所述缓存节点形成节点链表;The cache node forms a node linked list; 所述头节点包括链表头和业务头节点,所述地址信息为业务头节点的地址;所述链表头用于保存业务头节点的地址;所述节点链表中依次包括链表头、通用节点段、业务头节点及业务节点段。The head node includes a linked list header and a service head node, and the address information is the address of the service head node; the linked list header is used to store the address of the service head node; the node linked list sequentially includes a linked list header, a general node segment, Service head node and service node segment. 4.根据权利要求2所述的进行数据缓存的方法,其特征在于,所述选取业务节点包括:4. The method for performing data caching according to claim 2, wherein the selecting a service node comprises: 根据所述头节点中的地址信息,选取位于业务节点段开头的一个或多个业务节点;According to the address information in the head node, select one or more service nodes located at the beginning of the service node segment; 所述选取通用节点包括:The selection of general nodes includes: 根据所述头节点中的地址信息,选取位于通用节点段开头的一个或多个通用节点。According to the address information in the head node, one or more general nodes located at the beginning of the general node segment are selected. 5.根据权利要求2所述的进行数据缓存的方法,其特征在于,所述将所命中的通用节点中的内容复制到所选取的业务节点中,释放所命中的通用节点包括:5. The method for carrying out data caching according to claim 2, wherein the content in the hit general node is copied to the selected service node, and releasing the hit general node comprises: 使用所命中的通用节点中的内容更新所选取的业务节点,将所选取的业务节点移动到所述业务节点段的最后;Use the content in the hit general node to update the selected service node, and move the selected service node to the end of the service node segment; 清空所命中的通用节点的内容,将所命中的通用节点移动到所述通用节点段的开头。The contents of the hit general node are cleared, and the hit general node is moved to the beginning of the general node segment. 6.根据权利要求2所述的进行数据缓存的方法,其特征在于,所述将操作针对的数据复制到选取的通用节点中包括:6. The method for data caching according to claim 2, wherein the copying of the data targeted by the operation to the selected general node comprises: 使用操作针对的数据更新该通用节点的内容,将该通用节点移动到所述通用节点段的最后;updating the content of the generic node with the data targeted by the operation, moving the generic node to the end of the generic node segment; 所述将该周期性业务需要缓存的数据复制到选取的业务节点中包括:The copying of the data that needs to be cached for the periodic service to the selected service node includes: 使用该周期性业务需要缓存的数据更新该业务节点,将该业务节点移动到所述业务节点段的最后。The service node is updated using the data that the periodic service needs to cache, and the service node is moved to the end of the service node segment. 7.根据权利要求1所述的进行数据缓存的方法,其特征在于,当命中缓存节点时,所述方法还包括:7. The method for data caching according to claim 1, wherein when a cache node is hit, the method further comprises: 如果是通用业务命中通用节点或业务节点,则判断通用业务的类型,如果是写操作则更新所命中的缓存节点的内容;如果是删除操作则清空所命中的缓存节点的内容;如果是读操作则访问所命中的缓存节点的内容;If the general service hits the general node or service node, then judge the type of the general service, if it is a write operation, update the content of the hit cache node; if it is a delete operation, clear the content of the hit cache node; if it is a read operation Then access the content of the hit cache node; 如果是周期性业务命中业务节点,则访问所命中的业务节点的内容。If the periodic service hits the service node, the content of the hit service node is accessed. 8.根据权利要求1所述的进行数据缓存的方法,其特征在于:8. the method for carrying out data cache according to claim 1 is characterized in that: 所述缓存节点按照不同的数据类型划分为多个节点链表;每个节点链表中均包含通用节点和业务节点;The cache node is divided into multiple node linked lists according to different data types; each node linked list includes a general node and a service node; 所述当业务对底层的数据进行操作时,判断是否命中缓存节点包括:When the business operates on the underlying data, determining whether to hit the cache node includes: 当业务对底层的数据进行操作时,根据待操作数据的数据类型选择相应的节点链表,遍历所选择的节点链表,判断是否命中缓存节点;When the business operates the underlying data, select the corresponding node list according to the data type of the data to be operated, traverse the selected node list, and determine whether the cache node is hit; 所述选取业务节点包括:在所选择的节点链表中选取业务节点;The selecting a service node includes: selecting a service node in the selected node linked list; 所述选取通用节点包括:在所选择的节点链表中选取通用节点。The selecting a general node includes: selecting a general node in the selected node linked list. 9.一种装置,包括存储器和处理器;其特征在于,应用于对包括通用节点和业务节点的缓存节点进行数据缓存,所述存储器用于保存用于进行数据缓存的程序,所述处理器用于读取执行所述用于进行数据缓存的程序,执行权利要求1-8任一项所述的方法。9. A device comprising a memory and a processor; it is characterized in that, it is applied to cache data for a cache node including a general node and a service node, and the memory is used to save a program for performing data cache, and the processor is used for data caching. The method described in any one of claims 1-8 is executed by reading and executing the program for performing data caching. 10.一种存储介质,其特征在于,所述存储介质中存储有用于基于包括通用节点和业务节点的缓存节点进行数据缓存的程序,所述程序被设置为在运行时执行权利要求1-8任一项所述的方法。10. A storage medium, wherein a program for data caching based on a cache node comprising a general node and a service node is stored in the storage medium, and the program is configured to execute claims 1-8 at runtime The method of any one.
CN202011496893.5A 2020-12-17 2020-12-17 A method, device and storage medium for data caching Pending CN114647625A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011496893.5A CN114647625A (en) 2020-12-17 2020-12-17 A method, device and storage medium for data caching

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011496893.5A CN114647625A (en) 2020-12-17 2020-12-17 A method, device and storage medium for data caching

Publications (1)

Publication Number Publication Date
CN114647625A true CN114647625A (en) 2022-06-21

Family

ID=81991596

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011496893.5A Pending CN114647625A (en) 2020-12-17 2020-12-17 A method, device and storage medium for data caching

Country Status (1)

Country Link
CN (1) CN114647625A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040215883A1 (en) * 2003-08-01 2004-10-28 Oracle International Corporation Partitioned shared cache
CN103514106A (en) * 2012-06-20 2014-01-15 北京神州泰岳软件股份有限公司 Method for caching data
CN108459972A (en) * 2016-12-12 2018-08-28 中国航空工业集团公司西安航空计算技术研究所 A kind of efficient cache management design method of multichannel solid state disk
CN109446225A (en) * 2018-09-26 2019-03-08 平安科技(深圳)有限公司 Data cache method, device, computer equipment and storage medium
CN110674170A (en) * 2019-09-05 2020-01-10 苏州浪潮智能科技有限公司 Data caching method, device, device and medium based on reverse order reading of linked list
CN111190655A (en) * 2019-12-30 2020-05-22 中国银行股份有限公司 Processing method, device, equipment and system for application cache data

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040215883A1 (en) * 2003-08-01 2004-10-28 Oracle International Corporation Partitioned shared cache
CN103514106A (en) * 2012-06-20 2014-01-15 北京神州泰岳软件股份有限公司 Method for caching data
CN108459972A (en) * 2016-12-12 2018-08-28 中国航空工业集团公司西安航空计算技术研究所 A kind of efficient cache management design method of multichannel solid state disk
CN109446225A (en) * 2018-09-26 2019-03-08 平安科技(深圳)有限公司 Data cache method, device, computer equipment and storage medium
CN110674170A (en) * 2019-09-05 2020-01-10 苏州浪潮智能科技有限公司 Data caching method, device, device and medium based on reverse order reading of linked list
CN111190655A (en) * 2019-12-30 2020-05-22 中国银行股份有限公司 Processing method, device, equipment and system for application cache data

Similar Documents

Publication Publication Date Title
CN111309270B (en) A persistent memory key-value storage system
KR101717644B1 (en) Apparatus, system, and method for caching data on a solid-state storage device
US7072916B1 (en) Instant snapshot
KR101137299B1 (en) Hierarchical storage management for a file system providing snapshots
CN110321301B (en) A data processing method and device
US8706679B2 (en) Co-operative locking between multiple independent owners of data space
US7925858B2 (en) Linear space allocation mechanisms in data space
US6934822B2 (en) Organization of multiple snapshot copies in a data storage system
US7984255B2 (en) Optimizing reclamation of data space
US6957362B2 (en) Instantaneous restoration of a production copy from a snapshot copy in a data storage system
CN107180092B (en) File system control method and device and terminal
CN107391774B (en) Garbage Collection Method for Log File System Based on Data Deduplication
US20130031308A1 (en) Device driver for use in a data storage system
US20070106706A1 (en) Unlimited file system snapshots and clones
US7694103B1 (en) Efficient use of memory and accessing of stored records
WO2009033419A1 (en) A data caching processing method, system and data caching device
CN111651127B (en) Monitoring data storage method and device based on shingled magnetic recording disk
CN110945486B (en) Storage fragment management method and terminal
US9307024B2 (en) Efficient storage of small random changes to data on disk
KR101779174B1 (en) Data discard method for journaling filesystem and memory management apparatus thereof
CN110955488A (en) Virtualization method and system for persistent memory
JP2019028954A (en) Storage control apparatus, program, and deduplication method
WO2023116109A1 (en) Request processing method and apparatus, and device and non-volatile readable storage medium
CN114647625A (en) A method, device and storage medium for data caching
CN114442934B (en) Data processing method, device and storage engine

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