Flashback query method, device and storage medium for Neo4j graph database
By dividing Neo4j data files into data blocks and submitting them to the Git library, the problem of waste of Git library storage resources and low utilization caused by Neo4j data flashback query is solved, and efficient flashback query is achieved.
Patent Information
- Application Number
- CN202410872463.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-01
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2044-07-01
AI Technical Summary
The existing Neo4j data flashback query method leads to the waste of available storage resources in the Git library and low storage resource utilization, which cannot be effectively solved by existing technology.
By receiving the data write request from the Neo4j graph database, the data file is divided into several data blocks, the changed data blocks are determined according to the writing position, and the changed data blocks and non-data file type data storage files are submitted to the version library to generate Data version number, perform flashback query to reduce waste of storage resources.
It reduces the waste of storage resources in the Git library, improves the storage resource utilization of the Git library, and realizes efficient flashback query.
Smart Images

Figure CN118394979B
Abstract
Description
Technical Field
[0001] The present application relates to the field of databases, and in particular to a method, device and storage medium for flashback query of a Neo4j graph database. Background Art
[0002] Neo4j graph database is a high-performance graph database that uses graph data structures to store data at the bottom layer, rather than using table data structures like relational databases. Neo4j provides large-scale scalability, can process graphs of billions of nodes / relationships / attributes on a single machine, and can be expanded to run in parallel on multiple machines. Neo4j database files will be persisted to disk storage for long-term persistence, and data files are generally stored in / data / databases / graph.db under the Neo4j directory (v3.0+ version). Unlike traditional relational databases, Neo4j is a schema-free database, and the database only has points, relationships, attributes, and indexes, so Neo4j uses a fixed record length to persist the database, and uses offsets in these files to quickly insert and query data.
[0003] The flashback query of the database returns the data snapshot submitted at that time based on a past moment or system change number (SCN value). It can be used to query the historical version of data and also play a certain role in data recovery. The patent "A method and device for data flashback query and recovery of PostgreSQL database" and the patent "A method and device for data flashback query based on dolt database" respectively propose different methods to implement database flashback query, but they are all applicable to relational databases, not graph databases such as Neo4j.
[0004] In the related art, the method of implementing data flashback query based on Neo4j graph database is often to submit all Neo4j data storage files to the Git library, create versions for the data storage files, and thus implement flashback query of Neo4j graph database. However, each modification of Neo4j (adding records, deleting records, modifying records) will be persisted in the data storage file. Neo4j is based on file storage, and flashback query is implemented by using Git library to create versions for files. However, when creating a version, Git library will completely save the file before and after the modification at the same time. Even if only a small part of the content in a large file is modified, Git library will also completely save the modified file. Due to the repeated saving of unmodified file content, disk space is wasted. At the same time, due to the rapid expansion of Git library, the calculation efficiency of Git command is affected.
[0005] With regard to the problems in the related art of waste of available storage resources of Git library and low utilization rate of storage resources of Git library due to the existing Neo4j data flashback query method, no effective solution has been proposed yet. Summary of the invention
[0006] In this embodiment, a method, device and storage medium for flashback query of a Neo4j graph database are provided to solve the problem in the related art that the available storage resources of the Git library are wasted and the utilization rate of the storage resources of the Git library is low due to the existing Neo4j data flashback query method.
[0007] In a first aspect, a method for flashback query of a Neo4j graph database is provided in this embodiment, including:
[0008] Upon receiving a data version creation request for a Neo4j graph database, obtaining a write request for a data storage file of the Neo4j graph database, wherein the write request includes a file name and an actual write location of the data storage file;
[0009] Determine whether the type of the data storage file of the Neo4j graph database is a data file type, and if so, divide the data storage file of the Neo4j graph database based on a preset size to obtain a plurality of data blocks;
[0010] Determine a changed data block among a plurality of data blocks according to an actual write position;
[0011] Submit the changed data blocks and the data storage files of non-data file type in the Neo4j graph database to the version library to obtain the data version number of the Neo4j graph database;
[0012] Perform a flashback query based on the data version number to obtain the target flashback query result.
[0013] In some of the embodiments, before obtaining a write request for a data storage file, the method further includes:
[0014] Determine whether there is a write request being executed in the current online environment. If not, initiate a pause in the execution of the write request to the online environment and synchronize the data storage file of the Neo4j graph database to the flashback query environment.
[0015] In some of the embodiments, the write request parameters further include a write request operation execution timestamp and a size of an actual configuration page; wherein the size of the plurality of data blocks is an integer multiple of the size of the actual configuration page.
[0016] In some of the embodiments, determining a changed data block among a plurality of data blocks according to an actual write position includes:
[0017] The changed data block is determined according to the actual write position and the size of the data block.
[0018] In some of the embodiments, determining a changed data block among a plurality of data blocks according to an actual write position includes:
[0019] Sort the write requests according to the write request operation execution timestamps to obtain a queue of pending write requests;
[0020] Initialize a storage key-value pair structure, where the key of the storage key-value pair structure is the file name of the data storage file, and the value in the storage key-value pair structure is the actual location set of the changed data block;
[0021] Obtain the current write request in the pending write request queue, where the current write request includes the current write request file name and the actual write position of the current write request;
[0022] Determine the actual position of the changed data block according to the actual write position of the current write request;
[0023] Determine whether the current write request file name exists in the storage key-value pair structure;
[0024] If not, a new position set is created, and the actual position of the changed data block is added to the new position set, so as to obtain a position set including the actual position of the changed data block;
[0025] If so, obtain the position set corresponding to the current write request file name in the storage key-value pair structure, add the actual position of the changed data block to the position set corresponding to the current write request file name, and obtain a position set including the actual position of the changed data block;
[0026] The current write request is removed from the pending write request queue, and the above operation is repeated until all write requests in the pending write request queue are processed to obtain a target storage key-value pair structure, which is the changed data block.
[0027] In some of the embodiments, determining a changed data block among a plurality of data blocks according to an actual write position includes:
[0028] According to the actual position of the changed data block, the file content at the corresponding position in the data storage file is copied to the target storage key-value pair structure to obtain the changed data block.
[0029] In some of the embodiments, performing a flashback query according to the data version number to obtain a target flashback query result includes:
[0030] When a flashback query request is received, all unchanged data blocks and changed data blocks in the version library are retrieved according to the flashback query request;
[0031] According to the file name of the data storage file, the data blocks with the same file name in the retrieved data blocks are combined to obtain a target data file set;
[0032] Store the target data file set in a fixed directory of the flashback query environment;
[0033] Restart the Neo4j service;
[0034] Perform a flashback query in a fixed directory based on the data version number to obtain the target flashback query result.
[0035] In the second aspect, in this embodiment, a flashback query device for a Neo4j graph database is provided, which is applied to a Neo4j graph database and includes: an acquisition module, a judgment module, a positioning module, a version module, and a flashback query module, wherein:
[0036] The acquisition module is used to, upon receiving a request to establish a data version for a Neo4j graph database, acquire a write request for a data storage file of the Neo4j graph database, wherein the write request includes a file name and an actual write location of the data storage file;
[0037] A judgment module is used to judge whether the type of the data storage file of the Neo4j graph database is a data file type. If so, the data storage file of the Neo4j graph database is divided based on a preset size to obtain a plurality of data blocks;
[0038] A positioning module, used for determining a changed data block among a plurality of data blocks according to an actual writing position;
[0039] The version module is used to submit the changed data blocks and the data storage files of non-data file types in the Neo4j graph database to the version library to obtain the data version number of the Neo4j graph database;
[0040] The flashback query module is used to perform a flashback query according to the data version number to obtain a target flashback query result.
[0041] In a third aspect, an electronic device is provided in this embodiment, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the method for flashback query of Neo4j graph database described in the first aspect is implemented.
[0042] In a fourth aspect, a storage medium is provided in this embodiment, on which a computer program is stored, and when the program is executed by a processor, the method for flashback query of Neo4j graph database described in the first aspect is implemented.
[0043] Compared with the related art, the flashback query method for the Neo4j graph database provided in this embodiment obtains a write request for the data storage file of the Neo4j graph database when receiving a request to establish a version of data for the Neo4j graph database, wherein the write request includes the file name and the actual write location of the data storage file; determines whether the type of the data storage file of the Neo4j graph database is a data file type, and if so, divides the data storage file of the Neo4j graph database based on a preset size to obtain a number of data blocks; determines the changed data blocks among the several data blocks according to the actual write location; submits the changed data blocks and the data storage files of non-data file types in the Neo4j graph database to the version library together to obtain the data version number of the Neo4j graph database; performs a flashback query according to the data version number to obtain the target flashback query result, thereby reducing the waste of storage resources of the Git library and improving the storage resource utilization rate of the Git library.
[0044] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0046] Figure 1 This is a hardware structure block diagram of a terminal for the Neo4j graph database flashback query method of this embodiment.
[0047] Figure 2 It is a flowchart of the flashback query method for Neo4j graph database in this embodiment.
[0048] Figure 3 This is a flow chart of a data block positioning method according to a variation of this embodiment.
[0049] Figure 4 This is another flowchart of a flashback query method for a Neo4j graph database according to this embodiment.
[0050] Figure 5 It is a structural block diagram of the flashback query device for Neo4j graph database in this embodiment. DETAILED DESCRIPTION
[0051] In order to more clearly understand the purpose, technical solutions and advantages of the present application, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments.
[0052] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with general skills in the technical field to which this application belongs. The words "one", "a", "the", "these" and the like in this application do not indicate a quantitative limitation, and they may be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there may be three relationships, for example, "A and / or B" may mean: A exists alone, A and B exist at the same time, and B exists alone. Generally, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.
[0053] The method embodiment provided in this embodiment can be executed in a terminal, a computer or a similar computing device. For example, running on a terminal, Figure 1 : is a hardware structure block diagram of a terminal for the Neo4j graph database flashback query method of this embodiment. Figure 1 As shown, the terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 and a memory 104 for storing data, wherein the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA. The above terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.
[0054] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the Neo4j graph database flashback query method in this embodiment. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories can be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0055] The transmission device 106 is used to receive or send data via a network. The above network includes a wireless network provided by a communication provider of the terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (Radio Frequency, referred to as RF) module, which is used to communicate with the Internet wirelessly.
[0056] In this embodiment, a flashback query method for a Neo4j graph database is provided. Figure 2 is a flowchart of the flashback query method for Neo4j graph database in this embodiment, such as Figure 2 As shown, the process includes the following steps:
[0057] Step S201, upon receiving a request to create a data version for a Neo4j graph database, obtain a write request for a data storage file of the Neo4j graph database, wherein the write request includes a file name and an actual write location of the data storage file.
[0058] Specifically, the data of the Neo4j graph database is stored based on files. There are many types of data storage files, such as the file neostore.nodestore.db that stores node information, the file neostore.propertystore.db that stores property information, and the file neostore.relationshipstore.db that stores relationship information. In the flashback query, the Git library is used to establish version numbers for all files of the Neo4j graph database, and the flashback query is implemented by querying the version number. Before implementing the flashback query of the database, the data of the Neo4j graph database must be submitted to the Git library to establish the version number.
[0059] The specific process is as follows: when a request to establish a version of data for the Neo4j graph database is received, a specific write request is first obtained through the log module. The types of write requests include operations such as adding, deleting or modifying data in the Neo4j graph database. Among them, the write request includes write requests for data in all data storage file types as described above, and the write request parameters include the file name and actual write location of the data storage file. The file name can be used to distinguish the file type of the data storage file, and the actual write location can be used to determine the specific location of the write process, thereby modifying the changed data and modifying the data storage file to obtain a new version of the data file. The above-mentioned write requests are all stored in the flashback query environment.
[0060] When the Neo4j service is started, it will initialize the cache of the Neo4j service according to the user configuration and use the cache to complete the record update during the record update process. When appropriate, it will refresh the content in the cache to the data storage file to complete persistence. In the above persistence process, Neo4j uses the implementation class of the PageSwapper interface to refresh the content in the cache to the data storage file. When managing the cache, Neo4j will automatically divide the cache into pages, recorded as Page. Each Page will have a page identifier, recorded as PageID, and the size of a Page is recorded as PageSize. The value of PageSize defaults to 8KB, which can also be specified by system parameters. This is not specifically limited in this embodiment. In addition, when persisting, Neo4j will use the default implementation class SingleFilePageSwapper of the PageSwapper interface to implement it. The SingleFilePageSwapper class implements the write (write()) method of the PageSwapper interface, which is used to write the Page content corresponding to a certain PageID into the data storage file. Neo4j converts the PageID to obtain the actual write position fileOffset of the file, and finally calls the swapOut() method of the SingleFilePageSwapper class to actually write. The parameters received by the swapOut() method include the actual write position fileOffset of the data storage file.
[0061] The log module can record the parameters of the swapOut() method when it is executed, including the actual write position fileOffset of the file, through aspect-oriented programming (AOP interception) or by adding a log method. Combined with the context environment, the log module can also record the file name fileName of the data storage file when the method is executed.
[0062] Step S202, determining whether the type of the data storage file of the Neo4j graph database is a data file type, and if so, dividing the data storage file of the Neo4j graph database based on a preset size to obtain a plurality of data blocks.
[0063] Specifically, due to the different types of data storage files of the Neo4j graph database, the processing methods for the data storage files of the Neo4j graph database are also different. At present, data storage files can be divided into two categories. One category is to store specific record data. This type of file will become larger and larger as the number of records increases. This type of file is called a data file, and this type of data storage file is suitable for segmentation; the other category is to store statistical data (such as the maximum ID value of the record, etc.) or index data, which is a non-data file. The file storing statistical data will change with the number of records, but the file itself is small, and the file will not become larger and larger. Therefore, there is no need to segment the file storing statistical data; the file storing index data is not suitable for segmentation because the storage format is very complex. In this application, it is mainly due to the growth of data file types, which leads to the growth of files submitted to the Git library, occupying a large amount of memory, and the repeated storage of unchanged data leads to a large waste of storage space in the Git library. Therefore, we first determine whether the data storage file type of the Neo4j graph database is a data file type. If it is a data file type, the data storage file of the Neo4j graph database is divided based on the preset size to obtain several data blocks. If it is not a data file type, no division is performed and the original file is directly submitted to the Git library.
[0064] Step S203: determining a changed data block among the plurality of data blocks according to the actual write position.
[0065] Specifically, after the data storage file is divided into a number of data blocks, the actual write position in the write request is converted into an actual position in a specific data block, thereby obtaining a changed data block.
[0066] Step S204, submit the changed data blocks and the data storage files of non-data file types in the Neo4j graph database to the version library to obtain the data version number of the Neo4j graph database.
[0067] Specifically, when Neo4j manages data, it writes all data into data storage files in a fixed directory, submits the changed data blocks and data storage files of non-data file types to the Git repository, and the Git repository returns a hash value, which is used as the data version number of the Neo4j graph database. The version data in the Git repository is stored in the form of divided data blocks.
[0068] Step S205: perform a flashback query according to the data version number to obtain a target flashback query result.
[0069] After receiving the database flashback query request, all data blocks under the version number are queried in the Git library according to the data version number, and the files of all the data blocks obtained by the query are updated to the version to obtain a fixed directory under the flash query environment. Flashback query is performed under the fixed directory to obtain the target flashback query result.
[0070] Through the above steps S201 to S205, when a request for establishing a data version for the Neo4j graph database is received, a write request for the data storage file of the Neo4j graph database is obtained, wherein the write request includes the file name and the actual write location of the data storage file; it is determined whether the type of the data storage file of the Neo4j graph database is a data file type, and if so, the data storage file of the Neo4j graph database is divided based on a preset size to obtain a number of data blocks; the changed data blocks among the several data blocks are determined according to the actual write location; the changed data blocks and the data storage files of non-data file types in the Neo4j graph database are submitted to the version library together to obtain the data version number of the Neo4j graph database; a flashback query is performed according to the data version number to obtain the target flashback query result. Compared with the prior art of directly submitting the entire data storage file to the Git library to establish a version number, the present application divides the data storage file into several data blocks, locates the specific changed data block by writing the actual position, and submits the data storage file of the changed data block and the data storage file of the non-data file type in the Neo4j graph database to the Git library to establish a version number. The unchanged data blocks are no longer submitted to the Git library to establish a version number, which reduces the waste of Git library storage resources due to the repeated establishment of version numbers for unchanged data storage files in the Git library, and improves the utilization rate of Git library storage resources.
[0071] In some of the embodiments, before obtaining a write request for a data storage file, the method further includes:
[0072] Determine whether there is a write request being executed in the current online environment. If not, initiate a pause in the execution of the write request to the online environment and synchronize the data storage file of the Neo4j graph database to the flashback query environment.
[0073] Specifically, in order to avoid the impact of the data flashback query function on the read and write requests of the online environment, a synchronization module is set to synchronize the data storage files of the Neo4j database from the online environment to the flashback query environment.
[0074] When the synchronization module receives a request to establish a data version, it first determines whether there is a write request being executed in the current online environment. If there is a write request being executed, it will randomly wait for a period of time and then check again until there is no write request being executed. If there is no write request being executed, a request is sent to the online environment to suspend the execution of the write request. After the online environment confirms, the synchronization module starts the synchronization work and uses the synchronization tool to synchronize the data storage file of the Neo4j graph database to the flashback query environment. After the synchronization is completed, a request is sent to the online environment to resume the execution of the write request in the online environment, and the timestamp T at this time is recorded.
[0075] In another embodiment, the write request parameters further include a write request operation execution timestamp and a size of an actual configuration page; wherein the sizes of the plurality of data blocks are integer multiples of the size of the actual configuration page.
[0076] Specifically, when obtaining a specific write request through the log module, the obtained write request parameters also include the execution timestamp of the write request operation and the size of the actual configuration page; the write request operations are sorted according to the execution timestamps of each write request operation, and all changed data blocks are located in order according to the sorted write requests. When managing the cache, Neo4j will automatically divide the cache into pages, denoted as Page, i.e., configuration pages. Each Page will have a page identifier, denoted as PageID, and the size of a Page is denoted as PageSize. The value of PageSize defaults to 8KB, which can also be specified by system parameters. This embodiment does not make specific limitations on this. According to actual needs, multiple configuration pages are combined into a data block, and the size of the data block, chunkSize, is an integer multiple of the size of the actual configuration page.
[0077] In some other embodiments, determining a changed data block among a plurality of data blocks according to an actual write position includes: determining the changed data block according to the actual write position and a size of the data block.
[0078] Specifically, the actual write position fileOffset is obtained from the request parameters, and the actual write position fileOffset is converted into the change data block position chunkID. The specific conversion formula is:
[0079] chunkID=fileOffset / chunkSize.
[0080] In this embodiment, a method for locating a data block with a change is also provided. Figure 3 is a flowchart of a data block positioning method according to a variation of this embodiment. Figure 3 As shown, the changed data block among the plurality of data blocks is determined according to the actual write position, including:
[0081] Step S301, sorting the write requests according to the write request operation execution timestamps to obtain a queue S of write requests to be processed.
[0082] Specifically, the log module sorts the write requests according to the order of the execution timestamps of the write request operations to obtain a sorted queue S of write requests to be processed.
[0083] Step S302, initializing a storage key-value pair structure, the key of the storage key-value pair structure is the file name of the data storage file, and the value in the storage key-value pair structure is the actual location set of the changed data block.
[0084] Specifically, a storage key-value pair structure Map is initialized, denoted as PageMap, the key of PageMap is the write request file name fileName, and the value is the actual location set set of the changed data block.
[0085] Step S303, obtaining the current write request in the pending write request queue, the current write request including the current write request file name and the current write request actual write position; determining the actual position of the changed data block according to the current write request actual write position.
[0086] A write request is obtained from the pending request queue S in order as the current write request, and the current write request includes the write request file name and the actual write position of the write request. The actual write position fileOffset of the write request is converted into the actual position chunkID of the changed data block, and the conversion formula is: chunkID=fileOffset / chunkSize; chunkSize is the size of the data block.
[0087] Step S304, determine whether the current write request file name exists in the storage key-value pair structure; determine whether the write request file name fileName1 exists in the PageMap. If not, execute step S305, if yes, execute step S306.
[0088] Step S305, creating a new position set, adding the actual position of the changed data block to the newly created position set, to obtain a position set including the actual position of the changed data block; and executing step S307.
[0089] Specifically, a new position set is created, the actual position of the changed block is added to the new set, and the set is added to the PageMap as a value.
[0090] Step S306, obtain the location set corresponding to the current write request file name in the storage key-value pair structure, add the actual location of the changed data block to the location set corresponding to the current write request file name, and obtain the location set including the actual location of the changed data block. Then execute step S307.
[0091] Specifically, a location set set corresponding to the write request file name is obtained from PageMap, and the actual write location chunkID of the converted data block is added to the corresponding location set set and stored in PageMap.
[0092] Step S307: remove the current write request from the pending write request queue. Remove the current write request from the pending request queue S, and search for the next write request in the pending request queue S.
[0093] Step S308, determining whether there are any pending write requests in the pending request queue S, if so, returning to step S303; otherwise, executing step S309.
[0094] Step S309, outputting the target storage key-value pair structure, where the target storage key-value pair structure is the changed data block.
[0095] In some of the embodiments, determining a changed data block among several data blocks based on an actual write position includes: copying file contents at a corresponding position in a data storage file to a target storage key-value pair structure based on the actual position of the changed data block to obtain the changed data block.
[0096] Specifically, according to the changed data block location chunkID, find the file at the corresponding location in the database storage file synchronized from the online environment to the flashback query environment, copy the file content to the target storage key-value pair structure, and obtain the changed data block. Among them, its file content is determined according to {starting position, ending position}, starting position = chunkID × chunkSize; the ending position is calculated as follows, for example: the size of the data storage file is 99M, chunkSize = 10;
[0097] If (chunkID+1)×chunkSize is greater than the database storage file size, the end position = the database storage file size; if chunkID=9, that is, (9+1)×10=100, which is greater than the data storage file size 99, the end position of the changed data block is located at 99M.
[0098] If (chunkID+1)×chunkSize is less than or equal to the database storage file size, the end position = (chunkID+1)×chunkSize; if chunkID=1, that is, (1+1)×10=20, which is less than the data storage file size 99, the end position of the changed data block is located at 20M;
[0099] The new file is named with "original file name_chunkID" to obtain the changed data block.
[0100] In another embodiment, performing a flashback query according to the data version number to obtain a target flashback query result includes:
[0101] When a flashback query request is received, all unchanged data blocks and changed data blocks in the version library are retrieved according to the flashback query request; data blocks with the same file name in the retrieved data blocks are combined according to the file name of the data storage file to obtain a target data file set; the target data file set is stored in a fixed directory of the flashback query environment; the Neo4j service is restarted; a flashback query is performed in the fixed directory according to the data version number to obtain the target flashback query result.
[0102] Specifically, when a flashback query request is received, a flashback query can be performed according to the data version number, or a flashback query can be performed according to the write request operation execution timestamp. To perform a flashback query according to the data version number, first submit an application to the Git version library. The Git version library integrates the data blocks of the version number in the Git library according to the submitted version number, and combines the files with the same prefix into one file in the order of the chunkID value in the file name from small to large. The combination process can be completed using the cat command in the Linux system to obtain the combined file, and the combined file is named "original file name". The combined file is stored in a fixed directory of the flashback query environment, the data directory of the Neo4j service is designated as the fixed directory of the flashback query environment, and the Neo4j service is restarted. According to the version number to be queried, a flashback query is performed in the updated data directory of the Neo4j service, and the target flashback query result is obtained by querying. According to the write request operation execution timestamp, a flashback query is performed, and the latest data version number within the timestamp range is found. Based on this data version number, an application is submitted to the Git version library for a flashback query to obtain the target flashback query result.
[0103] This embodiment also provides a flashback query method for a Neo4j graph database. Figure 4 is another flowchart of a method for flashback querying a Neo4j graph database according to this embodiment. Figure 4 As shown, the process includes the following steps:
[0104] Step S401: receiving a request to establish a version of data in a Neo4j graph database.
[0105] Step S402, synchronizing data, when no write request is being executed in the current online environment, the data storage file of the Neo4j graph database is synchronized to the flashback query environment through the synchronization module.
[0106] Step S403, record the write request queue, record the write request of the data storage file through the log module, sort the write requests according to the write request operation execution timestamp, and obtain the pending write request queue, wherein the write request parameters include: the file name of the data storage file, the actual write location, the write request operation execution timestamp and the actual configuration page size.
[0107] Step S404, determining whether the type of the data storage file of the Neo4j graph database is a data file type, if so, executing step S405, if not, executing step S409;
[0108] Step S405, dividing the data storage file of the Neo4j graph database based on a preset size to obtain a number of data blocks; wherein the size of the data block is an integer multiple of the size of the actual configuration page.
[0109] Step S406, sequentially acquiring write requests in the write request queue, and determining the changed data block according to the actual write position and the size of the data block in the write request parameters;
[0110] Step S407, initialize a storage key-value pair structure, and store the acquired changed data block in the storage key-value pair structure, wherein the key of the storage key-value pair is the file name of the data storage file, and the value is the actual position of the changed data block.
[0111] Step S408, copying the file content at the corresponding position in the data storage file to the target storage key-value pair structure according to the actual position of the changed data block, to obtain the changed data block;
[0112] Step S409, submitting the changed data blocks and the data storage files of non-data file types to the Git version library, and generating corresponding version numbers;
[0113] Step S410: perform a flashback query according to the version number to obtain a target flashback query result.
[0114] Through the above steps S401 to S410, the data storage file of the data file type is divided into small data blocks, and the actual write position in the write request is used to locate the write position in the data block, so as to locate the changed data block, and the changed data block and the data storage file of the non-data file type are submitted to the Git library together, and the unchanged data block is not submitted to the Git library, and a new version number is generated according to the submitted data file. Compared with the current direct submission of the entire data storage file to the Git library to establish the version number, through this application, the content of the unchanged data block is excluded from repeated backup in the Git library, thereby reducing the waste of available storage resources of the Git library and improving the utilization rate of the storage resources of the Git library.
[0115] In this embodiment, a flashback query device for Neo4j graph database is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and will not be repeated hereafter. The terms "module", "unit", "subunit", etc. used below can be a combination of software and / or hardware that implements the predetermined functions. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0116] Figure 5 is a structural block diagram of a flashback query device for a Neo4j graph database according to this embodiment. Figure 5 As shown, the device 50 includes: an acquisition module 51, a judgment module 52, a positioning module 53, a version module 54 and a flashback query module 55, wherein:
[0117] The acquisition module 51 is used for, upon receiving a request for establishing a data version for a Neo4j graph database, obtaining a write request for a data storage file for the Neo4j graph database, wherein the write request includes a file name and an actual write location of the data storage file;
[0118] A judgment module 52 is used to judge whether the type of the data storage file of the Neo4j graph database is a data file type, and if so, divide the data storage file of the Neo4j graph database based on a preset size to obtain a plurality of data blocks;
[0119] A positioning module 53, used to determine a changed data block among a plurality of data blocks according to an actual write position;
[0120] A version module 54 is used to submit the changed data blocks and the data storage files of non-data file types in the Neo4j graph database to the version library to obtain the data version number of the Neo4j graph database;
[0121] The flashback query module 55 is used to perform a flashback query according to the data version number to obtain a target flashback query result.
[0122] It should be noted that the above modules can be functional modules or program modules, and can be implemented by software or hardware. For modules implemented by hardware, the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.
[0123] In this embodiment, an electronic device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0124] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0125] Optionally, in this embodiment, the processor may be configured to perform the following steps through a computer program:
[0126] S1. Upon receiving a data version creation request for a Neo4j graph database, obtain a write request for a data storage file of the Neo4j graph database, wherein the write request includes a file name and an actual write location of the data storage file.
[0127] S2, determining whether the type of the data storage file of the Neo4j graph database is a data file type, and if so, dividing the data storage file of the Neo4j graph database based on a preset size to obtain a plurality of data blocks.
[0128] S3, determining a changed data block among the plurality of data blocks according to the actual write position.
[0129] S4, submit the changed data blocks and the data storage files of non-data file types in the Neo4j graph database to the version library to obtain the data version number of the Neo4j graph database.
[0130] S5, performing a flashback query according to the data version number to obtain a target flashback query result.
[0131] It should be noted that the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and will not be repeated in this embodiment.
[0132] In addition, in combination with the flashback query method for Neo4j graph database provided in the above embodiment, a storage medium can also be provided in this embodiment to implement. The storage medium stores a computer program; when the computer program is executed by a processor, any one of the flashback query methods for Neo4j graph database in the above embodiment is implemented.
[0133] It should be understood that the specific embodiments described herein are only used to explain the application, rather than to limit it. Based on the embodiments provided in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the protection scope of this application.
[0134] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0135] Obviously, the drawings are only some examples or embodiments of the present application. For ordinary technicians in the field, the present application can also be applied to other similar situations based on these drawings without creative work. In addition, it is understandable that although the work done in this development process may be complicated and lengthy, for ordinary technicians in the field, certain changes in design, manufacturing or production based on the technical content disclosed in this application are only conventional technical means and should not be regarded as insufficient content disclosed in this application.
[0136] The term "embodiment" in this application refers to a specific feature, structure or characteristic described in conjunction with the embodiment that can be included in at least one embodiment of the present application. The appearance of this phrase in various locations in the specification does not necessarily mean the same embodiment, nor does it mean that it is mutually exclusive with other embodiments and is independent or optional. It is clearly or implicitly understood by those of ordinary skill in the art that the embodiments described in this application can be combined with other embodiments without conflict.
[0137] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0138] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of patent protection. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the scope of protection of the present application. Therefore, the scope of protection of the present application shall be subject to the attached claims.
Claims
1. A flashback query method for Neo4j graph database, characterized in that: include: Upon receiving a data version establishment request for the Neo4j graph database, obtaining a write request for a data storage file of the Neo4j graph database, wherein the write request includes a file name and an actual write location of the data storage file; Determine whether the type of the data storage file of the Neo4j graph database is a data file type, and if so, divide the data storage file of the Neo4j graph database based on a preset size to obtain a plurality of data blocks; Determine a changed data block among the plurality of data blocks according to the actual write position; Submit the changed data block and the data storage file of non-data file type in the Neo4j graph database to the version library to obtain the data version number of the Neo4j graph database; Perform a flashback query according to the data version number to obtain a target flashback query result; wherein, The step of determining a data block at a corresponding position among the plurality of data blocks according to the actual write position comprises: The actual write position is converted into an actual position in the plurality of data blocks, and the changed data block is determined according to the actual position.
2. The method for flashback query of Neo4j graph database according to claim 1, characterized in that: Before obtaining the write request for the data storage file, the method further includes: Determine whether a write request is being executed in the current online environment. If not, initiate a pause in the execution of the write request to the online environment, and synchronize the data storage file of the Neo4j graph database to the flashback query environment.
3. The method for flashback query of Neo4j graph database according to claim 1, characterized in that: The write request parameters also include the write request operation execution timestamp and the size of the actual configuration page; wherein, The sizes of the plurality of data blocks are integer multiples of the size of the actual configuration page.
4. The method for flashback query of Neo4j graph database according to claim 1, characterized in that: The step of determining a changed data block among the plurality of data blocks according to the actual write position comprises: The changed data block is determined according to the actual write position and the size of the data block.
5. The method for flashback query of Neo4j graph database according to claim 3, characterized in that: The step of determining a changed data block among the plurality of data blocks according to the actual write position comprises: Sorting the write requests according to the write request operation execution timestamps to obtain a queue of write requests to be processed; Initialize a storage key-value pair structure, the key of the storage key-value pair structure is the file name of the data storage file, and the value in the storage key-value pair structure is the actual position set of the changed data block; Obtaining a current write request in the pending write request queue, wherein the current write request includes a current write request file name and an actual write position of the current write request; Determine the actual position of the changed data block according to the actual write position of the current write request; Determine whether the current write request file name exists in the storage key-value pair structure; If not, a new position set is created, and the actual position of the changed data block is added to the new position set to obtain a position set including the actual position of the changed data block; If so, obtaining a position set corresponding to the current write request file name in the storage key-value pair structure, adding the actual position of the changed data block to the position set corresponding to the current write request file name, and obtaining a position set including the actual position of the changed data block; The current write request is removed from the pending write request list, and the above operation is repeated until all write requests in the pending write request list are processed to obtain a target storage key-value pair structure, which is the changed data block.
6. The method for flashback query of Neo4j graph database according to claim 5, characterized in that: The step of determining a changed data block among the plurality of data blocks according to the actual write position comprises: According to the actual position of the changed data block, the file content at the corresponding position in the data storage file is copied to the target storage key-value pair structure to obtain the changed data block.
7. The method for flashback query of Neo4j graph database according to claim 1, characterized in that: The flashback query is performed according to the data version number to obtain a target flashback query result, including: When a flashback query request is received, all unchanged data blocks and the changed data blocks in the version library are retrieved according to the flashback query request; According to the file name of the data storage file, the data blocks with the same file name in the retrieved data blocks are combined to obtain a target data file set; Storing the target data file set in a fixed directory of the flashback query environment; Restart the Neo4j service; A flashback query is performed in the fixed directory according to the data version number to obtain a target flashback query result.
8. A flashback query device for Neo4j graph database, characterized in that: include: Acquisition module, judgment module, positioning module, version module and flashback query module, among which: The acquisition module is used to, upon receiving a data establishment version request for the Neo4j graph database, acquire a write request for a data storage file of the Neo4j graph database, wherein the write request includes a file name and an actual write location of the data storage file; The judging module is used to judge whether the type of the data storage file of the Neo4j graph database is a data file type, and if so, divide the data storage file of the Neo4j graph database based on a preset size to obtain a plurality of data blocks; The positioning module is used to determine the changed data block in the plurality of data blocks according to the actual write position; wherein, determining the data block at the corresponding position in the plurality of data blocks according to the actual write position comprises: converting the actual write position into the actual position in the plurality of data blocks, and determining the changed data block according to the actual position; The version module is used to submit the changed data block and the data storage file of non-data file type in the Neo4j graph database to the version library to obtain the data version number of the Neo4j graph database; The flashback query module is used to perform a flashback query according to the data version number to obtain a target flashback query result.
9. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the flashback query method for the Neo4j graph database according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for flashback query and recovery of Neo4j graph database described in any one of claims 1 to 7 are implemented.
