Uploaded image for project: 'Sentry (Retired)'
  1. Sentry (Retired)
  2. SENTRY-1579

Sentry should avoid using Proxy

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.8.0, 2.0.0
    • None
    • Sentry
    • None

    Description

      Sentry code uses Java java.lang.Reflect.Proxy class in several places:

      SentryHDFSServiceClientFactory

      uses this to modify behavior in HA case.

      SentryServiceClientFactory

      uses it to modify behavior in connection pool or Ha case:

        public static SentryPolicyServiceClient create(Configuration conf) throws Exception {
          boolean haEnabled = conf.getBoolean(ClientConfig.SERVER_HA_ENABLED, false);
          boolean pooled = conf.getBoolean(ClientConfig.SENTRY_POOL_ENABLED, false);
          if (pooled) {
            return (SentryPolicyServiceClient) Proxy
                .newProxyInstance(SentryPolicyServiceClientDefaultImpl.class.getClassLoader(),
                    SentryPolicyServiceClientDefaultImpl.class.getInterfaces(),
                    new PoolClientInvocationHandler(conf));
          } else if (haEnabled) {
            return (SentryPolicyServiceClient) Proxy
                .newProxyInstance(SentryPolicyServiceClientDefaultImpl.class.getClassLoader(),
                    SentryPolicyServiceClientDefaultImpl.class.getInterfaces(),
                    new HAClientInvocationHandler(conf));
          } else {
            return new SentryPolicyServiceClientDefaultImpl(conf);
          }
        }
      
      
      SentryServiceClientPoolFactory

      uses it to modify behavior in HA case.

      This seems to be an abuse of the Proxy interface and some simpler solution should be possible. We should investigate.

      Note that in sentry-ha-redesign branch there is only one use in

      SentryPolicyServiceClient

      that is used to adjust behavior for pooled vs retry behaviors:

        public static SentryPolicyServiceClient create(Configuration conf) throws Exception {
          boolean pooled = conf.getBoolean(
              ClientConfig.SENTRY_POOL_ENABLED, ClientConfig.SENTRY_POOL_ENABLED_DEFAULT);
          if (pooled) {
            return (SentryPolicyServiceClient) Proxy
                .newProxyInstance(SentryPolicyServiceClientDefaultImpl.class.getClassLoader(),
                    SentryPolicyServiceClientDefaultImpl.class.getInterfaces(),
                    new PoolClientInvocationHandler(conf));
          } else {
            return (SentryPolicyServiceClient) Proxy
                .newProxyInstance(SentryPolicyServiceClientDefaultImpl.class.getClassLoader(),
                    SentryPolicyServiceClientDefaultImpl.class.getInterfaces(),
                    new RetryClientInvocationHandler(conf));
          }
        }
      

      Again, a more straightforward solution should be possible.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              akolb Alex Kolbasov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: