A document database auditing method and system

By receiving user audit requests from the document database, storing configuration information in the system table, and using memory buffers and double buffers for audit log persistence, the problem of incomplete auditing of read and write operations and complex configuration in existing technologies is solved, resulting in richer audit information and improved performance.

CN117520308BActive Publication Date: 2026-02-10CHINA TELECOM CLOUD TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202311568951.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-11-23
Publication Date
2026-02-10
Estimated Expiration
2043-11-23

AI Technical Summary

Technical Problem

Existing document databases fail to record detailed information such as the total time spent on requests and the number of documents accessed during read and write operation audits. Furthermore, the audit rules and parameter configurations are inconvenient, and the configuration process is complex and prone to errors.

Method used

By receiving user audit requests, configuration information is sent and stored in the system table of the document database. Nodes synchronize configuration information and use a shared lock and double buffer mechanism in the memory buffer to copy and persist audit logs. Audit information is recorded after the request is executed, and the configuration information is stored in the database tables of the document database itself.

Benefits of technology

It simplifies the configuration process, ensures configuration consistency and durability, enriches audit information, improves database performance, avoids configuration loss and operational errors, and significantly improves database throughput and stability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117520308B_ABST
    Figure CN117520308B_ABST
Patent Text Reader

Abstract

The present application relates to cloud database service technical field, provide a kind of document database auditing method and system, comprising: receiving user audit request, audit request includes configuration information and audit rule;Configuration information is sent and stored to the system table of document database by network call, and the multiple nodes in document database are obtained by system table synchronization The configuration information;Node is audited according to audit rule after synchronization configuration information, and audit result is filled as audit log;Based on the shared lock of memory buffer area, audit log is copied to the writable slot in content buffer area;Through the background thread different from the node in auditing, audit log is persisted to hard disk, to complete document database audit.The present application can obtain more abundant audit information, and the double mechanism of periodic triggering and buffer area usage threshold triggering makes the size of buffer area more controllable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of cloud database service technology, and in particular to a document database auditing method and system. Background Technology

[0002] Currently used distributed document databases support relatively comprehensive auditing functions, including flexible audit rule configuration, support for multiple output methods such as console, syslog, BSON file, and JSON file, and support for auditing DDL, replica sets and sharded clusters, authentication operations, and read and write operations.

[0003] However, the aforementioned document database does not adequately audit read and write operations. Existing technologies record read and write operations during permission checks, but this recording occurs before the request is executed. Therefore, it cannot record detailed information such as the total request time or the number of documents accessed, and this information cannot be ultimately reflected in the audit log.

[0004] Furthermore, the audit rules and parameter configuration are not convenient enough. Current technology uses configuration files and commands executed by connecting to the database node for setup. If configuration is used, a node restart is required for the changes to take effect; if commands are executed by connecting to the node, configuration will be lost after a node failure and restart. Additionally, both methods require operation on each database node. A typical MongoDB cluster has multiple mongos, configserver, and mongod nodes, making the configuration process complex and prone to errors. Summary of the Invention

[0005] The present invention aims to at least solve one of the technical problems existing in related technologies. To this end, the present invention provides a document database auditing method and system.

[0006] This invention provides a document database auditing method, comprising:

[0007] S1: Receive user audit request, the audit request including configuration information and audit rules;

[0008] S2: The configuration information is sent and stored in the system table of the document database via network call, and multiple nodes in the document database synchronously obtain the configuration information from the system table;

[0009] S3: After synchronizing the configuration information, the node performs an audit according to the audit rules and fills the audit results into the audit log;

[0010] S4: Using a shared lock based on a memory buffer, copy the audit log to a writable slot in the content buffer;

[0011] S5: The audit logs are persisted to disk through a background thread in the node that is different from the one used for auditing, in order to complete the document database audit.

[0012] According to a document database auditing method provided by the present invention, the system table in step S2 is the config.audit_settings table.

[0013] According to a document database auditing method provided by the present invention, in step S2, the types of nodes in the document database include:

