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

[Bug] Insert from empty source will begin an infinite transaction #38956

Closed
2 of 3 tasks
TangSiyang2001 opened this issue Aug 6, 2024 · 1 comment · Fixed by #38991
Closed
2 of 3 tasks

[Bug] Insert from empty source will begin an infinite transaction #38956

TangSiyang2001 opened this issue Aug 6, 2024 · 1 comment · Fixed by #38991
Assignees

Comments

@TangSiyang2001
Copy link
Collaborator

TangSiyang2001 commented Aug 6, 2024

Search before asking

  • I had searched in the issues and found no similar issues.

Version

master

What's Wrong?

As title.
InsertIntoTableCommand#runInternal

private void runInternal(ConnectContext ctx, StmtExecutor executor) throws Exception {
        AbstractInsertExecutor insertExecutor = initPlan(ctx, executor);
        // if the insert stmt data source is empty, directly return, no need to be executed.
        if (insertExecutor.isEmptyInsert()) {
            return;
        }
        insertExecutor.executeSingleInsert(executor, jobId);
}

Here insert command will not be actually started when empty relation, so callback of txn commit and publish will never be called, resulting in an infinite transaction which will only finish when timeout reached.

InsertIntoTableCommand#initPlan (transaction begins here)

public AbstractInsertExecutor initPlan(ConnectContext ctx, StmtExecutor executor) throws Exception {
        // ...
        try {
           // ...
            insertExecutor.beginTransaction();
            insertExecutor.finalizeSink(planner.getFragments().get(0), sink, physicalSink);
            targetTableIf.readUnlock();
        } catch (Throwable e) {
            targetTableIf.readUnlock();
            // the abortTxn in onFail need to acquire table write lock
            if (insertExecutor != null) {
                insertExecutor.onFail(e);
            }
            throw e;
        }

        executor.setProfileType(ProfileType.LOAD);
        // We exposed @StmtExecutor#cancel as a unified entry point for statement interruption,
        // so we need to set this here
        executor.setCoord(insertExecutor.getCoordinator());
        return insertExecutor;
    }

What You Expected?

Empty source optimization should commit and publish transaction.

How to Reproduce?

Just create an empty table, insert data from itself.

Anything Else?

introduced by #34418

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@TangSiyang2001
Copy link
Collaborator Author

Maybe just do not begin a transaction for empty insert is better.

dataroaring pushed a commit that referenced this issue Aug 7, 2024
…void infinite transaction (#38991)

## Proposed changes

Issue Number: close #38956 

As title.
TangSiyang2001 added a commit to TangSiyang2001/doris that referenced this issue Aug 8, 2024
…void infinite transaction (apache#38991)

## Proposed changes

Issue Number: close apache#38956 

As title.
dataroaring pushed a commit that referenced this issue Aug 8, 2024
…void infinite transaction (#38991) (#39108)

## Proposed changes

Issue Number: close #38956 

As title.
wyxxxcat pushed a commit to wyxxxcat/doris that referenced this issue Aug 14, 2024
…void infinite transaction (apache#38991)

## Proposed changes

Issue Number: close apache#38956 

As title.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant