github-advanced-security[bot] commented on code in PR #19548:
URL: https://github.com/apache/druid/pull/19548#discussion_r3349124333


##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/server/lookup/namespace/cache/OffHeapNamespaceExtractionCacheManager.java:
##########
@@ -81,35 +80,47 @@
     @Override
     public void run()
     {
-      if (disposed.compareAndSet(false, true)) {
+      if (tryDisposeFromCleaner()) {
+        // Log statement goes after doDispose(), because logging may fail (e. 
g. if we are in shutdownHooks).
+        log.error(
+            "OffHeapNamespaceExtractionCacheManager.disposeCache() was not 
called, disposed resources by the JVM");
+      }
+    }
+
+    private synchronized boolean tryDisposeFromCleaner()
+    {
+      if (disposed) {
+        return false;
+      }
+
+      try {
+        doDispose();
+        disposed = true;
+        return true;
+      }
+      catch (Throwable t) {
         try {
-          doDispose();
-          // Log statement goes after doDispose(), because logging may fail 
(e. g. if we are in shutdownHooks).
-          log.error(
-              "OffHeapNamespaceExtractionCacheManager.disposeCache() was not 
called, disposed resources by the JVM");
+          log.error(t, "Error while deleting key %s from MapDb", mapDbKey);
         }
-        catch (Throwable t) {
-          try {
-            log.error(t, "Error while deleting key %s from MapDb", mapDbKey);
-          }
-          catch (Exception e) {
-            t.addSuppressed(e);
-          }
-          Throwables.propagateIfInstanceOf(t, Error.class);
-          // Must not throw exceptions in the cleaner thread, possibly run in 
the JVM.
+        catch (Exception e) {
+          t.addSuppressed(e);
         }
+        Throwables.propagateIfInstanceOf(t, Error.class);

Review Comment:
   ## CodeQL / Deprecated method or constructor invocation
   
   Invoking [Throwables.propagateIfInstanceOf](1) should be avoided because it 
has been deprecated.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/11290)



##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/query/lookup/NamespaceLookupExtractorFactory.java:
##########
@@ -224,24 +227,87 @@
         throw new ISE("%s: %s, extractorID = %s", entry, noCacheReason, 
extractorID);
       }
       CacheScheduler.VersionedCache versionedCache = 
(CacheScheduler.VersionedCache) cacheState;
-      final byte[] v = StringUtils.toUtf8(versionedCache.getVersion());
-      final byte[] id = StringUtils.toUtf8(extractorID);
-      final byte injectiveByte = isInjective() ? (byte) 1 : (byte) 0;
-      final Supplier<byte[]> cacheKey = () ->
-          ByteBuffer
-              .allocate(CLASS_CACHE_KEY.length + id.length + 1 + v.length + 1 
+ 1)
-              .put(CLASS_CACHE_KEY)
-              .put(id).put((byte) 0xFF)
-              .put(v).put((byte) 0xFF)
-              .put(injectiveByte)
-              .array();
-      return versionedCache.asLookupExtractor(isInjective(), cacheKey);
+      return versionedCache.asLookupExtractor(isInjective(), 
makeCacheKeySupplier(versionedCache));
     }
     finally {
       readLock.unlock();
     }
   }
 
+  @Override
+  public Optional<RetainedLookupExtractor> acquireRetainedLookupExtractor()
+  {
+    for (int attemptsRemaining = MAX_RETAIN_ATTEMPTS; attemptsRemaining > 0; 
attemptsRemaining--) {

Review Comment:
   ## CodeQL / Useless comparison test
   
   Test is always true, because of [this condition](1).
   Test is always true, because of [this condition](2).
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/11289)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to