diff --git a/fe/fe-core/src/main/java/org/apache/doris/binlog/BinlogManager.java b/fe/fe-core/src/main/java/org/apache/doris/binlog/BinlogManager.java index 35588568511a3f..6d483a41314111 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/binlog/BinlogManager.java +++ b/fe/fe-core/src/main/java/org/apache/doris/binlog/BinlogManager.java @@ -25,6 +25,7 @@ import org.apache.doris.common.proc.BaseProcResult; import org.apache.doris.common.proc.ProcResult; import org.apache.doris.persist.AlterDatabasePropertyInfo; +import org.apache.doris.persist.AlterViewInfo; import org.apache.doris.persist.BarrierLog; import org.apache.doris.persist.BatchModifyPartitionsInfo; import org.apache.doris.persist.BinlogGcInfo; @@ -354,6 +355,18 @@ public void addColumnRename(TableRenameColumnInfo info, long commitSeq) { addBinlog(dbId, tableIds, commitSeq, timestamp, type, data, false, info); } + // add Modify view + public void addModifyViewDef(AlterViewInfo alterViewInfo, long commitSeq) { + long dbId = alterViewInfo.getDbId(); + List tableIds = Lists.newArrayList(); + tableIds.add(alterViewInfo.getTableId()); + long timestamp = -1; + TBinlogType type = TBinlogType.MODIFY_VIEW_DEF; + String data = alterViewInfo.toJson(); + + addBinlog(dbId, tableIds, commitSeq, timestamp, type, data, false, alterViewInfo); + } + // get binlog by dbId, return first binlog.version > version public Pair getBinlog(long dbId, long tableId, long prevCommitSeq) { TStatus status = new TStatus(TStatusCode.OK); diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/AlterViewInfo.java b/fe/fe-core/src/main/java/org/apache/doris/persist/AlterViewInfo.java index df1fb5696c6b15..c54dfcf7c3100f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/persist/AlterViewInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/persist/AlterViewInfo.java @@ -105,4 +105,8 @@ public static AlterViewInfo read(DataInput in) throws IOException { String json = Text.readString(in); return GsonUtils.GSON.fromJson(json, AlterViewInfo.class); } + + public String toJson() { + return GsonUtils.GSON.toJson(this); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java b/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java index 83e7977a9838b8..e5983dc6781750 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/persist/EditLog.java @@ -312,6 +312,7 @@ public static void loadJournal(Env env, Long logId, JournalEntity journal) { case OperationType.OP_MODIFY_VIEW_DEF: { AlterViewInfo info = (AlterViewInfo) journal.getData(); env.getAlterInstance().replayModifyViewDef(info); + env.getBinlogManager().addModifyViewDef(info, logId); break; } case OperationType.OP_RENAME_PARTITION: { @@ -1576,7 +1577,11 @@ public void logTableRename(TableInfo tableInfo) { } public void logModifyViewDef(AlterViewInfo alterViewInfo) { - logEdit(OperationType.OP_MODIFY_VIEW_DEF, alterViewInfo); + long logId = logEdit(OperationType.OP_MODIFY_VIEW_DEF, alterViewInfo); + if (LOG.isDebugEnabled()) { + LOG.debug("log modify view, logId : {}, infos: {}", logId, alterViewInfo); + } + Env.getCurrentEnv().getBinlogManager().addModifyViewDef(alterViewInfo, logId); } public void logRollupRename(TableInfo tableInfo) { diff --git a/gensrc/thrift/FrontendService.thrift b/gensrc/thrift/FrontendService.thrift index 47e2bee6c7267c..4f36c9ccc0949a 100644 --- a/gensrc/thrift/FrontendService.thrift +++ b/gensrc/thrift/FrontendService.thrift @@ -1190,6 +1190,7 @@ enum TBinlogType { RENAME_TABLE = 14, RENAME_COLUMN = 15, MODIFY_COMMENT = 16, + MODIFY_VIEW_DEF = 17, // Keep some IDs for allocation so that when new binlog types are added in the // future, the changes can be picked back to the old versions without breaking @@ -1206,8 +1207,7 @@ enum TBinlogType { // MODIFY_XXX = 17, // MIN_UNKNOWN = 18, // UNKNOWN_3 = 19, - MIN_UNKNOWN = 17, - UNKNOWN_2 = 18, + MIN_UNKNOWN = 18, UNKNOWN_3 = 19, UNKNOWN_4 = 20, UNKNOWN_5 = 21,