# US 2019/0317698 A1 · Disk Data Reading/Writing Method and Device

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2019/0317698 A1
- Document ID: US20190317698A1
- Status: Published application
- Kind: A1
- Application number: 16/348,248
- Filed: 2017-09-13
- Published: 2019-10-17
- Earliest claimed: 2016-11-08
- Assignees: Hangzhou Hikvision Digital Technology Co., Ltd.
- Applicants: Hangzhou Hikvision Digital Technology Co., Ltd.
- Inventors: Shiliang Pu; Min Ye; Peng Lin; Qiqian Lin; Weichun Wang
- Web page: https://patentgrep.com/patent/US20190317698A1

## CPC

- G06F 3/0644: {Management of space entities, e.g. partitions, extents, pools}
- G06F 11/2094: {Redundant storage or storage space (G06F11/2056 takes precedence)}
- G06F 3/0616: {in relation to life time, e.g. increasing Mean Time Between Failures [MTBF]}
- G06F 3/0619: {in relation to data integrity, e.g. data losses, bit errors}
- G06F 3/064: {Management of blocks}
- G06F 3/0676: {Magnetic disk device}
- G06F 11/2056: {by mirroring}
- G06F 16/14: Details of searching files based on file metadata
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

The embodiments of the present disclosure disclose a method and apparatus for reading or writing disk data. The disk includes a primary metadata block storing metadata, a backup metadata block for backing up metadata, and at least one object block group. Each object block group includes a data block storing object data, and an index block storing an index of the object data. The primary metadata block is located at a head of the disk; and the backup metadata block is located at a tail of the disk. The at least one object block group is located between the primary metadata block and the backup metadata block. In reading or writing object data, the index in the index block, the metadata in the primary metadata block and the metadata backed up in the backup metadata block can be separately operated. By applying the embodiments of the present disclosure, the life and security of the disk are increased.

## Claims

### Claim 1

A method for reading disk data, wherein a disk comprises a primary metadata block storing metadata, a backup metadata block for backing up the metadata, and at least one object block group; each object block group comprises a data block storing object data, and an index block storing an index of the object data; the primary metadata block is located at a head of the disk; the backup metadata block is located at a tail of the disk; the at least one object block group is located between the primary metadata block and the backup metadata block; the method comprises:
receiving a read instruction for target object data;
determining a first data block corresponding to the target object data according to an identifier of the target object data, the metadata in the primary metadata block, the metadata backed up in the backup metadata block, and an index in the index block in each object block group, and determining a first object block group in which the first data block is located;
reading the target object data from the first data block of the first object block group.

### Claim 2 (depends on 1)

The method according to claim 1, wherein, the index block comprises a primary index block and a backup index block; the primary index block is configured to store an index of object data, and the backup index block is configured to back up the index of the object data;
for each object block group, a primary index block in the object block group is located at a head of the object block group, and a backup index block in the object block group is located at a tail of the object block group; a data block in the object block group is located between the primary index block and the backup index block of the object block group;
the step of determining a first data block corresponding to the target object data according to an identifier of the target object data, the metadata in the primary metadata block, the metadata backed up in the backup metadata block, and an index in the index block in each object block group, and determining a first object block group in which the first data block is located comprises:
reading the metadata in the primary metadata block and/or the metadata backed up in the backup metadata block, and determining locations of the primary index block and the backup index block in each object block group;
reading the index in the primary index block or the index backed up in the backup index block at the determined locations; and
determining the first data block corresponding to the target object data according to the read index and the identifier of the target object data, and determining the first object block group in which the first data block is located.

### Claim 3 (depends on 2)

The method according to claim 2, wherein, the disk further comprises at least one reserved block; and the method further comprises:
when reading the metadata in the primary metadata block fails, or reading the metadata backed up in the backup metadata block fails, or reading the index in the primary index block in each object block group fails, or reading the index backed up in the backup index block in each object block group fails, determining the object block whose reading operation fails as a suspected bad block, and re-writing and/or re-reading object data into/from the suspected bad block;
if re-writing and/or re-reading the object data succeeds, repairing data in the suspected bad block according to primary and backup redundant data;
if re-writing and/or re-reading the object data fails, obtaining a reserved block and replacing the suspected bad block with the reserved block; overwriting the obtained reserved block according to the primary and backup redundant data, and updating the metadata in the primary metadata block and the metadata backed up in the backup metadata block.

