Copilot commented on code in PR #6734:
URL: https://github.com/apache/hive/pull/6734#discussion_r4020127936
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java:
##########
@@ -421,12 +421,8 @@ public <T> T unwrap(Class<T> iface) {
if (descriptor == null) {
throw new IllegalArgumentException("Unable to unwrap the store as " +
iface);
}
- String implClassName =
- conf.get("metastore." + descriptor.alias() + ".store.impl", "");
- Class<?> ifaceImpl = descriptor.defaultImpl();
- if (StringUtils.isNotEmpty(implClassName)) {
- ifaceImpl = conf.getClass(implClassName, ifaceImpl);
- }
+ Class<?> ifaceImpl =
+ conf.getClass("metastore." + descriptor.alias() + ".store.impl",
descriptor.defaultImpl());
Review Comment:
`Configuration.getClass` falls back only when the property is absent. If
`metastore.<alias>.store.impl` is present with an empty value, this now tries
to load the empty string as a class and `unwrap` fails, whereas the removed
`isNotEmpty` guard treated that value as the default implementation. Preserve
the blank-as-unset behavior while still using the configuration key for
non-empty custom implementations.
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/metastore/impl/NotificationStoreImpl.java:
##########
@@ -309,6 +323,7 @@ private <T> int doCleanNotificationEvents(final int ageSec,
final Optional<Integ
}
pm.deletePersistentAll(events);
}
+ query.closeAll();
Review Comment:
This method is now annotated `@NoTransaction`, so `TransactionHandler` does
not clear its `openQueries` tracker until `cleanOlderEvents` has finished every
batch. `PersistenceManagerProxy.newQuery` adds each batch query to that
tracker, and `query.closeAll()` does not remove the query object from the list,
so a large cleanup retains one tracked `Query` per batch for the whole call.
The tracker needs a per-batch removal/clear path (or the cleanup must use a
separately scoped persistence manager) to avoid introducing another unbounded
accumulation.
##########
standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/metastore/TestPersistenceContextEviction.java:
##########
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.hive.metastore.metastore;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hive.metastore.ExecutionContextTestUtils;
+import org.apache.hadoop.hive.metastore.HMSHandler;
+import org.apache.hadoop.hive.metastore.MetaStoreTestUtils;
+import org.apache.hadoop.hive.metastore.ObjectStore;
+import org.apache.hadoop.hive.metastore.Warehouse;
+import org.apache.hadoop.hive.metastore.annotation.MetastoreUnitTest;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NotificationEvent;
+import org.apache.hadoop.hive.metastore.api.NotificationEventRequest;
+import org.apache.hadoop.hive.metastore.api.NotificationEventResponse;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf;
+import org.apache.hadoop.hive.metastore.conf.MetastoreConf.ConfVars;
+import org.apache.hadoop.hive.metastore.messaging.EventMessage;
+import org.apache.hadoop.hive.metastore.model.MNotificationLog;
+import org.apache.hadoop.hive.metastore.utils.MetaStoreServerUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * Verifies batched metastore operations evict loaded JDO entities from the
persistence context.
+ * Without eviction, long-lived RawStore instances (for example the DB
notification cleaner thread)
+ * accumulate deleted entities in the L1 cache and can OOM.
+ */
+@Category(MetastoreUnitTest.class)
+public class TestPersistenceContextEviction {
+ private static final int BATCH_SIZE = 3;
+ private static final int NUM_EVENTS = 12;
+
+ private ObjectStore objectStore;
+ private Configuration conf;
+ private PersistenceManager pm;
+
+ @Before
+ public void setUp() throws Exception {
+ conf = MetastoreConf.newMetastoreConf();
+ MetastoreConf.setBoolVar(conf, ConfVars.HIVE_IN_TEST, true);
+ MetastoreConf.setLongVar(conf,
MetastoreConf.ConfVars.EVENT_CLEAN_MAX_EVENTS, BATCH_SIZE);
+ MetastoreConf.setLongVar(conf, ConfVars.RAWSTORE_PARTITION_BATCH_SIZE,
BATCH_SIZE);
+ MetaStoreTestUtils.setConfForStandloneMode(conf);
+
+ String currentUrl = MetastoreConf.getVar(conf, ConfVars.CONNECT_URL_KEY);
+ currentUrl = currentUrl.replace(MetaStoreServerUtils.JUNIT_DATABASE_PREFIX,
+ String.format("%s_%s", MetaStoreServerUtils.JUNIT_DATABASE_PREFIX,
UUID.randomUUID()));
+ MetastoreConf.setVar(conf, ConfVars.CONNECT_URL_KEY, currentUrl);
+
+ objectStore = new ObjectStore();
+ objectStore.setConf(conf);
+ HMSHandler.createDefaultCatalog(objectStore, new Warehouse(conf));
+ pm = objectStore.createRawStoreBundle().getPersistentManager();
+ }
+
+ @Test
+ public void testExecutionContextCountsLoadedNotificationEvents() throws
MetaException {
+ insertNotificationEvents(5, "payload");
+
+ objectStore.openTransaction();
+ try {
+ Query query = pm.newQuery(MNotificationLog.class);
+ List<MNotificationLog> events = (List<MNotificationLog>) query.execute();
+ pm.retrieveAll(events);
+ Assert.assertTrue("expected loaded events to remain in the persistence
context",
+ ExecutionContextTestUtils.countCachedInstances(pm,
MNotificationLog.class) >= 5);
+ } finally {
+ objectStore.rollbackTransaction();
+ }
+
+ Assert.assertEquals(0, ExecutionContextTestUtils.countCachedInstances(pm,
MNotificationLog.class));
+ }
+
+ @Test
+ public void testCleanNotificationEventsEvictsCachedEntities() throws
MetaException {
+ insertNotificationEvents(NUM_EVENTS, "x".repeat(50));
+
+ objectStore.openTransaction();
+ try {
+ objectStore.cleanNotificationEvents(0);
+ Assert.assertEquals("batched notification cleanup retains deleted events
in the L1 cache", NUM_EVENTS,
+ ExecutionContextTestUtils.countCachedInstances(pm,
MNotificationLog.class));
+ } finally {
+ objectStore.commitTransaction();
+ }
+
+ Assert.assertEquals("batched notification cleanup must not retain deleted
events in the L1 cache", 0,
+ ExecutionContextTestUtils.countCachedInstances(pm,
MNotificationLog.class));
Review Comment:
This test opens an outer `ObjectStore` transaction before calling the
`@NoTransaction` cleanup method, so each `cleanNotificationEventsBatch`
transaction is only nested and `commitTransaction` cannot perform the real
commit until this outer scope ends. The assertions therefore do not exercise
the per-batch commits and L1 eviction that are intended to prevent OOM; invoke
cleanup without the surrounding transaction (or add a separate test for this
nested case) and assert the cache immediately afterward.
--
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]