Skip to content

SegmentLoader refactoring#11466

Merged
abhishekagarwal87 merged 4 commits intoapache:masterfrom
abhishekagarwal87:segment_loader_refactoring
Jul 20, 2021
Merged

SegmentLoader refactoring#11466
abhishekagarwal87 merged 4 commits intoapache:masterfrom
abhishekagarwal87:segment_loader_refactoring

Conversation

@abhishekagarwal87
Copy link
Copy Markdown
Contributor

@abhishekagarwal87 abhishekagarwal87 commented Jul 19, 2021

This PR splits current SegmentLoader into SegmentLoader and SegmentCacheManager.

  • SegmentLoader - this class is responsible for building the segment object but does not expose any methods for downloading, cache space management, etc. Default implementation delegates the download operations to SegmentCacheManager and only contains the logic for building segments once downloaded. . This class will be used in SegmentManager to construct Segment objects.

  • SegmentCacheManager - this class manages the segment cache on the local disk. It fetches the segment files to the local disk, can clean up the cache, and in the future, support reserve and release on cache space. [See https://github.com/Make SegmentLoader extensible and customizable #11398]. This class will be used in ingestion tasks such as compaction, re-indexing where segment files need to be downloaded locally.


Key changed/added classes in this PR
  • SegmentLoader
  • SegmentCacheManager
  • SegmentLoadDropHandler
  • SegmentLocalCacheManager
  • SegmentLocalCacheLoader
  • SegmentLoaderFactory > SegmentCacheManagerFactory

This PR has:

  • been self-reviewed.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.

Copy link
Copy Markdown
Contributor

@jihoonson jihoonson left a comment

Choose a reason for hiding this comment

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

The refactoring LGTM overall, but the CI failure seems legit. Please fix it.

[ERROR] testDefaultViewManagerBind(org.apache.druid.sql.guice.SqlModuleTest) Time elapsed: 0.017 s <<< ERROR!
com.google.inject.CreationException:
Unable to create injector, see the following errors:

  1. No implementation for org.apache.druid.segment.loading.SegmentLoader was bound.
    while locating org.apache.druid.segment.loading.SegmentLoader
    for the 1st parameter of org.apache.druid.server.SegmentManager.(SegmentManager.java:120)
    while locating org.apache.druid.server.SegmentManager
    for the 3rd parameter of org.apache.druid.sql.calcite.schema.DruidSchema.(DruidSchema.java:153)
    while locating org.apache.druid.sql.calcite.schema.DruidSchema
    for the 1st parameter of org.apache.druid.sql.calcite.schema.SystemSchema.(SystemSchema.java:216)
    at org.apache.druid.sql.calcite.schema.DruidCalciteSchemaModule.configure(DruidCalciteSchemaModule.java:55) (via modules: org.apache.druid.sql.guice.SqlModule -> org.apache.druid.sql.calcite.schema.DruidCalciteSchemaModule)
  2. No implementation for org.apache.druid.segment.loading.SegmentLoader was bound.
    while locating org.apache.druid.segment.loading.SegmentLoader
    for the 1st parameter of org.apache.druid.server.SegmentManager.(SegmentManager.java:120)
    while locating org.apache.druid.server.SegmentManager
    for the 3rd parameter of org.apache.druid.sql.calcite.schema.DruidSchema.(DruidSchema.java:153)
    while locating org.apache.druid.sql.calcite.schema.DruidSchema
    for the 1st parameter of org.apache.druid.sql.calcite.schema.NamedDruidSchema.(NamedDruidSchema.java:35)
    at org.apache.druid.sql.guice.SqlBindings.addSchema(SqlBindings.java:58) (via modules: org.apache.druid.sql.guice.SqlModule -> org.apache.druid.sql.calcite.schema.DruidCalciteSchemaModule)

this.indexIO = Preconditions.checkNotNull(indexIO, "null IndexIO");
this.coordinatorClient = Preconditions.checkNotNull(coordinatorClient, "null CoordinatorClient");
this.segmentLoaderFactory = Preconditions.checkNotNull(segmentLoaderFactory, "null SegmentLoaderFactory");
this.segmentCacheManagerFactory = Preconditions.checkNotNull(segmentCacheManagerFactory, "null SegmentLoaderFactory");
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.

Suggested change
this.segmentCacheManagerFactory = Preconditions.checkNotNull(segmentCacheManagerFactory, "null SegmentLoaderFactory");
this.segmentCacheManagerFactory = Preconditions.checkNotNull(segmentCacheManagerFactory, "null segmentCacheManagerFactory");

this.indexIO = Preconditions.checkNotNull(indexIO, "null IndexIO");
this.coordinatorClient = Preconditions.checkNotNull(coordinatorClient, "null CoordinatorClient");
this.segmentLoaderFactory = Preconditions.checkNotNull(segmentLoaderFactory, "null SegmentLoaderFactory");
this.segmentCacheManagerFactory = Preconditions.checkNotNull(segmentCacheManagerFactory, "null SegmentLoaderFactory");
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.

Suggested change
this.segmentCacheManagerFactory = Preconditions.checkNotNull(segmentCacheManagerFactory, "null SegmentLoaderFactory");
this.segmentCacheManagerFactory = Preconditions.checkNotNull(segmentCacheManagerFactory, "null segmentCacheManagerFactory");

public interface SegmentCacheManager
{
boolean isSegmentCached(DataSegment segment);
File getSegmentFiles(DataSegment segment) throws SegmentLoadingException;
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.

Perhaps nice to add a javadoc that says, this method can fetch the segment file unless it's already loaded.

@abhishekagarwal87
Copy link
Copy Markdown
Contributor Author

Thanks @jihoonson for the review. I have addressed the comments and fixed the tests.

Copy link
Copy Markdown
Contributor

@jihoonson jihoonson left a comment

Choose a reason for hiding this comment

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

LGTM. Splitting interface makes sense to me.

@abhishekagarwal87 abhishekagarwal87 merged commit 94c1671 into apache:master Jul 20, 2021
@abhishekagarwal87 abhishekagarwal87 deleted the segment_loader_refactoring branch July 22, 2021 10:13
@clintropolis clintropolis added this to the 0.22.0 milestone Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants