[ 
https://issues.apache.org/jira/browse/HIVE-16873?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

BELUGA BEHR updated HIVE-16873:
-------------------------------
    Description: 
In {{org.apache.hadoop.hive.metastore.HiveMetaStore}} we have a {{Formatter}} 
class (and its buffer) tied to every thread.

This {{Formatter}} is for logging purposes. I would suggest that we simply let 
let the logging framework itself handle these kind of details and ditch the 
buffer per thread.

{code}
    public static final String AUDIT_FORMAT =
        "ugi=%s\t" + // ugi
            "ip=%s\t" + // remote IP
            "cmd=%s\t"; // command
    public static final Logger auditLog = LoggerFactory.getLogger(
        HiveMetaStore.class.getName() + ".audit");
    private static final ThreadLocal<Formatter> auditFormatter =
        new ThreadLocal<Formatter>() {
          @Override
          protected Formatter initialValue() {
            return new Formatter(new StringBuilder(AUDIT_FORMAT.length() * 4));
          }
        };

...

    private static final void logAuditEvent(String cmd) {
      final Formatter fmt = auditFormatter.get();
      ((StringBuilder) fmt.out()).setLength(0);

      String address = getIPAddress();
      if (address == null) {
        address = "unknown-ip-addr";
      }

      auditLog.info(fmt.format(AUDIT_FORMAT, ugi.getUserName(),
          address, cmd).toString());
    }
{code}

  was:
In {{org.apache.hadoop.hive.metastore.HiveMetaStore}} we have a {{Formatter}} 
class tied to every thread for logging.

{code}
    public static final String AUDIT_FORMAT =
        "ugi=%s\t" + // ugi
            "ip=%s\t" + // remote IP
            "cmd=%s\t"; // command
    public static final Logger auditLog = LoggerFactory.getLogger(
        HiveMetaStore.class.getName() + ".audit");
    private static final ThreadLocal<Formatter> auditFormatter =
        new ThreadLocal<Formatter>() {
          @Override
          protected Formatter initialValue() {
            return new Formatter(new StringBuilder(AUDIT_FORMAT.length() * 4));
          }
        };

...

    private static final void logAuditEvent(String cmd) {
      final Formatter fmt = auditFormatter.get();
      ((StringBuilder) fmt.out()).setLength(0);

      String address = getIPAddress();
      if (address == null) {
        address = "unknown-ip-addr";
      }

      auditLog.info(fmt.format(AUDIT_FORMAT, ugi.getUserName(),
          address, cmd).toString());
    }
{code}

I would suggest that we simply let let the logging framework itself handle 
these kind of details.


> Remove Thread Cache From Logging
> --------------------------------
>
>                 Key: HIVE-16873
>                 URL: https://issues.apache.org/jira/browse/HIVE-16873
>             Project: Hive
>          Issue Type: Improvement
>          Components: Metastore
>            Reporter: BELUGA BEHR
>            Priority: Minor
>         Attachments: HIVE-16873.1.patch
>
>
> In {{org.apache.hadoop.hive.metastore.HiveMetaStore}} we have a {{Formatter}} 
> class (and its buffer) tied to every thread.
> This {{Formatter}} is for logging purposes. I would suggest that we simply 
> let let the logging framework itself handle these kind of details and ditch 
> the buffer per thread.
> {code}
>     public static final String AUDIT_FORMAT =
>         "ugi=%s\t" + // ugi
>             "ip=%s\t" + // remote IP
>             "cmd=%s\t"; // command
>     public static final Logger auditLog = LoggerFactory.getLogger(
>         HiveMetaStore.class.getName() + ".audit");
>     private static final ThreadLocal<Formatter> auditFormatter =
>         new ThreadLocal<Formatter>() {
>           @Override
>           protected Formatter initialValue() {
>             return new Formatter(new StringBuilder(AUDIT_FORMAT.length() * 
> 4));
>           }
>         };
> ...
>     private static final void logAuditEvent(String cmd) {
>       final Formatter fmt = auditFormatter.get();
>       ((StringBuilder) fmt.out()).setLength(0);
>       String address = getIPAddress();
>       if (address == null) {
>         address = "unknown-ip-addr";
>       }
>       auditLog.info(fmt.format(AUDIT_FORMAT, ugi.getUserName(),
>           address, cmd).toString());
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to