[fix](meta) fix meta replay issue when upgrading from v2.0 to master (#28532)

Introduced from #27861

The `dbName` saved in `CreateTableInfo` has `default_cluster` prefix, it should be removed.

Also modify the entry of `getDb` in internal catalog. This is a cover-up plan in case there may still 
db name exist with `default_cluster` prefix.
This commit is contained in:
Mingyu Chen
2023-12-17 22:16:42 +08:00
committed by GitHub
parent 9b3d4bb5bc
commit b06f3edcab
5 changed files with 25 additions and 17 deletions

View File

@ -254,6 +254,8 @@ public class InternalCatalog implements CatalogIf<Database> {
if (StringUtils.isEmpty(dbName)) {
return null;
}
// ATTN: this should be removed in v3.0
dbName = ClusterNamespace.getNameFromFullName(dbName);
if (fullNameToDb.containsKey(dbName)) {
return fullNameToDb.get(dbName);
} else {
@ -1261,7 +1263,6 @@ public class InternalCatalog implements CatalogIf<Database> {
}
public void replayCreateTable(String dbName, Table table) throws MetaNotFoundException {
Database db = this.fullNameToDb.get(dbName);
try {
db.createTableWithLock(table, true, false);

View File

@ -217,8 +217,7 @@ public class JournalEntity implements Writable {
break;
}
case OperationType.OP_CREATE_TABLE: {
data = new CreateTableInfo();
((CreateTableInfo) data).readFields(in);
data = CreateTableInfo.read(in);
isRead = true;
break;
}

View File

@ -17,8 +17,10 @@
package org.apache.doris.persist;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.persist.gson.GsonPostProcessable;
import org.apache.doris.persist.gson.GsonUtils;
import com.google.gson.annotations.SerializedName;
@ -28,7 +30,7 @@ import java.io.DataOutput;
import java.io.IOException;
import java.util.Map;
public class AlterDatabasePropertyInfo implements Writable {
public class AlterDatabasePropertyInfo implements Writable, GsonPostProcessable {
@SerializedName(value = "dbId")
private long dbId;
@ -38,12 +40,6 @@ public class AlterDatabasePropertyInfo implements Writable {
@SerializedName(value = "properties")
private Map<String, String> properties;
public AlterDatabasePropertyInfo() {
// for persist
this.dbName = "";
this.properties = null;
}
public AlterDatabasePropertyInfo(long dbId, String dbName, Map<String, String> properties) {
this.dbId = dbId;
this.dbName = dbName;
@ -74,4 +70,9 @@ public class AlterDatabasePropertyInfo implements Writable {
public String toJson() {
return GsonUtils.GSON.toJson(this);
}
@Override
public void gsonPostProcess() throws IOException {
dbName = ClusterNamespace.getNameFromFullName(dbName);
}
}

View File

@ -18,8 +18,10 @@
package org.apache.doris.persist;
import org.apache.doris.catalog.Table;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.io.Text;
import org.apache.doris.common.io.Writable;
import org.apache.doris.persist.gson.GsonPostProcessable;
import org.apache.doris.persist.gson.GsonUtils;
import com.google.gson.annotations.SerializedName;
@ -31,7 +33,7 @@ import java.io.DataOutput;
import java.io.IOException;
import java.util.Objects;
public class CreateTableInfo implements Writable {
public class CreateTableInfo implements Writable, GsonPostProcessable {
public static final Logger LOG = LoggerFactory.getLogger(CreateTableInfo.class);
@SerializedName(value = "dbName")
@ -61,17 +63,17 @@ public class CreateTableInfo implements Writable {
table.write(out);
}
public void readFields(DataInput in) throws IOException {
dbName = Text.readString(in);
table = Table.read(in);
}
public static CreateTableInfo read(DataInput in) throws IOException {
CreateTableInfo createTableInfo = new CreateTableInfo();
createTableInfo.readFields(in);
return createTableInfo;
}
private void readFields(DataInput in) throws IOException {
dbName = ClusterNamespace.getNameFromFullName(Text.readString(in));
table = Table.read(in);
}
@Override
public int hashCode() {
return Objects.hash(dbName, table);
@ -99,4 +101,9 @@ public class CreateTableInfo implements Writable {
public String toString() {
return toJson();
}
@Override
public void gsonPostProcess() throws IOException {
dbName = ClusterNamespace.getNameFromFullName(dbName);
}
}

View File

@ -43,7 +43,7 @@ public class PersistMetaModules {
// Modules in this list is deprecated and will not be saved in meta file. (also should not be in MODULE_NAMES)
public static final ImmutableList<String> DEPRECATED_MODULE_NAMES = ImmutableList.of(
"loadJob", "cooldownJob", "AnalysisMgr", "mtmvJobManager");
"loadJob", "cooldownJob", "AnalysisMgr", "mtmvJobManager", "JobTaskManager");
static {
MODULES_MAP = Maps.newHashMap();