A method and apparatus for reading and writing database files

By opening files in Oracle ASM and using file mapping tables and data block legality checks, the problem of low read and write performance of Oracle ASM files is solved, efficient reading of the latest data block content is achieved, and database files are improved.

CN118981451BActive Publication Date: 2025-07-11DISJIE (BEIJING) DATA MANAGEMENT TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411051507.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-01
Publication Date
2025-07-11
Estimated Expiration
2044-08-01

AI Technical Summary

Technical Problem

Oracle ASM files have poor read and write performance, especially in the precise data block reading and writing scenarios, and the latest data block content cannot be read in real time.

Method used

Provides a database file reading and writing method, which can effectively read and write data block content by opening the target file in Oracle ASM, obtaining read and write file handles, and combining file mapping tables and data block legality checks.

Benefits of technology

Improves Oracle ASM file reading performance, ensures the latest data block contents are read, and improves file reading performance close to disk read and write levels, suitable for real-time database files.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118981451B_ABST
    Figure CN118981451B_ABST
Patent Text Reader

Abstract

The present application provides a method and apparatus for reading and writing database files. The method includes: inputting a target file name, opening the target file in Oracle ASM and returning a read / write file handle of the target file; using the returned read / write file handle of the target file as an input condition, reading the target file according to the size of the data to be read and the memory; using the returned read / write file handle of the target file as an input condition, inputting the write data memory and the data size, and writing the data to be written into the memory to the storage location of the target file; after the file read / write is completed, releasing the resources occupied by the read / write file handle, and actually writing the data in the cache to the storage location corresponding to the file. Based on the solution provided by the present application, when reading Oracle ASM storage files, it is possible to ensure a substantial improvement in file reading performance on the basis of reading the latest data, and there will be a substantial improvement in performance compared to directly calling the Oracle SQL execution mode to read files.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of databases, and in particular, to a method and device for reading and writing database files. Background Art

[0002] Oracle ASM is a volume management developed by Oracle Database to manage its own related data files. It can automatically manage disk groups and provide an effective data redundancy system. It is installed and deployed as a separate Oracle instance. Due to the existence of Oracle ASM, the original Oracle files that were directly stored under the operating system and could be directly and normally read now have to be indirectly read through Oracle's own interface.

[0003] The defects of the file read and write interface provided by Oracle are as follows: When an accurate data block read and write scenario needs to be applied, directly calling the interface provided by Oracle results in relatively poor read and write performance. Reading real-time changing files in the ASM storage format not made public by Oracle may also result in the inability to read the latest data block, leading to incorrect data reading. Real-time change means that during the operation of the Oracle database, the content of the files it manages will change dynamically. If the ASM storage format is used to read real-time changing data, in many cases, the content of the latest file data block cannot be read.

[0004] The main types of files managed in Oracle ASM are data files, log files, and control files. These files all adopt a block management mode, dividing a large file into multiple different integer data blocks according to the configured data block size. The commonly used data block size of Oracle data files is 8K (8192 bytes), and the commonly used data block size of Oracle log files is 512 bytes. Oracle ASM uses individual storage units to manage various files inside. Usually, the size of a storage unit is 1M (1048576 bytes), and the storage unit size is much larger than the data block size. Many integer file data blocks can be stored under one storage unit.

[0005] Under the influence of the Oracle Database Automatic Storage Management System, in many scenarios of fine-grained development, a faster and better method must be found to read and write files in Oracle ASM. Due to various limitations of Oracle itself, or rather, Oracle Database does not provide a method to accurately read and write its internal data files in terms of data blocks. As mentioned before, the corresponding interface provided by Oracle was only used by Oracle's own management script program to complete the corresponding functions when Oracle ASM was first introduced. Therefore, it can be indirectly guessed that Oracle has a similar interface internally, but there has never been a complete document. However, the performance of this interface (or the interface for accessing files) is very poor, only about 10%-20% of the normal disk read and write performance. Later, after the Oracle Database version was gradually upgraded, this part of the function completely disappeared, but the interfaces used in the early applications can still be used, and there is no complete introduction document for this part of the interfaces. There is also a method that, after understanding the internal structure of the Oracle ASM storage management system, reads files in ASM according to the ASM storage allocation mechanism. This method is only suitable for static databases, and the latest data may not be read through this method for files that are changing in real time. Oracle ASM is like a black box that stores the database's data files, log files, and control files. However, the method provided by Oracle for accurate file reading and writing (that is, reading and writing according to data blocks) has too low performance. Therefore, it is difficult when a software needs to perform accurate file reading and writing based on Oracle files. Summary of the Invention

