Skip to content

Commit b0e09ae

Browse files
morningmanclaude
andcommitted
[fix](fe) Print journal records kept without a payload in the BDBJE debug view
### What problem does this PR solve? Issue Number: None Related PR: #69575 Problem Summary: In BDBJE debug mode (enable_bdbje_debug_mode), SHOW PROC '/bdbje/<db>/<journalId>' renders a record through BdbjeJournalDataProcNode, which called getData().toString() without a null check. The readers of retired operation types consume the payload without keeping it, so their data is null: the op 500 tombstone added by this PR, the four PL/SQL operation types retired by #58700 (the same Text.readString(in) form) and the payload-less external-catalog operation types. Viewing any of those records failed with a NullPointerException. For op 500 this is a regression of this PR: before it the record failed to read and the row showed "Not Found". BDBTool, the other BDBJE inspection path, already prints a missing payload as null. The proc node now prints the payload with String.valueOf, so such a record shows null as its data. The op 500 tombstone stays the same as #58700's and branch-4.x's. Replay and checkpointing never read these payloads and are unaffected. ### Release note None ### Check List (For Author) - Test: Unit Test - BdbjeJournalDataProcNodeTest: an op 500 record and a retired PL/SQL record, in their written form, show their journal ID, operation name, size and null data; a live OP_SAVE_NEXTID record still shows its payload - Legacy415LanceUpgradeTest, BDBDebuggerTest - Behavior changed: No (the debug view no longer fails on these records) - Does this need documentation: No Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 7357266 commit b0e09ae

2 files changed

Lines changed: 131 additions & 1 deletion

File tree

