-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Don't update segment metadata if archive doesn't move anything #3476
Conversation
I totally didn't mean to push this to a druid-io branch, sorry about that. |
Odd failure:
|
https://travis-ci.org/druid-io/druid/jobs/161663853 different failure |
failed again https://travis-ci.org/druid-io/druid/jobs/161700091 |
* | ||
* @throws SegmentLoadingException on error | ||
*/ | ||
DataSegment archive(DataSegment segment) throws SegmentLoadingException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe annotate with @javax.annotation.Nullable
? This will make IDE to warn you about using the object, returned from this method, without null check.
* | ||
* @throws SegmentLoadingException on error | ||
*/ | ||
DataSegment restore(DataSegment segment) throws SegmentLoadingException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe annotate with @javax.annotation.Nullable
?
|
||
// Move segments | ||
for (DataSegment segment : unusedSegments) { | ||
List<DataSegment> restoredSegments = Lists.newLinkedList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think LinkedList
is pointless here. It's not a performance-critical place; but there should always be a reason to use LinkedList
rather than default ArrayList
. When reader sees LinkedList
, he spends mental cycles trying to understand, why it is used here. It's confusing when there is no apparent reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, I don't remember why that was here.
final DataSegment restored = toolbox.getDataSegmentArchiver().restore(segment); | ||
if (restored == null) { | ||
log.info("Segment [%s] did not move, not updating metadata", segment); | ||
} else { | ||
restoredSegments.add(toolbox.getDataSegmentArchiver().restore(segment)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe should use the restored
variable here rather than computing toolbox.getDataSegmentArchiver().restore(segment)
again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we should, fixing
// Move segments | ||
for (DataSegment segment : unusedSegments) { | ||
final DataSegment restored = toolbox.getDataSegmentArchiver().restore(segment); | ||
if (restored == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with ArchiveTask
, maybe restored != null
branch should go first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
@@ -22,18 +22,17 @@ | |||
import com.fasterxml.jackson.annotation.JsonProperty; | |||
import com.google.common.collect.ImmutableSet; | |||
import com.google.common.collect.Iterables; | |||
import com.google.common.collect.Lists; | |||
|
|||
import com.metamx.common.ISE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use new package, since java-util has moved?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
👍 after Travis |
👍 |
* @throws SegmentLoadingException on error | ||
*/ | ||
@Nullable | ||
DataSegment archive(DataSegment segment) throws SegmentLoadingException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of returning null, perhaps a nicer API would be to return an equivalent object. Then callers don't need to deal with potentially null returns. If a caller wants to know if anything was actually done, they could check retVal.equals(segment)
rather than retVal != null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's pretty challenging since loadSpec
is just a Map<String, Object>
which may have whatever junk in it. I opted for this way of doing it so that the implementation can make the determination on if the segment was moved or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, I forgot DataSegment identity is based around the segment identifier. OK then in that case what I said is nonsense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Fixes #3475
Expands the behavior of the archiver to handle when things don't actually move. In such a scenario metadata segment update actions are not attempted.
If an Archiver implementation does not honor the new interface contract, then the prior behavior is still preserved.