tkalkirill commented on code in PR #13889: URL: https://github.com/apache/ignite/pull/13889#discussion_r4768098858
########## 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: We discussed it in person and decided to keep the current solution. ########## 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: We discussed it in person and decided to keep the current solution. -- 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]
