A method for fast insertion of edges in a native graph store

By dividing edge storage into a persistent edge array and an edge cache, and adopting a delayed ID resolution strategy, the problems of high ID resolution overhead and low throughput during edge insertion in graph storage systems are solved, achieving high-efficiency edge insertion and query performance, and ensuring data integrity and system reliability.

CN123178677APending Publication Date: 2026-11-27JIANGSU DAMENG DATABASE CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611425559.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-15
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing graph storage systems suffer from high ID parsing overhead, low throughput, and high query latency when inserting edges. In particular, in large-scale graph scenarios, ID parsing caused by hash collisions and cache misses becomes a significant overhead for edge insertion, affecting the performance of online transaction processing.

Method used

A delayed ID resolution strategy is adopted, dividing edge storage into a persistent edge array and an edge cache. When inserting an edge, the vertex ID is not resolved immediately, but is first written to the edge cache and the ID resolution is completed asynchronously. The correctness of online queries is guaranteed by the hash index of the edge cache, and batch and timed methods are used to process ID resolution and persistence.

Benefits of technology

It significantly reduces online edge insertion latency, improves throughput, ensures query integrity and correctness, does not lose edge data in the event of system crash, and has low implementation cost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178677A_ABST
    Figure CN123178677A_ABST
Patent Text Reader

Abstract

The application discloses a method for quickly inserting edges in native graph storage, comprising the following steps: dividing the storage space of edges into a persistent edge array and an edge cache, receiving an edge insertion request, constructing a pending edge record, not performing the analysis of the source vertex external identifier and the target vertex external identifier to the internal vertex ID, and directly occupying the source vertex external identifier and the target vertex external identifier; appending the pending edge to the WAL log buffer in the memory, writing the pending edge into the edge cache, updating the hash index, enabling the online query to hit the pending edge according to the external identifier, and adding the reference of the pending edge record to a to-be-analyzed queue; and returning the insertion success immediately after the reference of the pending edge record is added to the to-be-analyzed queue.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of graph database and graph storage technology, specifically relating to a method for quickly inserting edges in native graph storage. Background Technology

[0002] Graph databases use vertices and edges as basic storage units and are widely used in scenarios such as social network analysis, knowledge graphs, financial risk control, and recommendation systems.

[0003] In the native graph storage architecture, vertex data is stored as vertex records, and edge data is stored as edge records. When inserting an edge (source vertex → destination vertex), the traditional process is as follows:

[0004] Vertex localization: Based on the external identifiers (such as the string UUID) of the source vertex and the destination vertex, the internal storage location of the two vertices is found through an index structure (hash table, B+ tree, etc.) to obtain the ID of the internal vertex.

[0005] Edge record construction: Write the source vertex internal ID and the destination vertex internal ID into the edge record, and populate the edge attribute data.

[0006] Edge record persistence: Write edge records to disk or to an adjacency list associated with the source / destination vertex.

[0007] The above process has the following technical bottlenecks:

[0008] (1) ID resolution overhead: Each edge insertion requires querying the vertex ID mapping table (external ID → internal ID), involving at least two index lookups. In large-scale graph scenarios (billions of vertices), hash collisions and cache misses make ID resolution a significant overhead for edge insertion.

[0009] (2) Online insertion latency is constrained by ID parsing: ID parsing and edge record writing are executed serially. When the external ID is a long string (such as UUID), the hash calculation and memory access overhead of ID parsing account for a large proportion of the total edge insertion latency, which restricts the performance of high-throughput online transaction processing (OLTP).

[0010] (3) Redundant parsing exists in batch scenarios: When inserting in batches, ID parsing is repeatedly performed on a large number of edges of the same vertex, resulting in redundant index lookup operations.

[0011] (4) In the online edge insertion process of the native graph storage system, the real-time parsing of vertex IDs incurs significant overhead, severely limiting the edge insertion throughput. How to reduce the ID parsing overhead and improve the online edge insertion throughput is a technical problem that urgently needs to be solved in this field. This invention provides a method for fast edge insertion in native graph storage, which significantly improves the online edge insertion throughput while ensuring the integrity and correctness of edge data during querying. Summary of the Invention

[0012] Purpose of the invention: To address the technical shortcomings of existing edge insertion methods, this invention proposes a method for fast edge insertion using native graph storage. By employing a delayed ID parsing strategy, the real-time ID lookup overhead during edge insertion is eliminated, enabling high-throughput online edge insertion while ensuring the integrity and correctness of edge data during queries.

[0013] Technical solution: This invention proposes a method for fast edge insertion using native graph storage, comprising:

[0014] The edge storage space is divided into a persistent edge array and an edge cache. The persistent edge array is used to store the final persistent form of the edge. The final persistent form of the edge records the source vertex internal ID, the destination vertex internal ID and the edge attribute. The edge cache is used to store edges that temporarily carry the external ID of the vertex, and maintains a write-ahead log (WAL), a hash index for locating the edge, and a queue of unresolved pointers or indices for recording edge records in the cache that have not yet completed ID resolution.

