ayushtkn commented on code in PR #6991:
URL: https://github.com/apache/hive/pull/6991#discussion_r4773538316
##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java:
##########
@@ -1405,6 +1407,74 @@ public void testDatabaseLocationOnDrop() throws
Throwable {
}
}
+ /**
+ * HIVE-30284: DROP DATABASE CASCADE must delete the managed dir even when
+ * table count exceeds {@link ConfVars#BATCH_RETRIEVE_MAX} (i.e. the
+ * dropDatabaseCascadePerTable path). Uses txnId=0 + softDelete=false to
+ * match what Hive.dropDatabase sends on a non-ACID session.
+ */
+ @Test
+ public void testDropDatabaseCascadeDeletesManagedDirForLargeDb() throws
Throwable {
+ silentDropDatabase(TEST_DB1_NAME);
+
+ String dbLocation =
+ MetastoreConf.getVar(conf, ConfVars.WAREHOUSE_EXTERNAL) +
"/testdb_cascade.db";
+ String mgdLocation =
+ MetastoreConf.getVar(conf, ConfVars.WAREHOUSE) + "/testdb_cascade.db";
+ new DatabaseBuilder()
+ .setName(TEST_DB1_NAME)
+ .setLocation(dbLocation)
+ .setManagedLocation(mgdLocation)
+ .create(client, conf);
+
+ // Use the URI the server assigned so transformers / auth rewrites are
honoured.
+ Path mgdPath = new
Path(client.getDatabase(TEST_DB1_NAME).getManagedLocationUri());
+
+ // setUp() sets BATCH_RETRIEVE_MAX=2, so 3 tables forces
dropDatabaseCascadePerTable.
+ int numTables = (int) MetastoreConf.getLongVar(conf,
ConfVars.BATCH_RETRIEVE_MAX) + 1;
+ for (int i = 0; i < numTables; i++) {
+ new TableBuilder()
+ .setDbName(TEST_DB1_NAME)
+ .setTableName("t_" + i)
+ .addCol("id", ColumnType.INT_TYPE_NAME)
+ .create(client, conf);
+ }
+
+ FileSystem mgdFs = FileSystem.get(mgdPath.toUri(), conf);
+ org.junit.Assume.assumeTrue(
+ "Managed dir not materialized in this harness", mgdFs.exists(mgdPath));
+
+ // Mirror Hive.dropDatabase: txnId=0 still flips the thrift isSet bit,
which is the trigger.
+ DropDatabaseRequest req = new DropDatabaseRequest();
+ req.setCatalogName(MetaStoreUtils.getDefaultCatalog(conf));
+ req.setName(TEST_DB1_NAME);
+ req.setIgnoreUnknownDb(false);
+ req.setDeleteData(true);
+ req.setCascade(true);
+ req.setSoftDelete(false);
+ req.setTxnId(0L);
Review Comment:
After the `Hive.java` fix, `Hive.dropDatabase` never calls `setTxnId` when
`txnId == 0`, so `isSetTxnId()` is `false` in production and the ``if
(req.isSetTxnId())`` block in `HookEnabledMetaStoreClient` is skipped entirely.
This test forces that block to run by calling `setTxnId(0L)`, so it only
exercises the `isSoftDelete()` guard — a secondary defence. That's valuable,
but a few gaps remain:
1. A `ql`-level test for `Hive.dropDatabase` is the only way to guard the
primary fix. Open a session with no txn (or a mocked txn manager returning 0),
capture the `DropDatabaseRequest` passed to the `MSC`, and `assert
!req.isSetTxnId()`. A variant with `txnId > 0` should `assert isSetTxnId() ==
true`. This is the test that breaks if the `Hive.java` guard is reverted. (A
variant here without `setTxnId(0L)` would pass with or without either fix,
since it bypasses `Hive.java` entirely.)
2. Keep this test as-is — it covers the `isSoftDelete()` guard.
3. Consider a soft-delete variant: `setSoftDelete(true)` + `setTxnId(n >
0)`, asserting the managed dir is deliberately left alone. Without it, nothing
locks in the intended `deleteManagedDir=false`cbehaviour.
4. Consider a `txnId > 0` + `softDelete=false `variant: verifies that a real
`ACID` non-soft-delete drop still removes the managed dir. No test covers this
path today.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]