From c8852c521efc01fdecb9c50d1f06bddb0be120c4 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Fri, 21 Apr 2023 02:43:34 +1200 Subject: [PATCH] Update MarkedAsDeleted logging to included check for loadingStarted --- .../io/ebeaninternal/api/LoadBeanBuffer.java | 2 ++ .../io/ebeaninternal/api/LoadBeanRequest.java | 1 + .../server/loadcontext/DLoadBeanContext.java | 26 ++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/LoadBeanBuffer.java b/ebean-core/src/main/java/io/ebeaninternal/api/LoadBeanBuffer.java index 0c976f05e7..a04652cba5 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/LoadBeanBuffer.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/LoadBeanBuffer.java @@ -24,4 +24,6 @@ public interface LoadBeanBuffer { void configureQuery(SpiQuery query, String lazyLoadProperty); boolean isCache(); + + void loadingStarted(); } diff --git a/ebean-core/src/main/java/io/ebeaninternal/api/LoadBeanRequest.java b/ebean-core/src/main/java/io/ebeaninternal/api/LoadBeanRequest.java index 5f1c67465b..457350641d 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/api/LoadBeanRequest.java +++ b/ebean-core/src/main/java/io/ebeaninternal/api/LoadBeanRequest.java @@ -56,6 +56,7 @@ public String description() { * Return the batch of beans to actually load. */ public Set batch() { + loadBuffer.loadingStarted(); return batch; } diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java b/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java index 4544973503..dfc049010b 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/loadcontext/DLoadBeanContext.java @@ -5,10 +5,7 @@ import io.ebean.bean.BeanLoader; import io.ebean.bean.EntityBeanIntercept; import io.ebean.bean.PersistenceContext; -import io.ebeaninternal.api.LoadBeanBuffer; -import io.ebeaninternal.api.LoadBeanContext; -import io.ebeaninternal.api.LoadBeanRequest; -import io.ebeaninternal.api.SpiQuery; +import io.ebeaninternal.api.*; import io.ebeaninternal.server.core.OrmQueryRequest; import io.ebeaninternal.server.deploy.BeanDescriptor; import io.ebeaninternal.server.deploy.BeanPropertyAssocMany; @@ -18,9 +15,12 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import static java.lang.System.Logger.Level.DEBUG; + /** * ToOne bean load context. */ @@ -156,6 +156,11 @@ public void add(EntityBeanIntercept ebi) { // get persistenceContext from first loaded bean into the buffer persistenceContext = ebi.persistenceContext(); } + if (loadingStarted.get()) { + if (CoreLog.markedAsDeleted.isLoggable(DEBUG)) { + CoreLog.markedAsDeleted.log(DEBUG, "Adding to batch after loadingStarted(1)", new RuntimeException("Adding to batch after load(1")); + } + } batch.add(ebi); } @@ -194,6 +199,13 @@ public boolean isCache() { return context.cache; } + private final AtomicBoolean loadingStarted = new AtomicBoolean(); + + @Override + public void loadingStarted() { + loadingStarted.set(true); + } + @Override public void loadBean(EntityBeanIntercept ebi) { // A lock is effectively held by EntityBeanIntercept.loadBean() @@ -203,6 +215,11 @@ public void loadBean(EntityBeanIntercept ebi) { } if (!batch.contains(ebi)) { // re-add to the batch and lazy load from DB skipping l2 cache + if (loadingStarted.get()) { + if (CoreLog.markedAsDeleted.isLoggable(DEBUG)) { + CoreLog.markedAsDeleted.log(DEBUG, "Adding to batch after loadingStarted(2)", new RuntimeException("Adding to batch after load(2")); + } + } batch.add(ebi); } else if (context.hitCache) { Set hits = context.desc.cacheBeanLoadAll(batch, persistenceContext, ebi.lazyLoadPropertyIndex(), ebi.lazyLoadProperty()); @@ -216,6 +233,7 @@ public void loadBean(EntityBeanIntercept ebi) { LoadBeanRequest req = new LoadBeanRequest(this, ebi, context.hitCache); context.desc.ebeanServer().loadBean(req); batch.clear(); + loadingStarted.set(false); } }