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

[BugFix] fix error parameters when replaying drop temp table #55056

Merged
merged 1 commit into from
Jan 23, 2025
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 @@ -2235,7 +2235,7 @@ public void replayDropTable(Database db, long tableId, boolean isForceDrop) {
try {
table = getTable(db.getId(), tableId);
if (table.isTemporaryTable()) {
table = db.unprotectDropTemporaryTable(tableId, isForceDrop, false);
table = db.unprotectDropTemporaryTable(tableId, isForceDrop, true);
UUID sessionId = ((OlapTable) table).getSessionId();
TemporaryTableMgr temporaryTableMgr = GlobalStateMgr.getCurrentState().getTemporaryTableMgr();
temporaryTableMgr.dropTemporaryTable(sessionId, db.getId(), table.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,31 @@

package com.starrocks.catalog;

import com.starrocks.analysis.TableName;
import com.starrocks.common.AnalysisException;
import com.starrocks.common.ExceptionChecker;
import com.starrocks.common.FeConstants;
import com.starrocks.ha.FrontendNodeType;
import com.starrocks.qe.ConnectContext;
import com.starrocks.qe.ShowResultSet;
import com.starrocks.server.GlobalStateMgr;
import com.starrocks.server.LocalMetastore;
import com.starrocks.sql.analyzer.SemanticException;
import com.starrocks.sql.ast.ShowCreateTableStmt;
import com.starrocks.sql.common.MetaUtils;
import com.starrocks.utframe.StarRocksAssert;
import com.starrocks.utframe.UtFrameUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestMethodOrder;

import java.util.List;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class TemporaryTableTest {
private static ConnectContext connectContext;
private static StarRocksAssert starRocksAssert;
Expand All @@ -58,6 +66,7 @@ private String getShowCreateTableResult(String table, ConnectContext ctx) throws
}

@Test
@Order(1)
public void testCreateTemporaryTable() throws Exception {
starRocksAssert.withTemporaryTable("create temporary table t0(" +
"c1 int, c2 int) engine=olap " +
Expand Down Expand Up @@ -103,6 +112,7 @@ public void testCreateTemporaryTable() throws Exception {
}

@Test
@Order(1)
public void testCreateTemporaryTableLike() throws Exception {
starRocksAssert.withTable("create table t (c1 int, c2 int) " +
"engine=olap duplicate key(`c1`) distributed by hash(`c1`) buckets 3 " +
Expand Down Expand Up @@ -148,6 +158,7 @@ public void testCreateTemporaryTableLike() throws Exception {
}

@Test
@Order(1)
public void testCreateTemporaryTableAbnormal() throws Exception {
// temporary table only support olap engine
ExceptionChecker.expectThrowsWithMsg(AnalysisException.class, "temporary table only support olap engine", () -> {
Expand Down Expand Up @@ -178,6 +189,7 @@ public void testCreateTemporaryTableAbnormal() throws Exception {
}

@Test
@Order(1)
public void testCreateView() throws Exception {
starRocksAssert.withTemporaryTable("create temporary table t1(c1 int,c2 int) " +
"engine=olap duplicate key(`c1`) distributed by hash(`c1`) " +
Expand All @@ -202,6 +214,7 @@ public void testCreateView() throws Exception {
}

@Test
@Order(1)
public void testAlterTable() throws Exception {
starRocksAssert.withTemporaryTable("create temporary table t1(c1 int,c2 int) " +
"engine=olap duplicate key(`c1`) distributed by hash(`c1`) " +
Expand All @@ -214,6 +227,7 @@ public void testAlterTable() throws Exception {
}

@Test
@Order(1)
public void testSubmitTask() throws Exception {
starRocksAssert.withTemporaryTable("create temporary table t1(c1 int,c2 int) " +
"engine=olap duplicate key(`c1`) distributed by hash(`c1`) " +
Expand All @@ -235,6 +249,7 @@ public void testSubmitTask() throws Exception {
}

@Test
@Order(1)
public void testNameConflict() throws Exception {
starRocksAssert.withTable("create table t1(c1 int,c2 int) " +
"engine=olap duplicate key(`c1`) distributed by hash(`c1`) " +
Expand Down Expand Up @@ -280,6 +295,7 @@ public void testNameConflict() throws Exception {
}

@Test
@Order(1)
public void testVisibility() throws Exception {
// 2 session, can't see each other
ConnectContext connectContext1 = UtFrameUtils.createDefaultCtx();
Expand All @@ -304,6 +320,7 @@ public void testVisibility() throws Exception {
}

@Test
@Order(1)
public void testAbnormalCases() throws Exception {
ConnectContext connectContext1 = UtFrameUtils.createDefaultCtx();
String createHiveCatalogStmt = "create external catalog hive_catalog properties (\"type\"=\"hive\", " +
Expand All @@ -325,6 +342,7 @@ public void testAbnormalCases() throws Exception {
}

@Test
@Order(1)
public void testDropTable() throws Exception {
starRocksAssert.withTemporaryTable("create temporary table t1(c1 int,c2 int, c3 int) " +
"engine=olap duplicate key(`c1`) distributed by hash(`c1`) " +
Expand All @@ -338,6 +356,7 @@ public void testDropTable() throws Exception {
}

@Test
@Order(1)
public void testShowData() throws Exception {
starRocksAssert.withTemporaryTable("create temporary table t1(c1 int,c2 int, c3 int) " +
"engine=olap duplicate key(`c1`) distributed by hash(`c1`) " +
Expand All @@ -347,4 +366,22 @@ public void testShowData() throws Exception {

}

@Test
@Order(2)
public void testReplayDropTable() throws Exception {
starRocksAssert.withDatabase("test").useDatabase("test").withTemporaryTable(
"create temporary table tmp(k1 int) duplicate key(k1) " +
"distributed by hash(k1) buckets 3 properties('replication_num'='1');");
LocalMetastore localMetastore = GlobalStateMgr.getCurrentState().getLocalMetastore();
Database database = starRocksAssert.getDb("test");
Assert.assertNotNull(database);
Table table = MetaUtils.getSessionAwareTable(connectContext, database, new TableName("test", "tmp"));
Assert.assertNotNull(table);
Assert.assertTrue(table.isOlapTable());
Assert.assertTrue(((OlapTable) table).isTemporaryTable());
// non-master node can replay drop temporary table successfully
GlobalStateMgr.getCurrentState().setFrontendNodeType(FrontendNodeType.FOLLOWER);
localMetastore.replayDropTable(database, table.getId(), false);
GlobalStateMgr.getCurrentState().setFrontendNodeType(FrontendNodeType.LEADER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -324,4 +324,5 @@ public void testCreateTableSerializeException() {
Assert.assertNull(db.getTable(tableId));
Assert.assertNull(db.getTable(tableName));
}

}
Loading