{"id":342851,"date":"2022-12-19T09:00:28","date_gmt":"2022-12-19T09:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=342851"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=342851","title":{"rendered":"<span>\u0411\u0430\u0437\u0430 \u043f\u043e \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0431\u0430\u0437\u044b<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ec4\/3f8\/614\/ec43f86147fc62a93d87523c54bba7de.png\" width=\"1920\" height=\"1080\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ec4\/3f8\/614\/ec43f86147fc62a93d87523c54bba7de.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u0432\u0430\u0436\u043d\u0435\u0439\u0448\u0438\u0445 \u043d\u0435\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0438\u043d\u0434\u0443\u0441\u0442\u0440\u0438\u0438 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f. \u0420\u043e\u0441\u0442 \u0431\u0438\u0437\u043d\u0435\u0441\u0430 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b IT \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043a\u0430\u043a \u0440\u043e\u0441\u0442 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u0446\u0435\u043d\u044b \u043e\u0442\u043a\u0430\u0437\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041d\u0430\u043c \u0432\u0441\u0435\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u0441 \u0441\u043e\u0442\u043d\u0435\u0439, \u0442\u0430\u043a \u0438 \u0441 \u0441\u043e\u0442\u043d\u0435\u0439 \u0442\u044b\u0441\u044f\u0447 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0435\u0449\u0435 \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b \u0434\u043b\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. <\/p>\n<p>\u041c\u044b \u043d\u0430 \u043f\u0430\u043b\u044c\u0446\u0430\u0445 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u043e\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0438 \u0434\u0430\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u044d\u0442\u0430\u043f \u00ab\u0440\u043e\u0441\u0442\u0430\u00bb.<\/p>\n<h4>\u041e \u0447\u0451\u043c \u0440\u0435\u0447\u044c?<\/h4>\n<p>\u0428\u0430\u0440\u0434\u0438\u043d\u0433 (\u0438\u043b\u0438 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435) \u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439, \u0448\u0430\u0440\u0434\u043e\u0432 (\u043e\u0442 \u0430\u043d\u0433\u043b. <em>shard<\/em> \u2014 \u043e\u0441\u043a\u043e\u043b\u043e\u043a). \u041d\u0435 \u043f\u0443\u0442\u0430\u0439\u0442\u0435 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0435\u0439, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u043c\u0438 \u0447\u0430\u0441\u0442\u044f\u043c\u0438 \u043e\u0431\u0449\u0435\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u0430 \u043a\u043e\u043f\u0438\u044f\u043c\u0438 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430.\u00a0<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/3df\/317\/049\/3df3170493c064434109655e7b9c58c4.png\" width=\"662\" height=\"442\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/3df\/317\/049\/3df3170493c064434109655e7b9c58c4.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0428\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u0430 \u0441\u0447\u0451\u0442 \u0438\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u044f\u0446\u0438\u044f\u043c\u0438 \u0411\u0414 (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0436\u0435\u043b\u0435\u0437\u043a\u0430\u0445), \u0447\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u043e\u0442\u0437\u044b\u0432\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0430\u0437\u043c\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0446\u0435\u043b\u043e\u043c \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435.\u00a0<\/p>\n<p>\u0428\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u043e\u0442 \u0430\u043d\u0433\u043b. <em>partition<\/em> \u2014 \u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0440\u0430\u0437\u0434\u0435\u043b). \u041e\u0442\u043b\u0438\u0447\u0438\u0435 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0439 \u0411\u0414, \u0430 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0445 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c \u0411\u0414.\u00a0<\/p>\n<h4>\u0421\u043f\u043e\u0441\u043e\u0431\u044b \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h4>\n<p>\u041e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 \u0411\u0414<\/strong>. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0430\u0437\u044b \u2014 MongoDB, Elasticsearch, ClickHouse \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u2014 \u0443\u043c\u0435\u044e\u0442 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u0441\u0432\u043e\u0438\u043c\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e. \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u044d\u0442\u043e \u043b\u0443\u0447\u0448\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 \u043a \u0411\u0414<\/strong>. \u0421\u0430\u043c\u044b\u0439 \u0441\u043f\u043e\u0440\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Vitess \u0438\u043b\u0438 Citus, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0435\u0441\u0442\u044c \u0440\u0438\u0441\u043a \u043f\u043e\u0442\u0435\u0440\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u043c\u0438 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438<\/strong>. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0411\u0414 \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u044e\u0442 \u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430, \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0432\u044b\u0442\u0435\u043a\u0430\u044e\u0449\u0438\u043c\u0438 \u0440\u0438\u0441\u043a\u0430\u043c\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u044d\u0442\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 \u0441\u0445\u043e\u0436\u0438: \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u043b\u044e\u0447 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (\u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u043a\u0430 \u0438\u043b\u0438 \u0445\u0435\u0448 \u0437\u0430\u043f\u0438\u0441\u0438) \u0438 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043d\u0438\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0448\u0430\u0440\u0434. \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043a\u043b\u044e\u0447\u0438 \u0441\u0442\u0430\u0440\u0430\u044e\u0442\u0441\u044f \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u044b\u043b\u0438 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u043e \u0448\u0430\u0440\u0434\u0430\u043c. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0411\u0414.\u00a0<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u044e\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430\u043c\u0438. \u041d\u0435\u043b\u044c\u0437\u044f \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u0438 \u043e \u00ab\u0433\u043e\u0440\u044f\u0447\u0438\u0445\u00bb \u0434\u0430\u043d\u043d\u044b\u0445, \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0447\u0430\u0449\u0435, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430 \u0448\u0430\u0440\u0434\u044b \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0443, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0432 \u043a\u0430\u043a\u043e\u0439 \u0448\u0430\u0440\u0434 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443.\u00a0<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h4>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0435 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0433\u043e\u0440\u044f\u0447\u043e \u043b\u044e\u0431\u0438\u043c\u043e\u0439 \u0432 Ozon PostgreSQL. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 Go, \u0430 \u043c\u0438\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Goose. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0430\u043c\u0438 \u0448\u0430\u0440\u0434\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u044f\u0446\u0438\u044e \u0411\u0414. \u041e\u0442\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043a\u0430\u0442\u044b\u0432\u0430\u0442\u044c PostgreSQL, \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0430\u0448 Storage \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u0448\u0430\u0440\u0434\u043e\u0432:\u00a0<\/p>\n<pre><code class=\"go\">\/\/ \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0448\u0430\u0440\u0434\u043e\u0432. const bucketQuantity = 2  const (     Shard1 ShardNum = iota     Shard2 ) \/\/ \u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0439 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438. type ShardNum int type shardMap map[ShardNum]*sqlx.DB  type Storage struct {     shardMap shardMap } <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0434\u043b\u044f Storage \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u044c\u043c\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0432\u0441\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0441 \u0411\u0414. <\/p>\n<pre><code class=\"go\">func initShardMap(ctx context.Context, dsns map[ShardNum]string) shardMap {     m := make(shardMap, len(dsns))     for sh, dsn := range dsns {     m[sh] = discoveryShard(ctx, dsn)     }      return m }  func discoveryShard(ctx context.Context, dsn string) *sqlx.DB {     db, err := sqlx.ConnectContext(ctx, \"postgres\", dsn)     if err != nil {     panic(err)     }      return db }  func NewStorage(ctx context.Context, dsns map[ShardNum]string) *Storage {     return &amp;Storage{     shardMap: initShardMap(ctx, dsns),     } } <\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0448\u0430\u0440\u0434\u044b \u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u043e\u0442\u0442\u0443\u0434\u0430. \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0451 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0448\u0430\u0440\u0434 \u0438\u0434\u0442\u0438.\u00a0<\/p>\n<p>\u041f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 ID (\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a) \u043d\u0430\u043c \u0445\u0432\u0430\u0442\u0438\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"go\">func (s *Storage) shardByItemID(itemID int64) ShardNum {    return ShardNum(itemID % bucketQuantity) } <\/code><\/pre>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043d\u0435\u0437\u0430\u0443\u0440\u044f\u0434\u043d\u044b\u0439\u00a0 \u043c\u0435\u0442\u043e\u0434 \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 \u0411\u0414. \u0422\u0443\u0442 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0435 \u0411\u0414 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430, \u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441 (<em>*sqlx.DB<\/em>) \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0448\u0430\u0440\u0434\u0430 \u0438\u0437 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b.<\/p>\n<pre><code class=\"go\">func (s *Storage) getItemsByID(ctx context.Context, shard *sqlx.DB, itemsIDs []int64) ([]models.Item, error) {    items := make([]models.Item, 0)      query, args, err := sq.        Select(itemsTableFields...).        From(itemsTable).        Where(sq.Eq{itemIDField: itemsIDs}).        PlaceholderFormat(sq.Dollar).        ToSql()    if err != nil {        err = errors.Wrap(err, \"[create query]\")        return items, err    }      err = shard.SelectContext(ctx, &amp;items, query, args...)    return items, err } <\/code><\/pre>\n<p>\u0421\u0430\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0448\u0430\u0440\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0447\u0443\u0442\u044c \u0432\u044b\u0448\u0435, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0448\u0438 <em>ItemIDs<\/em> \u043f\u043e \u043a\u0443\u0431\u044b\u0448\u043a\u0430\u043c. \u0421\u0430\u043c\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"go\">func (s *Storage) sortItemsIDsByShard(itemIDs ...int64) map[ShardNum][]int64 {    shardToItems := make(map[ShardNum][]int64)      for _, id := range itemIDs {        shardID := s.shardByItemID(id)        if _, ok := shardToItems[shardID]; !ok {            shardToItems[shardID] = make([]int64, 0)        }          shardToItems[shardID] = append(shardToItems[shardID], id)    }      return shardToItems } <\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u0430\u044f \u043e\u0431\u0451\u0440\u0442\u043e\u0447\u043a\u0430 \u2014 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e. \u0412\u043e\u0442 \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f Item. \u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u043d\u043e \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438\u00a0 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u044a\u0435\u0434\u0430\u044e\u0442 \u0440\u0430\u0441\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u043d\u0430\u043b\u043e\u0432.<\/p>\n<pre><code class=\"go\">func (s *Storage) GetItems(ctx context.Context, itemIDs ...int64) ([]models.Item, error) {    shardToItems := s.sortItemsIDsByShard(itemIDs...)      respChan := make(chan []models.Item, len(shardToItems))    errChan := make(chan error, len(shardToItems))    wg := &amp;sync.WaitGroup{}      for shardID, ids := range shardToItems {        wg.Add(1)        shard := s.shardMap[shardID]        go s.asyncGetItemsByID(ctx, shard, ids, wg, respChan, errChan)    }      wg.Wait()    close(respChan)    close(errChan)      result := make([]models.Item, 0)    for items := range respChan {        result = append(result, items...)    }      errs := make([]error, 0, len(errChan))    for e := range errChan {        errs = append(errs, e)    }    err := multierr.Combine(errs...)      return result, err } <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0442\u0435\u0440\u044f\u0442\u044c \u0441\u043c\u044b\u0441\u043b <em>getItemsByID<\/em> \u0437\u0430 \u043d\u0430\u0433\u0440\u043e\u043c\u043e\u0436\u0434\u0435\u043d\u0438\u0435\u043c \u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u0438 Wait-\u0433\u0440\u0443\u043f\u043f, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u043d\u0435\u043c \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 <em>asyncGetItemsByID<\/em>:<\/p>\n<pre><code class=\"go\">unc (s *Storage) asyncGetItemsByID(    ctx context.Context,    shard *sqlx.DB,    itemsIDs []int64,    wg *sync.WaitGroup,    resp chan&lt;- []models.Item,    errs chan&lt;- error, ) {    defer wg.Done()    items, err := s.getItemsByID(ctx, shard, itemsIDs)    if err != nil {        errs &lt;- errors.Wrapf(err, \"[getItemsByID] can't select from shard %d\", shard)    }      resp &lt;- items } <\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0412\u0441\u0451 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u0435\u043b\u044b\u0432\u0430\u0435\u043c \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0448\u0430\u0440\u0434\u044b:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"go\">func (s *Storage) AddItems(ctx context.Context, items ...models.Item) error {    itemsByShardMap := s.itemsByShard(items...)    errChan := make(chan error, len(itemsByShardMap))    wg := &amp;sync.WaitGroup{}      for shardID, items := range itemsByShardMap {        wg.Add(1)        shard := s.shardMap[shardID]        go s.asyncAddItems(ctx, errChan, wg, shard, items...)    }      wg.Wait()    close(errChan)      errs := make([]error, 0, len(errChan))    for e := range errChan {        errs = append(errs, e)    }      return multierr.Combine(errs...) }   func (s *Storage) itemsByShard(items ...models.Item) map[ShardNum][]models.Item {    itemsByShard := make(map[ShardNum][]models.Item)      for _, item := range items {        shardID := s.shardByItemID(item.ID)        if _, ok := itemsByShard[shardID]; !ok {            itemsByShard[shardID] = make([]models.Item, 0)        }          itemsByShard[shardID] = append(itemsByShard[shardID], item)    }      return itemsByShard }   func (s *Storage) asyncAddItems(    ctx context.Context,    errChan chan&lt;- error, wg *sync.WaitGroup,    shard *sqlx.DB,    items ...models.Item) {    defer wg.Done()    err := s.addItems(ctx, shard, items...)    errChan &lt;- errors.Wrapf(err, \"[asyncAddItems] can't insert to shard\") }   func (s *Storage) addItems(ctx context.Context, shard *sqlx.DB, items ...models.Item) error {    q := sq.        Insert(itemsTable).        Columns(itemsTableFields...).        PlaceholderFormat(sq.Dollar)      for _, item := range items {        q = q.Values(item.ID, item.CreatedAt)    }      query, args, err := q.ToSql()    if err != nil {        return errors.Wrap(err, \"[create query]\")    }      _, err = shard.DB.ExecContext(ctx, query, args...)    return err } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0443 \u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0438\u043a \u0434\u043b\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043b\u0430:<\/p>\n<pre><code class=\"go\">#!\/usr\/bin\/env bash export MIGRATION_DIR=.\/migrations\/   if [ \"${STAGE}\" = \"production\" ]; then    if [ \"$1\" = \"--dryrun\" ]; then        goose -dir ${MIGRATION_DIR} postgres \"user=${USER1} password=${PASSWORD1} dbname=${DBNAME1} host=${HOST1} port=${PORT1} sslmode=disable\" status        goose -dir ${MIGRATION_DIR} postgres \"user=${USER2} password=${PASSWORD2} dbname=${DBNAME2} host=${HOST2} port=${PORT2} sslmode=disable\" status    else        goose -dir ${MIGRATION_DIR} postgres \"user=${USER1} password=${PASSWORD1} dbname=${DBNAME1} host=${HOST1} port=${PORT1} sslmode=disable\" up        goose -dir ${MIGRATION_DIR} postgres \"user=${USER2} password=${PASSWORD2} dbname=${DBNAME2} host=${HOST2} port=${PORT2} sslmode=disable\" up    fi   elif [ \"${STAGE}\" = \"staging\" ]; then    if [ \"$1\" = \"--dryrun\" ]; then        goose -dir ${MIGRATION_DIR} postgres \"user=${USER1} password=${PASSWORD1} dbname=${DBNAME1} host=${HOST1} port=${PORT1} sslmode=disable\" status    else        goose -dir ${MIGRATION_DIR} postgres \"user=${USER1} password=${PASSWORD1} dbname=${DBNAME1} host=${HOST1} port=${PORT1} sslmode=disable\" up    fi elif [ \"${STAGE}\" = \"development\" ]; then    exit 0 fi <\/code><\/pre>\n<p>\u041e\u0447\u0435\u043d\u044c \u0443\u0434\u043e\u0431\u043d\u043e \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0433\u0434\u0435 \u0435\u0449\u0435 \u043d\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0438\u0445 \u043f\u0435\u0440\u0435\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0442\u044c. \u041d\u043e \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u043c\u044b \u0448\u0430\u0440\u0434\u0438\u043c \u0440\u0430\u0431\u043e\u0447\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435? \u0422\u0443\u0442, \u043a\u0430\u043a \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u0441\u044f \u0443 \u043d\u0430\u0441 \u043d\u0430 \u0420\u0443\u0441\u0438, case-by-case.<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c? \u041f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e! \u041e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0440\u0430\u0437\u0431\u043e\u0440 \u043e\u0447\u0435\u0440\u0435\u0434\u0435\u0439, \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438\u043b\u0438 \u0432\u043e\u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0434\u0435\u043b\u0430\u0435\u043c \u0440\u0435\u0437\u0435\u0440\u0432\u043d\u0443\u044e \u043a\u043e\u043f\u0438\u044e \u0431\u0430\u0437\u044b, \u0435\u0441\u043b\u0438 \u0435\u0449\u0451 \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u043b\u0438, \u043f\u0435\u0440\u0435\u0442\u0430\u0441\u043a\u0438\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u044e\u0447\u043e\u043c \u0438 \u0441\u043d\u043e\u0432\u0430 \u0432\u0432\u043e\u0434\u0438\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0432 \u044d\u043a\u0441\u043f\u043b\u0443\u0430\u0442\u0430\u0446\u0438\u044e, \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0434\u044f \u0440\u0435\u0433\u0440\u0435\u0441\u0441\u0438\u043e\u043d\u043d\u043e\u0435 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435.<\/p>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u044b? \u0422\u043e\u0433\u0434\u0430 \u0434\u0435\u043b\u0430\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0443 \u0432\u043d\u0443\u0442\u0440\u0438 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f. \u041f\u0438\u0448\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0432 \u043d\u043e\u0432\u044b\u0435 \u0448\u0430\u0440\u0434\u044b. \u0427\u0438\u0442\u0430\u0435\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u0437 \u043d\u043e\u0432\u043e\u0433\u043e \u0448\u0430\u0440\u0434\u0430; \u0435\u0441\u043b\u0438 \u0442\u0430\u043c \u043d\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u0441\u0442\u0430\u0440\u044b\u043c \u0448\u0430\u0440\u0434\u0430\u043c. \u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u0440\u043e\u043c \u0448\u0430\u0440\u0434\u0435, \u0442\u043e \u043f\u0440\u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0445 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u0442\u044c \u0432 \u043d\u043e\u0432\u044b\u0439 \u2014 \u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0448\u0430\u0440\u0434\u0430\u043c\u0438. \u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442. \u0418 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435, \u0432\u0441\u0435 \u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0435\u0445\u0430\u043b\u0438 \u0438\u043b\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0435, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u0434\u0443\u0442 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0414\u0430, \u0438 \u043d\u0430 \u043f\u0435\u0440\u0432\u044b\u0445 \u043f\u043e\u0440\u0430\u0445 \u044d\u0442\u043e \u043d\u0435 \u0442\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0430 \u043e\u0442\u0437\u044b\u0432\u0447\u0438\u0432\u043e\u0441\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0431\u0443\u0434\u044c\u0442\u0435 \u043a \u044d\u0442\u043e\u043c\u0443 \u0433\u043e\u0442\u043e\u0432\u044b.\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0438\u0448\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0411\u0414 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c \u0438\u0437 \u0443\u0441\u043b\u043e\u0432\u043d\u043e\u0439 kafka, \u0430 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b (REST\/GRPC) \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0442\u0430\u044e\u0449\u0438\u0435 (\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0434\u043b\u044f event sourcing), \u0442\u043e \u043c\u044b \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0447\u0442\u0435\u043d\u0438\u0435 \u0438\u0437 kafka, \u0432\u044b\u043a\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0432 prod \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0436\u0435 \u0436\u0438\u0432\u0435\u0442 \u0441 \u043d\u043e\u0432\u043e\u0439 \u0441\u0445\u0435\u043c\u043e\u0439 \u0448\u0430\u0440\u0434\u043e\u0432, \u043d\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0448\u043b\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 (\u043e\u043d\u043e \u0436\u0435 canary-deploy). \u0414\u0430\u043b\u0435\u0435 \u0434\u0436\u043e\u0431\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0438\u0442\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0441\u0442\u0430\u0440\u043e\u043c\u0443 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0443, \u0438 \u043f\u0438\u0448\u0435\u0442 \u0432 \u043d\u043e\u0432\u044b\u0439, \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u043c\u043e\u0436\u043d\u043e \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0438 \u0443\u0434\u0430\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0441\u0442\u0430\u0440\u043e\u0439 \u0441\u0445\u0435\u043c\u0435.\u00a0<\/p>\n<\/li>\n<\/ul>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0448\u0430\u0440\u0434, \u0430 \u043f\u043e\u0442\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0438\u0445 \u0438\u0437 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u043d\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u044f \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0435 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u043b.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u043b\u043d\u043e\u0442\u044b \u043a\u0430\u0440\u0442\u0438\u043d\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043c \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441. \u041f\u0438\u0441\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u0443\u0434\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u0448\u0430\u0440\u0434\u043e\u0432, \u0430 \u0432\u043e\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0438\u0445 \u0431\u0443\u0434\u0435\u043c \u0441\u0440\u0430\u0437\u0443 \u0438\u0437 \u0441\u0442\u0430\u0440\u043e\u0433\u043e \u0438 \u043d\u043e\u0432\u043e\u0433\u043e.\u00a0<\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0451 \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0435\u0439 \u0441\u0445\u0435\u043c\u044b \u0448\u0430\u0440\u0434\u043e\u0432 \u0432\u043d\u0443\u0442\u0440\u0438 Storage. \u0412\u043d\u0435\u0441\u0451\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b:<\/p>\n<pre><code class=\"go\">const legacyBucketQuantity = 2 const bucketQuantity = 3   const (    Shard1 ShardNum = iota    Shard2    Shard3 ) <\/code><\/pre>\n<p>\u0417\u0430\u0432\u0435\u0434\u0451\u043c \u0432\u043d\u0443\u0442\u0440\u0438 Storage <em>shardMapLegacy<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0434\u043e\u0440\u0435\u0448\u0430\u0440\u0434\u0438\u043d\u0433\u043e\u0432\u044b\u0439 \u043c\u0430\u043f\u043f\u0438\u043d\u0433:<\/p>\n<pre><code class=\"go\">type Storage struct {     shardMapLegacy shardMap     shardMap   shardMap } <\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f. \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 Storage \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u0434\u0432\u0435 \u0441\u0445\u0435\u043c\u044b:<\/p>\n<pre><code class=\"go\">func NewStorage(ctx context.Context, dsns map[ShardNum]string, dsnsLegacy map[ShardNum]string) *Storage {    return &amp;Storage{        shardMap:       initShardMap(ctx, dsns),        shardMapLegacy: initShardMap(ctx, dsnsLegacy),    } } <\/code><\/pre>\n<p>\u0417\u0430\u0432\u043e\u0434\u0438\u043c \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f <em>shardID<\/em>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u043b\u0435 \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0435\u0433\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c:<\/p>\n<pre><code class=\"go\">func (s *Storage) legacyShardByItemID(itemID int64) ShardNum {     return ShardNum(itemID % legacyBucketQuantity) } <\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u0435\u0449\u0451 \u0447\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0434\u0430. \u0420\u0435\u0447\u044c \u043e \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043b\u043d\u043e\u0439 \u043a\u043e\u043f\u0438\u0438 <em>sortItemsIDsByShard<\/em>; \u0440\u0430\u0437\u043d\u0438\u0446\u0430 \u043b\u0438\u0448\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u0448\u0430\u0440\u0434\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0440\u0430\u043d\u0435\u0435 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e.\u00a0<\/p>\n<pre><code class=\"go\">func (s *Storage) sortItemsIDsByLegacyShard(itemIDs ...int64) map[ShardNum][]int64 {     shardToItems := make(map[ShardNum][]int64)      for _, id := range itemIDs {     shardID := s.legacyShardByItemID(id)     if _, ok := shardToItems[shardID]; !ok {     shardToItems[shardID] = make([]int64, 0)     }      shardToItems[shardID] = append(shardToItems[shardID], id)     }      return shardToItems }  <\/code><\/pre>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f <em>Items<\/em> \u0432 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043d\u0435 \u043d\u0443\u0436\u0434\u0430\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0443\u0441\u043b\u043e\u0432\u0438\u043b\u0438\u0441\u044c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0438\u0448\u0435\u043c \u0432\u0441\u0435\u0433\u0434\u0430 \u0432 \u0441\u0432\u0435\u0436\u0438\u0435 \u0448\u0430\u0440\u0434\u044b, \u0430 \u0432\u043e\u0442 <em>GetItems<\/em> \u043d\u0430\u0434\u043e \u043f\u043e\u0434\u043f\u0440\u0430\u0432\u0438\u0442\u044c. \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u043d\u043a\u0443\u0440\u0435\u043d\u0442\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 \u0441\u0440\u0430\u0437\u0443 \u0432 \u0434\u0432\u0435 \u0441\u0445\u0435\u043c\u044b, \u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043a\u043b\u0435\u0438\u0432\u0430\u0442\u044c, \u043e\u0442\u0434\u0430\u0432\u0430\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u043c \u0441 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430 \u0448\u0430\u0440\u0434\u043e\u0432.<\/p>\n<pre><code class=\"go\">func (s *Storage) GetItems(ctx context.Context, itemIDs ...int64) ([]models.Item, error) {    wg := &amp;sync.WaitGroup{}      resultLegacy := make([]models.Item, 0)    resultActual := make([]models.Item, 0)      var err error      wg.Add(1)    go func() {        defer wg.Done()          res, e := s.getItems(ctx, itemIDs...)        err = multierr.Append(err, e)        resultActual = res    }()      wg.Add(1)    go func() {        defer wg.Done()          res, e := s.getItemsFromLegacyShardMap(ctx, itemIDs...)        err = multierr.Append(err, e)        resultLegacy = res    }()      wg.Wait()    result := mergeItems(resultActual, resultLegacy)      return result, err } <\/code><\/pre>\n<p>\u0421\u043a\u043b\u0435\u0439\u043a\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:\u00a0<\/p>\n<pre><code class=\"go\">func mergeItems(items, legacyItems []models.Item) []models.Item {    itemsMap := make(map[models.Item]struct{})      for _, item := range legacyItems {        itemsMap[item] = struct{}{}    }      for _, item := range items {        itemsMap[item] = struct{}{}    }      mergedItems := make([]models.Item, 0, len(itemsMap))    for item, _ := range itemsMap {        mergedItems = append(mergedItems, item)    }      return mergedItems } <\/code><\/pre>\n<p>\u041e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u0435\u0442\u0440\u0438\u043a\u0443 \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e\u0442\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u043e \u0441\u0442\u0430\u0440\u043e\u043c\u0443 \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u043b\u0438\u0441\u044c \u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0442\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0439 \u043b\u0435\u0433\u0430\u0441\u0438-\u0444\u043b\u043e\u0443.\u00a0<\/p>\n<p>\u041f\u0440\u0438 \u0442\u0430\u043a\u043e\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u0435 \u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0432\u043e\u043f\u0440\u043e\u0441: \u0447\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u00ab\u043c\u0451\u0440\u0442\u0432\u044b\u043c\u0438\u00bb \u0434\u0430\u043d\u043d\u044b\u043c\u0438,\u00a0 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u0435\u0436\u0430\u0442 \u043d\u0435 \u0432 \u0441\u0432\u043e\u0438\u0445 \u0448\u0430\u0440\u0434\u0430\u0445 \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430?\u00a0<\/p>\n<p>\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0432 \u043b\u043e\u0431: \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0437\u0430\u0440\u0435\u0448\u0430\u0440\u0434\u0438\u043b\u0438\u0441\u044c \u0441 \u0434\u0432\u0443\u0445 \u0434\u043e \u0447\u0435\u0442\u044b\u0440\u0451\u0445 \u0448\u0430\u0440\u0434\u043e\u0432, \u0438\u0434\u0451\u043c \u2014 \u0438 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u043b\u0435\u0433\u0430\u0441\u0438-\u0448\u0430\u0440\u0434\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u0433\u0434\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0434\u043b\u044f ID \u043a\u043b\u044e\u0447 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0435\u043a\u0443\u0449\u0435\u043c\u0443 \u0448\u0430\u0440\u0434\u0443:<\/p>\n<pre><code class=\"go\">DELETE FROM items WHERE ctid IN (    SELECT ctid    FROM items    WHERE id % 4 NOT IN (2, 2-4)    ); <\/code><\/pre>\n<p>\u0417.\u042b. \u0412\u0430\u0440\u0438\u0430\u043d\u0442 SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u044b \u0445\u0440\u0430\u043d\u0438\u043c \u0433\u043e\u0448\u043d\u044b\u0439 UInt64 \u0432 \u043f\u043e\u0441\u0442\u0433\u0440\u0435\u0432\u043e\u043c BigInt. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0433\u043e\u0448\u043d\u044b\u0435 \u0447\u0438\u0441\u043b\u0430 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0435\u0432\u0440\u0430\u0442\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0440\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0441\u0442\u0433\u0440\u0435\u0432\u044b\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0434\u0435\u043b\u0430\u0435\u043c NOT IN \u0434\u043b\u044f \u0440\u0435\u043d\u0434\u0436\u0430.<\/p>\n<p>\u0418\u043d\u043e\u0433\u0434\u0430 \u0432\u0441\u0442\u0440\u0435\u0447\u0430\u044e\u0442\u0441\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u0433\u0434\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u200e\u200e\u200e\u200e\u00ab\u043f\u0440\u043e\u0442\u0443\u0445\u0430\u0442\u044c\u00bb. \u0412 \u0442\u0430\u043a\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u0441\u0430\u043c\u043e\u0435 \u043b\u043e\u0433\u0438\u0447\u043d\u043e\u0435 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435 \u0440\u0435\u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430, \u0438 \u0434\u043e\u0436\u0434\u0430\u0442\u044c\u0441\u044f \u043f\u043e\u043a\u0430 \u043e\u043d\u0438 \u00ab\u043f\u0440\u043e\u0442\u0443\u0445\u043d\u0443\u0442\u00bb.<\/p>\n<p>\u0418 \u043f\u0430\u0440\u0430 \u0441\u043b\u043e\u0432 \u043e\u0431 \u0443\u043f\u044f\u0447\u043a\u0430\u0445, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u044f \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0441\u044f, \u2014 \u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0439 \u0411\u0414 \u0438 \u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0435 \u0446\u0435\u043b\u044b\u043c\u0438 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u044f\u043c\u0438. \u041f\u043e\u043d\u0430\u0447\u0430\u043b\u0443 \u043a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0438 \u0434\u0430\u0436\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e. \u0412\u0435\u0434\u044c \u0434\u043b\u044f \u0440\u0435\u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0442\u0430\u0449\u0438\u0442\u044c \u0446\u0435\u043b\u0443\u044e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u044e \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u0448\u0430\u0440\u0434\u0430 \u0432 \u0434\u0440\u0443\u0433\u043e\u0439. \u0418 \u044d\u0442\u043e \u0424\u0410\u0422\u0410\u041b\u042c\u041d\u0410\u042f \u041e\u0428\u0418\u0411\u041a\u0410. \u0421\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432\u044b \u0443\u0441\u0442\u0430\u043d\u0435\u0442\u0435 \u043e\u0442 <s>\u0442\u0440\u0451\u0445\u044d\u0442\u0430\u0436\u043d\u043e\u0433\u043e \u043c\u0430\u0442\u0430<\/s> <em>\u043d\u0435\u0433\u043e\u0434\u043e\u0432\u0430\u043d\u0438\u044f<\/em>, \u0432\u044b\u0437\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u044f\u0442\u0438\u044d\u0442\u0430\u0436\u043d\u044b\u043c\u0438 \u043f\u0430\u043a\u0435\u0442\u043d\u044b\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438, \u0438\u0437-\u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0433\u043e\u0440\u044f\u0447\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0432 \u043a\u0435\u0448. \u0422\u0430\u043a\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043b\u0438\u0448\u044c \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u043e \u0434\u0430\u0442\u0435, \u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043e\u0431\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u043a \u0441\u0432\u0435\u0436\u0438\u043c \u0438\u043b\u0438 \u0441\u0442\u0430\u0440\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c, \u043a\u0430\u043a, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e \u043c\u043d\u043e\u0433\u0438\u0445 OLAP-\u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445. \u0412 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043f\u0435\u0440\u0441\u043f\u0435\u043a\u0442\u0438\u0432\u043d\u0435\u0435 \u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043e\u0434\u043d\u043e\u0439 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0438, \u0430 \u0440\u0435\u0448\u0430\u0440\u0434\u0438\u0442\u044c \u0438\u0445 \u043f\u0443\u0442\u0451\u043c \u043f\u043e\u0441\u0442\u0435\u043f\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0430, \u0435\u0441\u043b\u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0411\u0414 \u043d\u0435 \u043f\u0440\u0435\u0434\u0443\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u0442 \u0441\u0432\u043e\u0438\u0445 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0440\u0435\u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0430.<\/p>\n<h4>\u0412\u043c\u0435\u0441\u0442\u043e \u0432\u044b\u0432\u043e\u0434\u0430<\/h4>\n<p>\u0420\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0437\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0440\u0435\u0448\u0430\u0440\u0434\u0438\u043d\u0433\u043e\u043c. \u0410 \u043f\u043e\u0442\u043e\u043c \u0435\u0449\u0451 \u0440\u0430\u0437, \u0438 \u0435\u0449\u0451, \u0438 \u0435\u0449\u0451, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e, \u0435\u0441\u043b\u0438 \u0431\u0438\u0437\u043d\u0435\u0441 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0441\u0442\u0438 \u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u0432\u0441\u0451 \u0431\u043e\u043b\u044c\u0448\u0435. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0438\u0431\u0435\u0440\u0435\u0433\u0438\u0442\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0430\u043c \u043f\u043e\u043c\u043e\u0433\u043b\u0438 \u043e\u0434\u043d\u0430\u0436\u0434\u044b, \u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u0441\u0442\u0440\u0430\u0448\u043d\u043e\u0433\u043e, \u0435\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0432\u044b \u0438\u0445 \u0431\u0443\u0434\u0435\u0442\u0435 \u0440\u0430\u0437 \u0432 \u043f\u043e\u043b\u0433\u043e\u0434\u0430.\u00a0<\/p>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0435 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u043d\u0430\u0434\u043e.\u00a0<\/p>\n<p>\u041a\u043b\u044e\u0447 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u0441 \u0443\u043c\u043e\u043c, \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043c\u0435\u0434\u0438\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0434 \u043c\u0435\u0442\u0440\u0438\u043a\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0447\u0451\u0442\u043a\u043e \u0432\u0438\u0434\u0435\u0442\u044c \u043a\u0430\u0440\u0442\u0438\u043d\u0443 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0438\u0448\u0443\u0442\u0441\u044f, \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0438 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f.<\/p>\n<p>\u041d\u0435 \u0442\u0430\u043a \u0441\u0442\u0440\u0430\u0448\u043d\u043e \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u0440\u0435\u0448\u0430\u0440\u0434\u0438\u043d\u0433. \u0412\u0430\u0436\u043d\u043e \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u043f\u043e\u0434\u0443\u043c\u0430\u0442\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0440\u0435\u0448\u0430\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u043a\u043e\u043d\u0441\u0438\u0441\u0442\u0435\u043d\u0442\u043d\u043e\u0441\u0442\u0438 \u043f\u0440\u0438 \u0440\u0435\u0448\u0430\u0440\u0434\u0438\u043d\u0433\u0435.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/ozontech\/blog\/705912\/\"> https:\/\/habr.com\/ru\/company\/ozontech\/blog\/705912\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0433\u043e\u0440\u0438\u0437\u043e\u043d\u0442\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u0432\u0430\u0436\u043d\u0435\u0439\u0448\u0438\u0445 \u043d\u0435\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u0439 \u0438\u043d\u0434\u0443\u0441\u0442\u0440\u0438\u0438 \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u0432\u0440\u0435\u043c\u044f. \u0420\u043e\u0441\u0442 \u0431\u0438\u0437\u043d\u0435\u0441\u0430 \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b IT \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0447\u0430\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u043a\u0430\u043a \u0440\u043e\u0441\u0442 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u0446\u0435\u043d\u044b \u043e\u0442\u043a\u0430\u0437\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041d\u0430\u043c \u0432\u0441\u0435\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043a\u0430\u043a \u0441 \u0441\u043e\u0442\u043d\u0435\u0439, \u0442\u0430\u043a \u0438 \u0441 \u0441\u043e\u0442\u043d\u0435\u0439 \u0442\u044b\u0441\u044f\u0447 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u0432. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0435\u0449\u0435 \u043d\u0430 \u0441\u0442\u0430\u0434\u0438\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0437\u0430\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b \u0434\u043b\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043e\u0434\u043d\u0438\u043c \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. <\/p>\n<p>\u041c\u044b \u043d\u0430 \u043f\u0430\u043b\u044c\u0446\u0430\u0445 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u0430\u043a \u043e\u043d\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0438 \u0434\u0430\u0436\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u043e\u0442 \u0441\u0430\u043c\u044b\u0439 \u044d\u0442\u0430\u043f \u00ab\u0440\u043e\u0441\u0442\u0430\u00bb.<\/p>\n<h4>\u041e \u0447\u0451\u043c \u0440\u0435\u0447\u044c?<\/h4>\n<p>\u0428\u0430\u0440\u0434\u0438\u043d\u0433 (\u0438\u043b\u0438 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435) \u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u043d\u0430 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439, \u0448\u0430\u0440\u0434\u043e\u0432 (\u043e\u0442 \u0430\u043d\u0433\u043b. <em>shard<\/em> \u2014 \u043e\u0441\u043a\u043e\u043b\u043e\u043a). \u041d\u0435 \u043f\u0443\u0442\u0430\u0439\u0442\u0435 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441 \u0440\u0435\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u0435\u0439, \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043d\u0435 \u0441\u043e\u0441\u0442\u0430\u0432\u043d\u044b\u043c\u0438 \u0447\u0430\u0441\u0442\u044f\u043c\u0438 \u043e\u0431\u0449\u0435\u0433\u043e \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430, \u0430 \u043a\u043e\u043f\u0438\u044f\u043c\u0438 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430.\u00a0<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0428\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u0430 \u0441\u0447\u0451\u0442 \u0438\u0445 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0435\u0436\u0434\u0443 \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u044f\u0446\u0438\u044f\u043c\u0438 \u0411\u0414 (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u0436\u0435\u043b\u0435\u0437\u043a\u0430\u0445), \u0447\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u043e\u0442\u0437\u044b\u0432\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u0441\u0435\u0440\u0432\u0438\u0441\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0430\u0437\u043c\u0435\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0446\u0435\u043b\u043e\u043c \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043c\u0435\u043d\u044c\u0448\u0435.\u00a0<\/p>\n<p>\u0428\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u044c \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f (\u043e\u0442 \u0430\u043d\u0433\u043b. <em>partition<\/em> \u2014 \u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0440\u0430\u0437\u0434\u0435\u043b). \u041e\u0442\u043b\u0438\u0447\u0438\u0435 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u0434\u0440\u0430\u0437\u0443\u043c\u0435\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043d\u0443\u0442\u0440\u0438 \u043e\u0434\u043d\u043e\u0439 \u0411\u0414, \u0430 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0438\u0445 \u043f\u043e \u0440\u0430\u0437\u043d\u044b\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c \u0411\u0414.\u00a0<\/p>\n<h4>\u0421\u043f\u043e\u0441\u043e\u0431\u044b \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h4>\n<p>\u041e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:<\/p>\n<ol>\n<li>\n<p><strong>\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438 \u0411\u0414<\/strong>. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0430\u0437\u044b \u2014 MongoDB, Elasticsearch, ClickHouse \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u2014 \u0443\u043c\u0435\u044e\u0442 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u0441\u0432\u043e\u0438\u043c\u0438 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438, \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e. \u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u044d\u0442\u043e \u043b\u0443\u0447\u0448\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0430\u0434\u0441\u0442\u0440\u043e\u0439\u043a\u0430\u043c\u0438 \u043a \u0411\u0414<\/strong>. \u0421\u0430\u043c\u044b\u0439 \u0441\u043f\u043e\u0440\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u043d\u0430\u0434\u0441\u0442\u0440\u043e\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0442 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 Vitess \u0438\u043b\u0438 Citus, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0435\u0441\u0442\u044c \u0440\u0438\u0441\u043a \u043f\u043e\u0442\u0435\u0440\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0438\u043c\u0438 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438<\/strong>. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0411\u0414 \u0434\u0430\u0436\u0435 \u043d\u0435 \u043f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u044e\u0442 \u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u0438\u0438 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430, \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u2014 \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0432\u044b\u0442\u0435\u043a\u0430\u044e\u0449\u0438\u043c\u0438 \u0440\u0438\u0441\u043a\u0430\u043c\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u0432 \u044d\u0442\u0438\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u0445 \u0441\u0445\u043e\u0436\u0438: \u043c\u044b \u0432\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043a\u043b\u044e\u0447 \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445 (\u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440, \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u043c\u0435\u0442\u043a\u0430 \u0438\u043b\u0438 \u0445\u0435\u0448 \u0437\u0430\u043f\u0438\u0441\u0438) \u0438 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043d\u0438\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u043d\u0443\u0436\u043d\u044b\u0439 \u0448\u0430\u0440\u0434. \u041a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u043a\u043b\u044e\u0447\u0438 \u0441\u0442\u0430\u0440\u0430\u044e\u0442\u0441\u044f \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u044b\u043b\u0438 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u043f\u043e \u0448\u0430\u0440\u0434\u0430\u043c. \u0421\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u043d\u0435 \u0441\u043b\u043e\u0436\u043d\u043e \u2014 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0411\u0414.\u00a0<\/p>\n<p>\u0412\u0430\u0436\u043d\u043e \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0432\u044b \u0434\u0435\u043b\u0430\u0435\u0442\u0435 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0435\u0441\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043b\u044e\u0447, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0430\u043c\u0438. \u041d\u0435\u043b\u044c\u0437\u044f \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u0438 \u043e \u00ab\u0433\u043e\u0440\u044f\u0447\u0438\u0445\u00bb \u0434\u0430\u043d\u043d\u044b\u0445, \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442 \u0447\u0430\u0449\u0435, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043d\u0430 \u0448\u0430\u0440\u0434\u044b \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0443, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0443\u044e, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437 \u0432 \u043a\u0430\u043a\u043e\u0439 \u0448\u0430\u0440\u0434 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443.\u00a0<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f<\/h4>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0435 \u0448\u0430\u0440\u0434\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0433\u043e\u0440\u044f\u0447\u043e \u043b\u044e\u0431\u0438\u043c\u043e\u0439 \u0432 Ozon PostgreSQL. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430 Go, \u0430 \u043c\u0438\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0443\u0434\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Goose. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0430\u043c\u0438 \u0448\u0430\u0440\u0434\u044b, \u0442\u043e \u0435\u0441\u0442\u044c \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u0443 \u0438\u043d\u0441\u0442\u0430\u043b\u043b\u044f\u0446\u0438\u044e \u0411\u0414. \u041e\u0442\u0432\u043b\u0435\u043a\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u0431\u043e\u0440 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u043a\u0430\u0442\u044b\u0432\u0430\u0442\u044c PostgreSQL, \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c.<\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0430\u0448 Storage \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u0448\u0430\u0440\u0434\u043e\u0432:\u00a0<\/p>\n<pre><code class=\"go\">\/\/ \u041e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0448\u0430\u0440\u0434\u043e\u0432. const bucketQuantity = 2  const (     Shard1 ShardNum = iota     Shard2 ) \/\/ \u0414\u043b\u044f \u043b\u0443\u0447\u0448\u0435\u0439 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0438. type ShardNum int type shardMap map[ShardNum]*sqlx.DB  type Storage struct {     shardMap shardMap } <\/code><\/pre>\n<p>\u041d\u0430\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u0434\u043b\u044f Storage \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u044c\u043c\u0451\u0442 \u043d\u0430 \u0441\u0435\u0431\u044f \u0432\u0441\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u043f\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0441 \u0411\u0414. <\/p>\n<pre><code class=\"go\">func initShardMap(ctx context.Context, dsns map[ShardNum]string) shardMap {     m := make(shardMap, len(dsns))     for sh, dsn := range dsns {     m[sh] = discoveryShard(ctx, dsn)     }      return m }  func discoveryShard(ctx context.Context, dsn string) *sqlx.DB {     db, err := sqlx.ConnectContext(ctx, \"postgres\", dsn)     if err != nil {     panic(err)     }      return db }  func NewStorage(ctx context.Context, dsns map[ShardNum]string) *Storage {     return &amp;Storage{     shardMap: initShardMap(ctx, dsns),     } } <\/code><\/pre>\n<p>\u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0420\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b \u0434\u043b\u044f \u0438\u0445 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0448\u0430\u0440\u0434\u044b \u0438 \u0447\u0442\u0435\u043d\u0438\u044f \u043e\u0442\u0442\u0443\u0434\u0430. \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0451 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u043e\u0433\u043e, \u0432 \u043a\u0430\u043a\u043e\u0439 \u0448\u0430\u0440\u0434 \u0438\u0434\u0442\u0438.\u00a0<\/p>\n<p>\u041f\u0440\u0438 \u0443\u0441\u043b\u043e\u0432\u0438\u0438 \u0440\u0430\u0432\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0438\u0445 ID (\u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u0430\u043a) \u043d\u0430\u043c \u0445\u0432\u0430\u0442\u0438\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0442\u0430\u0442\u043a\u0430 \u043e\u0442 \u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u0412\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<pre><code class=\"go\">func (s *Storage) shardByItemID(itemID int64) ShardNum {    return ShardNum(itemID % bucketQuantity) } <\/code><\/pre>\n<p>\u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u043e\u0442 \u0442\u0430\u043a\u043e\u0439 \u043d\u0435\u0437\u0430\u0443\u0440\u044f\u0434\u043d\u044b\u0439\u00a0 \u043c\u0435\u0442\u043e\u0434 \u0447\u0442\u0435\u043d\u0438\u044f \u0438\u0437 \u0411\u0414. \u0422\u0443\u0442 \u0441\u0442\u043e\u0438\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043d\u0430 \u0438\u043d\u0441\u0442\u0430\u043d\u0441\u0435 \u0411\u0414 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0430\u043f\u043f\u0438\u043d\u0433\u0430, \u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0438\u043d\u0441\u0442\u0430\u043d\u0441 (<em>*sqlx.DB<\/em>) \u043f\u043e \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u0448\u0430\u0440\u0434\u0430 \u0438\u0437 \u0441\u0438\u0433\u043d\u0430\u0442\u0443\u0440\u044b.<\/p>\n<pre><code class=\"go\">func (s *Storage) getItemsByID(ctx context.Context, shard *sqlx.DB, itemsIDs []int64) ([]models.Item, error) {    items := make([]models.Item, 0)      query, args, err := sq.        Select(itemsTableFields...).        From(itemsTable).        Where(sq.Eq{itemIDField: itemsIDs}).        PlaceholderFormat(sq.Dollar).        ToSql()    if err != nil {        err = errors.Wrap(err, \"[create query]\")        return items, err    }      err = shard.SelectContext(ctx, &amp;items, query, args...)    return items, err } <\/code><\/pre>\n<p>\u0421\u0430\u043c \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u0448\u0430\u0440\u0434\u0430 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0447\u0443\u0442\u044c \u0432\u044b\u0448\u0435, \u043a\u043e\u0433\u0434\u0430 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0448\u0438 <em>ItemIDs<\/em> \u043f\u043e \u043a\u0443\u0431\u044b\u0448\u043a\u0430\u043c. \u0421\u0430\u043c\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"go\">func (s *Storage) sortItemsIDsByShard(itemIDs ...int64) map[ShardNum][]int64 {    shardToItems := make(map[ShardNum][]int64)      for _, id := range itemIDs {        shardID := s.shardByItemID(id)        if _, ok := shardToItems[shardID]; !ok {            shardToItems[shardID] = make([]int64, 0)        }          shardToItems[shardID] = append(shardToItems[shardID], id)    }      return shardToItems } <\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043d\u0430\u044f \u043e\u0431\u0451\u0440\u0442\u043e\u0447\u043a\u0430 \u2014 \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u043b\u0438\u0441\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e. \u0412\u043e\u0442 \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f Item. \u041a\u0430\u0436\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043d \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u043e\u0439, \u043d\u043e \u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438\u00a0 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u0430 \u0441\u044a\u0435\u0434\u0430\u044e\u0442 \u0440\u0430\u0441\u043a\u0440\u0443\u0447\u0438\u0432\u0430\u043d\u0438\u044f \u043a\u0430\u043d\u0430\u043b\u043e\u0432.<\/p>\n<pre><code class=\"go\">func (s *Storage) GetItems(ctx context.Context, itemIDs ...int64) ([]models.Item, error) {    shardToItems := s.sortItemsIDsByShard(itemIDs...)      respChan := make(chan []models.Item, len(shardToItems))    errChan := make(chan error, len(shardToItems))    wg := &amp;sync.WaitGroup{}      for shardID, ids := range shardToItems {        wg.Add(1)        shard := s.shardMap[shardID]        go s.asyncGetItemsByID(ctx, shard, ids, wg, respChan, errChan)    }      wg.Wait()    close(respChan)    close(errChan)      result := make([]models.Item, 0)    for items := range respChan {        result = append(result, items...)    }      errs := make([]error, 0, len(errChan))    for e := range errChan {        errs = append(errs, e)    }    err := multierr.Combine(errs...)      return result, err } <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0442\u0435\u0440\u044f\u0442\u044c \u0441\u043c\u044b\u0441\u043b <em>getItemsByID<\/em> \u0437\u0430 \u043d\u0430\u0433\u0440\u043e\u043c\u043e\u0436\u0434\u0435\u043d\u0438\u0435\u043c \u043a\u0430\u043d\u0430\u043b\u043e\u0432 \u0438 Wait-\u0433\u0440\u0443\u043f\u043f, \u043c\u044b \u043f\u0440\u043e\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u043d\u0435\u043c \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 <em>asyncGetItemsByID<\/em>:<\/p>\n<pre><code class=\"go\">unc (s *Storage) asyncGetItemsByID(    ctx context.Context,    shard *sqlx.DB,    itemsIDs []int64,    wg *sync.WaitGroup,    resp chan&lt;- []models.Item,    errs chan&lt;- error, ) {    defer wg.Done()    items, err := s.getItemsByID(ctx, shard, itemsIDs)    if err != nil {        errs &lt;- errors.Wrapf(err, \"[getItemsByID] can't select from shard %d\", shard)    }      resp &lt;- items } <\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u0412\u0441\u0451 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043c\u044b \u043f\u0440\u043e\u0434\u0435\u043b\u044b\u0432\u0430\u0435\u043c \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0448\u0430\u0440\u0434\u044b:<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"go\">func (s *Storage) AddItems(ctx context.Context, items ...models.Item) error {    itemsByShardMap := s.itemsByShard(items...)    errChan := make(chan error, len(itemsByShardMap))    wg := &amp;sync.WaitGroup{}      for shardID, items := range itemsByShardMap {        wg.Add(1)        shard := s.shardMap[shardID]        go s.asyncAddItems(ctx, errChan, wg, shard, items...)    }      wg.Wait()    close(errChan)      errs := make([]error, 0, len(errChan))    for e := range errChan {        errs = append(errs, e)    }      return multierr.Combine(errs...) }   func (s *Storage) itemsByShard(items ...models.Item) map[ShardNum][]models.Item {    itemsByShard := make(map[ShardNum][]models.Item)      for _, item := range items {        shardID := s.shardByItemID(item.ID)        if _, ok := itemsByShard[shardID]; !ok {            itemsByShard[shardID] = make([]models.Item, 0)        }          itemsByShard[shardID] = append(itemsByShard[shardID], item)    }      return itemsByShard }   func (s *Storage) asyncAddItems(    ctx context.Context,    errChan chan&lt;- error, wg *sync.WaitGroup,    shard *sqlx.DB,    items ...models.Item) {    defer wg.Done()    err := s.addItems(ctx, shard, items...)    errChan &lt;- errors.Wrapf(err, \"[asyncAddItems] can't insert to shard\") }   func (s *Storage) addItems(ctx context.Context, shard *sqlx.DB, items ...models.Item) error {    q := sq.        Insert(itemsTable).        Columns(itemsTableFields...).        PlaceholderFormat(sq.Dollar)      for _, item := range items {        q = q.Values(item.ID, item.CreatedAt)    }      query, args, err := q.ToSql()    if err != nil {        return errors.Wrap(err, \"[create query]\")    }      _, err = shard.DB.ExecContext(ctx, query, args...)    return err } <\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041d\u0443 \u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0438\u043a \u0434\u043b\u044f \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043b\u0430:<\/p>\n<pre><code class=\"go\">#!\/usr\/bin\/env bash export MIGRATION_DIR=.\/migrations\/   if [ \"${STAGE}\" = \"production\" ]; then    if [ \"$1\" = \"--dryrun\" ]; then        goose -dir ${MIGRATION_DIR} postgres \"user=${USER1} password=${PASSWORD1} dbname=${DBNAME1} host=${HOST1} port=${PORT1} sslmode=disable\" status        goose -dir ${MIGRATION_DIR} postgres \"user=${USER2} password=${PASSWORD2} dbname=${DBNAME2} host=${HOST2} port=${PORT2} sslmode=disable\" status    else        goose -dir ${MIGRATION_DIR} postgres \"user=${USER1} password=${PASSWORD1} dbname=${DBNAME1} host=${HOST1} port=${PORT1} sslmode=disable\" up        goose -dir ${MIGRATION_DIR} postgres \"user=${USER2} password=${PASSWORD2} dbname=${DBNAME2} host=${HOST2} port=${PORT2} sslmode=disable\" up    fi   elif [ \"${STAGE}\" = \"staging\" ]; then    if [ \"$1\"<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-342851","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/342851","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=342851"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/342851\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=342851"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=342851"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=342851"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}