jihoonson commented on a change in pull request #9441: Improve
OvershadowableManager performance
URL: https://github.com/apache/druid/pull/9441#discussion_r389987875
##########
File path:
core/src/main/java/org/apache/druid/timeline/partition/OvershadowableManager.java
##########
@@ -105,12 +105,46 @@
this.overshadowedGroups = new TreeMap<>();
}
- OvershadowableManager(OvershadowableManager<T> other)
+ public OvershadowableManager<T> copyVisible()
{
- this.knownPartitionChunks = new HashMap<>(other.knownPartitionChunks);
- this.standbyGroups = new TreeMap<>(other.standbyGroups);
- this.visibleGroupPerRange = new TreeMap<>(other.visibleGroupPerRange);
- this.overshadowedGroups = new TreeMap<>(other.overshadowedGroups);
+ final OvershadowableManager<T> copy = new OvershadowableManager<>();
+ visibleGroupPerRange.forEach((partitionRange, versionToGroups) -> {
+ // There should be only one group per partition range
+ final AtomicUpdateGroup<T> group =
versionToGroups.values().iterator().next();
+ group.getChunks().forEach(chunk ->
copy.knownPartitionChunks.put(chunk.getChunkNumber(), chunk));
+
+ copy.visibleGroupPerRange.put(
+ partitionRange,
+ new SingleEntryShort2ObjectSortedMap<>(group.getMinorVersion(),
AtomicUpdateGroup.copy(group))
+ );
+ });
+ return copy;
+ }
+
+ public OvershadowableManager<T> deepCopy()
Review comment:
From the Item 13 (Override clone judiciously) of the book "Effective Java",
> Is all this complexity really necessary? Rarely. If you extend a class
that already implements `Cloneable`, you have little choice but to implement a
well-behaved `clone` method. Otherwise, you are usually better off providing an
alternative means of object copying. **A better approach to object copying is
to provide a _copy constructor_ or _copy factory_**.
I changed this method to a static factory based on this.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]