Database file operating system and method, terminal equipment and storage medium
By introducing an intermediate layer into the SQLite database to split the database file and bind virtual database handles and CPU cores, the problem of unique database handles is solved, multi-core parallel operation is realized, and the efficiency and performance of database file operation are improved.
Patent Information
- Application Number
- CN202410996980.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-24
- Publication Date
- 2024-11-15
AI Technical Summary
In a multi-core CPU environment, the SQLite database handle is unique, which prevents multiple cores from operating on the database file simultaneously. Furthermore, context switching between multiple cores consumes CPU performance and reduces database performance.
An intermediate layer is introduced to split the database file, generating multiple data information files. These files are then bound to different application processes and CPU cores via virtual database handles, enabling parallel operation of the multiple data information files.
It improves the efficiency of database file operations, avoids CPU performance loss caused by multi-core CPUs handling multi-process tasks, and enhances database performance.
Smart Images

Figure CN118964370A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to an operating system, method, terminal device and storage medium for a database file. Background Art
[0002] SQLite is a lightweight database, a relational database management system that complies with ACID, and is contained in a relatively small C library. ACID refers to the four characteristics that a database management system (DBMS) must have to ensure that transactions are correct and reliable when writing or updating data: atomicity (or indivisibility), consistency (consistency), isolation (also known as independence), and durability (durability). It has been widely used in many embedded products. SQLite occupies very low resources. In embedded devices, only a few hundred KB of memory may be enough.
[0003] When a process executes an SQL statement, the user state needs to call the database, and the database is operated through multiple CPU cores in the kernel state, such as Figure 1 As shown in the figure, in user state, users need to call the SQLite3 library to operate the DB file. In kernel state, the Linux system decomposes the task to multiple CPU cores 1 for processing under a multi-core CPU. At this time, it is in a high concurrency state. Under high concurrency, the kernel schedules multiple CPU cores to complete specific task execution, but there are the following problems:
[0004] (1) The database handle is unique, and multiple cores cannot operate the database DB file at the same time;
[0005] (2) Although multiple CPU cores increase processing power, context switching between multiple cores consumes CPU performance, resulting in the inability to efficiently complete CPU instructions, thereby reducing the performance of the multi-core database. Summary of the invention
[0006] In view of this, the embodiments of the present application provide an operating system, method, terminal device and storage medium for a database file, which can effectively solve the problem that the database handle is unique and multiple cores cannot operate the database file at the same time.
[0007] In a first aspect, an embodiment of the present application provides an operating system for a database file, including an intermediate layer and a database;
[0008] The database includes a plurality of database files, each of which includes a plurality of data information;
[0009] The intermediate layer is used to retrieve the corresponding database file according to the operation command, and split the database file to obtain multiple data information files; and generate a corresponding virtual database handle and data information process according to the real database handle of each data information file, and bind all the virtual database handles to different application processes and bind all the data information processes to different CPU cores;
[0010] When each of the application processes executes the virtual database handle, the corresponding CPU core is obtained through the virtual database handle, so that the CPU core executes the bound data information process to operate the corresponding data information file.
[0011] In some embodiments, the database files in the database are of at least two types, and the middle layer uses different splitting strategies to split the different types of database files, and the multiple data information files obtained by splitting are independent of each other.
[0012] In some embodiments, the splitting of different types of data files using different splitting strategies includes:
[0013] When the type of the database file is a table file, splitting it according to the table to obtain a plurality of the data information files;
[0014] When the type of the database file is a log information file, it is split according to information attributes to obtain a plurality of the data information files.
[0015] In some embodiments, when the type of the database file is a table file, the database file includes a terminal information table, a server information table and an encryption key table, and the corresponding data information files are terminal information files, server information files and encryption key files.
[0016] In some embodiments, when the type of the database file is a log information file, the database file includes alarm information, content information and log operation information, and the corresponding data information files are alarm files, content files and log operation files.
[0017] In a second aspect, an embodiment of the present application provides a method for operating a database file, which is applicable to the operating system of the above-mentioned database file; the operating method includes:
[0018] Retrieving the database file according to the operation command, and splitting the database file in the middle layer to obtain a plurality of the data information files;
[0019] Generate a corresponding virtual database handle and data information process according to the real database handle of each of the data information files;
[0020] Binding all the virtual database handles to different application processes and binding all the data information processes to different CPU cores;
[0021] When each of the application processes executes the virtual database handle, the corresponding CPU core is obtained through the virtual database handle, so that the CPU core executes the bound data information process to operate the corresponding data information file.
[0022] In some embodiments, obtaining the corresponding CPU core through the virtual database handle includes:
[0023] Determining the data information process corresponding to the real database according to the real database handle corresponding to the virtual database handle;
[0024] Determining the CPU core corresponding to the virtual database handle according to the CPU core bound to the data information process;
[0025] Among them, the CPU core bound to each data information process is different.
[0026] In some embodiments, it also includes: binding the data information process corresponding to each real database handle to a different CPU core according to the current usage rate of all CPU cores.
[0027] In a third aspect, an embodiment of the present application provides a terminal device, the terminal device comprising a processor and a memory, the memory storing a computer program, and the processor being used to execute the computer program to implement the above-mentioned database file operation method.
[0028] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium storing a computer program, which, when executed on a processor, implements the above-mentioned method for operating a database file.
[0029] The embodiments of the present application have the following beneficial effects:
[0030] The application proposes an operating system for a database file. By adding an intermediate layer, when operating a database file in a database, the database file is retrieved based on the intermediate layer connected to the database, and the database file is split into multiple data information files. A different virtual database handle is generated according to each data information file, so that the operated database handle is no longer unique; then different data information files are operated through different CPU cores, so that the database files can be operated simultaneously, thereby improving the efficiency of database file operations. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0032] Figure 1 A schematic diagram of the operation flow of a database file in the prior art is shown;
[0033] Figure 2 A schematic diagram showing an application scenario of an operating system for a database file in an embodiment of the present application is shown;
[0034] Figure 3 A schematic diagram showing a flow chart of a method for operating a database file in an embodiment of the present application;
[0035] Figure 4 A schematic diagram of a process for obtaining a CPU core corresponding to a virtual database handle in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0036] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments.
[0037] The components of the embodiments of the present application generally described and shown in the drawings herein may be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0038] Hereinafter, the terms "including", "having" and their cognates that can be used in various embodiments of the present application are intended only to indicate specific features, numbers, steps, operations, elements, components or a combination of the foregoing items, and should not be understood as first excluding the existence of one or more other features, numbers, steps, operations, elements, components or a combination of the foregoing items or increasing the possibility of one or more features, numbers, steps, operations, elements, components or a combination of the foregoing items. In addition, the terms "first", "second", "third" and the like are only used to distinguish descriptions and cannot be understood as indicating or implying relative importance.
[0039] Unless otherwise defined, all terms (including technical terms and scientific terms) used herein have the same meanings as those generally understood by those skilled in the art to which the various embodiments of the present application belong. The terms (such as those defined in generally used dictionaries) will be interpreted as having the same meanings as the contextual meanings in the relevant technical field and will not be interpreted as having idealized meanings or overly formal meanings unless clearly defined in the various embodiments of the present application.
[0040] In conjunction with the accompanying drawings, some embodiments of the present application are described in detail below. In the absence of conflict, the following embodiments and features in the embodiments can be combined with each other.
[0041] When a database file contains multiple tables, and multiple different application processes read / write data to the same database (DataBase, referred to as DB) file, the next application process will need to wait for the current application process to complete the database operation and release the handle before it can operate. The switching of process tasks depends to a certain extent on the scheduling strategy of the Linux system kernel, which may cause the application to waste a long time waiting for the database handle. During this waiting process, the module process will consume time waiting for the acquisition of the database handle. The database operation speed and performance are affected by the device IO performance. On a system with high CPU performance and low file IO read and write performance, frequent database operations will cause the program process to be often in a waiting state. To this end, the present application proposes to introduce an intermediate layer in the user state to process the database, that is, the intermediate layer parses the multi-table DB file and disassembles it into multiple single-table DB files to support the simultaneous operation of multiple data tables; and each database handle is bound to a single CPU core, which can avoid the CPU performance loss caused by the multi-core CPU processing multi-process tasks in the kernel state, thereby achieving the purpose of improving database performance.
[0042] Based on the above technical concept, the present application proposes an operating system, method, terminal device and storage medium for a database file. The operating system for the database file is described below in conjunction with some specific embodiments.
[0043] Figure 2 A schematic diagram of an application scenario of an operating system for a database file in an embodiment of the present application is shown. Exemplarily, the operating system for the database file includes an intermediate layer and a database.
[0044] In some embodiments, the database includes multiple database files, each database file includes multiple data information; the database includes at least two different types of database files, namely, table files and log files. When the type of the database file is a table file, the multiple data information included in the database file is multiple table information, and the table information includes a terminal information table, a server information table, and an encryption key table, etc.; when the database file includes a log file, the multiple data information included in the database file is log information.
[0045] In some embodiments, the middle layer is used to call the corresponding database file according to the operation command, and split the database file into multiple data information files; and generate a corresponding virtual database handle and data information process according to the real database handle of each data information file, and transmit all virtual database handles to different application processes.
[0046] In some embodiments, the present application adopts different splitting strategies to split different types of database files: when the type of the database file is a table file, it is split according to the table to obtain multiple data information files; the multiple data information included in the database file are terminal information tables, server information tables and encryption key tables, and the corresponding multiple data information files obtained by the splitting are terminal information files, server information files and encryption key files; wherein the terminal information files, server information files and encryption key files are independent of each other; when the type of the database file is a log information file, it is split according to information attributes to obtain multiple data information files; the multiple data information included in the database file are alarm information, content information and log operation information, and the corresponding multiple data information files obtained by the splitting are alarm files, content files and log operation files; wherein the alarm files, content files and log operation files are independent of each other.
[0047] In some embodiments, the operating system executes an operation command, firstly calls the corresponding database file according to the operation command, and splits the database file to obtain multiple data information files; then generates a corresponding virtual database handle and data information process according to the real database handle of each data information file, and binds all virtual database handles to different application processes and all data information processes to different CPU cores; finally, executes the virtual database handle through each application process to operate the corresponding data information file. Wherein, when executing the virtual database handle through each application process, first determine the data information process of the real database according to the real database handle corresponding to the virtual database handle; then determine the CPU core corresponding to the virtual database handle according to the CPU core bound to the data information process; finally, the CPU core executes the bound data information process to operate the corresponding data information file.
[0048] Specifically, when the operating system executes an operation command, it first retrieves the database file according to the operation command, and splits the data information 1, data information 2 and data information 3 included in the database file to obtain data information file 1, data information file 2 and data information file 3; then, according to the real database handle 1 of the data information file 1, a corresponding virtual database handle 1 and data information process 1 are generated, and the virtual database handle 1 is bound to the application process A, and the data information process A is bound to the CPU core 1; according to the real database handle 2 of the data information file 2, a corresponding virtual database handle 2 and data information process 2 are generated, and the virtual database handle 2 is bound to the application process B, and the data information process 2 is bound to the CPU core 2; according to the data information file The real database handle 3 of application 3 generates the corresponding virtual database handle 3 and data process 3, and binds the virtual database handle 3 to application process C and the data process 3 to CPU core 3; finally, when application process A executes the virtual database handle 1, it executes the data process 1 according to the bound CPU core 1 to operate the data file 1 corresponding to the real database handle 1; when application process B executes the virtual database handle 2, it executes the data process 2 according to the bound CPU core 2 to operate the data file 2 corresponding to the real database handle 2; when application process C executes the virtual database handle 3, it executes the data process 3 according to the bound CPU core 3 to operate the data file 3 corresponding to the real database handle 3.
[0049] It should be noted that the virtual database handle is an abstraction of the real database handle. For the middle layer, the virtual database handle can be used to distinguish the identification of each application process. Each virtual database handle is controlled by an independent application process, and the real database handle is controlled by an independent data information process. Based on the processing of the middle layer, the purpose of operating the database simultaneously can be achieved through multiple CPU cores.
[0050] This application improves database performance by supporting simultaneous operations through separated multiple data information files; at the same time, the real database handle of each data information file is bound to a single CPU core, reducing the CPU performance loss caused by the multi-core CPU processing multi-process tasks in the kernel state, so as to achieve the purpose of improving database performance.
[0051] Figure 3 A schematic flow chart of a method for operating a database file in an embodiment of the present application is shown. Exemplarily, the method includes:
[0052] S100, calling a database file according to an operation command, and splitting the database file in the middle layer to obtain multiple data information files.
[0053] In some embodiments, the operation command is first analyzed to obtain an analysis result, and a database file corresponding to the analysis result is retrieved through an intermediate layer; then, the database file is split in the intermediate layer to obtain multiple data information files; specifically, when the operating system executes the operation command, the database file to be retrieved is analyzed according to the operation command, and then the database file is retrieved through the intermediate layer, and the data information 1, data information 2 and data information 3 included in the data file are split to obtain data information file 1, data information file 2 and data information file 3.
[0054] S200, generating a corresponding virtual database handle and data information process according to the real database handle of each data information file.
[0055] In some embodiments, a corresponding virtual database handle 1 and a data information process 1 are generated based on the real database handle 1 of the data information file 1, a corresponding virtual database handle 2 and a data information process 2 are generated based on the real database handle 2 of the data information file 2, and a corresponding virtual database handle 3 and a data information process 3 are generated based on the real database handle 3 of the data information file 3.
[0056] S300, all virtual database handles are bound to different application processes respectively, and all data information processes are bound to different CPU cores respectively.
[0057] In some embodiments, virtual database handle 1 is bound to application process A, and data information process 1 is bound to CPU core 1; virtual database handle 2 is bound to application process B, and data information process 2 is bound to CPU core 2; virtual database handle 3 is bound to application process C, and data information process 3 is bound to CPU core 3.
[0058] S400, when each application process executes the virtual database handle, the corresponding CPU core is obtained through the virtual database handle.
[0059] In some embodiments, when application process A executes virtual database handle 1, CPU core 1 obtained according to virtual database handle 1 executes data information process 1 to operate data information file 1 corresponding to real database handle 1; when application process B executes virtual database handle 2, CPU core 2 obtained according to virtual database handle 2 executes data information process 2 to operate data information file 2 corresponding to real database handle 2; when application process C executes virtual database handle 3, CPU core 3 obtained according to virtual database handle 3 executes data information process 3 to operate data information file 3 corresponding to real database handle 3.
[0060] In some embodiments, such as Figure 4 As shown, obtaining the corresponding CPU core through the virtual database handle includes:
[0061] S410, determining a data information process corresponding to the real database according to the real database handle corresponding to the virtual database handle;
[0062] S420: Determine the CPU core corresponding to the virtual database handle according to the CPU core bound to the data information process.
[0063] Specifically, first determine the data process 1 according to the real database handle 1 corresponding to the virtual database handle 1, and then determine the data process 1 corresponding to the virtual database handle 1 according to the CPU core 1 bound to the data process 1, so as to operate the data file 1 corresponding to the real database handle 1; first determine the data process 2 according to the real database handle 2 corresponding to the virtual database handle 2, and then determine the data process 2 corresponding to the virtual database handle 2 according to the CPU core 2 bound to the data process 2, so as to operate the data file 2 corresponding to the real database handle 2; first determine the data process 3 according to the real database handle 3 corresponding to the virtual database handle 3, and then determine the data process 3 corresponding to the virtual database handle 3 according to the CPU core 3 bound to the data process 3, so as to operate the data file 3 corresponding to the real database handle 3.
[0064] In some embodiments, each data information process is bound to a different CPU core; specifically, based on the current usage rate of all CPU cores, the data information process corresponding to each real database handle is bound to a different CPU core; that is, the CPU usage rate over a period of time is obtained to determine the system resource usage, and each data information process of the real database handle obtained after control splitting is respectively bound to a different CPU core with a lower load. After binding, when the application process completes the virtual database handle, it will simultaneously process the operation command through the bound CPU core, thereby avoiding the additional CPU resources generated when the CPU core is switched to complete the operation command, i.e., the SQL statement, which in turn causes performance loss of the operating system.
[0065] S500, the CPU core executes the bound data information process to operate the corresponding data information file.
[0066] In some embodiments, when application process A executes virtual database handle 1, it executes data information process 1 according to the bound CPU core 1 to operate data information file 1 corresponding to real database handle 1; when application process B executes virtual database handle 2, it executes data information process 2 according to the bound CPU core 2 to operate data information file 2 corresponding to real database handle 2; when application process C executes virtual database handle 3, it executes data information process 3 according to the bound CPU core 3 to operate data information file 3 corresponding to real database handle 3.
[0067] Since the middle layer is an independent program, when the operation command is completed, the middle layer exits, and the multiple split data information files need to be merged into the original database file.
[0068] Therefore, compared with the prior art, in this application, application process A needs to read / write terminal information, and application process B needs to read / write encryption key information. When the middle layer is not introduced, application process B needs to wait for application process A to complete the read / write operation before it can operate the database. After the introduction of the middle layer, application process A and application process B can operate at the same time. For the application, the efficiency of the background processing of the application in the operating system is improved. In other words, the application process changes from directly obtaining the database handle to obtaining it from the middle layer. The middle layer will return a virtual database handle to the application process, and pass the SQL statement to the middle layer through the virtual database handle. The middle layer will parse the SQL statement and generate a real database handle, and complete the operation through the bound CPU core, and then return the operation result to the application process.
[0069] The present application also provides a terminal device. Exemplarily, the terminal device includes a processor and a memory, wherein the memory stores a computer program, and the processor runs the computer program to enable the terminal device to execute the above-mentioned database file operation method or complete the functions of each module in the above-mentioned data file operating system.
[0070] Among them, the processor can be an integrated circuit chip with signal processing capabilities. The processor can be a general-purpose processor, including a central processing unit (CPU), a graphics processing unit (GPU) and a network processor (NP), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or at least one of other programmable logic devices, discrete gates or transistor logic devices, and discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc., which can implement or execute the disclosed methods, steps and logic block diagrams in the embodiments of the present application.
[0071] The memory may be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc. The memory is used to store a computer program, and the processor may execute the computer program accordingly after receiving an execution instruction.
[0072] The present application also provides a computer-readable storage medium for storing the computer program used in the above-mentioned terminal device. For example, the computer-readable storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0073] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or the flow diagram, and the combination of boxes in the structure diagram and / or the flow diagram, can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0074] In addition, the functional modules or units in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0075] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a smart phone, a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application.
[0076] The above description is only a specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.
Claims
1. An operating system for a database file, characterized in that: Includes middle tier and database; The database includes a plurality of database files, each of which includes a plurality of data information; The middle layer is used to retrieve the corresponding database file according to the operation command, and split the database file into multiple data information files; And generating a corresponding virtual database handle and data information process according to the real database handle of each data information file, and binding all the virtual database handles to different application processes, and binding all the data information processes to different CPU cores; When each of the application processes executes the virtual database handle, the corresponding CPU core is obtained through the virtual database handle, so that the CPU core executes the bound data information process to operate the corresponding data information file.
2. The operating system for database files according to claim 1, characterized in that: The database files in the database are of at least two types, and the middle layer uses different splitting strategies to split the database files of different types, and the multiple data information files obtained by splitting are independent of each other.
3. The operating system for database files according to claim 2, characterized in that: The different splitting strategies are used to split different types of data files, including: When the type of the database file is a table file, splitting it according to the table to obtain a plurality of the data information files; When the type of the database file is a log information file, it is split according to information attributes to obtain a plurality of the data information files.
4. The operating system for database files according to claim 3, characterized in that: When the type of the database file is a table file, the database file includes a terminal information table, a server information table and an encryption key table, and the corresponding data information files are a terminal information file, a server information file and an encryption key file.
5. The operating system for database files according to claim 3, characterized in that: When the type of the database file is a log information file, the database file includes alarm information, content information and log operation information, and the corresponding data information file is an alarm file, a content file and a log operation file.
6. A method for operating a database file, characterized in that: An operating system applicable to the database file according to any one of claims 1 to 5; the operating method comprises: Retrieving the database file according to the operation command, and splitting the database file in the middle layer to obtain a plurality of the data information files; Generate a corresponding virtual database handle and data information process according to the real database handle of each of the data information files; Binding all the virtual database handles to different application processes and binding all the data information processes to different CPU cores; When each of the application processes executes the virtual database handle, the corresponding CPU core is obtained through the virtual database handle, so that the CPU core executes the bound data information process to operate the corresponding data information file.
7. The method for operating a database file according to claim 6, characterized in that: The obtaining the corresponding CPU core through the virtual database handle includes: Determining the data information process corresponding to the real database according to the real database handle corresponding to the virtual database handle; Determining the CPU core corresponding to the virtual database handle according to the CPU core bound to the data information process; Among them, the CPU core bound to each data information process is different.
8. The method for operating a database file according to claim 7, characterized in that: Also includes: According to the current usage rate of all CPU cores, the data information process corresponding to each real database handle is bound to a different CPU core.
9. A terminal device, characterized in that: The terminal device comprises a processor and a memory, the memory stores a computer program, and the processor is used to execute the computer program to implement the database file operation method according to any one of claims 6 to 8.
10. A computer-readable storage medium, characterized in that: It stores a computer program, which, when executed on a processor, implements the method for operating a database file according to any one of claims 6 to 8.
Citation Information
Cited By
Substrate management controller process monitoring method and electronic equipment
CN120743684A
