MasterofProject

Sogou Distributed file storage FastDFS (a) FastDFS acquaintance

label DistributedFastdfsstoragedistributed file systemload balancing
811 people read comment(3) Collection report
Classification:

First, FastDFS profile

FastDFS is an open source, distributed file system (File System Distributed), developed by the Ministry of Taobao development platform, a senior architect in Yuqing. As a distributed file system, the file management, features include: file storage, file synchronization, file access (file upload and file download) to solve the large storage capacity and load balancing problem, especially for medium and small-sized file (recommended range: 4KB < file size <500MB), to file as the carrier of the online service, such as album website, video website and so on has significant effect.

Two, FastDFS architecture

FastDFS by the client, tracking server and storage server, the basic structure as shown below.

Write the picture here.
Server Storage

Storage server (NSR) to group (roll, group or volume) as the unit of organization, a group contains multiple storage machine, data backup for each other and storage space to group within the minimum capacity of storage shall prevail, it is recommended that multiple storage group configuration as far as possible the same, so as to avoid the waste of storage space.

Group for the storage units of the organization can be conveniently carried out application isolation, load balance, the copy number of the custom (group inside the storage server number that is the number of copies of the group), such as the different application, save the data to the difference in the group will be able to isolate the application data, at the same time, can also according to the access characteristics of application will be applied assigned to different group to do load balancing; drawback is group of capacity by the single storage capacity constraints, also when the group has broken machines, data recovery can only rely on group mainland other machines, the recovery time will be very long.

Each storage group in storage depends on the local file system and storage can configure multiple data storage directory, for example, there are 10 disks, were mounted in the /data/disk1-/data/disk10, is May 10 this directory is configured as a data storage directory.

Storage to write a file request, will be based on the configuration of the rules (will be introduced later), select one of the storage directory to store the file. In order to avoid a single directory under the file number too much, in a first start, will create a 2 level subdirectories in the directory of each data storage, each level 256, a total of 65536 file, writes the file will to hash is routed to the a subdirectory, then the file data directly as a local file storage to the directory.

Server Tracker

Tracker is fastdfs coordinator, responsible for managing all the storage server and group, each storage after the start will connecting the tracker and inform their respective group, and keep the periodic heartbeat, tracker according to the heartbeat information storage, establish group==>[storage serverlist] mapping table.

Tracker is needed to manage the meta information is rare, are stored in memory; also tracker meta information are generated by the report on the storage of information, itself does not require any data persistence, which makes the tracker is easy to expand, directly increase the tracker machine can be extended to serve the tracker cluster, is complete equivalence between each tracker in a cluster, all trackers are accepted stroage heartbeat messages and generate metadata information to provide services to read and write.

Client
Client, as the initiator of the business request, through the proprietary interface, using the TCP/IP protocol and the tracker server or storage node for data interaction.

Three, FastDFS storage strategy

In order to support large capacity storage node (server) with the volume (or packet) organization. The storage system is composed of one or more volumes, the files between the volumes and volumes are independent of each other, and the file capacity of all volumes is accumulated as the file size of the entire storage system. A volume can be made up of one or more storage servers, and the files in one of the volumes are the same, and a number of storage servers in the volume play a role of redundancy and load balancing.

When the server is added in the volume, the existing file is automatically completed by the system, and the system automatically switches the new server to the on-line service after the completion of the synchronization.

When the storage space is insufficient or is about to run out, the volume can be dynamically added. You just need to add one or more servers and configure them as a new volume, thus increasing the capacity of the storage system.

Four, FastDFS upload process

FastDFS to provide users with basic file access interface, such as upload, download, append, delete, etc., to the client library to provide users with.

Write the picture here.

According to the front of the explanation, we know that Storage Server will periodically send their Server Tracker to store information. When Server Cluster Tracker in the Server Tracker more than one, the relationship between the various Tracker is equal, so the client can choose to upload any Tracker.

When Tracker receives a request from a client to upload a file, the file is assigned a group that can store the file, and when the group is selected, it decides which server storage to assign the group to the client. When the server storage is assigned, the client sends a request to the storage, and the storage will allocate a data storage directory for the file. Then allocate a fileid for the file, and finally generate the file name storage file based on the above information. File name format is as follows:
Write the picture here.

Five, FastDFS file synchronization

When writing files, the client will be written to group within a server storage that is considered to write the document successfully, server storage after writing the file, the file will be synchronized with the background thread to the same storage server group.

Each storage file and write a file, and write a binlog, binlog does not contain data file, containing only the element information such as file name, this binlog for background synchronization and storage will be recorded to other storage within the group synchronization schedule, so that after the restart can then the last schedule synchronization continues; progress are recorded in the timestamp, so it is best to ensure that all server in the cluster clock synchronization.

Storage synchronization schedule will be used as part of the metadata to report to the tracker, tracke in the choice of reading storage will be synchronized with the progress as a reference.

, finishing (such as a group in a, B, C three storage server, a to C synchronization schedule for T1 (T1 previously written documents have been synchronized to B, B to C synchronized to the time stamp for the T2 T2 > T1), the tracker receives the synchronization schedule information, will be the minimum of the C synchronization timestamp, the cases in T1 C synchronization timestamp T1 (i.e. all T1 previously written data is synchronized to the C); similarly, according to the above rules tracker for a and B to generate a synchronized time stamp.

Six, FastDFS file download

After the success of the client UploadFile, will get a storage generated file name, the next client in accordance with the file name you can access to the file.

Write the picture here.

Like file upload, when the downloadfile client can choose any server tracker. Tracker send download request to a tracker, must put on the file name information, tracke filename parsing a file group, size, creation time information from and to the request choice a storage used to service read requests.

This paper is in reading a great God of the finishing and excerpts, and added some of their own thinking, attach the following God link:Http://blog.yunnotes.net/index.php/fastdfs_design/

top
Five
step on
Zero
Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website
    personal data
    • visit60330 times
    • Integral:One thousand nine hundred and eighty-seven
    • Grade
    • Rank:11980th name
    • original91
    • Reproduced:9
    • Translation:0
    • Comments:62
    Blog column
    Latest comments