Skip to content
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

Allow passing database context through database http header #12417

Merged
merged 42 commits into from
Mar 12, 2024

Conversation

shounakmk219
Copy link
Collaborator

@shounakmk219 shounakmk219 commented Feb 14, 2024

Description

This PR aims to allow a way of passing the database context along with the API requests without disrupting the existing APIs.
The database context will be passed as a database http header along with the API requests. It is part of the effort to support database concept in Pinot #12333

Release Notes

  • Allow passing database name context through database http header

- Allow passing database through http header
- Create v2 endpoints for ones which accept table name as path param or part of request body.
@shounakmk219 shounakmk219 marked this pull request as draft February 14, 2024 07:19
@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2024

Codecov Report

Attention: Patch coverage is 55.09554% with 141 lines in your changes are missing coverage. Please review.

Project coverage is 61.65%. Comparing base (59551e4) to head (a7d6f93).
Report is 121 commits behind head on master.

Files Patch % Lines
...ntroller/helix/core/PinotHelixResourceManager.java 29.41% 17 Missing and 7 partials ⚠️
...oller/api/resources/PinotTableRestletResource.java 66.66% 14 Missing and 8 partials ⚠️
...ler/api/resources/PinotSegmentRestletResource.java 25.92% 20 Missing ⚠️
...roller/api/resources/PinotTaskRestletResource.java 0.00% 9 Missing ⚠️
...ler/api/resources/TableConfigsRestletResource.java 75.86% 2 Missing and 5 partials ⚠️
...java/org/apache/pinot/spi/config/TableConfigs.java 0.00% 7 Missing ⚠️
...a/org/apache/pinot/common/utils/DatabaseUtils.java 68.75% 3 Missing and 2 partials ⚠️
...ller/api/resources/PinotRealtimeTableResource.java 0.00% 5 Missing ⚠️
...ller/api/resources/PinotSchemaRestletResource.java 87.80% 1 Missing and 4 partials ⚠️
...ller/api/resources/PinotBrokerRestletResource.java 55.55% 4 Missing ⚠️
... and 14 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #12417      +/-   ##
============================================
- Coverage     61.75%   61.65%   -0.10%     
+ Complexity      207      198       -9     
============================================
  Files          2436     2455      +19     
  Lines        133233   134004     +771     
  Branches      20636    20781     +145     
============================================
+ Hits          82274    82623     +349     
- Misses        44911    45246     +335     
- Partials       6048     6135      +87     
Flag Coverage Δ
custom-integration1 <0.01% <0.00%> (-0.01%) ⬇️
integration <0.01% <0.00%> (-0.01%) ⬇️
integration1 <0.01% <0.00%> (-0.01%) ⬇️
integration2 0.00% <0.00%> (ø)
java-11 <0.01% <0.00%> (-61.71%) ⬇️
java-21 61.65% <55.09%> (+0.03%) ⬆️
skip-bytebuffers-false 61.65% <55.09%> (-0.10%) ⬇️
skip-bytebuffers-true 0.00% <0.00%> (-27.73%) ⬇️
temurin 61.65% <55.09%> (-0.10%) ⬇️
unittests 61.65% <55.09%> (-0.10%) ⬇️
unittests1 46.75% <44.44%> (-0.14%) ⬇️
unittests2 27.70% <51.27%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shounakmk219 shounakmk219 marked this pull request as ready for review February 14, 2024 12:50
@Jackie-Jiang Jackie-Jiang added feature release-notes Referenced by PRs that need attention when compiling the next release notes labels Feb 14, 2024
@Jackie-Jiang
Copy link
Contributor

cc @zhtaoxiang to also take a look

Copy link
Contributor

@Jackie-Jiang Jackie-Jiang left a comment

Choose a reason for hiding this comment

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

Can we also process the path parameter during the request filtering? IIRC there is a filter that can be applied after matching the path, and I don't like the idea of adding all these v2 APIs

@shounakmk219
Copy link
Collaborator Author

Can we also process the path parameter during the request filtering? IIRC there is a filter that can be applied after matching the path, and I don't like the idea of adding all these v2 APIs

Hey @Jackie-Jiang we can't update the URI in post match phase and path param context is only available there (doc ref).
Due to this limitation we are forced to manually handle the translation for the endpoints having table name as path param. Intent of the v2 APIs is to discourage the table name input as path param and eventually deprecate it so that we have a centralised place where translation is performed and avoid the maintenance overhead around it.
Let me know your thoughts.

Copy link
Contributor

@Jackie-Jiang Jackie-Jiang left a comment

Choose a reason for hiding this comment

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

I don't think we need to define a "default" database. If database is provided, then it is not default; if it is not provided, we should directly use table name as is

if (schemas != null) {
return schemas.stream().filter(schemaName -> isPartOfDatabase(schemaName, databaseName))
.collect(Collectors.toList());
if (databaseName != null) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will return all schemas when databaseName is null, shouldn't the null database name be considered as the default database and only return schemas under the default database?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good call. We need to loop over all schemas

Preconditions.checkState(
DatabaseUtils.translateTableName(tableConfigs.getTableName(), headers).equals(translatedTableName),
"Table name mismatch: %s is not equivalent to %s", tableConfigs.getTableName(), tableName);
tableConfigs.setTableName(DatabaseUtils.translateTableName(tableConfigs.getTableName(), headers));
Copy link
Collaborator Author

@shounakmk219 shounakmk219 Mar 12, 2024

Choose a reason for hiding this comment

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

setting the table name here will make all the validations on table/schema names redundant which are part of validateConfig(tableConfigs, typesToSkip); called below. This in a way will allow user to pass invalid schema or realtime/offline table names as ultimately it gets overridden by the translated raw table name.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point. Changed the order

@npawar
Copy link
Contributor

npawar commented May 22, 2024

@shounakmk219 do we have documentation on this feature?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature release-notes Referenced by PRs that need attention when compiling the next release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants