You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "maksaska (via GitHub)" <gi...@apache.org> on 2024/05/22 11:39:13 UTC
[PR] IGNITE-22189 [ignite]
maksaska opened a new pull request, #11357:
URL: https://github.com/apache/ignite/pull/11357
**What have been implemented:**
- CacheView: expiry policy factory String represantation. The CacheView#expiryPolicyFactory method returns readable output with ttl
- CacheView: entries pending expire. The flag shows if there are entries pending to expire. The time complexity for in-memory is O(logN), and for persistance is O(Number of partitions). The flag is based on the pendingTree/pendingEntries `BPlusTree` instance, that holds the information. The instance is hold within `IgniteCacheOffheapManager` implementation class, thus the flag can only return reasonable output for caches with eager ttl (eagerTtl = true), and group assigned. Otherwise "Unknown" is returned
- CacheGroupView: entries pending expire. The flag shows if there are entries pending to expire. The time complexity for in-memory is O(1), and for persistance is O(Number of partitions). The flag is based on the pendingTree/pendingEntries `BPlusTree` instance of `IgniteCacheOffheapManager` implementation class. There might be discreptancies for caches with different eager ttl within one group.
Thank you for submitting the pull request to the Apache Ignite.
In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:
### The Contribution Checklist
- [ ] There is a single JIRA ticket related to the pull request.
- [ ] The web-link to the pull request is attached to the JIRA ticket.
- [ ] The JIRA ticket has the _Patch Available_ state.
- [ ] The pull request body describes changes that have been made.
The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
- [ ] The pull request title is treated as the final commit message.
The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
- [ ] A reviewer has been mentioned through the JIRA comments
(see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers))
- [ ] The pull request has been checked by the Teamcity Bot and
the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
### Notes
- [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
- [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
- [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
- [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617536209
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
+ }
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
+ CacheGroupContext grpCtx = ctx.cache().cacheGroup(cache.groupId());
+
+ if (!cache.cacheConfiguration().isEagerTtl() || grpCtx == null || grpCtx.name() == null)
+ return "Unknown";
+
+ try {
+ return grpCtx.offheap().hasEntriesPendingExpire(cache.cacheId()) ? "Yes" : "No";
+ }
+ catch (IgniteCheckedException e) {
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * Returns {@link Duration} String representation with description
+ * @param msg descriptive message for {@link Duration} instance
+ * @param duration @link Duration}
+ * @return {@link Duration} representation with descriptive message
+ */
+ public String durationToStringWithCustomMessage(String msg, Duration duration) {
+ if (duration == null || duration.getTimeUnit() == null || duration.getDurationAmount() == 0)
+ return "";
+
+ return "[" + msg + "=" + duration.getDurationAmount() + duration.getTimeUnit() + "]";
Review Comment:
Fixed it
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617451520
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
+ }
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
Review Comment:
Changed the name to "expiryPolicyEntry"
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617548013
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
Review Comment:
There might be no custom toString() method from the user for this factory. If so, ClassName@HexHash might become a problem. It was actually the reason why we wanted changes here in the first place.
In addition I can add a className factory to the output. Usually it's incorporates the logic behind it. But it's only assumption. In general it's strange to give the user information about how the develoer decided to name the class.
Maybe there is other way, but I thought ttl information should suffice. It's short, readable and it contains everything the user want to know about the factory
WGYT?
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1616700228
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheGroupView.java:
##########
@@ -150,4 +152,21 @@ public int rebalanceOrder() {
public int backups() {
return ccfg.getBackups();
}
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
Review Comment:
We don't need such a column in chage groups view if we have it in cache view.
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java:
##########
@@ -1180,6 +1180,27 @@ private int expireInternal(
return pendingEntries != null ? pendingEntries.size() : 0;
}
+ /** {@inheritDoc} */
+ @Override public boolean hasEntriesPendingExpire() throws IgniteCheckedException {
+ return pendingEntries != null && !pendingEntries.isEmpty();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean hasEntriesPendingExpire(int cacheId) throws IgniteCheckedException {
+ if (pendingEntries != null) {
+ PendingRow row = new PendingRow(cacheId);
+
+ GridCursor<PendingRow> cursor = pendingEntries.find(row, row, PendingEntriesTree.WITHOUT_KEY);
+
+ while (cursor.next()) {
+ if (pendingEntries.findOne(cursor.get()) != null)
Review Comment:
Why do we need exctra call to `findOne`? Why just `return cursor.next();` is not enough?
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
Review Comment:
Point at the end of sentence.
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewCacheExpiryPolicyTest.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.expiry.Duration;
+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 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 {
+ /**Create ttl {@link Duration}*/
+ @Parameterized.Parameter
+ public long create;
+
+ /** Access ttl {@link Duration}*/
+ @Parameterized.Parameter(1)
+ public long update;
+
+ /** Update ttl {@link Duration}*/
+ @Parameterized.Parameter(2)
+ public long access;
+
+ /** Anticipated {@link String} expiry policy factory representation*/
+ @Parameterized.Parameter(3)
+ public String actual;
+
+ /**
+ * @return Test parameters.
+ */
+ @Parameterized.Parameters(name = "create={0}, update={1}, access={2}, actual={3}")
+ public static Collection parameters() {
+ return Arrays.asList(new Object[][] {
+ {2, 4, 8, "[create=2MILLISECONDS][update=4MILLISECONDS][access=8MILLISECONDS]"},
+ {1, -2, -1, "[create=1MILLISECONDS]"},
+ {-1, 0, -1, "Eternal"},
+ {0, 1, -1, "[update=1MILLISECONDS]"}
+ });
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ cleanPersistenceDir();
Review Comment:
Test doesn't use persistence. Methods `beforeTestsStarted`, `afterTestsStopped` are redundant.
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
Review Comment:
Use `StringBuilder` to reduce GC pressure
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
+ try (IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
+ )))) {
+
+ if (withPersistance)
+ g.cluster().state(ClusterState.ACTIVE);
+
+ String eternalCacheName = "eternalCache";
+ String createdCacheName = "createdCache";
+ String eagerTtlCacheName = "eagerTtlCache";
+ String withoutGrpCacheName = "withoutGrpCache";
+
+ CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
+ .setGroupName("group1")
+ .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
+
+ CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
+ .setGroupName("group2")
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
+ .setGroupName("group2")
+ .setEagerTtl(false)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
Review Comment:
Let's add cache without explicit expiry policy, but with expiring entry.
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
+ }
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
+ CacheGroupContext grpCtx = ctx.cache().cacheGroup(cache.groupId());
+
+ if (!cache.cacheConfiguration().isEagerTtl() || grpCtx == null || grpCtx.name() == null)
+ return "Unknown";
+
+ try {
+ return grpCtx.offheap().hasEntriesPendingExpire(cache.cacheId()) ? "Yes" : "No";
+ }
+ catch (IgniteCheckedException e) {
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * Returns {@link Duration} String representation with description
+ * @param msg descriptive message for {@link Duration} instance
+ * @param duration @link Duration}
+ * @return {@link Duration} representation with descriptive message
Review Comment:
Point at the end of each sentence.
`@link Duration}` - wrong formatting
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
+ }
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
Review Comment:
Can we shorten the method name? In SQL view it would be "HAS_ENTRIES_PENDING_EXPIRE" which is not very convinient.
##########
modules/core/src/main/java/org/apache/ignite/internal/managers/systemview/walker/CacheViewWalker.java:
##########
@@ -97,6 +97,7 @@ public class CacheViewWalker implements SystemViewRowAttributeWalker<CacheView>
v.accept(59, "writeBehindFlushSize", int.class);
v.accept(60, "writeBehindFlushThreadCount", int.class);
v.accept(61, "writeSynchronizationMode", CacheWriteSynchronizationMode.class);
+ v.accept(62, "hasEntriesPendingExpire", String.class);
Review Comment:
'Walker' classes shold not be changed manually. You should regenerate it using `SystemViewRowAttributeWalkerGenerator` (see javadoc for class).
You forgot to change `count` method and fields order is incorrect.
As far as I remember we have a tests checking full set of view columns. These tests should should be fixed to. Check team-city.
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java:
##########
@@ -56,6 +56,10 @@ public class CacheGroupDescriptor {
@GridToStringExclude
private volatile CacheConfiguration<?, ?> cacheCfg;
+ /** */
+ @GridToStringExclude
+ private volatile GridCacheProcessor cacheProc;
Review Comment:
`CacheGroupDescriptor` is some kind of DTO, which is distributed between nodes. Should not contain any node related classes (managers/processors/etc).
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
Review Comment:
`withPersistance` -> `withPersistence`
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
+ }
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
+ CacheGroupContext grpCtx = ctx.cache().cacheGroup(cache.groupId());
+
+ if (!cache.cacheConfiguration().isEagerTtl() || grpCtx == null || grpCtx.name() == null)
Review Comment:
Why do we skip caches with `grpCtx.name() == null`?
For `grpCtx == null` let's leave field empty or change the message. SInce when `isEagerTtl` is false - we can't check if expiring entries are exist, but when `grpCtx == null` - this mean node doesn't contain any cache group related data at all.
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
+ try (IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
Review Comment:
Always tested with persistence
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
+ try (IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
+ )))) {
+
+ if (withPersistance)
+ g.cluster().state(ClusterState.ACTIVE);
+
+ String eternalCacheName = "eternalCache";
+ String createdCacheName = "createdCache";
+ String eagerTtlCacheName = "eagerTtlCache";
+ String withoutGrpCacheName = "withoutGrpCache";
+
+ CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
+ .setGroupName("group1")
+ .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
+
+ CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
+ .setGroupName("group2")
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
+ .setGroupName("group2")
+ .setEagerTtl(false)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ g.createCache(eternalCache);
+ g.createCache(createdCache);
+ g.createCache(eagerTtlCache);
+ g.createCache(withoutGrpCache);
+
+ SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);
+
+ for (CacheView row : caches) {
+ switch (row.cacheName()) {
+ case "eternalCache":
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
Review Comment:
Why not `assertEquals("No", row.hasEntriesPendingExpire())`?
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
+ try (IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
+ )))) {
+
+ if (withPersistance)
+ g.cluster().state(ClusterState.ACTIVE);
+
+ String eternalCacheName = "eternalCache";
+ String createdCacheName = "createdCache";
+ String eagerTtlCacheName = "eagerTtlCache";
+ String withoutGrpCacheName = "withoutGrpCache";
+
+ CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
+ .setGroupName("group1")
+ .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
+
+ CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
+ .setGroupName("group2")
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
+ .setGroupName("group2")
+ .setEagerTtl(false)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ g.createCache(eternalCache);
+ g.createCache(createdCache);
+ g.createCache(eagerTtlCache);
+ g.createCache(withoutGrpCache);
+
+ SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);
+
+ for (CacheView row : caches) {
+ switch (row.cacheName()) {
+ case "eternalCache":
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(eternalCacheName).put(0, 0);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(eternalCacheName)
+ .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ break;
+
+ case "createdCache":
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(createdCacheName).put(0, 0);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ g.cache(createdCacheName)
+ .withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ g.cache(eagerTtlCacheName).put(2, 2);
Review Comment:
Why we use `eagerTtlCacheName` here?
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
Review Comment:
Point and space at the end of sentence.
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
+ }
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
+ CacheGroupContext grpCtx = ctx.cache().cacheGroup(cache.groupId());
+
+ if (!cache.cacheConfiguration().isEagerTtl() || grpCtx == null || grpCtx.name() == null)
+ return "Unknown";
+
+ try {
+ return grpCtx.offheap().hasEntriesPendingExpire(cache.cacheId()) ? "Yes" : "No";
+ }
+ catch (IgniteCheckedException e) {
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * Returns {@link Duration} String representation with description
+ * @param msg descriptive message for {@link Duration} instance
+ * @param duration @link Duration}
+ * @return {@link Duration} representation with descriptive message
+ */
+ public String durationToStringWithCustomMessage(String msg, Duration duration) {
+ if (duration == null || duration.getTimeUnit() == null || duration.getDurationAmount() == 0)
+ return "";
+
+ return "[" + msg + "=" + duration.getDurationAmount() + duration.getTimeUnit() + "]";
Review Comment:
Space after `duration.getDurationAmount()` for better readability of duration
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
+ }
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
+ CacheGroupContext grpCtx = ctx.cache().cacheGroup(cache.groupId());
+
+ if (!cache.cacheConfiguration().isEagerTtl() || grpCtx == null || grpCtx.name() == null)
+ return "Unknown";
+
+ try {
+ return grpCtx.offheap().hasEntriesPendingExpire(cache.cacheId()) ? "Yes" : "No";
+ }
+ catch (IgniteCheckedException e) {
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * Returns {@link Duration} String representation with description
+ * @param msg descriptive message for {@link Duration} instance
+ * @param duration @link Duration}
+ * @return {@link Duration} representation with descriptive message
+ */
+ public String durationToStringWithCustomMessage(String msg, Duration duration) {
Review Comment:
`private static`
Move method directly after the `expiryPolicyFactory` method (since it used only here) or to the end of the class.
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java:
##########
@@ -1180,6 +1180,27 @@ private int expireInternal(
return pendingEntries != null ? pendingEntries.size() : 0;
}
+ /** {@inheritDoc} */
+ @Override public boolean hasEntriesPendingExpire() throws IgniteCheckedException {
+ return pendingEntries != null && !pendingEntries.isEmpty();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean hasEntriesPendingExpire(int cacheId) throws IgniteCheckedException {
+ if (pendingEntries != null) {
+ PendingRow row = new PendingRow(cacheId);
+
+ GridCursor<PendingRow> cursor = pendingEntries.find(row, row, PendingEntriesTree.WITHOUT_KEY);
Review Comment:
In case of not shared group we should use `exists`
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
Review Comment:
Point at the end of sentence.
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
Review Comment:
Here we should output information about the factory in readable form (not only about instance), perhaps S.toString() on factory will be enough.
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewCacheExpiryPolicyTest.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.expiry.Duration;
+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 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 {
+ /**Create ttl {@link Duration}*/
+ @Parameterized.Parameter
+ public long create;
+
+ /** Access ttl {@link Duration}*/
+ @Parameterized.Parameter(1)
+ public long update;
+
+ /** Update ttl {@link Duration}*/
+ @Parameterized.Parameter(2)
+ public long access;
+
+ /** Anticipated {@link String} expiry policy factory representation*/
+ @Parameterized.Parameter(3)
+ public String actual;
+
+ /**
+ * @return Test parameters.
+ */
+ @Parameterized.Parameters(name = "create={0}, update={1}, access={2}, actual={3}")
+ public static Collection parameters() {
+ return Arrays.asList(new Object[][] {
+ {2, 4, 8, "[create=2MILLISECONDS][update=4MILLISECONDS][access=8MILLISECONDS]"},
+ {1, -2, -1, "[create=1MILLISECONDS]"},
+ {-1, 0, -1, "Eternal"},
+ {0, 1, -1, "[update=1MILLISECONDS]"}
+ });
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ cleanPersistenceDir();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ super.afterTestsStopped();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Test for {@link CacheView} expiry policy factory representation. The test initializes the {@link CacheConfiguration}
+ * with custom {@link PlatformExpiryPolicyFactory}. Given different ttl input, the test checks the {@link String}
+ * expiry policy factory outcome for {@link CacheView#expiryPolicyFactory()}.
+ */
+ @Test
+ public void testCacheViewExpiryPolicy() throws Exception {
+ try (IgniteEx g = startGrid()) {
+ CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>();
+ ccfg.setName("cache");
+ ccfg.setExpiryPolicyFactory(new PlatformExpiryPolicyFactory(create, update, access));
Review Comment:
`SingletonFactory` should be tested too.
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1620763541
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +263,114 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration. */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration. */
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info. */
+ private void testCacheViewExpiryPolicy(boolean withPersistence) throws Exception {
+ try (IgniteEx g = !withPersistence ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
+ )))) {
+
+ if (withPersistence)
+ g.cluster().state(ClusterState.ACTIVE);
+
+ String eternalCacheName = "eternalCache";
+ String createdCacheName = "createdCache";
+ String eagerTtlCacheName = "eagerTtlCache";
+ String withoutGrpCacheName = "withoutGrpCache";
+ String dfltCacheName = "defaultCache";
+
+ CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
+ .setGroupName("group1")
+ .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
+
+ CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
+ .setGroupName("group2")
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
+ .setGroupName("group2")
+ .setEagerTtl(false)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> dfltCache = new CacheConfiguration<Long, Long>(dfltCacheName)
+ .setGroupName("group3");
+
+ g.createCache(eternalCache);
+ g.createCache(createdCache);
+ g.createCache(eagerTtlCache);
+ g.createCache(withoutGrpCache);
+ g.createCache(dfltCache);
+
+ SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);
+
+ for (CacheView row : caches) {
+ switch (row.cacheName()) {
+ case "defaultCache":
+ case "eternalCache":
+ assertEquals("No", row.expiryPolicyEntry());
+
+ g.cache(row.cacheName()).put(0, 0);
+
+ assertEquals("No", row.expiryPolicyEntry());
+
+ g.cache(row.cacheName())
+ .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertEquals("Yes", row.expiryPolicyEntry());
+ assertTrue(waitForCondition(() -> row.expiryPolicyEntry().equals("No"), getTestTimeout()));
+
+ break;
+
+ case "createdCache":
+ assertEquals("No", row.expiryPolicyEntry());
+
+ g.cache(createdCacheName).put(0, 0);
+
+ assertEquals("Yes", row.expiryPolicyEntry());
+ assertTrue(waitForCondition(() -> row.expiryPolicyEntry().equals("No"), getTestTimeout()));
+
+ g.cache(createdCacheName)
+ .withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertEquals("Yes", row.expiryPolicyEntry());
+ assertTrue(waitForCondition(() -> row.expiryPolicyEntry().equals("No"), getTestTimeout()));
+
+ g.cache(eagerTtlCacheName).put(2, 2);
+ assertEquals("No", row.expiryPolicyEntry());
+
+ break;
+
+ case "eagerTtlCache":
+ assertEquals("Unknown", row.expiryPolicyEntry());
+
+ break;
+
+ case "withoutGrpCache":
+ assertEquals("There is no cache group related data", row.expiryPolicyEntry());
Review Comment:
Fixed it
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617500586
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java:
##########
@@ -1180,6 +1180,27 @@ private int expireInternal(
return pendingEntries != null ? pendingEntries.size() : 0;
}
+ /** {@inheritDoc} */
+ @Override public boolean hasEntriesPendingExpire() throws IgniteCheckedException {
+ return pendingEntries != null && !pendingEntries.isEmpty();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean hasEntriesPendingExpire(int cacheId) throws IgniteCheckedException {
+ if (pendingEntries != null) {
+ PendingRow row = new PendingRow(cacheId);
+
+ GridCursor<PendingRow> cursor = pendingEntries.find(row, row, PendingEntriesTree.WITHOUT_KEY);
Review Comment:
In a way, I used this field in `GridCacheOffheapManager#init0(boolean checkExists)`, which I invoked for "not shared group" case with `checkExists=true`
Maybe I've misinterpreted your comment. Can you elaborate?
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1620761239
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java:
##########
@@ -1180,6 +1180,18 @@ private int expireInternal(
return pendingEntries != null ? pendingEntries.size() : 0;
}
+ /** {@inheritDoc} */
+ @Override public boolean hasEntriesPendingExpire(int cacheId) throws IgniteCheckedException {
+ if (pendingEntries == null)
+ return false;
+
+ PendingRow row = new PendingRow(cacheId);
+
+ GridCursor<PendingRow> cursor = pendingEntries.find(row, row, PendingEntriesTree.WITHOUT_KEY);
Review Comment:
Fixed it
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java:
##########
@@ -2691,6 +2700,27 @@ public long expiredSize() throws IgniteCheckedException {
return delegate0 == null ? 0 : pendingTree.size();
}
+ /**
+ * Checks if the cache has entries pending expire.
+ *
+ * @return {@code True} if there are entries pending expire.
+ * @throws IgniteCheckedException If failed to get number of pending entries.
+ */
+ public boolean hasEntriesPendingExpire(int cacheId) throws IgniteCheckedException {
+ if (pendingTree == null)
+ return false;
+
+ PendingRow row = new PendingRow(cacheId);
+ GridCursor<PendingRow> cur;
+
+ if (grp.sharedGroup())
+ cur = pendingTree.find(row, row, PendingEntriesTree.WITHOUT_KEY);
+ else
+ return init0(true) != null && !pendingTree.isEmpty();
Review Comment:
Fixed it
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617533498
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
+ try (IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
+ )))) {
+
+ if (withPersistance)
+ g.cluster().state(ClusterState.ACTIVE);
+
+ String eternalCacheName = "eternalCache";
+ String createdCacheName = "createdCache";
+ String eagerTtlCacheName = "eagerTtlCache";
+ String withoutGrpCacheName = "withoutGrpCache";
+
+ CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
+ .setGroupName("group1")
+ .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
+
+ CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
+ .setGroupName("group2")
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
+ .setGroupName("group2")
+ .setEagerTtl(false)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
Review Comment:
Done!
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1628062036
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -344,26 +344,58 @@ public String expiryPolicyFactory() {
ExpiryPolicy expiryPlc = (ExpiryPolicy)cache.cacheConfiguration().getExpiryPolicyFactory().create();
- Function<Duration, String> func = (duration) -> {
- if (duration == null)
- return null;
+ AtomicBoolean first = new AtomicBoolean(true);
- return new StringBuilder()
- .append(duration.getDurationAmount())
- .append(' ')
- .append(duration.getTimeUnit() == null ? TimeUnit.MILLISECONDS : duration.getTimeUnit())
- .toString();
- };
+ StringBuilder expiryPlcStrBld = new StringBuilder(expiryPlc.getClass().getSimpleName());
- String expiryPlcStr = new StringBuilder(expiryPlc.getClass().getSimpleName())
- .append(" [create=").append(func.apply(expiryPlc.getExpiryForCreation()))
- .append(", update=").append(func.apply(expiryPlc.getExpiryForUpdate()))
- .append(", access=").append(func.apply(expiryPlc.getExpiryForAccess()))
- .append(']').toString();
+ appendField(expiryPlcStrBld, "create", expiryPlc::getExpiryForCreation, first);
+ appendField(expiryPlcStrBld, "update", expiryPlc::getExpiryForUpdate, first);
+ appendField(expiryPlcStrBld, "access", expiryPlc::getExpiryForAccess, first);
+
+ if (!first.get())
+ expiryPlcStrBld.append(']');
return S.toString((Class<Factory<?>>)cache.cacheConfiguration().getExpiryPolicyFactory().getClass(),
- cache.cacheConfiguration().getExpiryPolicyFactory(),
- "expiryPlc", expiryPlcStr);
+ cache.cacheConfiguration().getExpiryPolicyFactory(), "expiryPlc", expiryPlcStrBld);
+ }
+
+
+ /**
+ * @param out {@link StringBuilder} to append to.
+ * @param fieldName create/update/access expiry policy field name.
+ * @param durationSupplier Duration supplier for specified expiry policy field name.
+ * @param first {@link AtomicBoolean} flag indicating whether the field is the first in sequence.
+ */
+ private static void appendField(
+ StringBuilder out,
+ String fieldName,
+ Supplier<Duration> durationSupplier,
Review Comment:
`durationSupplier` is senseless, just use duration.
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -344,26 +344,58 @@ public String expiryPolicyFactory() {
ExpiryPolicy expiryPlc = (ExpiryPolicy)cache.cacheConfiguration().getExpiryPolicyFactory().create();
- Function<Duration, String> func = (duration) -> {
- if (duration == null)
- return null;
+ AtomicBoolean first = new AtomicBoolean(true);
- return new StringBuilder()
- .append(duration.getDurationAmount())
- .append(' ')
- .append(duration.getTimeUnit() == null ? TimeUnit.MILLISECONDS : duration.getTimeUnit())
- .toString();
- };
+ StringBuilder expiryPlcStrBld = new StringBuilder(expiryPlc.getClass().getSimpleName());
- String expiryPlcStr = new StringBuilder(expiryPlc.getClass().getSimpleName())
- .append(" [create=").append(func.apply(expiryPlc.getExpiryForCreation()))
- .append(", update=").append(func.apply(expiryPlc.getExpiryForUpdate()))
- .append(", access=").append(func.apply(expiryPlc.getExpiryForAccess()))
- .append(']').toString();
+ appendField(expiryPlcStrBld, "create", expiryPlc::getExpiryForCreation, first);
+ appendField(expiryPlcStrBld, "update", expiryPlc::getExpiryForUpdate, first);
+ appendField(expiryPlcStrBld, "access", expiryPlc::getExpiryForAccess, first);
+
+ if (!first.get())
+ expiryPlcStrBld.append(']');
return S.toString((Class<Factory<?>>)cache.cacheConfiguration().getExpiryPolicyFactory().getClass(),
- cache.cacheConfiguration().getExpiryPolicyFactory(),
- "expiryPlc", expiryPlcStr);
+ cache.cacheConfiguration().getExpiryPolicyFactory(), "expiryPlc", expiryPlcStrBld);
+ }
+
+
+ /**
+ * @param out {@link StringBuilder} to append to.
+ * @param fieldName create/update/access expiry policy field name.
+ * @param durationSupplier Duration supplier for specified expiry policy field name.
+ * @param first {@link AtomicBoolean} flag indicating whether the field is the first in sequence.
+ */
+ private static void appendField(
+ StringBuilder out,
+ String fieldName,
+ Supplier<Duration> durationSupplier,
+ AtomicBoolean first) {
Review Comment:
Put `) {` to the next line
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617459883
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheGroupDescriptor.java:
##########
@@ -56,6 +56,10 @@ public class CacheGroupDescriptor {
@GridToStringExclude
private volatile CacheConfiguration<?, ?> cacheCfg;
+ /** */
+ @GridToStringExclude
+ private volatile GridCacheProcessor cacheProc;
Review Comment:
Removed it
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617508281
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
Review Comment:
Fixed it
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
Review Comment:
Fixed the typo
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617533237
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
+ try (IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
+ )))) {
+
+ if (withPersistance)
+ g.cluster().state(ClusterState.ACTIVE);
+
+ String eternalCacheName = "eternalCache";
+ String createdCacheName = "createdCache";
+ String eagerTtlCacheName = "eagerTtlCache";
+ String withoutGrpCacheName = "withoutGrpCache";
+
+ CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
+ .setGroupName("group1")
+ .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
+
+ CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
+ .setGroupName("group2")
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
+ .setGroupName("group2")
+ .setEagerTtl(false)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ g.createCache(eternalCache);
+ g.createCache(createdCache);
+ g.createCache(eagerTtlCache);
+ g.createCache(withoutGrpCache);
+
+ SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);
+
+ for (CacheView row : caches) {
+ switch (row.cacheName()) {
+ case "eternalCache":
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
Review Comment:
Indeed. Refactored it
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1620762625
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +336,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();
Review Comment:
Added information about the factory as well
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617532158
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
+ try (IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
+ )))) {
+
+ if (withPersistance)
+ g.cluster().state(ClusterState.ACTIVE);
+
+ String eternalCacheName = "eternalCache";
+ String createdCacheName = "createdCache";
+ String eagerTtlCacheName = "eagerTtlCache";
+ String withoutGrpCacheName = "withoutGrpCache";
+
+ CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
+ .setGroupName("group1")
+ .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
+
+ CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
+ .setGroupName("group2")
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
+ .setGroupName("group2")
+ .setEagerTtl(false)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ g.createCache(eternalCache);
+ g.createCache(createdCache);
+ g.createCache(eagerTtlCache);
+ g.createCache(withoutGrpCache);
+
+ SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);
+
+ for (CacheView row : caches) {
+ switch (row.cacheName()) {
+ case "eternalCache":
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(eternalCacheName).put(0, 0);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(eternalCacheName)
+ .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ break;
+
+ case "createdCache":
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(createdCacheName).put(0, 0);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ g.cache(createdCacheName)
+ .withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ g.cache(eagerTtlCacheName).put(2, 2);
Review Comment:
Since the `IgniteCacheOffheapManager` relates group to all the caches within it, I wanted to make sure, that cache manipulation will not affect the other cache "expiry entries" flag from the same group.
From the group prospective (`CacheGroupView`), `CacheGroupContext's `IgniteCacheOffheapManager` instance will only relate to the first cache configuration after initialization, but all the other caches will still affect this instance (`IgniteCacheOffheapManager`), had they have been changed. This is anticipated. But, since we only looking on one cache independently from any cache from the same group, we don't want to see interference between the caches.
I just simply wanted to check that one cache doesn't affect the other.
WDYT?
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1618812044
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheGroupView.java:
##########
@@ -18,6 +18,7 @@
package org.apache.ignite.spi.systemview.view;
import java.util.Map;
+import org.apache.ignite.IgniteCheckedException;
Review Comment:
Redundant change
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheGroupView.java:
##########
@@ -26,6 +27,7 @@
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.TopologyValidator;
import org.apache.ignite.internal.managers.systemview.walker.Order;
+import org.apache.ignite.internal.processors.cache.CacheGroupContext;
Review Comment:
Redundant change
##########
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:
`SingletonFactory` created via `EternalExpiryPolicy.factoryOf` methods
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +336,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();
+
+ StringBuilder expiryPlcFactoryStrBld = new StringBuilder();
+
+ BiFunction<String, Duration, StringBuilder> func = (msg, duration) -> {
+ StringBuilder result = new StringBuilder();
+
+ if (duration == null || duration.getTimeUnit() == null || duration.getDurationAmount() == 0)
+ return result;
+
+ return result
+ .append('[').append(msg).append('=').append(duration.getDurationAmount())
+ .append(' ').append(duration.getTimeUnit()).append(']');
+ };
+
+ expiryPlcFactoryStrBld.append(func.apply("create", expiryPlc.getExpiryForCreation()));
+ expiryPlcFactoryStrBld.append(func.apply("update", expiryPlc.getExpiryForUpdate()));
+ expiryPlcFactoryStrBld.append(func.apply("access", expiryPlc.getExpiryForAccess()));
+
+ return expiryPlcFactoryStrBld.length() == 0 ? "Eternal" : expiryPlcFactoryStrBld.toString();
+ }
+
+ /** @return {@code Yes} if cache has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'. */
+ public String expiryPolicyEntry() {
Review Comment:
Perhaps, `hasExpiringEntries`?
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java:
##########
@@ -1180,6 +1180,18 @@ private int expireInternal(
return pendingEntries != null ? pendingEntries.size() : 0;
}
+ /** {@inheritDoc} */
+ @Override public boolean hasEntriesPendingExpire(int cacheId) throws IgniteCheckedException {
+ if (pendingEntries == null)
+ return false;
+
+ PendingRow row = new PendingRow(cacheId);
+
+ GridCursor<PendingRow> cursor = pendingEntries.find(row, row, PendingEntriesTree.WITHOUT_KEY);
Review Comment:
In case of !sharedGroup we should check only `isEmpty':
```
if (grp.sharedGroup()) {
PendingRow row = new PendingRow(cacheId);
GridCursor<PendingRow> cursor = pendingEntries.find(row, row, PendingEntriesTree.WITHOUT_KEY);
return cursor.next();
}
else
return !pendingEntries.isEmpty();
```
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +263,114 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration. */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration. */
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info. */
+ private void testCacheViewExpiryPolicy(boolean withPersistence) throws Exception {
+ try (IgniteEx g = !withPersistence ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
+ )))) {
+
+ if (withPersistence)
+ g.cluster().state(ClusterState.ACTIVE);
+
+ String eternalCacheName = "eternalCache";
+ String createdCacheName = "createdCache";
+ String eagerTtlCacheName = "eagerTtlCache";
+ String withoutGrpCacheName = "withoutGrpCache";
+ String dfltCacheName = "defaultCache";
+
+ CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
+ .setGroupName("group1")
+ .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
+
+ CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
+ .setGroupName("group2")
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
+ .setGroupName("group2")
+ .setEagerTtl(false)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> dfltCache = new CacheConfiguration<Long, Long>(dfltCacheName)
+ .setGroupName("group3");
+
+ g.createCache(eternalCache);
+ g.createCache(createdCache);
+ g.createCache(eagerTtlCache);
+ g.createCache(withoutGrpCache);
+ g.createCache(dfltCache);
+
+ SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);
+
+ for (CacheView row : caches) {
+ switch (row.cacheName()) {
+ case "defaultCache":
+ case "eternalCache":
+ assertEquals("No", row.expiryPolicyEntry());
+
+ g.cache(row.cacheName()).put(0, 0);
+
+ assertEquals("No", row.expiryPolicyEntry());
+
+ g.cache(row.cacheName())
+ .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertEquals("Yes", row.expiryPolicyEntry());
+ assertTrue(waitForCondition(() -> row.expiryPolicyEntry().equals("No"), getTestTimeout()));
+
+ break;
+
+ case "createdCache":
+ assertEquals("No", row.expiryPolicyEntry());
+
+ g.cache(createdCacheName).put(0, 0);
+
+ assertEquals("Yes", row.expiryPolicyEntry());
+ assertTrue(waitForCondition(() -> row.expiryPolicyEntry().equals("No"), getTestTimeout()));
+
+ g.cache(createdCacheName)
+ .withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertEquals("Yes", row.expiryPolicyEntry());
+ assertTrue(waitForCondition(() -> row.expiryPolicyEntry().equals("No"), getTestTimeout()));
+
+ g.cache(eagerTtlCacheName).put(2, 2);
+ assertEquals("No", row.expiryPolicyEntry());
+
+ break;
+
+ case "eagerTtlCache":
+ assertEquals("Unknown", row.expiryPolicyEntry());
+
+ break;
+
+ case "withoutGrpCache":
+ assertEquals("There is no cache group related data", row.expiryPolicyEntry());
Review Comment:
It's not correct, here cache group is created with `sharedGroup == false` flag.
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheOffheapManager.java:
##########
@@ -2691,6 +2700,27 @@ public long expiredSize() throws IgniteCheckedException {
return delegate0 == null ? 0 : pendingTree.size();
}
+ /**
+ * Checks if the cache has entries pending expire.
+ *
+ * @return {@code True} if there are entries pending expire.
+ * @throws IgniteCheckedException If failed to get number of pending entries.
+ */
+ public boolean hasEntriesPendingExpire(int cacheId) throws IgniteCheckedException {
+ if (pendingTree == null)
+ return false;
+
+ PendingRow row = new PendingRow(cacheId);
+ GridCursor<PendingRow> cur;
+
+ if (grp.sharedGroup())
+ cur = pendingTree.find(row, row, PendingEntriesTree.WITHOUT_KEY);
+ else
+ return init0(true) != null && !pendingTree.isEmpty();
Review Comment:
If store is not inited, than `pendingTree == null`, so we can't reach this line.
We don't need to construct row in case of not shared group, let's refactor to something like this:
```
if (grp.sharedGroup()) {
PendingRow row = new PendingRow(cacheId);
GridCursor<PendingRow> cur = pendingTree.find(row, row, PendingEntriesTree.WITHOUT_KEY);
return cur.next();
}
else
return !pendingTree.isEmpty();
```
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +336,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();
+
+ StringBuilder expiryPlcFactoryStrBld = new StringBuilder();
+
+ BiFunction<String, Duration, StringBuilder> func = (msg, duration) -> {
+ StringBuilder result = new StringBuilder();
+
+ if (duration == null || duration.getTimeUnit() == null || duration.getDurationAmount() == 0)
+ return result;
+
+ return result
+ .append('[').append(msg).append('=').append(duration.getDurationAmount())
+ .append(' ').append(duration.getTimeUnit()).append(']');
+ };
+
+ expiryPlcFactoryStrBld.append(func.apply("create", expiryPlc.getExpiryForCreation()));
+ expiryPlcFactoryStrBld.append(func.apply("update", expiryPlc.getExpiryForUpdate()));
+ expiryPlcFactoryStrBld.append(func.apply("access", expiryPlc.getExpiryForAccess()));
+
+ return expiryPlcFactoryStrBld.length() == 0 ? "Eternal" : expiryPlcFactoryStrBld.toString();
+ }
+
+ /** @return {@code Yes} if cache has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'. */
+ public String expiryPolicyEntry() {
+ CacheGroupContext grpCtx = ctx.cache().cacheGroup(cache.groupId());
+
+ if (!cache.cacheConfiguration().isEagerTtl() || grpCtx == null)
+ return "Unknown";
+ else if (grpCtx.name() == null)
+ return "There is no cache group related data";
Review Comment:
Looks like this is case for `!sharedGroup`
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +336,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();
Review Comment:
We should also expose information about factory (according to method name)
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1628090284
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -344,26 +344,58 @@ public String expiryPolicyFactory() {
ExpiryPolicy expiryPlc = (ExpiryPolicy)cache.cacheConfiguration().getExpiryPolicyFactory().create();
- Function<Duration, String> func = (duration) -> {
- if (duration == null)
- return null;
+ AtomicBoolean first = new AtomicBoolean(true);
- return new StringBuilder()
- .append(duration.getDurationAmount())
- .append(' ')
- .append(duration.getTimeUnit() == null ? TimeUnit.MILLISECONDS : duration.getTimeUnit())
- .toString();
- };
+ StringBuilder expiryPlcStrBld = new StringBuilder(expiryPlc.getClass().getSimpleName());
- String expiryPlcStr = new StringBuilder(expiryPlc.getClass().getSimpleName())
- .append(" [create=").append(func.apply(expiryPlc.getExpiryForCreation()))
- .append(", update=").append(func.apply(expiryPlc.getExpiryForUpdate()))
- .append(", access=").append(func.apply(expiryPlc.getExpiryForAccess()))
- .append(']').toString();
+ appendField(expiryPlcStrBld, "create", expiryPlc::getExpiryForCreation, first);
+ appendField(expiryPlcStrBld, "update", expiryPlc::getExpiryForUpdate, first);
+ appendField(expiryPlcStrBld, "access", expiryPlc::getExpiryForAccess, first);
+
+ if (!first.get())
+ expiryPlcStrBld.append(']');
return S.toString((Class<Factory<?>>)cache.cacheConfiguration().getExpiryPolicyFactory().getClass(),
- cache.cacheConfiguration().getExpiryPolicyFactory(),
- "expiryPlc", expiryPlcStr);
+ cache.cacheConfiguration().getExpiryPolicyFactory(), "expiryPlc", expiryPlcStrBld);
+ }
+
+
+ /**
+ * @param out {@link StringBuilder} to append to.
+ * @param fieldName create/update/access expiry policy field name.
+ * @param durationSupplier Duration supplier for specified expiry policy field name.
+ * @param first {@link AtomicBoolean} flag indicating whether the field is the first in sequence.
+ */
+ private static void appendField(
+ StringBuilder out,
+ String fieldName,
+ Supplier<Duration> durationSupplier,
+ AtomicBoolean first) {
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -344,26 +344,58 @@ public String expiryPolicyFactory() {
ExpiryPolicy expiryPlc = (ExpiryPolicy)cache.cacheConfiguration().getExpiryPolicyFactory().create();
- Function<Duration, String> func = (duration) -> {
- if (duration == null)
- return null;
+ AtomicBoolean first = new AtomicBoolean(true);
- return new StringBuilder()
- .append(duration.getDurationAmount())
- .append(' ')
- .append(duration.getTimeUnit() == null ? TimeUnit.MILLISECONDS : duration.getTimeUnit())
- .toString();
- };
+ StringBuilder expiryPlcStrBld = new StringBuilder(expiryPlc.getClass().getSimpleName());
- String expiryPlcStr = new StringBuilder(expiryPlc.getClass().getSimpleName())
- .append(" [create=").append(func.apply(expiryPlc.getExpiryForCreation()))
- .append(", update=").append(func.apply(expiryPlc.getExpiryForUpdate()))
- .append(", access=").append(func.apply(expiryPlc.getExpiryForAccess()))
- .append(']').toString();
+ appendField(expiryPlcStrBld, "create", expiryPlc::getExpiryForCreation, first);
+ appendField(expiryPlcStrBld, "update", expiryPlc::getExpiryForUpdate, first);
+ appendField(expiryPlcStrBld, "access", expiryPlc::getExpiryForAccess, first);
+
+ if (!first.get())
+ expiryPlcStrBld.append(']');
return S.toString((Class<Factory<?>>)cache.cacheConfiguration().getExpiryPolicyFactory().getClass(),
- cache.cacheConfiguration().getExpiryPolicyFactory(),
- "expiryPlc", expiryPlcStr);
+ cache.cacheConfiguration().getExpiryPolicyFactory(), "expiryPlc", expiryPlcStrBld);
+ }
+
+
+ /**
+ * @param out {@link StringBuilder} to append to.
+ * @param fieldName create/update/access expiry policy field name.
+ * @param durationSupplier Duration supplier for specified expiry policy field name.
+ * @param first {@link AtomicBoolean} flag indicating whether the field is the first in sequence.
+ */
+ private static void appendField(
+ StringBuilder out,
+ String fieldName,
+ Supplier<Duration> durationSupplier,
Review Comment:
Done!
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1627886110
##########
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:
Tried to reduce the number of Strings in favor of StringBuilder. Added checks for `ETERNAL` and `ZERO` durations. Refactored the logic for `ExpiryPolicy` string representation to take into account nulls
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617458317
##########
modules/core/src/main/java/org/apache/ignite/internal/managers/systemview/walker/CacheViewWalker.java:
##########
@@ -97,6 +97,7 @@ public class CacheViewWalker implements SystemViewRowAttributeWalker<CacheView>
v.accept(59, "writeBehindFlushSize", int.class);
v.accept(60, "writeBehindFlushThreadCount", int.class);
v.accept(61, "writeSynchronizationMode", CacheWriteSynchronizationMode.class);
+ v.accept(62, "hasEntriesPendingExpire", String.class);
Review Comment:
Refactered CacheGroupView and CacheView. Regenerated this part of the code and checked the tests. For now it is fixed
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617445824
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheGroupView.java:
##########
@@ -150,4 +152,21 @@ public int rebalanceOrder() {
public int backups() {
return ccfg.getBackups();
}
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
Review Comment:
Removed it
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617507233
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
+ try (IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
Review Comment:
I don't think so. There is a ternanry conditional operator inside the try
`IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration()...`
Nevertheless, I checked the configuration for each case (`withPersistance = true/false`), the falg is working correctly
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617533782
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
Review Comment:
Refactored it
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617548390
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewCacheExpiryPolicyTest.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.expiry.Duration;
+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 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 {
+ /**Create ttl {@link Duration}*/
+ @Parameterized.Parameter
+ public long create;
+
+ /** Access ttl {@link Duration}*/
+ @Parameterized.Parameter(1)
+ public long update;
+
+ /** Update ttl {@link Duration}*/
+ @Parameterized.Parameter(2)
+ public long access;
+
+ /** Anticipated {@link String} expiry policy factory representation*/
+ @Parameterized.Parameter(3)
+ public String actual;
+
+ /**
+ * @return Test parameters.
+ */
+ @Parameterized.Parameters(name = "create={0}, update={1}, access={2}, actual={3}")
+ public static Collection parameters() {
+ return Arrays.asList(new Object[][] {
+ {2, 4, 8, "[create=2MILLISECONDS][update=4MILLISECONDS][access=8MILLISECONDS]"},
+ {1, -2, -1, "[create=1MILLISECONDS]"},
+ {-1, 0, -1, "Eternal"},
+ {0, 1, -1, "[update=1MILLISECONDS]"}
+ });
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ cleanPersistenceDir();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ super.afterTestsStopped();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Test for {@link CacheView} expiry policy factory representation. The test initializes the {@link CacheConfiguration}
+ * with custom {@link PlatformExpiryPolicyFactory}. Given different ttl input, the test checks the {@link String}
+ * expiry policy factory outcome for {@link CacheView#expiryPolicyFactory()}.
+ */
+ @Test
+ public void testCacheViewExpiryPolicy() throws Exception {
+ try (IgniteEx g = startGrid()) {
+ CacheConfiguration<Integer, Integer> ccfg = new CacheConfiguration<>();
+ ccfg.setName("cache");
+ ccfg.setExpiryPolicyFactory(new PlatformExpiryPolicyFactory(create, update, access));
Review Comment:
Added other factories to the test
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit closed pull request #11357: IGNITE-22189 expiry policy info in CacheView and CacheGroupView
URL: https://github.com/apache/ignite/pull/11357
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617534048
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
+ }
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
+ CacheGroupContext grpCtx = ctx.cache().cacheGroup(cache.groupId());
+
+ if (!cache.cacheConfiguration().isEagerTtl() || grpCtx == null || grpCtx.name() == null)
+ return "Unknown";
+
+ try {
+ return grpCtx.offheap().hasEntriesPendingExpire(cache.cacheId()) ? "Yes" : "No";
+ }
+ catch (IgniteCheckedException e) {
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * Returns {@link Duration} String representation with description
+ * @param msg descriptive message for {@link Duration} instance
+ * @param duration @link Duration}
+ * @return {@link Duration} representation with descriptive message
Review Comment:
Fixed the typo
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617501258
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewCacheExpiryPolicyTest.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.expiry.Duration;
+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 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 {
+ /**Create ttl {@link Duration}*/
+ @Parameterized.Parameter
+ public long create;
+
+ /** Access ttl {@link Duration}*/
+ @Parameterized.Parameter(1)
+ public long update;
+
+ /** Update ttl {@link Duration}*/
+ @Parameterized.Parameter(2)
+ public long access;
+
+ /** Anticipated {@link String} expiry policy factory representation*/
+ @Parameterized.Parameter(3)
+ public String actual;
+
+ /**
+ * @return Test parameters.
+ */
+ @Parameterized.Parameters(name = "create={0}, update={1}, access={2}, actual={3}")
+ public static Collection parameters() {
+ return Arrays.asList(new Object[][] {
+ {2, 4, 8, "[create=2MILLISECONDS][update=4MILLISECONDS][access=8MILLISECONDS]"},
+ {1, -2, -1, "[create=1MILLISECONDS]"},
+ {-1, 0, -1, "Eternal"},
+ {0, 1, -1, "[update=1MILLISECONDS]"}
+ });
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ cleanPersistenceDir();
Review Comment:
Removed them
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617464480
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheOffheapManagerImpl.java:
##########
@@ -1180,6 +1180,27 @@ private int expireInternal(
return pendingEntries != null ? pendingEntries.size() : 0;
}
+ /** {@inheritDoc} */
+ @Override public boolean hasEntriesPendingExpire() throws IgniteCheckedException {
+ return pendingEntries != null && !pendingEntries.isEmpty();
+ }
+
+ /** {@inheritDoc} */
+ @Override public boolean hasEntriesPendingExpire(int cacheId) throws IgniteCheckedException {
+ if (pendingEntries != null) {
+ PendingRow row = new PendingRow(cacheId);
+
+ GridCursor<PendingRow> cursor = pendingEntries.find(row, row, PendingEntriesTree.WITHOUT_KEY);
+
+ while (cursor.next()) {
+ if (pendingEntries.findOne(cursor.get()) != null)
Review Comment:
It's an overcoding from my side. I refactored this part
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1620760641
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheGroupView.java:
##########
@@ -18,6 +18,7 @@
package org.apache.ignite.spi.systemview.view;
import java.util.Map;
+import org.apache.ignite.IgniteCheckedException;
Review Comment:
Fixed it
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheGroupView.java:
##########
@@ -26,6 +27,7 @@
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.TopologyValidator;
import org.apache.ignite.internal.managers.systemview.walker.Order;
+import org.apache.ignite.internal.processors.cache.CacheGroupContext;
Review Comment:
Fixed it
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1620763041
##########
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:
Added additional test cases
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1627874645
##########
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:
Removed additional cases. Fixed constructors: removed 'new' to EternalExpiryPolicy().factoryof()
##########
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:
Fixed
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617532158
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
+ try (IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
+ )))) {
+
+ if (withPersistance)
+ g.cluster().state(ClusterState.ACTIVE);
+
+ String eternalCacheName = "eternalCache";
+ String createdCacheName = "createdCache";
+ String eagerTtlCacheName = "eagerTtlCache";
+ String withoutGrpCacheName = "withoutGrpCache";
+
+ CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
+ .setGroupName("group1")
+ .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
+
+ CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
+ .setGroupName("group2")
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
+ .setGroupName("group2")
+ .setEagerTtl(false)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ g.createCache(eternalCache);
+ g.createCache(createdCache);
+ g.createCache(eagerTtlCache);
+ g.createCache(withoutGrpCache);
+
+ SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);
+
+ for (CacheView row : caches) {
+ switch (row.cacheName()) {
+ case "eternalCache":
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(eternalCacheName).put(0, 0);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(eternalCacheName)
+ .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ break;
+
+ case "createdCache":
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(createdCacheName).put(0, 0);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ g.cache(createdCacheName)
+ .withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ g.cache(eagerTtlCacheName).put(2, 2);
Review Comment:
Since the `IgniteCacheOffheapManager` relates group to all the caches within it, I wanted to make sure, that cache manipulation will not affect the other cache "expiry entries" flag from the same group.
From the group prospective (`CacheGroupView`), `CacheGroupContext`'s `IgniteCacheOffheapManager` instance will only relate to the first cache configuration after initialization, but all the other caches will still affect this instance (`IgniteCacheOffheapManager`), had they have been changed. This is anticipated. But, since we only looking on one cache independently from any cache from the same group, we don't want to see interference between the caches.
I just simply wanted to check that one cache doesn't affect the other.
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617508681
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
Review Comment:
Fixed the typo
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
Review Comment:
Fixed the typo
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617487137
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
+ }
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
+ CacheGroupContext grpCtx = ctx.cache().cacheGroup(cache.groupId());
+
+ if (!cache.cacheConfiguration().isEagerTtl() || grpCtx == null || grpCtx.name() == null)
Review Comment:
I thought it is convinient to group all the cases together under '_Unknown_' message. Since there is no group data, we can not know for sure if there are any entries pending expiration. I separeted this case with the message:
_"There is no cache group related data"_
WDYT?
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617532158
##########
modules/core/src/test/java/org/apache/ignite/internal/metric/SystemViewSelfTest.java:
##########
@@ -259,6 +264,215 @@ public void testCacheGroupsView() throws Exception {
}
}
+ /** Tests work of {@link SystemView} for cache expiry policy info with in-memory configuration */
+ @Test
+ public void testCacheViewExpiryPolicyWithInMemory() throws Exception {
+ testCacheViewExpiryPolicy(false);
+ }
+
+ /** Tests work of {@link SystemView} for cache expiry policy info with persist configuration*/
+ @Test
+ public void testCacheViewExpiryPolicyWithPersist() throws Exception {
+ testCacheViewExpiryPolicy(true);
+ }
+
+ /** Tests work of {@link SystemView} for cache groups expiry policy info */
+ private void testCacheViewExpiryPolicy(boolean withPersistance) throws Exception {
+ try (IgniteEx g = !withPersistance ? startGrid() : startGrid(getConfiguration().setDataStorageConfiguration(
+ new DataStorageConfiguration().setDefaultDataRegionConfiguration(
+ new DataRegionConfiguration().setPersistenceEnabled(true)
+ )))) {
+
+ if (withPersistance)
+ g.cluster().state(ClusterState.ACTIVE);
+
+ String eternalCacheName = "eternalCache";
+ String createdCacheName = "createdCache";
+ String eagerTtlCacheName = "eagerTtlCache";
+ String withoutGrpCacheName = "withoutGrpCache";
+
+ CacheConfiguration<Long, Long> eternalCache = new CacheConfiguration<Long, Long>(eternalCacheName)
+ .setGroupName("group1")
+ .setExpiryPolicyFactory(EternalExpiryPolicy.factoryOf());
+
+ CacheConfiguration<Long, Long> createdCache = new CacheConfiguration<Long, Long>(createdCacheName)
+ .setGroupName("group2")
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> eagerTtlCache = new CacheConfiguration<Long, Long>(eagerTtlCacheName)
+ .setGroupName("group2")
+ .setEagerTtl(false)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ CacheConfiguration<Long, Long> withoutGrpCache = new CacheConfiguration<Long, Long>(withoutGrpCacheName)
+ .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 500L)));
+
+ g.createCache(eternalCache);
+ g.createCache(createdCache);
+ g.createCache(eagerTtlCache);
+ g.createCache(withoutGrpCache);
+
+ SystemView<CacheView> caches = g.context().systemView().view(CACHES_VIEW);
+
+ for (CacheView row : caches) {
+ switch (row.cacheName()) {
+ case "eternalCache":
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(eternalCacheName).put(0, 0);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(eternalCacheName)
+ .withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ break;
+
+ case "createdCache":
+ assertTrue(row.hasEntriesPendingExpire().equals("No"));
+
+ g.cache(createdCacheName).put(0, 0);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ g.cache(createdCacheName)
+ .withExpiryPolicy(new ModifiedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, 200L)))
+ .put(1, 1);
+
+ assertTrue(row.hasEntriesPendingExpire().equals("Yes"));
+ assertTrue(waitForCondition(() -> row.hasEntriesPendingExpire().equals("No"), getTestTimeout()));
+
+ g.cache(eagerTtlCacheName).put(2, 2);
Review Comment:
Since the `IgniteCacheOffheapManager` relates group to all the caches within it, I wanted to make sure, that cache manipulation will not affect the other cache "expiry entries" flag from the same group.
From the group prospective (`CacheGroupView`), `CacheGroupContext`'s `IgniteCacheOffheapManager` instance will only relate to the first cache configuration after initialization, but all the other caches will still affect this instance (`IgniteCacheOffheapManager`), had they have been changed. This is anticipated. But, since we only looking on one cache independently from any cache from the same group, we don't want to see interference between the caches.
I just simply wanted to check that one cache doesn't affect the other.
WDYT?
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1617535786
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +335,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();
+
+ String expiryPlcFactoryStr = "";
+
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("create", expiryPlc.getExpiryForCreation());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("update", expiryPlc.getExpiryForUpdate());
+ expiryPlcFactoryStr += durationToStringWithCustomMessage("access", expiryPlc.getExpiryForAccess());
+
+ return expiryPlcFactoryStr.equals("") ? "Eternal" : expiryPlcFactoryStr;
+ }
+
+ /** @return {@code Yes} if group has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'*/
+ public String hasEntriesPendingExpire() {
+ CacheGroupContext grpCtx = ctx.cache().cacheGroup(cache.groupId());
+
+ if (!cache.cacheConfiguration().isEagerTtl() || grpCtx == null || grpCtx.name() == null)
+ return "Unknown";
+
+ try {
+ return grpCtx.offheap().hasEntriesPendingExpire(cache.cacheId()) ? "Yes" : "No";
+ }
+ catch (IgniteCheckedException e) {
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * Returns {@link Duration} String representation with description
+ * @param msg descriptive message for {@link Duration} instance
+ * @param duration @link Duration}
+ * @return {@link Duration} representation with descriptive message
+ */
+ public String durationToStringWithCustomMessage(String msg, Duration duration) {
Review Comment:
Decided to remove the method completly, since the generator treats it as independent output for which it thinks there will be a column.
--
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
Re: [PR] IGNITE-22189 expiry policy info in CacheView and CacheGroupView [ignite]
Posted by "maksaska (via GitHub)" <gi...@apache.org>.
maksaska commented on code in PR #11357:
URL: https://github.com/apache/ignite/pull/11357#discussion_r1620761818
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +336,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();
+
+ StringBuilder expiryPlcFactoryStrBld = new StringBuilder();
+
+ BiFunction<String, Duration, StringBuilder> func = (msg, duration) -> {
+ StringBuilder result = new StringBuilder();
+
+ if (duration == null || duration.getTimeUnit() == null || duration.getDurationAmount() == 0)
+ return result;
+
+ return result
+ .append('[').append(msg).append('=').append(duration.getDurationAmount())
+ .append(' ').append(duration.getTimeUnit()).append(']');
+ };
+
+ expiryPlcFactoryStrBld.append(func.apply("create", expiryPlc.getExpiryForCreation()));
+ expiryPlcFactoryStrBld.append(func.apply("update", expiryPlc.getExpiryForUpdate()));
+ expiryPlcFactoryStrBld.append(func.apply("access", expiryPlc.getExpiryForAccess()));
+
+ return expiryPlcFactoryStrBld.length() == 0 ? "Eternal" : expiryPlcFactoryStrBld.toString();
+ }
+
+ /** @return {@code Yes} if cache has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'. */
+ public String expiryPolicyEntry() {
Review Comment:
Yep. It's more informative
##########
modules/core/src/main/java/org/apache/ignite/spi/systemview/view/CacheView.java:
##########
@@ -331,7 +336,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();
+
+ StringBuilder expiryPlcFactoryStrBld = new StringBuilder();
+
+ BiFunction<String, Duration, StringBuilder> func = (msg, duration) -> {
+ StringBuilder result = new StringBuilder();
+
+ if (duration == null || duration.getTimeUnit() == null || duration.getDurationAmount() == 0)
+ return result;
+
+ return result
+ .append('[').append(msg).append('=').append(duration.getDurationAmount())
+ .append(' ').append(duration.getTimeUnit()).append(']');
+ };
+
+ expiryPlcFactoryStrBld.append(func.apply("create", expiryPlc.getExpiryForCreation()));
+ expiryPlcFactoryStrBld.append(func.apply("update", expiryPlc.getExpiryForUpdate()));
+ expiryPlcFactoryStrBld.append(func.apply("access", expiryPlc.getExpiryForAccess()));
+
+ return expiryPlcFactoryStrBld.length() == 0 ? "Eternal" : expiryPlcFactoryStrBld.toString();
+ }
+
+ /** @return {@code Yes} if cache has expired entries, {@code No} otherwise. If {@code eagerTtl = true} returns 'Unknown'. */
+ public String expiryPolicyEntry() {
+ CacheGroupContext grpCtx = ctx.cache().cacheGroup(cache.groupId());
+
+ if (!cache.cacheConfiguration().isEagerTtl() || grpCtx == null)
+ return "Unknown";
+ else if (grpCtx.name() == null)
+ return "There is no cache group related data";
Review Comment:
Fixed it
--
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