Skip to content
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 @@ -126,6 +126,12 @@ public List<OrderBy> getOrdering()
{
return Cursors.ascendingTimeOrder();
}

@Override
public int getNumRows()
{
return 1234;
}
Comment on lines +131 to +134
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unused?

};

public static class SegmentForTesting extends QueryableIndexSegment
Expand Down Expand Up @@ -178,6 +184,8 @@ public <T> T as(@Nonnull Class<T> clazz)
return (T) INDEX;
} else if (clazz.equals(CursorFactory.class)) {
return (T) new QueryableIndexCursorFactory(INDEX);
} else if (clazz.equals(PhysicalSegmentInspector.class)) {
return (T) new QueryableIndexPhysicalSegmentInspector(INDEX);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,25 @@ boolean isSegmentCached(final DataSegment segment)
return false;
}

/**
* Testing use only please, any callers that want to do stuff with segments should use
* {@link #acquireCachedSegment(DataSegment)} or {@link #acquireSegment(DataSegment)} instead. Does not hold locks
* and so is not really safe to use while the cache manager is active
*/
@VisibleForTesting
@Nullable
public ReferenceCountedSegmentProvider getSegmentReferenceProvider(DataSegment segment)
{
final SegmentCacheEntry cacheEntry = new SegmentCacheEntry(segment);
for (StorageLocation location : locations) {
final SegmentCacheEntry entry = location.getCacheEntry(cacheEntry.id);
if (entry != null) {
return entry.referenceProvider;
}
}
return null;
}

/**
* Returns the effective segment info directory based on the configuration settings.
* The directory is selected based on the following configurations injected into this class:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,11 @@ public void dropSegment(final DataSegment dataSegment)
try (final Closer closer = Closer.create()) {
final Optional<Segment> oldSegment = cacheManager.acquireCachedSegment(oldSegmentRef);
long numberOfRows = oldSegment.map(segment -> {
closer.register(segment);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: the oldSegment.map here seems a bit unnecessary, could be more readable if use simple if oldSegment.isPresent()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me the structure seems reasonable, since for regular segments it is doing return countInspector.getNumRows() and the return val numberOfRows ends up going to the dataSourceState.removeSegment call.

final PhysicalSegmentInspector countInspector = segment.as(PhysicalSegmentInspector.class);
if (countInspector != null) {
return countInspector.getNumRows();
}
CloseableUtils.closeAndWrapExceptions(segment);
return 0;
}).orElse(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.druid.query.expression.TestExprMacroTable;
import org.apache.druid.segment.IndexIO;
import org.apache.druid.segment.IndexSpec;
import org.apache.druid.segment.ReferenceCountedSegmentProvider;
import org.apache.druid.segment.SegmentLazyLoadFailCallback;
import org.apache.druid.segment.SegmentMapFunction;
import org.apache.druid.segment.TestHelper;
Expand All @@ -45,7 +46,6 @@
import org.apache.druid.segment.loading.LeastBytesUsedStorageLocationSelectorStrategy;
import org.apache.druid.segment.loading.LocalDataSegmentPuller;
import org.apache.druid.segment.loading.LocalLoadSpec;
import org.apache.druid.segment.loading.SegmentCacheManager;
import org.apache.druid.segment.loading.SegmentLoaderConfig;
import org.apache.druid.segment.loading.SegmentLoadingException;
import org.apache.druid.segment.loading.SegmentLocalCacheManager;
Expand Down Expand Up @@ -90,7 +90,9 @@ public class SegmentManagerTest extends InitializedNullHandlingTest
);

private ExecutorService executor;
private SegmentLocalCacheManager cacheManager;
private SegmentManager segmentManager;
private SegmentLocalCacheManager virtualCacheManager;
private SegmentManager virtualSegmentManager;

@Rule
Expand Down Expand Up @@ -160,7 +162,7 @@ public boolean isVirtualStorage()
);

final List<StorageLocation> storageLocations = loaderConfig.toStorageLocations();
final SegmentLocalCacheManager cacheManager = new SegmentLocalCacheManager(
cacheManager = new SegmentLocalCacheManager(
storageLocations,
loaderConfig,
new LeastBytesUsedStorageLocationSelectorStrategy(storageLocations),
Expand All @@ -170,7 +172,7 @@ public boolean isVirtualStorage()
segmentManager = new SegmentManager(cacheManager);

final List<StorageLocation> virtualStorageLocations = virtualLoaderConfig.toStorageLocations();
final SegmentCacheManager virtualCacheManager = new SegmentLocalCacheManager(
virtualCacheManager = new SegmentLocalCacheManager(
virtualStorageLocations,
virtualLoaderConfig,
new LeastBytesUsedStorageLocationSelectorStrategy(virtualStorageLocations),
Expand Down Expand Up @@ -238,8 +240,12 @@ public void testLoadBootstrapSegment() throws ExecutionException, InterruptedExc
@Test
public void testDropSegment() throws SegmentLoadingException, ExecutionException, InterruptedException, IOException
{
List<ReferenceCountedSegmentProvider> referenceProviders = new ArrayList<>();
for (DataSegment eachSegment : SEGMENTS) {
segmentManager.loadSegment(eachSegment);
ReferenceCountedSegmentProvider refProvider = cacheManager.getSegmentReferenceProvider(eachSegment);
referenceProviders.add(refProvider);
Assert.assertFalse(refProvider.isClosed());
}

final List<Future<Void>> futures = ImmutableList.of(SEGMENTS.get(0), SEGMENTS.get(2)).stream()
Expand All @@ -260,6 +266,14 @@ public void testDropSegment() throws SegmentLoadingException, ExecutionException
assertResult(
ImmutableList.of(SEGMENTS.get(1), SEGMENTS.get(3), SEGMENTS.get(4))
);
for (int i = 0; i < SEGMENTS.size(); i++) {
Assert.assertEquals(0, referenceProviders.get(i).getNumReferences());
if (i == 0 || i == 2) {
Assert.assertTrue(referenceProviders.get(i).isClosed());
} else {
Assert.assertFalse(referenceProviders.get(i).isClosed());
}
}
}

private Void loadSegmentOrFail(DataSegment segment)
Expand Down
Loading