Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZOOKEEPER-4607 : Fix decode problem when sub tnx type is error. #1915

Merged
merged 8 commits into from
Jul 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
narrow visibility and use constant instead of magic number
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Jul 18, 2023
commit ba2e0ab3e826b5d9419c67332f8ed217c64bcbdc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.jute.BinaryInputArchive;
import org.apache.jute.BinaryOutputArchive;
import org.apache.jute.Record;
import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.server.ExitCode;
import org.apache.zookeeper.server.Request;
import org.apache.zookeeper.server.TxnLogEntry;
Expand Down Expand Up @@ -308,12 +309,13 @@ private void printTxn(byte[] bytes, String prefix) throws IOException {
}

/**
* get the formatted string from the txn.
* Get the formatted string from the txn.
*
* @param txn transaction log data
* @return the formatted string
*/
// @VisibleForTesting
public static String getFormattedTxnStr(Record txn) throws IOException {
static String getFormattedTxnStr(Record txn) {
StringBuilder txnData = new StringBuilder();
if (txn == null) {
return txnData.toString();
Expand Down Expand Up @@ -342,29 +344,24 @@ public static String getFormattedTxnStr(Record txn) throws IOException {
for (int i = 0; i < txnList.size(); i++) {
Txn t = txnList.get(i);
if (i == 0) {
txnData.append(Request.op2String(t.getType()) + ":");
if (t.getType() == -1) {
txnData.append(ByteBuffer.wrap(t.getData()).getInt());
} else {
txnData.append(checkNullToEmpty(t.getData()));
}
txnData.append(Request.op2String(t.getType())).append(":");
} else {
txnData.append(";" + Request.op2String(t.getType()) + ":");
if (t.getType() == -1) {
txnData.append(ByteBuffer.wrap(t.getData()).getInt());
} else {
txnData.append(checkNullToEmpty(t.getData()));
}
txnData.append(";").append(Request.op2String(t.getType())).append(":");
}
if (t.getType() == ZooDefs.OpCode.error) {
txnData.append(ByteBuffer.wrap(t.getData()).getInt());
} else {
txnData.append(checkNullToEmpty(t.getData()));
}
}
} else {
txnData.append(txn.toString());
txnData.append(txn);
}

return txnData.toString();
}

private static String checkNullToEmpty(byte[] data) throws IOException {
private static String checkNullToEmpty(byte[] data) {
if (data == null || data.length == 0) {
return "";
}
Expand Down