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;
}
}
@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);
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);
}
/**