| 1 | 9 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | package Net::Etcd::KV::Txn; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 9 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 9 | ▶ | use Types::Standard qw(InstanceOf Str Int Bool HashRef ArrayRef); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 9 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 9 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 9 | with 'Net::Etcd::Role::Actions'; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =head1 NAME | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | Net::Etcd::KV::Txn | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 9 | our $VERSION = '0.021'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Txn processes multiple requests in a single transaction. A txn request increments | ||||||||||||||||||||||||||||
| 28 | the revision of the key-value store and generates events with the same revision for | ||||||||||||||||||||||||||||
| 29 | every completed request. It is not allowed to modify the same key several times | ||||||||||||||||||||||||||||
| 30 | within one txn. | ||||||||||||||||||||||||||||
| 31 | From google paxosdb paper: Our implementation hinges around a powerful primitive which | ||||||||||||||||||||||||||||
| 32 | we call MultiOp. All other database operations except for iteration are implemented as | ||||||||||||||||||||||||||||
| 33 | a single call to MultiOp. A MultiOp is applied atomically and consists of three components: | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1. A list of tests called guard. Each test in guard checks a single entry in the database. | ||||||||||||||||||||||||||||
| 36 | It may check for the absence or presence of a value, or compare with a given value. Two | ||||||||||||||||||||||||||||
| 37 | different tests in the guard may apply to the same or different entries in the database. | ||||||||||||||||||||||||||||
| 38 | All tests in the guard are applied and MultiOp returns the results. If all tests are true, | ||||||||||||||||||||||||||||
| 39 | MultiOp executes t op (see item 2 below), otherwise it executes f op (see item 3 below). | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 2. A list of database operations called t op. Each operation in the list is either an insert, | ||||||||||||||||||||||||||||
| 42 | delete, or lookup operation, and applies to a single database entry. Two different operations | ||||||||||||||||||||||||||||
| 43 | in the list may apply to the same or different entries in the database. These operations are | ||||||||||||||||||||||||||||
| 44 | executed if guard evaluates to true. | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3. A list of database operations called f op. Like t op, but executed if guard evaluates to false. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head1 ACCESSORS | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head2 endpoint | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | /v3alpha/kv/txn | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 9 | has endpoint => ( | |||||||||||||||||||||||||||
| 57 | is => 'ro', | ||||||||||||||||||||||||||||
| 58 | isa => Str, | ||||||||||||||||||||||||||||
| 59 | default => '/kv/txn' | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head2 compare | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | compare is a list of predicates representing a conjunction of terms. If the comparisons | ||||||||||||||||||||||||||||
| 65 | succeed, then the success requests will be processed in order, and the response will | ||||||||||||||||||||||||||||
| 66 | contain their respective responses in order. If the comparisons fail, then the failure | ||||||||||||||||||||||||||||
| 67 | requests will be processed in order, and the response will contain their respective | ||||||||||||||||||||||||||||
| 68 | responses in order. | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | =cut | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 9 | has compare => ( | |||||||||||||||||||||||||||
| 73 | is => 'ro', | ||||||||||||||||||||||||||||
| 74 | isa => ArrayRef, | ||||||||||||||||||||||||||||
| 75 | required => 1, | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | =head2 success | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | success is a list of requests which will be applied when compare evaluates to true. | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =cut | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 9 | has success => ( | |||||||||||||||||||||||||||
| 85 | is => 'ro', | ||||||||||||||||||||||||||||
| 86 | isa => ArrayRef, | ||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =head2 failure | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | failure is a list of requests which will be applied when compare evaluates to false. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 9 | has failure => ( | |||||||||||||||||||||||||||
| 96 | is => 'ro', | ||||||||||||||||||||||||||||
| 97 | isa => ArrayRef, | ||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 PUBLIC METHODS | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =head2 create | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | create txn | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =cut | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | #TODO hack alert | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | sub create { | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 0 | my $compare = $self->compare; | |||||||||||||||||||||||||||
| 113 | 0 | my $success = $self->success; | |||||||||||||||||||||||||||
| 114 | 0 | my $failure = $self->failure; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | my $txn ='"compare":[' . join(',',@$compare) . '],'; | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | $txn .= '"success":[' . join(',', @$success) . ']' if defined $success; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | $txn .= ',' if defined $success and defined $failure; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $success and defined $failure
MC/DC0%0/2
defined $success and defined $failure
defined $success
defined $failure
Truth table0%0/3
A and B
A= defined $successB= defined $failure
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | $txn .= '"failure":[ ' . join(',', @$failure) . ']' if defined $failure; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | $self->{json_args} = '{' . $txn . '}'; | |||||||||||||||||||||||||||
| 121 | # print STDERR Dumper($self); | ||||||||||||||||||||||||||||
| 122 | 0 | $self->request; | |||||||||||||||||||||||||||
| 123 | 0 | return $self; | |||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 9 | 1; | |||||||||||||||||||||||||||