-
Notifications
You must be signed in to change notification settings - Fork 695
GEODE-3764: prevent early idle expiration #940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,15 +121,21 @@ public long getTTLExpirationTime() throws EntryNotFoundException { | |
|
|
||
| /** Return the absolute time when idle expiration occurs, or 0 if not used */ | ||
| public long getIdleExpirationTime() throws EntryNotFoundException { | ||
| long idle = getIdleTimeoutInMillis(); | ||
| if (idle > 0) { | ||
| return getLastAccessedTime() + idle; | ||
| } | ||
| return 0L; | ||
| } | ||
|
|
||
| protected long getIdleTimeoutInMillis() { | ||
| long idle = getIdleAttributes().getTimeout(); | ||
| long tilt = 0; | ||
| if (idle > 0) { | ||
| if (getLocalRegion() != null && !getLocalRegion().EXPIRY_UNITS_MS) { | ||
| idle *= 1000; | ||
| } | ||
| tilt = getLastAccessedTime() + idle; | ||
| } | ||
| return tilt; | ||
| return idle; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -149,12 +155,33 @@ long getExpiryMillis() throws EntryNotFoundException { | |
| */ | ||
| protected boolean isExpirationPossible() throws EntryNotFoundException { | ||
| long expTime = getExpirationTime(); | ||
| if (expTime > 0L && getNow() >= expTime) { | ||
| return true; | ||
| if (expTime > 0L) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What should happen if expiration is due to ttl?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then it is okay to just expire based on the local information.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dschneider-pivotal Thanks Darrel. I thought the same that we should be expiring if its TTL. |
||
| long now = getNow(); | ||
| if (now >= expTime) { | ||
| if (isIdleExpiredOnOthers()) { | ||
| return true; | ||
| } else { | ||
| // our last access time was reset so recheck | ||
| expTime = getExpirationTime(); | ||
| if (expTime > 0L && now >= expTime) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Added for GEODE-3764. | ||
| * | ||
| * @return true if other members last access time indicates we have expired | ||
| */ | ||
| protected boolean isIdleExpiredOnOthers() throws EntryNotFoundException { | ||
| // by default return true since we don't need to check with others | ||
| return true; | ||
| } | ||
|
|
||
| /** | ||
| * Returns false if the region reliability state does not allow this expiry task to fire. | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| * 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.geode.internal.cache; | ||
|
|
||
| public interface InternalDistributedRegion<K, V> | ||
| extends InternalRegion<K, V>, CacheDistributionAdvisee { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * 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.geode.internal.cache; | ||
|
|
||
| import java.io.DataInput; | ||
| import java.io.DataOutput; | ||
| import java.io.IOException; | ||
| import java.util.Set; | ||
|
|
||
| import org.apache.geode.DataSerializer; | ||
| import org.apache.geode.distributed.internal.DistributionManager; | ||
| import org.apache.geode.distributed.internal.MessageWithReply; | ||
| import org.apache.geode.distributed.internal.PooledDistributionMessage; | ||
| import org.apache.geode.distributed.internal.ReplyMessage; | ||
| import org.apache.geode.distributed.internal.membership.InternalDistributedMember; | ||
| import org.apache.geode.internal.InternalStatisticsDisabledException; | ||
|
|
||
| /** | ||
| * Sends the region name and key of the entry that we want the last access time for. If for any | ||
| * reason this message can not obtain the last access time then zero will be returned. | ||
| * | ||
| * @since Geode 1.4 | ||
| */ | ||
| public class LatestLastAccessTimeMessage<K> extends PooledDistributionMessage | ||
| implements MessageWithReply { | ||
|
|
||
| private int processorId; | ||
| private String regionName; | ||
| private K key; | ||
|
|
||
| public LatestLastAccessTimeMessage() { | ||
| // nothing | ||
| } | ||
|
|
||
| public LatestLastAccessTimeMessage(LatestLastAccessTimeReplyProcessor replyProcessor, | ||
| Set<InternalDistributedMember> recipients, InternalDistributedRegion<K, ?> region, K key) { | ||
| this.setRecipients(recipients); | ||
| this.processorId = replyProcessor.getProcessorId(); | ||
| this.key = key; | ||
| this.regionName = region.getFullPath(); | ||
| } | ||
|
|
||
| @Override | ||
| public int getDSFID() { | ||
| return LATEST_LAST_ACCESS_TIME_MESSAGE; | ||
| } | ||
|
|
||
| @Override | ||
| protected void process(DistributionManager dm) { | ||
| long latestLastAccessTime = 0L; | ||
| InternalDistributedRegion<K, ?> region = | ||
| (InternalDistributedRegion<K, ?>) dm.getCache().getRegion(this.regionName); | ||
| if (region != null) { | ||
| RegionEntry entry = region.getRegionEntry(this.key); | ||
| if (entry != null) { | ||
| try { | ||
| latestLastAccessTime = entry.getLastAccessed(); | ||
| } catch (InternalStatisticsDisabledException ignored) { | ||
| // last access time is not available | ||
| } | ||
| } | ||
| } | ||
| ReplyMessage.send(getSender(), this.processorId, latestLastAccessTime, dm); | ||
| } | ||
|
|
||
| @Override | ||
| public void fromData(DataInput in) throws IOException, ClassNotFoundException { | ||
| super.fromData(in); | ||
| this.processorId = DataSerializer.readPrimitiveInt(in); | ||
| this.regionName = DataSerializer.readString(in); | ||
| this.key = DataSerializer.readObject(in); | ||
| } | ||
|
|
||
| @Override | ||
| public void toData(DataOutput out) throws IOException { | ||
| super.toData(out); | ||
| DataSerializer.writePrimitiveInt(this.processorId, out); | ||
| DataSerializer.writeString(this.regionName, out); | ||
| DataSerializer.writeObject(this.key, out); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * 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.geode.internal.cache; | ||
|
|
||
| import java.util.Set; | ||
|
|
||
| import org.apache.geode.CancelException; | ||
| import org.apache.geode.distributed.internal.DM; | ||
| import org.apache.geode.distributed.internal.ReplyException; | ||
| import org.apache.geode.distributed.internal.membership.InternalDistributedMember; | ||
| import org.apache.geode.internal.Version; | ||
|
|
||
| /** | ||
| * Operation that determines the latest last access time for a given region and key | ||
| * | ||
| * @since Geode 1.4 | ||
| */ | ||
| public class LatestLastAccessTimeOperation<K> { | ||
| private final InternalDistributedRegion<K, ?> region; | ||
| private final K key; | ||
|
|
||
| public LatestLastAccessTimeOperation(InternalDistributedRegion<K, ?> region, K key) { | ||
| this.region = region; | ||
| this.key = key; | ||
| } | ||
|
|
||
| public long getLatestLastAccessTime() { | ||
| final Set<InternalDistributedMember> recipients = | ||
| this.region.getCacheDistributionAdvisor().adviseInitializedReplicates(); | ||
| final DM dm = this.region.getDistributionManager(); | ||
| dm.retainMembersWithSameOrNewerVersion(recipients, Version.GEODE_140); | ||
| final LatestLastAccessTimeReplyProcessor replyProcessor = | ||
| new LatestLastAccessTimeReplyProcessor(dm, recipients); | ||
| dm.putOutgoing( | ||
| new LatestLastAccessTimeMessage<>(replyProcessor, recipients, this.region, this.key)); | ||
| try { | ||
| replyProcessor.waitForReplies(); | ||
| } catch (ReplyException e) { | ||
| if (!(e.getCause() instanceof CancelException)) { | ||
| throw e; | ||
| } | ||
| } catch (InterruptedException e) { | ||
| dm.getCancelCriterion().checkCancelInProgress(e); | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
| return replyProcessor.getLatestLastAccessTime(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this always true? Can last accessed time from another member can be newer than ours, but still be expired? Do we need to test this new value against the expiration time point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the new commit that addresses this issue.
If a later lastAccessTime is obtained from others, the caller of this method now rechecks if it is still expired or if it should be rescheduled. This will prevent an extra round of messages in the case in which two members have slightly different lastAccessTimes but are both expired.