5858import org .apache .ignite .thread .IgniteThread ;
5959import org .jetbrains .annotations .Nullable ;
6060
61+ import static org .apache .ignite .internal .processors .cache .GridCacheOperation .CREATE ;
62+ import static org .apache .ignite .internal .processors .cache .GridCacheOperation .DELETE ;
6163import static org .apache .ignite .internal .processors .cache .GridCacheOperation .READ ;
6264import static org .apache .ignite .internal .processors .cache .GridCacheOperation .TRANSFORM ;
65+ import static org .apache .ignite .internal .processors .cache .GridCacheOperation .UPDATE ;
6366
6467/**
6568 * Transaction entry. Note that it is essential that this class does not override
@@ -237,7 +240,7 @@ public IgniteTxEntry() {
237240 * @param ctx Cache registry.
238241 * @param tx Owning transaction.
239242 * @param op Operation.
240- * @param val Value.
243+ * @param cacheVal Value.
241244 * @param ttl Time to live.
242245 * @param conflictExpireTime DR expire time.
243246 * @param entry Cache entry.
@@ -247,7 +250,7 @@ public IgniteTxEntry() {
247250 public IgniteTxEntry (GridCacheContext <?, ?> ctx ,
248251 IgniteInternalTx tx ,
249252 GridCacheOperation op ,
250- CacheObject val ,
253+ CacheObject cacheVal ,
251254 long ttl ,
252255 long conflictExpireTime ,
253256 GridCacheEntryEx entry ,
@@ -262,7 +265,9 @@ public IgniteTxEntry(GridCacheContext<?, ?> ctx,
262265
263266 this .ctx = ctx ;
264267 this .tx = tx ;
265- this .val .value (op , val , false , false );
268+
269+ updateValue (op , cacheVal , false , false );
270+
266271 this .entry = entry ;
267272 this .ttl = ttl ;
268273 this .conflictExpireTime = conflictExpireTime ;
@@ -282,7 +287,7 @@ public IgniteTxEntry(GridCacheContext<?, ?> ctx,
282287 * @param ctx Cache registry.
283288 * @param tx Owning transaction.
284289 * @param op Operation.
285- * @param val Value.
290+ * @param cacheVal Value.
286291 * @param entryProcessor Entry processor.
287292 * @param invokeArgs Optional arguments for EntryProcessor.
288293 * @param ttl Time to live.
@@ -295,7 +300,7 @@ public IgniteTxEntry(GridCacheContext<?, ?> ctx,
295300 public IgniteTxEntry (GridCacheContext <?, ?> ctx ,
296301 IgniteInternalTx tx ,
297302 GridCacheOperation op ,
298- CacheObject val ,
303+ CacheObject cacheVal ,
299304 EntryProcessor <Object , Object , Object > entryProcessor ,
300305 Object [] invokeArgs ,
301306 long ttl ,
@@ -313,7 +318,9 @@ public IgniteTxEntry(GridCacheContext<?, ?> ctx,
313318
314319 this .ctx = ctx ;
315320 this .tx = tx ;
316- this .val .value (op , val , false , false );
321+
322+ updateValue (op , cacheVal , false , false );
323+
317324 this .entry = entry ;
318325 this .ttl = ttl ;
319326 this .filters = filters ;
@@ -373,7 +380,9 @@ public IgniteTxEntry cleanCopy(GridCacheContext<?, ?> ctx) {
373380 cp .val = new TxEntryValueHolder ();
374381
375382 cp .filters = filters ;
376- cp .val .value (val .op (), val .value (), val .hasWriteValue (), val .hasReadValue ());
383+
384+ cp .updateValue (val .op (), val .value (), val .hasWriteValue (), val .hasReadValue ());
385+
377386 cp .entryProcessorsCol = entryProcessorsCol ;
378387 cp .ttl = ttl ;
379388 cp .conflictExpireTime = conflictExpireTime ;
@@ -466,7 +475,7 @@ void setAndMarkValid(GridCacheOperation op, CacheObject val) {
466475 * @param hasWriteVal Has write value flag.
467476 */
468477 void setAndMarkValid (GridCacheOperation op , CacheObject val , boolean hasWriteVal , boolean hasReadVal ) {
469- this . val . value (op , val , hasWriteVal , hasReadVal );
478+ updateValue (op , val , hasWriteVal , hasReadVal );
470479
471480 markValid ();
472481 }
@@ -476,7 +485,7 @@ void setAndMarkValid(GridCacheOperation op, CacheObject val, boolean hasWriteVal
476485 * to further peek operations.
477486 */
478487 public void markValid () {
479- prevVal . value ( val .op (), val .value (), val .hasWriteValue (), val .hasReadValue ());
488+ updateValue ( prevVal , val .op (), val .value (), val .hasWriteValue (), val .hasReadValue ());
480489 }
481490
482491 /**
@@ -640,13 +649,13 @@ public void cached(GridCacheEntryEx entry) {
640649 }
641650
642651 /**
643- * @param oldVal Old value.
652+ * @param oldCacheVal Old value.
644653 */
645- public void oldValue (CacheObject oldVal ) {
646- if (this . oldVal == null )
647- this . oldVal = new TxEntryValueHolder ();
654+ public void oldValue (CacheObject oldCacheVal ) {
655+ if (oldVal == null )
656+ oldVal = new TxEntryValueHolder ();
648657
649- this . oldVal . value ( op (), oldVal , true , true );
658+ updateValue ( oldVal , op (), oldCacheVal , true , true );
650659 }
651660
652661 /**
@@ -698,6 +707,34 @@ public boolean hasPreviousValue() {
698707 return prevVal .op ();
699708 }
700709
710+ /**
711+ * @param op Cache operation.
712+ * @param cacheVal Cache value.
713+ * @param hasWriteVal Write value presence flag.
714+ * @param hasReadVal Read value presence flag.
715+ */
716+ public void updateValue (GridCacheOperation op , CacheObject cacheVal , boolean hasWriteVal , boolean hasReadVal ) {
717+ updateValue (val , op , cacheVal , hasWriteVal , hasReadVal );
718+ }
719+
720+ /**
721+ * @param hld Tx entry value holder.
722+ * @param op Cache operation.
723+ * @param cacheVal Cache value.
724+ * @param hasWriteVal Write value presence flag.
725+ * @param hasReadVal Read value presence flag.
726+ */
727+ public void updateValue (TxEntryValueHolder hld , GridCacheOperation op , CacheObject cacheVal , boolean hasWriteVal , boolean hasReadVal ) {
728+ if (hasReadVal && hld .hasWriteValue ())
729+ return ;
730+
731+ hld .op (op );
732+ hld .value (cacheVal );
733+
734+ hld .hasWriteValue (hasWriteVal || op == CREATE || op == UPDATE || op == DELETE );
735+ hld .hasReadValue (hasReadVal || op == READ );
736+ }
737+
701738 /**
702739 * @return Time to live.
703740 */
@@ -727,21 +764,21 @@ public void conflictExpireTime(long conflictExpireTime) {
727764 }
728765
729766 /**
730- * @param val Entry value.
767+ * @param cacheVal Entry value.
731768 * @param writeVal Write value flag.
732769 * @param readVal Read value flag.
733770 */
734- public void value (@ Nullable CacheObject val , boolean writeVal , boolean readVal ) {
735- this . val . value ( this . val .op (), val , writeVal , readVal );
771+ public void value (@ Nullable CacheObject cacheVal , boolean writeVal , boolean readVal ) {
772+ updateValue ( val .op (), cacheVal , writeVal , readVal );
736773 }
737774
738775 /**
739776 * Sets read value if this tx entry does not have write value yet.
740777 *
741- * @param val Read value to set.
778+ * @param cacheVal Read value to set.
742779 */
743- public void readValue (@ Nullable CacheObject val ) {
744- this . val . value ( this . val .op (), val , false , true );
780+ public void readValue (@ Nullable CacheObject cacheVal ) {
781+ updateValue ( val .op (), cacheVal , false , true );
745782 }
746783
747784 /**
0 commit comments