| 595 | |
| 596 | |
| 597 | Result<Group::Membership> GroupProcess::doJoin( |
| 598 | const string& data, |
| 599 | const Option<string>& label) |
| 600 | { |
| 601 | CHECK_EQ(state, READY); |
| 602 | |
| 603 | const string path = znode + "/" + (label.isSome() ? (label.get() + "_") : ""); |
| 604 | |
| 605 | // Create a new ephemeral node to represent a new member and use the |
| 606 | // the specified data as its contents. |
| 607 | string result; |
| 608 | |
| 609 | const int code = zk->create( |
| 610 | path, |
| 611 | data, |
| 612 | acl, |
| 613 | ZOO_SEQUENCE | ZOO_EPHEMERAL, |
| 614 | &result); |
| 615 | |
| 616 | if (code == ZINVALIDSTATE || (code != ZOK && zk->retryable(code))) { |
| 617 | CHECK_NE(zk->getState(), ZOO_AUTH_FAILED_STATE); |
| 618 | return None(); |
| 619 | } else if (code != ZOK) { |
| 620 | return Error( |
| 621 | "Failed to create ephemeral node at '" + path + |
| 622 | "' in ZooKeeper: " + zk->message(code)); |
| 623 | } |
| 624 | |
| 625 | // Invalidate the cache (it will/should get immediately populated |
| 626 | // via the 'updated' callback of our ZooKeeper watcher). |
| 627 | memberships = None(); |
| 628 | |
| 629 | // Save the sequence number but only grab the basename. Example: |
| 630 | // "/path/to/znode/label_0000000131" => "0000000131". |
| 631 | const string basename = strings::tokenize(result, "/").back(); |
| 632 | |
| 633 | // Strip the label before grabbing the sequence number. |
| 634 | const string node = label.isSome() |
| 635 | ? strings::remove(basename, label.get() + "_") |
| 636 | : basename; |
| 637 | |
| 638 | Try<int32_t> sequence = numify<int32_t>(node); |
| 639 | CHECK_SOME(sequence); |
| 640 | |
| 641 | Promise<bool>* cancelled = new Promise<bool>(); |
| 642 | owned[sequence.get()] = cancelled; |
| 643 | |
| 644 | return Group::Membership(sequence.get(), label, cancelled->future()); |
| 645 | } |
| 646 | |
| 647 | |
| 648 | Result<bool> GroupProcess::doCancel(const Group::Membership& membership) |
nothing calls this directly
no test coverage detected