Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MarkedAsDeleted logging to included check for loadingStarted #3035

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public interface LoadBeanBuffer {
void configureQuery(SpiQuery<?> query, String lazyLoadProperty);

boolean isCache();

void loadingStarted();
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public String description() {
* Return the batch of beans to actually load.
*/
public Set<EntityBeanIntercept> batch() {
loadBuffer.loadingStarted();
return batch;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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()
Expand All @@ -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<EntityBeanIntercept> hits = context.desc.cacheBeanLoadAll(batch, persistenceContext, ebi.lazyLoadPropertyIndex(), ebi.lazyLoadProperty());
Expand All @@ -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);
}
}

Expand Down