Skip to content

HIVE-29981: compact2 reinforcement - #6884

Open
DanielZhu58 wants to merge 10 commits into
apache:masterfrom
DanielZhu58:nonpublic03
Open

DanielZhu58 wants to merge 10 commits into
apache:masterfrom
DanielZhu58:nonpublic03

Conversation

@DanielZhu58

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Why are the changes needed?

Does this PR introduce any user-facing change?

How was this patch tested?

throw new MetaException("Cannot determine storage location of " + dbName + "." + tblName
+ "; compaction is not supported for this table or partition");
}
rqst.setRunas(TxnUtils.findUserToRunAs(location, table, conf));

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.

Existing-table cleanup still accepts the caller’s location, so Cleaner may delete a path different from the authorized table.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.
For non-privileged callers, a supplied cleanup location must now be inside the authorized table's or partition's location after normalizing. Otherwise it is rejected.

allowedRoots.add(normalizePath(warehouse, new Path(db.getManagedLocationUri())));
}
allowedRoots.add(normalizePath(warehouse, warehouse.getDatabaseManagedPath(db)));
boolean allowed = allowedRoots.stream()

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.

Database containment isn’t enough. A fake table name can still target another table’s directory right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acknowledged.
Fixed by removing the database-level fallback.
Non-privileged callers can only clean up for an existing table they are authorized on, and the location is constrained to it.

String catName = parsedDbName[CAT_NAME];
String dbName = parsedDbName[DB_NAME];
String tblName = rqst.getTablename();
rqst.setDbname(dbName);

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.

The catalog is removed after authorization, so the queued operation may affect a same-named table in the default catalog. Also, check if you need normalize catName, dbName, and tblName.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. The request is now queued with the normalized db and table names from the fetched table.

authorizeCleanupOfMissingTable(rqst, catName, dbName);
return;
}
firePreEvent(new PreAlterTableEvent(table, table, this));

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 authorizes compaction as ADD COLUMNS. Could we use the actual COMPACT operation instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A COMPACT pre-event would also need changes in HiveMetaStoreAuthorizer and the authorization plugins, so it's better as a follow-up.

}
@Override
public CompactionResponse compact2(CompactionRequest rqst) throws TException {
try {

@dengzhhu653 dengzhhu653 Oct 21, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The compact2 is a maintenance API, let's consider:
If a user passes in authorizeProxyPrivilege, then let the request go, otherwise fire the authorization check on the table being requested.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acknowedged. Callers with proxy privilege (same rules as authorizeProxyPrivilege) pass through. Everyone else is authorized against the table.

String tblName = rqst.getTablename();
rqst.setDbname(dbName);

FilterUtils.checkDbAndTableFilters(isServerFilterEnabled, filterHook, catName, dbName, tblName);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we don't need to check checkDbAndTableFilters, a PreAlterTableEvent is enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acknowledged.

@dengzhhu653
dengzhhu653 requested a balanced review from Copilot October 21, 2026 02:17

Copilot AI left a comment

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

6 open issues
What changed in this PR

Reinforces metastore server-side authorization for compact2 and submit_for_cleanup, including stricter handling of cleanup requests when the backing table is missing.

Changes:

  • Add server-side authorization + run-as derivation for compact2 and submit_for_cleanup.
  • Add validation to restrict cleanup of missing-table locations to be strictly within database roots.
  • Extend/adjust metastore server tests to cover new authorization and validation paths.
File Description
standalone-metastore/​metastore-server/​src/​test/​java/​org/​apache/​hadoop/​hive/​metastore/​TestHmsServerAuthorization.java Adds new authorization/validation tests for compact2 and submitForCleanup.
standalone-metastore/​metastore-server/​src/​test/​java/​org/​apache/​hadoop/​hive/​metastore/​TestFilterHooks.java Adjusts test environment setup to avoid filter-hook blocking during compaction enqueue.
standalone-metastore/​metastore-server/​src/​main/​java/​org/​apache/​hadoop/​hive/​metastore/​handler/​TransactionHandler.java Implements authorization + location restriction logic for client-initiated compaction/cleanup requests.

Review effort: Lite

public boolean submit_for_cleanup(CompactionRequest rqst, long highestWriteId, long txnId)
throws TException {
try {
authorizeAndPrepareCompactionRequest(rqst, true);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the target table/partition has been dropped, is it better to ignore such case? cause we do nothing in Cleaner for this case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acknowledged.

try {
authorizeAndPrepareCompactionRequest(rqst);
} catch (Exception e) {
rethrowException(e);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we don't need to re-throw the exception

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acknowledged. Removed the try/catch.

e.getMessage());
return false;
} catch (Exception e) {
rethrowException(e);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we don't need to re-throw the generic exception

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acknowledged.

* trusted in embedded mode, when the proxy check is disabled, in test mode, or when the user has host-proxy
* privileges.
*/
protected boolean hasProxyPrivilege() throws TException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method is similar to authorizeProxyPrivilege, can we reuse this method? upon TException, return false

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acknowledged. It now calls authorizeProxyPrivilege() and returns false on TException. I also made its error log generic.

+ table.getTableName() + "; compaction is not supported for this table or partition");
}

String requestedLocation = rqst.getProperties() == null ? null : rqst.getProperties().get(META_TABLE_LOCATION);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we check the META_TABLE_LOCATION here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The Cleaner purges the location property as is, without looking at the table.
Without this check a caller authorized on table A could pass table B's directory and have it purged.

if (rqst.isSetPartitionname() && rqst.getPartitionname() != null) {
List<String> partVals = getPartValsFromName(table, rqst.getPartitionname());
Partition partition = getMS().getPartition(catName, table.getDbName(), table.getTableName(), partVals);
location = partition.getSd() == null ? null : partition.getSd().getLocation();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

partition.getSd shouldn't be null

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acknowledge. Removed the null check.

Copilot AI left a comment

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.

@dengzhhu653

Copy link
Copy Markdown
Member

@DanielZhu58 The 2 failures sound related, could you fix them please?

cc @kuczoram @deniskuzZ can you take a look please if have cycles?

@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

5 participants