A multi-label weak pattern-based graph database metadata management method and system
By constructing active and historical version storage structures, and combining minimum transaction identifiers and logical deletion markers, metadata management of a multi-label weak schema graph database is achieved. This solves the concurrency control problem of metadata management, optimizes storage resources, improves the consistency and visibility of concurrent transactions, and adapts to the business needs of high-concurrency scenarios.
Patent Information
- Application Number
- CN202611403368.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-10
- Publication Date
- 2026-11-27
AI Technical Summary
Existing weak schema graph databases have insufficient concurrency control capabilities in metadata management, which cannot meet the metadata management requirements in large-scale high-concurrency scenarios. In addition, traditional strong schema graph databases have strong rigid constraints on data schemas, serious waste of storage resources, and high operation and maintenance costs.
A graph database metadata management method based on multi-label weak mode is adopted to construct active version storage structure and historical version storage structure to realize multi-version concurrency control of metadata. Version visibility is determined by minimum transaction identifier and logical deletion mark, transaction isolation is combined with snapshot transaction identifier, and automatic cleanup and distributed synchronization mechanism are introduced.
It optimizes metadata storage resources, improves metadata consistency and visibility for concurrent transactions, reduces storage resource fragmentation, adapts to high-concurrency multi-transaction scenarios, supports accurate metadata version traceability and differentiated activation, and meets the auditing needs of high-compliance scenarios such as finance and government.
Smart Images