[0006] This application aims to at least solve one of the technical problems in the related art to some extent.

[0007] To this end, the first objective of this application is to propose a method for reading and writing database files to more conveniently read and write Oracle ASM files.

[0008] The second objective of this application is to propose a device for reading and writing database files.

[0009] To achieve the above objective, the first aspect embodiment of this application proposes a method for reading and writing database files, including:

[0010] Input the target file name, open the target file in Oracle ASM and return the read and write file handle of the target file;

[0011] Using the returned read and write file handle of the target file as the input condition, read the target file according to the size of the data to be read and the memory.

[0012] Taking the read / write file handle of the returned target file as the input condition, inputting the data memory to be written and the data size, and writing the data that needs to be written into the memory to the storage location of the target file;

[0013] After the reading and writing of the target file is completed, release the resources occupied by the read / write file handle, and actually write the data in the cache to the storage location corresponding to the target file.

[0014] Optionally, before inputting the target file name, it further includes:

[0015] Connect to the Oracle ASM database instance, query the ASM management disk group name, disk detailed information, and ASM allocation unit size information;

[0016] Create the memory structure required inside the local ASM module.

[0017] Optionally, inputting the target file name, opening the target file in Oracle ASM and returning the read / write file handle of the target file includes:

[0018] Query the Oracle ASM database instance according to the input file name to obtain the storage file number of the target file in Oracle ASM;

[0019] Query the storage file number in the Oracle ASM internal table to obtain the file storage mapping table of the target file sorted by data blocks;

[0020] Based on the file storage mapping table, call the Oracle ASM package to obtain the file attribute information of the target file;

[0021] Based on the file attribute information, call the Oracle ASM package to execute the opening of the target file, establish a file mapping table in combination with the query process of the Oracle ASM internal table, and return the read / write file handle to the upper layer after the target file is opened.

[0022] Optionally, taking the read / write file handle of the returned target file as the input condition, reading the target file according to the data size and memory required includes:

[0023] Read the memory structure information of the target file according to the read / write file handle to obtain the file mapping table and the read / write offset position information of the current target file;

[0024] Search the file mapping table according to the read / write offset position information to obtain the disk group name and disk offset information of Oracle ASM corresponding to the current offset position;

[0025] Read the content of the corresponding data block of the target file from the Oracle ASM disk into memory, and perform a data block legality check on the data read from the disk;

[0026] Return the data blocks that pass the data check to the upper layer for use, and move the offset of the target file to increase by the size of the corresponding data block;

[0027] Check whether the data after offset has been completely read. Stop reading until no data can be read or the remaining size of the read data is 0, and return the read length.

[0028] Optionally, the data block legality check on the data read from the disk includes:

[0029] Extract the internal checksum of the data block, the SCN information of the data block, and the block number information of the data block when the target file is opened;

[0030] Calculate a new checksum based on the data read from the disk, and determine whether the new checksum is consistent with the internal checksum of the data block extracted when the target file is opened. If they are inconsistent, the data is considered illegal;

[0031] Determine whether the block number information of the data read from the disk is consistent with the block number information of the data block extracted when the target file is opened. If they are inconsistent, the data is considered illegal.

[0032] Compare the SCN information of the data block with the start SCN and end SCN recorded in the read data file header. If the SCN in the data block is greater than the start SCN of the read data file header record, or the SCN in the data block is less than the end SCN of the read data file header record, the data is considered illegal.

[0033] Optionally, it further includes:

[0034] If the data is illegal, perform data repair processing on the illegal data. The repair processing includes reconstructing some data blocks and rereading some data blocks by calling the data packet interface provided by the database.

[0035] Optionally, with the read / write file handle of the returned target file as the input condition, input the write data memory and data size, and write the data that needs to be written into the memory to the storage location of the target file, including:

[0036] Extract the memory structure information when the target file is opened according to the read / write file handle to obtain the file mapping table and the read / write offset position information of the current target file;

[0037] Search the file mapping table according to the read / write offset position information to obtain the disk group information of the Oracle ASM corresponding to the current offset position and the write disk offset;

[0038] Based on the disk group information of Oracle ASM corresponding to the current offset position and the offset of writing to the disk, write the input write data to the corresponding Oracle ASM disk, and move the target file offset after writing is completed;

[0039] Check whether the data after offset is written completely. If it is not written completely, repeatedly execute the writing process in a loop until the input data is written completely.

[0040] Optionally, it further includes:

[0041] Based on the read / write offset position information of the current target file, according to the given value of the file offset to be moved, move the target file offset during the read / write process according to the whence parameter; wherein, during the read process, the value of the file offset to be moved is the increased legal data block size; wherein, during the write process, the value of the file offset to be moved is the size of the written data.

[0042] Optionally, after the read / write of the target file is completed, releasing the resources occupied by the read / write file handle includes:

[0043] After the file read / write is completed, extract the memory structure information when the target file is opened according to the read / write file handle, and call the system memory release interface to release the memory structure information allocated when the target file is opened.

[0044] To achieve the above object, an embodiment of the second aspect of the present application proposes a database file read / write device, including:

[0045] An opening module, configured to input a target file name, open the target file in Oracle ASM and return the read / write file handle of the target file;

[0046] A reading module, configured to use the returned read / write file handle of the target file as an input condition, and read the target file according to the data size and memory to be read;

[0047] A writing module, configured to use the returned read / write file handle of the target file as an input condition, input the write data memory and data size, and write the data to be written into the memory to the storage location of the target file;

[0048] A closing module, configured to release the resources occupied by the read / write file handle after the file read / write is completed, and actually write the data in the cache to the storage location corresponding to the file.

[0049] The technical solutions provided by the embodiments of the present application at least bring the following beneficial effects:

[0050] By using this method to read Oracle ASM storage files, it is possible to significantly improve the file reading performance on the basis of ensuring the latest data is read. That is, for Oracle database files with real-time changes, the latest data block content can also be read, and the file reading performance is basically close to the disk read and write performance; in the intermediate machine mode, by setting up a remote file read and write connection proxy program, it is also possible to quickly read Oracle ASM files, and the performance of this method is significantly improved compared to directly calling the Oracle SQL execution mode to read files; using this method can make the application software developed based on Oracle file reading more efficient.

[0051] Additional aspects and advantages of the present application will be given in part in the following description, become apparent in part from the following description, or be understood through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0052] The above and / or additional aspects and advantages of the present application will become apparent and be readily understood from the following description of the embodiments in conjunction with the drawings, in which:

[0053] Figure 1 is a flowchart of a method for reading and writing database files according to an embodiment of the present application;

[0054] Figure 2 is a flowchart of the database file reading steps according to an embodiment of the present application;

[0055] Figure 3 is a block diagram of a device for reading and writing database files according to an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0056] The embodiments of the present application will be described in detail below. The examples of the embodiments are shown in the drawings, where the same or similar reference numerals represent the same or similar elements or elements with the same or similar functions throughout. The embodiments described below with reference to the drawings are exemplary and are intended to explain the present application and should not be construed as limiting the present application.

[0057] The present application will ultimately implement data reading and writing with an ASM module, providing an Oracle ASM file access interface externally. External application programs can more conveniently read and write Oracle ASM files by calling this ASM module.

[0058] The following will detail the specific implementation method inside the newly developed ASM module by specifically reading a certain actual Oracle ASM database file.

[0059] Figure 1 is a flowchart of a method for reading and writing database files according to an embodiment of the present application, as Figure 1As shown in the figure, the method includes the following steps:

[0060] Step 101, input the target file name, open the target file in Oracle ASM and return the read / write file handle of the target file.

[0061] In the embodiment of the present application, before the overall ASM module read / write interface is started, a mount action similar to that of a file system needs to be performed. This action mainly completes the reading of the basic metadata of the database ASM instance, the initialization of the internal data structure of the read / write interface, and makes more preparations for the subsequent rapid response to the actual data file reading and writing.

[0062] It can be understood that there is also an unmount action corresponding to this mount action. The tasks completed by unmount are basically the opposite of those of the mount action. It mainly releases the resources (memory, database connection, file handle) used during the file access process. Since the mount and unmount actions are relatively time-consuming, they are basically one-time actions in data processing. Usually, in an actual application program, the mount task is completed at the beginning of the program startup, and the unmount action is performed when the program stops.

[0063] Specifically, before inputting the target file name, a mount action is performed, including connecting to the Oracle ASM database instance, querying the ASM management disk group name, disk detailed information, ASM allocation unit size information, etc., and creating the memory structure required inside the local ASM module to make more preparations for the subsequent reading and writing of files.

[0064] After the reading and writing are completed, an unmount action is performed, disconnecting from the Oracle ASM database instance and closing the locally opened cache file. Release the allocated memory resources. This interface is called when the entire program stops and is specifically described in subsequent step 104.

[0065] In the embodiment of the present application, a certain Oracle ASM file is read and written by calling the open interface, and finally a read / write file handle is returned to the upper layer. To be different from the file handle returned by the operating system when opening a file, the file handle is set to be relatively large. The size of the file handle returned by the operating system is usually below 65535. Therefore, the size of the ASM module open file handle is the sequence number plus 65535, so that it can be ensured that it can be directly distinguished whether the opened file is an Oracle ASM file or an operating system file through the file handle. The definition of this open interface is:

[0066] extern int asm_open(const char*fn,int mode);

[0067] The meanings, names, and types of related parameters are shown in Table 1.

[0068] Table 1

[0069]

[0070] The return value of this function: less than 0 indicates failure, greater than 0 indicates success, and at the same time, a file descriptor is returned.

[0071] Specifically, step 101 further includes:

[0072] Step 201: Query the Oracle ASM database instance according to the input file name to obtain the storage file number of the target file in Oracle ASM.

[0073] In an embodiment of the present application, according to the input file name, combined with the disk name, file type, file label, etc. stored in Oracle ASM, query the Oracle ASM database instance to obtain the unique identifier of the target file in Oracle ASM, that is, the storage file number. It should be noted that this storage file number must be a number.

[0074] In addition, the files in Oracle ASM can also exist in the form of aliases. For this type of file, it is necessary to query the Oracle ASM v$ASM_ALIAS view to obtain the file unique identifier. The V$ASM_ALIAS view is a data dictionary that provides detailed information about the aliases defined in ASM.

[0075] Step 202: Query the storage file number in the Oracle ASM internal table to obtain the file storage mapping table of the target file sorted by data blocks.

[0076] After obtaining the unique identifier of the target file, that is, the storage file number, query this storage file number in the Oracle ASM internal table to obtain the file storage mapping table of the target file sorted by data blocks.

[0077] It should be noted that the Oracle table to be queried in this step is X$KFFXP. This file storage mapping table can accurately read the content of the Oracle ASM file data block in combination with the disk group information during the previous mount. However, the read content is not yet complete, and the data read may not be the latest data block data for a changing database.

[0078] Step 203: Based on the file storage mapping table, call the Oracle ASM package to obtain the file attribute information of the target file.

[0079] In this step, the Oracle ASM package is called to obtain file attribute information, which will be applied to the subsequent opening operation. This part needs to call the DBMS_DISKGROUP.GETFILEATTR package.

[0080] It can be understood that DBMS_DISKGROUP.GETFILEATTR is a procedure in the Oracle internal package DBMS_DISKGROUP, used to obtain the attributes of ASM files. This procedure allows database administrators or developers to retrieve the attribute information of specific ASM files by providing parameters such as file name, file type, file size, and block size.