[0014] The mongos node is a sharded cluster node;

[0015] The mongod node is a replica set node.

[0016] According to the document database auditing method provided by the present invention, the audit log in step S3 is in JSON format.

[0017] According to a document database auditing method provided by the present invention, step S4 further includes:

[0018] S41: Acquire the shared lock for the content buffer;

[0019] S42: Based on the size of the audit log, obtain the writable slot in the memory buffer through atomic operations;

[0020] S43: Copy the audit log to the writable slot;

[0021] S44: Release the shared lock on the content buffer.

[0022] According to a document database auditing method provided by the present invention, step S5 further includes:

[0023] S51: Acquire the mutex lock for the memory buffer that needs to be persisted;

[0024] S52: Swap pointers and swap roles between the memory buffer that needs to be persisted and the empty buffer;

[0025] S53: Release the mutex lock on the memory buffer that needs to be persisted;

[0026] S54: Batch persist the contents of the audit logs in the memory buffer that need to be persisted to the log file on the hard disk.

[0027] According to the document database auditing method provided by the present invention, the persistence triggering condition in step S5 is:

[0028] The memory buffer usage rate is triggered when it reaches a preset threshold.

[0029] It is triggered periodically within a given time period.

[0030] The present invention also provides a document database auditing system, comprising:

[0031] Configuration synchronization module: used to receive user audit requests, and also used to send and store configuration information to the system table of the document database, and synchronize the configuration information of multiple nodes in the document database by the system table;

[0032] Audit execution module: Used to perform audits according to audit rules and populate the audit results into the audit log;

[0033] Log copy module: used to copy the audit logs obtained by the audit execution module to the writable slots in the content buffer;

[0034] Log persistence module: Used to persist the audit logs to disk through a background thread in the node that is different from the auditing thread.

[0035] The present invention also provides a document database auditing device, comprising:

[0036] A memory and at least one processor, wherein the memory stores instructions;

[0037] At least one of the processors invokes the instructions in the memory to cause the document database auditing device to perform a document database auditing method as described in any of the preceding claims.

[0038] The present invention also provides a computer-readable storage medium storing instructions that, when executed by a processor, implement a document database auditing method as described in any of the preceding claims.

[0039] This invention provides a document database auditing method, system, device, and storage medium. Firstly, it simplifies the configuration process by directly writing the configuration to the system table and automatically synchronizing it in the background, thus simplifying the process and ensuring configuration consistency and durability. Secondly, it provides richer audit information by placing the auditing process for read and write operations after the request is completed, allowing the recording of key information such as request time, number of indexes scanned, and number of documents scanned in the audit log. Thirdly, it offers significant performance improvements through lock-free buffers, dual buffer mechanisms, and optimized audit log generation logic, ensuring that database throughput does not decrease significantly after enabling auditing, achieving a significant performance improvement compared to existing technologies. Finally, it is more stable and controllable through a dual mechanism of fixed buffer size, periodic triggering, and buffer usage threshold triggering, making the buffer size more controllable and the memory usage of database nodes more manageable.

[0040] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0041] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0042] Figure 1 This is a flowchart of a document database auditing method provided in an embodiment of the present invention;

[0043] Figure 2 This is a schematic diagram of the structure of a document database auditing system provided in an embodiment of the present invention.

[0044] Figure label:

[0045] 100. Configuration synchronization module; 200. Audit execution module; 300. Log copy module; 400. Log persistence module. Detailed Implementation

[0046] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this 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 this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention. The following embodiments are used to illustrate this invention but should not be used to limit the scope of this invention.

[0047] In the description of the embodiments of the present invention, it should be noted that the terms "center," "longitudinal," "lateral," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing the embodiments of the present invention and 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 embodiments of the present invention. In addition, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.

[0048] In the description of the embodiments of the present invention, it should be noted that, unless otherwise explicitly specified and limited, the terms "connected" and "linked" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium. Those skilled in the art can understand the specific meaning of the above terms in the embodiments of the present invention based on the specific circumstances.

