You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "alex-plekhanov (via GitHub)" <gi...@apache.org> on 2024/06/04 14:24:52 UTC

Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]

alex-plekhanov commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1626023218


##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java:
##########
@@ -1132,6 +1132,15 @@ private Metas getOrAllocateCacheMetas() throws IgniteCheckedException {
         return size;
     }
 
+    /** {@inheritDoc} */
+    @Override public boolean hasEntriesPendingExpire(int cacheId) throws IgniteCheckedException {
+        for (CacheDataStore store : cacheDataStores())

Review Comment:
   Braces



##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +339,46 @@ public String cacheWriterFactory() {
 
     /** @see CacheConfiguration#getExpiryPolicyFactory() */
     public String expiryPolicyFactory() {
-        return toStringSafe(cache.cacheConfiguration().getExpiryPolicyFactory());
+        if (cache.cacheConfiguration().getExpiryPolicyFactory() == null)
+            return null;
+
+        ExpiryPolicy expiryPlc = (ExpiryPolicy)cache.cacheConfiguration().getExpiryPolicyFactory().create();
+
+        Function<Duration, String> func = (duration) -> {
+            if (duration == null)
+                return null;
+
+            return new StringBuilder()
+                .append(duration.getDurationAmount())
+                .append(' ')
+                .append(duration.getTimeUnit() == null ? TimeUnit.MILLISECONDS : duration.getTimeUnit())
+                .toString();

Review Comment:
   Here is string still created, so StringBuilder is not required.
   Let's handle ETERNAL somehow (compare with Duration.ETERNAL) and omit `null` components. For example: `CreatedExpiryPolicy [create=100 MILLISECONDS]`,  `EternalExpiryPolicy [create=ETERNAL]`,  etc



##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewCacheExpiryPolicyTest.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.ignite.internal.metric;
+
+import java.util.Arrays;
+import java.util.Collection;
+import javax.cache.configuration.Factory;
+import javax.cache.configuration.FactoryBuilder;
+import javax.cache.expiry.CreatedExpiryPolicy;
+import javax.cache.expiry.Duration;
+import javax.cache.expiry.EternalExpiryPolicy;
+import javax.cache.expiry.ExpiryPolicy;
+import javax.cache.expiry.ModifiedExpiryPolicy;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.platform.cache.expiry.PlatformExpiryPolicyFactory;
+import org.apache.ignite.spi.systemview.view.CacheView;
+import org.apache.ignite.spi.systemview.view.SystemView;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.ignite.internal.processors.cache.ClusterCachesInfo.CACHES_VIEW;
+
+/** Tests for {@link CacheView} expiry policy factory representation. */
+@RunWith(Parameterized.class)
+public class SystemViewCacheExpiryPolicyTest extends GridCommonAbstractTest {
+    /** {@link Factory} instances for test with different expiry policy. */
+    @SuppressWarnings("unchecked")
+    private static final Factory[] TTL_FACTORIES = {
+        null,
+        new FactoryBuilder.SingletonFactory<ExpiryPolicy>(new EternalExpiryPolicy()),

Review Comment:
   No additional tests needed. `EternalExpiryPolicy.factoryOf()` is the same as `new FactoryBuilder.SingletonFactory<ExpiryPolicy>(new EternalExpiryPolicy())`, so, let's just fix these constructors.



-- 
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: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org