[0081] Step 204: Based on the file attribute information, call the Oracle ASM package to open the target file, establish a file mapping table in combination with the query process of the Oracle ASM internal table, and return a read / write file handle to the upper layer after the target file is opened.

[0082] In the embodiment of the present application, according to the file attribute information provided in step 203, the Oracle ASM package is called to perform the file opening task. This part needs to call the DBMS_DISKGROUP.OPEN package.

[0083] In an embodiment of the present application, the file mapping table and the read / write file handle returned by DBMS_DISKGROUP.OPEN are finally stored in the handle list of the local ASM module. After the entire ASM file opening is completed, a file handle will be returned to the upper layer. This handle is 65535 plus the sequence number of the file in the ASM module. After the above steps, the entire Oracle ASM file opening task is completed, and then the target file can be read and written.

[0084] Step 102: Using the returned read / write file handle of the target file as the input condition, read the target file according to the data size and memory required to be read.

[0085] In the embodiment of the present application, the file data stored in Oracle ASM is read into the input memory by calling the read interface. The definition of this interface is:

[0086] extern ssize_t asm_read(int fd,void*buf,size_t count);

[0087] The meanings, names, and types of the relevant parameters are shown in Table 2.

[0088] Table 2

[0089]

[0090] The function returns -1 to indicate a read error, a value greater than 0 to indicate the size of the read data, and 0 to indicate that there is no data to read.

[0091] Specifically, the internal implementation process of the read interface is as follows:

[0092] Step 301: Read the memory structure information of the target file according to the read / write file handle to obtain the file mapping table and the read / write offset position information of the current target file.

[0093] In the embodiment of the present application, the internal management structure in the ASM module is found according to the input read / write file handle, and then the memory structure information of the opened file is obtained. The last read / write offset position information of the file can be obtained from the memory structure information, and according to this offset position information, it can be known which specific part of the file is to be read next.

[0094] Step 302: Search the file mapping table according to the read / write offset position information to obtain the disk group name and disk offset information of the Oracle ASM corresponding to the current offset position.

[0095] In the embodiment of the present application, the file mapping table of the opened part of the file is searched according to the file read / write offset position information to find the disk group name and disk offset information of the Oracle ASM corresponding to this offset position.

[0096] Step 303: Read the corresponding data block content of the target file from the Oracle ASM disk into the memory, and perform a data block legality check on the data read from the disk.

[0097] In the embodiment of the present application, the corresponding data block content is read from the Oracle ASM disk into the memory. If the corresponding file on the disk is not opened, the file needs to be opened first.

[0098] It can be understood that a data block legality check needs to be performed on the data read from the disk. The main purpose of the legality check is that the data read directly from the ASM disk may be incorrect or the latest data block cannot be read. The key structure information required for the check includes: the file type information when the file is opened, the block number information of the current checked data block, the internal check code of the data block, and the SCN information of the data block.

[0099] Specifically, the steps of the legality check are as follows:

[0100] Calculate a new check code according to the data read from the disk, and determine whether the new check code is consistent with the internal check code of the data block extracted when the target file is opened. If they are inconsistent, the data is considered illegal;

[0101] Determine whether the block number information of the data read from the disk is consistent with the block number information of the data block extracted when the target file is opened. If they are inconsistent, the data is considered illegal.

[0102] Compare the SCN information of the data block with the start SCN and end SCN recorded in the read data file header. If the SCN in the data block is greater than the start SCN recorded in the read data file header, or the SCN in the data block is less than the end SCN recorded in the read data file header, the data is considered illegal.

[0103] Step 304: Return the data blocks that pass the data legality check to the upper layer for use, and move the target file offset to increase by the size of the corresponding data block.

[0104] In the embodiment of the present application, the data blocks that pass the data legality check are directly returned to the upper layer for use, while the illegal data blocks are subjected to data repair processing. Some data blocks are reconstructed, and some data blocks are reread by calling the data packet interface provided by the database.

