Summary of the invention
In internal memory, take up room excessive at metadata in the correlation technique, the problem that causes system reliability to reduce, the present invention proposes the method and apparatus that a kind of metadata is handled, and can save the storage space of metadata in internal memory, and guarantee the reliability of system.
Technical scheme of the present invention is achieved in that
According to an aspect of the present invention, proposed the method that a kind of metadata is handled, this method comprises:
The metadata store of needs storages to internal memory, when the metadata of having stored in the internal memory reaches under the situation of preset value, is set up data structure in internal memory;
For the new metadata of needs storages, generate the index of new metadata and with the index stores that generates to data structure.
Wherein, the index stores that generates is further comprised to data structure:
Generate index according to the metadata of having stored in the internal memory, if do not have index in the data structure, then with the index stores that generates to data structure, and the index metadata corresponding that will generate is deleted from internal memory.
And, the index stores that generates is further comprised to data structure:
Generate index according to the metadata of having stored in the internal memory, if had index in the data structure, then the index metadata corresponding that generates is deleted from internal memory.
And, when needs are carried out the operation of metadata correspondence, the index that is recorded in the data structure is read from internal memory, the index of reading is reverted to metadata and carry out the corresponding operation of this metadata.
In addition, if in the process of generator data directory the generation systems fault, then stop to generate index according to new metadata, and after the system failure is eliminated, continue according to new metadata generate index and with the index stores of generation to data structure.
In addition, after the system failure is eliminated, if there are not the difference data in the metadata of memory, then when needs are carried out the operation of metadata correspondence, the index that is recorded in the data structure is read from internal memory, the index of reading is reverted to metadata and carry out the corresponding operation of this metadata.
And, after the system failure is eliminated, if there are the difference data in the metadata of memory, then the difference data carried out synchronously and generate index according to the data synchronously, with the index stores of the data correspondence after synchronously to data structure;
When needs are carried out the operation of metadata correspondence, the index that is recorded in the data structure is read from internal memory, the index of reading is reverted to metadata and carry out the corresponding operation of this metadata.
According to another aspect of the present invention, proposed the device that a kind of metadata is handled, this device comprises:
Memory module, the metadata store that is used for will needing to store when the metadata of having stored in the internal memory reaches under the situation of preset value, is set up data structure to internal memory in internal memory;
Generation module, for the new metadata of needs storages, be used for generating the index of new metadata and with the index stores that generates to data structure.
Wherein, this device further comprises:
Removing module, after the index stores that will generate is to data structure, generation module generates index according to the metadata of having stored in the internal memory, if do not have index in the data structure, then with the index stores that generates to data structure, the index metadata corresponding that removing module will generate is deleted from internal memory.
And after the index stores that will generate was to data structure, generation module generated index according to the metadata of having stored in the internal memory, if had index in the data structure, then removing module is deleted the index metadata corresponding that generates from internal memory.
The present invention by the metadata store that will need to store to internal memory, when the metadata of having stored in the internal memory reaches under the situation of preset value, in internal memory, set up data structure, new metadata for the needs storage, generate the index of new metadata and with the index stores that generates to data structure, can save the storage space of metadata in internal memory, and guarantee the reliability of system.
Embodiment
Below in conjunction with the accompanying drawing in the embodiment of the invention, the technical scheme in the embodiment of the invention is clearly and completely described, obviously, described embodiment only is the present invention's part embodiment, rather than whole embodiment.Based on the embodiment among the present invention, the every other embodiment that those of ordinary skills obtain belongs to the scope of protection of the invention.
According to embodiments of the invention, the method that provides a kind of metadata to handle.
As shown in Figure 1, the method for handling according to the metadata of the embodiment of the invention comprises:
Step S101 to internal memory, when the metadata of having stored in the internal memory reaches under the situation of preset value, sets up data structure with the metadata store of needs storages in internal memory;
Step S103, for the new metadata of needs storages, generate the index of new metadata and with the index stores that generates to data structure.
For example, can in internal memory, set up a B+ tree (corresponding to above-mentioned data structure), the information that in this B+ tree, has comprised whole key words in all leaf node, and sensing contains the pointer of these keyword record, and leaf node can link in proper order according to the arrangement requirement of key word, therefore, B+ tree canned data is exactly the index of metadata.
Wherein, index stores to the processing procedure in the data structure that generates is further comprised: generate index according to the metadata of having stored in the internal memory, if do not have index in the data structure, then with the index stores that generates to data structure, and the index metadata corresponding that will generate is deleted from internal memory.
And, index stores to the processing procedure in the data structure that generates be may further include: generate index according to the metadata of having stored in the internal memory, if had index in the data structure, then the index metadata corresponding that generates is deleted from internal memory.By generating index stores to data structure according to the metadata of having stored, and metadata deleted, can effectively save the space of internal memory, and avoid both having preserved metadata for same object in the internal memory and also preserved index, can further optimize the utilization of memory headroom.
And, when needs are carried out the operation of metadata correspondence, the index that is recorded in the data structure is read from internal memory, the index of reading is reverted to metadata and carry out the corresponding operation of this metadata.
In addition, if in the process of generator data directory the generation systems fault, then stop to generate index according to new metadata, and after the system failure is eliminated, continue according to new metadata generate index and with the index stores of generation to data structure.
In addition, after the system failure is eliminated, if there are not the difference data in the metadata of memory, then when needs are carried out the operation of metadata correspondence, the index that is recorded in the data structure is read from internal memory, the index of reading is reverted to metadata and carry out the corresponding operation of this metadata.
And, after the system failure is eliminated, if there are the difference data in the metadata of memory, then the difference data carried out synchronously and generate index according to the data synchronously, with the index stores of the data correspondence after synchronously to data structure;
When needs are carried out the operation of metadata correspondence, the index that is recorded in the data structure is read from internal memory, the index of reading is reverted to metadata and carry out the corresponding operation of this metadata.
Because the file size of metadata is all smaller, so, repeatedly identical file is operated and the data volume of log, it might be the multiple of meta data file, so, daily record can be compressed, i.e. log not, and just record the minimizing (that is, only preserving the index of metadata) which file guarantees the daily record amount unusually.Therefore, concrete method is:
Step 1 when the metadata fault, can still record the operation of metadata according to the mode of daily record.If unusual metadata node can recover normal in the relatively shorter time, then metadata is still recovered according to the method for using daily record by system.
Step 2, if the daily record amount of the metadata of record reaches certain threshold values (being preset value), then begin to set up a B+ tree in the metadata node that service is provided, when system receives Operation Log, log no longer, but will be recorded in the B+ tree by operand (i.e. the index that is generated by metadata).If object has been recorded in the B+ tree, then the metadata of serving is normally write in success.
Step 3, when the newly-increased metadata operation object of record was set to B+, the data that also will be recorded as daily record were resolved, and the operand of daily record correspondence is recorded in the B+ tree, if exist, then not at record, finish if be recorded to the step of B+ tree, then delete the daily record of having recorded.
Step 4, if journal file is being generated index and depositing in the process of B+ tree, the node of serving breaks down, at this moment, system should stop service, waits for and continues reconstruct B+ tree after unusual node is reached the standard grade again, continues to provide professional.
Step 5 after unusual node is reached the standard grade, for the node of serving, has the disposal route of following three kinds of situations:
Method one, if do not create the B+ tree in the system, then the metadata of illustrative system storage does not also reach threshold values (being preset value), at this moment, only needs that daily record is applied to the meta data server of just having reached the standard grade and gets final product.
Method two, if successfully created the B+ tree in the system, and there is not the existence of difference daily record (being the difference data), the content with the object of the metadata that records on the B+ tree that then can be concurrent is read (read be for the data that guarantee to read be up-to-date) from internal memory from internal memory, and and the new operation mutual exclusion to these data, and the metadata node of reaching the standard grade after sending to data unusually, after the other side writes the metadata store space with the data of object, delete the data item (being the index of metadata) in the B+ tree again.
Method three if created successful B+ tree in the system, and has the existence of difference daily record (being the difference data), at this moment, can be divided into two kinds of situations and handle:
Situation one continues daily record is converted to the B+ tree, waits and changes successfully, handles by method two.
Situation two, residual quantity daily record and B+ tree are recovered to the other side simultaneously, at this moment, need handle the recovery of metadata in residual quantity daily record and the B+ tree in sequence, increase the concurrency of operation, and, owing to reduced the link of daily record to the conversion of B+ tree, daily record simultaneously and B+ tree recover simultaneously, and the fast recovery of systematic comparison is finished, and improve the reliability of system.
According to embodiments of the invention, the device that provides a kind of metadata to handle.
As shown in Figure 2, the device of handling according to the metadata of the embodiment of the invention comprises:
Memory module 21, the metadata store that is used for will needing to store when the metadata of having stored in the internal memory reaches under the situation of preset value, is set up data structure to internal memory in internal memory;
Generation module 22, for the new metadata of needs storages, be used for generating the index of new metadata and with the index stores that generates to data structure.
Wherein, this device further comprises:
The removing module (not shown), after the index stores that will generate is to data structure,generation module 22 generates index according to the metadata of having stored in the internal memory, if do not have index in the data structure, then with the index stores that generates to data structure, the index metadata corresponding that removing module will generate is deleted from internal memory.
And after the index stores that will generate was to data structure,generation module 22 generated index according to the metadata of having stored in the internal memory, if had index in the data structure, then removing module is deleted the index metadata corresponding that generates from internal memory.
In sum, by means of technique scheme of the present invention, on the basis of the method that traditional metadata is recovered, disposal route when disclosing metadata fault in a kind of distributed system, by the metadata store that will need to store to internal memory, when the metadata of having stored in the internal memory reaches under the situation of preset value, in internal memory, set up data structure, new metadata for the needs storage, generate the index of new metadata and with the index stores that generates to data structure, can save the storage space of metadata in internal memory, and guarantee the reliability of system.
In addition, the present invention can also make system when breaking down, by log at first, by the time default threshold values, carry out daily record compression (setting up data structure) more automatically, thereby reduce the time that metadata is recovered, by this method, log no longer, saved log space, and, when unusual node is reached the standard grade again, improve the sales volume that recovers, guaranteed the reliability of system.
Below only be preferred embodiment of the present invention, in order to limit the present invention, within the spirit and principles in the present invention not all, any modification of doing, be equal to replacement, improvement etc., all should be included within protection scope of the present invention.