Repository navigation
Conversation
orca-review-bot
left a comment
There was a problem hiding this comment.
Nice split. The adapter → handler → catalog stack follows the generic-table pattern, and the scan SPI being off by default matches the dev-list plan.
Main thing: existing directories are invisible to the location-overlap check. PolarisEntityUtils.asLocationBasedEntity has no DIRECTORY case, so the list-based sibling check resolves a sibling directory and then drops it. As a result, two directories, or a new table and an existing directory, can overlap. I left the details on the overlap call in the handler.
Tests to add: directory-vs-directory and table-vs-directory overlap, create when <name>__inventory already exists, and a base_location that contains the namespace location, so the inventory table sits inside the scanned prefix.
I also checked that a pre-existing __inventory table makes create fail and roll back the directory entity, which is the right behavior.
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| realmConfig(), identifier, Set.of(baseLocation), resolvedParent); | ||
| // The scan exposes the names and sizes of the objects under the base location: it must not | ||
| // overlap the location of a sibling table, view, directory or namespace | ||
| ((LocalIcebergCatalog) icebergCatalog) |
There was a problem hiding this comment.
This comment promises no overlap with a sibling directory, but existing directories never get checked. The sibling loop in LocalIcebergCatalog resolves them and then passes them through PolarisEntityUtils.asLocationBasedEntity, which has no DIRECTORY case and returns empty. So directory B can sit under directory A, and its scan would list A's objects. The same gap lets a new Iceberg table land inside an existing directory. Can we add case DIRECTORY -> DirectoryEntity.of(entity) there and add a test for both cases?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
There was a problem hiding this comment.
- This comment is helpful but cant solve not sufficient on its own. ModelEntity.fromEntity only sets location_without_scheme for Iceberg table/view and namespace — not DIRECTORY:
ModelEntity.java
if (entity.getType() == PolarisEntityType.TABLE_LIKE) {
if (entity.getSubType() == PolarisEntitySubType.ICEBERG_TABLE
|| entity.getSubType() == PolarisEntitySubType.ICEBERG_VIEW) {
builder.locationWithoutScheme(
StorageLocation.of(
entity.getPropertiesAsMap().get(PolarisEntityConstants.ENTITY_BASE_LOCATION))
.withoutScheme());
}
}
if (entity.getType() == PolarisEntityType.NAMESPACE) {
Directories store base_location in internal props (DirectoryEntity.BASE_LOCATION_KEY), not location like Iceberg entities. So generateOverlapQuery may never see them even if asLocationBasedEntity is fixed.
- MutationAttempt.updateLocationsIndex only reads
ENTITY_BASE_LOCATION("location") from obj properties. Directories use baseLocation on DirectoryObj / base_location in internal props. Same overlap gap on NoSQL backends.
| try { | ||
| this.icebergCatalog.createTable(tableId, DIRECTORY_TABLE_SCHEMA); | ||
| LOGGER.debug("Created associated Iceberg table {} for directory {}", tableId, identifier); | ||
| } catch (RuntimeException e) { |
There was a problem hiding this comment.
This catches every RuntimeException, CommitStateUnknownException included. If the inventory commit actually succeeded, we drop the directory but leave <name>__inventory behind. Every later create of that name then fails on the leftover table. Should we skip the rollback (or check tableExists) when the commit state is unknown?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| public interface DirectoryScanService { | ||
|
|
||
| /** | ||
| * @param identifier the directory identifier, also the identifier of its inventory table |
There was a problem hiding this comment.
The inventory table is <name>__inventory, so it isn't the same identifier as the directory. Can we fix this so SPI implementers don't write to the wrong table?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| .defaultValue(true) | ||
| .buildFeatureConfiguration(); | ||
|
|
||
| public static final FeatureConfiguration<Boolean> ENABLE_DIRECTORIES = |
There was a problem hiding this comment.
Defaulting a beta feature to on means every catalog's config response changes on upgrade (hence all the regtest ref churn). Was default-true agreed for 1.9.0, or should this be false like ENABLE_DIRECTORY_SCAN?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| String prefix, | ||
| String namespace, | ||
| CreateDirectoryRequest createDirectoryRequest, | ||
| List<String> polarisDirectoryAccessDelegation, |
There was a problem hiding this comment.
polarisDirectoryAccessDelegation is accepted but never read, so clients can send the header and nothing happens. Can we drop it from the spec until it's wired through, or pass it to the handler?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
ArnabKarmakar1108
left a comment
There was a problem hiding this comment.
Thanks for working on this!
| realmConfig(), identifier, Set.of(baseLocation), resolvedParent); | ||
| // The scan exposes the names and sizes of the objects under the base location: it must not | ||
| // overlap the location of a sibling table, view, directory or namespace | ||
| ((LocalIcebergCatalog) icebergCatalog) |
There was a problem hiding this comment.
- This comment is helpful but cant solve not sufficient on its own. ModelEntity.fromEntity only sets location_without_scheme for Iceberg table/view and namespace — not DIRECTORY:
ModelEntity.java
if (entity.getType() == PolarisEntityType.TABLE_LIKE) {
if (entity.getSubType() == PolarisEntitySubType.ICEBERG_TABLE
|| entity.getSubType() == PolarisEntitySubType.ICEBERG_VIEW) {
builder.locationWithoutScheme(
StorageLocation.of(
entity.getPropertiesAsMap().get(PolarisEntityConstants.ENTITY_BASE_LOCATION))
.withoutScheme());
}
}
if (entity.getType() == PolarisEntityType.NAMESPACE) {
Directories store base_location in internal props (DirectoryEntity.BASE_LOCATION_KEY), not location like Iceberg entities. So generateOverlapQuery may never see them even if asLocationBasedEntity is fixed.
- MutationAttempt.updateLocationsIndex only reads
ENTITY_BASE_LOCATION("location") from obj properties. Directories use baseLocation on DirectoryObj / base_location in internal props. Same overlap gap on NoSQL backends.
| } | ||
|
|
||
| @Test | ||
| public void testInventoryTableCoexistsWithDirectory() { |
There was a problem hiding this comment.
We are only covering inventory created after the directory, not create-directory when __inventory already exists at the handler layer. I think adding a case for that would improve the coverage.
| if (targetLocation.isChildOf(siblingLocation) | ||
| || siblingLocation.isChildOf(targetLocation)) { | ||
| throw new ForbiddenException( | ||
| "Unable to create entity at location '%s' because it conflicts with existing table or namespace at " |
There was a problem hiding this comment.
I think the message should also mention directories. Same for line 1709.
| federatedCatalog = | ||
| federatedCatalogFactory | ||
| .get() | ||
| .createDirectoryCatalog( |
There was a problem hiding this comment.
After ENABLE_CATALOG_FEDERATION, createDirectoryCatalog defaults to UnsupportedOperationException. Directories enabled on a federated catalog fail at runtime with a generic unsupported error. Rejecting earlier with a clear message would be clearer or we can document “internal catalog only”.
|
|
||
| @QuarkusTest | ||
| @TestProfile(Profiles.PolarisAuthzBaseProfile.class) | ||
| public class PolarisDirectoryCatalogHandlerAuthzTest extends PolarisAuthzTestBase { |
There was a problem hiding this comment.
We are covering list/create/load/drop but no scanDirectory matrix.
| * drop flow goes through the REST layer, including authorization and location validation. | ||
| */ | ||
| @ExtendWith(PolarisIntegrationTestExtension.class) | ||
| public class PolarisDirectoryServiceIntegrationTest { |
There was a problem hiding this comment.
I think we are missing cases where directory exists then overlapping table, two overlapping directories.
|
Heads-up: #5967 has been merged, so Could you rebase onto |
This is the second of three PRs split from #4613:
DirectoryScanServiceSPIIt is stacked on #5927: until that one is merged, this PR also shows its commit. Only the last commit (
Add the Directory entity, REST endpoints and DirectoryScanService SPI) belongs to this PR.Changes
DIRECTORYtable-like sub-type andDirectoryEntity(base location, include/exclude filters, scan schedule), with its NoSQL mapping (DirectoryObj). The relational persistence needs no schema change.DirectoryCatalogAdapter,DirectoryCatalogHandler,PolarisDirectoryCatalog), with the corresponding events (newDIRECTORYevent category). Creating a directory also creates its Iceberg inventory table with a predefined schema. The table is named<directory>__inventory, because a directory and a table cannot share a name in a namespace (both are table-like entities). Dropping the directory drops the table.base_locationis validated like a table location: it must be within the catalog's allowed locations, and within the namespace location unlesspolaris.config.allow.unstructured.table.locationistrueon the catalog. It must not overlap the location of a sibling table, view, directory or namespace. Filters must be valid regular expressions.DirectoryScanServiceSPI:POST .../directories/{directory}/scanauthorizes the request (UPDATE_TABLEon the directory), vends read/list credentials scoped tobase_location, and then calls theDirectoryScanServicebean. An extension can provide its own bean. In this PR, the default bean (DefaultDirectoryScanService, a@DefaultBean) rejects the scan. The next PR replaces it with the simple scan service.ENABLE_DIRECTORIES(defaulttrue) enables the directory endpoints.ENABLE_DIRECTORY_SCAN(defaultfalse) enables the scan endpoint: when disabled, the endpoint is rejected and not advertised in the catalog config. BecauseENABLE_DIRECTORIESdefaults totrue, every catalog config now lists the four directory endpoints, hence the regtest reference updates.Tests
AbstractPolarisDirectoryCatalogTest(relational and NoSQL in-memory),PolarisDirectoryCatalogHandlerAuthzTest,DirectoryConfigEndpointsTest,PolarisResourcePathsTest,TestTableLikeMapping.DirectoryServiceIntegrationTest: end-to-end REST test on a file-based catalog (create/load/list/drop, location validation, read-only principal cannot scan or drop).Notes for reviewers
DirectoryScannertoDirectoryCatalogHandler, so creating a directory does not depend on the scanner.directories.md.Checklist
CHANGELOG.md(if needed)site/content/in-dev/unreleased(if needed)