Row re-use fix 73/85473/1
authorTschaen, Brendan <ctschaen@att.com>
Tue, 16 Apr 2019 13:51:58 +0000 (09:51 -0400)
committerTschaen, Brendan <ctschaen@att.com>
Tue, 16 Apr 2019 13:51:58 +0000 (09:51 -0400)
This prevents rows from being split properly, will follow up on issue

Change-Id: I6d9ebbf8cf9abd2cac4992be407fb6cb44cb318b
Issue-ID: MUSIC-326
Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
mdbc-server/src/main/java/org/onap/music/mdbc/DatabasePartition.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 4204960..c8cad47 100755 (executable)
@@ -195,4 +195,18 @@ public class DatabasePartition {
         }
         return false;
     }
+    
+    /**
+     * Checks if the database partition contains all of the ranges
+     * @param ranges
+     * @return
+     */
+    public synchronized boolean contains(List<Range> ranges) {
+        for (Range range: ranges) {
+            if (!isContained(range)) {
+                return false;
+            }
+        }
+        return true;
+    }
 }
\ No newline at end of file
index e41b7c0..cb37a55 100644 (file)
@@ -2124,7 +2124,8 @@ public class MusicMixin implements MusicInterface {
     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) {
+
+        if (latestRows.size()==1 && latestRows.get(0).getDBPartition().contains(ranges)) {
             //reuse current row if possible
             MusicRangeInformationRow row = latestRows.get(0);
             LockResult lockresult = locks.get(row.getPartitionIndex());
index 8823b81..110cc80 100644 (file)
@@ -293,8 +293,8 @@ public class OwnershipAndCheckpoint{
         //Find
         Map<UUID,LockResult> newLocks = new HashMap<>();
         List<Range> rangesToOwn = mi.getRangeDependencies(ranges);
-        List<MusicRangeInformationRow> rows = extractRowsForRange(mi,rangesToOwn, false);
-        Dag toOwn =  Dag.getDag(rows,rangesToOwn);
+        List<MusicRangeInformationRow> rangesToOwnRows = extractRowsForRange(mi,rangesToOwn, false);
+        Dag toOwn =  Dag.getDag(rangesToOwnRows,rangesToOwn);
         Dag currentlyOwn = new Dag();
         while ( (toOwn.isDifferent(currentlyOwn) || !currentlyOwn.isOwned() ) &&
                 !timeout(opId)
@@ -302,8 +302,8 @@ public class OwnershipAndCheckpoint{
             takeOwnershipOfDag(mi, currPartition, opId, newLocks, toOwn);
             currentlyOwn=toOwn;
             //TODO instead of comparing dags, compare rows
-            rows = extractRowsForRange(mi, rangesToOwn, false);
-            toOwn =  Dag.getDag(rows,rangesToOwn);
+            rangesToOwnRows = extractRowsForRange(mi, rangesToOwn, false);
+            toOwn =  Dag.getDag(rangesToOwnRows,rangesToOwn);
         }
         if (!currentlyOwn.isOwned() || toOwn.isDifferent(currentlyOwn)) {
             //hold on to previous partition
@@ -314,9 +314,9 @@ public class OwnershipAndCheckpoint{
             throw new MDBCServiceException("Ownership timeout");
         }
         Set<Range> allRanges = currentlyOwn.getAllRanges();
-        List<MusicRangeInformationRow> isLatestRows = extractRowsForRange(mi, new ArrayList<>(allRanges), true);
-        currentlyOwn.setRowsPerLatestRange(getIsLatestPerRange(toOwn,isLatestRows));
-        return mi.mergeLatestRowsIfNecessary(currentlyOwn,rows,ranges,newLocks,opId);
+        List<MusicRangeInformationRow> latestRows = extractRowsForRange(mi, new ArrayList<>(allRanges), true);
+        currentlyOwn.setRowsPerLatestRange(getIsLatestPerRange(toOwn,latestRows));
+        return mi.mergeLatestRowsIfNecessary(currentlyOwn,latestRows,ranges,newLocks,opId);
     }
     
     /**