[0049] In embodiments of the present invention, unless otherwise explicitly specified and limited, "above" or "below" the second feature can mean that the first feature is in direct contact with the second feature, or that the first feature is in indirect contact with the second feature through an intermediate medium. Furthermore, "above," "on top of," and "over" the second feature can mean that the first feature is directly above or diagonally above the second feature, or simply that the first feature is at a higher horizontal level than the second feature. "Below," "below," and "under" the second feature can mean that the first feature is directly below or diagonally below the second feature, or simply that the first feature is at a lower horizontal level than the second feature.

[0050] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0051] To better understand this invention, the following explanations are provided for the technical terms used in this invention.

[0052] JSON (JavaScript Object Notation) is a lightweight data-interchange format that uses a language-independent text format to store and represent data. Its concise and clear hierarchical structure makes JSON an ideal language for data exchange.

[0053] BSON (Binary JSON): A binary storage format based on JSON extensions. It is primarily used as a data storage and network transmission format in MongoDB databases and can represent simple data structures, arrays, and various data types in MongoDB.

[0054] MongoDB: A distributed document database that uses BSON as its storage and network transmission format. It supports very flexible data structures and a very rich query language.

[0055] Mongos: The access layer node in the MongoDB architecture, which can also be considered a proxy node. Mongos directly provides database services to the outside world, shielding users from the details of the underlying distributed architecture.

[0056] Mongod: The storage layer node in the MongoDB architecture. It has data storage capabilities and also provides external database services. It can provide services directly to users or provide services to external users through the mongos proxy.

[0057] Config server: In a MongoDB cluster architecture, this is a node that stores configuration information. It is typically a replica set of three mongod nodes and mainly stores information such as sharded table configurations, routing, and data balancing strategies.

[0058] Shard server: A node in the MongoDB cluster architecture that stores user database table data. A MongoDB cluster may contain one or more shards, and each shard is generally composed of 3 shard server (mongod) nodes.

[0059] MongoDB Replica Set: A MongoDB architecture that typically consists of three mongod nodes forming a highly available architecture that directly provides services to the outside world. Horizontal scaling to expand capacity is not possible under a replica set architecture.

[0060] MongoDB sharded cluster: A MongoDB architecture typically consists of multiple mongos nodes, multiple shardserver replica sets, and one config server replica set. The mongos nodes provide database services and forward requests to the corresponding shard servers for processing based on routing information. The config server provides configuration storage and synchronization functions. The shard servers provide data storage and read / write request processing functions. The cluster architecture has good horizontal scaling capabilities.

[0061] Database auditing: A database security technology that focuses on security time and is based on comprehensive and precise auditing. It records database activities in real time and helps users generate compliance reports and trace the root cause of incidents by recording and analyzing user access behavior to the database.

[0062] DDL (Data Description Language): Used to define the various levels of the database schema, including logical structure, physical characteristics, mapping of logical data to physical data, and access rules.

[0063] The following is combined with Figures 1 to 2 Embodiments of the present invention are described.

[0064] This invention provides a document database auditing method, comprising:

[0065] S1: Receive user audit request, the audit request including configuration information and audit rules;

[0066] Furthermore, in this stage, the user first selects the corresponding document database instance on the console page, then enables or disables the auditing function, and can also configure the corresponding auditing rules.

[0067] S2: The configuration information is sent and stored in the system table of the document database via network call, and multiple nodes in the document database synchronously obtain the configuration information from the system table;

[0068] Furthermore, the configuration made in step S1 will be sent to the document database via network calls and stored in the config.audit_settings table of the document database.

[0069] In step S2, the system table is the config.audit_settings table.

[0070] In step S2, the types of nodes in the document database include:

[0071] The mongos node is a sharded cluster node;

[0072] The mongod node is a replica set node.

[0073] Furthermore, the audit configuration information is then synchronized to each node of the document database. For sharded cluster instances, this means that each mongos node synchronizes to the audit configuration information; for replica set instances, this means that each mongod node synchronizes to the audit configuration information.

