vldpyatkov commented on code in PR #13889: URL: https://github.com/apache/ignite/pull/13889#discussion_r4740758287
########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxEntryProcessorChain.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.cache.transactions; + +import javax.cache.processor.EntryProcessor; +import org.apache.ignite.internal.managers.deployment.GridDeploymentManager; +import org.apache.ignite.internal.processors.cache.CacheInvokeEntry; +import org.apache.ignite.internal.processors.cache.CacheObject; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.util.typedef.T2; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.jetbrains.annotations.Nullable; + +/** Executes a chain of entry processors for one transaction entry. */ +public class TxEntryProcessorChain { + /** + * Runs the processors in order, keeping the state from the last successful processor if one fails. + * + * @param txEntry Transaction entry containing the processors. + * @param cacheVal Initial value of the entry. + * @param ver Version of the entry before the processors are applied. + * @return Final entry state and result or error of the last executed processor. + */ + public static Result execute( + IgniteTxEntry txEntry, + @Nullable CacheObject cacheVal, + @Nullable GridCacheVersion ver + ) { + GridCacheContext<?, ?> ctx = txEntry.context(); + KeyCacheObject key = txEntry.key(); + + Object keyVal = null; + Object res = null; + boolean modified = false; + + for (T2<EntryProcessor<Object, Object, Object>, Object[]> t : txEntry.entryProcessors()) { + EntryProcessor<Object, Object, Object> proc = t.get1(); + + try { + restoreDeploymentContext(ctx, proc); + + var invokeEntry = new CacheInvokeEntry<>(key, keyVal, cacheVal, null, ver, txEntry.keepBinary(), txEntry.cached()); Review Comment: I noted that the fourth parameter is always null. It likely means that you will deserialize the value in each entry processor. ########## modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheTxInvokeTest.java: ########## @@ -17,17 +17,48 @@ package org.apache.ignite.internal.processors.cache; +import javax.cache.processor.EntryProcessorException; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.binary.BinaryObject; import org.apache.ignite.cache.CacheAtomicityMode; +import org.apache.ignite.cache.CacheEntryProcessor; import org.apache.ignite.cache.CacheMode; import org.apache.ignite.configuration.NearCacheConfiguration; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.transactions.Transaction; +import org.apache.ignite.transactions.TransactionConcurrency; +import org.junit.Test; import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL; import static org.apache.ignite.cache.CacheMode.PARTITIONED; +import static org.apache.ignite.cache.CachePeekMode.BACKUP; +import static org.apache.ignite.cache.CachePeekMode.PRIMARY; +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; /** * */ public class IgniteCacheTxInvokeTest extends IgniteCacheInvokeAbstractTest { Review Comment: These tests do not well fit the new ones. This class inherits the supper class and changes only properties but does not add a new test scenario. Mya be we can find a better place for these new tests? ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java: ########## @@ -2038,4 +2000,20 @@ private class PrepareTimeoutObject extends GridTimeoutObjectAdapter { return S.toString(PrepareTimeoutObject.class, this); } } + + /** */ + private static TxEntryProcessorChain.Result applyEntryProcessors( + IgniteTxEntry txEntry, @Nullable + CacheObject val, + @Nullable GridCacheVersion ver + ) { + IgniteThread.onEntryProcessorEntered(false); Review Comment: I do not have an idea right now what it is for, but it is used in all four cases. Why don't you extract it in the common method? ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/tx/SqlTransactionsDmlTest.java: ########## @@ -0,0 +1,71 @@ +/* + * 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.tx; + +import java.util.List; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.query.calcite.GridCommonAbstractWrapperTest; +import org.apache.ignite.transactions.Transaction; +import org.junit.jupiter.api.Test; + +import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC; +import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED; + +/** */ +public class SqlTransactionsDmlTest extends GridCommonAbstractWrapperTest { Review Comment: I do not think we really need SQL tests here, because our change is enclosed in the core. ########## modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/TxEntryProcessorChain.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.cache.transactions; + +import javax.cache.processor.EntryProcessor; +import org.apache.ignite.internal.managers.deployment.GridDeploymentManager; +import org.apache.ignite.internal.processors.cache.CacheInvokeEntry; +import org.apache.ignite.internal.processors.cache.CacheObject; +import org.apache.ignite.internal.processors.cache.GridCacheContext; +import org.apache.ignite.internal.processors.cache.KeyCacheObject; +import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.util.typedef.T2; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.jetbrains.annotations.Nullable; + +/** Executes a chain of entry processors for one transaction entry. */ +public class TxEntryProcessorChain { + /** + * Runs the processors in order, keeping the state from the last successful processor if one fails. + * + * @param txEntry Transaction entry containing the processors. + * @param cacheVal Initial value of the entry. + * @param ver Version of the entry before the processors are applied. + * @return Final entry state and result or error of the last executed processor. + */ + public static Result execute( + IgniteTxEntry txEntry, + @Nullable CacheObject cacheVal, + @Nullable GridCacheVersion ver + ) { + GridCacheContext<?, ?> ctx = txEntry.context(); + KeyCacheObject key = txEntry.key(); + + Object keyVal = null; + Object res = null; + boolean modified = false; + + for (T2<EntryProcessor<Object, Object, Object>, Object[]> t : txEntry.entryProcessors()) { + EntryProcessor<Object, Object, Object> proc = t.get1(); + + try { + restoreDeploymentContext(ctx, proc); + + var invokeEntry = new CacheInvokeEntry<>(key, keyVal, cacheVal, null, ver, txEntry.keepBinary(), txEntry.cached()); + + res = proc.process(invokeEntry, t.get2()); + + if (invokeEntry.modified()) { + CacheObject updatedVal = ctx.toCacheObject(ctx.unwrapTemporary(invokeEntry.getValue(true))); Review Comment: I think we can avoid a serialization in one chain process. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
