[GitHub] [ignite] ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client transactions support

2019-08-15 Thread GitBox
ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client 
transactions support
URL: https://github.com/apache/ignite/pull/6734#discussion_r314224189
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientConnectionContext.java
 ##
 @@ -85,6 +99,15 @@
 /** Cursor counter. */
 private final AtomicLong curCnt = new AtomicLong();
 
+/** Tx id. */
+private final AtomicInteger txIdSeq = new AtomicInteger();
 
 Review comment:
   My bad, you are right.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client transactions support

2019-08-15 Thread GitBox
ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client 
transactions support
URL: https://github.com/apache/ignite/pull/6734#discussion_r314219383
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/tx/ClientTxContext.java
 ##
 @@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.platform.client.tx;
+
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import org.apache.ignite.IgniteCheckedException;
+import 
org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
+import org.apache.ignite.transactions.TransactionState;
+
+/**
+ * Client transaction context.
+ */
+public class ClientTxContext {
+/** Transaction id. */
+private final int txId;
+
+/** Transaction. */
+private final GridNearTxLocal tx;
+
+/** Lock. */
+private final Lock lock = new ReentrantLock();
+
+/**
+ * Constructor.
+ */
+public ClientTxContext(int txId, GridNearTxLocal tx) {
+this.txId = txId;
+this.tx = tx;
 
 Review comment:
   arg checks?


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client transactions support

2019-08-15 Thread GitBox
ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client 
transactions support
URL: https://github.com/apache/ignite/pull/6734#discussion_r314215035
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java
 ##
 @@ -1199,6 +1199,9 @@
  */
 public static final String IGNITE_TX_OWNER_DUMP_REQUESTS_ALLOWED = 
"IGNITE_TX_OWNER_DUMP_REQUESTS_ALLOWED";
 
+/** Maximum count of active transactions per connection for thin clients. 
*/
+public static final String IGNITE_THIN_MAX_ACTIVE_TX_PER_CONNECTION = 
"IGNITE_THIN_MAX_ACTIVE_TX_PER_CONNECTION";
 
 Review comment:
   I think this should go to `ClientConnectorConfiguration` instead where we 
already have things like `maxOpenCursorsPerConn`.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client transactions support

2019-08-15 Thread GitBox
ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client 
transactions support
URL: https://github.com/apache/ignite/pull/6734#discussion_r314215128
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientConnectionContext.java
 ##
 @@ -216,4 +241,61 @@ public ClientAffinityTopologyVersion 
checkAffinityTopologyVersion() {
 return new ClientAffinityTopologyVersion(newVer, changed);
 }
 }
+
+/**
+ * Next transaction id for this connection.
+ */
+public int nextTxId() {
+int txId = txIdSeq.incrementAndGet();
+
+return txId == 0 ? txIdSeq.incrementAndGet() : txId;
+}
+
+/**
+ * Transaction context by transaction id.
+ *
+ * @param txId Tx ID.
+ */
+public ClientTxContext txContext(int txId) {
+return txs.get(txId);
+}
+
+/**
+ * Add new transaction context to connection.
+ *
+ * @param txCtx Tx context.
+ */
+public void addTxContext(ClientTxContext txCtx) {
+if (txsCnt.incrementAndGet() > ACTIVE_TX_LIMIT) {
+txsCnt.decrementAndGet();
+
+throw new IgniteClientException(ClientStatus.TX_LIMIT_EXCEEDED, 
"Active transactions per connection limit " +
+"(" + ACTIVE_TX_LIMIT + ") exceeded. To start a new 
transaction you need to wait for some of currently " +
+"active transactions complete. To change the limit set up " + 
IGNITE_THIN_MAX_ACTIVE_TX_PER_CONNECTION +
 
 Review comment:
   See above, let's not use system properties for this.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client transactions support

2019-08-15 Thread GitBox
ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client 
transactions support
URL: https://github.com/apache/ignite/pull/6734#discussion_r314216029
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientRequestHandler.java
 ##
 @@ -53,11 +60,40 @@
 this.ctx = ctx;
 this.authCtx = authCtx;
 this.ver = ver;
+log = ctx.kernalContext().log(getClass());
 }
 
 /** {@inheritDoc} */
 @Override public ClientListenerResponse handle(ClientListenerRequest req) {
 try {
+if (req instanceof ClientTxAwareRequest) {
+if (((ClientTxAwareRequest)req).isTransactional()) {
 
 Review comment:
   Please introduce a variable to reduce casts.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client transactions support

2019-08-15 Thread GitBox
ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client 
transactions support
URL: https://github.com/apache/ignite/pull/6734#discussion_r314219584
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/tx/ClientTxContext.java
 ##
 @@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.platform.client.tx;
+
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import org.apache.ignite.IgniteCheckedException;
+import 
org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
+import org.apache.ignite.transactions.TransactionState;
+
+/**
+ * Client transaction context.
+ */
+public class ClientTxContext {
+/** Transaction id. */
+private final int txId;
+
+/** Transaction. */
+private final GridNearTxLocal tx;
+
+/** Lock. */
+private final Lock lock = new ReentrantLock();
+
+/**
+ * Constructor.
+ */
+public ClientTxContext(int txId, GridNearTxLocal tx) {
+this.txId = txId;
+this.tx = tx;
+}
+
+/**
+ * Aquire context to work with transaction in the current thread.
+ */
+@SuppressWarnings("LockAcquiredButNotSafelyReleased")
+public void aquire() throws IgniteCheckedException {
 
 Review comment:
   `aquire` -> `acquire`


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client transactions support

2019-08-15 Thread GitBox
ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client 
transactions support
URL: https://github.com/apache/ignite/pull/6734#discussion_r314220898
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/tx/ClientTxEndRequest.java
 ##
 @@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.platform.client.tx;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryRawReader;
+import 
org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
+import 
org.apache.ignite.internal.processors.platform.client.ClientConnectionContext;
+import org.apache.ignite.internal.processors.platform.client.ClientRequest;
+import org.apache.ignite.internal.processors.platform.client.ClientResponse;
+import org.apache.ignite.internal.processors.platform.client.ClientStatus;
+import 
org.apache.ignite.internal.processors.platform.client.IgniteClientException;
+
+/**
+ * End the transaction request.
+ */
+public class ClientTxEndRequest extends ClientRequest implements 
ClientTxAwareRequest {
+/** Transaction id. */
+private final int txId;
+
+/** Transaction committed. */
+private final boolean committed;
+
+/**
+ * Constructor.
+ *
+ * @param reader Reader.
+ */
+public ClientTxEndRequest(BinaryRawReader reader) {
+super(reader);
+
+txId = reader.readInt();
+committed = reader.readBoolean();
+}
+
+/** {@inheritDoc} */
+@Override public ClientResponse process(ClientConnectionContext ctx) {
+ClientTxContext txCtx = ctx.txContext(txId);
+
+if (txCtx == null && !committed)
+return super.process(ctx);
+
+if (txCtx == null)
+throw new IgniteClientException(ClientStatus.TX_NOT_FOUND, 
"Transaction with id " + txId + " not found.");
+
+try (GridNearTxLocal tx = txCtx.tx()) {
+if (committed)
+tx.commit();
+else
+tx.rollback();
+}
+catch (IgniteCheckedException e) {
+throw new IgniteClientException(ClientStatus.FAILED, 
e.getMessage(), e);
 
 Review comment:
   Do we need this catch block at all? I think exceptions are handled up the 
stack anyway.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client transactions support

2019-08-15 Thread GitBox
ptupitsyn commented on a change in pull request #6734: IGNITE-9410 Thin client 
transactions support
URL: https://github.com/apache/ignite/pull/6734#discussion_r314213823
 
 

 ##
 File path: 
modules/core/src/main/java/org/apache/ignite/internal/processors/platform/client/ClientConnectionContext.java
 ##
 @@ -85,6 +99,15 @@
 /** Cursor counter. */
 private final AtomicLong curCnt = new AtomicLong();
 
+/** Tx id. */
+private final AtomicInteger txIdSeq = new AtomicInteger();
 
 Review comment:
   Let's make it `AtomicLong` as above


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services