shubhluck commented on code in PR #6991:
URL: https://github.com/apache/hive/pull/6991#discussion_r4806286409
##########
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:
Thank you @ayushtkn for your valuable feedback on the given fix, I've
addressed all four:
**(1) ql-level test for `Hive.dropDatabase`** — added `TestHiveDropDatabase`
with a mocked `IMetaStoreClient` and `ArgumentCaptor<DropDatabaseRequest>`:
- `noOpenTxnDoesNotFlipIsSetTxnId` — default TxnMgr returns 0; asserts
`!req.isSetTxnId()`. This is the test that breaks if the `Hive.java` guard is
reverted.
- `realTxnIdIsForwarded` — mocked TxnMgr returning 1234; asserts
`isSetTxnId() && getTxnId() == 1234`.
- `locklessReadsSetsSoftDelete` — covers the lockless-reads branch.
**(2)** Kept the `setTxnId(0L)` test as a secondary defence on the
`HookEnabledMetaStoreClient` guard.
**(3) softDelete=true + txnId>0 preservation variant** — added
`testDropDatabaseCascadeKeepsManagedDirForSoftDeleteTables`. Tables are stamped
`transactional=true` + `transactional_properties=insert_only` +
`soft_delete=true` so the server's `TxnUtils.isTableSoftDeleteEnabled` returns
true and honours `deleteManagedDir=false`. Asserts the managed dir survives the
cascade.
**(4) txnId>0 + softDelete=false variant** — added
`testDropDatabaseCascadeDeletesManagedDirForLargeDb_acidNonSoftDelete`:
ordinary ACID (non-lockless-reads) drop still removes the managed dir
synchronously.
--
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]