Committed by
Gerrit Code Review
adding group garbage collection functionality
If a group has a reference count of zero for more than a configurable timeout, it is garbage collected. This feature can be deactivated by component config. Change-Id: I254d62a90ef7ac8d2ce2f406b67957455a5bf4d0
Showing
5 changed files
with
28 additions
and
0 deletions
| ... | @@ -35,6 +35,7 @@ public class DefaultGroup extends DefaultGroupDescription | ... | @@ -35,6 +35,7 @@ public class DefaultGroup extends DefaultGroupDescription |
| 35 | private long bytes; | 35 | private long bytes; |
| 36 | private long referenceCount; | 36 | private long referenceCount; |
| 37 | private GroupId id; | 37 | private GroupId id; |
| 38 | + private int age; | ||
| 38 | 39 | ||
| 39 | /** | 40 | /** |
| 40 | * Initializes default values. | 41 | * Initializes default values. |
| ... | @@ -48,6 +49,7 @@ public class DefaultGroup extends DefaultGroupDescription | ... | @@ -48,6 +49,7 @@ public class DefaultGroup extends DefaultGroupDescription |
| 48 | packets = 0; | 49 | packets = 0; |
| 49 | bytes = 0; | 50 | bytes = 0; |
| 50 | referenceCount = 0; | 51 | referenceCount = 0; |
| 52 | + age = 0; | ||
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | /** | 55 | /** |
| ... | @@ -128,6 +130,11 @@ public class DefaultGroup extends DefaultGroupDescription | ... | @@ -128,6 +130,11 @@ public class DefaultGroup extends DefaultGroupDescription |
| 128 | return this.bytes; | 130 | return this.bytes; |
| 129 | } | 131 | } |
| 130 | 132 | ||
| 133 | + @Override | ||
| 134 | + public int age() { | ||
| 135 | + return age; | ||
| 136 | + } | ||
| 137 | + | ||
| 131 | /** | 138 | /** |
| 132 | * Sets the new state for this entry. | 139 | * Sets the new state for this entry. |
| 133 | * | 140 | * |
| ... | @@ -171,6 +178,11 @@ public class DefaultGroup extends DefaultGroupDescription | ... | @@ -171,6 +178,11 @@ public class DefaultGroup extends DefaultGroupDescription |
| 171 | @Override | 178 | @Override |
| 172 | public void setReferenceCount(long referenceCount) { | 179 | public void setReferenceCount(long referenceCount) { |
| 173 | this.referenceCount = referenceCount; | 180 | this.referenceCount = referenceCount; |
| 181 | + if (referenceCount == 0) { | ||
| 182 | + age++; | ||
| 183 | + } else { | ||
| 184 | + age = 0; | ||
| 185 | + } | ||
| 174 | } | 186 | } |
| 175 | 187 | ||
| 176 | @Override | 188 | @Override |
| ... | @@ -214,6 +226,7 @@ public class DefaultGroup extends DefaultGroupDescription | ... | @@ -214,6 +226,7 @@ public class DefaultGroup extends DefaultGroupDescription |
| 214 | .add("description", super.toString()) | 226 | .add("description", super.toString()) |
| 215 | .add("groupid", id) | 227 | .add("groupid", id) |
| 216 | .add("state", state) | 228 | .add("state", state) |
| 229 | + .add("age", age) | ||
| 217 | .toString(); | 230 | .toString(); |
| 218 | } | 231 | } |
| 219 | 232 | ... | ... |
| ... | @@ -96,4 +96,12 @@ public interface Group extends GroupDescription { | ... | @@ -96,4 +96,12 @@ public interface Group extends GroupDescription { |
| 96 | * @return number of flow rules or other groups pointing to this group | 96 | * @return number of flow rules or other groups pointing to this group |
| 97 | */ | 97 | */ |
| 98 | long referenceCount(); | 98 | long referenceCount(); |
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * Obtains the age of a group. The age reflects the number of polling rounds | ||
| 102 | + * the group has had a reference count of zero. | ||
| 103 | + * | ||
| 104 | + * @return the age of the group as an integer | ||
| 105 | + */ | ||
| 106 | + int age(); | ||
| 99 | } | 107 | } | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -23,6 +23,7 @@ import org.junit.After; | ... | @@ -23,6 +23,7 @@ import org.junit.After; |
| 23 | import org.junit.Before; | 23 | import org.junit.Before; |
| 24 | import org.junit.Test; | 24 | import org.junit.Test; |
| 25 | import org.onlab.junit.TestUtils; | 25 | import org.onlab.junit.TestUtils; |
| 26 | +import org.onosproject.cfg.ComponentConfigAdapter; | ||
| 26 | import org.onosproject.cluster.NodeId; | 27 | import org.onosproject.cluster.NodeId; |
| 27 | import org.onosproject.core.DefaultGroupId; | 28 | import org.onosproject.core.DefaultGroupId; |
| 28 | import org.onosproject.core.GroupId; | 29 | import org.onosproject.core.GroupId; |
| ... | @@ -129,6 +130,7 @@ public class DistributedGroupStoreTest { | ... | @@ -129,6 +130,7 @@ public class DistributedGroupStoreTest { |
| 129 | groupStoreImpl.storageService = new TestStorageService(); | 130 | groupStoreImpl.storageService = new TestStorageService(); |
| 130 | groupStoreImpl.clusterCommunicator = new ClusterCommunicationServiceAdapter(); | 131 | groupStoreImpl.clusterCommunicator = new ClusterCommunicationServiceAdapter(); |
| 131 | groupStoreImpl.mastershipService = new MasterOfAll(); | 132 | groupStoreImpl.mastershipService = new MasterOfAll(); |
| 133 | + groupStoreImpl.cfgService = new ComponentConfigAdapter(); | ||
| 132 | groupStoreImpl.activate(); | 134 | groupStoreImpl.activate(); |
| 133 | groupStore = groupStoreImpl; | 135 | groupStore = groupStoreImpl; |
| 134 | auditPendingReqQueue = | 136 | auditPendingReqQueue = | ... | ... |
| ... | @@ -156,6 +156,11 @@ public class GroupsResourceTest extends ResourceTest { | ... | @@ -156,6 +156,11 @@ public class GroupsResourceTest extends ResourceTest { |
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | @Override | 158 | @Override |
| 159 | + public int age() { | ||
| 160 | + return 0; | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + @Override | ||
| 159 | public Type type() { | 164 | public Type type() { |
| 160 | return GroupDescription.Type.ALL; | 165 | return GroupDescription.Type.ALL; |
| 161 | } | 166 | } | ... | ... |
-
Please register or login to post a comment