Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ private boolean rollback(long taskId) {
* @param table Run the table for insert overwrite
*/
public void recordRunningTableOrException(DatabaseIf db, TableIf table) {
// The logic of OlapTable executing insert overwrite is to create temporary partitions,
// replace partitions, etc.
// If executed in parallel, it may cause problems such as not being able to find temporary partitions.
// But in terms of external table, we don't care the internal logic of execution,
// so there's no need to keep records
if (!(table instanceof OlapTable)) {
return;
}
long dbId = db.getId();
long tableId = table.getId();
runningLock.writeLock().lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,27 @@
package org.apache.doris.insertoverwrite;

import org.apache.doris.catalog.DatabaseIf;
import org.apache.doris.catalog.TableIf;
import org.apache.doris.catalog.OlapTable;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.MetaNotFoundException;
import org.apache.doris.datasource.hive.HMSExternalTable;

import mockit.Expectations;
import mockit.Mocked;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;

public class InsertOverwriteManagerTest {
@Mocked
private DatabaseIf db;

@Mocked
private TableIf table;
private OlapTable table;

@Mocked
private HMSExternalTable hmsExternalTable;

@Before
public void setUp()
Expand All @@ -57,6 +61,14 @@ public void setUp()
table.getName();
minTimes = 0;
result = "table1";

hmsExternalTable.getId();
minTimes = 0;
result = 3L;

hmsExternalTable.getName();
minTimes = 0;
result = "hmsTable";
}
};
}
Expand All @@ -65,13 +77,17 @@ public void setUp()
public void testParallel() {
InsertOverwriteManager manager = new InsertOverwriteManager();
manager.recordRunningTableOrException(db, table);
try {
manager.recordRunningTableOrException(db, table);
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("Not allowed"));
}
Assertions.assertThrows(org.apache.doris.nereids.exceptions.AnalysisException.class,
() -> manager.recordRunningTableOrException(db, table));
manager.dropRunningRecord(db.getId(), table.getId());
manager.recordRunningTableOrException(db, table);
Assertions.assertDoesNotThrow(() -> manager.recordRunningTableOrException(db, table));
}

@Test
public void testHmsTableParallel() {
InsertOverwriteManager manager = new InsertOverwriteManager();
manager.recordRunningTableOrException(db, hmsExternalTable);
Assertions.assertDoesNotThrow(() -> manager.recordRunningTableOrException(db, hmsExternalTable));
manager.dropRunningRecord(db.getId(), hmsExternalTable.getId());
}
}