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

[ISSUE #7454] Utilizing cache to avoid duplicate parsing #7455

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public RemotingCommand processRequest(final ChannelHandlerContext ctx, RemotingC
RemotingCommand response = RemotingCommand.createResponseCommand(PopMessageResponseHeader.class);
final PopMessageResponseHeader responseHeader = (PopMessageResponseHeader) response.readCustomHeader();
final PopMessageRequestHeader requestHeader =
(PopMessageRequestHeader) request.decodeCommandCustomHeader(PopMessageRequestHeader.class);
(PopMessageRequestHeader) request.decodeCommandCustomHeader(PopMessageRequestHeader.class, true);
StringBuilder startOffsetInfo = new StringBuilder(64);
StringBuilder msgOffsetInfo = new StringBuilder(64);
StringBuilder orderCountInfo = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class RemotingCommand {
private String remark;
private HashMap<String, String> extFields;
private transient CommandCustomHeader customHeader;
private transient CommandCustomHeader cachedHeader;

private SerializeType serializeTypeCurrentRPC = serializeTypeConfigInThisServer;

Expand Down Expand Up @@ -260,10 +261,19 @@ public void writeCustomHeader(CommandCustomHeader customHeader) {

public CommandCustomHeader decodeCommandCustomHeader(
Class<? extends CommandCustomHeader> classHeader) throws RemotingCommandException {
return decodeCommandCustomHeader(classHeader, true);
return decodeCommandCustomHeader(classHeader, false);
}

public CommandCustomHeader decodeCommandCustomHeader(Class<? extends CommandCustomHeader> classHeader,
public CommandCustomHeader decodeCommandCustomHeader(
Class<? extends CommandCustomHeader> classHeader, boolean isCached) throws RemotingCommandException {
if (isCached && cachedHeader != null) {
return cachedHeader;
}
cachedHeader = decodeCommandCustomHeaderDirectly(classHeader, true);
return cachedHeader;
}

public CommandCustomHeader decodeCommandCustomHeaderDirectly(Class<? extends CommandCustomHeader> classHeader,
boolean useFastEncode) throws RemotingCommandException {
CommandCustomHeader objectHeader;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private HashMap<String, String> buildExtFields(List<Field> fields) {

private void check(RemotingCommand command, List<Field> fields,
Class<? extends CommandCustomHeader> classHeader) throws Exception {
CommandCustomHeader o1 = command.decodeCommandCustomHeader(classHeader, false);
CommandCustomHeader o1 = command.decodeCommandCustomHeaderDirectly(classHeader, false);
CommandCustomHeader o2 = classHeader.getDeclaredConstructor().newInstance();
((FastCodesHeader)o2).decode(command.getExtFields());
for (Field f : fields) {
Expand Down
Loading