Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api:support nested txn #265

Merged
merged 1 commit into from
Jan 18, 2018
Merged

api:support nested txn #265

merged 1 commit into from
Jan 18, 2018

Conversation

danielrohe
Copy link
Contributor

solves #143, how can it be tested locally with docker?

@lburgazzoli
Copy link
Collaborator

There is a failure on travis-ci, could you pease have a look ?

@fanminshi
Copy link
Member

it seems like tests failed.

testNestedTxn(com.coreos.jetcd.internal.impl.KVTest)  Time elapsed: 0.115 s  <<< FAILURE!
java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: etcdserver: key not found
	at com.coreos.jetcd.internal.impl.KVTest.testNestedTxn(KVTest.java:226)
Caused by: java.util.concurrent.ExecutionException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: etcdserver: key not found
Caused by: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: etcdserver: key not found

also the ci seems to be crazy i saw too many logs on downloading dependencies.

@fanminshi
Copy link
Member

you should run docker with https://github.com/coreos/jetcd/blob/master/etc/scripts/run_etcd_docker.sh then run you test against it.
take a look how other test does it.

@danielrohe
Copy link
Contributor Author

danielrohe commented Dec 18, 2017

Actually I already tried this locally and then looked at the referenced issue at etcd (etcd-io/etcd#7857) there the API is destined for version 3.3. The docker configuration in the script uses version 3.2.

Is there already a docker image of etcd with API version 3.3?

@fanminshi
Copy link
Member

@danielrohe i see what's going on. the nested txn is going to be in etcd 3.3 release. so we need to test the code again etcd 3.3. I believe there etcd v3.3.0 release candidate will be out this week. then you can test the code against rc.

@@ -15,7 +15,7 @@
# limitations under the License.
#

ETCD_VERSION="v3.2"
ETCD_VERSION="v3.3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, only v3.3.0-rc.0 is released https://github.com/coreos/etcd/releases/tag/v3.3.0-rc.0. does this script work locally?

Also i think the pr should be merged until the official v3.3.0 being released.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to know!

Copy link
Member

@fanminshi fanminshi Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielrohe have you taken a look on how nested txn is written in go client via this pr https://github.com/coreos/etcd/pull/8102/files?

I am currently reviewing this pr against that one. fyi.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looked at this PR to see how it was implemented in Go and then converted to Java. Tried to follow your conventions with static methods and builders. Converted also the test case from Go to Java to see whether it really works.

@fanminshi
Copy link
Member

please also modify TxnResponse.java to include the following:

  /**
   * @returns a list of TxnResponse; empty list if none.
   */
  public synchronized List<TxnResponse> getTxnResponses() {
    if (txnResponses == null) {
      txnResponses = getResponse().getResponsesList().stream()
          .filter((responseOp) -> responseOp.getResponseCase() == RESPONSE_TXN)
          .map(responseOp -> new TxnResponse(responseOp.getResponseTxn()))
          .collect(Collectors.toList());
    }

    return txnResponses;
  }

Also please add a test in TxnResponseTest to verify that getTxnResponses works properly.

@@ -194,4 +194,43 @@ public void testTxn() throws Exception {
test.assertEquals(getResp.getKvs().size(), 1);
test.assertEquals(getResp.getKvs().get(0).getValue().toStringUtf8(), putValue.toStringUtf8());
}

@Test
public void testNestedTxn() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's follow the format TestTxnNested from go client https://github.com/coreos/etcd/blob/master/clientv3/integration/txn_test.go#L193

@Test
  public void testNestedTxn() throws Exception {
    ByteSequence foo = ByteSequence.fromString("txn_foo");
    ByteSequence bar = ByteSequence.fromString("txn_bar");
    ByteSequence barz = ByteSequence.fromString("txn_barz");
    ByteSequence abc = ByteSequence.fromString("txn_abc");
    ByteSequence oneTwoThree = ByteSequence.fromString("txn_123");


    Txn txn = kvClient.txn();
    Cmp cmp = new Cmp(foo, Cmp.Op.EQUAL, CmpTarget.version(0));
    CompletableFuture<com.coreos.jetcd.kv.TxnResponse> txnResp = txn.If(cmp)
        .Then(Op.put(foo, bar, PutOption.DEFAULT),
            Op.txn(null,
                new Op[] {Op.put(abc, oneTwoThree, PutOption.DEFAULT)},
                null))
        .Else(Op.put(foo, barz, PutOption.DEFAULT)).commit();
    txnResp.get();

    GetResponse getResp = kvClient.get(foo).get();
    test.assertEquals(getResp.getKvs().size(), 1);
    test.assertEquals(getResp.getKvs().get(0).getValue().toStringUtf8(), bar.toStringUtf8());

    GetResponse getResp2 = kvClient.get(abc).get();
    test.assertEquals(getResp2.getKvs().size(), 1);
    test.assertEquals(getResp2.getKvs().get(0).getValue().toStringUtf8(), oneTwoThree.toStringUtf8());
  }

@fanminshi
Copy link
Member

@danielrohe sorry for the delay. I have reviewed the code and made some suggestions.
code looks good in general.

@danielrohe
Copy link
Contributor Author

Adjusted code based on your suggestions.

assertThat(txnResponse.getTxnResponses().size()).isEqualTo(1);
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line

@fanminshi
Copy link
Member

lgtm

@xiang90
Copy link
Contributor

xiang90 commented Jan 12, 2018

@danielrohe Please squash the commits into one, and fix the new line issue. We will get this merged once they are done.

@xiang90
Copy link
Contributor

xiang90 commented Jan 18, 2018

lgtm.

can you squash the commits into one? or we can use github feature to get this squashed.

@danielrohe
Copy link
Contributor Author

already squashed them

@xiang90 xiang90 merged commit 82edd9f into etcd-io:master Jan 18, 2018
@fanminshi fanminshi mentioned this pull request Feb 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants