Skip to content

Commit

Permalink
[BugFix] Fix the issue where FE restart fails when creating a table c…
Browse files Browse the repository at this point in the history
…ontaining too many tablets (backport #53062) (#53353)

Signed-off-by: gengjun-git <[email protected]>
Co-authored-by: gengjun-git <[email protected]>
  • Loading branch information
mergify[bot] and gengjun-git authored Dec 2, 2024
1 parent bcbdec7 commit 3565f36
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 3 deletions.
9 changes: 9 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/catalog/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,15 @@ public boolean registerTableUnlocked(Table table) {
}
}

public void unRegisterTableUnlocked(Table table) {
if (table == null) {
return;
}

idToTable.remove(table.getId());
nameToTable.remove(table.getName());
}

public void dropTable(String tableName, boolean isSetIfExists, boolean isForce) throws DdlException {
Table table;
writeLock();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.starrocks.journal;

public class SerializeException extends RuntimeException {
public SerializeException(String message) {
super(message);
}
}
7 changes: 5 additions & 2 deletions fe/fe-core/src/main/java/com/starrocks/persist/EditLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.gson.JsonParseException;
import com.starrocks.alter.AlterJobV2;
import com.starrocks.alter.BatchAlterJobPersistInfo;
import com.starrocks.authentication.UserAuthenticationInfo;
Expand Down Expand Up @@ -64,6 +65,7 @@
import com.starrocks.journal.JournalEntity;
import com.starrocks.journal.JournalInconsistentException;
import com.starrocks.journal.JournalTask;
import com.starrocks.journal.SerializeException;
import com.starrocks.journal.bdbje.Timestamp;
import com.starrocks.load.DeleteInfo;
import com.starrocks.load.DeleteMgr;
Expand Down Expand Up @@ -1264,9 +1266,10 @@ private JournalTask submitLog(short op, Writable writable, long maxWaitIntervalM
entity.setOpCode(op);
entity.setData(writable);
entity.write(buffer);
} catch (IOException e) {
} catch (IOException | JsonParseException e) {
// The old implementation swallow exception like this
LOG.info("failed to serialize, ", e);
LOG.info("failed to serialize journal data", e);
throw new SerializeException("failed to serialize journal data");
}
JournalTask task = new JournalTask(startTimeNano, buffer, maxWaitIntervalMs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
import com.starrocks.common.util.concurrent.CountingLatch;
import com.starrocks.connector.ConnectorMetadata;
import com.starrocks.connector.exception.StarRocksConnectorException;
import com.starrocks.journal.SerializeException;
import com.starrocks.lake.DataCacheInfo;
import com.starrocks.lake.LakeMaterializedView;
import com.starrocks.lake.LakeTable;
Expand Down Expand Up @@ -2330,6 +2331,10 @@ void onCreate(Database db, Table table, String storageVolumeId, boolean isSetIfN
CreateTableInfo createTableInfo = new CreateTableInfo(db.getFullName(), table, storageVolumeId);
GlobalStateMgr.getCurrentState().getEditLog().logCreateTable(createTableInfo);
table.onCreate(db);
} catch (SerializeException e) {
db.unRegisterTableUnlocked(table);
LOG.warn("create table failed", e);
ErrorReport.reportDdlException(ErrorCode.ERR_CANT_CREATE_TABLE, table.getName(), e.getMessage());
} finally {
db.writeUnlock();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static void beforeClass() throws Exception {
Config.alter_scheduler_interval_millisecond = 1000;
FeConstants.runningUnitTest = true;

UtFrameUtils.createMinStarRocksCluster();
UtFrameUtils.createMinStarRocksCluster(true, RunMode.SHARED_NOTHING);

// create connect context
connectContext = UtFrameUtils.createDefaultCtx();
Expand Down Expand Up @@ -255,4 +255,18 @@ public void testAlterTableProperties() throws Exception {
Assert.assertEquals("Cannot parse text to Duration", e.getMessage());
}
}

@Test
public void testCreateTableSerializeException() {
final long tableId = 1000010L;
final String tableName = "test";
Database db = connectContext.getGlobalStateMgr().getLocalMetastore().getDb("test");
LocalMetastore localMetastore = connectContext.getGlobalStateMgr().getLocalMetastore();
SerializeFailedTable table = new SerializeFailedTable(1000010L, "serialize_test");

Assert.assertThrows(DdlException.class, () -> localMetastore.onCreate(db, table, "", true));

Assert.assertNull(db.getTable(tableId));
Assert.assertNull(db.getTable(tableName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2021-present StarRocks, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package com.starrocks.server;

import com.starrocks.catalog.Table;
import com.starrocks.persist.gson.GsonPreProcessable;

import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;

public class SerializeFailedTable extends Table implements GsonPreProcessable {

public SerializeFailedTable(long id, String name) {
super(id, name, TableType.OLAP, new ArrayList<>());
}

@Override
public void write(DataOutput out) throws IOException {
throw new IOException("failed");
}

@Override
public void gsonPreProcess() throws IOException {
throw new IOException("failed");
}
}

0 comments on commit 3565f36

Please sign in to comment.