Committed by
Flavio Castro
Fixed Distributed Group Store
Change-Id: I6e5b2119505e7961fd696440ebb6f996e6b1b72c
Showing
1 changed file
with
100 additions
and
7 deletions
| ... | @@ -432,6 +432,32 @@ public class DistributedGroupStore | ... | @@ -432,6 +432,32 @@ public class DistributedGroupStore |
| 432 | groupDesc.deviceId()); | 432 | groupDesc.deviceId()); |
| 433 | storeGroupDescriptionInternal(groupDesc); | 433 | storeGroupDescriptionInternal(groupDesc); |
| 434 | } | 434 | } |
| 435 | + private Group getMatchingExtraneousGroupbyId(DeviceId deviceId, Integer groupId) { | ||
| 436 | + ConcurrentMap<GroupId, Group> extraneousMap = | ||
| 437 | + getExtraneousGroupIdTable(deviceId); | ||
| 438 | + if (extraneousMap == null) { | ||
| 439 | + log.debug("getMatchingExtraneousGroupbyId: No extraneous groups for {}", deviceId); | ||
| 440 | + return null; | ||
| 441 | + } | ||
| 442 | + return extraneousMap.get(new DefaultGroupId(groupId)); | ||
| 443 | + } | ||
| 444 | + | ||
| 445 | + private Group getMatchingExtraneousGroupbyBuckets(DeviceId deviceId, | ||
| 446 | + GroupBuckets buckets) { | ||
| 447 | + ConcurrentMap<GroupId, Group> extraneousMap = | ||
| 448 | + getExtraneousGroupIdTable(deviceId); | ||
| 449 | + if (extraneousMap == null) { | ||
| 450 | + log.debug("getMatchingExtraneousGroupbyId: No extraneous groups for {}", deviceId); | ||
| 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 | + } | ||
| 435 | 461 | ||
| 436 | private void storeGroupDescriptionInternal(GroupDescription groupDesc) { | 462 | private void storeGroupDescriptionInternal(GroupDescription groupDesc) { |
| 437 | // Check if a group is existing with the same key | 463 | // Check if a group is existing with the same key |
| ... | @@ -455,6 +481,80 @@ public class DistributedGroupStore | ... | @@ -455,6 +481,80 @@ public class DistributedGroupStore |
| 455 | return; | 481 | return; |
| 456 | } | 482 | } |
| 457 | 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 " + | ||
| 498 | + "with matched extraneous group found in Device {} for group id {}", | ||
| 499 | + groupDesc.deviceId(), | ||
| 500 | + groupDesc.givenGroupId()); | ||
| 501 | + StoredGroupEntry group = new DefaultGroup( | ||
| 502 | + matchingExtraneousGroup.id(), groupDesc); | ||
| 503 | + // Insert the newly created group entry into key and id maps | ||
| 504 | + getGroupStoreKeyMap(). | ||
| 505 | + put(new GroupStoreKeyMapKey(groupDesc.deviceId(), | ||
| 506 | + groupDesc.appCookie()), group); | ||
| 507 | + // Ensure it also inserted into group id based table to | ||
| 508 | + // avoid any chances of duplication in group id generation | ||
| 509 | + getGroupIdTable(groupDesc.deviceId()). | ||
| 510 | + put(matchingExtraneousGroup.id(), group); | ||
| 511 | + addOrUpdateGroupEntry(matchingExtraneousGroup); | ||
| 512 | + removeExtraneousGroupEntry(matchingExtraneousGroup); | ||
| 513 | + return; | ||
| 514 | + } else { | ||
| 515 | + //Group buckets are not matching. Update group | ||
| 516 | + //with user provided buckets. | ||
| 517 | + //TODO | ||
| 518 | + log.debug("storeGroupDescriptionInternal: Buckets are not matching " + | ||
| 519 | + "with matched extraneous group found in Device {} for group id {}", | ||
| 520 | + groupDesc.deviceId(), | ||
| 521 | + groupDesc.givenGroupId()); | ||
| 522 | + } | ||
| 523 | + } else { | ||
| 524 | + log.debug("storeGroupDescriptionInternal: No matching extraneous groups found in Device {} for group id {}", | ||
| 525 | + groupDesc.deviceId(), groupDesc.givenGroupId()); | ||
| 526 | + } | ||
| 527 | + } else { | ||
| 528 | + //Check if there is an extraneous group with user provided buckets | ||
| 529 | + matchingExtraneousGroup = getMatchingExtraneousGroupbyBuckets( | ||
| 530 | + groupDesc.deviceId(), groupDesc.buckets()); | ||
| 531 | + if (matchingExtraneousGroup != null) { | ||
| 532 | + //Group is already existing with the same buckets. | ||
| 533 | + //So reuse this group. | ||
| 534 | + log.debug("storeGroupDescriptionInternal: Matching extraneous group found in Device {}", | ||
| 535 | + groupDesc.deviceId()); | ||
| 536 | + //Create a group entry object | ||
| 537 | + StoredGroupEntry group = new DefaultGroup( | ||
| 538 | + matchingExtraneousGroup.id(), groupDesc); | ||
| 539 | + // Insert the newly created group entry into key and id maps | ||
| 540 | + getGroupStoreKeyMap(). | ||
| 541 | + put(new GroupStoreKeyMapKey(groupDesc.deviceId(), | ||
| 542 | + groupDesc.appCookie()), group); | ||
| 543 | + // Ensure it also inserted into group id based table to | ||
| 544 | + // avoid any chances of duplication in group id generation | ||
| 545 | + getGroupIdTable(groupDesc.deviceId()). | ||
| 546 | + put(matchingExtraneousGroup.id(), group); | ||
| 547 | + addOrUpdateGroupEntry(matchingExtraneousGroup); | ||
| 548 | + removeExtraneousGroupEntry(matchingExtraneousGroup); | ||
| 549 | + return; | ||
| 550 | + } else { | ||
| 551 | + //TODO: Check if there are any empty groups that can be used here | ||
| 552 | + log.debug("storeGroupDescriptionInternal: No matching extraneous groups found in Device {}", | ||
| 553 | + groupDesc.deviceId()); | ||
| 554 | + } | ||
| 555 | + } | ||
| 556 | + | ||
| 557 | + | ||
| 458 | GroupId id = null; | 558 | GroupId id = null; |
| 459 | if (groupDesc.givenGroupId() == null) { | 559 | if (groupDesc.givenGroupId() == null) { |
| 460 | // Get a new group identifier | 560 | // Get a new group identifier |
| ... | @@ -882,13 +982,6 @@ public class DistributedGroupStore | ... | @@ -882,13 +982,6 @@ public class DistributedGroupStore |
| 882 | ConcurrentMap<GroupId, Group> extraneousIdTable = | 982 | ConcurrentMap<GroupId, Group> extraneousIdTable = |
| 883 | getExtraneousGroupIdTable(group.deviceId()); | 983 | getExtraneousGroupIdTable(group.deviceId()); |
| 884 | extraneousIdTable.put(group.id(), group); | 984 | extraneousIdTable.put(group.id(), group); |
| 885 | - // Check the reference counter | ||
| 886 | - if (group.referenceCount() == 0) { | ||
| 887 | - log.debug("Flow reference counter is zero and triggering remove", | ||
| 888 | - group.id(), | ||
| 889 | - group.deviceId()); | ||
| 890 | - notifyDelegate(new GroupEvent(Type.GROUP_REMOVE_REQUESTED, group)); | ||
| 891 | - } | ||
| 892 | } | 985 | } |
| 893 | 986 | ||
| 894 | @Override | 987 | @Override | ... | ... |
-
Please register or login to post a comment