[0015] Receive an edge insertion request, construct a pending edge record, the pending edge record includes at least the source vertex external identifier, the target vertex external identifier, edge attributes, and a state flag indicating that it is not resolved. Do not perform the resolution from the source vertex external identifier and the target vertex external identifier to the internal vertex ID, and directly use the source vertex external identifier and the target vertex external identifier as placeholders.

[0016] The undetermined edge is appended to the WAL log buffer in memory, written to the edge cache, and the hash index is updated so that online queries can hit the undetermined edge based on the external identifier; and the reference of the undetermined edge record is added to the parsing queue.

[0017] After adding the reference to the pending edge record to the parsing queue, the system immediately returns a success message for insertion.

[0018] Furthermore, after returning a successful insertion, the references in the queue to be parsed are processed asynchronously, the vertex ID of the undetermined edge corresponding to the reference is parsed, and the parsed edge is transferred from the edge cache to the persistent edge array.

[0019] Furthermore, the hash index uses the edge record identifier as the key, and simultaneously maintains an auxiliary index using the external identifiers of the source vertex and the external identifiers of the destination vertex as keys, which is used to retrieve the associated undetermined edges by vertex during online queries.

[0020] Furthermore, the asynchronous processing of references in the queue to be parsed, performing vertex ID parsing on the undetermined edges corresponding to the references, and transferring the parsed edges from the edge cache to the persistent edge array includes:

[0021] Take a batch of undetermined edge records from the queue to be parsed;

[0022] The edge records marked as parsed in the batch to be processed are directly identified as edge records to be migrated;

[0023] The edge records marked as unresolved in the batch to be processed are taken as edge records to be resolved. The external identifiers of the source vertex and the external identifiers of the target vertex involved in each edge record to be resolved in the batch to be processed are collected. The collected external identifiers of the source vertex and the external identifiers of the target vertex are deduplicated to obtain a unique set of external vertex identifiers.

[0024] Based on the unique external vertex identifier set, a batch query of the vertex ID mapping table is performed to obtain the internal vertex ID corresponding to each external identifier in the unique external vertex identifier set. The obtained internal vertex IDs are then backfilled into the corresponding edge record to be parsed, and the status mark of the backfilled edge record to be parsed is updated to be parsed, so as to obtain the edge record to be migrated.

[0025] Using the edge identifier in the edge record to be migrated as the idempotent key, each edge record to be migrated is migrated and written into the persistent edge array;

[0026] After the edge record to be migrated is migrated and written to the persistent edge array, the adjacency index of the source vertex and the target vertex of the corresponding edge record is updated, and the edge record that has been persisted is removed from the hash index of the edge cache, so that the edge record that has been persisted is managed by the page cache corresponding to the persistent edge array.

[0027] Advance the checkpoint of the WAL and mark the batch to be processed as having completed vertex ID resolution and persistence.

[0028] Furthermore, only when the triggering condition is met, the references in the queue to be parsed are processed asynchronously, the vertex ID of the undetermined edge corresponding to the reference is parsed, and the parsed edge is transferred from the edge cache to the persistent edge array.

[0029] The triggering condition is that the number of edges in the queue to be parsed reaches the batch threshold, or the time interval since the last parsing exceeds the timed threshold.

[0030] Furthermore, it also includes:

[0031] Upon receiving an online query request, the edge cache is queried first based on the online query request: the hash index is used to determine whether the edge corresponding to the online query request hits the edge cache;

[0032] If a match is found and the matched edge record has been parsed, then the edge data corresponding to the edge record is returned directly.

[0033] If a match is found and the edge record has not been completely resolved, then perform immediate ID resolution on the edge record.

[0034] If no match is found, the persistent edge array is queried: the corresponding persistent edge is retrieved through the vertex adjacency index and returned;

[0035] The execution of immediate ID resolution includes:

[0036] Query the vertex ID mapping table to obtain the internal vertex ID of the corresponding vertex, fill the internal vertex ID back into the edge record, update the status mark of the edge record to be resolved, and then return the edge data corresponding to the edge record.

[0037] Furthermore, it also includes:

[0038] Receive a vertex adjacent edge query request, the vertex adjacent edge query request carries the vertex external identifier and indicates whether the query type is out-edge query or in-edge query;

[0039] The external identifier of the vertex is parsed into an internal vertex ID, and the corresponding vertex record is located based on the internal vertex ID;

[0040] Obtain the edges associated with the vertex using two separate methods:

[0041] The first approach involves retrieving persistent edges from the persistent edge array using the adjacency index.

[0042] The second approach involves retrieving incompletely migrated edge records from the edge cache using the auxiliary index. Specifically, when the query type is an outbound edge query, the source vertex's external identifier is used as the retrieval key in the auxiliary index; when the query type is an inbound edge query, the destination vertex's external identifier is used as the retrieval key in the auxiliary index. For the retrieved incompletely parsed edge records, immediate ID resolution is triggered: the vertex ID mapping table is queried to obtain the corresponding vertex's internal vertex ID, which is then backfilled into the corresponding edge record, and the status marker of the corresponding edge record is updated to "resolved."