[0074] S3: After synchronizing the configuration information, the node performs an audit according to the audit rules and fills the audit results into the audit log;

[0075] The audit log in step S3 is in JSON format.

[0076] Furthermore, after each node synchronizes to the configuration, it begins to audit the user's operation commands. The command execution thread fills the command execution result information into the audit log in JSON format and records the result in the local log.

[0077] This invention also uses hook functions added to the MongoDB kernel code to record operation commands and execution results. This invention places the audit position of read and write operations after the command execution is completed. In this way, the audit log content of this invention can include information such as the execution time of the request, the number of indexes scanned and the number of documents.

[0078] User operations on the MongoDB database are processed through hook functions to collect information, which then generate audit logs in JSON format and insert them into a fixed-size memory buffer. When the usage rate of the memory buffer reaches a set threshold, or when the time since the last disk flush reaches a set threshold, the contents of the memory buffer are written to a log file on the disk for persistent storage in subsequent steps.

[0079] S4: Using a shared lock based on a memory buffer, copy the audit log to a writable slot in the content buffer;

[0080] Step S4 further includes:

[0081] S41: Acquire the shared lock for the content buffer;

[0082] S42: Based on the size of the audit log, obtain the writable slot in the memory buffer through atomic operations;

[0083] S43: Copy the audit log to the writable slot;

[0084] S44: Release the shared lock on the content buffer.

[0085] Further, the process in this stage is as follows: acquire the shared lock of the memory buffer; based on the current size of the audit log, acquire the writable slot in the memory buffer through atomic operations; after successfully acquiring the slot, copy the contents of the audit log to the slot in the memory buffer; release the shared lock of the memory buffer; if the memory buffer utilization rate exceeds 90%, notify the background disk flushing thread to perform a dual buffer switch through a condition variable.

[0086] The execution process requires holding a shared lock on the memory buffer. Because it is a shared lock, multiple instruction execution threads can complete this operation concurrently. After this step is completed, the task of the instruction execution thread ends and the execution result can be returned to the client. The operation of persisting the audit log to the hard disk will be completed asynchronously by a dedicated background thread.

[0087] S5: The audit logs are persisted to disk through a background thread in the node that is different from the one used for auditing, in order to complete the document database audit.

[0088] Step S5 further includes:

[0089] S51: Acquire the mutex lock for the memory buffer that needs to be persisted;

[0090] S52: Swap pointers and swap roles between the memory buffer that needs to be persisted and the empty buffer;

[0091] S53: Release the mutex lock on the memory buffer that needs to be persisted;

[0092] S54: Batch persist the contents of the audit logs in the memory buffer that need to be persisted to the log file on the hard disk.

[0093] The persistence trigger condition in step S5 is as follows:

[0094] The memory buffer usage rate is triggered when it reaches a preset threshold.

[0095] It is triggered periodically within a given time period.

[0096] Each node will start a background thread to perform the operation of persisting audit logs to disk. The specific operation steps are as follows: periodically (every 100ms) and triggered by the current buffer usage threshold to perform persistence operation; acquire the mutex lock of the memory buffer to be persisted; swap the pointers of the memory buffer to be persisted and an unused blank buffer, and swap their roles; since it is only a pointer swap, the execution time is very short; release the mutex lock of the memory buffer to be persisted; in the lock-free state, batch persist the contents of the memory buffer to be persisted to the log file on disk.

[0097] The present invention also provides a document database auditing system, comprising:

[0098] Configuration synchronization module 100: used to receive user audit requests, and also used to send and store configuration information to the system table of the document database, and synchronize the configuration information of multiple nodes in the document database by the system table;

[0099] Audit execution module 200: Used to perform audits according to audit rules and populate the audit results into the audit log;

[0100] Log copy module 300: used to copy the audit logs obtained by the audit execution module 200 to a writable slot in the content buffer;

[0101] Log persistence module 400: Used to persist the audit logs to disk through a background thread in the node that is different from the auditing thread.

