Repository navigation
Conversation
orca-review-bot
left a comment
There was a problem hiding this comment.
Nice, compact scanner. Commit and cleanup handling look right: the new file is deleted on a normal failure and kept when the commit state is unknown. Auth and credential scoping stay in the handler, which is where they belong.
A few things not tied to one line:
- Tests: can we add a DirectoryScannerTest case for the inventory table living under
base_location(its files shouldn't be counted), and one wherecommit()throwsCommitFailedExceptionand the new data file gets deleted? A scan in one of the S3 ITs (RustFS/Floci) would also exercise the vended READ+LIST creds against a real object store. - Docs: directories.md already covers sync behavior and columns. Can we add that the listing is held in memory, so large directories aren't a good fit yet?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| List<String> include, | ||
| List<String> exclude) { | ||
| // The FileIO factory wraps the FileIO, and the wrapper does not expose the prefix operations | ||
| FileIO io = sourceIO instanceof ExceptionMappingFileIO w ? w.getInnerIo() : sourceIO; |
There was a problem hiding this comment.
This reaches past the wrapper through getInnerIo(), which is @VisibleForTesting. Listing errors then skip the UnknownHost mapping the wrapper is there for. ExceptionMappingFileIO.wrap already keeps SupportsBulkOperations with a subclass. Can we do the same for SupportsPrefixOperations and drop the unwrap here?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| List<Pattern> includePatterns = compile(include); | ||
| List<Pattern> excludePatterns = compile(exclude); | ||
|
|
||
| List<Record> records = new ArrayList<>(); |
There was a problem hiding this comment.
Every matching object becomes a Record in this list before anything gets written, so heap use grows with the size of the prefix. Fine while the flag is off, but the first big bucket someone points this at could OOM the server. Can we open the DataWriter up front and write records as we list?
🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.
| for (FileInfo file : prefixIO.listPrefix(baseLocation)) { | ||
| String uri = file.location(); | ||
| // The inventory table may live under the base location: do not index its own files | ||
| if (uri.startsWith(inventoryLocation)) { |
There was a problem hiding this comment.
This is a plain string prefix check against table.location(). If listPrefix returns a different form (s3a vs s3, an extra slash), the inventory would start indexing its own files. Did you check that the forms match on S3? Not sure about GCS/ADLS either.
🤖 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!
| String baseLocation, | ||
| List<String> include, | ||
| List<String> exclude) { | ||
| // The FileIO factory wraps the FileIO, and the wrapper does not expose the prefix operations |
There was a problem hiding this comment.
Prefix support is detected only after unwrapping ExceptionMappingFileIO something like:
WasbTranslatingFileIO -> ExceptionMappingFileIO -> real FileIO (can list)
Production Azure setups use WasbTranslatingFileIOFactory, which returns WasbTranslatingFileIO outside ExceptionMappingFileIO. I think we should either unwrap the full factory wrapper chain (like ExceptionMappingFileIO.getInnerIo()), or delegate listPrefix from WasbTranslatingFileIO to the inner IO.
| List<Pattern> includePatterns = compile(include); | ||
| List<Pattern> excludePatterns = compile(exclude); |
There was a problem hiding this comment.
patterns are Pattern.compile’d on every scan and matched with .find(). Complex regexes can cause heavy backtracking on long URIs during UPDATE_TABLE-authorized scan. Should we consider timeouts, or pattern complexity limit?
| try { | ||
| if (!records.isEmpty()) { | ||
| dataFileLocation = table.locationProvider().newDataLocation(UUID.randomUUID() + ".parquet"); | ||
| overwrite.addFile(write(table, dataFileLocation, records)); |
There was a problem hiding this comment.
Not sure but is this thread safe? Should we serialize on directory/inventory id?
|
|
||
| List<Record> records = new ArrayList<>(); | ||
| String inventoryLocation = StorageLocation.ensureTrailingSlash(table.location()); | ||
| for (FileInfo file : prefixIO.listPrefix(baseLocation)) { |
There was a problem hiding this comment.
We are not considering any trailing slashes in listPrefix(baseLocation) but object stores and FileIO implementations often treat s3://b/p and s3://b/p/ differently. The tests are always using a trailing slash.
| if (matches(uri, includePatterns, excludePatterns)) { | ||
| Record record = GenericRecord.create(table.schema()); | ||
| record.setField("file_uri", uri); | ||
| record.setField("content_type", URLConnection.guessContentTypeFromName(uri)); |
There was a problem hiding this comment.
URLConnection.guessContentTypeFromName(uri) can often return null right? Some rows are going to have null content_type.
| assertThat(directoryApi.scanDirectory(catalogName, IMAGES)).isEqualTo(2L); | ||
| assertThat(restCatalog.loadTable(IMAGES_INVENTORY).currentSnapshot()).isNotNull(); |
There was a problem hiding this comment.
Can we also assert file_uri values, filter behavior? It'd be helpful in preventing regressions from passing.
|
Heads-up: #5967 has been merged, so Could you rebase onto |
This is the third of three PRs split from #4613:
DirectoryScanServiceSPIIt is stacked on #5928: until the previous PRs are merged, this PR also shows their commits. Only the last commit (
Add a simple directory scan service to populate the directory inventory table) belongs to this PR.Changes
DefaultDirectoryScanService(the defaultDirectoryScanServicebean) now uses a simple scanner,DirectoryScanner, to populate the directory inventory table onPOST /polaris/v1/{prefix}/namespaces/{namespace}/directories/{directory}/scan:base_location(with read/list credentials scoped to that location), applies the include/exclude filters, and replaces the table content with a Parquet data file in a single overwrite commit. A failed scan leaves the table unchanged. If the commit state is unknown, the new data file is kept, as the commit may have landed.file_uri,content_type(guessed from the file name),sizeandlast_modified. The other columns are left empty.FileIOthat supports listing a prefix.ENABLE_DIRECTORY_SCAN): the scan is synchronous and keeps the listing in memory, so it is not suited to large directories yet.scan-schedulestays informational, so periodic scans are left to the caller or an external scheduler.DirectoryScanServicebean (for example to compute checksums or update the table incrementally).Dependencies: adds
iceberg-data,iceberg-parquetandparquet-hadoop(same Parquet version as the one already on the runtime classpath) to the runtime service, with the matchingLICENSEentries. The Spark plugin and Spark tests exclude the server's Parquet, so it does not override the Parquet version provided by Spark.Tests
DirectoryScannerTest: scanner behavior on an in-memory file system (filters, rescan, recorded metadata, wrappedFileIO, missing prefix operations support, unknown commit state).DirectoryServiceIntegrationTest: the end-to-end test now scans the directory between create and drop.Notes for reviewers
Checklist
CHANGELOG.md(if needed)site/content/in-dev/unreleased(if needed)