Skip to content

HIVE-29436: Iceberg materialized view rebuild locking issue#6330

Draft
kasakrisz wants to merge 3 commits intoapache:masterfrom
kasakrisz:HIVE-29436-master-iceberg-mv-lock
Draft

HIVE-29436: Iceberg materialized view rebuild locking issue#6330
kasakrisz wants to merge 3 commits intoapache:masterfrom
kasakrisz:HIVE-29436-master-iceberg-mv-lock

Conversation

@kasakrisz
Copy link
Contributor

@kasakrisz kasakrisz commented Feb 20, 2026

What changes were proposed in this pull request?

Do not acquire a rebuild lock for materialized views stored by Iceberg because we rely on Iceberg's concurrency management.

Why are the changes needed?

Subsequent materialized view rebuilds may fail. See jira for details: https://issues.apache.org/jira/browse/HIVE-29436

Does this PR introduce any user-facing change?

No.

How was this patch tested?

mvn test -Dtest.output.overwrite -Dtest=TestIcebergCliDriver.java -Dqfile=mv_iceberg_orc2.q -pl itests/qtest-iceberg -Pitests

@kasakrisz kasakrisz marked this pull request as draft February 20, 2026 15:31
@kasakrisz kasakrisz requested a review from deniskuzZ March 5, 2026 13:44
@kasakrisz kasakrisz marked this pull request as ready for review March 5, 2026 13:44
alter materialized view mat1 rebuild;

alter materialized view mat1 rebuild;
alter materialized view mat2 rebuild;

Choose a reason for hiding this comment

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

In this test we are checking if rebuild for different materialized views succeeds. Can we also test if rebuilds of the same MV also works both in a serialized way within a session and in a concurrent sessions scenario ?


if (!this.ctx.isExplainPlan() && (AcidUtils.isTransactionalTable(table) ||
table.isNonNative() && table.getStorageHandler().areSnapshotsSupported())) {
if (!this.ctx.isExplainPlan() && (AcidUtils.isTransactionalTable(table))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

When the materialized view is stored in Hive ACID with source table as an iceberg, it would still fail. Mentioned in https://issues.apache.org/jira/browse/HIVE-29496. Can close it as duplicate once that is fixed too.

@kasakrisz kasakrisz force-pushed the HIVE-29436-master-iceberg-mv-lock branch from fea89fb to 8a458be Compare March 13, 2026 13:32
@kasakrisz kasakrisz marked this pull request as draft March 13, 2026 13:32
@sonarqubecloud
Copy link

rewrittenAST = ParseUtils.parse(rewrittenInsertStatement, ctx);
this.ctx.addSubContext(ctx);

if (!this.ctx.isExplainPlan() && (AcidUtils.isTransactionalTable(table) ||
Copy link
Member

Choose a reason for hiding this comment

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

is it safe to drop? it covers not only iceberg tables

HiveTxnManager txnManager = getTxnMgr();
LockState state;
try {
state = txnManager.acquireMaterializationRebuildLock(
Copy link
Member

Choose a reason for hiding this comment

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

in case it's not needed, why not drop the API as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found that there is a TxnType.MATER_VIEW_REBUILD so which I guess could be used instead of the acquireMaterializationRebuildLock functionality. I would like to add a test to confirm that it is safe to drop the latter.

The test should run two rebuilds parallel targeting the same MV:

-- Session #1
start transaction
alter materialized view mat1 rebuild;

-- Session #2
start transaction
alter materialized view mat1 rebuild;
commit;

-- Session #1
commit; -- this commit should fail or rollback

Do you know if there are any tests for running DDLs on the same table ?

Copy link
Member

@deniskuzZ deniskuzZ Mar 18, 2026

Choose a reason for hiding this comment

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

DDL is not supported inside transaction block, only DML. Note, I haven't tested this, it might work, but i doubt that.

please check the HiveIcebergOutputCommitter

Transaction txn = IcebergAcidUtil.getOrCreateTransaction(table, jobConf)

something similar probably would be needed in HiveIcebergMetaHook.

Maybe you could use EXCL_WRITE lock instead to serialize the MV rebuilds

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I miss typed it. I meant DML.
I would like to test both ACID and Iceberg tables/MV but it is hard to create 2 sessions from test. It is not possible with q test. I'm trying to use MiniHS2 via jdbc but it seems that even if I start a transaction the insert into an ACID table statement commits the txn automatically

      statement.execute("start transaction");
      statement.execute("insert into t1 values (0, 1), (2, 20)");
      statement.execute("commit");

throws:

org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: LockException [Error 20008]: Operation COMMIT is not allowed without an active

Copy link
Member

@deniskuzZ deniskuzZ Mar 18, 2026

Choose a reason for hiding this comment

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

check the iceberg_multi_table_txn.q or TestConcurrentMultiTableTransactions

Note, start transaction is under the feature flag ATM, you need to set "hive.in.test"=true

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