A kind of implementation method of improved Copy on write snapshot and device
Technical field
The present invention relates to computer memory technical field, particularly a kind of implementation method of improved Copy on write snapshot and device.
Background technology
The accelerated development of infotech makes the scale of key business data of enterprise expand day by day, and enterprise not only requires memory capacity increasing, and is also increasingly high to the data safe requirement.Along with the raising of storage application demand, the user needs online backup and protected data.Snapshot (Snapshot) technology is the guard method of a kind of online data effectively, can realize online data backup fast.
Snapshot is a complete usable copy of specific data set, and this copy comprises that specific data is integrated into the reflection of certain time point.The specific data set is called the source data district, and the reflection of certain time point is called the snapshot data district.Present snapping technique mainly contains two kinds: Copy on write (Copy-On-Write) and redirected write (Redirect-On-Write).Wherein the Copy on write technology takes up room for a short time, and establishment speed is fast, and less to the influence of source data district access performance, is widely used in the various fast photographic systems.
The Copy on write technology can generate the snapshot to the storage data change when input new data or data with existing are updated at every turn.Do like this can when hard disk write error, file corruption or program mal take place restore data promptly.But, if desired all data on network or the storage medium are filed completely or when recovering, the snapshots before all must be available.The Copy on write technology is not carried out any copying data when creating snapshot, only be required to be source data district initial snapshot reference pointer index, identifies this actual present position of time point data, so create the Copy on write snapshot, moment can be accomplished establishment.
The Copy on write snapping technique is by specifying magnitude unit that the source data zoning is divided into plurality of data piece (chunk), and data block is the base unit of snapshot deal with data.The principle of Copy on write is following: after creating the Copy on write snapshot; When write data requests was received in the source data district, storage system was at first searched snapshot reference pointer index, judged whether source data district data block to be revised has set up reference pointer; If this data block is not set up reference pointer; Then earlier with this data block copy to the snapshot data district, and set up the reference pointer of this data block, upgrade source data district data block then; If this data block has been set up reference pointer, represent that then this data block has copied the snapshot data district to, can directly upgrade this data block.The snapshot data district has just backed up all change data behind the source data district snapshot like this, has promptly generated the reflection of source data district at the snapshot creation time point.
The Copy on write snapshot treating apparatus of prior art is as shown in Figure 1, comprises that the user asks receiver module 101, read-write judge module 102, block management data module 103, snapshot index of reference module 104, source data district module 105, data block copy module 106, snapshot index of reference update module 107 and snapshot data district module 108.
The user asks receiver module 101 to be used to receive the access request from the user;
Read-write judge module 102 is used for the access request that judges request receiver module 101 received and is read request or writes request, if write request, then this is write request and is sent to block management data module 103.If read request then is sent to source data district data block 105 with this read request, carry out corresponding operating by 105 pairs of these read requests of source data district data block.
Block management data module 103; Be used for start address big or small according to source data district data block and from the request of writing of reading and writing judge module 102; Calculate source data district data block number to be revised, and the gained data block number is sent to snapshot index of reference module 104.
Preserved the snapshot reference pointer index of preset setting in the snapshot index of reference module 104, the mapping relations of the data block number that said snapshot reference pointer index is the equal of the source data district and the data block number in snapshot data district.And according to search said snapshot reference pointer index from the data block number of block management data module 103; If set up snapshot index of reference about said data block number; Then notification source data field module 105 responds the said request of writing; If do not set up snapshot index of reference, then with said data block number notification data block copy module 106 about said data block number.
Source data district module 105 comprises the source data district, and is used for the data block in source data district is carried out read-write operation.
Data block copy module 106 is used for after the notice of receiving snapshot index of reference module 104, reading source data district data block to be revised, and the sector position that data block writes the snapshot data district is set, and the data block that reads is write said sector position.
Snapshot index of reference update module 107; Be used for after 106 pairs of snapshot data districts of data block copy module module 108 is carried out write operation; The snapshot data district data block that foundation newly writes and the snapshot reference pointer of source data district data block; And the snapshot reference pointer of said foundation is sent to snapshot index of reference module 104, the snapshot reference pointer index of snapshot index of reference module 104 is upgraded.
Snapshot data district module 108 is used to preserve the data block in snapshot data district.
The treatment scheme of snapping technique during for the writing of prior art shown in Figure 2 comprises the steps:
Step 201: create the snapshot data district.
Step 202: according to the data block size in the source data district of appointment; The snapshot data zoning is divided into the plurality of data piece; Each data block has unique data block number; Data block size and source data district data block equal and opposite in direction, and initial snapshot reference pointer index, the mapping relations of the data block number that said snapshot reference pointer index is the equal of the source data district and the data block number in snapshot data district.
Step 203: the source data district receives user's access request.
Step 204: judge this access request whether for writing request, if execution in step 205 then, otherwise go to step 211.
Step 205: according to source data district data block size with write the request start address, calculate data block number to be revised.
Step 206: with the gained data block number is key word, searches snapshot reference pointer index.
Step 207: judge whether to set up the snapshot reference pointer, if then go to step 211, otherwise execution in step 208.
Step 208: read the source data district and wait to revise data block X1, the sector position that data block writes the snapshot data district is set.
Step 209: the data block Y1 that the data block that reads is write the said sector position in snapshot data district.
Step 210: the snapshot reference pointer of data block Y1 of setting up data block X1 and the snapshot data district in source data district.
Step 211: response read-write requests, access originator data field data block X1.
Though Copy on write snapshot creation speed is fast; And only need preserve the data block that change takes place in the source data district; The space hold rate is also lower, but the Copy on write snapping technique needs earlier data block is backuped to the snapshot data district and in internal memory, sets up the snapshot reference pointer when data block is changed for the first time in the source data district; Could upgrade this data block then, this writes request to the user and has brought bigger delay; Along with the data of source data district change are more and more, the internal memory that the snapshot index of reference is consumed is with increasing simultaneously, and the shared storage space in snapshot data district is also increasing, and this all brings very big burden to storage system.
Summary of the invention
In view of this, the objective of the invention is to, propose a kind of implementation method and device of improved Copy on write snapshot, can reduce the storage space that postpones and save the snapshot data district.
The implementation method of a kind of improved Copy on write snapshot that the embodiment of the invention proposes is provided with source data position chart; Corresponding N the data block of the every bit of said source data position chart; Write data in the data block of bit for effectively expression correspondence, bit is not write data in the corresponding data block of invalid then expression, and N is a natural number; This method comprises the steps:
A, establishment snapshot data district; The snapshot data zoning is divided into a plurality of data blocks, snapshot data district data block size and source data district data block equal and opposite in direction, and initial snapshot reference pointer index; Duplication source data position chart to the snapshot data district as snapshot data position chart;
B, source data district receive the request of writing, and confirm saidly to write the corresponding source data district data block of request, and judge whether J bit of the source data position chart that said source data district data block is corresponding be effective, if execution in step C then, J is a natural number; Otherwise go to step e;
C, judge whether J corresponding bit of snapshot data position chart be effective, if effective, execution in step D then, otherwise go to step e;
D, judge whether said source data district data block has set up the snapshot reference pointer; If set up the snapshot reference pointer, then go to step e, otherwise; Read the data of this source data district data block; The data block that reads is written to the snapshot data district,, and adds snapshot reference pointer index for this data block is set up the snapshot reference pointer;
E, the corresponding bit state of modification source data position chart are effectively, and the source data district responds the said request of writing.
Wherein, the said definite said data block number Chunk that writes the corresponding source data district data block of request of step B
nEqual to write the big or small M of request start address divided by source data district data block.
J bit of the source data position chart that said source data district data block is corresponding equals source data district data block number Chunk
nDivided by the corresponding number of data blocks N of the every bit of source data position chart.
Preferably, the said source data position chart that is provided with comprises the steps:
Set up initialized source data position chart, confirm the number of data blocks N that the every bit of bitmap table identifies according to memory size, all bits of bitmap table are initialized as disarmed state.
The embodiment of the invention proposes a kind of implement device of improved Copy on write snapshot, comprising: the user asks receiver module, source data district module, snapshot data district module; Source data district module comprises the source data district that a plurality of data blocks are formed, and is used for the data block in source data district is carried out read-write operation; Snapshot data district module is used to preserve the data block in snapshot data district; The user asks receiver module, is used to receive the request of writing from the user;
It is characterized in that this device also comprises: block management data module, snapshot index of reference module, data block copy module, snapshot index of reference update module, source data position chart module and snapshot position chart module;
The block management data module is used for asking to calculate source data district data block number to be revised according to said writing, and the gained data block number is sent to source data position chart module;
Source data position chart module is used to safeguard source data position chart; Corresponding N the data block of the every bit of said source data position chart; Write data in the data block of bit for effectively expression correspondence, bit is not write data in the corresponding data block of invalid then expression; After the data block number of receiving from the block management data module, judge whether J bit of the source data position chart that said data block number is corresponding be effective, if then bit sequence number J and data block number are sent to snapshot position chart module; N, J are natural number; After the source data district carries out write operation, said data block number the bit of corresponding source data position chart be set to effectively;
Snapshot data position chart module is used for when creating snapshot, the source data position chart in the chart module of duplication source data position to the snapshot data district as snapshot data position chart; And, judge whether J bit of snapshot data position chart be effective according to bit sequence number J from source data position chart module, if effectively then said data block number is sent to snapshot index of reference module; If the invalid said source data district module of then notifying is carried out corresponding write operation;
Snapshot index of reference module; Be used to preserve the snapshot reference pointer index that is provided with in advance, and, search said snapshot reference pointer index according to data block number from snapshot position chart module; If set up snapshot index of reference about said data block number; Then notification source data field module responds is said writes request, if do not set up the snapshot index of reference about said data block number, then with said data block number notification data block copy module;
The data block copy module is used for after the notice of receiving snapshot index of reference module, reads source data district data block to be revised, and the data block that reads is write the data block in snapshot data district;
Snapshot index of reference update module; Be used for after the data block copy module is carried out write operation to snapshot data district module; The snapshot data district data block that foundation newly writes and the snapshot reference pointer of source data district data block; And the said snapshot reference pointer that will set up is sent to snapshot index of reference module, and the snapshot reference pointer index of snapshot index of reference module is upgraded, and notifies said source data district module to carry out corresponding write operation then.
Said source data position chart module further comprises:
Initialization unit is used to set up initialized source data position chart, confirms the number of data blocks N that the every bit of bitmap table identifies according to memory size, and all bits of bitmap table are initialized as disarmed state.
Can find out from above technical scheme, when creating snapshot, the bitmap table of source book this moment copied to snapped volume preserve, as the data field bitmap table of this snapshot.Write when request when the source data district receives, the bitmap table in source data district judges whether this data block is effective, and is invalid as if this data block, then directly responds this and writes request; If this data block is effective, then further judge by the bitmap table in snapshot data district whether this data block is effective; If this data block is invalid, then directly responds this and write request.Through above-mentioned improvement, writing request for main frame greatly can directly respond, and need not to copy this data block to the snapshot data district.The present invention program can reduce the clear data copy greatly, and the snapshot of when source volume data is sky, creating can not cause any copying data, can reduce snapshot index of reference and snapshot data district size than prior art, improves the storage space utilization factor.
Description of drawings
The treating apparatus of snapping technique when Fig. 1 is writing of prior art;
The treatment scheme synoptic diagram of snapping technique when Fig. 2 is writing of prior art;
Fig. 3 is for disposing the initialization process process flow diagram that the embodiment of the invention need be carried out;
Fig. 4 is the treating apparatus of embodiment of the invention snapping technique when writing;
Fig. 5 is the treatment scheme synoptic diagram of embodiment of the invention snapping technique when writing.
Embodiment
The present invention program's basic ideas are following:
On existing Copy on write snapping technique basis; Increase judge module in source data district and snapshot data district respectively; Be used for judging when the source data district receives and write when asking, whether need copy the corresponding data piece to the snapshot data district, and only under the situation of needs, just carry out said copy function.
For making the object of the invention, technical scheme and advantage clearer, the present invention is done further to set forth in detail below in conjunction with accompanying drawing.
Come identification sources data field and snapshot data district respective data blocks whether effective through introducing bitmap table (bitmap) in the embodiment of the invention.Each bit of bitmap table can corresponding one or more data blocks.In order to write down source data district data block state, bitmap table must be created when creating the source data district.When the source data district was created, the source data district did not comprise any validated user data, and it is invalid that all data blocks are, and this moment, source data position all bits of chart all were designated disarmed state.Write request along with storage system constantly receives, the data block that the request write writes is identified as the valid data piece.After creating snapshot; Source data position chart possibly change some bit state because new writing asked; The data block state in source data district when writing down snapshot creation, duplication source data position chart is to the snapshot data district, as the bitmap table in snapshot data district when creating snapshot; Snapshot data bitmap area table record during the establishment snapshot, the state of source data district data block.Through setting up said bitmap table, can reduce in the Copy on write snapshot processes copy to invalid data block, through reducing the invalid data copy, both reduced the user and write request delay, also improved the storage space utilization factor.
Embodiment of the invention scheme relates to the source data district, snapshot data district, snapshot reference pointer index, source data position chart, snapshot data position chart.Wherein user's valid data are deposited in the source data district; The data of revising behind the snapshot time point of backup source data field, snapshot data district; The mapping relations of source data district data block and snapshot data district data block set up in snapshot reference pointer index; Whether source data position chart is used for describing source data district data block effective; Snapshot data position chart is used for describing when creating snapshot, and whether source data district data block is effective.
The initial treatment flow process of the embodiment of the invention comprises the steps: according to shown in Figure 3
Step 301: in storage system, create the source data district, prepare to receive the user writable request;
Step 302: according to the data designated block size, the source data zoning is divided into the plurality of data piece, the data block size should be the integral multiple of disk sector, can be according to the big or small specified data block size of Installed System Memory (RAM);
Step 303: set up source data position chart, the data block that the every bit sign of bitmap table is N, N is a natural number.N representes the number of data blocks of every bit sign, can confirm according to Installed System Memory (RAM) size.The data block of every bit sign is few more, and then bitmap table is big more, and the degree of accuracy of specified data piece effective status is also high more; All bits of bitmap table are initialized as disarmed state; Be that all data blocks of source data district are disarmed state;
Step 304: the source data district receives user's access request.
Step 305: judge said access request whether for writing request, if order execution in step 306 then; Otherwise directly go to step 308;
Step 306: according to the data block size, every bit identification data block number and the reference position calculating source data position chart bit corresponding of writing request with this data block number.
If source data district data block sizes values is M, the number of data blocks of the every bit sign of bitmap table is N, and it is A that the user asks start address, and then the corresponding source data district data block number computing formula of this request is:
Chunk
n=A/M (formula one)
The corresponding bit computing formula of data block is:
Bit
n=Chunk
n/ N (formula two)
Step 307: it is effective revising the source data position corresponding bit state of chart;
Step 308: source data district response user's access request, and return step 304.
The treatment scheme of the Copy on write snapshot that the embodiment of the invention proposes is as shown in Figure 4, comprises the steps:
Step 401: create the snapshot data district;
Step 402: according to the specific data block size snapshot data zoning is divided into the plurality of data piece, snapshot data district data block size and source data district data block equal and opposite in direction, and initial snapshot reference pointer index;
Step 403: duplication source data position chart is set up snapshot data position chart to the snapshot data district;
Step 404: the source data district receives user access request;
Step 405: judge that whether said user access request is for writing request, if not write request, commentaries on classics step 415; If write request, order execution in step 406;
Step 406: calculate data block number to be revised according to source data district data block size with writing the request start address, use formula one;
Step 407: according to data block number to be revised, calculate the corresponding source data position chart bit of said data block number, use formula two;
Step 408: judge whether chart corresponding bit position, source data position is effective,, represent that this data block is invalid, change step 415 if invalid; If effectively, order execution in step 409;
Step 409: judge whether chart corresponding bit position, snapshot data position is effective,, represent that this data block is invalid, change step 415 if invalid; If effectively, order execution in step 410.
Suppose that bit and chart corresponding bit position, the said source data of step 408 position that formula two calculates are J bits in the chart of source data position; Corresponding relation according to source data position chart and snapshot data position chart; Chart corresponding bit position, said snapshot data position also is a J bit of snapshot data position chart, and wherein J is a natural number.
Step 410: with the data block number is key word, searches snapshot reference pointer index;
Step 411: judge whether this source data district data block has set up the snapshot reference pointer,, change step 415 if set up the snapshot reference pointer; If do not set up the snapshot reference pointer, order execution in step 412;
Step 412: read the data of this source data district data block, and the sector position that data block writes the snapshot data district is set;
Step 413: the data block that reads is written to the snapshot data district;
Step 414:, and add snapshot reference pointer index for this data block is set up the snapshot reference pointer;
Step 415: if read request, the source data district directly reads corresponding data, and responds this read request; If write request, revising the source data position corresponding bit state of chart is that effectively the source data district writes data and responds the said request of writing.
Mainly in step 408 and step 409, promptly according to source data district and snapshot data position chart, whether judgement waits to revise data block is effective status to the improvement of traditional Copy on write snapping technique in the present invention; If this data block is a disarmed state; Then directly change step 415, can avoid the copy of invalid data block on the one hand, improve the user and write the request response; Can reduce the snapshot index of reference pointer of invalid data on the one hand; Reduce the memory headroom that the snapshot index of reference takies, can eliminate on the other hand invalid data in the snapshot data district shared storage space, thereby improve the space availability ratio of storage system.
In the use of source data district, the valid data that the user writes only account for the seldom part in source data district probably, and at this moment, promptly most of data block in source data district is disarmed state.The method of using the present invention to propose is created when writing behind the snapshot; If the most of data block in source data district is a disarmed state; During snapshot operation, directly respond user's request when then writing, avoid interpolation the copy and the snapshot reference pointer of invalid data block; Reduce the user greatly and write request delay, improve the storage system space availability ratio.
The embodiment of the invention also proposes a kind of device of improved Copy on write snapshot; This device is as shown in Figure 5, comprises that the user asks receiver module 501, read-write judge module 502, block management data module 503, source data position chart module 504, source data district module 505, snapshot data position chart module 506, snapshot index of reference module 507, data block copy module 508, snapshot index of reference update module 509 and snapshot data district module 510.Compare the Copy on write fast photographing device of prior art shown in Figure 1, increased source data position chart module 504 and snapshot data position chart module 506.The function of above-mentioned each module is following:
The user asks receiver module 501 to be used to receive the access request from the user;
Read-write judge module 502 is used for the access request that judges request receiver module 501 received and is read request or writes request, if write request, then this is write request and is sent to block management data module 503.If read request then is sent to source data district data block 505 with this read request, carry out corresponding operating by 505 pairs of these read requests of source data district data block.
Block management data module 503; Be used for start address big or small according to source data district data block and from the request of writing of reading and writing judge module 502; Calculate source data district data block number to be revised, and the gained data block number is sent to source data position chart module 504.
Source data position chart module 504 is used to safeguard source data position chart; Corresponding N the data block of the every bit of said source data position chart; Write data in the data block of bit for effectively expression correspondence, bit is not write data in the corresponding data block of invalid then expression; After the data block number of receiving from the block management data module, judge whether J bit of the source data position chart that said data block number is corresponding be effective, if then bit sequence number J and data block number are sent to snapshot position chart module 506; N, J are natural number; After the source data district carries out write operation, said data block number the bit of corresponding source data position chart be set to effectively.
Source data district module 505 comprises the source data district, and is used for the data block in source data district is carried out read-write operation.
Snapshot data position chart module 506, the source data position chart that is used for duplication source data position chart module to the snapshot data district as snapshot data position chart; And, judge whether J bit of snapshot data position chart be effective according to bit sequence number J from source data position chart module, if effectively then said data block number is sent to snapshot index of reference module 507;
Preserved the snapshot reference pointer index of preset setting in the snapshot index of reference module 507, the mapping relations of the data block number that said snapshot reference pointer index is the equal of the source data district and the data block number in snapshot data district.And according to search said snapshot reference pointer index from the data block number of snapshot data position chart module 506; If set up snapshot index of reference about said data block number; Then notification source data field module 505 responds the said request of writing; If do not set up snapshot index of reference, then with said data block number notification data block copy module 506 about said data block number.
Data block copy module 508 is used for after the notice of receiving snapshot index of reference module 507, reading source data district data block to be revised, and the sector position that data block writes the snapshot data district is set, and the data block that reads is write said sector position.
Snapshot index of reference update module 509; Be used for after 508 pairs of snapshot data districts of data block copy module module 510 is carried out write operation; The snapshot data district data block that foundation newly writes and the snapshot reference pointer of source data district data block; And the snapshot reference pointer of said foundation is sent to snapshot index of reference module 507, and the snapshot reference pointer index of snapshot index of reference module 507 is upgraded, notify said source data district module 505 to carry out corresponding write operation then.
Snapshot data district module 510 is used to preserve the data block in snapshot data district.
Embodiment of the invention scheme is improved on existing Copy on write snapshot scheme; Increase bitmap table in source data district and snapshot data district; When receiving, the source data district writes when request; Earlier judge according to source data position chart whether this data block is effective, and chart corresponding bit position, source data position is set for effective.If this data block is invalid, then directly responds this and write request; If this data block of source data position chart sign is effective, then further judge according to snapshot data position chart whether this data block is effective; If this data block is invalid, then directly responds this and write request.So when source data position chart that data block is corresponding or chart corresponding bit position, snapshot data position are invalid, can directly respond this and write request, and need not to copy this data block to the snapshot data district.Can reduce the user through improvement and write request delay, reduce snapshot index of reference and snapshot data district size, improve the storage space utilization factor.
The above is merely preferred embodiment of the present invention, not in order to restriction the present invention, all any modifications of within spirit of the present invention and principle, being done, is equal to and replaces and improvement etc., all should be included within protection scope of the present invention.