anton-vinogradov commented on code in PR #13447:
URL: https://github.com/apache/ignite/pull/13447#discussion_r3752369656
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java:
##########
@@ -64,58 +68,70 @@ public class GridCacheEntryInfo implements
SelfMarshallingMessage, CacheIdAware
/** Deleted flag. */
private boolean deleted;
- /** {@inheritDoc} */
- @Override public int cacheId() {
- return cacheId;
- }
-
/**
- * @param cacheId Cache ID.
+ * Empty constructor for serialization purposes.
+ * see {@link #expireTimeDelta}.
*/
- public void cacheId(int cacheId) {
+ public GridCacheEntryInfo() {
+ initTime = U.currentTimeMillis();
+ }
+
+ /** */
+ public GridCacheEntryInfo(int cacheId, KeyCacheObject key, @Nullable
CacheObject val, GridCacheVersion ver, long expireTime, long ttl) {
+ assert expireTime >= 0;
+
+ if (expireTime != 0) {
+ initTime = U.currentTimeMillis();
+
+ expireTimeDelta = expireTime - initTime;
+
+ // In theory, here we can get the thread paused causing a negative
delta value. Possible negative values
+ // shouldn't be treated as disabled expiration. Correct behavior
is expired timeout.
+ if (expireTimeDelta < 0)
+ expireTimeDelta = 0;
Review Comment:
Do we need a warning here?
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java:
##########
@@ -64,58 +68,70 @@ public class GridCacheEntryInfo implements
SelfMarshallingMessage, CacheIdAware
/** Deleted flag. */
private boolean deleted;
- /** {@inheritDoc} */
- @Override public int cacheId() {
- return cacheId;
- }
-
/**
- * @param cacheId Cache ID.
+ * Empty constructor for serialization purposes.
+ * see {@link #expireTimeDelta}.
*/
- public void cacheId(int cacheId) {
+ public GridCacheEntryInfo() {
+ initTime = U.currentTimeMillis();
+ }
+
+ /** */
+ public GridCacheEntryInfo(int cacheId, KeyCacheObject key, @Nullable
CacheObject val, GridCacheVersion ver, long expireTime, long ttl) {
+ assert expireTime >= 0;
+
+ if (expireTime != 0) {
+ initTime = U.currentTimeMillis();
+
+ expireTimeDelta = expireTime - initTime;
+
+ // In theory, here we can get the thread paused causing a negative
delta value. Possible negative values
+ // shouldn't be treated as disabled expiration. Correct behavior
is expired timeout.
+ if (expireTimeDelta < 0)
+ expireTimeDelta = 0;
+ }
+
this.cacheId = cacheId;
+ this.key = key;
+ this.val = val;
+ this.ver = ver;
+ this.ttl = ttl;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int cacheId() {
+ return cacheId;
}
/**
* @param key Entry key.
*/
- public void key(KeyCacheObject key) {
+ public void key(@Nullable KeyCacheObject key) {
this.key = key;
}
/**
* @return Entry key.
*/
- public KeyCacheObject key() {
+ @Nullable public KeyCacheObject key() {
return key;
}
/**
* @return Entry value.
*/
- public CacheObject value() {
+ public @Nullable CacheObject value() {
return val;
}
/**
- * @param val Entry value.
- */
- public void value(CacheObject val) {
- this.val = val;
- }
-
- /**
- * @return Expire time.
+ * @return Expire time >= 0. 0 means no expiration is set.
*/
public long expireTime() {
- return expireTime;
- }
+ assert initTime > 0;
+ assert expireTimeDelta >= -1L;
Review Comment:
Asserts give us nothing in prod.
Should be solved by logic, not by asserts.
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java:
##########
@@ -64,58 +68,70 @@ public class GridCacheEntryInfo implements
SelfMarshallingMessage, CacheIdAware
/** Deleted flag. */
private boolean deleted;
- /** {@inheritDoc} */
- @Override public int cacheId() {
- return cacheId;
- }
-
/**
- * @param cacheId Cache ID.
+ * Empty constructor for serialization purposes.
+ * see {@link #expireTimeDelta}.
*/
- public void cacheId(int cacheId) {
+ public GridCacheEntryInfo() {
+ initTime = U.currentTimeMillis();
+ }
+
+ /** */
+ public GridCacheEntryInfo(int cacheId, KeyCacheObject key, @Nullable
CacheObject val, GridCacheVersion ver, long expireTime, long ttl) {
+ assert expireTime >= 0;
+
+ if (expireTime != 0) {
+ initTime = U.currentTimeMillis();
+
+ expireTimeDelta = expireTime - initTime;
+
+ // In theory, here we can get the thread paused causing a negative
delta value. Possible negative values
+ // shouldn't be treated as disabled expiration. Correct behavior
is expired timeout.
+ if (expireTimeDelta < 0)
+ expireTimeDelta = 0;
+ }
+
this.cacheId = cacheId;
+ this.key = key;
+ this.val = val;
+ this.ver = ver;
+ this.ttl = ttl;
+ }
+
+ /** {@inheritDoc} */
+ @Override public int cacheId() {
+ return cacheId;
}
/**
* @param key Entry key.
*/
- public void key(KeyCacheObject key) {
+ public void key(@Nullable KeyCacheObject key) {
this.key = key;
}
/**
* @return Entry key.
*/
- public KeyCacheObject key() {
+ @Nullable public KeyCacheObject key() {
return key;
}
/**
* @return Entry value.
*/
- public CacheObject value() {
+ public @Nullable CacheObject value() {
return val;
}
/**
- * @param val Entry value.
- */
- public void value(CacheObject val) {
- this.val = val;
- }
-
- /**
- * @return Expire time.
+ * @return Expire time >= 0. 0 means no expiration is set.
*/
public long expireTime() {
- return expireTime;
- }
+ assert initTime > 0;
+ assert expireTimeDelta >= -1L;
- /**
- * @param expireTime Expiration time.
- */
- public void expireTime(long expireTime) {
- this.expireTime = expireTime;
+ return expireTimeDelta == -1L ? 0L : initTime + expireTimeDelta;
Review Comment:
Possible negative number without handling.
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEntryInfo.java:
##########
@@ -64,58 +68,70 @@ public class GridCacheEntryInfo implements
SelfMarshallingMessage, CacheIdAware
/** Deleted flag. */
private boolean deleted;
- /** {@inheritDoc} */
- @Override public int cacheId() {
- return cacheId;
- }
-
/**
- * @param cacheId Cache ID.
+ * Empty constructor for serialization purposes.
+ * see {@link #expireTimeDelta}.
*/
- public void cacheId(int cacheId) {
+ public GridCacheEntryInfo() {
+ initTime = U.currentTimeMillis();
Review Comment:
Do we need initTime always, even when expireTime == 0?
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMapEntry.java:
##########
@@ -396,23 +396,14 @@ protected GridDhtLocalPartition localPartition() {
try {
if (!obsolete()) {
- info = new GridCacheEntryInfo();
-
- info.key(key);
- info.cacheId(cctx.cacheId());
-
long expireTime = expireTimeExtras();
- boolean expired = expireTime != 0 && expireTime <=
U.currentTimeMillis();
+ CacheObject val0 = expireTime == 0 || expireTime >
U.currentTimeMillis() ? val : null;
Review Comment:
Should expireTime be transferred to GridCacheEntryInfo to make a clear
decision once?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]