Skip to content

Commit

Permalink
refactor: minor changes in ridbag thresholds initializations
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Sep 5, 2023
1 parent 9f3c948 commit 88e6abe
Showing 1 changed file with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -98,45 +99,43 @@ 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<OIdentifiable> it = ridBag.rawIterator(); it.hasNext(); ) {
add(it.next());
}
}

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<OIdentifiable, Change> 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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 88e6abe

Please sign in to comment.