Github user shivzone commented on a diff in the pull request: https://github.com/apache/incubator-hawq/pull/1379#discussion_r199593983 --- Diff: pxf/pxf-service/src/main/java/org/apache/hawq/pxf/service/servlet/SecurityServletFilter.java --- @@ -42,8 +52,51 @@ private static final Log LOG = LogFactory.getLog(SecurityServletFilter.class); private static final String USER_HEADER = "X-GP-USER"; - private static final String MISSING_HEADER_ERROR = String.format("Header %s is missing in the request", USER_HEADER); - private static final String EMPTY_HEADER_ERROR = String.format("Header %s is empty in the request", USER_HEADER); + private static final String SEGMENT_INDEX_HEADER = "X-GP-SEGMENT-ID"; + private static final String TRANSACTION_ID_HEADER = "X-GP-XID"; + private static final String MISSING_HEADER_ERROR = "Header %s is missing in the request"; + private static final String EMPTY_HEADER_ERROR = "Header %s is empty in the request"; + private static Map<SegmentTransactionId, TimedProxyUGI> cache = new ConcurrentHashMap<>(); + private static DelayQueue<TimedProxyUGI> delayQueue = new DelayQueue<>(); + private static long UGI_CACHE_EXPIRY = 15 * 60 * 1000L; // 15 Minutes + + + private static class TimedProxyUGI implements Delayed { + long startTime; + UserGroupInformation proxyUGI; + SegmentTransactionId session; + + public TimedProxyUGI(UserGroupInformation proxyUGI, SegmentTransactionId session) { + this.startTime = System.currentTimeMillis(); + this.proxyUGI = proxyUGI; + this.session = session; + } + + @Override + public long getDelay(TimeUnit unit) { + return unit.convert(getDelayMillis(), TimeUnit.MILLISECONDS); + } + + @Override + public int compareTo(Delayed other) { + return Long.compare(this.getDelayMillis(), ((TimedProxyUGI)other).getDelayMillis()); + } + + private long getDelayMillis() { + return (startTime + UGI_CACHE_EXPIRY) - System.currentTimeMillis(); + } + } + + private static class SegmentTransactionId { + String segmentIndex; --- End diff -- Not having to explicitly invoke close() was based on our choice to rely on expiration and inUse status. @lavjain can you recollect why transactionID woudln't do ?
---