-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix parser failed when binlog_row_value_options=partial_json (#5018)
* 修改json部分更新的问题 * 保证after-image的情况下位点回退完整
- Loading branch information
Showing
2 changed files
with
57 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
|
||
/** | ||
* Extracting JDBC type & value information from packed rows-buffer. | ||
* | ||
* | ||
* @see mysql-5.1.60/sql/log_event.cc - Rows_log_event::print_verbose_one_row | ||
* @author <a href="mailto:[email protected]">Changyuan.lh</a> | ||
* @version 1.0 | ||
|
@@ -70,7 +70,7 @@ public final boolean nextOneRow(BitSet columns) { | |
|
||
/** | ||
* Extracting next row from packed buffer. | ||
* | ||
* | ||
* @see mysql-5.1.60/sql/log_event.cc - | ||
* Rows_log_event::print_verbose_one_row | ||
*/ | ||
|
@@ -104,7 +104,7 @@ public final boolean nextOneRow(BitSet columns, boolean after) { | |
|
||
/** | ||
* Extracting next field value from packed buffer. | ||
* | ||
* | ||
* @see mysql-5.1.60/sql/log_event.cc - | ||
* Rows_log_event::print_verbose_one_row | ||
*/ | ||
|
@@ -114,7 +114,7 @@ public final Serializable nextValue(final String columName, final int columnInde | |
|
||
/** | ||
* Extracting next field value from packed buffer. | ||
* | ||
* | ||
* @see mysql-5.1.60/sql/log_event.cc - | ||
* Rows_log_event::print_verbose_one_row | ||
*/ | ||
|
@@ -277,7 +277,7 @@ static int mysqlToJavaType(int type, final int meta, boolean isBinary) { | |
|
||
/** | ||
* Extracting next field value from packed buffer. | ||
* | ||
* | ||
* @see mysql-5.1.60/sql/log_event.cc - log_event_print_value | ||
*/ | ||
final Serializable fetchValue(String columnName, int columnIndex, int type, final int meta, boolean isBinary) { | ||
|
@@ -1077,30 +1077,21 @@ final Serializable fetchValue(String columnName, int columnIndex, int type, fina | |
if (partialBits.get(1)) { | ||
// print_json_diff | ||
int position = buffer.position(); | ||
StringBuilder builder = JsonDiffConversion.print_json_diff(buffer, | ||
len, | ||
columnName, | ||
columnIndex, | ||
charset); | ||
value = builder.toString(); | ||
buffer.position(position + len); | ||
} else { | ||
if (0 == len) { | ||
// fixed issue #1 by lava, json column of zero length | ||
// has no | ||
// value, value parsing should be skipped | ||
value = ""; | ||
} else { | ||
int position = buffer.position(); | ||
Json_Value jsonValue = JsonConversion.parse_value(buffer.getUint8(), | ||
buffer, | ||
len - 1, | ||
try { | ||
StringBuilder builder = JsonDiffConversion.print_json_diff(buffer, | ||
len, | ||
columnName, | ||
columnIndex, | ||
charset); | ||
StringBuilder builder = new StringBuilder(); | ||
jsonValue.toJsonString(builder, charset); | ||
value = builder.toString(); | ||
buffer.position(position + len); | ||
} catch (IllegalArgumentException e) { | ||
buffer.position(position); | ||
// print_json_diff failed, fallback to parse_value | ||
parseJsonFromFullValue(len); | ||
} | ||
} else { | ||
parseJsonFromFullValue(len); | ||
} | ||
javaType = Types.VARCHAR; | ||
length = len; | ||
|
@@ -1155,6 +1146,25 @@ final Serializable fetchValue(String columnName, int columnIndex, int type, fina | |
return value; | ||
} | ||
|
||
private void parseJsonFromFullValue(int len) { | ||
if (0 == len) { | ||
// fixed issue #1 by lava, json column of zero length | ||
// has no | ||
// value, value parsing should be skipped | ||
value = ""; | ||
} else { | ||
int position = buffer.position(); | ||
Json_Value jsonValue = JsonConversion.parse_value(buffer.getUint8(), | ||
buffer, | ||
len - 1, | ||
charset); | ||
StringBuilder builder = new StringBuilder(); | ||
jsonValue.toJsonString(builder, charset); | ||
value = builder.toString(); | ||
buffer.position(position + len); | ||
} | ||
} | ||
|
||
public final boolean isNull() { | ||
return fNull; | ||
} | ||
|