[0102] The present invention also provides a document database auditing device, comprising:

[0103] A memory and at least one processor, wherein the memory stores instructions;

[0104] At least one of the processors invokes the instructions in the memory to cause the document database auditing device to perform a document database auditing method as described in any of the preceding claims.

[0105] In some embodiments, the device may vary considerably due to differences in configuration or performance, and may include one or more processors, for example, one or more processors and memory, and one or more storage media for storing applications or data, such as one or more mass storage devices. The memory and storage media may be transient or persistent storage. The program stored in the storage media may include one or more modules, each module including a series of instructions for operating on the device. Furthermore, the processor may be configured to communicate with the storage media and execute a series of instructions stored in the storage media on the device.

[0106] The device may also include one or more power supplies, one or more wired or wireless network interfaces, one or more input / output interfaces, and / or one or more operating systems, such as Windows Server, MacOSX, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that the device structure shown above does not constitute a limitation on the device, and may include more or fewer components than illustrated, or combine certain components, or have different component arrangements.

[0107] The present invention also provides a computer-readable storage medium storing instructions that, when executed by a processor, implement a document database auditing method as described in any of the preceding claims.

[0108] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0109] If the integrated unit is implemented as a software functional unit and sold or distributed as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0110] The document database auditing method and system provided by this invention have the following advantages:

[0111] To achieve concurrent writing to the memory buffer, existing technologies acquire a mutex lock before writing to the memory buffer after each thread generates an audit log. This prevents true concurrency in modifying the memory buffer, resulting in poor performance. This invention acquires the memory buffer slot through atomic operations after each thread generates an audit log, and then multiple threads concurrently write to the memory buffer without interfering with each other. This lock-free approach avoids thread blocking and thus improves performance.

[0112] By employing a double-buffer mechanism, the threads writing to the buffer and reading from the buffer to flush to disk do not interfere with each other. Existing technologies require the background flushing thread to acquire a mutex lock, then read the contents of the buffer and persist them to disk. During this process, the thread writing to the buffer is blocked, resulting in poor performance. This invention uses a double-buffer mechanism to swap pointers between the two buffers when flushing is needed. This operation is performed under the protection of a read-write lock. Because pointer swapping is highly efficient, the above operation can be completed quickly. Afterward, the thread writing to the buffer can concurrently write audit logs to the new buffer, while the contents of the previous buffer are persisted to disk by the background thread. The two operate independently, effectively avoiding blocking of the thread writing to the buffer, thereby improving the read / write efficiency of the buffer.

[0113] By employing a dual mechanism of timed periodic triggering and buffer usage threshold triggering, the size of the memory buffer is ensured to be controllable. Existing technologies use timed periodic triggering to persist the contents of the buffer to disk, then clear the buffer before continuing to write. In this approach, the buffer size fluctuates with the amount of requests within the period, making it uncontrollable. In this invention, the buffer size is fixed, and in addition to timed periodic triggering, persistence is proactively initiated via event notification when the buffer usage reaches 90%. This method effectively controls the buffer size.

[0114] The existing technology optimizes the audit log generation logic by generating audit logs in BSON format, filtering them according to BSON audit rules, and then converting them into JSON format for output. Both the BSON rule filtering and the BSON-to-JSON conversion operations are very CPU-intensive, ultimately leading to a decrease in overall database throughput. This invention makes two targeted optimizations: First, the audit rule filtering stage is moved forward by performing rule filtering through string matching before generating audit logs, thus avoiding unnecessary audit log generation processes. Second, instead of generating BSON format logs and then converting them to JSON, the final JSON format logs are generated directly from the audit information using string concatenation.

[0115] By employing a dual mechanism of timed periodic triggering and buffer usage threshold triggering, the size of the memory buffer is ensured to be controllable. Existing technologies use a timed periodic triggering mechanism to persist the contents of the buffer to disk, and then clear the buffer before continuing to write. In this way, the size of the buffer changes with the amount of requests within the period and is not controllable. In this invention, the buffer size is fixed, and in addition to timed periodic triggering, persistence is actively performed through event notification when the buffer usage reaches 90%. In this way, the buffer size can be effectively controlled.

