TAILIEUCHUNG - MySQL High Availability- P5

MySQL High Availability- P5: A lot of research has been done on replication, but most of the resulting concepts are never put into production. In contrast, MySQL replication is widely deployed but has never been adequately explained. This book changes that. Things are explained here that were previously limited to people willing to read a lot of source code and spend a lot of time debugging it in production, including a few late-night sessions. | NODE array localhost 3310 var run mysqld function getShardAndNodeFromUserId userId common global NODE 1 shardNo shardNumber userId 2 row NODE shardNo count NODE db_server row 0 localhost row 2 row 0 row 1 conn mysql_connect db_server query_user 3 mysql_select_db shard_ shardNo conn return array shardNo conn function getShardAndNodeFromArticleId articleId common query SELECT user_id FROM article_author WHERE article_id d mysql_select_db common result mysql_query sprintf query articleId link row mysql_fetch_row result return getShardAndNodeFromUserId row 0 common Updating or reading a shard After you have identified the shard number and the node it is time to create the functions to retrieve information from the shards. Example 5-10 defines two such functions getArticlesForUser This function accepts a user ID and returns an array of all articles the user has written. The partition function ensures that all articles are on the same shard so the function in line 1 computes the shard number shared by all the articles. The node for the shard is then fetched in line 2. After that the correct database name for the shard is computed line 3 and a single query is sent to the node to retrieve all the articles in the shard. getCommentsForArticle This function accepts a user ID and an article ID and returns an array consisting of the article and all comments for the article. In this particular case the user ID is part of the full article ID so it is available to the caller without further searching. The functions are pretty straightforward and after the correct shard has been identified it is sufficient to send the query to the correct node. Since there can be several shards on the same node it is necessary to ensure the correct database is read. To simplify the presentation the function does not contain any error handling at all. Example 5-10. PHP functions for retrieving articles and comments function getArticlesForUser userId common query END_OF_SQL SELECT .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.