‎fe/fe-core/src/main/java/org/apache/doris/common/proc/BdbjeJournalDataProcNode.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public ProcResult fetchResult() throws AnalysisException {
5252
BDBDebugger.JournalEntityWrapper entity = env.getJournalEntity(dbName, journalId);
5353

5454
short opCode = entity.entity == null ? -1 : entity.entity.getOpCode();
55-
String data = entity.entity == null ? entity.errMsg : entity.entity.getData().toString();
55+
// The readers of retired operation types (e.g. the PL/SQL and Lance index job tombstones) consume the
56+
// payload without keeping it; print such a record the way BDBTool does.
57+
String data = entity.entity == null ? entity.errMsg : String.valueOf(entity.entity.getData());
5658
result.addRow(Lists.newArrayList(entity.journalId.toString(),
5759
OperationType.getOpName(opCode), entity.size.toString(), data));
5860

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.common.proc;
19+
20+
import org.apache.doris.common.AnalysisException;
21+
import org.apache.doris.common.Config;
22+
import org.apache.doris.common.io.Text;
23+
import org.apache.doris.common.jmockit.Deencapsulation;
24+
import org.apache.doris.journal.JournalEntity;
25+
import org.apache.doris.journal.bdbje.BDBDebugger;
26+
import org.apache.doris.persist.OperationType;
27+
28+
import com.google.common.collect.Lists;
29+
import org.junit.jupiter.api.AfterEach;
30+
import org.junit.jupiter.api.Assertions;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
33+
import org.mockito.Mockito;
34+
35+
import java.io.ByteArrayInputStream;
36+
import java.io.ByteArrayOutputStream;
37+
import java.io.DataInputStream;
38+
import java.io.DataOutputStream;
39+
import java.io.IOException;
40+
import java.util.List;
41+
42+
/**
43+
* SHOW PROC '/bdbje/dbName/journalId', the BDBJE debug-mode view of a single journal record.
44+
*/
45+
public class BdbjeJournalDataProcNodeTest {
46+
private static final String DB_NAME = "1";
47+
48+
private boolean debugMode;
49+
private BDBDebugger.BDBDebugEnv debugEnv;
50+
51+
@BeforeEach
52+
public void setUp() {
53+
debugMode = Config.enable_bdbje_debug_mode;
54+
debugEnv = BDBDebugger.get().getEnv();
55+
}
56+
57+
@AfterEach
58+
public void tearDown() {
59+
Config.enable_bdbje_debug_mode = debugMode;
60+
Deencapsulation.setField(BDBDebugger.get(), "debugEnv", debugEnv);
61+
}
62+
63+
@Test
64+
public void recordsOfRetiredOperationTypesArePrintable() throws Exception {
65+
// The readers of retired operation types consume the payload without keeping it. Op 500 is the Lance
66+
// index job of unreleased branch-4.x builds, written as Text-framed JSON; the PL/SQL operation types were
67+
// retired the same way.
68+
BDBDebugger.JournalEntityWrapper lanceIndexJob = record(7L, OperationType.OP_LANCE_INDEX_JOB_UPSERT,
69+
"{\"jid\":7,\"rev\":2,\"cid\":10101,\"dbn\":\"db1\",\"tbn\":\"tbl1\",\"iid\":\"idx_v\","
70+
+ "\"it\":\"IVF_PQ\",\"cn\":[\"v\"],\"rs\":\"RUNNING\"}");
71+
BDBDebugger.JournalEntityWrapper plsqlPackage = record(8L, OperationType.OP_DROP_PLSQL_PACKAGE,
72+
"{\"name\":\"pkg1\",\"catalogId\":0,\"dbName\":\"db1\"}");
73+
Assertions.assertNull(lanceIndexJob.entity.getData());
74+
Assertions.assertNull(plsqlPackage.entity.getData());
75+
installDebugEnv(lanceIndexJob, plsqlPackage);
76+
77+
// MUTATION: with getData().toString() both rows fail with a NullPointerException.
78+
Assertions.assertEquals(Lists.newArrayList("7", "OP_LANCE_INDEX_JOB_UPSERT",
79+
lanceIndexJob.size.toString(), "null"), fetchRow(7L));
80+
Assertions.assertEquals(Lists.newArrayList("8", "OP_DROP_PLSQL_PACKAGE",
81+
plsqlPackage.size.toString(), "null"), fetchRow(8L));
82+
}
83+
84+
@Test
85+
public void liveRecordStillShowsItsPayload() throws Exception {
86+
BDBDebugger.JournalEntityWrapper nextId = record(9L, OperationType.OP_SAVE_NEXTID, "12345");
87+
installDebugEnv(nextId);
88+
89+
Assertions.assertEquals(Lists.newArrayList("9", "OP_SAVE_NEXTID", nextId.size.toString(), "12345"),
90+
fetchRow(9L));
91+
}
92+
93+
/** A journal record as BDBDebugEnv#getJournalEntity reads it back from BDBJE. */
94+
private static BDBDebugger.JournalEntityWrapper record(long journalId, short opCode, String payload)
95+
throws IOException {
96+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
97+
try (DataOutputStream out = new DataOutputStream(bytes)) {
98+
out.writeShort(opCode);
99+
// The int-length framing that both Text#write and Text.writeString produce.
100+
Text.writeString(out, payload);
101+
}
102+
BDBDebugger.JournalEntityWrapper wrapper = new BDBDebugger.JournalEntityWrapper(journalId);
103+
wrapper.size = bytes.size();
104+
JournalEntity entity = new JournalEntity();
105+
try (DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes.toByteArray()))) {
106+
entity.readFields(in);
107+
Assertions.assertEquals(-1, in.read(), "the record must be consumed exactly");
108+
}
109+
wrapper.entity = entity;
110+
return wrapper;
111+
}
112+
113+
private static void installDebugEnv(BDBDebugger.JournalEntityWrapper... records) {
114+
BDBDebugger.BDBDebugEnv env = Mockito.mock(BDBDebugger.BDBDebugEnv.class);
115+
for (BDBDebugger.JournalEntityWrapper record : records) {
116+
Mockito.when(env.getJournalEntity(DB_NAME, record.journalId)).thenReturn(record);
117+
}
118+
Deencapsulation.setField(BDBDebugger.get(), "debugEnv", env);
119+
Config.enable_bdbje_debug_mode = true;
120+
}
121+
122+
private static List<String> fetchRow(long journalId) throws AnalysisException {
123+
ProcResult result = new BdbjeJournalDataProcNode(DB_NAME, journalId).fetchResult();
124+
Assertions.assertEquals(BdbjeJournalDataProcNode.TITLE_NAMES, result.getColumnNames());
125+
Assertions.assertEquals(1, result.getRows().size());
126+
return result.getRows().get(0);
127+
}
128+
}

0 commit comments

Comments
 (0)