{"id":459,"date":"2019-10-09T19:32:03","date_gmt":"2019-10-09T11:32:03","guid":{"rendered":"https:\/\/www.myway5.com\/?p=459"},"modified":"2023-07-05T21:40:05","modified_gmt":"2023-07-05T13:40:05","slug":"etcd-distribute-lock","status":"publish","type":"post","link":"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/","title":{"rendered":"etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f"},"content":{"rendered":"<h2>\u4e00\u3001\u6982\u8ff0<\/h2>\n<p>\u5728etcd\u7684clientv3\u5305\u4e2d\uff0c\u5b9e\u73b0\u4e86\u5206\u5e03\u5f0f\u9501\u3002\u4f7f\u7528\u8d77\u6765\u548c<code>mutex<\/code>\u662f\u7c7b\u4f3c\u7684\uff0c\u4e3a\u4e86\u4e86\u89e3\u5176\u4e2d\u7684\u5de5\u4f5c\u673a\u5236\uff0c\u8fd9\u91cc\u7b80\u8981\u7684\u505a\u4e00\u4e0b\u603b\u7ed3\u3002<\/p>\n<h2>\u4e8c\u3001\u4f7f\u7528\u65b9\u5f0f<\/h2>\n<p>etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u5728<code>go.etcd.io\/etcd\/clientv3\/concurrency<\/code>\u5305\u4e2d\uff0c\u4e3b\u8981\u63d0\u4f9b\u4e86\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li>func NewMutex(s *Session, pfx string) *Mutex\uff0c \u7528\u6765\u65b0\u5efa\u4e00\u4e2amutex<\/li>\n<li>func (m *Mutex) Lock(ctx context.Context) error\uff0c\u5b83\u4f1a\u963b\u585e\u76f4\u5230\u62ff\u5230\u4e86\u9501\uff0c\u5e76\u4e14\u652f\u6301\u901a\u8fc7context\u6765\u53d6\u6d88\u83b7\u53d6\u9501\u3002<\/li>\n<li>func (m *Mutex) Unlock(ctx context.Context) error\uff0c\u89e3\u9501<\/li>\n<\/ul>\n<p>\u56e0\u6b64\u5728\u4f7f\u7528etcd\u63d0\u4f9b\u7684\u5206\u5e03\u5f0f\u9501\u5f0f\u975e\u5e38\u7b80\u5355\uff0c\u901a\u5e38\u5c31\u662f\u5b9e\u4f8b\u5316\u4e00\u4e2amutex\uff0c\u7136\u540e\u5c1d\u8bd5\u62a2\u5360\u9501\uff0c\u4e4b\u540e\u8fdb\u884c\u4e1a\u52a1\u5904\u7406\uff0c\u6700\u540e\u89e3\u9501\u5373\u53ef\u3002<\/p>\n<p>\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-go line-numbers\">package main\n\nimport (\n    \"context\"\n    \"github.com\/coreos\/etcd\/clientv3\"\n    \"github.com\/coreos\/etcd\/clientv3\/concurrency\"\n    \"log\"\n    \"sync\"\n    \"time\"\n)\n\nvar n = 0\n\n\/\/ \u4f7f\u7528worker\u6a21\u62df\u9501\u7684\u62a2\u5360\nfunc worker(key string) error {\n    endpoints := []string{\"127.0.0.1:2379\"}\n\n    cfg := clientv3.Config{\n        Endpoints:            endpoints,\n        DialTimeout:          3 * time.Second,\n    }\n\n    cli, err := clientv3.New(cfg)\n    if err != nil {\n        log.Println(\"new cli error:\", err)\n        return err\n    }\n\n    sess, err := concurrency.NewSession(cli)\n    if err != nil {\n        return err\n    }\n\n    m := concurrency.NewMutex(sess, \"\/\"+key)\n\n    err = m.Lock(context.TODO())\n    if err != nil {\n        log.Println(\"lock error:\", err)\n        return err\n    }\n\n    defer func() {\n        err = m.Unlock(context.TODO())\n        if err != nil {\n            log.Println(\"unlock error:\", err)\n        }\n    }()\n\n    log.Println(\"get lock: \", n)\n    n++\n    time.Sleep(time.Second) \/\/ \u6a21\u62df\u6267\u884c\u4ee3\u7801\n\n\n    return nil\n}\n\nfunc main() {\n    var wg sync.WaitGroup\n    wg.Add(3)\n    go func() {\n        defer wg.Done()\n        err := worker(\"lockname\")\n        if err != nil {\n            log.Println(err)\n        }\n    }()\n\n\n    go func() {\n        defer wg.Done()\n        err := worker(\"lockname\")\n        if err != nil {\n            log.Println(err)\n        }\n    }()\n\n    go func() {\n        defer wg.Done()\n        err := worker(\"lockname\")\n        if err != nil {\n            log.Println(err)\n        }\n    }()\n\n    wg.Wait()\n}\n<\/code><\/pre>\n<h2>\u4e09\u3001\u5b9e\u73b0\u673a\u5236<\/h2>\n<p><code>Lock()<\/code>\u51fd\u6570\u7684\u5b9e\u73b0\u5f88\u7b80\u5355\u3002\u8fd9\u91cc\u53ef\u4ee5\u8d34\u51fa\u6765\u770b\u4e00\u4e0b\uff1a<\/p>\n<pre><code class=\"language-go line-numbers\">\/\/ Lock locks the mutex with a cancelable context. If the context is canceled\n\/\/ while trying to acquire the lock, the mutex tries to clean its stale lock entry.\nfunc (m *Mutex) Lock(ctx context.Context) error {\n    s := m.s\n    client := m.s.Client()\n\n    m.myKey = fmt.Sprintf(\"%s%x\", m.pfx, s.Lease())\n    cmp := v3.Compare(v3.CreateRevision(m.myKey), \"=\", 0)\n    \/\/ put self in lock waiters via myKey; oldest waiter holds lock\n    put := v3.OpPut(m.myKey, \"\", v3.WithLease(s.Lease()))\n    \/\/ reuse key in case this session already holds the lock\n    get := v3.OpGet(m.myKey)\n    \/\/ fetch current holder to complete uncontended path with only one RPC\n    getOwner := v3.OpGet(m.pfx, v3.WithFirstCreate()...)\n    resp, err := client.Txn(ctx).If(cmp).Then(put, getOwner).Else(get, getOwner).Commit()\n    if err != nil {\n        return err\n    }\n    m.myRev = resp.Header.Revision\n    if !resp.Succeeded {\n        m.myRev = resp.Responses[0].GetResponseRange().Kvs[0].CreateRevision\n    }\n    \/\/ if no key on prefix \/ the minimum rev is key, already hold the lock\n    ownerKey := resp.Responses[1].GetResponseRange().Kvs\n    if len(ownerKey) == 0 || ownerKey[0].CreateRevision == m.myRev {\n        m.hdr = resp.Header\n        return nil\n    }\n\n    \/\/ wait for deletion revisions prior to myKey\n    hdr, werr := waitDeletes(ctx, client, m.pfx, m.myRev-1)\n    \/\/ release lock key if wait failed\n    if werr != nil {\n        m.Unlock(client.Ctx())\n    } else {\n        m.hdr = hdr\n    }\n    return werr\n}\n<\/code><\/pre>\n<p>\u9996\u5148\u901a\u8fc7\u4e00\u4e2a\u4e8b\u52a1\u6765\u5c1d\u8bd5\u52a0\u9501\uff0c\u8fd9\u4e2a\u4e8b\u52a1\u4e3b\u8981\u5305\u542b\u4e864\u4e2a\u64cd\u4f5c: <code>cmp<\/code>\u3001<code>put<\/code>\u3001<code>get<\/code>\u3001<code>getOwner<\/code>\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0ckey\u662f\u7531<code>pfx<\/code>\u548c<code>Lease()<\/code>\u7ec4\u6210\u7684\u3002<\/p>\n<ul>\n<li>cmp: \u6bd4\u8f83\u52a0\u9501\u7684key\u7684\u4fee\u8ba2\u7248\u672c\u662f\u5426\u662f0\u3002\u5982\u679c\u662f0\u5c31\u4ee3\u8868\u8fd9\u4e2a\u9501\u4e0d\u5b58\u5728\u3002<\/li>\n<li>put: \u5411\u52a0\u9501\u7684key\u4e2d\u5b58\u50a8\u4e00\u4e2a\u7a7a\u503c\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u5c31\u662f\u4e00\u4e2a\u52a0\u9501\u7684\u64cd\u4f5c\uff0c\u4f46\u662f\u8fd9\u628a\u9501\u662f\u6709\u8d85\u65f6\u65f6\u95f4\u7684\uff0c\u8d85\u65f6\u7684\u65f6\u95f4\u662fsession\u7684\u9ed8\u8ba4\u65f6\u957f\u3002\u8d85\u65f6\u662f\u4e3a\u4e86\u9632\u6b62\u9501\u6ca1\u6709\u88ab\u6b63\u5e38\u91ca\u653e\u5bfc\u81f4\u6b7b\u9501\u3002<\/li>\n<li>get: get\u5c31\u662f\u901a\u8fc7key\u6765\u67e5\u8be2<\/li>\n<li>getOwner: \u6ce8\u610f\u8fd9\u91cc\u662f\u7528<code>m.pfx<\/code>\u6765\u67e5\u8be2\u7684\uff0c\u5e76\u4e14\u5e26\u4e86\u67e5\u8be2\u53c2\u6570<code>WithFirstCreate()<\/code>\u3002\u4f7f\u7528<code>pfx<\/code>\u6765\u67e5\u8be2\u662f\u56e0\u4e3a\u5176\u4ed6\u7684session\u4e5f\u4f1a\u7528\u540c\u6837\u7684<code>pfx<\/code>\u6765\u5c1d\u8bd5\u52a0\u9501\uff0c\u5e76\u4e14\u56e0\u4e3a\u6bcf\u4e2aLeaseID\u90fd\u4e0d\u540c\uff0c\u6240\u4ee5\u7b2c\u4e00\u6b21\u80af\u5b9a\u4f1a<code>put<\/code>\u6210\u529f\u3002\u4f46\u662f\u53ea\u6709\u6700\u65e9\u4f7f\u7528\u8fd9\u4e2a<code>pfx<\/code>\u7684<code>session<\/code>\u624d\u662f\u6301\u6709\u9501\u7684\uff0c\u6240\u4ee5\u8fd9\u4e2agetOwner\u7684\u542b\u4e49\u5c31\u662f\u8fd9\u6837\u7684\u3002<\/li>\n<\/ul>\n<p>\u63a5\u4e0b\u6765\u624d\u662f\u901a\u8fc7\u5224\u65ad\u6765\u68c0\u67e5\u662f\u5426\u6301\u6709\u9501<\/p>\n<pre><code class=\"language-go line-numbers\">m.myRev = resp.Header.Revision\nif !resp.Succeeded {\n    m.myRev = resp.Responses[0].GetResponseRange().Kvs[0].CreateRevision\n}\n\/\/ if no key on prefix \/ the minimum rev is key, already hold the lock\nownerKey := resp.Responses[1].GetResponseRange().Kvs\nif len(ownerKey) == 0 || ownerKey[0].CreateRevision == m.myRev {\n    m.hdr = resp.Header\n    return nil\n}\n<\/code><\/pre>\n<p><code>m.myRev<\/code>\u662f\u5f53\u524d\u7684\u7248\u672c\u53f7\uff0c<code>resp.Succeeded<\/code>\u662f<code>cmp<\/code>\u4e3atrue\u65f6\u503c\u4e3atrue\uff0c\u5426\u5219\u662ffalse\u3002\u8fd9\u91cc\u7684\u5224\u65ad\u8868\u660e\u5f53\u540c\u4e00\u4e2asession\u975e\u7b2c\u4e00\u6b21\u5c1d\u8bd5\u52a0\u9501\uff0c\u5f53\u524d\u7684\u7248\u672c\u53f7\u5e94\u8be5\u53d6\u8fd9\u4e2akey\u7684\u6700\u65b0\u7684\u7248\u672c\u53f7\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u53d6\u5f97\u9501\u7684\u6301\u6709\u8005\u7684key\u3002\u5982\u679c\u5f53\u524d\u6ca1\u6709\u4eba\u6301\u6709\u8fd9\u628a\u9501\uff0c\u90a3\u4e48\u9ed8\u8ba4\u5f53\u524d\u4f1a\u8bdd\u83b7\u5f97\u4e86\u9501\u3002\u6216\u8005\u9501\u6301\u6709\u8005\u7684\u7248\u672c\u53f7\u548c\u5f53\u524d\u7684\u7248\u672c\u53f7\u4e00\u81f4\uff0c \u90a3\u4e48\u5f53\u524d\u7684\u4f1a\u8bdd\u5c31\u662f\u9501\u7684\u6301\u6709\u8005\u3002<\/p>\n<pre><code class=\"language-go line-numbers\">\/\/ wait for deletion revisions prior to myKey\nhdr, werr := waitDeletes(ctx, client, m.pfx, m.myRev-1)\n\/\/ release lock key if wait failed\nif werr != nil {\n    m.Unlock(client.Ctx())\n} else {\n    m.hdr = hdr\n}\n<\/code><\/pre>\n<p>\u4e0a\u9762\u8fd9\u6bb5\u4ee3\u7801\u5c31\u5f88\u597d\u7406\u89e3\u4e86\uff0c\u56e0\u4e3a\u8d70\u5230\u8fd9\u91cc\u8bf4\u660e\u6ca1\u6709\u83b7\u53d6\u5230\u9501\uff0c\u90a3\u4e48\u8fd9\u91cc\u7b49\u5f85\u9501\u7684\u5220\u9664\u3002<\/p>\n<pre><code class=\"line-numbers\">\/\/ waitDeletes efficiently waits until all keys matching the prefix and no greater\n\/\/ than the create revision.\nfunc waitDeletes(ctx context.Context, client *v3.Client, pfx string, maxCreateRev int64) (*pb.ResponseHeader, error) {\n    getOpts := append(v3.WithLastCreate(), v3.WithMaxCreateRev(maxCreateRev))\n    for {\n        resp, err := client.Get(ctx, pfx, getOpts...)\n        if err != nil {\n            return nil, err\n        }\n        if len(resp.Kvs) == 0 {\n            return resp.Header, nil\n        }\n        lastKey := string(resp.Kvs[0].Key)\n        if err = waitDelete(ctx, client, lastKey, resp.Header.Revision); err != nil {\n            return nil, err\n        }\n    }\n}\n<\/code><\/pre>\n<p><code>waitDeletes<\/code>\u65b9\u6cd5\u7684\u5b9e\u73b0\u4e5f\u5f88\u7b80\u5355\uff0c\u4f46\u662f\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u91cc\u7684<code>getOpts<\/code>\u53ea\u4f1a\u83b7\u53d6\u6bd4\u5f53\u524d\u4f1a\u8bdd\u7248\u672c\u53f7\u66f4\u4f4e\u7684key\uff0c\u7136\u540e\u53bb\u76d1\u63a7\u6700\u65b0\u7684key\u7684\u5220\u9664\u3002\u7b49\u8fd9\u4e2akey\u5220\u9664\u4e86\uff0c\u81ea\u5df1\u4e5f\u5c31\u62ff\u5230\u9501\u4e86\u3002<\/p>\n<p>\u8fd9\u79cd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u548c\u6211\u4e00\u5f00\u59cb\u7684\u9884\u60f3\u662f\u4e0d\u540c\u7684\u3002\u5b83\u4e0d\u5b58\u5728\u9501\u7684\u7ade\u4e89\uff0c\u4e0d\u5b58\u5728\u91cd\u590d\u7684\u5c1d\u8bd5\u52a0\u9501\u7684\u64cd\u4f5c\u3002\u800c\u662f\u901a\u8fc7\u4f7f\u7528\u7edf\u4e00\u7684\u524d\u7f00<code>pfx<\/code>\u6765put\uff0c\u7136\u540e\u6839\u636e\u5404\u81ea\u7684\u7248\u672c\u53f7\u6765\u6392\u961f\u83b7\u53d6\u9501\u3002\u6548\u7387\u975e\u5e38\u7684\u9ad8\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.myway5.com\/wp-content\/uploads\/2019\/10\/etcd\u5206\u5e03\u5f0f\u9501.png\" alt=\"etcd \u5206\u5e03\u5f0f\u9501\" \/><\/p>\n<p>\u5982\u56fe\u6240\u793a\uff0c\u5171\u67094\u4e2asession\u6765\u52a0\u9501\uff0c\u90a3\u4e48\u6839\u636erevision\u6765\u6392\u961f\uff0c\u83b7\u53d6\u9501\u7684\u987a\u5e8f\u4e3asession2 -> session3 -> session1 -> session4\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u8fd9\u91cc\u4e3a\u4ec0\u4e48\u53ef\u4ee5\u901a\u8fc7revision\u6765\u5224\u5b9a\u83b7\u53d6\u9501\u7684\u987a\u5e8f\uff0c\u5c31\u9700\u8981\u66f4\u6df1\u5165\u7684\u4e86\u89e3etcd\u7684\u5185\u90e8\u673a\u5236\u4ee5\u53caraft\u534f\u8bae\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6982\u8ff0 \u5728etcd\u7684clientv3\u5305\u4e2d\uff0c\u5b9e\u73b0\u4e86\u5206\u5e03\u5f0f\u9501\u3002\u4f7f\u7528\u8d77\u6765\u548cmutex\u662f\u7c7b\u4f3c\u7684\uff0c\u4e3a\u4e86\u4e86\u89e3\u5176\u4e2d\u7684\u5de5\u4f5c\u673a &hellip; <a href=\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[94,93],"tags":[95],"class_list":["post-459","post","type-post","status-publish","format-standard","hentry","category-etcd","category-distributed-system","tag-etcd"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f - \u4e00\u53ea\u5b89\u9759\u7684\u732b<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f - \u4e00\u53ea\u5b89\u9759\u7684\u732b\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u3001\u6982\u8ff0 \u5728etcd\u7684clientv3\u5305\u4e2d\uff0c\u5b9e\u73b0\u4e86\u5206\u5e03\u5f0f\u9501\u3002\u4f7f\u7528\u8d77\u6765\u548cmutex\u662f\u7c7b\u4f3c\u7684\uff0c\u4e3a\u4e86\u4e86\u89e3\u5176\u4e2d\u7684\u5de5\u4f5c\u673a &hellip; \u7ee7\u7eed\u9605\u8bfbetcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/\" \/>\n<meta property=\"og:site_name\" content=\"\u4e00\u53ea\u5b89\u9759\u7684\u732b\" \/>\n<meta property=\"article:published_time\" content=\"2019-10-09T11:32:03+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-07-05T13:40:05+00:00\" \/>\n<meta name=\"author\" content=\"jiangpengfei\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"jiangpengfei\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/\"},\"author\":{\"name\":\"jiangpengfei\",\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"headline\":\"etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f\",\"datePublished\":\"2019-10-09T11:32:03+00:00\",\"dateModified\":\"2023-07-05T13:40:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/\"},\"wordCount\":66,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"keywords\":[\"etcd \u5206\u5e03\u5f0f\u9501\"],\"articleSection\":[\"etcd\",\"\u5206\u5e03\u5f0f\u7cfb\u7edf\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/\",\"url\":\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/\",\"name\":\"etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f - \u4e00\u53ea\u5b89\u9759\u7684\u732b\",\"isPartOf\":{\"@id\":\"https:\/\/www.myway5.com\/#website\"},\"datePublished\":\"2019-10-09T11:32:03+00:00\",\"dateModified\":\"2023-07-05T13:40:05+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.myway5.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.myway5.com\/#website\",\"url\":\"https:\/\/www.myway5.com\/\",\"name\":\"\u4e00\u53ea\u5b89\u9759\u7684\u732b\",\"description\":\"\u60f3\u5565\u5462\",\"publisher\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.myway5.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685\",\"name\":\"jiangpengfei\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g\",\"caption\":\"jiangpengfei\"},\"logo\":{\"@id\":\"https:\/\/www.myway5.com\/#\/schema\/person\/image\/\"},\"url\":\"https:\/\/www.myway5.com\/index.php\/author\/joyme\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f - \u4e00\u53ea\u5b89\u9759\u7684\u732b","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/","og_locale":"zh_CN","og_type":"article","og_title":"etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f - \u4e00\u53ea\u5b89\u9759\u7684\u732b","og_description":"\u4e00\u3001\u6982\u8ff0 \u5728etcd\u7684clientv3\u5305\u4e2d\uff0c\u5b9e\u73b0\u4e86\u5206\u5e03\u5f0f\u9501\u3002\u4f7f\u7528\u8d77\u6765\u548cmutex\u662f\u7c7b\u4f3c\u7684\uff0c\u4e3a\u4e86\u4e86\u89e3\u5176\u4e2d\u7684\u5de5\u4f5c\u673a &hellip; \u7ee7\u7eed\u9605\u8bfbetcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f","og_url":"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/","og_site_name":"\u4e00\u53ea\u5b89\u9759\u7684\u732b","article_published_time":"2019-10-09T11:32:03+00:00","article_modified_time":"2023-07-05T13:40:05+00:00","author":"jiangpengfei","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"jiangpengfei","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/#article","isPartOf":{"@id":"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/"},"author":{"name":"jiangpengfei","@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"headline":"etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f","datePublished":"2019-10-09T11:32:03+00:00","dateModified":"2023-07-05T13:40:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/"},"wordCount":66,"commentCount":1,"publisher":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"keywords":["etcd \u5206\u5e03\u5f0f\u9501"],"articleSection":["etcd","\u5206\u5e03\u5f0f\u7cfb\u7edf"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/","url":"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/","name":"etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f - \u4e00\u53ea\u5b89\u9759\u7684\u732b","isPartOf":{"@id":"https:\/\/www.myway5.com\/#website"},"datePublished":"2019-10-09T11:32:03+00:00","dateModified":"2023-07-05T13:40:05+00:00","breadcrumb":{"@id":"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.myway5.com\/index.php\/2019\/10\/09\/etcd-distribute-lock\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.myway5.com\/"},{"@type":"ListItem","position":2,"name":"etcd\u5206\u5e03\u5f0f\u9501\u7684\u5b9e\u73b0\u65b9\u5f0f"}]},{"@type":"WebSite","@id":"https:\/\/www.myway5.com\/#website","url":"https:\/\/www.myway5.com\/","name":"\u4e00\u53ea\u5b89\u9759\u7684\u732b","description":"\u60f3\u5565\u5462","publisher":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.myway5.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/b19267e8b106343431e163ec96950685","name":"jiangpengfei","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.myway5.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f8c7de757f6e0247412bcfd31b7c2271?s=96&d=monsterid&r=g","caption":"jiangpengfei"},"logo":{"@id":"https:\/\/www.myway5.com\/#\/schema\/person\/image\/"},"url":"https:\/\/www.myway5.com\/index.php\/author\/joyme\/"}]}},"views":8594,"_links":{"self":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/459","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/comments?post=459"}],"version-history":[{"count":3,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/459\/revisions"}],"predecessor-version":[{"id":1573,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/posts\/459\/revisions\/1573"}],"wp:attachment":[{"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/media?parent=459"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/categories?post=459"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.myway5.com\/index.php\/wp-json\/wp\/v2\/tags?post=459"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}