[0105] After reading this part of the data, increase the file offset by the size of the corresponding data block.

[0106] As a possible implementation, call the lseek interface to change the internal offset of the file that needs to be read and written currently, which is convenient for random file reading operations.

[0107] Definition of the lseek interface:

[0108] extern int64_t asm_lseek(int fd, int64_t ofs, int whence);

[0109] The interface parameters are shown in Table 3.

[0110] Table 3

[0111]

[0112] This lseek interface returns the value of the current internal offset position of the file after actual movement.

[0113] The main internal steps of this lseek interface implementation:

[0114] Obtain the memory structure information of the file when it is opened according to the input parameter fd. The file offset position information is reserved in this file memory structure; extract the total file size information and combine it with the whence parameter to move the file offset value.

[0115] Among them, ofs less than 0 means moving towards the file head direction, and greater than 0 means moving towards the file end position direction. When moving the file offset, it is necessary to prevent exceeding the total file size after moving the offset.

[0116] It can be understood that during the reading process, the moving file offset value is the legal data block size that increases.

[0117] Step 305: Check whether the data after offset has been completely read. Stop reading until no data can be read or the remaining data size is 0, and return the reading length.

[0118] In the embodiment of the present application, if there are multiple data blocks in the data read at one time, the processes of the previous steps 301-304 need to be repeatedly executed in a loop until no data can be read or the remaining data size is 0, that is, until the cache for storing data is full.

[0119] Step 103: Using the read / write file handle of the returned target file as the input condition, input the data memory to be written and the data size, and write the data that needs to be written into the memory to the storage location of the target file.

[0120] In the embodiment of the present application, Oracle format data is written into the Oracle ASM storage by calling the write interface. The definition of the write interface is as follows:

[0121] extern ssize_t asm_write(int fd, const void* buf, size_t count);

[0122] The interface parameters are shown in Table 4.

[0123] Table 4

[0124]

[0125] If the function returns -1, it indicates a write error; if it is greater than 0, it indicates the actual size of the written data.

[0126] Specifically, the internal implementation process of this write interface is as follows:

[0127] Step 401: Extract the memory structure information when the target file is opened according to the read / write file handle, and obtain the file mapping table and the read / write offset position information of the current target file.

[0128] In the embodiment of the present application, referring to Step 301, find the internal management structure of the ASM module according to the input read / write file handle, and then obtain the memory structure information when the file is opened. From the memory structure information, the last read / write offset position information of the file can be obtained. According to this offset position information, it can be known which specific part of the file needs to be written next.

[0129] Step 402: Search the file mapping table according to the read / write offset position information to obtain the disk group information of Oracle ASM corresponding to the current offset position and the offset of the write disk.

[0130] Step 403: Based on the disk group information of Oracle ASM corresponding to the current offset position and the offset of the write disk, write the input write data to the corresponding Oracle ASM disk. After the writing is completed, move the target file offset.

[0131] Step 404: Check whether the data after the offset has been written completely. If not, repeatedly execute the writing process until the input data is written completely.

[0132] It should be noted that when moving the target file offset after the writing is completed, it is implemented by relying on the lseek interface. During the writing process, the value of the moved file offset is the size of the written data.

[0133] Step 104: After the reading and writing of the target file are completed, release the resources occupied by the read / write file handle, and actually write the data in the cache to the storage location corresponding to the target file.

[0134] In the embodiment of the present application, the process of releasing the resources opened by the open interface is implemented by relying on the close interface, that is, all the memory structure information allocated by open is released. The definition of this close interface is:

[0135] extern int asm_close(int fd);

[0136] The interface parameters of this close interface are shown in Table 5.

[0137] Table 5

[0138]

[0139] A return value of 0 indicates that the resource release is successful, and -1 indicates failure.

[0140] The implementation process is that after the file reading and writing are completed, extract the memory structure information when the target file is opened according to the read / write file handle, and call the system memory release interface to release the memory structure information allocated when the target file is opened.

[0141] To implement the above embodiment, the present application also proposes a database file read / write device.