### Claim 4 (depends on 1)

The method according to claim 1, wherein, the step of determining a data block corresponding to the target object data according to an identifier of the target object data, the metadata in the primary metadata block, the metadata backed up in the backup metadata block, and an index in the index block in each object block group comprises:
calculating a first index check value of the identifier of the target object data;
acquiring an identifier of the first data block and a first data length for the first index check value from a preset index database; wherein the preset index database is configured to store a corresponding relationship among an index check value, an identifier of a data block, and a data length; the index check value stored in the preset index database is determined according to the metadata in the primary metadata block, the metadata backed up in the backup metadata block, and the index in the index block in each object block group;
determining the first data block according to the identifier of the first data block;
the step of reading the target object data from the first data block of the first object block group comprises:
reading the target object data with the first data length from the first data block of the first object block group.

### Claim 5

A method for writing disk data, wherein a disk comprises: a primary metadata block storing metadata, a backup metadata block for backing up the metadata, and at least one object block group; each object block group comprises: a data block storing object data, and an index block storing an index of the object data; the primary metadata block is located at a head of the disk; and the backup metadata block is located at a tail of the disk; the at least one object block group is located between the primary metadata block and the backup metadata block; the method comprises:
receiving a writing instruction for target object data;
determining an idle first data block in the at least one object block group, and determining a first object block group corresponding to the first data block; and
writing the target object data into the first data block of the first object block group, and updating an index in an index block in the first object block group, the metadata in the primary metadata block and the metadata backed up in the backup metadata block according to an identifier of the target object data.

### Claim 6 (depends on 5)

The method according to claim 5, wherein, the index block comprises a primary index block and a backup index block; the primary index block is configured to store an index of object data, and the backup index block is configured to back up the index of the object data;
for each object block group, a primary index block in the object block group is located at a head of the object block group, and a backup index block in the object block group is located at a tail of the object block group; a data block in the object block group is located between the primary index block and the backup index block of the object block group;
the step of updating an index in an index block in the first object block group, the metadata in the primary metadata block and the metadata backed up in the backup metadata block according to an identifier of the target object data comprises:
writing the identifier of the target object data as an index into a primary index block in the first object block group, writing the identifier of the target object data as an index into a backup index block in the first object block group, updating metadata corresponding to the first data block in the primary metadata block, and backing up the metadata corresponding to the first data block into the backup metadata block.

### Claim 7 (depends on 6)

The method according to claim 6, wherein, the disk further comprises at least one reserved block; the method further comprises:
when updating the index in the primary index block in the first object block group fails, or updating the index backed up in the backup index block in the first object block group fails, or updating the metadata in the primary metadata block fails, or updating the metadata backed up in the backup metadata block fails, determining the object block whose updating operation fails as a suspected bad block, and re-writing and/or re-reading object data into/from the suspected bad block;
if re-writing and/or re-reading the object data succeeds, repairing critical data in the suspected bad block according to primary and backup redundant data;
if re-writing and/or re-reading the object data fails, obtaining a reserved block and replacing the suspected bad block with the reserved block; overwriting the obtained reserved block according to the primary and backup redundant data, and updating the metadata in the primary metadata block and the metadata backed up in the backup metadata block.

### Claim 8 (depends on 5)

The method according to claim 5, wherein, after updating an index in an index block in the first object block group, the metadata in the primary metadata block and the metadata backed up in the backup metadata block according to an identifier of the target object data, the method further comprises:
calculating a first index check value of the identifier of the target object data; and
storing the first index check value, the identifier of the first data block, and a first data length of the target object data into a preset index database correspondingly; wherein the preset index database is configured to store a corresponding relationship among an index check value, an identifier of a data block, and a data length.

### Claim 9

