Uploaded image for project: 'Apache RocketMQ'
  1. Apache RocketMQ
  2. ROCKETMQ-259

Too many reflection calls when decode remoting command header

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.0.0-incubating, 4.1.0-incubating
    • Fix Version/s: 4.2.0
    • Component/s: rocketmq-remoting
    • Labels:
      None

      Description

      Each field in a CommandCustomHeader will be checked to ensure some key fields aren't null when decode RemotingCommand header. This process will cause a reflection call, and current code has a cache mechanism, but it doesn't work.

      Annotation annotation = getNotNullAnnotation(field);
      if (annotation != null) {
          throw new RemotingCommandException("the custom field <" + fieldName + "> is null");
      }
      
      private Annotation getNotNullAnnotation(Field field) {
              Annotation annotation = NOT_NULL_ANNOTATION_CACHE.get(field);
      
              if (annotation == null) { 
                  annotation = field.getAnnotation(CFNotNull.class); //[1]
                  synchronized (NOT_NULL_ANNOTATION_CACHE) {
                      NOT_NULL_ANNOTATION_CACHE.put(field, annotation);
                  }
              }
              return annotation;
          }
      

      [1]. If a field doesn't has CFNotNull annotation, each check will cause a reflection call.

        Attachments

          Activity

            People

            • Assignee:
              Yukon yukon
              Reporter:
              Yukon yukon
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: