-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Don't update segment metadata if archive doesn't move anything #3476
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
Changes from all commits
62d918d
3ba410f
5e52f1f
1858bbf
e54c0ac
452f732
5a9001f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,31 @@ | |
|
|
||
| import io.druid.timeline.DataSegment; | ||
|
|
||
| import javax.annotation.Nullable; | ||
|
|
||
| public interface DataSegmentArchiver | ||
| { | ||
| public DataSegment archive(DataSegment segment) throws SegmentLoadingException; | ||
| public DataSegment restore(DataSegment segment) throws SegmentLoadingException; | ||
| /** | ||
| * Perform an archive task on the segment and return the resulting segment or null if there was no action needed. | ||
| * | ||
| * @param segment The source segment | ||
| * | ||
| * @return The segment after archiving or `null` if there was no archiving performed. | ||
| * | ||
| * @throws SegmentLoadingException on error | ||
| */ | ||
| @Nullable | ||
| DataSegment archive(DataSegment segment) throws SegmentLoadingException; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's pretty challenging since
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| /** | ||
| * Perform the restore from an archived segment and return the resulting segment or null if there was no action | ||
| * | ||
| * @param segment The source (archived) segment | ||
| * | ||
| * @return The segment after it has been unarchived | ||
| * | ||
| * @throws SegmentLoadingException on error | ||
| */ | ||
| @Nullable | ||
| DataSegment restore(DataSegment segment) throws SegmentLoadingException; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe annotate with |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package io.druid.storage.s3; | ||
|
|
||
| import com.fasterxml.jackson.databind.BeanProperty; | ||
| import com.fasterxml.jackson.databind.DeserializationContext; | ||
| import com.fasterxml.jackson.databind.InjectableValues; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.module.SimpleModule; | ||
| import com.google.common.collect.ImmutableList; | ||
| import com.google.common.collect.ImmutableMap; | ||
| import io.druid.jackson.DefaultObjectMapper; | ||
| import io.druid.segment.loading.SegmentLoadingException; | ||
| import io.druid.timeline.DataSegment; | ||
| import org.easymock.EasyMock; | ||
| import org.jets3t.service.impl.rest.httpclient.RestS3Service; | ||
| import org.joda.time.Interval; | ||
| import org.junit.Assert; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class S3DataSegmentArchiverTest | ||
| { | ||
| private static final ObjectMapper MAPPER = new DefaultObjectMapper() | ||
| .setInjectableValues(new InjectableValues() | ||
| { | ||
| @Override | ||
| public Object findInjectableValue( | ||
| Object valueId, DeserializationContext ctxt, BeanProperty forProperty, Object beanInstance | ||
| ) | ||
| { | ||
| return PULLER; | ||
| } | ||
| }).registerModule(new SimpleModule("s3-archive-test-module").registerSubtypes(S3LoadSpec.class)); | ||
| private static final S3DataSegmentArchiverConfig ARCHIVER_CONFIG = new S3DataSegmentArchiverConfig() | ||
| { | ||
| @Override | ||
| public String getArchiveBucket() | ||
| { | ||
| return "archive_bucket"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getArchiveBaseKey() | ||
| { | ||
| return "archive_base_key"; | ||
| } | ||
| }; | ||
| private static final S3DataSegmentPusherConfig PUSHER_CONFIG = new S3DataSegmentPusherConfig(); | ||
| private static final RestS3Service S3_SERVICE = EasyMock.createStrictMock(RestS3Service.class); | ||
| private static final S3DataSegmentPuller PULLER = new S3DataSegmentPuller(S3_SERVICE); | ||
| private static final DataSegment SOURCE_SEGMENT = DataSegment | ||
| .builder() | ||
| .binaryVersion(1) | ||
| .dataSource("dataSource") | ||
| .dimensions(ImmutableList.<String>of()) | ||
| .interval(Interval.parse("2015/2016")) | ||
| .version("version") | ||
| .loadSpec(ImmutableMap.<String, Object>of( | ||
| "type", | ||
| S3StorageDruidModule.SCHEME, | ||
| S3DataSegmentPuller.BUCKET, | ||
| "source_bucket", | ||
| S3DataSegmentPuller.KEY, | ||
| "source_key" | ||
| )) | ||
| .build(); | ||
|
|
||
| @BeforeClass | ||
| public static void setUpStatic() | ||
| { | ||
| PUSHER_CONFIG.setBaseKey("push_base"); | ||
| PUSHER_CONFIG.setBucket("push_bucket"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSimpleArchive() throws Exception | ||
| { | ||
| final DataSegment archivedSegment = SOURCE_SEGMENT | ||
| .withLoadSpec(ImmutableMap.<String, Object>of( | ||
| "type", | ||
| S3StorageDruidModule.SCHEME, | ||
| S3DataSegmentPuller.BUCKET, | ||
| ARCHIVER_CONFIG.getArchiveBucket(), | ||
| S3DataSegmentPuller.KEY, | ||
| ARCHIVER_CONFIG.getArchiveBaseKey() + "archived" | ||
| )); | ||
| final S3DataSegmentArchiver archiver = new S3DataSegmentArchiver(MAPPER, S3_SERVICE, ARCHIVER_CONFIG, PUSHER_CONFIG) | ||
| { | ||
| @Override | ||
| public DataSegment move(DataSegment segment, Map<String, Object> targetLoadSpec) throws SegmentLoadingException | ||
| { | ||
| return archivedSegment; | ||
| } | ||
| }; | ||
| Assert.assertEquals(archivedSegment, archiver.archive(SOURCE_SEGMENT)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSimpleArchiveDoesntMove() throws Exception | ||
| { | ||
| final S3DataSegmentArchiver archiver = new S3DataSegmentArchiver(MAPPER, S3_SERVICE, ARCHIVER_CONFIG, PUSHER_CONFIG) | ||
| { | ||
| @Override | ||
| public DataSegment move(DataSegment segment, Map<String, Object> targetLoadSpec) throws SegmentLoadingException | ||
| { | ||
| return SOURCE_SEGMENT; | ||
| } | ||
| }; | ||
| Assert.assertNull(archiver.archive(SOURCE_SEGMENT)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSimpleRestore() throws Exception | ||
| { | ||
| final DataSegment archivedSegment = SOURCE_SEGMENT | ||
| .withLoadSpec(ImmutableMap.<String, Object>of( | ||
| "type", | ||
| S3StorageDruidModule.SCHEME, | ||
| S3DataSegmentPuller.BUCKET, | ||
| ARCHIVER_CONFIG.getArchiveBucket(), | ||
| S3DataSegmentPuller.KEY, | ||
| ARCHIVER_CONFIG.getArchiveBaseKey() + "archived" | ||
| )); | ||
| final S3DataSegmentArchiver archiver = new S3DataSegmentArchiver(MAPPER, S3_SERVICE, ARCHIVER_CONFIG, PUSHER_CONFIG) | ||
| { | ||
| @Override | ||
| public DataSegment move(DataSegment segment, Map<String, Object> targetLoadSpec) throws SegmentLoadingException | ||
| { | ||
| return archivedSegment; | ||
| } | ||
| }; | ||
| Assert.assertEquals(archivedSegment, archiver.restore(SOURCE_SEGMENT)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSimpleRestoreDoesntMove() throws Exception | ||
| { | ||
| final S3DataSegmentArchiver archiver = new S3DataSegmentArchiver(MAPPER, S3_SERVICE, ARCHIVER_CONFIG, PUSHER_CONFIG) | ||
| { | ||
| @Override | ||
| public DataSegment move(DataSegment segment, Map<String, Object> targetLoadSpec) throws SegmentLoadingException | ||
| { | ||
| return SOURCE_SEGMENT; | ||
| } | ||
| }; | ||
| Assert.assertNull(archiver.restore(SOURCE_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 annotate with
@javax.annotation.Nullable? This will make IDE to warn you about using the object, returned from this method, without null check.