Skip to content

Commit

Permalink
[fix](meta) fix meta replay issue when upgrading from v2.0 to master (a…
Browse files Browse the repository at this point in the history
…pache#28532)

Introduced from apache#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.
  • Loading branch information
morningman authored Dec 17, 2023
1 parent 9b3d4bb commit b06f3ed
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ public Database getDbNullable(String dbName) {
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 {
Expand Down Expand Up @@ -1261,7 +1263,6 @@ public void createTableAsSelect(CreateTableAsSelectStmt stmt) throws DdlExceptio
}

public void replayCreateTable(String dbName, Table table) throws MetaNotFoundException {

Database db = this.fullNameToDb.get(dbName);
try {
db.createTableWithLock(table, true, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ public void readFields(DataInput in) throws IOException {
break;
}
case OperationType.OP_CREATE_TABLE: {
data = new CreateTableInfo();
((CreateTableInfo) data).readFields(in);
data = CreateTableInfo.read(in);
isRead = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,7 +30,7 @@
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;

Expand All @@ -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;
Expand Down Expand Up @@ -74,4 +70,9 @@ public static AlterDatabasePropertyInfo read(DataInput in) throws IOException {
public String toJson() {
return GsonUtils.GSON.toJson(this);
}

@Override
public void gsonPostProcess() throws IOException {
dbName = ClusterNamespace.getNameFromFullName(dbName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +33,7 @@
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")
Expand Down Expand Up @@ -61,17 +63,17 @@ public void write(DataOutput out) throws IOException {
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);
Expand Down Expand Up @@ -99,4 +101,9 @@ public String toJson() {
public String toString() {
return toJson();
}

@Override
public void gsonPostProcess() throws IOException {
dbName = ClusterNamespace.getNameFromFullName(dbName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b06f3ed

Please sign in to comment.