[0142] Figure 3 It is a block diagram of a database file read / write device 10 shown according to the embodiment of the present application, including:

[0143] Open module 100, which is used to input the target file name, open the target file in Oracle ASM and return the read / write file handle of the target file;

[0144] Read module 200, which is used to take the read / write file handle of the returned target file as the input condition and read the target file according to the size of the data to be read and the memory;

[0145] Write module 300, which is used to take the read / write file handle of the returned target file as the input condition, input the write data memory and the data size, and write the data that needs to be written into the memory to the storage location of the target file;

[0146] Close module 400, which is used to release the resources occupied by the read / write file handle after the file reading and writing are completed, and actually write the data in the cache to the storage location corresponding to the file.

[0147] Regarding the device in the above embodiments, the specific ways in which each module performs operations have been described in detail in the embodiments related to the method, and will not be elaborated here.

[0148] It should be understood that various forms of the processes shown above can be used, steps can be reordered, added or deleted. For example, the steps described in this application can be executed in parallel, sequentially or in a different order, as long as the desired results of the technical solution of this application can be achieved, and no limitations are imposed here.

[0149] The above specific implementation manners do not constitute a limitation on the protection scope of this application. Those skilled in the art should understand that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application shall be included within the protection scope of this application.

Claims

1. A method for reading and writing database files, characterized in that, Including: Input the target file name, open the target file in Oracle ASM and return the read / write file handle of the target file; Using the returned read / write file handle of the target file as the input condition, read the target file according to the size of the data to be read and the memory; Using the returned read / write file handle of the target file as the input condition, input the memory for writing data and the data size, and write the data that needs to be written into the memory to the storage location of the target file; After the reading and writing of the target file is completed, release the resources occupied by the read / write file handle, and actually write the data in the cache to the corresponding storage location of the target file; The input of the target file name, opening the target file in Oracle ASM and returning the read / write file handle of the target file includes: Query the Oracle ASM database instance according to the input file name to obtain the storage file number of the target file in Oracle ASM; Query the storage file number in the Oracle ASM internal table to obtain the file storage mapping table of the target file sorted by data blocks; Based on the file storage mapping table, call the Oracle ASM package to obtain the file attribute information of the target file; Based on the file attribute information, call the Oracle ASM package to open the target file, establish a file mapping table in combination with the query process of the Oracle ASM internal table, and return the read / write file handle to the upper layer after the target file is opened; The use of the returned read / write file handle of the target file as the input condition to read the target file according to the size of the data to be read and the memory includes: Read the memory structure information of the target file according to the read / write file handle to obtain the file mapping table and the read / write offset position information of the current target file; Search the file mapping table according to the read / write offset position information to obtain the disk group name and disk offset information of Oracle ASM corresponding to the current offset position; Read the corresponding data block content of the target file from the Oracle ASM disk into the memory, and perform a data block legality check on the data read from the disk; Return the data blocks with legal checked data to the upper layer for use, and move the target file offset to increase the corresponding data block size; Check whether the data after the offset is completely read. Stop reading until no data can be read or the remaining data size is 0, and return the read length; The data block legality check on the data read from the disk includes: Extract the internal check code of the data block, the data block SCN information, and the data block number information when the target file is opened; Calculate a new check code according to the data read from the disk, and judge whether the new check code is consistent with the internal check code of the data block extracted when the target file is opened. If not, the data is considered illegal; Judge whether the data block number information of the data read from the disk is consistent with the data block number information extracted when the target file is opened. If not, the data is considered illegal; Compare the SCN information of the data block with the start SCN and end SCN of the read data file header record. If the SCN in the data block is greater than the start SCN of the read data file header record, or the SCN in the data block is less than the end SCN of the read data file header record, the data is considered illegal.

2. The method according to claim 1, characterized in that, Before inputting the target file name, it also includes: Connect to the Oracle ASM database instance, query the ASM management disk group name, disk detailed information, and ASM allocation unit size information; Create the memory structure required inside the local ASM module.

