WO2011097932A1 - 数据库的访问方法、装置及数据库应用系统 - Google Patents

数据库的访问方法、装置及数据库应用系统 Download PDF

Info

Publication number
WO2011097932A1
WO2011097932A1 PCT/CN2010/080435 CN2010080435W WO2011097932A1 WO 2011097932 A1 WO2011097932 A1 WO 2011097932A1 CN 2010080435 W CN2010080435 W CN 2010080435W WO 2011097932 A1 WO2011097932 A1 WO 2011097932A1
Authority
WO
WIPO (PCT)
Prior art keywords
database
shared data
atomic operation
access
atomic
Prior art date
Application number
PCT/CN2010/080435
Other languages
English (en)
French (fr)
Inventor
陈志标
彭勇飞
毛永祥
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP10845602.1A priority Critical patent/EP2500831A4/en
Publication of WO2011097932A1 publication Critical patent/WO2011097932A1/zh
Priority to US13/487,849 priority patent/US20120239634A1/en
Priority to US13/903,724 priority patent/US20130262426A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2365Ensuring data consistency and integrity

Definitions

  • the present invention relates to the field of databases, and in particular, to a method, device and system for accessing a database.
  • the traditional database management system uses the C/S (client/server) access mode, effectively isolating the application and database system, ensuring the robustness of the system; but the C/S access mode generates additional networks.
  • Communication usually TCP/IP
  • TCP/IP Transmission Control Protocol
  • the access and modification of the data itself is in the microsecond level, but the current network latency of the local area network is generally On the millisecond level, even if you access the machine, there is overhead in the processing of the protocol stack and process switching.
  • Embedded access is an efficient way to access, and with the development of in-memory databases, it is increasingly accepted by most people. Embedded access compiles an in-memory database with an application, allowing multiple applications to share a single database instance, which improves the real-time nature of data access.
  • the embedded access method brings efficient access, it also has the following defects: When an application modifies the data of the in-memory database for some reason, it may be abnormally quit, which may result in the modification not being completed (such as a certain One half of the data structure has been modified or some internal mutex resources have not been released, which puts the database in an inconsistent state, which prevents other applications from using the in-memory database again. Summary of the invention
  • the embodiment of the invention provides a database access method, device and system to ensure database consistency.
  • An embodiment of the present invention provides a method for accessing a database, including:
  • the shared data of the database mapped to the address space of the process is accessed by atomic operations provided by the atomic operation interface.
  • the embodiment of the invention provides a database access device, including:
  • a receiving module configured to receive a modify operation request for the shared data of the database, where the shared data of the database is mapped into an address space of the process
  • a decomposition module configured to decompose the modification operation request into a preset number of atomic operation sequences
  • a calling module configured to invoke an atomic operation interface according to an execution order of each atomic operation sequence
  • an atomic access module configured to The atomic operation provided by the atomic operation interface accesses the shared data of the database mapped to the address space of the process.
  • An embodiment of the present invention provides a database application system, including: a database for storing data and the database access device described above; the database access device is configured to access the database.
  • the modification operation of the database is performed by accessing the shared data of the database through atomic operations, and the atomic operation processing is not interrupted by other processes while being performed, and the data can be guaranteed. Consistency improves the protection of shared data in multi-process embedded access databases.
  • FIG. 1 is a flowchart of a method for accessing a database according to an embodiment of the present invention
  • FIG. 2 is a flowchart of a method for accessing a database according to an embodiment of the present invention
  • FIG. 3 is a flowchart of a method for accessing a database according to an embodiment of the present invention
  • FIG. 4 is a schematic diagram of a memory composition of data according to an embodiment of the present invention.
  • FIG. 5 is a structural diagram of a database access device according to an embodiment of the present invention.
  • FIG. 6 is a structural diagram of an atomic access module according to an embodiment of the present invention.
  • FIG. 7 is a structural diagram of a database access device according to an embodiment of the present invention.
  • FIG. 8 is a structural diagram of a permission setting module according to an embodiment of the present invention.
  • FIG. 9 is a structural diagram of a database application system according to an embodiment of the present invention.
  • FIG. 10 is a schematic diagram of an application scenario of a database application system according to an embodiment of the present invention
  • FIG. 11 is a schematic diagram of an application scenario of a database application system according to an embodiment of the present invention.
  • an embodiment of the present invention provides a method for accessing a database, including:
  • S101 Receive a modify operation request for the shared data of the database, where the shared data of the database is mapped into the address space of the process;
  • the shared data of the database needs to be mapped to the address space of the process. That is, the shared data of the database is loaded into the address space of the process.
  • a process can include an application process and a database service process.
  • the database can be an embedded concurrent access database.
  • the atomic operation provided by the atomic operation interface accesses the shared data of the above database in the address space of the process.
  • an atomic operation interface can be provided by the kernel driver of the operating system through which atomic access to the shared data of the database is performed. That is, the shared data of the database can be accessed through atomic operations provided by the kernel driver of the operating system.
  • an atomic operation interface can be provided through a database service process through which atomic access to the shared data of the database is performed. That is, the shared data of the database can be accessed through atomic operations provided by the service process of the database.
  • the modification operation of the database is performed by accessing the shared data of the database through atomic operations, and the atomic operation processing is not interrupted by other processes while being performed, and the data can be guaranteed. Consistency improves the protection of shared data in multi-process embedded access databases.
  • an embodiment of the present invention provides a method for accessing a database, including:
  • S110 Receive an operation request for shared data of the database, where the shared data of the database is mapped into an address space of the process;
  • the shared data of the database needs to be mapped to the address space of the process. That is, the shared data of the database is loaded into the address space of the process.
  • the process includes an application process and a database service process.
  • the preset logical objects may include but are not limited to the following three types:
  • Memory objects include, add new memory blocks, delete memory blocks;
  • Data objects include, insert new records, delete records, update records
  • Index objects include, insert index, delete index.
  • the shared data of the above database may be subjected to corresponding atomic operation processing according to the type of atomic operation (for example, performing memory operation processing, Data operation processing or index operation processing;), and then processing the internal objects of the database.
  • the type of atomic operation for example, performing memory operation processing, Data operation processing or index operation processing;
  • the method may further include:
  • the process may include an application process and a database service process.
  • the atomic operation interface is an atomic operation interface provided by the operating system kernel driver, ie, the atomic operation processing is provided to the database through the operating system kernel driver, then for the database service process and the application process, The access rights of the mapped shared data are set to read-only permissions;
  • the atomic operation interface provides an atomic operation interface for the database service process, that is, through the database service process to provide atomic operation processing for the database, then for the database service process, access to the mapped shared data Set to read and write permissions; For application processes, set access to mapped shared data to read-only permissions.
  • the application because the application is set to read-only permissions in this embodiment, the application itself does not have the authority to modify the shared data of the database. If the application wants to modify the shared data, then the application will modify it by calling the operating system kernel or the atomic operation process provided by the database service process.
  • the operating system kernel can read and write shared data, and the database service process is set. In the case of read and write permissions, it is also possible to share data with the association. This reduces access to shared data in the presence of memory access violations or wild pointers in the application code, resulting in illegal destruction of data in the in-memory database.
  • the operation request is a read operation request, according to the read operation request, accessing the shared data of the database mapped to the process space.
  • a read operation request eg, a query request
  • first breaks it down into a series of atomic operations then calls the atomic operation interface provided by the operating system kernel driver or database service process to complete these atomic operations, and finally returns the result to the user.
  • the embodiment of the present invention improves the multi-process embedded concurrent access shared memory by decomposing the modification operation of the database into an atomic operation by the above technical solution, and the atomic operation processing is not interrupted by other processes during the process.
  • the protection of the shared data of the database ensures the consistency of the data.
  • the shared data of the mapping is set with different access rights according to the category of the process, which reduces the situation that the process is abnormally accessed and the database is abnormal. Further, if the application is found to be crashed by the abnormality detection, the unbound transaction bound by the application is rolled back, the resources occupied by the unfinished transaction are released, and the data is restored.
  • an embodiment of the present invention provides a method for accessing a database, where the method includes: S210: mapping shared data of a database into an address space of a process;
  • the memory composition of the database can be as shown in FIG.
  • the memory of the memory database includes a fixed length control block and a plurality of memory data blocks of different sizes.
  • the shared data of the database needs to be mapped to the address space of the process. That is, the shared data of the database is loaded into the address space of the process.
  • the mapping for shared data can include two stages of initial loading and access loading.
  • the atomic operation of the database can be encapsulated as a kernel driver of the operating system, and the kernel of the operating system provides an atomic operation interface for the internal database.
  • the initialization loading is performed as follows:
  • the address of the control block After saving the head address information of the control block, the address of the control block can be found by the header address information of the control block.
  • illegal access to shared data of the database can be protected by setting different access rights for the mapped shared data according to the category of the process.
  • the mapped shared data is set to read-only permissions for the database's service process and application process.
  • the kernel can read and write these shared data.
  • mapping a database server in one embodiment is the same as mapping the application, including:
  • a new block of data is added to the database, it must be incremented by the kernel driver. Therefore, for access loads, only exist in database service programs and applications.
  • the head pointer of the data block to be accessed does not exist in the in-process private block header pointer array, the relevant information needs to be read from the control block and mapped into the process space of the database server or application, and the private is updated at the same time.
  • the kernel driver can be cancelled, and the atomic operation interface is directly provided by the service process: This requires opening a shared memory communication area between the application and the database service process for atomic operation communication. .
  • communication may also be performed using the TCP/IP protocol or using a Socket (socket) protocol; in another embodiment, other IPC (Inter Process Communication, The inter-process communication means that the communication is performed, and the embodiment of the present invention is not particularly limited.
  • mapping shared data of a database to a database server you need to make the mapped shared data read and write.
  • the kernel driver is cancelled and the atomic operation interface is directly provided by the database service process, the shared data of the database is not mapped to the kernel driver in step S210.
  • the request statement can be a SQL request or a PL request statement.
  • the method includes:
  • the session in S231 is generated when the application connects to the database; for example, the user performs operations such as modifying or querying the database, and these operations all generate a session.
  • the SQL request is taken as an example.
  • the lock is released upon transaction commit.
  • the index directly access the index data structure to obtain a record ID that satisfies the condition
  • the index data structure may be an index page; in an embodiment, the index data structure may also be an index block, which is not specifically limited in the embodiment of the present invention.
  • the index data structure is an index page or an index block
  • the index page or the index block when the index page or the index block is accessed, the page or block is latched, and the latch is unblocked after the access.
  • step S237 reassembling the obtained actual records into a format required by the user.
  • the method includes:
  • the SQL request is taken as an example.
  • the lock is released upon transaction commit.
  • the atomic operation sequences when the execution plan is decomposed into a preset number of atomic operation sequences, the atomic operation sequences have a preset execution order.
  • S246 Calling an atomic operation interface to process an atomic operation according to an execution sequence of each atomic operation sequence
  • the atomic operation can be processed by calling an atomic operation processing interface provided by the kernel driver; in this case, the device that performs the atomic operation processing can be packaged as a kernel driver of the operating system, such that the kernel of the operating system The driver can provide an atomic operation processing interface for the database.
  • the atomic operations can be handled by an atomic operation interface provided by the database service process; in this case, in one embodiment, a shared memory communication area can be opened between the application and the database service process.
  • a shared memory communication area can be opened between the application and the database service process.
  • the TCP/IP protocol can also be used for communication or communication using the Socket protocol; in another embodiment, other IPC means can be used for communication.
  • the embodiment of the present invention is not particularly limited.
  • the shared data is mapped into the address space of the process.
  • the access permission of the database service process to the shared data of the database needs to be set to read and write permissions.
  • the preset logical objects may include but are not limited to the following three types:
  • Memory objects include, add new memory blocks, delete memory blocks;
  • Data objects include, insert new records, delete records, update records
  • Index objects include, insert an index, delete an index
  • the shared data of the above database may be subjected to corresponding atomic operation processing according to the type of atomic operation (for example, performing memory operation processing, data operation processing, or index operation processing), In turn, the internal objects of the database are processed.
  • the type of atomic operation for example, performing memory operation processing, data operation processing, or index operation processing
  • step S248 after each atomic operation is processed, a UNDO message is recorded for each atomic operation; after step S248, if there is still an atomic operation that has not been processed, the process returns to step S247.
  • the UNDO message is recorded by the system's log module before each atomic operation is completed and returned to the application.
  • step S250 that is, after the processing result is returned to the user, it can be counted as the end of the user request processing.
  • the method may further include:
  • the application ID bound to the session may be obtained from a session, and the application is determined according to the application ID.
  • the database service process is a separate process of the database that performs some of the system's system tasks.
  • step S260 includes:
  • S263. Determine, according to the application ID, whether the application has exited. If not, process the next session; if yes, determine if the session has outstanding transactions, if there are no outstanding transactions, set the session to idle state, and then process the next session; if there are outstanding transactions, Release the latch used by these outstanding transactions, roll back the outstanding transaction, and set the session to idle Status.
  • the embodiment of the present invention improves the multi-process embedded concurrent access shared memory by decomposing the modification operation of the database into an atomic operation by the above technical solution, and the atomic operation processing is not interrupted by other processes during the process.
  • the protection of the shared data of the database ensures the consistency of the data.
  • the shared data of the mapping is set according to the category of the process, and the application is set to read-only permission. If the application needs to modify the shared data, it can only be processed by atomic operation, and the code of the application is reduced. There is a case where the memory access is out of bounds or the wild pointer causes the data of the in-memory database to be illegally destroyed. Further, after the request processing of the user ends, if the application is found to be crashed by the abnormality detection, the unbound transaction bound by the application is rolled back, the resources occupied by the uncompleted transaction are released, and data recovery is performed.
  • an embodiment of the present invention provides a database access apparatus, including:
  • the receiving module 310 is configured to receive a modify operation request for the shared data of the database, where the shared data of the database is mapped into the address space of the process;
  • the shared data of the database needs to be mapped to the address space of the process. That is, the shared data of the database is loaded into the address space of the process.
  • the decomposition module 320 is configured to decompose the above modification operation request into a preset number of atomic operations ⁇
  • the calling module 330 is configured to invoke an atomic operation interface according to an execution order of each atomic operation sequence
  • the atomic access module 340 is configured to access the shared data of the above database mapped to the address space of the process through the atomic operations provided by the atomic operation interface.
  • an atomic operation interface can be provided by the kernel driver of the operating system through which atomic access to the shared data of the database is performed. That is, the shared data of the database can be accessed through atomic operations provided by the kernel driver of the operating system.
  • an atomic operation interface can be provided through a database service process through which atomic access to the shared data of the database is performed. That is, the shared data of the database can be accessed through atomic operations provided by the service process of the database.
  • the atomic access module 340 can include:
  • a type obtaining unit 341, configured to acquire a type of each atomic operation sequence, each of the above atomic operations
  • the type of the work is pre-divided according to the preset logical object
  • the preset logical objects may include but are not limited to the following three types:
  • Memory objects include, add new memory blocks, delete memory blocks;
  • Data objects include, insert new records, delete records, update records
  • Index objects include, insert index, delete index.
  • the processing unit 342 is configured to perform corresponding atomic operation processing on the shared data of the database mapped to the address space of the process according to the types of the atomic operations described above through the atomic operation interface.
  • the shared data of the above database may be subjected to corresponding atomic operation processing according to the type of atomic operation (for example, performing memory operation processing, data operation processing, or index operation processing), In turn, the internal objects of the database are processed.
  • the type of atomic operation for example, performing memory operation processing, data operation processing, or index operation processing
  • an atomic operational processing interface can be provided to the database through the kernel driver of the operating system.
  • an atomic operational processing interface can be provided to the database through a database service process.
  • the modification operation of the database is performed by accessing the shared data of the database through atomic operations, and the atomic operation processing is not interrupted by other processes while being performed, and the data can be guaranteed. Consistency improves the protection of shared data in multi-process embedded access databases.
  • the apparatus may further include:
  • the loading module 300 is configured to map the shared data of the database into the address space of the process; the permission setting module 301 is configured to set corresponding access rights to the process to which the shared data is mapped according to the category of the process, where the process includes Application process and database service process.
  • the exception processing module 302 is configured to: traverse the session table generated by the shared data of the access database after the processing request is processed, to obtain a session; and determine, when the application exits, according to the application identification code ID of the session binding If the session has outstanding transactions, release the latch used by the incomplete transaction; roll back the outstanding transaction and set the session to idle.
  • the receiving module 310 is further configured to receive a read operation request for the shared data of the database.
  • the read operation processing module 303 is configured to access the shared data of the database mapped to the process space according to the read operation request.
  • the rights setting module 301 can include:
  • the first authority setting unit 3011 is configured to: when the atomic operation interface is an atomic operation interface provided by the kernel driver of the operating system, set the access permission of the application process and the database service process to the mapped shared data to read-only permission;
  • the second authority setting unit 3012 is configured to: when the atomic operation interface is an atomic operation interface provided by the service process of the database, set an access permission of the application process to the mapped shared data to a read-only permission, and map the service process pair of the database.
  • the access rights for shared data are set to read and write permissions.
  • the embodiment of the present invention improves the multi-process embedded concurrent access shared memory by decomposing the modification operation of the database into an atomic operation by the above technical solution, and the atomic operation processing is not interrupted by other processes during the process.
  • the protection of the shared data of the database ensures the consistency of the data.
  • the shared data of the mapping is set according to the category of the process, and the application is set to read-only permission. If the application needs to modify the shared data, it can only be processed by atomic operation, and the code of the application is reduced. There is a case where the memory access is out of bounds or the wild pointer causes the data of the in-memory database to be illegally destroyed. Further, after the request processing of the user ends, if the application is found to be crashed by the abnormality detection, the unbound transaction bound by the application is rolled back, the resources occupied by the uncompleted transaction are released, and data recovery is performed.
  • an embodiment of the present invention provides a database application system, including a database 10 and a database access device 20;
  • Database 10 for storing data
  • the database accessing device 20 is configured to receive a modification operation request for the shared data of the database, where the shared data of the database is mapped into the address space of the process; when the operation request is a modification operation request, the modification operation request is decomposed into the pre-processing A set of atomic operation sequences; in accordance with the execution order of each atomic operation sequence, the atomic operation interface is called, and the shared data of the above-mentioned database mapped to the address space of the process is accessed through the atomic operation provided by the atomic operation interface.
  • a process can include an application process and a database service process.
  • the database can be accessed concurrently for the database.
  • an atomic operation interface can be provided by the kernel driver of the operating system through which atomic access to the shared data of the database is performed. That is, the shared data of the database can be accessed through atomic operations provided by the kernel driver of the operating system.
  • an atomic operation interface can be provided through a database service process through which atomic access to the shared data of the database is performed. That is, the shared data of the database can be accessed through atomic operations provided by the service process of the database.
  • the database access device 20 is further configured to receive a read operation request for the shared data of the database; and according to the read operation request, access the shared data of the database mapped to the address space of the process.
  • the embodiment of the present invention improves the multi-process embedded concurrent access shared memory by decomposing the modification operation of the database into an atomic operation by the above technical solution, and the atomic operation processing is not interrupted by other processes during the process.
  • the protection of the shared data of the database ensures the consistency of the data.
  • the shared data of the mapping is set according to the category of the process, and the application is set to read-only permission. If the application needs to modify the shared data, it can only be processed by atomic operation, and the code of the application is reduced. There is a case where the memory access is out of bounds or the wild pointer causes the data of the in-memory database to be illegally destroyed. Further, after the request processing of the user ends, if the application is found to be crashed by the abnormality detection, the unbound transaction bound by the application is rolled back, the resources occupied by the uncompleted transaction are released, and data recovery is performed.
  • an embodiment of the present invention provides a schematic diagram of an application scenario of a database application system.
  • an atomic operation process is provided for a database by using an operating system kernel driver, that is, an atomic operation interface is a kernel driver of an operating system.
  • the atomic operation interface provided.
  • the access process of the application process and the database service process to the mapped shared data is set to read-only permission.
  • the operating system's kernel driver can use the kernel to read and write these shared data.
  • the operating system's kernel provides atomic operations to access the shared data of the database, and the shared data of the database is modified.
  • the access rights of the application process and the database service process to the database shared data are all set to read-only permissions, when the user wants to modify the shared data through the application process and the database service process, then The database application system calls the atomic operation interface provided by the operating system kernel driver to complete the modification through atomic operations.
  • the embodiment of the present invention improves the multi-process embedded concurrent access shared memory by decomposing the modification operation of the database into an atomic operation by the above technical solution, and the atomic operation processing is not interrupted by other processes during the process.
  • the protection of the shared data of the database ensures the consistency of the data.
  • the shared data of the mapping is set according to the category of the process, and the application is set to read-only permission. If the application needs to modify the shared data, it can only be processed by atomic operation, and the code of the application is reduced. There is a case where the memory access is out of bounds or the wild pointer causes the data of the in-memory database to be illegally destroyed.
  • an embodiment of the present invention provides a schematic diagram of an application scenario of a database application system.
  • an atomic operation process is provided for a database through a database service process, that is, an atomic operation interface is a service process of the database.
  • the atomic operation interface provided.
  • a shared memory communication area is opened between the application and the database service process for communication between atomic operations.
  • the access permission of the application process to the mapped shared data is set to read-only permission; and the shared data of the database is mapped to the map.
  • the access process of the database service process to the mapped shared data is set to read and write permissions.
  • the database application system calls the database service process to provide the data service process.
  • the atomic operation interface is modified by atomic operations. Since the database service process provides an atomic operation interface, the access permission of the database service process for the database shared data is set to read and write permissions, so when the user wants to pass the database When the service process modifies the shared data of the database, it will directly modify it through the atomic operation interface in the service process.
  • a shared memory communication area can be opened between the application and the database service process for communication of atomic operations.
  • the TCP/IP protocol may be used for communication or the Socket protocol may be used for communication; in another embodiment, other IPC means may be used for communication, and the embodiment of the present invention does not. Special restrictions.
  • the embodiment of the present invention processes the modification operation of the database into atomic operations, and the atomic operation processing is not interrupted by other processes during the process, thereby improving multi-process embedded concurrent access to the shared memory database.
  • the protection of shared data ensures data consistency.
  • the shared data of the mapping is set according to the category of the process, and the application is set to read-only permission. If the application needs to modify the shared data, it can only be processed by atomic operation, and the code of the application is reduced. There is a case where the memory access is out of bounds or the wild pointer causes the data of the in-memory database to be corrupted.
  • the storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Computer Security & Cryptography (AREA)
  • Storage Device Security (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Description

数据库的访问方法、 装置及数据库应用系统
本申请要求于 2010年 2月 12日提交中国专利局,申请号为 201010113632.0, 发明名称为"数据库的访问方法、装置及系统"的中国专利申请的优先权,其全 部内容通过引用结合在本申请中。 技术领域
本发明涉及数据库领域, 特别涉及一种数据库的访问方法、 装置及系统。
背景技术
随着电信业的发展, 对数据存储的实时性和健壮性要求越来越高, 同时 内存等硬件的集成度和访问速度得到提高, 成本得到降低, 这就决定了内存 数据库在电信业中扮演了越来越重要的角色。
传统的数据库管理系统釆用了 C/S (客户端 /服务器) 的访问模式, 有效 的隔离了应用程序和数据库系统, 保证了系统的健壮性; 但 C/S访问模式下 产生了额外的网络通信(通常是 TCP/IP )开销, 限制了数据库系统的实时性, 特别是在高速的内存数据库中, 数据本身的访问和修改都是在微秒级下, 但 当前局域网的网络时延一般是在毫秒级上, 即使是访问本机, 也存在协议栈 的处理和进程切换的开销。 这些都使得 C/S模式成为内存数据库的一种访问 瓶颈。 嵌入式访问是一种高效的访问方式, 伴随着内存数据库的发展, 越来 越被大多数人接受。 嵌入式的访问是将内存数据库与应用程序联合编译在一 起, 从而允许多个应用程序共享使用一个数据库实例, 这样提高了数据访问 的实时性。
嵌入式的访问方式带来高效的访问的同时, 也存在如下缺陷: 当某个应 用程序在修改内存数据库的数据时因为某些原因异常退出了, 这就可能导致 这种修改没有完成(如某个数据结构修改了一半或者某些内部互斥资源没有 释放), 使得数据库处于一种不一致的状态, 从而导致其他应用程序无法再次 使用内存数据库。 发明内容
本发明实施例提供一种数据库的访问方法、 装置及系统, 以保证数据库 的一致性。
本发明实施例提供一种数据库的访问方法, 包括:
接收对数据库的共享数据的修改操作请求, 所述数据库的共享数据映射 到了进程的地址空间中;
将所述修改操作请求分解为预置个数的原子操作序列;
按照各个原子操作序列的执行顺序调用原子操作接口;
通过所述原子操作接口提供的原子操作, 访问映射到进程的地址空间的 所述数据库的共享数据。
本发明实施例提供一种数据库访问装置, 包括:
接收模块, 用于接收对数据库的共享数据的修改操作请求, 所述数据库 的共享数据映射到了进程的地址空间中;
分解模块, 用于将所述修改操作请求分解为预置个数的原子操作序列; 调用模块, 用于按照各个原子操作序列的执行顺序, 调用原子操作接口; 原子访问模块, 用于通过所述原子操作接口提供的原子操作, 访问映射 到进程的地址空间的所述数据库的共享数据。
本发明实施例提供一种数据库应用系统, 包括: 用于存储数据的数据库 和上述的数据库访问装置; 所述数据库访问装置用于对所述数据库进行访问。
本发明实施例通过以上技术方案, 对数据库的修改操作, 通过原子操作 访问所述数据库的共享数据来进行处理, 而原子操处理作在进行时不会被其 它的进程打断, 能够保证数据的一致性, 提高了多进程嵌入式访问数据库的 共享数据的保护程度。 附图说明
为了更清楚地说明本发明实施例中的技术方案, 下面将对实施例描述中 所需要使用的附图作简单地介绍, 显而易见地, 下面描述中的附图仅仅是本 发明的一些实施例, 对于本领域普通技术人员来讲, 在不付出创造性劳动性 的前提下, 还可以根据这些附图获得其他的附图。
图 1本发明实施例提供一种数据库的访问方法的流程图;
图 2本发明实施例提供一种数据库的访问方法的流程图;
图 3本发明实施例提供一种数据库的访问方法的流程图;
图 4本发明实施例提供一种数据的内存组成示意图;
图 5本发明实施例提供一种数据库访问装置结构图;
图 6本发明实施例提供在一种原子访问模块的结构图;
图 7本发明实施例提供一种数据库访问装置结构图;
图 8本发明实施例提供一种权限设置模块的结构图;
图 9本发明实施例提供一种数据库应用系统结构图;
图 10本发明实施例提供一种数据库应用系统的应用场景示意图; 图 11本发明实施例提供一种数据库应用系统的应用场景示意图。
具体实施方式
下面将结合本发明实施例中的附图, 对本发明实施例中的技术方案进行 清楚、 完整地描述, 显然, 所描述的实施例仅仅是本发明一部分实施例, 而 不是全部的实施例。 基于本发明中的实施例, 本领域普通技术人员在没有作 出创造性劳动前提下所获得的所有其他实施例 , 都属于本发明保护的范围。
如图 1所示, 本发明实施例提供一种数据库的访问方法, 包括:
S101 , 接收对数据库的共享数据的修改操作请求, 该数据库的共享数据 映射到了进程的地址空间中;
在一个实施例中, 应用程序在使用数据库时, 需要将数据库的共享数据 映射到进程的地址空间。 即, 将数据库的共享数据加载到进程的地址空间。
在一个实施例中, 进程可以包括应用程序进程和数据库服务进程。
在一个实施例中, 数据库可以为嵌入式并发访问数据库。
5102, 将上述修改操作请求分解为预置个数的原子操作序列;
5103 , 按照各个原子操作序列的执行顺序, 调用原子操作接口;
5104 , 通过原子操作接口提供的原子操作访问射到进程的地址空间中上 述数据库的共享数据。 在一个实施例中, 可以通过操作系统的内核驱动来提供一个原子操作接 口, 通过该原子操作接口对该数据库的共享数据进行原子操作访问。 即, 可 以通过操作系统的内核驱动提供的原子操作访问所述数据库的共享数据。
在一个实施例中, 可以通过数据库的服务进程来提供一个原子操作接口, 通过该原子操作接口对该数据库的共享数据进行原子操作访问。 即, 可以通 过所述数据库的服务进程提供的原子操作访问所述数据库的共享数据。
本发明实施例通过以上技术方案, 对数据库的修改操作, 通过原子操作 访问所述数据库的共享数据来进行处理, 而原子操处理作在进行时不会被其 它的进程打断, 能够保证数据的一致性, 提高了多进程嵌入式访问数据库的 共享数据的保护程度。
如图 2所示, 本发明实施例提供一种数据库的访问方法, 包括:
S110 , 接收对数据库的共享数据的操作请求, 上述数据库的共享数据映 射到了进程的地址空间中;
在一个实施例中, 应用程序在使用数据库时, 需要将数据库的共享数据 映射到进程的地址空间。 即, 将数据库的共享数据加载到进程的地址空间。
在一个实施例中, 进程包括应用程序进程和数据库服务进程。
S120 , 当所述操作请求为修改操作请求时, 将上述修改操作请求分解为 预置个数的原子操作序列;
S130, 按照各个原子操作序列的执行顺序, 调用原子操作接口;
S141 , 获取各个原子操作序列的类型, 上述各个原子操作的类型为根据 预置的逻辑对象预先划分的;
在一个实施例中, 预置的逻辑对象可以包括但不仅限于以下 3种:
( 1 ) 内存对象: 包括, 增加新内存块, 删除内存块;
( 2 ) 数据对象: 包括, 插入新记录, 删除记录, 更新记录;
( 3 ) 索引对象: 包括, 插入索引, 删除索引。
S142 , 根据各个原子操作序列的类型, 通过所述原子操作接口对所述数 据库的共享数据进行相应的原子操作操作处理。
以上述三种逻辑对象为例, 在一个实施例中, 可以根据原子操作的类型 对上述数据库的共享数据进行相应的原子操作处理(如, 进行内存操作处理、 数据操作处理或者索引操作处理;), 进而对数据库内部对象进行处理。
如图 2中的虚线框所示, 在一个实施例中, 该方法还可以包括:
5107 , 将数据库的共享数据映射到进程的地址空间中;
5108 , 根据所述进程的类别, 对上述共享数据映射到的进程设置相应的 访问权限; 在一个实施例中, 进程可以包括应用程序进程和数据库服务进程。
在一个实施例中, 如果原子操作的接口为操作系统内核驱动提供的原子 操作接口, 即, 通过操作系统内核驱动为数据库提供原子操作处理, 那么对 于数据库的服务进程和应用程序进程, 将它们对映射的共享数据的访问权限 设置为只读权限;
在一个实施例中, 如果原子操作接口为数据库服务进程提供的原子操作 接口, 即, 通过数据库服务进程为数据库提供原子操作处理, 那么对于数据 库的服务进程, 将其对映射的共享数据的访问权限设置为读写权限; 对于应 用程序进程, 将其对映射的共享数据的访问权限设置为只读权限。
这样, 在一个实施例中, 因为, 本实施例中应用程序被设置为只读权限, 应用程序本身时没有权限去修改数据库的共享数据的。 如果应用程序想要修 改共享数据, 那么该应用程序就会通过调用操作系统内核或者数据库服务进 程提供的原子操作处理进行修改, 而操作系统内核是可以读写共享数据的, 数据库的服务进程在设置为读写权限的情况下也是可以对协共享数据的。 这 样就减少了在应用程序的代码存在内存访问越界或者野指针的情况下对共享 数据进行访问, 导致内存数据库的数据被非法破坏的情况。
5109 , 当所述操作请求为读操作请求时, 根据该读操作请求, 访问映射 到进程空间的数据库的共享数据。
在一个实施例中,对于一个读操作请求(例如,查询请求)如 "select * from tbl where idx = 1" , 直接访问映射到进程空间的数据的库共享数据; 对于一个 修改操作请求, 如 "update tbl set fl = 1 where idx = 1" , 先将此分解成一系列 的原子操作序列, 然后调用操作系统内核驱动或者数据库服务进程提供的原 子操作接口完成这些原子操作, 最终将结果返回给用户。
S150 , 对上述操作请求 (读操作请求或者修改操作请求)处理结束后, 遍历访问所述数据库的共享数据产生的会话表, 获取一个会话; 根据该会话 绑定的应用程序标识码 ID判定所述应用程序退出时, 若该会话还有未完成的 事务, 释放未完成的事务所使用的闩; 将未完成的事务回滚, 将该会话设为 空闲状态。
本发明实施例通过以上技术方案, 通过将对数据库的修改操作分解为原 子操作进行处理, 而原子操处理作在进行时不会被其它的进程打断, 提高了 多进程嵌入式并发访问共享内存数据库的共享数据的保护性, 能够保证数据 的一致性。 而且对映射的共享数据根据进程的类别来设置不同的访问权限, 减少了进程越权访问导致数据库异常的情况。 进一步地, 通过异常检测一旦 发现应用发生崩溃, 会对应用绑定的未完成事务进行回滚, 释放未完成的事 务占用的资源, 进行数据恢复。
如图 3所示, 本发明实施例提供一种数据库的访问方法, 该方法包括: S210, 将数据库的共享数据映射到进程的地址空间中;
在一个实施例中, 数据库的内存组成可以如图 4所示。 由图 4可知, 内 存数据库的内存包括一个固定长度的控制块和多个大小不一的内存数据块。
在一个实施例中, 应用程序在使用数据库时, 需要将数据库的共享数据 映射到进程的地址空间。 即, 将数据库的共享数据加载到进程的地址空间。
在一个实施例中, 对于共享数据的映射可以包括初始化加载和访问加载 两个阶段。
在一个实施例中, 可以将数据库的原子操作封装为操作系统的内核驱动, 由操作系统的内核为数据库内部提供原子操作接口, 初始化加载按照如下过 程进行:
1、 对内核驱动进行映射;
( 1 )根据数据库的配置信息, 获取控制文件, 分配内存, 读入控制文件 生成控制块, 保存生成的控制块的头地址信息。
对控制块的头地址信息进行保存后, 可以通过控制块的头地址信息找到 控制块的地址。
( 2 )分析控制块的信息, 分配内存并加载控制块信息中记录的各个数据 块信息, 并将数据块的头指针保存到数据块头指针数组中。
( 3 )根据数据库的配置信息, 申请数据库的全局共享区域, 并在这个区 域上初始化各种全局信息: 例如, 对日志区, 事务管理区, 锁资源区, 资源 跟踪区, 系统表快速緩冲区等进行初始化。
2、 对数据库服务程序进行映射;
3、 对应用程序进行映射;
在一个实施例中, 可以通过对映射的共享数据根据进程的类别来设置不 同的访问权限, 来对数据库的共享数据的非法访问进行保护。 例如, 在一个 实施例中, 对于数据库的服务进程和应用程序进程, 将映射的共享数据设置 为只读权限。 而对于内核驱动来说, 利用内核可以读写这些共享数据。
在一个实施例中对数据库服务程序进行映射的过程和对应用程序进行映 射的过程是一样的, 均包括:
( 1 )映射上述内核驱动创建的控制块, 保存映射后的控制块头地址信息 到私有内存中。 设置该映射地址为只读属性。
( 2 ) 根据控制块中的信息, 映射内核驱动创建的各个数据块, 并将 数据块的头指针保持到私有的数据块头指针数组中, 并设置这些映射地址为 只读属性。
( 3 ) 加载全局共享区域, 并保存各种全局信息的头指针到使用内存 中。
在一个实施例中, 如果数据库新增一块数据块, 必须通过内核驱动进行 增加。 因此, 对于访问加载, 只存在于数据库服务程序和应用程序。 当要访 问的数据块的头指针在进程内私有的数据块头指针数组中不存在时, 需要从 控制块中读取相关信息, 并映射到数据库服务程序或者应用程序的进程空间 中, 同时更新私有的数据块头指针数组。
需要说明的是, 在另一个实施例中, 可以取消内核驱动, 直接由服务进 程提供原子操作接口: 这样需要在应用程序与数据库服务进程间开启一个共 享内存通信区, 用于进行原子操作的通信。 当然可以理解的是在另一个实施 例中, 还可以使用 TCP/IP协议进行通信或者使用 Socket (套接字)协议进行 通信;在另一个实施例中,还可以使用其它 IPC ( Inter Process Communication, 进程间通信)手段进行通信, 本发明实施例不做特别的限定。 将数据库的共 享数据映射到数据库服务程序时, 需要将映射的共享数据设为可读写。 当然很好理解的是, 在取消内核驱动, 直接由数据库的服务进程提供原 子操作接口的情况下, 步骤 S210中不会将数据库的共享数据对内核驱动进行 映射。
S220, 解析收到的请求语句;
S221 , 检验该请求语句的有效性;
S222 - S223 , 如果有效则对该请求语句进行优化, 并生成执行计划。 在一个实施例中, 请求语句可以为 SQL请求或者 PL请求语句。
在一个实施例中, 如果请求语句有效, 会生成多个执行计划, 这时进行 优化就是选择一个最佳的执行计划。
S230, 若该执行计划为读操作, 则包括:
S231 , 检查当前会话是否已启动事务, 如果否, 则启动一个新的读事务, 并将该新的读事务绑定到当前会话; 如果是, 则进行下面的步骤;
在一个实施例中, S231 中的会话是由应用程序连接到数据库时产生的; 例如, 用户对数据库进行修改或查询等操作, 这些操作都会产生会话。
S232, 根据执行计划, 对所需要访问的表进行加锁;
在一个实施例中, 以 SQL请求为例进行说明, 收到的请求语句为 SQL请 求, 例如为 select * from tbl where idx = 1" , 这样才艮据该请求就可以知道该请 求需要访问表 1 ( tbl )。
在一个实施例中, 锁在事务提交时释放。
S233 , 判断是否能够使用索引对所需要访问的表进行访问;
5234, 如果能够使用索引, 则直接访问索引数据结构获取满足条件的记 录 ID;
在一个实施例中, 索引数据结构可以为索引页; 在一个实施例中索引数 据结构还可以为索引块, 本发明实施例不做特别的限定。
在一个实施例中, 索引数据结构为索引页或者索引块时, 在访问索引页 或者索引块时, 会对该页或者块进行加闩, 在访问完后进行解闩。
5235, 根据 S234中的记录 ID , 访问得到实际记录;
5236, 若不能够使用索引, 则对需要访问的表进行全表扫描, 得到实际 记录, 并跳转到步骤 S237; S237, 对得到的实际记录重新组装成用户需要的格式。
5240, 若该执行计划为写操作, 则包括:
5241 , 检查当前会话是否已启动事务;
5242, 如果当前为读事务, 则现提交该事务, 并启动一个新的写事务; S243 , 如果无事务也启动一个新的写事务; 如果当前为写事务, 则进行 下面的步骤;
5244, 根据执行计划, 对需要访问的表进行加锁;
在一个实施例中, 以 SQL请求为例进行说明, 收到的请求语句为 SQL请 求, 例如为 "update tbl set fl = 1 where idx =1" , 这样才艮据该请求就可以知道 该请求需要访问表 1 ( tbl )。
在一个实施例中, 锁在事务提交时释放。
5245, 将执行计划分解为预置个数的原子操作序列;
在一个实施例中, 当将执行计划分解为为预置个数的原子操作序列时, 这些原子操作序列有着预置的执行顺序。
S246, 按照各个原子操作序列的执行顺序, 调用原子操作接口对原子操 作进行处理;
在一个实施例中, 可以通过调用内核驱动提供的原子操作处理接口对原 子操作进行处理; 这种情况下, 可以是将执行原子操作处理的装置封装为操 作系统的内核驱动, 这样操作系统的内核驱动可以为数据库提供原子操作处 理接口。
在一个实施例中, 可以通过数据库服务进程提供的原子操作接口对原子 操作进行处理; 这种情况下, 在一个实施例种, 可以在应用程序与数据库服 务进程间开启一个共享内存通信区, 用于进行原子操作的通讯; 当然可以理 解的是在另一个实施例中, 还可以使用 TCP/IP协议进行通信或者使用 Socket 协议进行通信; 在另一个实施例中, 还可以使用其它 IPC手段进行通信, 本 发明实施例不做特别的限定。 这样在步骤 S210中将共享数据映射到进程的地 址空间中, 在映射到数据库服务进程的地址空间中时, 需要将数据库服务进 程对数据库的共享数据的访问权限设置为读写权限。
S247 , 根据预置的逻辑对象, 对原子操作进行类型划分, 根据原子操作 的类型对数据库的共享数据进行相应的原子操作处理;
在一个实施例中, 预置的逻辑对象可以包括但不仅限于以下 3种:
( 1 ) 内存对象: 包括, 增加新内存块, 删除内存块;
( 2 ) 数据对象: 包括, 插入新记录, 删除记录, 更新记录;
( 3 ) 索引对象: 包括, 插入索引, 删除索引;
以上述三种逻辑对象为例, 在一个实施例中, 可以根据原子操作的类型 对上述数据库的共享数据进行相应的原子操作处理(如, 进行内存操作处理、 数据操作处理或者索引操作处理 ), 进而对数据库内部对象进行处理。
S248, 每个原子操作处理完后, 对每个原子操作记 UNDO曰志; 步骤 S248后, 若还有原子操作没有处理完毕, 则返回步骤 S247。
在一个实施例中, 在每个原子操作处理完成返回到应用程序前, 都会通 过系统的日志模块对操作记录记 UNDO曰志。
S250, 将执行计划的处理结果返回给用户;
至此, 在步骤 S250结束后, 即, 将处理结果返回给用户后, 可以算作一 次用户请求处理过程的结束。
如图 3中的虚线框所示, 在一个实施例中, 该方法还可以包括:
5260, 在对用户的请求处理结束后, 对内存数据库进行异常检测与恢复; 在一个实施例中, 可以从一个会话中获取该会话绑定的应用程序 ID, 当 根据应用程序 ID判断该应用程序已经退出时, 若该会话还有未完成的事务, 释放这些未完成事务使用的闩, 将未完成的事务回滚, 并将该会话设为空闲 状态。 在一个实施例中, 数据库服务进程是数据库一个独立的进程, 它能够 完成数据库的一些系统任务。
在一个实施例中, 步骤 S260主要过程包括:
5261 , 遍历会话表, 获取一个会话
S262, 从会话中获取会话绑定的应用程序 ID。
S263 , 根据应用程序 ID判断该应用程序是否已经退出。 如果否, 处理下 一个会话; 如果是, 判断该会话是否有未完成的事务, 如果没有未完成的事 务, 则将该会话设为空闲状态, 然后处理下一个会话; 如果有未完成的事务, 释放这些未完成事务使用的闩, 将未完成的事务回滚, 并将该会话设为空闲 状态。
本发明实施例通过以上技术方案, 通过将对数据库的修改操作分解为原 子操作进行处理, 而原子操处理作在进行时不会被其它的进程打断, 提高了 多进程嵌入式并发访问共享内存数据库的共享数据的保护性, 能够保证数据 的一致性。 而且对映射的共享数据根据进程的类别来设置不同的反问权限, 将应用程序设置为只读权限, 应用程序若需要对共享数据进行修改, 只能通 过原子操作进行处理, 减少了应用程序的代码存在内存访问越界或者野指针, 导致内存数据库的数据被非法破坏的情况。 进一步地, 在对用户的请求处理 结束后, 通过异常检测一旦发现应用发生崩溃, 会对应用绑定的未完成事务 进行回滚, 释放未完成的事务占用的资源, 进行数据恢复。
如图 5所示, 本发明实施例提供一种数据库访问装置, 包括:
接收模块 310 , 用于接收对数据库的共享数据的修改操作请求, 上述数据 库的共享数据映射到了进程的地址空间中;
在一个实施例中, 应用程序在使用数据库时, 需要将数据库的共享数据 映射到进程的地址空间。 即, 将数据库的共享数据加载到进程的地址空间。
分解模块 320 , 用于将上述修改操作请求分解为预置个数的原子操作序 歹 |J ;
调用模块 330 , 用于按照各个原子操作序列的执行顺序, 调用原子操作接 口;
原子访问模块 340 , 用于通过上述原子操作接口提供的原子操作, 访问映 射到进程的地址空间的上述数据库的共享数据。
在一个实施例中, 可以通过操作系统的内核驱动来提供一个原子操作接 口, 通过该原子操作接口对该数据库的共享数据进行原子操作访问。 即, 可 以通过操作系统的内核驱动提供的原子操作访问所述数据库的共享数据。
在一个实施例中, 可以通过数据库的服务进程来提供一个原子操作接口, 通过该原子操作接口对该数据库的共享数据进行原子操作访问。 即, 可以通 过所述数据库的服务进程提供的原子操作访问所述数据库的共享数据。
如图 6所示, 在一个实施例中, 原子访问模块 340可以包括:
类型获取单元 341 , 用于获取各个原子操作序列的类型, 上述各个原子操 作的类型为根据预置的逻辑对象预先划分的;
在一个实施例中, 预置的逻辑对象可以包括但不仅限于以下 3种:
( 1 ) 内存对象: 包括, 增加新内存块, 删除内存块;
( 2 ) 数据对象: 包括, 插入新记录, 删除记录, 更新记录;
( 3 ) 索引对象: 包括, 插入索引, 删除索引。
处理单元 342 , 用于根据上述各个根据原子操作的类型, 通过上述原子操 作接口对映射到进程的地址空间的数据库的共享数据进行相应原子操作处 理。
以上述三种逻辑对象为例, 在一个实施例中, 可以根据原子操作的类型 对上述数据库的共享数据进行相应的原子操作处理(如, 进行内存操作处理、 数据操作处理或者索引操作处理 ), 进而对数据库内部对象进行处理。
在一个实施例中, 可以通过操作系统的内核驱动为数据库提供原子操作 处理接口。
在一个实施例中, 可以通过数据库服务进程为数据库提供原子操作处理 接口。
本发明实施例通过以上技术方案, 对数据库的修改操作, 通过原子操作 访问所述数据库的共享数据来进行处理, 而原子操处理作在进行时不会被其 它的进程打断, 能够保证数据的一致性, 提高了多进程嵌入式访问数据库的 共享数据的保护程度。
如图 7所示, 在一个实施例中, 该装置还可以包括:
加载模块 300 , 用于将数据库的共享数据映射到进程的地址空间中; 权限设置模块 301 , 用于根据所述进程的类别, 对共享数据映射到的进程 设置相应的访问权限, 在这里进程包括应用程序进程和数据库服务进程。
异常处理模块 302, 用于在对所述操作请求处理完毕后, 遍历访问数据库 的共享数据产生的会话表, 获取一个会话; 根据该会话绑定的应用程序标识 码 ID判定所述应用程序退出时, 若该会话还有未完成的事务, 释放未完成的 事务所使用的闩; 将未完成的事务回滚, 将该会话设为空闲状态。
在一个实施例中, 接收模块 310还可以用于接收对所述数据库的共享数 据的读操作请求; 此时, 如图 7所示改装置还可以包括: 读操作处理模块 303 , 用于根据该读操作请求, 访问映射到进程空间的数 据库的共享数据。
如图 8所示, 在一个实施例中, 权限设置模块 301可以包括:
第一权限设置单元 3011 , 用于当原子操作接口为操作系统的内核驱动提 供的原子操作接口时, 将应用程序进程和数据库的服务进程对映射的共享数 据的访问权限设置为只读权限;
第二权限设置单元 3012, 用于当原子操作接口为数据库的服务进程提供 的原子操作接口时, 将应用程序进程对映射的共享数据的访问权限设置为只 读权限, 将数据库的服务进程对映射的共享数据的访问权限设置为读写权限。
本发明实施例通过以上技术方案, 通过将对数据库的修改操作分解为原 子操作进行处理, 而原子操处理作在进行时不会被其它的进程打断, 提高了 多进程嵌入式并发访问共享内存数据库的共享数据的保护性, 能够保证数据 的一致性。 而且对映射的共享数据根据进程的类别来设置不同的反问权限, 将应用程序设置为只读权限, 应用程序若需要对共享数据进行修改, 只能通 过原子操作进行处理, 减少了应用程序的代码存在内存访问越界或者野指针, 导致内存数据库的数据被非法破坏的情况。 进一步地, 在对用户的请求处理 结束后, 通过异常检测一旦发现应用发生崩溃, 会对应用绑定的未完成事务 进行回滚, 释放未完成的事务占用的资源, 进行数据恢复。
如图 9所示, 本发明实施例提供一种数据库应用系统, 包括数据库 10和 数据库访问装置 20;
数据库 10, 用于存储数据;
数据库访问装置 20 , 用于接收对数据库的共享数据的修改操作请求, 该 数据库的共享数据映射到了进程的地址空间中; 当所述操作请求为修改操作 请求时, 将上述修改操作请求分解为预置个数的原子操作序列; 按照各个原 子操作序列的执行顺序, 调用原子操作接口, 通过原子操作接口提供的原子 操作, 访问映射到进程的地址空间的上述数据库的共享数据。
在一个实施例中, 应用程序在使用数据库时, 需要将数据库的共享数据 映射到进程的地址空间。 即, 将数据库的共享数据加载到进程的地址空间。 在一个实施例中, 进程可以包括应用程序进程和数据库服务进程。 在一个实 施例中, 数据库可以为嵌入式并发访问数据库。
在一个实施例中, 可以通过操作系统的内核驱动来提供一个原子操作接 口, 通过该原子操作接口对该数据库的共享数据进行原子操作访问。 即, 可 以通过操作系统的内核驱动提供的原子操作访问所述数据库的共享数据。
在一个实施例中, 可以通过数据库的服务进程来提供一个原子操作接口, 通过该原子操作接口对该数据库的共享数据进行原子操作访问。 即, 可以通 过所述数据库的服务进程提供的原子操作访问所述数据库的共享数据。
在一个实施例中, 数据库访问装置 20还用于, 接收对所述数据库的共享 数据的读操作请求; 根据所述读操作请求, 访问映射到进程的地址空间的所 述数据库的共享数据。
数据库访问装置 20的结构和功能在上述实施例中已经详细描述, 在此不 再赘述。
本发明实施例通过以上技术方案, 通过将对数据库的修改操作分解为原 子操作进行处理, 而原子操处理作在进行时不会被其它的进程打断, 提高了 多进程嵌入式并发访问共享内存数据库的共享数据的保护性, 能够保证数据 的一致性。 而且对映射的共享数据根据进程的类别来设置不同的反问权限, 将应用程序设置为只读权限, 应用程序若需要对共享数据进行修改, 只能通 过原子操作进行处理, 减少了应用程序的代码存在内存访问越界或者野指针, 导致内存数据库的数据被非法破坏的情况。 进一步地, 在对用户的请求处理 结束后, 通过异常检测一旦发现应用发生崩溃, 会对应用绑定的未完成事务 进行回滚, 释放未完成的事务占用的资源, 进行数据恢复。
如图 10所示,本发明实施例提供一种数据库应用系统的应用场景示意图, 在本实施例中, 通过操作系统内核驱动为数据库提供原子操作处理, 即, 原 子操作接口为操作系统的内核驱动提供的原子操作接口。
在本实施例中, 在将数据库的共享数据映射到图 10中的应用程序进程和 数据库服务进程时, 将应用程序进程和数据库的服务进程对映射的共享数据 的访问权限设置为只读权限。 而操作系统的内核驱动利用内核可以对这些共 享数据进行读写。 当收到修改操作命令时, 通过操作系统的内核提供原子操 作访问数据库的共享数据, 对数据库的共享数据进行修改。 在本实施例中, 由于应用程序进程和数据库服务进程对于数据库共享数 据的访问权限均被设置为只读权限, 因此当用户想通过应用程序进程和数据 库服务进程对共享数据进行修改时, 这时数据库应用系统会调用操作系统内 核驱动提供的原子操作接口, 通过原子操作完成修改。
具体的原子操作处理方式, 在前述实施例中已经详细描述, 在此不再赘 述。
本发明实施例通过以上技术方案, 通过将对数据库的修改操作分解为原 子操作进行处理, 而原子操处理作在进行时不会被其它的进程打断, 提高了 多进程嵌入式并发访问共享内存数据库的共享数据的保护性, 能够保证数据 的一致性。 而且对映射的共享数据根据进程的类别来设置不同的反问权限, 将应用程序设置为只读权限, 应用程序若需要对共享数据进行修改, 只能通 过原子操作进行处理, 减少了应用程序的代码存在内存访问越界或者野指针, 导致内存数据库的数据被非法破坏的情况。
如图 11所示,本发明实施例提供一种数据库应用系统的应用场景示意图, 在本实施例中, 通过数据库服务进程为数据库提供原子操作处理, 即, 原子 操作接口为所述数据库的服务进程提供的原子操作接口。 在图 11中, 在应用 程序和数据库服务进程间开启了一个共享内存通信区, 用于进行原子操作间 的通信。
由于在本实施例中, 取消了内核驱动, 直接通过数据库服务进程为数据 库提供原子操作处理, 所以:
在本实施例中,在将数据库的共享数据映射到图 11中的应用程序进程时, 将应用程序进程对映射的共享数据的访问权限设置为只读权限; 在将数据库 的共享数据映射到图 11中的数据库服务进程时, 将数据库的服务进程对映射 的共享数据的访问权限设置为读写权限。
在本实施例中, 由于应用程序进程对于数据库共享数据的访问权限被设 置为只读权限, 因此当用户想通过应用程序进程对共享数据进行修改时, 这 时数据库应用系统会调用数据库服务进程提供的原子操作接口, 通过原子操 作完成修改。 而由于数据库服务进程提供原子操作接口, 数据库服务进程对 于数据库共享数据的访问权限被设置为读写权限, 因此当用户想通过数据库 服务进程对数据库的共享数据进行修改时, 会直接通过服务进程里的原子操 作接口来完成修改。
具体的原子操作处理方式, 在前述实施例中已经详细描述, 在此不再赘 述。
在本实施例中, 可以在应用程序和数据库服务进程间开启一个共享内存 通信区, 用于进行原子操作的通信。 当然可以理解的是在另一个实施例中, 还可以使用 TCP/IP协议进行通信或者使用 Socket协议进行通信;在另一个实 施例中, 还可以使用其它 IPC手段进行通信, 本发明实施例不做特别的限定。
本发明实施例通过以上技术方案, 通过将对数据库的修改操作分解为原 子操作进行处理, 而原子操作处理在进行时不会被其它的进程打断, 提高了 多进程嵌入式并发访问共享内存数据库的共享数据的保护性, 能够保证数据 的一致性。 而且对映射的共享数据根据进程的类别来设置不同的反问权限, 将应用程序设置为只读权限, 应用程序若需要对共享数据进行修改, 只能通 过原子操作进行处理, 减少了应用程序的代码存在内存访问越界或者野指针, 导致内存数据库的数据被 法破坏的情况。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流 程, 是可以通过计算机程序来指令相关的硬件来完成, 所述的程序可存储于 一计算机可读取存储介质中, 该程序在执行时, 可包括如上述各方法的实施 例的流程。其中,所述的存储介质可为磁碟、光盘、只读存储记忆体(Read-Only Memory, ROM )或随机存储记忆体 ( Random Access Memory, RAM )等。
以上所述仅为本发明的几个实施例, 本领域的技术人员依据申请文件公 开的可以对本发明进行各种改动或变型而不脱离本发明的精神和范围。

Claims

权 利 要 求
1、 一种数据库的访问方法, 其特征在于, 包括:
接收对数据库的共享数据的修改操作请求, 所述数据库的共享数据映射 到了进程的地址空间中;
将所述修改操作请求分解为预置个数的原子操作序列;
按照各个原子操作序列的执行顺序调用原子操作接口;
通过所述原子操作接口提供的原子操作, 访问映射到进程的地址空间的 所述数据库的共享数据。
2、 如权利要求 1所述的数据库的访问方法, 其特征在于, 所述通过所述 原子操作接口提供的原子操作, 访问映射到进程的地址空间的所述数据库的 共享数据, 包括:
根据所述各个原子操作序列的类型, 通过所述原子操作接口对映射到进 程的地址空间的所述数据库的共享数据进行相应的原子操作处理; 其中, 所 述各个原子操作的类型为根据预置的逻辑对象预先划分的。
3、 如权利要求 1所述的数据库的访问方法, 其特征在于, 所述原子操作 接口包括:
操作系统的内核驱动提供的原子操作接口;
或者, 所述数据库的服务进程提供的原子操作接口。
4、 如权利要求 3所述的数据库的访问方法, 其特征在于, 所述接收对数 据库的共享数据的修改操作请求之前, 所述方法还包括:
将所述数据库的共享数据映射到进程的地址空间中;
根据所述进程的类别, 对所述共享数据映射到的进程设置相应的访问权 限, 所述进程包括应用程序进程和数据库服务进程。
5、 如权利要求 4所述的数据库的访问方法, 其特征在于, 所述根据所述 进程的类别, 对所述共享数据映射到的进程设置相应的访问权限, 包括: 当所述原子操作接口为操作系统的内核驱动提供的原子操作接口时, 将 所述应用程序进程和所述数据库的服务进程对所述共享数据的访问权限设置 为只读权限;
当所述原子操作接口为所述数据库的服务进程提供的原子操作接口时, 将所述应用程序进程对所述共享数据的访问权限设置为只读权限, 将所述数 据库的服务进程对所述共享数据的访问权限设置为读写权限。
6、 如权利要求 1所述的数据库的访问方法, 其特征在于, 所述方法还包 括:
接收对所述数据库的共享数据的读操作请求;
根据所述读操作请求, 访问映射到进程的地址空间的所述数据库的共享 数据。
7、 如权利要求 6所述的数据库的访问方法, 其特征在于, 所述方法还包 括:
遍历访问所述数据库的共享数据产生的会话表, 获取一个会话; 根据所述会话绑定的应用程序标识码 ID判定所述应用程序退出时, 若所 述会话还有未完成的事务, 释放所述未完成的事务所使用的闩; 将所述未完 成的事务回滚, 将所述会话设为空闲状态。
8、 如权利要求 2所述的数据库的访问方法, 其特征在于, 所述逻辑对象 包括以下几种对象中的一个或多个:
内存对像, 数据对象, 以及索引对象。
9、 一种数据库访问装置, 其特征在于, 包括:
接收模块, 用于接收对数据库的共享数据的修改操作请求, 所述数据库 的共享数据映射到了进程的地址空间中;
分解模块, 用于将所述修改操作请求分解为预置个数的原子操作序列; 调用模块, 用于按照各个原子操作序列的执行顺序, 调用原子操作接口; 原子访问模块, 用于通过所述原子操作接口提供的原子操作, 访问映射 到进程的地址空间的所述数据库的共享数据。
10、 如权利要求 9 所述的数据库访问装置, 其特征在于, 所述原子访问 模块包括:
类型获取单元, 用于获取所述各个原子操作序列的类型, 所述各个原子 操作的类型为根据预置的逻辑对象预先划分的;
处理单元, 用于根据所述各个原子操作序列的类型, 通过所述原子操作 接口对映射到进程的地址空间的所述数据库的共享数据进行相应的原子操作 操作处理。
11、 如权利要求 9 所述的数据库访问装置, 其特征在于, 所述装置还包 括:
加载模块, 用于将所述数据库的共享数据映射到进程的地址空间中; 权限设置模块, 用于根据所述进程的类别, 对所述共享数据映射到的进 程设置相应的访问权限, 所述进程包括应用程序进程和数据库服务进程。
12、 如权利要求 11所述的数据库访问装置, 其特征在于, 所述权限设置 模块包括:
第一权限设置单元, 用于当所述原子操作接口为操作系统的内核驱动提 供的原子操作接口时, 将所述应用程序进程和所述数据库的服务进程对所述 共享数据的访问权限设置为只读权限; 或者 第二权限设置单元, 用于当所述原子操作接口为所述数据库的服务进程 提供的原子操作接口时, 将所述应用程序进程对所述共享数据的访问权限设 置为只读权限, 将所述数据库的服务进程对所述共享数据的访问权限设置为 读写权限。
13、 如权利要求 9所述的数据库访问装置, 其特征在于,
所述接收模块还用于, 接收对所述数据库的共享数据的读操作请求; 所述装置还包括读操作处理模块, 用于根据所述读操作请求, 直接访问 映射到进程空间的所述数据库的共享数据。
14、 如权利要求 13所述的数据库访问装置, 其特征在于, 所述装置还包 括:
异常处理模块, 用于遍历访问所述数据库的共享数据产生的会话表, 获 取一个会话; 根据所述会话绑定的应用程序标识码 ID判定所述应用程序退出 时, 若所述会话还有未完成的事务, 释放所述未完成的事务所使用的闩; 将 所述未完成的事务回滚, 将所述会话设为空闲状态。
15、 一种数据库应用系统, 其特征在于, 包括: 用于存储数据的数据库 和如权利要求 9 - 14任一项权利要求所述的数据库访问装置; 所述数据库访问 装置用于对所述数据库进行访问。
PCT/CN2010/080435 2010-02-12 2010-12-29 数据库的访问方法、装置及数据库应用系统 WO2011097932A1 (zh)

Priority Applications (3)

Application Number Priority Date Filing Date Title
EP10845602.1A EP2500831A4 (en) 2010-02-12 2010-12-29 METHOD AND DEVICE FOR ACCESSING A DATABASE AND DATABASE APPLICATION SYSTEM
US13/487,849 US20120239634A1 (en) 2010-02-12 2012-06-04 Method and apparatus for accessing database and database application system
US13/903,724 US20130262426A1 (en) 2010-02-12 2013-05-28 Method and apparatus for accessing database and database application system

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN2010101136320A CN102156700A (zh) 2010-02-12 2010-02-12 数据库的访问方法、装置及系统
CN201010113632.0 2010-02-12

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US13/487,849 Continuation US20120239634A1 (en) 2010-02-12 2012-06-04 Method and apparatus for accessing database and database application system

Publications (1)

Publication Number Publication Date
WO2011097932A1 true WO2011097932A1 (zh) 2011-08-18

Family

ID=44367231

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2010/080435 WO2011097932A1 (zh) 2010-02-12 2010-12-29 数据库的访问方法、装置及数据库应用系统

Country Status (4)

Country Link
US (2) US20120239634A1 (zh)
EP (1) EP2500831A4 (zh)
CN (1) CN102156700A (zh)
WO (1) WO2011097932A1 (zh)

Families Citing this family (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102760155B (zh) * 2012-05-30 2018-02-13 中兴通讯股份有限公司 一种基于数据库的事务控制方法及装置
CN102984277B (zh) * 2012-12-17 2015-11-25 北京奇虎科技有限公司 防止恶意连接的系统和方法
CN104820508A (zh) * 2014-01-30 2015-08-05 联发科技(新加坡)私人有限公司 设定权限的数据共享方法以及触控电子装置
CN104021145B (zh) * 2014-05-16 2018-03-06 华为技术有限公司 一种混合业务并发访问的方法和装置
GB2527529B (en) * 2014-06-24 2021-07-14 Advanced Risc Mach Ltd A device controller and method for performing a plurality of write transactions atomically within a non-volatile data storage device
CN105550178A (zh) * 2014-10-29 2016-05-04 中兴通讯股份有限公司 一种数据库的处理方法、装置及系统
CN104881330B (zh) * 2015-05-22 2018-08-21 大唐移动通信设备有限公司 一种多进程共享数据的方法和装置
CN106527958B (zh) 2015-09-09 2020-03-10 阿里巴巴集团控股有限公司 用于分布式存储系统的写入数据、获取数据的方法和设备
US10929573B2 (en) * 2017-03-21 2021-02-23 The Boeing Company Systems and methods for designing and modeling products in a cloud environment
US10877992B2 (en) 2017-11-30 2020-12-29 International Business Machines Corporation Updating a database
CN110287044B (zh) * 2019-07-02 2021-08-03 广州虎牙科技有限公司 无锁共享内存处理方法、装置、电子设备及可读存储介质
CN110347533A (zh) * 2019-07-11 2019-10-18 中国工商银行股份有限公司 数据异常的处理方法、装置、计算设备及介质
CN113141235B (zh) * 2020-01-20 2022-07-22 华为技术有限公司 处理数据的方法和相关装置
CN111984998A (zh) * 2020-08-20 2020-11-24 北京人大金仓信息技术股份有限公司 数据库的强制访问控制方法和装置
CN112115097B (zh) * 2020-09-28 2023-08-29 合肥沛睿微电子股份有限公司 运行日志信息的访问方法及存储设备
CN113342805B (zh) * 2021-04-21 2023-04-11 湖北微源卓越科技有限公司 多进程共享数据的系统及方法
CN115203176B (zh) * 2022-09-15 2023-03-07 太平金融科技服务(上海)有限公司深圳分公司 数据库操作方法、装置、设备、存储介质和程序产品

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101082928A (zh) * 2007-06-25 2007-12-05 腾讯科技(深圳)有限公司 一种数据库访问的方法及数据库映射系统
CN101221565A (zh) * 2007-12-20 2008-07-16 康佳集团股份有限公司 一种利用嵌入式数据库对flash数据进行管理的方法
CN101295306A (zh) * 2007-04-26 2008-10-29 国际商业机器公司 目录服务器中的修改条目名称操作方法和相应设备
CN101520797A (zh) * 2009-02-11 2009-09-02 国电南瑞科技股份有限公司 电力系统跨平台大数据文件高速并发存取方法

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6457021B1 (en) * 1998-08-18 2002-09-24 Microsoft Corporation In-memory database system
CN100353325C (zh) * 2004-08-23 2007-12-05 华为技术有限公司 实现共享内存数据库的方法及内存数据库系统
CN100433011C (zh) * 2006-01-17 2008-11-12 中兴通讯股份有限公司 嵌入式环境下内存数据库的一致性保护方法
KR100790991B1 (ko) * 2006-03-22 2008-01-03 삼성전자주식회사 데이터베이스 관리 시스템을 이용하여 파일시스템의메타데이터를 관리하는 방법
CN1885882A (zh) * 2006-06-29 2006-12-27 上海交通大学 基于嵌入式移动数据库的短信息管理系统
CN201289643Y (zh) * 2008-10-21 2009-08-12 上海第二工业大学 基于fpga的嵌入式数据库系统

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101295306A (zh) * 2007-04-26 2008-10-29 国际商业机器公司 目录服务器中的修改条目名称操作方法和相应设备
CN101082928A (zh) * 2007-06-25 2007-12-05 腾讯科技(深圳)有限公司 一种数据库访问的方法及数据库映射系统
CN101221565A (zh) * 2007-12-20 2008-07-16 康佳集团股份有限公司 一种利用嵌入式数据库对flash数据进行管理的方法
CN101520797A (zh) * 2009-02-11 2009-09-02 国电南瑞科技股份有限公司 电力系统跨平台大数据文件高速并发存取方法

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP2500831A4 *

Also Published As

Publication number Publication date
US20120239634A1 (en) 2012-09-20
EP2500831A1 (en) 2012-09-19
US20130262426A1 (en) 2013-10-03
EP2500831A4 (en) 2014-07-30
CN102156700A (zh) 2011-08-17

Similar Documents

Publication Publication Date Title
WO2011097932A1 (zh) 数据库的访问方法、装置及数据库应用系统
US9129058B2 (en) Application monitoring through continuous record and replay
EP3217285B1 (en) Transmitting data
US20160119198A1 (en) Deep Packet Inspection Method and Device, and Coprocessor
US11934383B2 (en) Mimetic database-based network operating system design method
WO2022151776A1 (zh) 一种云平台虚拟机回收方法及计算机设备
US20160034582A1 (en) Computing device and method for executing database operation command
CN109923547B (zh) 程序行为监控设备、分布式对象生成管理设备、存储介质、以及程序行为监视系统
WO2012083797A1 (zh) 一种分布式文件系统的写锁定方法及系统
US8572627B2 (en) Providing supplemental semantics to a transactional queue manager
WO2020000716A1 (zh) 大数据分析系统、服务器、数据处理方法、程序和存储介质
CN113157411B (zh) 一种基于Celery的可靠可配置任务系统及装置
WO2023284473A1 (zh) 数据管理方法、装置、计算机设备及存储介质
US20230401241A1 (en) System for lightweight objects
WO2022242372A1 (zh) 对象处理方法、装置、计算机设备和存储介质
WO2021139113A1 (zh) 交易信息的加签方法、装置、计算机设备和存储介质
CN111221642B (zh) 一种数据处理方法、装置、存储介质及终端
US9009731B2 (en) Conversion of lightweight object to a heavyweight object
US8635331B2 (en) Distributed workflow framework
CN114356599A (zh) 业务消息处理系统及方法
CN114036164A (zh) 一种乐观锁和悲观锁组合的高并发交易加锁方法及系统
Spector Communication support in operating systems for distributed transactions
WO2023221804A1 (zh) 内存管理方法、网络设备及计算机可读存储介质
WO2005020074A1 (ja) コンピュータシステム及びそれに用いるプログラム実行環境実現方法並びにそのプログラム
Abdulla et al. Automatic verification of directory-based consistency protocols with graph constraints

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 10845602

Country of ref document: EP

Kind code of ref document: A1

REEP Request for entry into the european phase

Ref document number: 2010845602

Country of ref document: EP

WWE Wipo information: entry into national phase

Ref document number: 2010845602

Country of ref document: EP

NENP Non-entry into the national phase

Ref country code: DE