Committed by
Gerrit Code Review
Group AUDIT enhancements
Change-Id: I867e57e616a727efaf940810e1fef7806ca5d28f
Showing
2 changed files
with
96 additions
and
7 deletions
| ... | @@ -62,6 +62,7 @@ public class DistributedFlowObjectiveStore | ... | @@ -62,6 +62,7 @@ public class DistributedFlowObjectiveStore |
| 62 | .withSerializer(Serializer.using( | 62 | .withSerializer(Serializer.using( |
| 63 | new KryoNamespace.Builder() | 63 | new KryoNamespace.Builder() |
| 64 | .register(byte[].class) | 64 | .register(byte[].class) |
| 65 | + .register(Versioned.class) | ||
| 65 | .build())) | 66 | .build())) |
| 66 | .build(); | 67 | .build(); |
| 67 | 68 | ... | ... |
| ... | @@ -434,6 +434,31 @@ public class DistributedGroupStore | ... | @@ -434,6 +434,31 @@ public class DistributedGroupStore |
| 434 | storeGroupDescriptionInternal(groupDesc); | 434 | storeGroupDescriptionInternal(groupDesc); |
| 435 | } | 435 | } |
| 436 | 436 | ||
| 437 | + private Group getMatchingExtraneousGroupbyId(DeviceId deviceId, Integer groupId) { | ||
| 438 | + ConcurrentMap<GroupId, Group> extraneousMap = | ||
| 439 | + extraneousGroupEntriesById.get(deviceId); | ||
| 440 | + if (extraneousMap == null) { | ||
| 441 | + return null; | ||
| 442 | + } | ||
| 443 | + return extraneousMap.get(new DefaultGroupId(groupId)); | ||
| 444 | + } | ||
| 445 | + | ||
| 446 | + private Group getMatchingExtraneousGroupbyBuckets(DeviceId deviceId, | ||
| 447 | + GroupBuckets buckets) { | ||
| 448 | + ConcurrentMap<GroupId, Group> extraneousMap = | ||
| 449 | + extraneousGroupEntriesById.get(deviceId); | ||
| 450 | + if (extraneousMap == null) { | ||
| 451 | + return null; | ||
| 452 | + } | ||
| 453 | + | ||
| 454 | + for (Group extraneousGroup:extraneousMap.values()) { | ||
| 455 | + if (extraneousGroup.buckets().equals(buckets)) { | ||
| 456 | + return extraneousGroup; | ||
| 457 | + } | ||
| 458 | + } | ||
| 459 | + return null; | ||
| 460 | + } | ||
| 461 | + | ||
| 437 | private void storeGroupDescriptionInternal(GroupDescription groupDesc) { | 462 | private void storeGroupDescriptionInternal(GroupDescription groupDesc) { |
| 438 | // Check if a group is existing with the same key | 463 | // Check if a group is existing with the same key |
| 439 | if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) { | 464 | if (getGroup(groupDesc.deviceId(), groupDesc.appCookie()) != null) { |
| ... | @@ -456,6 +481,74 @@ public class DistributedGroupStore | ... | @@ -456,6 +481,74 @@ public class DistributedGroupStore |
| 456 | return; | 481 | return; |
| 457 | } | 482 | } |
| 458 | 483 | ||
| 484 | + Group matchingExtraneousGroup = null; | ||
| 485 | + if (groupDesc.givenGroupId() != null) { | ||
| 486 | + //Check if there is a extraneous group existing with the same Id | ||
| 487 | + matchingExtraneousGroup = getMatchingExtraneousGroupbyId( | ||
| 488 | + groupDesc.deviceId(), groupDesc.givenGroupId()); | ||
| 489 | + if (matchingExtraneousGroup != null) { | ||
| 490 | + log.debug("storeGroupDescriptionInternal: Matching extraneous group found in Device {} for group id {}", | ||
| 491 | + groupDesc.deviceId(), | ||
| 492 | + groupDesc.givenGroupId()); | ||
| 493 | + //Check if the group buckets matches with user provided buckets | ||
| 494 | + if (matchingExtraneousGroup.buckets().equals(groupDesc.buckets())) { | ||
| 495 | + //Group is already existing with the same buckets and Id | ||
| 496 | + // Create a group entry object | ||
| 497 | + log.debug("storeGroupDescriptionInternal: Buckets also matching in Device {} for group id {}", | ||
| 498 | + groupDesc.deviceId(), | ||
| 499 | + groupDesc.givenGroupId()); | ||
| 500 | + StoredGroupEntry group = new DefaultGroup( | ||
| 501 | + matchingExtraneousGroup.id(), groupDesc); | ||
| 502 | + // Insert the newly created group entry into key and id maps | ||
| 503 | + getGroupStoreKeyMap(). | ||
| 504 | + put(new GroupStoreKeyMapKey(groupDesc.deviceId(), | ||
| 505 | + groupDesc.appCookie()), group); | ||
| 506 | + // Ensure it also inserted into group id based table to | ||
| 507 | + // avoid any chances of duplication in group id generation | ||
| 508 | + getGroupIdTable(groupDesc.deviceId()). | ||
| 509 | + put(matchingExtraneousGroup.id(), group); | ||
| 510 | + addOrUpdateGroupEntry(matchingExtraneousGroup); | ||
| 511 | + removeExtraneousGroupEntry(matchingExtraneousGroup); | ||
| 512 | + return; | ||
| 513 | + } else { | ||
| 514 | + //Group buckets are not matching. Update group | ||
| 515 | + //with user provided buckets. | ||
| 516 | + //TODO | ||
| 517 | + log.debug("storeGroupDescriptionInternal: Buckets are not matching in Device {} for group id {}", | ||
| 518 | + groupDesc.deviceId(), | ||
| 519 | + groupDesc.givenGroupId()); | ||
| 520 | + } | ||
| 521 | + } | ||
| 522 | + } else { | ||
| 523 | + //Check if there is an extraneous group with user provided buckets | ||
| 524 | + matchingExtraneousGroup = getMatchingExtraneousGroupbyBuckets( | ||
| 525 | + groupDesc.deviceId(), groupDesc.buckets()); | ||
| 526 | + if (matchingExtraneousGroup != null) { | ||
| 527 | + //Group is already existing with the same buckets. | ||
| 528 | + //So reuse this group. | ||
| 529 | + log.debug("storeGroupDescriptionInternal: Matching extraneous group found in Device {}", | ||
| 530 | + groupDesc.deviceId()); | ||
| 531 | + //Create a group entry object | ||
| 532 | + StoredGroupEntry group = new DefaultGroup( | ||
| 533 | + matchingExtraneousGroup.id(), groupDesc); | ||
| 534 | + // Insert the newly created group entry into key and id maps | ||
| 535 | + getGroupStoreKeyMap(). | ||
| 536 | + put(new GroupStoreKeyMapKey(groupDesc.deviceId(), | ||
| 537 | + groupDesc.appCookie()), group); | ||
| 538 | + // Ensure it also inserted into group id based table to | ||
| 539 | + // avoid any chances of duplication in group id generation | ||
| 540 | + getGroupIdTable(groupDesc.deviceId()). | ||
| 541 | + put(matchingExtraneousGroup.id(), group); | ||
| 542 | + addOrUpdateGroupEntry(matchingExtraneousGroup); | ||
| 543 | + removeExtraneousGroupEntry(matchingExtraneousGroup); | ||
| 544 | + return; | ||
| 545 | + } else { | ||
| 546 | + //TODO: Check if there are any empty groups that can be used here | ||
| 547 | + log.debug("storeGroupDescriptionInternal: No matching extraneous groups found in Device {}", | ||
| 548 | + groupDesc.deviceId()); | ||
| 549 | + } | ||
| 550 | + } | ||
| 551 | + | ||
| 459 | GroupId id = null; | 552 | GroupId id = null; |
| 460 | if (groupDesc.givenGroupId() == null) { | 553 | if (groupDesc.givenGroupId() == null) { |
| 461 | // Get a new group identifier | 554 | // Get a new group identifier |
| ... | @@ -883,13 +976,8 @@ public class DistributedGroupStore | ... | @@ -883,13 +976,8 @@ public class DistributedGroupStore |
| 883 | ConcurrentMap<GroupId, Group> extraneousIdTable = | 976 | ConcurrentMap<GroupId, Group> extraneousIdTable = |
| 884 | getExtraneousGroupIdTable(group.deviceId()); | 977 | getExtraneousGroupIdTable(group.deviceId()); |
| 885 | extraneousIdTable.put(group.id(), group); | 978 | extraneousIdTable.put(group.id(), group); |
| 886 | - // Check the reference counter | 979 | + // Don't remove the extraneous groups, instead re-use it when |
| 887 | - if (group.referenceCount() == 0) { | 980 | + // a group request comes with the same set of buckets |
| 888 | - log.debug("Flow reference counter is zero and triggering remove", | ||
| 889 | - group.id(), | ||
| 890 | - group.deviceId()); | ||
| 891 | - notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_REQUESTED, group)); | ||
| 892 | - } | ||
| 893 | } | 981 | } |
| 894 | 982 | ||
| 895 | @Override | 983 | @Override | ... | ... |
-
Please register or login to post a comment