In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
Today, I would like to talk to you about what the principle of Swift is, many people may not know much about it. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
Background and overview
Swift was originally a highly available distributed object storage service developed by Rackspace and contributed to the OpenStack open source community as one of its initial core sub-projects in 2010 to provide virtual machine mirror storage services for its Nova sub-project. Swift is built on a relatively cheap standard hardware storage infrastructure without using RAID (disk redundancy Array). By introducing consistent hashing technology and data redundancy at the software level, it achieves high availability and scalability at the expense of a certain degree of data consistency, and supports multi-tenant mode, container and object read and write operations, which is suitable for solving the problem of unstructured data storage in Internet application scenarios.
This project is based on Python, adopts Apache 2.0 license agreement, and can be used to develop commercial systems.
Fundamentals consistent hash (Consistent Hashing)
For massive-level objects, they need to be stored on thousands of servers and hard disk devices. The first step is to solve the addressing problem, that is, how to distribute objects to these device addresses. Swift is based on consistent hashing technology, through calculation, objects can be evenly distributed to the virtual nodes in the virtual space, and the amount of data that needs to be moved can be greatly reduced when adding or deleting nodes; the size of the virtual space usually uses the n-power of 2 to facilitate efficient shift operations; then the virtual nodes are mapped to the actual physical storage devices through the unique data structure Ring (ring) to complete the addressing process.
Figure 1. Consistent hash
As shown in figure 1, the hash space increasing counterclockwise has four bytes with a total length of 32 bits, with an integer range of [0,232-1]; moving the hash result to the right produces 232m virtual nodes, such as eight virtual nodes in the case of mreply 29. In the actual deployment, the appropriate number of virtual nodes needs to be carefully calculated to achieve a balance between storage space and workload.
Data consistency Model (Consistency Model)
According to Eric Brewer's CAP (Consistency,Availability,Partition Tolerance) theory, it is impossible to satisfy three aspects at the same time. Swift abandons strict consistency (satisfying ACID transaction level) and uses the final consistency model (Eventual Consistency) to achieve high availability and infinite scalability. In order to achieve this goal, Swift adopts the Quorum arbitration agreement (Quorum means a quorum):
(1) definition: n: total number of copies of data; W: number of copies confirmed to be accepted for write operations; R: number of copies for read operations
(2) strong consistency: RendW > N to ensure that the read and write operations on the replica will intersect, thus ensuring that the latest version can be read; if Whistle N < R > 1, then all updates are required, which is suitable for strong consistency in a large number of read / write scenarios; if Renewal N < W > 1, only one copy is updated, and the latest version is obtained by reading all copies, which is suitable for strong consistency in a large number of writes and a small number of read scenarios.
(3) weak consistency: R+WN/2, which ensures that the set of replicas of read and write operations produces at least one intersection, that is, Runw > N. The default configuration of Swift is Noble 3, which means that there will be 3 replicas of each object, which will be stored on nodes in different areas as far as possible; Word2 means that at least 2 copies need to be updated before a write is successful; when ringing 1 means that a read operation is successful, the old version (weak consistency model) may be read. When running 2, you need to add the x-newest=true parameter to the request header of the read operation to read the metadata information of the two copies at the same time, and then compare the timestamps to determine which is the latest version (strong consistency model); if the data is inconsistent, the backend service process will complete data synchronization through detection and replication protocols within a certain time window, so as to ensure the final consistency. As shown in figure 2:
Figure 2. Example of Quorum protocol
Data structure of ring
The ring is designed to map virtual nodes (partitions) to a set of physical storage devices and provide some redundancy, and its data structure consists of the following information:
The storage device list and device information include a unique identification number (id), an area number (zone), a weight (weight), an IP address (ip), a port (port), a device name (device) and metadata (meta).
Partition-to-device mapping (replica2part2dev_id array)
Calculate the displacement of the partition number (part_shift integer, m in figure 1)
Take the calculation process of finding an object as an example:
Figure 3. Data mechanism of ring
Use the object's hierarchical structure account/container/object as the key, use the MD5 hash algorithm to get a hash value, and move the first 4 bytes of the hash value to the right to get the partition index number, the number of bits to be moved is specified by the part_shift setting above Find all the device numbers corresponding to the partition in the partition-to-device mapping table (replica2part2dev_id) according to the partition index number. These devices will be selected and deployed in different areas (Zone) as far as possible, which is just an abstract concept. It can be a machine, a rack, or even a cluster in a building to provide the highest level of redundancy. It is recommended to deploy at least 5 areas. The weight parameter is a relative value that can be adjusted according to the size of the disk. The higher the weight, the more space can be allocated and more partitions can be deployed.
Swift defines rings for accounts, containers, and objects, and the process of finding accounts and containers is the same.
Data model
Swift uses a hierarchical data model and has a three-tier logical structure: Account/Container/Object (account / container / object). There is no limit on the number of nodes in each layer and can be expanded at will. Accounts and personal accounts here are not a concept, but can be understood as tenants, which are used as a top-level isolation mechanism and can be used by multiple personal accounts; containers represent a set of objects, similar to folders or directories; leaf nodes represent objects, which are composed of metadata and content, as shown in figure 4:
Figure 4. Swift data model
Click to view the larger image
System architecture
Swift adopts a completely symmetrical, resource-oriented distributed system architecture design, and all components can be expanded to avoid spreading due to a single point of failure and affecting the operation of the whole system; the communication mode adopts non-blocking Imax O mode, which improves the system throughput and response ability.
Figure 5. Swift system architecture
Click to view the larger image
Swift components include:
Proxy service (Proxy Server): the external object service API looks up the service address based on the information of the ring and forwards the user's request to the corresponding account, container or object service. Due to the stateless REST request protocol, you can scale out to balance the load.
Authentication Service (Authentication Server): verifies the identity information of the access user and obtains an object access token (Token) that is valid for a certain period of time; verifies the validity of the access token and caches it until the expiration time.
Caching service (Cache Server): the cached content includes object service tokens, account and container existence information, but does not cache the data of the object itself; caching service can use Memcached cluster, and Swift will use consistent hashing algorithm to allocate cache addresses.
Account service (Account Server): a service that provides account metadata and statistics and maintains a list of contained containers, with the information for each account stored in an SQLite database.
Container service (Container Server): a service that provides container metadata and statistics and maintains a list of objects contained, and the information for each container is also stored in an SQLite database.
Object service (Object Server): provides object metadata and content services. The content of each object is stored in the file system as a file, and the metadata is stored as a file attribute. It is recommended to use a XFS file system that supports extended attributes.
Replication Service (Replicator): checks whether the local partition replica and the remote replica are consistent, specifically by comparing the hash file with the advanced watermark, and updates the remote copy with Push when inconsistencies are found, for example, the object replication service uses the remote file copy tool rsync to synchronize; another task is to ensure that the marked deleted objects are removed from the file system.
Update service (Updater): when an object cannot be updated immediately due to high load, the task will be serialized to queue in the local file system for asynchronous updates after the service is restored For example, if the container server does not update the object list in time after the object is successfully created, the update operation of the container will enter the queue, and the update service will scan the queue and update the queue accordingly after the system returns to normal.
Audit Service (Auditor): checks the integrity of objects, containers, and accounts. If bit-level errors are found, files are quarantined and other copies are made to overwrite locally corrupted copies; other types of errors are logged.
Account cleanup Service (Account Reaper): removes an account marked for deletion and deletes all containers and objects it contains.
API
Swift provides HTTP-based REST service interfaces through Proxy Server to CRUD accounts, containers and objects. Before accessing the Swift service, you need to obtain the access token through the authentication service, and then add the header information X-Auth-Token to the request sent. The following is an example of a request to return a list of containers in an account:
GET / v1 / HTTP/1.1Host: storage.swift.comX-Auth-Token: eaaafd18-0fed-4b3a-81b4-663c99ec1cbb response header information contains status code 200. container list is contained in the response body: HTTP/1.1 200 OkDate: Thu, 07 Jan 2013 18:57:07 GMTServer: ApacheContent-Type: text/plain; charset=UTF-8Content-Length: 32imagesmoviesdocumentsbackups
All the operations supported by Swift can be summarized into Table 1:
Table 1. Swift RESTful API summary
Resource type URLGETPUTPOSTDELETEHEAD account / account/ get container list-get account metadata container / account/container get object list create container update container metadata delete container get container metadata object / account/container/object get object content and metadata create, update or copy object update object metadata delete object get object metadata
Detailed API specifications can be found in the developer's Guide. Application development can be implemented with the binding of Python, which is already included in the Swift project. If you use other programming languages, you can refer to Rackspace's Cloud Files API that is compatible with Swift and support binding in languages such as Java,.Net,Ruby,PHP.
As a stable and highly available open source object storage, OpenStack Swift has been commercially deployed by many enterprises, such as Sina's App Engine has been launched and provides Swift-based object storage services, Korea Telecom's Ucloud Storage services. There is reason to believe that because of its complete openness, wide user base and community contributors, Swift may become an open standard for cloud storage, thus breaking the monopoly position of Amazon S3 in the market and driving cloud computing towards a more open and interoperable direction.
After reading the above, do you have any further understanding of the principle of Swift? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.