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

fix: Xplan validation erroneously throws warning on missing objects #1218

Merged
merged 1 commit into from
Jul 11, 2024
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 @@ -27,7 +27,6 @@
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -136,7 +135,7 @@ public InstanceCollection next() {
List<InstanceReference> instances = getNextAtomicPart();
biggestAtom = Math.max(biggestAtom, instances.size());

if (part.size() + instances.size() > maxObjects) {
if (part.size() > 0 && part.size() + instances.size() > maxObjects) {
// add to part candidates for later use
nextCandidates.add(instances);
if (!verticesLeft()) {
Expand Down Expand Up @@ -199,7 +198,14 @@ public InstanceCollection next() {
*/
private List<InstanceReference> getNextAtomicPart() {
// select an arbitrary vertex
Vertex vtx = graph.someVertex();
Vertex vtx = null;

if (handleFirst != null) {
vtx = graph.getVertex(handleFirst);
}
if (vtx == null) {
vtx = graph.someVertex();
}
if (vtx != null) {
// get all vertices associated with that vertex
final Set<Vertex> visited = new LinkedHashSet<>();
Expand Down Expand Up @@ -236,22 +242,20 @@ public Boolean compute(LoopBundle<Vertex> loop) {
result.add(ref);
}
else {
Iterable<Vertex> referers = associated.getVertices(Direction.IN);
Set<String> ids = new HashSet<>();
if (referers != null) {
for (Vertex referer : referers) {
Object ident = referer.getId();
if (ident != null) {
ids.add(ident.toString());
}
for (Vertex referer : associated.getVertices(Direction.IN)) {
Object ident = referer.getId();
if (ident != null) {
ids.add(ident.toString());
}
}

if (ids.isEmpty()) {
log.warn("Encountered referenced object w/o associated instance: "
+ associated.getId());
}
else {
String enumIds = ids.stream().collect(Collectors.joining(", "));
String enumIds = String.join(", ", ids);
log.warn("Encountered referenced object w/o associated instance: "
+ associated.getId() + " - referenced from " + enumIds);
}
Expand Down Expand Up @@ -294,23 +298,37 @@ public void remove() {

private boolean partitioned = false;

private final T handleFirst;

/**
* Create a new reference graph from the given instance collection.
*
* @param inspector the instance inspector to use
* @param instances the
* @param handleFirst the ID of the first instance to handle, optional and
* can be null
*/
public ReferenceGraph(IdentityReferenceInspector<T> inspector, InstanceCollection instances) {
public ReferenceGraph(IdentityReferenceInspector<T> inspector, InstanceCollection instances,
T handleFirst) {
this.graph = new CustomTinkerGraph();
this.inspector = inspector;
this.originalCollection = instances;
this.handleFirst = handleFirst;

populate(instances);

// identified vertices no longer needed after populate
identifiedVertices.clear();
}

/**
* @param inspector the instance inspector to use
* @param instances the
*/
public ReferenceGraph(IdentityReferenceInspector<T> inspector, InstanceCollection instances) {
this(inspector, instances, null);
}

/**
* Populate the graph with the instances from the given collection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void partitionByPlan(ProgressIndicator progress, IOReporter reporter)
for (String planId : planIdToInstancesMapping.keySet()) {
MultiInstanceCollection mic = new MultiInstanceCollection(
Arrays.asList(planIdToInstancesMapping.get(planId), nonPlanInstances));
ReferenceGraph<String> rg = new ReferenceGraph<String>(new XMLInspector(), mic);
ReferenceGraph<String> rg = new ReferenceGraph<String>(new XMLInspector(), mic, planId);

Iterator<InstanceCollection> p = rg.partition(1, reporter);
while (p.hasNext()) {
Expand Down
Loading