Data query method and apparatus
View Patent ↗This disclosure provides a data query method and apparatus. The method includes: dividing an object storage system into a plurality of storage spaces based on time slices, establishing a mapping relationship between the storage spaces, the time slices, and operation records, recording time slice information corresponding to a snapshot after generating the snapshot, and implementing services such as a read-only service, a snapshot rollback service, and an object change service based on the snapshot, so as to improve query performance without adding extra storage overheads.
1. A data query method, comprising:
generating a mapping relationship, wherein the mapping relationship indicates a one-to-one correspondence between a plurality of operations and a plurality of storage spaces in a storage system, wherein the plurality of operations occur at different occurrence moments, and a first storage space in the plurality of storage spaces stores a first storage object on which processing based on a first operation has been performed, wherein the first operation is corresponding to the first storage space, and the first storage space is one of the plurality of storage spaces;
generating operation records recording the occurrence moments of the plurality of operations, wherein each of the operation records records the occurrence moment of one of the plurality of operations;
receiving a first query request, wherein the first query request requests to query a storage status of the first storage object at a first moment;
determining, from the plurality of operations based on the operation records, the first operation before the first moment; and
determining, based on the mapping relationship, the first storage object stored in the first storage space corresponding to the first operation.
2. The method according to claim 1 , wherein the operation records are categorized into a plurality of time slices, each of the plurality of operations is associated with one of the plurality of time slices in accordance with the occurrence moment of the operation, and an operation record in each time slice comprises time information of the time slice.
3. The method according to claim 2 , wherein the generating operation records comprises:
generating new metadata based on time information of a time slot associated with the first operation and metadata corresponding to the first storage object.
4. The method according to claim 3 , wherein the storage system establishes a first snapshot in a first time slice and the first time slice is the time slice associated with the first operation, and the method further comprises:
determining the first time slice based on a snapshot name of the first snapshot and determining the metadata and the first storage object based on the first time slice, when the storage system receives a read request for the first snapshot from a client.
5. The method according to claim 1 , wherein the storage system establishes a first snapshot in a first time slice, and the method further comprises:
determining a first time period based on a time slice in which a rollback request for the first snapshot occurs and the first time slice, when the storage system receives the rollback request from a client; and deleting all operation records in the first time period from the operation records.
6. The method according to claim 1 , wherein, when the first operation is a modify operation, the processing based on the first operation comprises appending to the first storage object stored in one of the plurality of storage spaces at a preceding moment without overwriting the first storage object stored in one of the plurality of storage spaces at the preceding moment.
7. The method according to claim 6 , wherein, when the first operation is a delete operation, the processing based on the first operation comprises marking as deleted the first storage object stored in one of the plurality of storage spaces at a preceding moment without deleting the first storage object stored in one of the plurality of storage spaces at the preceding moment.
8. A data query apparatus, comprising:
a communication interface; and
a processor coupled to the communication interface and configured to:
generate a mapping relationship, wherein the mapping relationship indicates a one-to-one correspondence between a plurality of operations and a plurality of storage spaces that are corresponding to a storage system, wherein the plurality of operations occur at different occurrence moments, and a first storage space in the plurality of storage spaces stores a first storage object on which processing based on a first operation has been performed, wherein the first operation is corresponding to the first storage space, and the first storage space is one of the plurality of storage spaces;
generate operation records recording the occurrence moments of the plurality of operations, wherein each of the operation records records the occurrence moment of one of the plurality of operations;
receive a first query request, wherein the first query request requests to query a storage status of the first storage object at a first moment;
determine, from the plurality of operations based on the operation records, the first operation before the first moment; and
determine, based on the mapping relationship, the first storage object stored in the first storage space corresponding to the first operation.
9. The apparatus according to claim 8 , wherein the operation records are categorized into a plurality of time slices, each of the plurality of operations is associated with one of the plurality of time slices in accordance with the occurrence moment of the operation, and an operation record in each time slice comprises time information of the time slice.
10. The apparatus according to claim 9 , wherein processor is further configured to:
generate new metadata based on time information of a time slice associated with the first operation and metadata corresponding to the first storage object.
11. The apparatus according to claim 10 , wherein the storage system establishes a first snapshot in a first time slice and the first time slice is the time slice associated with the first operation, and the processor is further configured to:
determine the first time slice based on a snapshot name of the first snapshot and determine the metadata and the first storage object based on the first time slice, when the storage system receives a read request for the first snapshot from a client.
12. The apparatus according to claim 8 , wherein the storage system establishes a first snapshot in a first time slice, the processor is further configured to:
determine a first time period based on a time slice in which a rollback request for the first snapshot occurs and the first time slice, when the storage system receives the rollback request from a client; and
delete all operation records in the first time period from the operation records.
13. A non-transitory computer-readable medium, wherein the non-transitory computer-readable medium stores a computer program, the program comprising instructions, that when executed by a computer, enable the computer to perform steps comprising:
generating a mapping relationship, wherein the mapping relationship indicates a one-to-one correspondence between a plurality of operations and a plurality of storage spaces that are corresponding to a storage system, wherein the plurality of operations occur at different occurrence moments, and a first storage space in the plurality of storage spaces is stores a first storage object on which processing based on a first operation has been performed, wherein the first operation is corresponding to the first storage space, and the first storage space is one of the plurality of storage spaces;
generating operation records recording the occurrence moments of the plurality of operations, wherein each of the operation records records the occurrence moment of one of the plurality of operations;
receiving a first query request, wherein the first query request requests to query a storage status of the first storage object at a first moment;
determining, from the plurality of operations based on the operation records, the first operation before the first moment; and
determining, based on the mapping relationship, the first storage object stored in the first storage space corresponding to the first operation.
14. The non-transitory computer-readable medium according to claim 13 , wherein the operation records are categorized into a plurality of time slices, each of the plurality of operations is associated with one of the plurality of time slices in accordance with the occurrence moment of the operation, and an operation record in each time slice comprises time information of the time slice.
15. The non-transitory computer-readable medium according to claim 14 , wherein the computer is enabled to further perform steps comprising:
generating new metadata based on time information of a time slice associated with the first operation and metadata corresponding to the first storage object.
16. The non-transitory computer-readable medium according to claim 15 , wherein the storage system establishes a first snapshot in a first time slice and the first time slice is the time slice associated with the first operation, and the computer is enabled to further perform steps comprising:
determining the first time slice based on a snapshot name of the first snapshot and determining the metadata and the first storage object based on the first time slice, when the storage system receives a read request for the first snapshot from a client.
17. The non-transitory computer-readable medium according to claim 13 , wherein the storage system establishes a first snapshot in a first time slice, the computer is enabled to further perform steps comprising:
determining a first time period based on a time slice in which a rollback request for the first snapshot occurs and the first time slice, when the storage system receives the rollback request from a client; and
deleting all operation records in the first time period from the operation records.