Skip to content

Commit

Permalink
[opt] (binlog) Support Modify ViewDef binlog #41167 (#44520)
Browse files Browse the repository at this point in the history
cherry pick from #41167

Co-authored-by: yanmingfu <[email protected]>
Co-authored-by: yanmingfu <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2024
1 parent f7dda9e commit e8d2918
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 30 deletions.
65 changes: 38 additions & 27 deletions fe/fe-core/src/main/java/org/apache/doris/binlog/BinlogManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -322,6 +323,43 @@ public void addTruncateTable(TruncateTableInfo info, long commitSeq) {
addBinlog(dbId, tableIds, commitSeq, timestamp, type, data, false, record);
}

public void addTableRename(TableInfo info, long commitSeq) {
long dbId = info.getDbId();
long tableId = info.getTableId();
TBinlogType type = TBinlogType.RENAME_TABLE;
String data = info.toJson();
BarrierLog log = new BarrierLog(dbId, tableId, type, data);
addBarrierLog(log, commitSeq);
}

public void addColumnRename(TableRenameColumnInfo info, long commitSeq) {
long dbId = info.getDbId();
long tableId = info.getTableId();
TBinlogType type = TBinlogType.RENAME_COLUMN;
String data = info.toJson();
BarrierLog log = new BarrierLog(dbId, tableId, type, data);
addBarrierLog(log, commitSeq);
}

public void addModifyComment(ModifyCommentOperationLog info, long commitSeq) {
long dbId = info.getDbId();
long tableId = info.getTblId();
TBinlogType type = TBinlogType.MODIFY_COMMENT;
String data = info.toJson();
BarrierLog log = new BarrierLog(dbId, tableId, type, data);
addBarrierLog(log, commitSeq);
}

// add Modify view
public void addModifyViewDef(AlterViewInfo alterViewInfo, long commitSeq) {
long dbId = alterViewInfo.getDbId();
long tableId = alterViewInfo.getTableId();
TBinlogType type = TBinlogType.MODIFY_VIEW_DEF;
String data = alterViewInfo.toJson();
BarrierLog log = new BarrierLog(dbId, tableId, type, data);
addBarrierLog(log, commitSeq);
}

// get binlog by dbId, return first binlog.version > version
public Pair<TStatus, TBinlog> getBinlog(long dbId, long tableId, long prevCommitSeq) {
TStatus status = new TStatus(TStatusCode.OK);
Expand Down Expand Up @@ -358,33 +396,6 @@ public Pair<TStatus, Long> getBinlogLag(long dbId, long tableId, long prevCommit
}
}

public void addTableRename(TableInfo info, long commitSeq) {
long dbId = info.getDbId();
long tableId = info.getTableId();
TBinlogType type = TBinlogType.RENAME_TABLE;
String data = info.toJson();
BarrierLog log = new BarrierLog(dbId, tableId, type, data);
addBarrierLog(log, commitSeq);
}

public void addColumnRename(TableRenameColumnInfo info, long commitSeq) {
long dbId = info.getDbId();
long tableId = info.getTableId();
TBinlogType type = TBinlogType.RENAME_COLUMN;
String data = info.toJson();
BarrierLog log = new BarrierLog(dbId, tableId, type, data);
addBarrierLog(log, commitSeq);
}

public void addModifyComment(ModifyCommentOperationLog info, long commitSeq) {
long dbId = info.getDbId();
long tableId = info.getTblId();
TBinlogType type = TBinlogType.MODIFY_COMMENT;
String data = info.toJson();
BarrierLog log = new BarrierLog(dbId, tableId, type, data);
addBarrierLog(log, commitSeq);
}

// get the dropped partitions of the db.
public List<Long> getDroppedPartitions(long dbId) {
lock.readLock().lock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,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: {
Expand Down Expand Up @@ -1444,7 +1445,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) {
Expand Down
4 changes: 2 additions & 2 deletions gensrc/thrift/FrontendService.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,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
Expand All @@ -1046,8 +1047,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,
Expand Down

0 comments on commit e8d2918

Please sign in to comment.