From 88e6abe09d32dfa852a43493ac72a79501b7a76a Mon Sep 17 00:00:00 2001 From: Tglman Date: Tue, 5 Sep 2023 13:52:32 +0100 Subject: [PATCH] refactor: minor changes in ridbag thresholds initializations --- .../orient/core/db/record/ridbag/ORidBag.java | 42 +++++++++++++------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/com/orientechnologies/orient/core/db/record/ridbag/ORidBag.java b/core/src/main/java/com/orientechnologies/orient/core/db/record/ridbag/ORidBag.java index fb82df42a82..3563534bc28 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/db/record/ridbag/ORidBag.java +++ b/core/src/main/java/com/orientechnologies/orient/core/db/record/ridbag/ORidBag.java @@ -23,6 +23,7 @@ import com.orientechnologies.common.collection.OCollection; import com.orientechnologies.common.serialization.types.OByteSerializer; import com.orientechnologies.common.serialization.types.OUUIDSerializer; +import com.orientechnologies.orient.core.config.OContextConfiguration; import com.orientechnologies.orient.core.config.OGlobalConfiguration; import com.orientechnologies.orient.core.db.ODatabaseDocumentInternal; import com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal; @@ -98,14 +99,13 @@ public class ORidBag private ORecordId ownerRecord; private String fieldName; - private int topThreshold = - OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger(); - private int bottomThreshold = - OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.getValueAsInteger(); + private int topThreshold; + private int bottomThreshold; private UUID uuid; public ORidBag(final ORidBag ridBag) { + initThresholds(); init(); for (Iterator it = ridBag.rawIterator(); it.hasNext(); ) { add(it.next()); @@ -113,30 +113,29 @@ public ORidBag(final ORidBag ridBag) { } public ORidBag() { - init(); - } - - public ORidBag(final int iTopThreshold, final int iBottomThreshold) { - topThreshold = iTopThreshold; - bottomThreshold = iBottomThreshold; + initThresholds(); init(); } public ORidBag(UUID uuid) { + initThresholds(); init(); this.uuid = uuid; } public ORidBag(OBonsaiCollectionPointer pointer, Map changes, UUID uuid) { + initThresholds(); delegate = new OSBTreeRidBag(pointer, changes); this.uuid = uuid; } private ORidBag(final byte[] stream) { + initThresholds(); fromStream(stream); } public ORidBag(ORidBagDelegate delegate) { + initThresholds(); this.delegate = delegate; } @@ -245,8 +244,7 @@ public boolean isToSerializeEmbedded() { if (getOwner() instanceof ORecord && !((ORecord) getOwner()).getIdentity().isPersistent()) { return true; } - if (OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.getValueAsInteger() - >= size()) { + if (bottomThreshold >= size()) { return true; } return false; @@ -503,6 +501,26 @@ public boolean tryMerge(final ORidBag otherValue, boolean iMergeSingleItemsOfMul return false; } + protected void initThresholds() { + if (ODatabaseRecordThreadLocal.instance().isDefined() + && !ODatabaseRecordThreadLocal.instance().get().isClosed()) { + OContextConfiguration conf = ODatabaseRecordThreadLocal.instance().get().getConfiguration(); + topThreshold = + conf.getValueAsInteger(OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD); + + bottomThreshold = + conf.getValueAsInteger(OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD); + + } else { + + topThreshold = + OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger(); + + bottomThreshold = + OGlobalConfiguration.RID_BAG_SBTREEBONSAI_TO_EMBEDDED_THRESHOLD.getValueAsInteger(); + } + } + protected void init() { if (topThreshold < 0) { if (ODatabaseRecordThreadLocal.instance().isDefined()