[0043] The edges obtained from the two paths will be merged and returned.

[0044] Furthermore, after the WAL log buffer is flushed to disk, the corresponding edge record is considered to have reached a crash-safe state. The crash-safe state does not depend on the completion of vertex ID parsing or the migration of edge records into the persistent edge array.

[0045] Furthermore, it also includes system crash recovery steps, including:

[0046] Starting from the most recent checkpoint, the log records in the WAL are replayed sequentially;

[0047] For log records that are replayed as edge insertion records and are not covered by the checkpoint, the undetermined edges are reconstructed based on the undetermined edge records written in the form of vertex external identifiers. The reconstructed undetermined edges are restored to the edge cache, and the hash index and the parsing queue are restored.

[0048] For log records that are replayed as parsed completed records and are not covered by the checkpoint, confirm that the corresponding edge has been persisted and remove the corresponding edge from the parsing queue to be recovered;

[0049] Restart the background asynchronous parsing thread to continue processing the undetermined edges in the restored parsing queue, so as to complete the vertex ID parsing and migration to the persistent edge array; wherein, the migration write performs idempotency checks with edge identifiers, edges that have been written to the persistent edge array are skipped, and only the migration persistence is completed for edges that have not yet been written.

[0050] After the recovery is complete, the hash index of the edge cache will be rebuilt to a consistent state.

[0051] Furthermore, it also includes a stratified back pressure control step, including:

[0052] Monitor the memory usage of the edge records to be parsed in the edge cache;

[0053] When the memory usage reaches a soft threshold, soft backpressure control is executed. The soft backpressure control includes: reducing the response priority of online insertion requests, returning a cache pressure reminder to the application layer, and increasing the parsing frequency of the background asynchronous parsing thread.

[0054] When the memory usage exceeds the hard threshold, before adding the reference of the pending edge record to the parsing queue in the online insertion path, synchronous wait control is executed: if the background asynchronous parsing thread is running, the current insertion thread is blocked until the current batch parsing is completed and the cache space of the edge cache is released; if the background asynchronous parsing thread is idle, an emergency batch parsing is triggered immediately.

[0055] When the memory usage falls below the soft threshold, the normal asynchronous insertion mode is restored.

[0056] The maximum capacity of the side cache is dynamically determined at system startup based on a certain proportion of available physical memory, or an absolute value is specified in the configuration file.

[0057] Beneficial effects: Compared with the prior art, the present invention has the following advantages:

[0058] (1) Online edge insertion latency is significantly reduced: the insertion path completely skips the vertex ID mapping table lookup, and the latency is reduced to only "WAL buffer write + edge cache insertion + return", and the online insertion throughput is increased several times.

[0059] (2) Low amortized overhead of batch ID parsing: IDs are parsed centrally through batch + timed mechanism. The external ID of the same vertex is only queried once in the current batch, avoiding the repeated parsing overhead when inserting one by one.

[0060] (3) Query path performance is not significantly affected: Immediate ID resolution is only triggered when the edge is queried but before it is processed in the background batch, which is a low-frequency path. The ID resolution of the vast majority of edges is completed through the background batch path, so query performance is not affected.

[0061] (4) Guarantee of query semantic correctness: The hash index of the edge cache ensures that the query correctly hits the non-persistent edge record; the instant ID resolution ensures that the internal ID is resolved in time before the query is returned, and the query result is complete and correct.

[0062] (5) Reliable crash recovery: edge records are persisted through WAL logs before ID resolution is completed, so the accepted edge data is not lost in system crash; edge migration adopts idempotent writing based on edge identifier, so no duplicate edge records will be generated after crash recovery.

[0063] (6) Low implementation cost: It can be achieved by adding an edge cache layer and a background asynchronous parsing thread to the existing storage engine, without modifying the underlying vertex ID mapping table. Attached Figure Description

[0064] Figure 1 This is a diagram of the overall system architecture. Figure 1 The diagram shows that the system is divided into four layers: the application layer API receives read and write requests; the edge cache is responsible for hot data storage (including hash index and parsing queue); the persistent edge array stores parsed edge records; the background asynchronous thread completes the parsing and migration of external IDs to internal IDs in batches; and the WAL log manager ensures write reliability.

[0065] Figure 2 Insert a flowchart for the edge; Figure 2The diagram shows: Online fast path: After receiving a request, construct pending edge records, write them to the WAL log and edge cache in parallel, add them to the parsing queue and return, without triggering ID parsing; Background asynchronous path: Triggered by batch threshold N or timed threshold T, batch parse external IDs into internal IDs, migrate them to a persistent array and update the index; the two paths are decoupled in time.

[0066] Figure 3 This is a flowchart of the online query path. Figure 3 The query first checks the edge cache index, and then splits into three branches based on the status: if the cache is hit and resolved (resolved=true), it returns directly; if the cache is hit but not resolved (low-frequency path), it immediately triggers ID resolution and backfilling; if the cache is not hit, it checks the persistent edge array; the three paths are finally aggregated into a complete query result. Detailed Implementation