Figure CN123178697A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of graph database metadata management technology, and in particular relates to a graph database metadata management method and system based on multi-label weak mode. Background Technology
[0002] Graph databases are database systems specifically designed for storing and querying graph-structured data, consisting of vertices and edges to represent relationships between entities. Due to their efficient relational query capabilities, graph databases are widely used in fields such as social networks, recommendation systems, knowledge graphs, and financial risk control.
[0003] Based on the constraint strength of the data pattern, graph databases can be divided into two categories: strong-pattern and weak-pattern. Strong-pattern graph databases require the pre-definition of complete data structures such as vertex types, edge types, and attribute constraints, and data writing must strictly follow the predefined data pattern. Weak-pattern graph databases support dynamic data writing without a predefined data pattern, support multiple labels on a single vertex, and are more suitable for application scenarios with rapid business iteration and dynamic changes in data structure.
[0004] Traditional strong-schema graph databases generally adopt a storage design where "one label corresponds to one vertex table and one relation corresponds to one edge table," which has significant technical drawbacks in large-scale dynamic business scenarios. A rigid data schema imposes strong constraints and has poor business adaptability. A strong schema requires a complete data schema structure to be defined before data is written. When business requirements change, modifying the data schema requires complex data definition language (DDL) operations, which can easily affect online business operations and severely restrict system availability and business iteration efficiency.
[0005] There is a serious waste of storage resources. When the graph contains a large number of labels or relationship types, a large number of independent data tables will be generated. Each table needs to maintain its own storage structure, index information and statistical information, which not only causes fragmentation and redundancy of storage resources, but also significantly increases the complexity of table management of the storage engine.
[0006] Metadata management is difficult and costly. Each data table corresponds to an independent metadata entry, and the synchronization, backup, and recovery of metadata must be handled table by table. In large-scale, multi-label scenarios, maintenance personnel need to manage tens of thousands of metadata entries, which can easily lead to omissions or operational errors. Furthermore, the processing performance will drop sharply in scenarios with multiple concurrent DDL operations.
[0007] To address the lack of flexibility in strongly schema graph databases, weakly schema graph databases are gradually becoming the mainstream development direction in the industry. They support dynamic data writing without predefined data schemas and the ability to freely bind vertices with multiple labels, significantly lowering the barrier to data access. To solve data consistency issues in concurrent scenarios, Multi-Version Concurrency Control (MVCC) technology has been introduced into the graph database field to achieve transactional snapshot isolation of business data.
[0008] Chinese patent application CN112214649A discloses a distributed transaction resolution system for temporal graph databases. This solution addresses the characteristics of temporal graph data, such as infrequent changes in graph structure and frequent writing of temporal attributes. It updates the versions of static structures like nodes and edges on an object-by-object basis and employs single-value granular version control for temporal attributes. It resolves read-write concurrency conflicts through a memory-based MVCC mechanism, with transactions acquiring version numbers in two phases. Write operations determine whether to execute an update based on the version number, thereby improving the transaction processing performance and concurrency capabilities of temporal graph data.
[0009] However, the above solutions and existing mainstream weak-mode graph database technologies all focus MVCC capabilities on the business data level, only implementing multi-version snapshot isolation for business data such as vertices, edges, and attributes. They have not been pushed down to the core metadata management system of the graph database. There are still many unresolved technical shortcomings at the metadata management level, which cannot meet the metadata management needs in large-scale high-concurrency scenarios. Summary of the Invention
[0010] The purpose of this invention is to provide a graph database metadata management method and system based on multi-label weak mode, which partially solves or alleviates the above-mentioned shortcomings in the prior art and can meet the metadata management needs in large-scale high-concurrency scenarios.
[0011] To solve the aforementioned technical problems, the present invention specifically adopts the following technical solution: A first aspect of the present invention is to provide a graph database metadata management method based on multi-tag weak mode, comprising the following steps: A metadata storage structure is constructed, which includes an active version storage structure and a historical version storage structure. The active version storage structure uses the unique identifier of the metadata as the retrieval primary key and stores the version number, minimum transaction identifier, logical deletion mark, and metadata storage pointer of the current active version of the corresponding metadata. The historical version storage structure is grouped according to the unique identifier of the metadata and stores its historical versions in the version generation time sequence under the same metadata. Configure a minimum transaction identifier and a logical deletion flag for each metadata version. The minimum transaction identifier is the transaction commit number corresponding to the generation of the version, and the logical deletion flag is used to identify whether the version is in a logical deletion state. A snapshot transaction identifier is generated when a transaction starts and is bound to that transaction. The snapshot transaction identifier remains unchanged throughout the entire lifecycle of the transaction. Based on the snapshot transaction identifier, and combined with the minimum transaction identifier and the logical deletion flag, a metadata version visibility determination is performed to determine the metadata version accessible to the current transaction.
[0012] Furthermore, for structure class metadata, version changes are only visible to new transactions started after the change is committed. The structure class metadata includes the names and definition structures of graphs, labels, and relationships. For configuration-type metadata, version changes take effect globally after commit, and are accessible to all active transactions. The configuration-type metadata includes indexing rules, time-to-live configurations, data constraints, and auto-incrementing sequences.
[0013] Furthermore, methods for determining metadata version visibility include: Retrieve the active version storage structure to obtain the minimum transaction identifier and logical deletion marker of the current active version; If the snapshot transaction identifier of the current transaction is greater than or equal to the minimum transaction identifier, and the logical deletion flag is in an undeleted state, then return the metadata of the current active version; If the snapshot transaction identifier of the current transaction is less than the minimum transaction identifier, then a valid historical version with the corresponding time sequence is matched in the historical version storage structure and returned; If the logical deletion mark of the current active version is deleted, and the snapshot transaction identifier of the current transaction is greater than or equal to the minimum transaction identifier, then the metadata is determined to be invisible.
[0014] Furthermore, when metadata is modified or deleted, a version update process is executed, including: Retrieve the current active version from the active version storage structure based on the unique identifier in the metadata; Generate a new version number and write the complete metadata and corresponding parameters of the current active version into the historical version storage structure; Create new version metadata information. If it is a modification operation, set the logical deletion flag to not deleted and the minimum transaction identifier to the current modification transaction number; if it is a deletion operation, set the logical deletion flag to deleted and the minimum transaction identifier to the current deletion transaction number. Update the version number, minimum transaction identifier, logical deletion flag, and metadata storage pointer of the corresponding metadata in the active version storage structure, and point the metadata storage pointer to the new version; Broadcast metadata change notifications to all nodes in the distributed cluster.
[0015] Furthermore, each metadata corresponds to a version chain, and each metadata version records the previous version number, which is used to link all iterations of the metadata throughout its entire lifecycle.
[0016] Furthermore, it also includes an automatic label creation step that is triggered when vertices are created, including: Query metadata based on graph identifier and label name to determine if the label already exists; If the tag does not exist, a unique tag identifier is requested from the global configuration manager, the tag metadata structure is initialized, the minimum transaction identifier and logical deletion flag of the initial version are configured, the tag metadata is persisted and stored, and the tag creation event is broadcast to all nodes; If the label already exists, the existing label identifier will be used directly.
[0017] Furthermore, it also includes an automatic relationship creation step that is triggered when an edge is created, including: Query metadata based on graph identifier and relation name to determine if the relation already exists; If the relationship does not exist, a unique relationship identifier is requested from the global configuration manager, the relationship metadata structure is initialized, the minimum transaction identifier and logical deletion flag of the initial version are configured, the relationship metadata is persisted and stored, and the relationship creation event is broadcast to all nodes; If the relation already exists, use the existing relation identifier directly.
[0018] Furthermore, it also includes automatic cleanup steps for tags and relationships, including: Traverse all graphs in the system and perform cleanup condition checks on all labels and relationships under each graph one by one; For labels, the validation conditions include zero vertex count under the label, no index configuration under the label, no lifetime configuration under the label, and no data constraints under the label. For relations, the validation conditions include zero edge count, no index configuration, no time-to-live configuration, and no data constraints. Only when all validation conditions are met will the corresponding tag or relationship be added to the cleanup list, the cleanup operation be performed in batches, a new version of metadata with logical deletion markers be generated, the active version storage structure be updated, and the deletion event be broadcast.
[0019] Furthermore, it also includes historical garbage collection steps, including: Obtain the smallest snapshot transaction identifier of all active read transactions in the system, and use it as the global baseline snapshot identifier; Traverse all historical version entries in the historical version storage structure and filter out historical versions whose minimum transaction identifier is less than the global baseline snapshot identifier and which are not the current active latest version as recyclable versions; Perform bulk physical deletion on recyclable versions.
[0020] Furthermore, the triggering conditions for garbage collection in historical versions include any of the following: The time interval since the last garbage collection exceeds a preset threshold; The total number of historical versions in the historical version storage structure exceeds a preset threshold. The storage space occupied by the historical version storage structure exceeds the preset capacity threshold.
[0021] Furthermore, it also includes a distributed metadata synchronization step: Metadata changes are recorded uniformly by the global configuration manager; Generate incremental synchronization data packets and synchronize them to all nodes in the cluster; After receiving the incremental synchronization data packet, each node updates its local active version storage structure, historical version storage structure, and metadata cache, and completes the version chain of the corresponding metadata.
[0022] Furthermore, when a new node joins the cluster or when data inconsistencies occur between nodes, a full synchronization is performed, synchronizing the metadata storage structure and all historical version data to the target node.
[0023] This invention also provides a graph database metadata management system based on multi-tag weak mode, comprising: A metadata storage component is used to construct a metadata storage structure, which includes an active version storage structure and a historical version storage structure. The active version storage structure uses the unique identifier of the metadata as the retrieval primary key and stores the version number, minimum transaction identifier, logical deletion flag, and metadata storage pointer of the current active version of the corresponding metadata. The historical version storage structure is grouped by the unique identifier of the metadata and stores its historical versions in the version generation sequence under the same metadata. The version management component is used to configure a minimum transaction identifier and a logical deletion flag for each metadata version. The minimum transaction identifier is the transaction commit number corresponding to the generation of the version, and the logical deletion flag is used to identify whether the version is in a logical deletion state. A snapshot transaction identifier is generated when a transaction starts and is bound to that transaction. The snapshot transaction identifier remains unchanged throughout the entire lifecycle of the transaction. Based on the snapshot transaction identifier, and combined with the minimum transaction identifier and the logical deletion flag, a metadata version visibility determination is performed to determine the metadata version accessible to the current transaction. An automatic cleanup management component is used to periodically perform multi-condition cleanup checks on tags and relationships, and to perform batch metadata cleanup operations that meet the conditions. The garbage collection management component is used to filter expired historical versions based on the global minimum active snapshot transaction identifier and perform garbage collection on historical versions. A distributed synchronization management component used to synchronize metadata changes to all nodes in the cluster.
[0024] Beneficial effects:
[0025] (1) Storage resource optimization.
[0026] This invention breaks away from the traditional strong-mode design of "one label, one table; one relationship, one table," and instead maintains only one default vertex table and one default edge table for each graph. This reduces the number of tables in the system, lowers the table management overhead of the storage engine and reduces resource fragmentation issues. The unified metadata storage also facilitates global resource optimization and management.
[0027] (2) Metadata MVCC transaction-level isolation.
[0028] Unlike traditional weak-mode databases that only support MVCC for business data and have a single global version for metadata, this invention is the first to implement multi-version concurrency control at the full-category metadata level in GDMBase, extending MVCC capabilities to all metadata dimensions, including graphs, tags, relationships, indexes, and TTL. By strongly binding the transaction snapshot number to the metadata version min_xid, it achieves transactional repeatable read isolation for structured metadata, resolving the industry pain point of chaotic metadata views in concurrent transactions. Taking graph name deletion as an example, early-starting long transactions can stably retain the old graph metadata view at the time of startup, unaffected by subsequent graph deletions, tag renaming, or other operations. All read and write operations within the transaction are completed based on a unified snapshot, ensuring a completely consistent view and preventing operation failures due to subsequent metadata deletions. Subsequent new transactions can only perceive the latest metadata version, accurately achieving time-series isolation and filling the technical gap of weak-mode graph databases lacking transactional isolation for metadata.
[0029] (3) Differentiated metadata activation mechanism.
[0030] To address the shortcomings of traditional weak-mode databases where metadata is uniformly applied globally and cannot adapt to differentiated business needs, this invention adopts a binary control strategy. For graph-related structural metadata, a transaction snapshot isolation and version visibility mechanism is used to ensure consistency across concurrent transactions. For system configuration metadata such as indexes, TTL, and constraints, a read-committed, globally effective mechanism is used to ensure that system control rules are implemented in real time. This mechanism is unique to GDMBase (a graph database) and resolves the long-standing industry contradiction that "metadata transaction isolation leads to configuration lag, while immediate configuration effectiveness violates transaction isolation," thus adapting to complex business scenarios involving high concurrency and multiple concurrent read / write operations.
[0031] (4) Metadata version traceability capability.
[0032] Unlike traditional databases that only record general metadata operation logs and cannot trace individual objects, this invention constructs an independent and dedicated version chain for each graph, tag, and relation metadata object. By linking the entire lifecycle of iterative versions through a leading version number, it achieves precise traceability and targeted rollback at the unit data object level. It can accurately match the metadata snapshot version corresponding to any transaction, clearly identifying the transaction, time, and content of each metadata modification. This meets the auditing and fault recovery needs of highly compliant scenarios such as finance and government, and solves the core problems of inconsistent metadata versions and the inability to bind transactions and versions in traditional weak-mode databases. Attached Figure Description
[0033] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. In all the drawings, similar elements or parts are generally identified by similar reference numerals. The elements or parts in the drawings are not necessarily drawn to scale. Obviously, the drawings described below are some embodiments of the present invention, and those skilled in the art can obtain other drawings based on these drawings without any creative effort.
[0034] Figure 1 This is a structural schematic diagram of Embodiment 1 of the present invention; Figure 2 This is a flowchart of Embodiment 2 of the present invention. Detailed Implementation
[0035] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are within the scope of protection of the present invention.
[0036] In this document, suffixes such as "module," "part," or "unit" used to denote elements are used only for the purpose of illustrative purposes and have no specific meaning in themselves. Therefore, "module," "part," or "unit" may be used interchangeably.
[0037] In this document, the terms "upper," "lower," "inner," "outer," "front," "rear," "one end," and "the other end," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the present invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the present invention. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0038] In this document, unless otherwise explicitly specified and limited, the terms "installed," "equipped with," "connected," etc., should be interpreted broadly. For example, "connection" can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection, a direct connection, or an indirect connection through an intermediate medium; it can be a connection within two components. Those skilled in the art can understand the specific meaning of the above terms in this invention based on the specific circumstances.
[0039] In this document, "and / or" includes any and all combinations of one or more of the listed related items.
[0040] In this article, "multiple" means two or more, that is, it includes two, three, four, five, etc.
[0041] Example 1:
[0042] 1. System overall architecture.
[0043] like Figure 1 As shown, the graph database metadata management system based on multi-tag weak mode described in this embodiment adopts a layered architecture design, including an application layer, a metadata management layer, a storage layer, and a distributed coordination layer from top to bottom. This embodiment is implemented based on the GDMBase graph database architecture, natively supports multi-tag weak mode data writing, and realizes multi-version concurrent control and full lifecycle automated management of metadata for all categories.
[0044] 1.1 Application Layer.
[0045] The application layer provides upper-layer business functions such as graph querying, graph analysis, graph management, and metadata management. It receives user business requests and metadata operation requests, interacts with the metadata management layer through a unified metadata access interface, obtains metadata information of graphs, tags, and relationships, and returns processing results. The application layer supports mainstream graph query languages such as Gremlin and Cypher, and also provides native metadata management APIs, supporting operations such as tag / relationship creation, deletion, querying, and version rollback.
[0046] 1.2 Metadata Management Layer.
[0047] The metadata management layer includes a dictionary management module, which is responsible for the unified management and control of metadata. This dictionary management module comprises five sub-components: a metadata storage component, a version management component, an automatic cleanup management component, a garbage collection management component, and a distributed synchronization management component.
[0048] The metadata storage component is used to build and maintain a two-tier metadata storage structure, providing persistent storage and read / write interfaces for metadata, and managing the storage mapping relationship between active and historical versions.
[0049] Version management components are used for version control of metadata, transaction snapshot management, visibility determination, differential effect control and version traceability, to achieve MVCC transaction isolation of metadata across all categories.
[0050] The automatic cleanup management component is used for the automatic creation and triggering of tags and relationships, the detection of cleanup conditions, and the batch cleanup execution, realizing the automated operation and maintenance of metadata throughout its entire lifecycle.
[0051] The garbage collection management component is responsible for managing the garbage collection strategy of historical versions, detecting trigger conditions, and cleaning up expired versions to prevent historical versions from growing indefinitely and occupying storage resources.
[0052] The distributed synchronization management component is responsible for broadcasting and synchronizing metadata changes, managing node status, and maintaining the metadata view of the distributed cluster. Figure 1 To the point of being responsive.
[0053] 1.3 Storage layer.
[0054] The storage layer includes the system table module and the RocksDB storage engine, providing persistent storage capabilities for metadata.
[0055] The system table module is responsible for the structured persistence of metadata, storing core data such as tag metadata, relationship metadata, graph metadata, and version metadata.
[0056] The RocksDB storage engine is implemented based on an LSM (Log Structure Merge Tree) structure, natively supporting multi-version concurrency control. It achieves version time-series management through user-defined transaction identifiers, providing underlying storage support for a two-tier metadata storage structure. In this embodiment, the core mapping relationships of the active version storage structure are cached in memory to improve query performance, while complete data is persisted to RocksDB. The historical version storage structure is fully persisted to RocksDB and organized according to preset grouping and sorting rules.
[0057] 1.4 Distributed Coordination Layer.
[0058] The distributed coordination layer includes a global configuration manager and a broadcast service, providing global coordination capabilities for the entire cluster.
[0059] The global configuration manager is responsible for the unified management of global metadata, the allocation of globally unique identifiers, and the atomicity guarantee of version commits. It is the central node for distributed metadata changes. In this embodiment, the global configuration manager uses the Raft protocol to achieve leader election and state consistency, ensuring the uniqueness of global identifier allocation and the atomicity of metadata changes.
[0060] The broadcast service is responsible for the reliable delivery of metadata change notifications, supporting both incremental and full synchronization modes to ensure that the metadata of all nodes in the cluster is viewed correctly. Figure 1 To.
[0061] 2. Data Structures.
[0062] The metadata version information structure includes: An object identifier uniquely identifies a piece of metadata; Version number, representing the iteration version number of the metadata object, is used to build an independent version chain; min_xid is the transaction commit number generated in the current version, which is the minimum effective transaction identifier for this version. del_flag, a version deletion status flag, is used to distinguish logically deleted versions from valid versions; Finally, modify the transaction identifier to record the transaction that last modified this metadata version, which is used for MVCC version isolation and transaction snapshot matching; Creation time: Records the creation time of this version; Activity status: Indicates whether this version is currently active. The previous version number points to the previous version of the metadata object and is used to form an independent version chain.
[0063] The tag metadata structure contains the following fields: The graph identifier indicates the graph to which the label belongs; A tag identifier, which uniquely identifies a tag; Tag name, the text name of the tag; Creation time, the creation time of the tag; Finally, modify the transaction identifier, and finally modify the transaction with the label. Extended information includes an index list, a time-to-live configuration list, and a constraint list; Statistical information, including the number of vertices, records the total number of vertices that use this tag.
[0064] The relational metadata structure contains the following fields: The graph identifier indicates the graph to which the relation belongs; A relation identifier uniquely identifies a relation. The relation name, the text name of the relation; Creation time, the time the relationship was created; Finally, modify the transaction identifier, and finally modify the transaction related to the relationship. Extended information includes an index list, a time-to-live configuration list, and a constraint list; Statistical information, including the number of edges, records the total number of edges that use this relation.
[0065] The aforementioned data structure employs a compact binary serialization format, effectively reducing metadata storage overhead while ensuring serialization and deserialization performance. The two-tier storage architecture uses a lightweight mapped storage mode: the active version stores only pointers and core parameters, resulting in compact memory usage and cache friendliness; historical versions are stored in ordered groups, avoiding memory fragmentation and pointer overhead associated with linked list structures, thus achieving higher storage efficiency.
[0066] 3. Two-tier metadata storage structure.
[0067] This embodiment adopts a two-layer separate storage architecture of active version storage structure and historical version storage structure to achieve a balance between fast access to the current version and orderly tracing of historical versions.
[0068] 3.1 Active version storage structure.
[0069] The active version storage structure stores information and data pointers for the current active latest version of all metadata, providing millisecond-level fast access capabilities. The active version storage structure uses the unique identifier of the metadata as the primary key for retrieval and stores the version number of the current active version of the corresponding metadata, the minimum transaction identifier (min_xid), the logical deletion flag (del_flag), and the metadata storage pointer.
[0070] In this embodiment, the active version storage structure adopts a key-value mapping pattern, including: Retrieve the primary key, a unique identifier for metadata (metadata object ID).
[0071] The mapped value contains four fields: the version number of the current latest version, the minimum transaction identifier, the logical deletion flag, and the metadata storage pointer.
[0072] The metadata storage pointer points to the physical address of the complete metadata of this version in persistent storage, and the complete metadata content can be read directly through the pointer.
[0073] During business operations, the vast majority of metadata queries can be performed directly through the active version mapping table in memory to complete parameter verification and data location without accessing the disk, which greatly improves query performance.
[0074] 3.2 Historical version storage structure.
[0075] The historical version storage structure is used to store all historical iterations of all metadata, supporting historical query, time travel, version rollback and fault tracing functions.
[0076] In this embodiment, the historical version storage structure adopts a two-layer ordered mapping design.
[0077] The outer mapping is grouped by the unique identifier of the metadata, and all historical versions of the same graph, the same label, and the same relation object are aggregated and stored. The key is the object ID and the value is the set of all historical versions of that object.
[0078] The inner mapping is for all historical versions of the same object, arranged in ascending order by version number or smallest transaction identifier, forming an ordered version list that supports binary search to quickly locate the target time-series version.
[0079] The historical version storage structure is fully persisted to the RocksDB storage engine, and the ordered key-value feature of RocksDB is used to achieve ordered storage in the inner layer; historical versions of the same object are stored continuously, reducing random disk I / O and improving retrieval performance.
[0080] Example 2:
[0081] like Figure 2 As shown, this embodiment provides a graph database metadata management method based on multi-tag weak mode, which realizes MVCC transaction isolation, differentiated effect and version traceability of metadata of all categories.
[0082] S1 constructs a metadata storage structure, which includes an active version storage structure and a historical version storage structure. The active version storage structure uses the unique identifier of the metadata as the primary key for retrieval and stores the version number, minimum transaction identifier, logical deletion marker, and metadata storage pointer of the current active version of the corresponding metadata. The historical version storage structure is grouped according to the unique identifier of the metadata and stores its historical versions in the version generation sequence under the same metadata.
[0083] This step forms the storage foundation of the entire multi-version metadata management system, providing underlying storage support for subsequent MVCC transaction isolation, version visibility determination, single-object version tracing, and historical version garbage collection. In this embodiment, the metadata storage structure includes an active version storage structure and a historical version storage structure.
[0084] The active version storage structure carries the system's regular metadata query requests, with the goal of achieving millisecond-level current version location and visibility determination.
[0085] The retrieval primary key uses the unique identifier (object_id) of the metadata object. This primary key is a globally assigned 64-bit unsigned integer. Each graph, label, and relation metadata object corresponds to a globally unique object_id. Different types of metadata (graph, label, relation) are segmented in the ID encoding space to avoid ID conflicts between different types of metadata. This primary key allows direct location of the current active version of the corresponding metadata object without the need for traversal searching.
[0086] The active version storage structure does not store the complete entity of metadata, but only the management parameters and data pointer of the current active version, totaling 4 fields.
[0087] The version number (version_id) is the iteration number of the currently active latest version, which monotonically increases from 0 and is used for comparing the order of versions and locating the version chain.
[0088] The minimum transaction identifier (min_xid) is the transaction commit number corresponding to the current active version when it was generated, which means that "this version is visible to all transactions with a transaction identifier greater than or equal to this value".
[0089] Logical deletion flag (del_flag): A boolean flag, true indicates that the current active version is in a logical deletion state, and false indicates that it is in a normal valid state; this flag is used to implement logical deletion of metadata, rather than direct physical deletion, to ensure that long transactions earlier than the deletion operation can still access the old version.
[0090] Metadata storage pointer (data_ptr): Points to the physical address of the complete metadata entity in persistent storage (such as key offset or memory block address in RocksDB). This pointer allows direct reading of complete metadata content (such as tag names, index configurations, TTL rules, vertex statistics, etc.) without storing the full variable-length data in the active layer.
[0091] The historical version storage structure is used to completely retain all iterations of each metadata object throughout its entire lifecycle, supporting historical version queries, time travel queries, version tracing, fault rollback and compliance auditing, while ensuring the retrieval efficiency of historical versions.
[0092] It adopts a two-layer ordered mapping design with the outer layer grouped by object and the inner layer sorted by time sequence, which is different from the traditional global unordered metadata log storage mode.
[0093] The outer grouping is based on the unique identifier (object_id) of the metadata object, and all historical versions of the same metadata object are aggregated and stored. When querying the historical version of a specific object, the group of that object can be located directly, without having to traverse all historical versions globally, greatly narrowing the search scope.
[0094] The inner sorting is performed on all historical versions under the same metadata object, arranged in ascending order of version generation time (by version number or smallest transaction identifier). The core value of ordered storage is that it supports binary search to locate the target version.
[0095] Each historical version entry stores complete version control information and a complete metadata entity.
[0096] The version control information includes version number, minimum transaction identifier, logical deletion marker, previous version number, creation time, and last modified transaction identifier, which are linked together by the previous version number to form an independent version chain.
[0097] A complete metadata entity includes the complete metadata content of the corresponding version, such as all fields of tag metadata and all fields of relationship metadata, ensuring that historical versions can be completely restored.
[0098] The construction of the storage structure also includes three initialization operations.
[0099] Initialize the globally unique identifier allocator and use a pre-allocation batch mechanism to assign a globally unique object_id to the graph, label, and relation metadata objects created subsequently, ensuring no ID conflicts in a distributed environment.
[0100] Load the persistent metadata data from the disk, rebuild the active version hash mapping in memory, and synchronously verify the integrity of the historical version storage and the continuity of the version chain.
[0101] Initialize system configuration parameters, including active version cache size, automatic cleanup detection cycle, garbage collection trigger threshold, etc., to complete the startup configuration of the storage system.
[0102] S2 configures a minimum transaction identifier and a logical deletion flag for each metadata version. The minimum transaction identifier is the transaction commit number corresponding to the generation of the version, and the logical deletion flag is used to identify whether the version is in a logical deletion state.
[0103] The minimum transaction identifier min_xid is the global transaction commit sequence number corresponding to the generation and formal commit of the metadata version. It is a globally monotonically increasing 64-bit unsigned integer, uniformly assigned by the global transaction manager to ensure global uniqueness and strictly increasing timing.
[0104] This parameter represents the minimum transaction boundary that this version can be effective externally. All transactions with a snapshot transaction identifier greater than or equal to this value at startup have basic access to this version; transactions with a snapshot transaction identifier less than this value are unaware of the existence of this version.
[0105] The value of `min_xid` is tied to the commit transaction of the version. In the initial creation scenario, when the metadata object is created for the first time and an initial version is generated, `min_xid` is set to the commit number of the transaction that performed the creation operation. This means that from the commit of that transaction, the new metadata is visible to subsequent new transactions. In the modification and update scenario, when metadata attributes are modified and a new version is generated, `min_xid` is set to the commit number of the transaction that performed the modification operation. This means that from the commit of that transaction, the modified metadata is visible to subsequent new transactions. In the deletion operation scenario, when metadata is deleted and a marked version is generated, `min_xid` is set to the commit number of the transaction that performed the deletion operation. This means that from the commit of that transaction, the deletion status of the metadata is visible to subsequent new transactions.
[0106] As a core parameter for MVCC visibility determination, `min_xid` defines the time boundary of version effectiveness, achieving snapshot isolation—ensuring that "old transactions cannot see new changes, and new transactions cannot see old views"—and guaranteeing the repeatable read level of transactions. Since transaction commit numbers are naturally monotonically increasing, `min_xid` can be directly used as the time sequence sorting key for historical versions, supporting ordered storage and binary search of historical versions without the need for additional version time sequence fields. During historical version garbage collection, by comparing `min_xid` with the global minimum active transaction snapshot identifier, expired versions without any active transaction references can be accurately filtered out, ensuring the safety of garbage collection.
[0107] The logical deletion flag `del_flag` is a boolean field that marks the deletion status of metadata versions, with values of only `true` (deleted) or `false` (not deleted / valid). This parameter replaces direct physical deletion with a version flag. When deleting metadata, historical data is not directly erased; instead, a new version carrying the deletion flag is generated. Deletion semantics are achieved through status flags, avoiding the long transaction access failure problem caused by physical deletion.
[0108] The value of `del_flag` strictly corresponds to the operation type. In creation and modification scenarios, for normally generated valid versions, `del_flag` is uniformly set to `false`, indicating that this version is a normal and valid metadata version. In deletion scenarios, when performing a metadata deletion operation, the generated new version has `del_flag` set to `true`, indicating that this version is a deletion-marked version, and the metadata is logically deleted at the transaction point corresponding to this version.
[0109] The deletion operation only adds a new deletion marker version; it does not modify or clear any historical versions. Long transactions that started earlier than the deletion transaction can still access the valid historical versions before deletion and will not encounter operation failures with "metadata not found" errors. New transactions that started later than the deletion transaction can identify the deletion status of the latest version and return the result that the object does not exist, thus achieving time-series isolation of the deletion operation.
[0110] In the historical version chain, normal iteration versions and deletion-marked versions can be clearly distinguished, which not only supports accurate change auditing, but also facilitates accurate identification of invalid deleted versions during garbage collection, avoiding the accidental deletion of valid historical data.
[0111] By embedding the deletion status into the version parameters, there is no need to maintain a separate global deletion record table. This unifies the version management logic for the three types of operations: creation, modification, and deletion, and reduces system complexity.
[0112] Whenever metadata is created, modified, or deleted, the version number of the new version is generated first, and the commit sequence number of the current operation transaction is obtained synchronously.
[0113] The value of del_flag is set according to the operation type: set to false for creation and modification operations, and set to true for deletion operations.
[0114] Assign the commit number of the current transaction to the min_xid of the new version to complete the parameter configuration. The configured two parameters, together with the version number, the previous version number, metadata entities, and other information, form a complete version record and are written to the historical version storage structure; at the same time, they are synchronously updated to the mapping entries in the active version storage structure as the basis for visibility determination.
[0115] S3 generates a snapshot transaction identifier bound to the transaction when the transaction starts, and the snapshot transaction identifier remains unchanged throughout the entire lifecycle of the transaction.
[0116] The snapshot transaction identifier (snap_xid) is a globally unique time sequence identifier assigned when a transaction starts. It represents the time sequence boundary of the metadata versions that the transaction can see. It can only see the metadata versions committed before the transaction starts, and metadata changes committed after the transaction starts are not visible to the transaction.
[0117] The identifier adopts the same global transaction sequence number system as min_xid, both of which are 64-bit unsigned integers and are uniformly generated by the same global transaction identifier allocator. This ensures that the two are in the same time space and can be directly compared in size, which is the premise for the subsequent visibility determination logic to be valid.
[0118] The snapshot transaction identifier (snap_xid) is uniformly assigned by the global transaction manager, relying on a global atomic incrementing counter to ensure that the snapshot_xid of all nodes and all transactions is globally unique and strictly monotonically increasing, eliminating issues of duplication, rollback, or timing discrepancies. In distributed scenarios, the global configuration manager coordinates the master node to uniformly assign the snapshot, avoiding sequence number conflicts across multiple nodes.
[0119] The allocation is completed the moment a transaction starts and before any data operations (including metadata queries, vertex / edge reads and writes) are performed, ensuring that the transaction is executed based on a unified snapshot view from the very first operation.
[0120] The snapshot transaction identifier (snap_xid) follows the principle of "one identifier per transaction," meaning each transaction is assigned a snap_xid only once. Nested transactions and child transactions all use the snap_xid of the parent transaction, ensuring a consistent view within the same transaction context and preventing inconsistencies in internal views.
[0121] The snap_xid is written to the transaction context structure and accompanies the transaction throughout its entire lifecycle, from startup, execution, commit to rollback, serving as a fixed baseline parameter for all metadata access within that transaction. During transaction execution, regardless of how many metadata creation, modification, or deletion operations other concurrent transactions commit, and regardless of how global metadata is updated, the snap_xid of the current transaction always retains the value assigned at startup. It will not be dynamically refreshed, will not increment with the global transaction number, and will not change due to the transaction's own write operations.
[0122] All metadata query, modification, and deletion requests within a transaction will automatically carry this snap_xid to the metadata version management component, serving as the sole transaction-side basis for visibility determination, and will remain unchanged throughout the entire process.
[0123] In traditional weakly schemated graph databases, all transactions share a globally up-to-date view of metadata. Once metadata is modified, all concurrent transactions immediately detect it, making long transactions highly susceptible to non-repeatable read issues such as inconsistent query results. By fixing the `snap_xid`, all metadata access within a transaction is based on a unified view at startup, thoroughly ensuring the consistency of the metadata view within the transaction and achieving a repeatable read isolation level for structured metadata.
[0124] In step S2, the min_xid of each metadata version marks the effective start point of the version, while the snap_xid marks the view start point of the transaction. The two can be accurately determined by a simple comparison logic that snap_xid≥min_xid indicates that the version is visible. This eliminates the need for complex version traversal or timing calculations, making the determination logic extremely simple and highly efficient.
[0125] S4 performs metadata version visibility determination based on the snapshot transaction identifier, combined with the minimum transaction identifier and the logical deletion flag, to determine the metadata version accessible to the current transaction.
[0126] The methods for determining the visibility of S41 metadata versions include: S411 retrieves the active version storage structure and obtains the minimum transaction identifier and logical deletion marker of the current active version.
[0127] Using the unique identifier object_id of the target metadata object as the search key, retrieve the active version storage hash table in memory, obtain the minimum transaction identifier min_xid and logical deletion flag del_flag of the current active latest version of the object, and at the same time obtain the metadata storage pointer of the corresponding version.
[0128] S412 If the snapshot transaction identifier of the current transaction is greater than or equal to the minimum transaction identifier, and the logical deletion mark is in an undeleted state, then return the metadata of the current active version.
[0129] If the snapshot transaction identifier (snap_xid) of the current transaction is greater than or equal to the minimum transaction identifier (min_xid) of the current active version, and the logical deletion flag (del_flag) of the current active version is false, then after passing the determination, the complete metadata entity content is read directly through the metadata storage pointer obtained in S411 and returned, thus ending this visibility determination process.
[0130] S413 If the snapshot transaction identifier of the current transaction is less than the minimum transaction identifier, then match the valid historical version with the corresponding time sequence in the historical version storage structure and return it.
[0131] If the snapshot transaction identifier of the current transaction is less than the minimum transaction identifier min_xid of the current active version, it means that the current active version was generated later than the transaction start time, and this new version is not visible to the current transaction. It is necessary to go back to the historical versions and find the last valid version committed before the transaction started.
[0132] Enter the historical version storage structure and locate the historical version group corresponding to the metadata object; based on the ordered nature of historical versions arranged in ascending order of min_xid, a binary search algorithm is used for fast retrieval, with the goal of finding the largest historical version that satisfies min_xid≤snap_xid and del_flag=false; if a matching historical version is found, the complete metadata of that version is read and returned; if no valid version matching the conditions is found after traversing all historical versions, "metadata object does not exist" is returned.
[0133] S414 If the logical deletion mark of the current active version is deleted, and the snapshot transaction identifier of the current transaction is greater than or equal to the minimum transaction identifier, then it is determined that the metadata is not visible.
[0134] If the following conditions are met: the logical deletion flag `del_flag` of the current active version is true, and the snapshot transaction identifier `snap_xid` of the current transaction is greater than or equal to the minimum transaction identifier `min_xid` of the current active version, then the visibility determination process will end after the condition is met and "metadata object does not exist" is returned.
[0135] At this point, the metadata has already been deleted, and the start time of the current transaction is later than the commit time of the deletion operation. Therefore, the metadata is not visible to the current transaction, which is consistent with the business semantics of physical deletion.
[0136] This embodiment divides metadata into two categories: structural metadata and configuration metadata, and applies differentiated activation rules to balance transaction consistency and system real-time performance.
[0137] Structure class metadata includes the names and definitions of graphs, labels, and relationships. Changes to this type of metadata directly affect the data view of transactions. Version changes to structure class metadata strictly follow the MVCC visibility rules mentioned above, and are only visible to new transactions started after the change is committed. Active transactions started before the change is committed still access the old version, ensuring the repeatable read isolation level of transactions.
[0138] Configuration metadata includes indexing rules, time-to-live (TTL) configurations, data constraints, and auto-increment sequences. This type of metadata falls under system management and configuration, requiring real-time updates to ensure correct system operation. Version changes to configuration metadata take effect globally immediately upon submission, allowing all active transactions to access the latest configuration in real time. This prevents issues such as index expiration, data stagnation, lagging constraints, and inconsistent global auto-increment sequences.
[0139] When metadata is modified or deleted, the S42 version management component executes a standardized version update process to generate a new version and maintain the version chain. The specific steps are as follows: S421 retrieves the current active version from the active version storage structure based on the unique identifier of the metadata.
[0140] Using the unique identifier object_id of the target metadata object as the search key, retrieve the active version storage hash table in memory to obtain the full information of the current active version, including version number, minimum transaction identifier min_xid, logical deletion flag del_flag, and metadata storage pointer; and read the complete metadata entity of this version in persistent storage, such as the tag name, extended configuration, statistics and other fields, through the metadata storage pointer.
[0141] The purpose of reading the complete metadata entity is to provide baseline data for the new version. Modification operations are based on the content of the old version to change fields, and deletion operations retain the complete content of the old version for historical traceability. No data of the old version is modified throughout the process.
[0142] If the corresponding object is not found in the active version storage, it indicates that this is the first creation of the scenario, and the current version number is recorded as -1, with no previous version; this process is for modification / deletion scenarios, and the object is assumed to already exist.
[0143] This step is a pure read operation, requiring no locking, and can be completed quickly using an active version of the in-memory hash table, with a very short processing time.
[0144] S422 generates a new version number and writes the complete metadata and corresponding parameters of the current active version into the historical version storage structure.
[0145] The new version number is generated by adding 1 to the current active version number. The version number follows a monotonically increasing rule, starting from 0 and iterating sequentially, naturally representing the chronological order of versions, and also serving as a node identifier in the version chain.
[0146] Completely serialize all information of the current active version, including complete metadata entity, version number, min_xid, del_flag, previous version number, creation time and other version fields, and append it to the historical version storage structure, belonging to the end of the group corresponding to the object_id.
[0147] Older versions of data are archived completely without any modification or marking, and are permanently retained in historical storage. This design ensures the read-only nature of historical versions, allowing long-running transactions to safely access older versions without data inconsistency or access failures due to write operations.
[0148] Historical versions are written in append mode, with historical versions of the same object arranged chronologically. This eliminates the need to modify existing historical data, resulting in high disk I / O performance and preventing disruption of the existing version chain.
[0149] The archived content includes all fields and metadata entities of the old version, ensuring that historical versions can be fully restored and supporting version rollback and audit traceability.
[0150] S423 creates new version metadata information. If it is a modification operation, it sets the logical deletion flag to not deleted and the minimum transaction identifier to the current modification transaction number; if it is a deletion operation, it sets the logical deletion flag to deleted and the minimum transaction identifier to the current deletion transaction number.
[0151] Construct a new version metadata structure, populate basic fields such as object identifier, new version number, creation time, and last modified transaction identifier, and configure parameters differently according to the operation type.
[0152] In the modification operation scenario, set the logical deletion flag del_flag to false, set the minimum transaction identifier min_xid to the commit transaction number of the current modification transaction, set the previous version number to the version number of the old version, and write the modified metadata entity content to the new version.
[0153] In the deletion operation scenario, the logical deletion flag del_flag is set to true, the minimum transaction identifier min_xid is set to the commit transaction number of the current deletion transaction, and the previous version number is set to the version number of the old version; the metadata entity retains the complete content of the old version, and the deletion semantics are only implemented through the flag bit.
[0154] The version's effective date is strictly tied to the transaction commit sequence, ensuring that the new version is not visible to any other transactions before the transaction is committed, thus meeting the isolation requirements of database transactions.
[0155] The deletion operation does not erase any metadata; it only generates a new version with a deletion marker. Longer transactions that precede the deletion transaction can still access the old valid version in historical storage and will not encounter errors due to the deletion operation. Newer transactions that follow the deletion transaction are aware of the deletion status through the deletion marker of the active version, thus achieving time-series isolation.
[0156] Each new version records the previous version number, naturally forming a complete iteration chain of the metadata object from its creation to the present, without the need to maintain an additional linked list structure, and supporting precise tracing of a single object.
[0157] S424 updates the version number, minimum transaction identifier, logical deletion flag, and metadata storage pointer of the corresponding metadata in the active version storage structure, and points the metadata storage pointer to the new version.
[0158] Update the mapping entry for the corresponding object_id in the active version storage structure, synchronously updating the version number, minimum transaction identifier, logical deletion flag, and metadata storage pointer, all pointing to the newly generated version. After the update is complete, the new version officially becomes the current active version of this metadata object.
[0159] After the update is completed, subsequent newly initiated transaction queries will perform visibility determination based on the parameters of the new version; while the old version has been fully archived to historical storage, and long transactions started earlier can still be accessed normally through historical versions, with read and write operations not interfering with each other.
[0160] S425 broadcasts metadata change notifications to all nodes in the distributed cluster.
[0161] The distributed synchronization management component generates incremental synchronization data packets, which are then synchronized to all slave nodes in the cluster via a reliable broadcast mechanism based on the Raft protocol. The core content of the broadcast data packet includes: metadata object_id, new version number, min_xid, del_flag, previous version number, change type (modification / deletion), and a summary of the new version metadata.
[0162] After receiving the notification, each slave node parses the version parameters and metadata content, synchronously updates the local active version storage mapping, and appends the new version to the version chain of the corresponding object in the local historical version storage, thus completing the local version chain.
[0163] Based on the Raft protocol, broadcast reliability and atomicity are achieved, ensuring that a majority of nodes receive changes before confirming commits. Even in network partitions or node failure scenarios, eventual data consistency is guaranteed, preventing inconsistencies where some nodes update while others do not. Each node completes its local chain using a preceding version number, ensuring complete consistency in version iteration order and parameter configuration across the entire cluster, supporting cross-node views of distributed transactions. Figure 1 To the point of being responsive.
[0164] Through the above process, each modification or deletion of metadata will generate an independent new version, while the old version will be fully preserved in the historical storage and will not be overwritten or directly deleted, thus ensuring the integrity of the version chain.
[0165] In this embodiment, an independent version chain is constructed for each piece of metadata. The creation, modification, renaming, deletion and other iterations of the object throughout its entire lifecycle are linked by the preceding version number field to form a closed-loop traceability link.
[0166] This version chain allows for precise location of the metadata version corresponding to any transaction snapshot, querying of metadata status at any historical moment, and rollback of specified metadata to any historical version in the version chain, enabling rapid fault recovery and refined auditing.
[0167] Example 3:
[0168] This embodiment is applied to the management of tags and relationships.
[0169] Creating and cleaning up S5 tags and relationships.
[0170] S51 triggers the automatic label creation step when creating vertices.
[0171] Automatic label creation is triggered when vertices are created, ensuring that label metadata exists automatically when data is written, without requiring pre-definition by the user. The specific process is as follows: S511 queries metadata based on graph identifier and label name to determine whether the label already exists.
[0172] Upon receiving a vertex creation request, after parsing out the graph identifier and label name, a two-level query mechanism is used to determine whether the label already exists, using the graph identifier and label name as the joint query key.
[0173] First-level query. Prioritizes retrieving the tag metadata cache in the local node's memory (a hash mapping based on the active version storage structure), and quickly matches the corresponding tag object using the combination key of the graph identifier and the tag name.
[0174] Second-level query. If the memory cache is not hit, the underlying RocksDB tag system table is retrieved, and a disk-level query is performed to confirm the existence of the corresponding tag metadata.
[0175] If the corresponding tag metadata is matched at either level of the two-level query, it is determined that "the tag already exists"; if neither level of the query matches, it is determined that "the tag does not exist".
[0176] If the tag does not exist, S512 requests a unique tag identifier from the global configuration manager, initializes the tag metadata structure, configures the minimum transaction identifier and logical deletion flag for the initial version, persists the tag metadata, and broadcasts the tag creation event to all nodes.
[0177] If the tag is determined to be non-existent, the complete tag creation and synchronization process will be executed, with the following specific steps: Request a globally unique tag identifier from the global configuration manager.
[0178] A tag identifier request is initiated to the global configuration manager of the distributed cluster, with the request parameters including the graph identifier and the tag name. Based on the obtained tag identifier, a complete tag metadata object is initialized, with all fields assigned values according to their initial state.
[0179] Tag creation is a metadata creation operation that follows a unified version management standard. The initial version is configured with two core parameters: the minimum transaction identifier `min_xid` and the logical deletion flag `del_flag` are set to `false`, indicating that the initial version is valid metadata. Simultaneously, the initial version number is configured as 0, and the preceding version number as -1, representing no preceding version and the starting point of the version chain.
[0180] After initialization is complete, the tag metadata and initial version information are written to storage according to a unified version update process.
[0181] The distributed synchronization management component generates tags to create incremental synchronization packets. These packets are then synchronized to all nodes in the cluster via a reliable broadcast mechanism based on the Raft protocol. The synchronization packet content includes a graph identifier, tag identifier, tag name, initial version's min_xid, del_flag, and version number.
[0182] Upon receiving the broadcast, each slave node synchronously updates its local memory cache, active version storage structure, and historical version storage structure, completing its local tag metadata and version chain to ensure that the tag metadata of all nodes in the entire cluster is visible. Figure 1 This is to prevent other nodes from creating the same tag.
[0183] S513 If the label already exists, use the existing label identifier.
[0184] If a label already exists, the corresponding label identifier is extracted directly from the matched metadata and returned to the upper-level vertex creation logic, without having to repeat the creation process.
[0185] The reused tag identifiers are completely consistent with the globally assigned ID system, ensuring that tags with the same name under the same graph always correspond to the same global ID, thus ensuring the consistency of metadata; When a large number of vertices with the same label are written in batches, the label creation process is triggered only for the first vertex write. Subsequent vertex writes directly reuse the existing label IDs, and the performance of batch writes is almost unaffected by metadata management.
[0186] S52 triggers an automatic relationship creation step when creating an edge. The specific steps are as follows: S521 queries metadata based on graph identifier and relation name to determine whether the relation already exists; If the relationship does not exist, S522 requests a unique relationship identifier from the global configuration manager, initializes the relationship metadata structure, configures the minimum transaction identifier and logical deletion flag for the initial version, persists the relationship metadata, and broadcasts the relationship creation event to all nodes. S523 If the relation already exists, the existing relation identifier is used directly.
[0187] The steps for creating a relationship are similar to those for creating a vertex, and the specific technical details will not be elaborated here.
[0188] Automatic cleanup of S53 tags and relationships.
[0189] This step is the recycling phase of the metadata full lifecycle automated operation and maintenance system. It is scheduled and executed periodically in the background by the automatic cleanup management component. It is an asynchronous offline operation and does not block online business read and write operations throughout the process.
[0190] S531 traverses all graphs in the system and performs cleanup condition checks on all labels and relationships under each graph one by one.
[0191] The cleanup task is triggered by the timer of the automatic cleanup management component. By default, the system performs a full cleanup check once per hour. Users can dynamically adjust the check cycle according to business scenarios, such as increasing the frequency during off-peak hours and decreasing the frequency during peak hours. Task scheduling is independent of the business read / write chain and is executed asynchronously in the background throughout, without consuming business request processing resources.
[0192] The cleanup and detection process employs a three-tiered traversal order: global graph, labels within a single graph, and relationships within a single graph, scanning all metadata objects layer by layer.
[0193] First, obtain a list of identifiers for all graphs in a valid state in the system. Then, perform subsequent checks on each graph one by one. The checks on labels and relationships are carried out independently on a graph-by-graph basis, and the cleanup logic between different graphs does not interfere with each other.
[0194] For the current graph, retrieve a list of all undeleted tag metadata from the active version storage structure, and perform tag cleanup condition checks one by one.
[0195] Synchronously obtain a list of metadata for all non-deleted relationships in the current graph, and perform relationship cleanup condition checks one by one.
[0196] For labels, the S532 validation conditions include: the number of vertices under the label is zero; there is no index configuration under the label; there is no lifetime configuration under the label; and there are no data constraints under the label.
[0197] Tag cleaning uses four conditions and logic; all conditions must be met for a tag to be deemed cleanable.
[0198] Condition 1: The number of vertices under the label is zero.
[0199] Read the vertex count field from the tag metadata statistics. If the value is greater than 0, it means that there are still vertices with the tag attached, the tag is in business use and cannot be cleaned up; if it is equal to 0, proceed to the next check.
[0200] Condition 2: No index configuration exists under the tag.
[0201] Read the index list from the extended information of the tag metadata. If the list is not empty, it means that the user has created an attribute index or full-text index for the tag, which means that the user has a clear business plan and it cannot be cleaned up; if the list is empty, proceed to the next verification.
[0202] Condition 3: There is no Time-to-Live (TTL) configuration under the tag.
[0203] Read the time-to-live (TTL) configuration list from the extended information of the tag metadata. If the list is not empty, it means that the tag has configured an automatic vertex expiration rule, and the business is still managing the data lifecycle under the tag through the TTL rule, so it cannot be cleaned up; if the list is empty, proceed to the next verification step.
[0204] Condition 4: There are no data constraints under the label.
[0205] Read the list of data constraints in the extended information of the tag metadata. If the list is not empty, it means that the tag is configured with data integrity constraints such as non-empty attributes, uniqueness, and value range. This means that the business has a clear structural definition for the tag and it cannot be cleaned up. If the list is empty, it is determined to be a cleanable tag.
[0206] If all four conditions are met, the tag is determined to be cleanable.
[0207] For relations, the S533 validation conditions include zero edge count, no index configuration, no time-to-live configuration, and no data constraints.
[0208] The logic for cleaning up and verifying relationships is the same as that for labels, using the same four conditions and judgment rules, except that the statistical object is changed from "number of vertices" to "number of edges".
[0209] Condition 1: The number of edges under the relation is zero. This is a basic premise; subsequent checks only proceed when no edges are using the relation.
[0210] Condition 2: No index configuration exists under the relationship. Edge indexes created on the relationship are explicitly configured by the user and should not be accidentally deleted due to temporary lack of data.
[0211] Condition 3: No Time-to-Live (TTL) configuration exists under the relationship. Relationships configured with TTL are long-term reused objects and cannot be cleaned up.
[0212] Condition 4: No data constraints exist under the relationship. Relationships with configured attribute constraints and referential integrity constraints indicate a clearly defined business logic that cannot be cleaned up.
[0213] If all four conditions are met, the relationship is determined to be cleanable.
[0214] S534 adds the corresponding tag or relationship to the cleanup list only when all validation conditions are met, performs the cleanup operation in batches, generates a new version of metadata with logical deletion markers, updates the active version storage structure, and broadcasts the deletion event.
[0215] After the traversal is complete, all tags and relationships that pass all four checks will be added to the cleanup list. The purpose of batch collection is to reduce the number of cleanup operations.
[0216] For metadata objects in the cleanup list, a standard metadata deletion process is executed in batches, fully reusing the overall MVCC version management mechanism, rather than direct physical deletion: Following a unified version update process, a new version is generated for each tag / relationship to be cleaned up, the logical deletion flag (del_flag) is set to true, the minimum transaction identifier (min_xid) is the commit transaction number of the current cleanup transaction, and the previous version number is the original active version number.
[0217] The original active version is completely archived to the historical version storage structure, preserving the complete version chain.
[0218] After the batch cleanup is completed, the distributed synchronization management component generates a unified metadata deletion incremental synchronization package, and synchronizes the deletion event to all nodes in the cluster through a reliable broadcast mechanism based on the Raft protocol.
[0219] Example 4:
[0220] This example applies to historical versions of garbage collection.
[0221] S6 historical version garbage collection.
[0222] Historical version garbage collection (GC) is the final resource reclamation stage of the metadata lifecycle management system. It is executed asynchronously in the background by the garbage collection management component. Under the premise of not affecting the operation of online transactions, it cleans up expired historical versions that are no longer referenced by any transactions, thus preventing the metadata historical versions from expanding indefinitely and occupying storage resources.
[0223] S61 obtains the smallest snapshot transaction identifier of all active read transactions in the system, and uses it as the global baseline snapshot identifier.
[0224] The system iterates through all currently active read and read-write transactions, collects the snapshot transaction identifier (snap_xid) bound to each transaction, and takes the minimum value among them as the global baseline snapshot identifier (min_active_xid), which serves as a unified criterion for determining whether historical versions are reclaimable.
[0225] In this step, only the snapshot identifier of the read view for a transaction is counted; the commit number of the write transaction is not included in the count. This is because the visibility of metadata versions is determined solely by the snapshot identifier at the time the transaction starts, and all read operations for a transaction are performed based on a fixed snapshot_xid.
[0226] The active transaction list is maintained uniformly by the global transaction manager. During data collection, the instantaneous state of the list is read through atomic snapshots to avoid baseline deviations caused by transaction start / end during the collection process and ensure the accuracy of the baseline value.
[0227] min_active_xid represents the view time point corresponding to the earliest started and still running transaction in the current system, which is the oldest valid transaction view in the entire system.
[0228] S62 iterates through all historical version entries in the historical version storage structure, filters out historical versions whose smallest transaction identifier is less than the global baseline snapshot identifier and which are not the current active latest version, and identifies them as reclaimable versions.
[0229] Iterate through all historical version entries of all metadata objects in the historical version storage structure one by one, and filter reclaimable versions based on two conditions, both of which must be met simultaneously.
[0230] The minimum transaction identifier min_xid of this historical version is less than the global baseline snapshot identifier min_active_xid; This version is not the current active latest version of the corresponding metadata object.
[0231] Versions that meet both conditions are considered recyclable and added to the deletion list.
[0232] Historical versions are stored using a structure that groups by object and sorts by time sequence. Therefore, traversal does not require a global scan of all entries; each entry can be processed individually by object group. Historical versions of the same object are sorted in ascending order by min_xid. Thus, a binary search can be used to quickly locate the first version that satisfies min_xid ≥ min_active_xid. All historical versions before this one satisfy the time sequence condition and can be batch-marked as awaiting recycling without needing to compare them one by one, significantly improving filtering efficiency.
[0233] For historical versions marked for logical deletion, the same judgment rules apply. As long as both conditions are met, whether it's a normal iteration version or a version marked for deletion, it will be included in the reclamation scope, completely releasing the historical storage of deleted objects.
[0234] S63 performs bulk physical deletion on recyclable versions.
[0235] Remove all historical version entries from the list to be deleted in batches and permanently remove them from the historical version storage structure, simultaneously releasing the corresponding disk storage space and memory cache space.
[0236] All recyclable versions are sorted by storage location and then deleted in batches to reduce random disk I / O and improve recycling efficiency. For RocksDB-based storage engines, deletion requests are submitted all at once through the batch deletion interface, reducing the merging and compression pressure on the storage engine.
[0237] After deletion, the system synchronously updates garbage collection statistics, including the time of this collection, the number of versions cleaned, the amount of storage space released, and the total number of remaining historical versions, for operation and maintenance monitoring and subsequent collection trigger condition determination.
[0238] In a distributed scenario, after the master node completes its recycling, it broadcasts a version cleanup event. Each slave node then synchronously cleans up its local historical version storage and cache, ensuring that the storage status of all nodes in the cluster is completely consistent.
[0239] This embodiment supports three triggering conditions; version recycling occurs when any one of them is met: One is time interval triggering. The system records the last garbage collection time, calculates the interval between the current time and the last collection time, and if it exceeds the preset time interval threshold (default 24 hours), then collection is triggered.
[0240] Second, the version count triggers the system to count the total number of historical versions in the historical version storage structure. If the total number exceeds the preset maximum threshold (default 10,000), the system will trigger the recycling.
[0241] Third, storage space triggering: the system counts the disk space occupied by historical versions of storage. If it exceeds the preset maximum storage space threshold (default 10GB), it will trigger recycling.
[0242] Example 5:
[0243] This embodiment provides a distributed synchronization mechanism.
[0244] The distributed synchronization subsystem is based on the Raft reliable broadcast protocol to achieve global consistency synchronization at the metadata version level. It is adapted to the multi-version metadata architecture of this invention and solves the problems of lagging and inconsistent metadata views of traditional weak-mode database nodes.
[0245] When any node triggers metadata creation, modification, or deletion operations and generates a new version, the global configuration manager uniformly records parameters such as the object identifier, version number, min_xid, and del_flag of the new version, ensuring the atomicity of the change operation. Subsequently, the broadcast service generates incremental synchronization data packets, which only encapsulate the changed metadata version information, without needing to synchronize the full metadata, significantly reducing network transmission overhead.
[0246] After all slave nodes in the cluster receive the synchronization data packet, they parse the new version parameters and metadata content, update the local active version mapping relationship, historical version storage chain and cached data, and complete the iteration version chain of the corresponding metadata object to ensure that the local version parameters, timing logic and visibility rules of each node are completely consistent with those of the master node.
[0247] For special scenarios such as newly launched nodes and network partition recovery, the system supports full metadata version synchronization, synchronizing the complete dual-layer storage structure and all historical version data, quickly filling in the missing version chain and parameter configuration of nodes, ensuring that the metadata view and version status of all nodes in the cluster are completely unified, and supporting the high concurrency and high availability operation of the distributed cluster.
[0248] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0249] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a computer terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0250] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims. All of these forms are within the protection scope of the present invention.
Claims
1. A method for managing metadata in a graph database based on multi-label weak mode, characterized in that, Includes the following steps: Construct a metadata storage structure, which includes an active version storage structure and a historical version storage structure; The active version storage structure uses the unique identifier of the metadata as the retrieval primary key and stores the version number of the current active version of the corresponding metadata, the minimum transaction identifier, the logical deletion marker, and the metadata storage pointer. The historical version storage structure is grouped by unique metadata identifiers, and its historical versions are stored in the version generation sequence under the same metadata. Configure a minimum transaction identifier and a logical deletion flag for each metadata version. The minimum transaction identifier is the transaction commit number corresponding to the generation of the version, and the logical deletion flag is used to identify whether the version is in a logical deletion state. A snapshot transaction identifier is generated when a transaction starts and is bound to that transaction. The snapshot transaction identifier remains unchanged throughout the entire lifecycle of the transaction. Based on the snapshot transaction identifier, and combined with the minimum transaction identifier and the logical deletion flag, a metadata version visibility determination is performed to determine the metadata version accessible to the current transaction.
2. The graph database metadata management method based on multi-tag weak mode according to claim 1, characterized in that: For structure class metadata, version changes are only visible to new transactions started after the change is committed. The structure class metadata includes the names and definition structures of graphs, labels, and relationships. For configuration-type metadata, version changes take effect globally after commit, and are accessible to all active transactions. The configuration-type metadata includes indexing rules, time-to-live configurations, data constraints, and auto-incrementing sequences.
3. The graph database metadata management method based on multi-tag weak mode according to claim 1, characterized in that, Methods for determining metadata version visibility include: Retrieve the active version storage structure to obtain the minimum transaction identifier and logical deletion marker of the current active version; If the snapshot transaction identifier of the current transaction is greater than or equal to the minimum transaction identifier, and the logical deletion flag is in an undeleted state, then return the metadata of the current active version; If the snapshot transaction identifier of the current transaction is less than the minimum transaction identifier, then a valid historical version with the corresponding time sequence is matched in the historical version storage structure and returned; If the logical deletion mark of the current active version is deleted, and the snapshot transaction identifier of the current transaction is greater than or equal to the minimum transaction identifier, then the metadata is determined to be invisible.
4. The graph database metadata management method based on multi-tag weak mode according to claim 1, characterized in that, When metadata is modified or deleted, a version update process is executed, including: Retrieve the current active version from the active version storage structure based on the unique identifier in the metadata; Generate a new version number and write the complete metadata and corresponding parameters of the current active version into the historical version storage structure; Create new version metadata information. If it is a modification operation, set the logical deletion flag to not deleted and the minimum transaction identifier to the current modification transaction number; if it is a deletion operation, set the logical deletion flag to deleted and the minimum transaction identifier to the current deletion transaction number. Update the version number, minimum transaction identifier, logical deletion flag, and metadata storage pointer of the corresponding metadata in the active version storage structure, and point the metadata storage pointer to the new version; Broadcast metadata change notifications to all nodes in the distributed cluster.
5. The graph database metadata management method based on multi-tag weak mode according to claim 1, characterized in that, Each metadata corresponds to a version chain, and each metadata version records the previous version number. All iterations of the metadata throughout its entire lifecycle are linked together through the previous version number.
6. The graph database metadata management method based on multi-tag weak mode according to claim 1, characterized in that, It also includes an automatic label creation step that is triggered when vertices are created, including: Query metadata based on graph identifier and label name to determine if the label already exists; If the tag does not exist, a unique tag identifier is requested from the global configuration manager, the tag metadata structure is initialized, the minimum transaction identifier and logical deletion flag of the initial version are configured, the tag metadata is persisted and stored, and the tag creation event is broadcast to all nodes; If the label already exists, the existing label identifier will be used.
7. The graph database metadata management method based on multi-tag weak mode according to claim 1, characterized in that, It also includes an automatic relationship creation step that is triggered when an edge is created, including: Query metadata based on graph identifier and relation name to determine if the relation already exists; If the relationship does not exist, a unique relationship identifier is requested from the global configuration manager, the relationship metadata structure is initialized, the minimum transaction identifier and logical deletion flag of the initial version are configured, the relationship metadata is persisted and stored, and the relationship creation event is broadcast to all nodes; If the relation already exists, use the existing relation identifier directly.
8. The graph database metadata management method based on multi-tag weak mode according to claim 1, characterized in that, It also includes automatic tag and relationship cleanup steps, including: Traverse all graphs in the system and perform cleanup condition checks on all labels and relationships under each graph one by one; For labels, the validation conditions include zero vertex count under the label, no index configuration under the label, no lifetime configuration under the label, and no data constraints under the label. For relations, the validation conditions include zero edge count, no index configuration, no time-to-live configuration, and no data constraints. Only when all validation conditions are met will the corresponding tag or relationship be added to the cleanup list, the cleanup operation be performed in batches, a new version of metadata with logical deletion markers be generated, the active version storage structure be updated, and the deletion event be broadcast.
9. The graph database metadata management method based on multi-tag weak mode according to claim 1, characterized in that, It also includes historical garbage collection steps, including: Obtain the smallest snapshot transaction identifier of all active read transactions in the system, and use it as the global baseline snapshot identifier; Traverse all historical version entries in the historical version storage structure and filter out historical versions whose minimum transaction identifier is less than the global baseline snapshot identifier and which are not the current active latest version as recyclable versions; Perform bulk physical deletion on recyclable versions.
10. The graph database metadata management method based on multi-label weak mode according to claim 9, characterized in that, The conditions for triggering garbage collection in historical versions include any of the following: The time interval since the last garbage collection exceeds a preset threshold; The total number of historical versions in the historical version storage structure exceeds a preset threshold. The storage space occupied by the historical version storage structure exceeds the preset capacity threshold.
11. The graph database metadata management method based on multi-tag weak mode according to claim 1, characterized in that, It also includes the distributed metadata synchronization step: Metadata changes are recorded uniformly by the global configuration manager; Generate incremental synchronization data packets and synchronize them to all nodes in the cluster; After receiving the incremental synchronization data packet, each node updates its local active version storage structure, historical version storage structure, and metadata cache, and completes the version chain of the corresponding metadata.
12. The graph database metadata management method based on multi-label weak mode according to claim 11, characterized in that, When a new node joins the cluster or when data inconsistencies occur between nodes, a full synchronization is performed, synchronizing the metadata storage structure and all historical version data to the target node.
13. A graph database metadata management system based on multi-label weak mode, characterized in that, include: A metadata storage component is used to construct a metadata storage structure, which includes an active version storage structure and a historical version storage structure. The active version storage structure uses the unique identifier of the metadata as the retrieval primary key and stores the version number of the current active version of the corresponding metadata, the minimum transaction identifier, the logical deletion marker, and the metadata storage pointer. The historical version storage structure is grouped by unique metadata identifiers, and its historical versions are stored in the version generation sequence under the same metadata. The version management component is used to configure a minimum transaction identifier and a logical deletion flag for each metadata version. The minimum transaction identifier is the transaction commit number corresponding to the generation of the version, and the logical deletion flag is used to identify whether the version is in a logical deletion state. A snapshot transaction identifier is generated when a transaction starts and is bound to the transaction. The snapshot transaction identifier remains unchanged throughout the entire lifecycle of the transaction. Based on the snapshot transaction identifier, combined with the minimum transaction identifier and the logical deletion flag, a metadata version visibility determination is performed to determine the metadata versions that the current transaction can access. An automatic cleanup management component is used to periodically perform multi-condition cleanup checks on tags and relationships, and to perform batch metadata cleanup operations that meet the conditions. The garbage collection management component is used to filter expired historical versions based on the global minimum active snapshot transaction identifier and perform garbage collection on historical versions. A distributed synchronization management component used to synchronize metadata changes to all nodes in the cluster.
Citation Information
Patent Citations
Tense graph database distributed transaction solution system
CN112214649A