An apparatus for reading disk data, wherein a disk comprises a primary metadata block storing metadata, a backup metadata block for backing up the metadata, and at least one object block group; each object block group comprises a data block storing object data, an index block storing an index of the object data; the primary metadata block is located at a head of the disk; the backup metadata block is located at a tail of the disk; the at least one object block group is located between the primary metadata block and the backup metadata block; the apparatus comprises:
an instruction receiving unit, configured for receiving a read instruction for target object data;
an information determining unit, configured for determining a first data block corresponding to the target object data according to an identifier of the target object data, the metadata in the primary metadata block, the metadata backed up in the backup metadata block, and an index in the index block in each object block group, and determining a first object block group in which the first data block is located; and
a data reading unit, configured for reading the target object data from the first data block of the first object block group.

### Claim 10 (depends on 9)

The apparatus according to claim 9, wherein, the index block comprises a primary index block and a backup index block; the primary index block is configured to store an index of object data, and the backup index block is configured to back up the index of the object data;
for each object block group, a primary index block in the object block group is located at a head of the object block group, and a backup index block in the object block group is located at a tail of the object block group; a data block in the object block group is located between the primary index block and the backup index block of the object block group;
the information determining unit is configured for:
reading the metadata in the primary metadata block and/or the metadata backed up in the backup metadata block, and determining locations of the primary index block and the backup index block in each object block group;
reading the index in the primary index block or the index backed up in the backup index block at the determined locations; and
determining the first data block corresponding to the target object data according to the read index and the identifier of the target object data, and determining the first object block group in which the first data block is located.

### Claim 11 (depends on 10)

The apparatus according to claim 10, wherein, the disk further comprises at least one reserved block; the apparatus further comprises:
a bad block determining unit, configured for, when reading the metadata in the primary metadata block fails, or reading the metadata backed up in the backup metadata block fails, or reading the index in the primary index block in each object block group fails, or reading the index backed up in the backup index block in each object block group fails, determining the object block whose reading operation fails as a suspected bad block, and re-writing and/or re-reading object data into/from the suspected bad block;
a data repairing unit, configured for, if re-writing and/or re-reading the object data succeeds, repairing data in the suspected bad block according to primary and backup redundant data; and
a data overwriting unit, configured for, if re-writing and/or re-reading the object data fails, obtaining a reserved block and replacing the suspected bad block with the reserved block; overwriting the obtained reserved block according to the primary and backup redundant data, and updating the metadata in the primary metadata block and the metadata backed up in the backup metadata block.

### Claim 12 (depends on 9)

The apparatus according to claim 9, wherein, the information determining unit is configured for:
calculating a first index check value of the identifier of the target object data;
acquiring an identifier of the first data block and a first data length for the first index check value from a preset index database; wherein the preset index database is configured to store a corresponding relationship among an index check value, an identifier of a data block, and a data length; the index check value stored in the preset index database is determined according to the metadata in the primary metadata block, the metadata backed up in the backup metadata block, and the index in the index block in each object block group; and
determining the first data block according to the identifier of the first data block, and determining the first object block group in which the first data block is located;
the data reading unit is configured for:
reading the target object data with the first data length from the first data block of the first object block group.

### Claim at position 13

13-16. (canceled)

### Claim 17 (depends on 1)

An electronic device, wherein the electronic device comprises a processor, a communication interface, a memory, and a communication bus; wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
the memory is configured to store an application program;
the processor is configured to perform the method according to claim 1.

### Claim 18 (depends on 5)

An electronic device, wherein the electronic device comprises a processor, a communication interface, a memory, and a communication bus; wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
the memory is configured to store an application program;
the processor is configured to performs the method according to claim 5.

### Claim 19

(canceled)

### Claim 20

(canceled)

### Claim 21 (depends on 1)

A non-transitory storage medium, wherein the storage medium is configured to store an application program, and the application program performs the method according to claim 1 when being executed.

### Claim 22 (depends on 5)

A non-transitory storage medium, wherein the storage medium is configured to store an application program, and the application program performs the method according to claim 5 when being executed.