[0067] This invention proposes a fast edge insertion method based on delayed ID updates. The core idea is to divide edge storage into two parts: a persistent edge array and an edge cache. When inserting an edge, the vertex ID is not immediately parsed. Instead, the edge record with the external ID tag is first written to the WAL log, and then to the edge cache. ID parsing and persistence are completed asynchronously through batch and timed methods. The hash index of the edge cache ensures the correctness of online queries. For details, please refer to [link to relevant documentation]. Figure 1 Specifically, it includes the following steps:

[0068] A two-layer edge storage architecture is constructed, consisting of a persistent edge array and an edge cache. The persistent edge array is organized as a contiguous array, with each edge record storing the complete (source vertex internal ID, destination vertex internal ID, and edge attributes), representing the final persistent form of the edge. The persistent edge array interacts with disk via memory-mapped files (mmap) or direct I / O. The edge cache resides in an in-memory edge buffer layer, used to receive online inserted edges. Edge records in the edge cache temporarily carry the vertex external ID instead of the internal ID and maintain the following auxiliary structures:

[0069] Hash Index: Uses edge record identifier (edgeId) as key to quickly locate edge record; at the same time, it maintains auxiliary indexes using source vertex external ID and destination vertex external ID as keys, which are used to retrieve associated undetermined edges by vertex during online queries.

[0070] WAL Log Buffer: Edge records in the edge cache are first written to the write-ahead log buffer. When the log buffer reaches a set size or time interval, they are written to disk in batches to ensure the persistence of edge data.

[0071] The Pending Resolution Queue records pointers or indices of edge records in the cache that have not yet completed ID resolution, for consumption by the background asynchronous resolution thread.

[0072] The data structure for the pending edge records in the edge cache is defined as follows:

[0073] PendingEdgeRecord { string srcExternalId; / / Source vertex external ID (placeholder when not resolved) string dstExternalId; / / Destination vertex external ID (placeholder when not resolved) uint64 srcInternalId; / / Source vertex internal ID (filled after resolution, initially 0 / NULL) uint64 dstInternalId; / / Destination vertex internal ID (filled after resolution, initially 0 / NULL) byte[] properties; / / Edge attribute data bool resolved; / / Whether ID resolution is complete uint64 edgeId; / / Unique edge identifier (used for hash indexing)}

[0074] The side cache manager data structure is as follows:

