Reuse current musicrangeinformation row if possible 72/84272/1
authorTschaen, Brendan <ctschaen@att.com>
Thu, 4 Apr 2019 20:18:51 +0000 (16:18 -0400)
committerTschaen, Brendan <ctschaen@att.com>
Thu, 4 Apr 2019 20:18:51 +0000 (16:18 -0400)
Change-Id: I748a43cefada08df42894968698adcf48a635afb
Issue-ID: MUSIC-326
Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java

index 8b91b28..71f1b8b 100755 (executable)
@@ -313,7 +313,20 @@ public interface MusicInterface {
 
     void releaseLocks(Map<UUID, LockResult> newLocks) throws MDBCServiceException;
 
-    OwnershipReturn mergeLatestRows(Dag extendedDag, List<MusicRangeInformationRow> latestRows, List<Range> ranges,
+    /**
+     * Combine previous musicrangeinformation rows for new partition, if necessary
+     * 
+     * Does not merge rows if a single previous row is sufficient to match new partition needed
+     * 
+     * @param extendedDag
+     * @param latestRows
+     * @param ranges
+     * @param locks
+     * @param ownershipId
+     * @return
+     * @throws MDBCServiceException
+     */
+    OwnershipReturn mergeLatestRowsIfNecessary(Dag extendedDag, List<MusicRangeInformationRow> latestRows, List<Range> ranges,
             Map<UUID, LockResult> locks, UUID ownershipId) throws MDBCServiceException;
 
 }
index c176ad9..4e8e08e 100644 (file)
@@ -2110,9 +2110,17 @@ public class MusicMixin implements MusicInterface {
     }
 
     @Override
-    public OwnershipReturn mergeLatestRows(Dag extendedDag, List<MusicRangeInformationRow> latestRows, List<Range> ranges,
-                                            Map<UUID,LockResult> locks, UUID ownershipId) throws MDBCServiceException{
+    public OwnershipReturn mergeLatestRowsIfNecessary(Dag extendedDag, List<MusicRangeInformationRow> latestRows,
+            List<Range> ranges, Map<UUID, LockResult> locks, UUID ownershipId) throws MDBCServiceException {
         recoverFromFailureAndUpdateDag(extendedDag,latestRows,ranges,locks);
+        if (latestRows.size()==1) {
+            //reuse current row if possible
+            MusicRangeInformationRow row = latestRows.get(0);
+            LockResult lockresult = locks.get(row.getPartitionIndex());
+            if (lockresult!=null) {
+                return new OwnershipReturn(ownershipId, lockresult.getLockId(), row.getPartitionIndex(), ranges, extendedDag);
+            }
+        }
         List<MusicRangeInformationRow> changed = setReadOnlyAnyDoubleRow(extendedDag, latestRows,locks);
         releaseLocks(changed, locks);
         MusicRangeInformationRow row = createAndAssignLock(ranges);
index ef98ebd..8823b81 100644 (file)
@@ -316,7 +316,7 @@ public class OwnershipAndCheckpoint{
         Set<Range> allRanges = currentlyOwn.getAllRanges();
         List<MusicRangeInformationRow> isLatestRows = extractRowsForRange(mi, new ArrayList<>(allRanges), true);
         currentlyOwn.setRowsPerLatestRange(getIsLatestPerRange(toOwn,isLatestRows));
-        return mi.mergeLatestRows(currentlyOwn,rows,ranges,newLocks,opId);
+        return mi.mergeLatestRowsIfNecessary(currentlyOwn,rows,ranges,newLocks,opId);
     }
     
     /**