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
9 changes: 5 additions & 4 deletions fe/src/main/java/org/apache/doris/catalog/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -2468,6 +2468,7 @@ public void dropDb(DropDbStmt stmt) throws DdlException {
public void unprotectDropDb(Database db) {
for (Table table : db.getTables()) {
unprotectDropTable(db, table.getId());
Catalog.getCurrentColocateIndex().removeTable(table.getId());
}
}

Expand Down Expand Up @@ -2533,7 +2534,7 @@ public void recoverDatabase(RecoverDbStmt recoverStmt) throws DdlException {

// log
RecoverInfo recoverInfo = new RecoverInfo(db.getId(), -1L, -1L);
Catalog.getInstance().getEditLog().logRecoverDb(recoverInfo);
editLog.logRecoverDb(recoverInfo);
} finally {
unlock();
}
Expand Down Expand Up @@ -3546,7 +3547,7 @@ private Table createOlapTable(Database db, CreateTableStmt stmt, boolean isResto
} else {
info = ColocatePersistInfo.CreateForAddTable(tableId, groupId, db.getId(), new ArrayList<>());
}
Catalog.getInstance().getEditLog().logColocateAddTable(info);
editLog.logColocateAddTable(info);
}

LOG.info("successfully create table[{};{}]", tableName, tableId);
Expand Down Expand Up @@ -4126,11 +4127,11 @@ public void dropTable(DropTableStmt stmt) throws DdlException {
unprotectDropTable(db, table.getId());

DropInfo info = new DropInfo(db.getId(), table.getId(), -1L);
Catalog.getInstance().getEditLog().logDropTable(info);
editLog.logDropTable(info);

if (Catalog.getCurrentColocateIndex().removeTable(table.getId())) {
ColocatePersistInfo colocateInfo = ColocatePersistInfo.CreateForRemoveTable(table.getId());
Catalog.getInstance().getEditLog().logColocateRemoveTable(colocateInfo);
editLog.logColocateRemoveTable(colocateInfo);
}
} finally {
db.writeUnlock();
Expand Down
74 changes: 64 additions & 10 deletions fe/src/test/java/org/apache/doris/catalog/ColocateTableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@
package org.apache.doris.catalog;

import com.google.common.collect.Lists;
import mockit.Deencapsulation;
import mockit.Expectations;
import mockit.Injectable;
import mockit.Mock;
import mockit.MockUp;
import org.apache.doris.analysis.Analyzer;
import org.apache.doris.analysis.ColumnDef;
import org.apache.doris.analysis.CreateDbStmt;
import org.apache.doris.analysis.CreateTableStmt;
import org.apache.doris.analysis.DropDbStmt;
import org.apache.doris.analysis.DropTableStmt;
import org.apache.doris.analysis.HashDistributionDesc;
import org.apache.doris.analysis.KeysDesc;
import org.apache.doris.analysis.TableName;
import org.apache.doris.analysis.TypeDef;
import org.apache.doris.cluster.Cluster;
import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.util.PropertyAnalyzer;
Expand All @@ -39,6 +43,7 @@
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.system.SystemInfoService;
import org.apache.doris.task.AgentBatchTask;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
Expand All @@ -48,13 +53,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class ColocateTableTest {
private TableName dbTableName1;
private TableName dbTableName2;
private TableName dbTableName3;
private String dbName = "default:testDb";
private String tableName1 = "t1";
private String tableName2 = "t2";
private String tableName3 = "t3";
Expand All @@ -65,7 +72,7 @@ public class ColocateTableTest {
private Map<String, String> properties = new HashMap<String, String>();

private Catalog catalog;
private Database db = new Database();
private Database db;
private Analyzer analyzer;

@Injectable
Expand All @@ -82,7 +89,6 @@ public class ColocateTableTest {

@Before
public void setUp() throws Exception {
String dbName = "testDb";
dbTableName1 = new TableName(dbName, tableName1);
dbTableName2 = new TableName(dbName, tableName2);
dbTableName3 = new TableName(dbName, tableName3);
Expand Down Expand Up @@ -117,11 +123,6 @@ public void setUp() throws Exception {

new Expectations(catalog) {
{
catalog.getDb(anyString);
result = db;
catalog.getDb(anyLong);
result = db;

Catalog.getCurrentSystemInfo();
result = systemInfoService;

Expand All @@ -134,13 +135,19 @@ public void setUp() throws Exception {
paloAuth.checkTblPriv((ConnectContext) any, anyString, anyString, PrivPredicate.CREATE);
result = true;
paloAuth.checkTblPriv((ConnectContext) any, anyString, anyString, PrivPredicate.DROP);
result = true;
result = true; minTimes = 0; maxTimes = 1;
}
};

catalog.getEditLog();
result = editLog;
new Expectations() {
{
Deencapsulation.setField(catalog, "editLog", editLog);
}
};

InitDataBase();
db = catalog.getDb(dbName);

new MockUp<AgentBatchTask>() {
@Mock
void run() {
Expand All @@ -156,6 +163,31 @@ boolean await(long timeout, TimeUnit unit) {
};
}

private void InitDataBase() throws Exception {
CreateDbStmt dbStmt = new CreateDbStmt(true, dbName);
new Expectations(dbStmt) {
{
dbStmt.getClusterName();
result = clusterName;
}
};

ConcurrentHashMap<String, Cluster> nameToCluster = new ConcurrentHashMap<>();
nameToCluster.put(clusterName, new Cluster(clusterName, 1));
new Expectations() {
{
Deencapsulation.setField(catalog, "nameToCluster", nameToCluster);
}
};

catalog.createDb(dbStmt);
}

@After
public void tearDown() throws Exception {
catalog.clear();
}

private void CreateParentTable(int numBecket, Map<String, String> properties) throws Exception {
properties.put(PropertyAnalyzer.PROPERTIES_COLOCATE_WITH, tableName1);

Expand Down Expand Up @@ -350,6 +382,28 @@ public void testCreateAndDropMultilevelColocateTable() throws Exception {
Assert.assertFalse(index.isSameGroup(childId, grandchildId));
}

@Test
public void testDropDbWithColocateTable() throws Exception {
int numBecket = 1;

CreateParentTable(numBecket, properties);

ColocateTableIndex index = Catalog.getCurrentColocateIndex();
long tableId = db.getTable(tableName1).getId();

Assert.assertEquals(1, index.getGroup2DB().size());
Assert.assertEquals(1, index.getAllGroupIds().size());

Long dbId = db.getId();
Assert.assertEquals(index.getDB(tableId), dbId);

DropDbStmt stmt = new DropDbStmt(false, dbName);
catalog.dropDb(stmt);

Assert.assertEquals(0, index.getGroup2DB().size());
Assert.assertEquals(0, index.getAllGroupIds().size());
}

@Test
public void testBucketNum() throws Exception {
int parentBecketNum = 1;
Expand Down