3. The method according to claim 1, characterized in that, It also includes: If the data is illegal, perform data repair processing on the illegal data. The repair processing includes reconstructing some data blocks and rereading some data blocks by calling the data packet interface provided by the database.

4. The method according to claim 1, wherein Taking the read / write file handle of the returned target file as the input condition, inputting the write data memory and data size, and writing the data that needs to be written into the memory to the storage location of the target file, includes: Extract the memory structure information when the target file is opened according to the read / write file handle to obtain the file mapping table and the read / write offset position information of the current target file; Search the file mapping table according to the read / write offset position information to obtain the Oracle ASM disk group information corresponding to the current offset position and the write disk offset; Based on the Oracle ASM disk group information corresponding to the current offset position and the write disk offset, write the input write data to the corresponding Oracle ASM disk, and move the target file offset after writing is completed; Check whether the data after the offset is written completely. If it is not written completely, repeatedly execute the writing process in a loop until the input data is written completely.

5. The method according to claim 4, wherein It also includes: Based on the read / write offset position information of the current target file, according to the given value of the file offset movement amount, move the target file offset during the read / write process according to the whence parameter; where during the read process, the value of the file offset movement amount is the size of the added legal data block; where during the write process, the value of the file offset movement amount is the size of the written data.

6. The method according to claim 5, wherein After the target file read / write is completed, releasing the resources occupied by the read / write file handle, includes: After the file read / write is completed, extract the memory structure information when the target file is opened according to the read / write file handle, and call the system memory release interface to release the memory structure information allocated when the target file is opened.

7. A database file reading and writing device, characterized in that, Includes: An open module, used to input the target file name, open the target file in Oracle ASM and return the read / write file handle of the target file; A read module, used to take the read / write file handle of the returned target file as the input condition, and read the target file according to the data size and memory required to be read; A write module, used to take the read / write file handle of the returned target file as the input condition, input the write data memory and data size, and write the data that needs to be written into the memory to the storage location of the target file; A close module, used to release the resources occupied by the read / write file handle after the file read / write is completed, and actually write the data in the cache to the storage location corresponding to the file; The opening module is further configured to query the Oracle ASM database instance according to the input file name, and obtain the storage file number of the target file in the Oracle ASM; Query the storage file number in the Oracle ASM internal table to obtain the file storage mapping table of the target file sorted by data blocks; Based on the file storage mapping table, call the Oracle ASM package to obtain the file attribute information of the target file; Based on the file attribute information, call the Oracle ASM package to execute the opening of the target file, establish a file mapping table in combination with the query process of the Oracle ASM internal table, and return a read / write file handle to the upper layer after the target file is opened; The reading module is further configured to read the memory structure information of the target file according to the read / write file handle to obtain the file mapping table and the read / write offset position information of the current target file; Search the file mapping table according to the read / write offset position information to obtain the disk group name and disk offset information of the Oracle ASM corresponding to the current offset position; Read the corresponding data block content of the target file from the Oracle ASM disk into the memory, and perform a data block legality check on the data read from the disk; Return the data blocks with legal checked data to the upper layer for use, and move the target file offset to increase the corresponding data block size; Check whether the data after the offset is completely read until no data can be read or the remaining size of the read data is 0, end the reading, and return the reading length; The data block legality check on the data read from the disk includes: Extract the internal check code of the data block, the data block SCN information, and the data block number information when the target file is opened; Calculate a new check code according to the data read from the disk, and determine whether the new check code is consistent with the internal check code of the data block extracted when the target file is opened. If they are inconsistent, the data is considered illegal; Determine whether the data block number information of the data read from the disk is consistent with the data block number information extracted when the target file is opened. If they are inconsistent, the data is considered illegal; Compare the data block SCN information with the start SCN and end SCN recorded in the read data file header. If the SCN in the data block is greater than the start SCN of the read data file header record, or the SCN in the data block is less than the end SCN of the read data file header record, the data is considered illegal.

Citation Information

Patent Citations

  • Method for realizing local file system through object storage system

    CN107045530A

  • File analysis method oriented to ASM (Automated Storage Management) file system

    CN107622123A