[0116] Existing technologies use configuration files and configuration commands to modify memory values ​​for auditing configurations, which are stored and synchronized using the document database's own tables. These methods are very complex to handle scenarios such as node restarts and node additions, and are prone to inconsistencies such as configuration loss. This invention uses a dedicated table for each document database instance to store the configuration and implements a configuration synchronization process in the document database kernel. This simplifies the configuration process and ensures the persistence and consistency of the configuration.

[0117] Existing technologies record audit information for insert, delete, read, and update operations during the permission verification phase, while this invention records audit information only upon completion of read / write commands. This allows the audit information to include key information such as request execution time, the number of index entries and documents scanned by the read / write request, and the number of documents modified and inserted.

[0118] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A document database auditing method, characterized in that, include: S1: Receive user audit request, the audit request including configuration information and audit rules; S2: The configuration information is sent and stored in the system table of the document database via a network call, and multiple nodes in the document database synchronously obtain the configuration information from the system table; wherein, the system table is the config.audit_settings table; S3: After synchronizing the configuration information, the node performs an audit according to the audit rules and fills the audit results into the audit log; S4: Using a shared lock based on a memory buffer, copy the audit log to a writable slot in the content buffer; Step S4 further includes: S41: acquiring a shared lock on the content buffer; S42: acquiring a writable slot in the memory buffer through an atomic operation based on the size of the audit log; S43: copying the audit log to the writable slot; S44: releasing the shared lock on the content buffer. S5: The audit logs are persisted to the hard disk through a background thread in the node that is different from the auditing thread, in order to complete the document database audit; Step S5 further includes: S51: acquiring the mutex lock of the memory buffer that needs to be persisted; S52: swapping pointers and roles of the memory buffer that needs to be persisted and the empty buffer; S53: releasing the mutex lock of the memory buffer that needs to be persisted; S54: batch persisting the contents of the audit log in the memory buffer that needs to be persisted to the log file on the hard disk.

2. The document database auditing method according to claim 1, characterized in that, In step S2, the types of nodes in the document database include: The mongos node is a sharded cluster node; The mongod node is a replica set node.

3. The document database auditing method according to claim 1, characterized in that, The audit log mentioned in step S3 is in JSON format.

4. The document database auditing method according to claim 1, characterized in that, The persistence trigger condition in step S5 is: The memory buffer usage rate is triggered when it reaches a preset threshold. It is triggered periodically within a given time period.

5. A document database auditing system, characterized in that, include: Configuration synchronization module: used to receive user audit requests, and also used to send and store configuration information to the system table of the document database, and synchronize the configuration information of multiple nodes in the document database by the system table; the system table is the config.audit_settings table; Audit execution module: Used to perform audits according to audit rules and populate the audit results into the audit log; Log copy module: used to copy the audit logs obtained by the audit execution module to the writable slots in the content buffer; The log copy module is further configured to: acquire a shared lock on the content buffer; acquire a writable slot in the memory buffer through an atomic operation based on the size of the audit log; copy the audit log to the writable slot; and release the shared lock on the content buffer. Log persistence module: used to persist the audit logs to disk through a background thread in the node that is different from the auditing thread; The log persistence module is further used to: acquire the mutex lock of the memory buffer that needs to be persisted; swap the pointers and roles of the memory buffer that needs to be persisted and the empty buffer; and release the mutex lock of the memory buffer that needs to be persisted. The audit logs in the memory buffer that need to be persisted are persisted in batches to log files on the hard disk.

6. A document database auditing device, characterized in that, include: A memory and at least one processor, wherein the memory stores instructions; At least one of the processors invokes the instructions in the memory to cause the document database auditing device to perform a document database auditing method as described in any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed by a processor, implement a document database auditing method as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Database service method and system

    CN113515499A

  • Database management

    US20200117730A1