Skip to content

Commit

Permalink
[Enhancement] Log the content of journal entity on replay failure (#4…
Browse files Browse the repository at this point in the history
…6011)

Signed-off-by: Dejun Xia <[email protected]>
(cherry picked from commit 759125c)

# Conflicts:
#	fe/fe-core/src/main/java/com/starrocks/persist/metablock/SRMetaBlockReader.java
#	fe/fe-core/src/main/java/com/starrocks/server/GlobalStateMgr.java
#	fe/fe-core/src/main/java/com/starrocks/server/LocalMetastore.java
  • Loading branch information
nshangyiming authored and mergify[bot] committed May 21, 2024
1 parent 9793e83 commit 62e6d34
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ public void close() throws IOException, SRMetaBlockException {
// normally it's because this FE has just rollbacked from a higher version that would produce more metadata
int rest = header.getNumJson() - numJsonReaded;
LOG.warn("Meta block for {} read {} json < total {} json, will skip the rest {} json",
<<<<<<< HEAD
header.getName(), numJsonReaded, header.getNumJson(), rest);
for (int i = 0; i != rest; ++ i) {
LOG.warn("skip {} json: {}", i, Text.readStringWithChecksum(checkedInputStream));
=======
header.getSrMetaBlockID(), numJsonRead, header.getNumJson(), rest);
for (int i = 0; i != rest; ++i) {
LOG.warn("skip {}th json: {}", i, Text.readStringWithChecksum(checkedInputStream));
>>>>>>> 759125c841 ([Enhancement] Log the content of journal entity on replay failure (#46011))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@
import com.starrocks.common.Pair;
import com.starrocks.common.ThreadPoolManager;
import com.starrocks.common.UserException;
<<<<<<< HEAD
=======
import com.starrocks.common.io.Text;
>>>>>>> 759125c841 ([Enhancement] Log the content of journal entity on replay failure (#46011))
import com.starrocks.common.io.Writable;
import com.starrocks.common.util.Daemon;
import com.starrocks.common.util.LeaderDaemon;
Expand Down Expand Up @@ -1976,18 +1980,25 @@ protected boolean replayJournalInner(JournalCursor cursor, boolean flowControl)
// apply
EditLog.loadJournal(this, entity);
} catch (Throwable e) {
<<<<<<< HEAD
if (canSkipBadReplayedJournal()) {
LOG.error("!!! DANGER: SKIP JOURNAL {}: {} !!!",
replayedJournalId.incrementAndGet(),
entity == null ? null : entity.getData(),
e);
=======
if (canSkipBadReplayedJournal(e)) {
LOG.error("!!! DANGER: SKIP JOURNAL, id: {}, data: {} !!!",
replayedJournalId.incrementAndGet(), journalEntityToReadableString(entity), e);
>>>>>>> 759125c841 ([Enhancement] Log the content of journal entity on replay failure (#46011))
if (!readSucc) {
cursor.skipNext();
}
continue;
}
// handled in outer loop
LOG.warn("catch exception when replaying {},", replayedJournalId.get() + 1, e);
LOG.warn("catch exception when replaying journal, id: {}, data: {},",
replayedJournalId.get() + 1, journalEntityToReadableString(entity), e);
throw e;
}

Expand Down Expand Up @@ -2025,7 +2036,29 @@ protected boolean replayJournalInner(JournalCursor cursor, boolean flowControl)
return false;
}

<<<<<<< HEAD
private boolean canSkipBadReplayedJournal() {
=======
private String journalEntityToReadableString(JournalEntity entity) {
if (entity == null) {
return "null";
}
Writable data = entity.getData();
try {
return GsonUtils.GSON.toJson(data);
} catch (Exception e) {
// In older version, data may not be json, here we just return the class name.
return data.getClass().getName();
}
}

protected boolean canSkipBadReplayedJournal(Throwable t) {
if (Config.metadata_enable_recovery_mode) {
LOG.warn("skip journal load failure because cluster is in recovery mode");
return true;
}

>>>>>>> 759125c841 ([Enhancement] Log the content of journal entity on replay failure (#46011))
try {
for (String idStr : Config.metadata_journal_skip_bad_journal_ids.split(",")) {
if (!StringUtils.isEmpty(idStr) && Long.valueOf(idStr) == replayedJournalId.get() + 1) {
Expand Down
22 changes: 22 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/server/LocalMetastore.java
Original file line number Diff line number Diff line change
Expand Up @@ -2455,11 +2455,33 @@ private void createOlapOrLakeTable(Database db, CreateTableStmt stmt) throws Ddl
}
}

<<<<<<< HEAD
private void processConstraint(
Database db, OlapTable olapTable, Map<String, String> properties) throws AnalysisException {
List<UniqueConstraint> uniqueConstraints = PropertyAnalyzer.analyzeUniqueConstraint(properties, db, olapTable);
if (uniqueConstraints != null) {
olapTable.setUniqueConstraints(uniqueConstraints);
=======
public void replayCreateTable(CreateTableInfo info) {
Table table = info.getTable();
Database db = this.fullNameToDb.get(info.getDbName());
Locker locker = new Locker();
locker.lockDatabase(db, LockType.WRITE);
try {
db.registerTableUnlocked(table);
if (table.isTemporaryTable()) {
TemporaryTableMgr temporaryTableMgr = GlobalStateMgr.getCurrentState().getTemporaryTableMgr();
UUID sessionId = ((OlapTable) table).getSessionId();
temporaryTableMgr.addTemporaryTable(sessionId, db.getId(), table.getName(), table.getId());
}
table.onReload();
} catch (Throwable e) {
LOG.error("replay create table failed: {}", table, e);
// Rethrow, we should not eat the exception when replaying editlog.
throw e;
} finally {
locker.unLockDatabase(db, LockType.WRITE);
>>>>>>> 759125c841 ([Enhancement] Log the content of journal entity on replay failure (#46011))
}

List<ForeignKeyConstraint> foreignKeyConstraints =
Expand Down

0 comments on commit 62e6d34

Please sign in to comment.