Method for guaranteeing consistency of metadata in distributed file system

The invention provides a method for guaranteeing consistency of metadata in a distributed file system, which includes the steps: enabling the distributed file system to be organized and stored with a block as a unit; when the metadata are revised, revising internal memory data blocks firstly, and recording the revised data blocks; writing the revised information of the metadata blocks into a log file, and synchronizing the revised metadata blocks to a magnetic disk; after the revised metadata blocks are synchronized to the magnetic disk, discarding recorded items for the metadata blocks and only keeping revised records; and after a fault occurs, entering a recovery flow, and applying corresponding revision to the metadata blocks again according to the revised information in the log file for the metadata blocks. On the premise without affecting the operating efficiency of the metadata, consistency of the metadata of the whole system can be guaranteed after the fault occurs by recovering to remove the metadata which are not untimely and completely synchronized to the magnetic disk when the fault occurs.