[0075] EdgeCacheManager {

[0076] `Mutex resolveMutex;` / / Resolve thread mutexes

[0077] HashMap<EdgeId, PendingEdgeRecord*>

[0078] hashIndex; / / Primary hash index (located by edgeId) HashMap <ExternalId, List<PendingEdgeRecord*> >

[0079] srcIndex; / / Secondary index (located by the external ID of the source vertex) HashMap <ExternalId, List<PendingEdgeRecord*> >

[0080] dstIndex; / / Secondary index (located by the external ID of the destination vertex)

[0081] ConcurrentQueue<PendingEdgeRecord*>

[0082] pendingQueue; / / Queue to be resolved (lock-free multi-producer single-consumer queue) Atomic <uint64>pendingCount; / / Number of edges to be resolved

[0083] uint64 batchThreshold; / / Batch trigger threshold (e.g., 1000)

[0084] uint64 timerIntervalMs; / / Timer trigger interval (e.g., 100ms)

[0085] uint64 maxCacheSize; / / Maximum side cache size (used for backpressure determination) float softThresholdRatio; / / Soft backpressure ratio (e.g., 0.70) floathardThresholdRatio; / / Hard backpressure ratio (e.g., 0.90)

[0086] WAL log recording format

[0087] WalRecord { uint8 recordType; / / Record type: 0x01=INSERT_EDGE,

[0088] / / 0x02 = RESOLVE_COMPLETE uint64 edgeId; / / Unique edge identifier uint64 timestamp; / / Timestamp string srcExternalId; / / External ID of source vertex string dstExternalId; / / External ID of destination vertex byte[] properties; / / Edge attribute data uint32 crc32; / / CRC checksum}

[0089] The persistent array record (final form) data structure is as follows:

[0090] PersistentEdgeRecord { uint64 srcInternalId; / / Source vertex internal ID (already resolved) uint64 dstInternalId; / / Destination vertex internal ID (already resolved) uint64properties_addr; / / Edge attribute data address uint64 flags; / / Flags (version number, deletion flag, etc.)}

[0091] Based on the above data structure, the following core processes will be explained.

[0092] Core Process 1: When the storage engine receives an edge insertion request (source vertex external ID Src, destination vertex external ID Dst, edge attribute Props), see [link to relevant documentation]. Figure 2 Perform the following steps:

[0093] Step 101: Assign a unique edge identifier. Obtain a monotonically increasing or timestamp-based unique edge identifier (edgeId) from the global edge ID allocator, and use it as the primary key for the edge cache and WAL log.

[0094] Step 102: Receive the edge insertion request and construct a pending edge record with the format: [srcExternalId, dstExternalId, props, resolved=false]. Do not perform ID resolution; use the external ID as a placeholder. Create a PendingEdgeRecord instance, filling the srcExternalId field with Src, the dstExternalId field with Dst, and the properties field with Props. Set srcInternalId and dstInternalId to empty (or zero), and set resolved to false.

[0095] Step 103: Serialize the pending edge record into a WAL record and append it to the WAL log buffer in memory to ensure crash recovery capability. The WAL record carries the complete srcExternalId, dstExternalId, and properties, with edgeId and timestamp as auxiliary fields. WAL writing must be completed before the edge cache is modified.

[0096] Step 104: Insert the pending edge record into the edge cache memory area, update the hash index with edgeId as the key so that subsequent queries can hit the edge through the edge cache, and at the same time create auxiliary index entries with srcExternalId and dstExternalId as keys respectively.

[0097] Step 105: Add the reference (pointer or index) of the pending edge record to the tail of the parsing queue, and atomically increment the pending edge counter pendingCount.

[0098] Step 106: Immediately return a success message to the application layer. No vertex ID mapping table lookup operations occurred during the entire online insertion path.

[0099] Core Process Two: The background asynchronous parsing thread consumes the queue to be parsed in batches and on a timed basis, migrating the edges from the cache to the persistent edge array:

[0100] Step 201: The asynchronous parsing thread is awakened when any of the following conditions are met: (i) the pending counter pendingCount reaches the batch threshold (e.g., 1000 records); (ii) the time interval since the last parsing completion exceeds the timer threshold (e.g., 100ms) and pendingCount is greater than zero.

[0101] Step 202: Continuously retrieve the maximum number of pending edge records from the head of the queue to be resolved, forming the current processing batch. For edge records that have already been resolved (resolved=true), proceed directly to the migration step (step 206) to ensure timely persistence and removal from the cache.

[0102] Step 203: For edge records that have not yet been parsed, traverse all undetermined edge records in the batch, extract all srcExternalId and dstExternalId, and obtain a unique set of vertex external IDs after deduplication.

[0103] Step 204: Batch query the vertex ID mapping table. Using the unique set of external vertex IDs as input, call the batch parsing interface of the vertex ID mapping table. The mapping table can employ methods such as grouped hashing batch probing or hotspot caching to accelerate batch queries, returning all internal IDs corresponding to external IDs at once.

[0104] Step 205: Traverse each unresolved edge record in the batch, write the corresponding srcInternalId and dstInternalId into the edge record according to the batch parsing result, and set the resolved flag to true.

[0105] Step 206: Batch append the parsed edge records to the end of the persistent edge array, performing idempotent writing based on edge identifiers to avoid duplicate persistence. Simultaneously update the outgoing edge adjacency index of the source vertex and the incoming edge adjacency index of the destination vertex, and register the position of the newly written edge in the persistent array to the adjacency record of the corresponding vertex.

[0106] Step 207: Remove the migrated edge record entries from the hash index of the edge cache. The persisted edge data is managed by the page cache of the edge array. Subsequent queries will directly access the page cache and release the corresponding memory.

[0107] Step 208: Advance the WAL log checkpoint position based on the walOffset of the last edge in the current batch, indicating that all edge insertion records before this position have been parsed and persisted. Subsequent crash recovery can skip the WAL records before the advanced checkpoint.

[0108] Boundary handling: If, during the batch parsing in step 204, it is found that the external ID of some vertices does not exist in the mapping table (the edge references a vertex that has not been created), the edge record is marked as "parsing failed" and moved into the dead letter queue, and the corresponding exception record is written to WAL.

[0109] For step 201, the following state variables are maintained by the global scheduler: batch threshold (number of edges), time interval (milliseconds), and timestamp of the last parsing completion.

[0110] The scheduler checks two conditions in each polling cycle: (i) whether the parsing counter has reached or exceeded the batch threshold; and (ii) whether the difference between the current time and the last parsing completion time exceeds the time interval and the parsing counter is greater than zero. Meeting either condition triggers an asynchronous parsing batch. After the parsing batch is completed, the timestamp of the last parsing completion is updated.

[0111] This invention employs adaptive interval adjustment, which involves balancing throughput and end-to-end latency: when the number of edges to be parsed in the edge cache is small (low load), the timed trigger interval is appropriately shortened to reduce the average dwell time of edges in the cache; when the number of edges to be parsed is large (high load), the timed trigger interval is appropriately extended to increase the processing size of each batch and improve batch processing efficiency. The adjustment range is constrained by the upper and lower limits of the configuration to avoid excessively long intervals under extreme loads, which could lead to an increase in the immediate parsing frequency of query paths.

[0112] Core Process 3: Employ a cache-first, hierarchical query strategy for online queries, such as... Figure 3 As shown, it specifically includes:

[0113] One-sided query, i.e., query by edgeId:

[0114] First, the edge cache hash index is queried using `edgeId` as the key. If a match is found, the `resolved` flag is checked: if it's true, the result is returned directly; if it's false, it indicates the edge was queried and matched before batch processing in the background, belonging to a low-frequency path. In this case, immediate ID resolution is triggered, which involves calling the vertex ID mapping form parsing interface to obtain `srcInternalId` and `dstInternalId` and backfilling them, setting `resolved` to true, and then returning. This type of edge skips the ID resolution step and is directly migrated during subsequent batch processing in the background.

[0115] If the edge cache misses, it indicates that the edge has been migrated to the persistent edge array, which is then retrieved and returned using the edgeId. The persistent edge array is managed through memory mapping, and frequently accessed edge data resides in memory using a page cache, resulting in query latency close to that of the edge cache hit path.

[0116] Vertex Adjacency Edge Query (Query all outgoing or incoming edges of a given vertex):

[0117] First, resolve the external vertex ID to an internal ID (this is essential in the query path, as the internal ID is needed to locate vertex records). Then, retrieve the edges in two ways: obtain persistent edges from the persistent edge array using adjacency indexes; obtain undetermined edges from the edge cache using auxiliary hash indexes. Outgoing edges are retrieved using `srcExternalId`, and incoming edges are retrieved using `dstExternalId`. For unresolved records, trigger immediate ID resolution. Finally, merge the results from both approaches and return them.

[0118] The instant ID resolution path is a low-frequency path (see...) Figure 3 Under typical load, the vast majority of edges have already had their IDs resolved and migrated to the persistent edge array during background batch processing. Only a very small number of edges queried within the batch processing time window trigger immediate resolution. Given that the probability of newly inserted edges being queried online in a short period of time is low, this low-frequency path will not have a significant negative impact on overall query performance.

[0119] Key features: ID resolution is shifted entirely to the backend, meaning it's normally handled by batch processing in the background. Edges matched by queries before batch processing are resolved immediately at the time of the query. Online insertion paths completely skip ID resolution, significantly reducing insertion latency.

[0120] The persistence of the WAL log buffer and the operation of the side cache follow the following consistency guarantees:

[0121] Write the records to the WAL log buffer first, and then write them to the edge cache (WAL-Ahead principle).

[0122] After the WAL log buffer is flushed to disk, the corresponding edge record is considered to be persisted (no need to wait for ID resolution to complete).

[0123] When recovering from a system crash, perform the following steps:

[0124] Step 301: Replay the WAL log, starting from the most recent checkpoint and reading the WAL log records sequentially.

[0125] Step 302: For WAL records of type INSERT_EDGE that have not yet been covered by a checkpoint, rebuild the pending edge records and restore them to the edge cache (including the hash index and the parsing queue). For WAL records of type RESOLVE_COMPLETE that have not yet been covered by a checkpoint, confirm that the corresponding edges have been persisted and remove them from the parsing queue to be restored.

[0126] Step 303: Restart the background asynchronous parsing thread to continue processing the restored parsing queue.

[0127] Step 304: After the recovery is complete, rebuild the hash index of the edge cache to a consistent state.

[0128] The pending edge records in the WAL log are written in the form of external IDs, which do not depend on internal IDs, so crash recovery will not cause ID inconsistency.

[0129] In this embodiment of the invention, the idempotency of WAL redo is guaranteed as follows:

[0130] (i) The persistent step of the batch parsing in the background adopts idempotent writing based on edgeId - before appending to the persistent edge array, the persistent edge array index is queried with edgeId. If the edgeId already exists, the writing is skipped (adjacency relationship is only built when the adjacency index is missing).

[0131] (ii) If the crash occurs during the batch migration process, the WAL is replayed and the pending edges are rebuilt during recovery. When the background parsing thread re-executes the migration, the edges that have been partially written to the persistent array are skipped due to the edgeId idempotency check, and only the edges that have not yet been written are persisted for the first time.

[0132] (iii) The adjacency index is updated in an idempotent manner—the association between the same vertex and the same edge is established only once, and repeated updates do not generate additional index records.

[0133] Example 2:

[0134] Based on the above embodiments, the vertex ID mapping table adopts a compact open addressable hash table structure, and its batch query interface makes full use of the cache locality of batch access:

[0135] Batch Hash Probing: During batch parsing, the set of external IDs to be queried is grouped according to the memory region where their hash values ​​reside. For groups belonging to the same hash slot region, the corresponding region data from the mapping table is loaded into the CPU cache in batches, and the lookup and comparison of all external IDs within the group is completed while the cache is hot. Compared to random lookup one by one, batch probing effectively improves the CPU cache hit rate and reduces the number of main memory accesses.

[0136] Hotspot Vertex ID Cache: A limited-capacity LRU hotspot cache is set up at the front end of the vertex ID mapping table. During batch parsing, the hotspot cache is queried first; if a match is found, the internal ID is retrieved directly. For frequently referenced vertices (such as supernodes), the hotspot cache can significantly reduce repeated accesses to the main mapping table.

[0137] Example 3:

[0138] Based on the above embodiments, the referenced source or destination vertex may be deleted after edge insertion but before ID resolution is complete. Therefore, the embodiments of the present invention employ the following processing scheme:

[0139] Optimistic mode: During batch parsing in the background, if a batch query of the vertex ID mapping table finds that some external IDs do not exist, the edge is marked as an "isolated edge," not written to the persistent edge array, removed from the edge cache, and a corresponding discard record is written to the WAL. For edges that have already been written to the persistent edge array through immediate parsing, the associated edges are marked as invalid through cascading tags when the vertex is deleted.

[0140] Protection mode: When a vertex deletion operation is executed, first check if there is a pending edge record referencing the vertex in the edge cache hash index; if so, provide two options: (a) block the deletion operation and require the associated edge to be processed first; (b) cascade delete the corresponding pending edge record and write it to the WAL rollback record.

[0141] In most OLTP scenarios, the optimistic mode is recommended to maintain the non-blocking characteristics of the edge insertion path.

[0142] Example 4:

[0143] Based on the above embodiments, this embodiment of the invention, in order to prevent the side cache from expanding indefinitely in high-throughput write scenarios due to the background parsing rate being lower than the online insertion rate, implements layered backpressure control:

[0144] Soft Backpressure: When the estimated memory usage of the edge records to be parsed in the edge cache reaches a soft threshold (such as 70% of the maximum cache capacity), the response priority of online insertion is reduced and a "cache pressure" prompt is returned to the application layer. At the same time, the background parsing frequency is accelerated (shortening the time interval and increasing the batch threshold).

[0145] Hard backpressure: When the side cache usage reaches a hard threshold (e.g., 90% of the maximum cache capacity), the online insertion path performs synchronous waiting before being added to the parsing queue: if the background asynchronous parsing thread is running, the current insertion thread is blocked until the current batch is completed and the cache space is released; if the background thread is idle, an emergency batch parsing is immediately triggered. When the cache usage falls below the soft threshold, normal asynchronous insertion mode is restored. Hard backpressure prevents side cache from experiencing OutOfMemory (OOM) errors.

[0146] Capacity adaptive strategy: The maximum capacity of the side cache is dynamically determined at system startup based on a certain percentage (e.g., 20%) of available physical memory, or an absolute value is specified in the configuration file. When the remaining physical memory of the system is detected to be lower than the safety threshold, the capacity of the side cache is actively reduced to speed up background parsing and lower both the soft and hard thresholds.

Claims

1. A method for fast edge insertion in native graph storage, characterized in that: include: The edge storage space is divided into a persistent edge array and an edge cache. The persistent edge array is used to store the final persistent form of the edge. The final persistent form of the edge records the source vertex internal ID, the destination vertex internal ID and the edge attribute. The edge cache is used to store edges that temporarily carry the external ID of the vertex, and maintains a write-ahead log (WAL), a hash index for locating the edge, and a queue of unresolved pointers or indices for recording edge records in the cache that have not yet completed ID resolution. Receive an edge insertion request, construct a pending edge record, the pending edge record includes at least the source vertex external identifier, the target vertex external identifier, edge attributes, and a state flag indicating that it is not resolved. Do not perform the resolution from the source vertex external identifier and the target vertex external identifier to the internal vertex ID, and directly use the source vertex external identifier and the target vertex external identifier as placeholders. The undetermined edge is appended to the WAL log buffer in memory, written to the edge cache, and the hash index is updated so that online queries can hit the undetermined edge based on the external identifier; and the reference of the undetermined edge record is added to the parsing queue. After adding the reference to the pending edge record to the parsing queue, the system immediately returns a success message for insertion.

2. The method for fast edge insertion in native graph storage according to claim 1, characterized in that: After successful insertion, the references in the queue to be parsed are processed asynchronously, the vertex ID of the undetermined edge corresponding to the reference is parsed, and the parsed edge is transferred from the edge cache to the persistent edge array.

3. The method for fast edge insertion in native graph storage according to claim 1, characterized in that: The hash index uses the edge record identifier as the key, and also maintains an auxiliary index using the external identifiers of the source vertex and the external identifier of the destination vertex as keys, which is used to retrieve the associated undetermined edges by vertex during online queries.

4. The method for fast edge insertion in native graph storage according to claim 2, characterized in that: The asynchronous processing of references in the queue to be parsed, performing vertex ID parsing on the undetermined edges corresponding to the references, and transferring the parsed edges from the edge cache to the persistent edge array includes: Take a batch of undetermined edge records from the queue to be parsed; The edge records in the batch to be processed that are marked as parsed are directly identified as edge records to be migrated; The edge records marked as unresolved in the batch to be processed are taken as edge records to be resolved. The external identifiers of the source vertex and the external identifiers of the target vertex involved in each edge record to be resolved in the batch to be processed are collected. The collected external identifiers of the source vertex and the external identifiers of the target vertex are deduplicated to obtain a unique set of external vertex identifiers. Based on the unique external vertex identifier set, a batch query of the vertex ID mapping table is performed to obtain the internal vertex ID corresponding to each external identifier in the unique external vertex identifier set. The obtained internal vertex IDs are then backfilled into the corresponding edge record to be parsed, and the status mark of the backfilled edge record to be parsed is updated to be parsed, so as to obtain the edge record to be migrated. Using the edge identifier in the edge record to be migrated as the idempotent key, each edge record to be migrated is migrated and written into the persistent edge array; After the edge record to be migrated is migrated and written to the persistent edge array, the adjacency index of the source vertex and the target vertex of the corresponding edge record is updated, and the edge record that has been persisted is removed from the hash index of the edge cache, so that the edge record that has been persisted is managed by the page cache corresponding to the persistent edge array. Advance the checkpoint of the WAL and mark the batch to be processed as having completed vertex ID resolution and persistence.

5. The method for fast edge insertion in native graph storage according to claim 4, characterized in that: Only when the triggering condition is met, the references in the queue to be parsed are processed asynchronously, the vertex ID of the undetermined edge corresponding to the reference is parsed, and the parsed edge is transferred from the edge cache to the persistent edge array. The triggering condition is that the number of edges in the queue to be parsed reaches the batch threshold, or the time interval since the last parsing exceeds the timed threshold.

6. The method for fast edge insertion in native graph storage according to claim 1, characterized in that: Also includes: Upon receiving an online query request, the edge cache is queried first based on the online query request: the hash index is used to determine whether the edge corresponding to the online query request hits the edge cache; If a match is found and the matched edge record has been parsed, then the edge data corresponding to the edge record is returned directly. If a match is found and the edge record has not been completely resolved, then perform immediate ID resolution on the edge record. If no match is found, the persistent edge array is queried: the corresponding persistent edge is retrieved through the vertex adjacency index and returned; The execution of immediate ID resolution includes: Query the vertex ID mapping table to obtain the internal vertex ID of the corresponding vertex, fill the internal vertex ID back into the edge record, update the status mark of the edge record to be resolved, and then return the edge data corresponding to the edge record.

7. The method for fast edge insertion in native graph storage according to claim 1, characterized in that: Also includes: Receive a vertex adjacent edge query request, the vertex adjacent edge query request carries the vertex external identifier and indicates whether the query type is out-edge query or in-edge query; The external identifier of the vertex is parsed into an internal vertex ID, and the corresponding vertex record is located based on the internal vertex ID; Obtain the edges associated with the vertex using two separate methods: The first approach involves retrieving persistent edges from the persistent edge array using the adjacency index. The second approach involves retrieving incompletely migrated edge records from the edge cache using the auxiliary index. Specifically, when the query type is an outbound edge query, the source vertex's external identifier is used as the retrieval key in the auxiliary index; when the query type is an inbound edge query, the destination vertex's external identifier is used as the retrieval key in the auxiliary index. For the retrieved incompletely parsed edge records, immediate ID resolution is triggered: the vertex ID mapping table is queried to obtain the corresponding vertex's internal vertex ID, which is then backfilled into the corresponding edge record, and the status marker of the corresponding edge record is updated to "resolved." The edges obtained from the two paths will be merged and returned.

8. The method for fast edge insertion in native graph storage according to claim 1, characterized in that: Once the WAL log buffer is flushed to disk, the corresponding edge record is considered to have reached a crash-safe state. This crash-safe state does not depend on the completion of vertex ID parsing or the migration of edge records into the persistent edge array.

9. The method for fast edge insertion in native graph storage according to claim 4, characterized in that: It also includes system crash recovery steps, including: Starting from the most recent checkpoint, the log records in the WAL are replayed sequentially; For log records that are replayed as edge insertion records and are not covered by the checkpoint, the undetermined edges are reconstructed based on the undetermined edge records written in the form of vertex external identifiers. The reconstructed undetermined edges are restored to the edge cache, and the hash index and the parsing queue are restored. For log records that are replayed as parsed completed records and are not covered by the checkpoint, confirm that the corresponding edge has been persisted and remove the corresponding edge from the parsing queue to be recovered; Restart the background asynchronous parsing thread to continue processing the undetermined edges in the restored parsing queue, so as to complete the vertex ID parsing and migration to the persistent edge array; wherein, the migration write performs idempotency checks with edge identifiers, edges that have been written to the persistent edge array are skipped, and only the migration persistence is completed for edges that have not yet been written. After the recovery is complete, the hash index of the edge cache will be rebuilt to a consistent state.

10. The method for fast edge insertion in native graph storage according to claim 1, characterized in that: It also includes a stratified back pressure control step, including: Monitor the memory usage of the edge records to be parsed in the edge cache; When the memory usage reaches a soft threshold, soft backpressure control is executed. The soft backpressure control includes: reducing the response priority of online insertion requests, returning a cache pressure reminder to the application layer, and increasing the parsing frequency of the background asynchronous parsing thread. When the memory usage exceeds the hard threshold, before adding the reference of the pending edge record to the parsing queue in the online insertion path, synchronous wait control is executed: if the background asynchronous parsing thread is running, the current insertion thread is blocked until the current batch parsing is completed and the cache space of the edge cache is released; if the background asynchronous parsing thread is idle, an emergency batch parsing is triggered immediately. When the memory usage falls below the soft threshold, the normal asynchronous insertion mode is restored.

11. The maximum capacity of the side cache is dynamically determined at system startup based on a certain proportion of available physical memory, or an absolute value is specified in the configuration file.