aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTschaen, Brendan <ctschaen@att.com>2019-10-09 10:24:12 -0400
committerTschaen, Brendan <ctschaen@att.com>2019-10-09 10:24:12 -0400
commit947f876a1950c2308519e939ea875118f71bfd26 (patch)
tree5d4c177dba1b3f89a283f1cb8db38b2f94ab576b
parent3c1bd98f91094be3b9a3484e4afba0b29f621b40 (diff)
Various bug fixes and code cleanup
Issue-ID: MUSIC-524 Signed-off-by: Tschaen, Brendan <ctschaen@att.com> Change-Id: I20bb92f820ae373dfd1b365e8e279431aa999af0
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/DatabasePartition.java18
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/MdbcConnection.java8
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/TestUtils.java2
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java26
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java88
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java6
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java21
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/MdbcTestUtils.java15
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java4
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MySQLMixinTest.java2
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java4
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/query/QueryProcessorTest.java10
12 files changed, 102 insertions, 102 deletions
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/DatabasePartition.java b/mdbc-server/src/main/java/org/onap/music/mdbc/DatabasePartition.java
index 314248f..4122623 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/DatabasePartition.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/DatabasePartition.java
@@ -48,12 +48,18 @@ public class DatabasePartition {
* The only requirement is that the ranges are not overlapping.
*/
- public DatabasePartition() {
- this(new HashSet<Range>(),null,"");
- }
public DatabasePartition(UUID mriIndex) {
- this(new HashSet<Range>(), mriIndex,"");
+ this(new HashSet<Range>(), mriIndex);
+ }
+
+ /**
+ * Create unlocked partition
+ * @param ranges
+ * @param mriIndex
+ */
+ public DatabasePartition(Set<Range> ranges, UUID mriIndex) {
+ this(ranges, mriIndex, null);
}
public DatabasePartition(Set<Range> knownRanges, UUID mriIndex, String lockId) {
@@ -90,7 +96,9 @@ public class DatabasePartition {
}
- public synchronized boolean isLocked(){return lockId != null && !lockId.isEmpty(); }
+ public synchronized boolean isLocked(){
+ return lockId != null && !lockId.isEmpty();
+ }
public synchronized boolean isReady() {
return ready;
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/MdbcConnection.java b/mdbc-server/src/main/java/org/onap/music/mdbc/MdbcConnection.java
index f662207..7ce1d71 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/MdbcConnection.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/MdbcConnection.java
@@ -193,7 +193,7 @@ public class MdbcConnection implements Connection {
dbi.preCommitHook();
try {
- partition = mi.splitPartitionIfNecessary(partition, rangesUsed);
+ partition = mi.splitPartitionIfNecessary(partition, rangesUsed, ownerId);
} catch (MDBCServiceException e) {
logger.warn(EELFLoggerDelegate.errorLogger,
"Failure to split partition '" + partition.getMRIIndex() + "' trying to continue",
@@ -617,14 +617,10 @@ public class MdbcConnection implements Connection {
}
Dag dag = ownershipReturn.getDag();
if(dag!=null) {
- DagNode node = dag.getNode(ownershipReturn.getRangeId());
- MusicRangeInformationRow row = node.getRow();
- Map<MusicRangeInformationRow, LockResult> lock = new HashMap<>();
- lock.put(row, new LockResult(row.getPartitionIndex(), ownershipReturn.getOwnerId(), true, ranges));
ownAndCheck.checkpoint(this.mi, this.dbi, dag, ranges, ownershipReturn.getOwnershipId());
//TODO: need to update pointer in alreadyapplied if a merge happened instead of in prestatement hook
newPartition = new DatabasePartition(ownershipReturn.getRanges(), ownershipReturn.getRangeId(),
- ownershipReturn.getOwnerId());
+ ownershipReturn.getLockId());
}
} catch (MDBCServiceException e) {
MusicDeadlockException de = Utils.getDeadlockException(e);
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/TestUtils.java b/mdbc-server/src/main/java/org/onap/music/mdbc/TestUtils.java
index 736e579..3dcfaf0 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/TestUtils.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/TestUtils.java
@@ -49,7 +49,7 @@ public class TestUtils {
new MusicRangeInformationRow(dbPartition, new ArrayList<>(), true);
MusicRangeInformationRow newRow = new MusicRangeInformationRow(dbPartition, new ArrayList<>(), true);
DatabasePartition partition=null;
- partition = mixin.createLockedMRIRow(newRow);
+ partition = mixin.createLockedMRIRow(newRow, "");
return partition;
}
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
index a4e3e08..c1936f6 100755
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java
@@ -45,19 +45,19 @@ import org.onap.music.mdbc.tables.*;
*/
public interface MusicInterface {
class OwnershipReturn{
- private final UUID ownershipId;
+ private final UUID ownershipOpId;
private final String lockId;
private final UUID rangeId;
private final Set<Range> ranges;
private final Dag dag;
- public OwnershipReturn(UUID ownershipId, String ownerId, UUID rangeId, Set<Range> ranges, Dag dag){
- this.ownershipId=ownershipId;
- this.lockId=ownerId;
+ public OwnershipReturn(UUID ownershipOpId, String lockId, UUID rangeId, Set<Range> ranges, Dag dag){
+ this.ownershipOpId=ownershipOpId;
+ this.lockId=lockId;
this.rangeId=rangeId;
this.ranges=ranges;
this.dag=dag;
}
- public String getOwnerId(){
+ public String getLockId(){
return lockId;
}
public UUID getRangeId(){
@@ -65,7 +65,7 @@ public interface MusicInterface {
}
public Set<Range> getRanges(){ return ranges; }
public Dag getDag(){return dag;}
- public UUID getOwnershipId() { return ownershipId; }
+ public UUID getOwnershipId() { return ownershipOpId; }
}
/**
* Get the name of this MusicInterface mixin object.
@@ -214,10 +214,11 @@ public interface MusicInterface {
/**
* This function is used to create a new locked row in the MRI table
* @param info the information used to create the row
+ * @param owner owner of the lock for deadlock detection
* @return the new partition object that contain the new information used to create the row
* @throws MDBCServiceException
*/
- DatabasePartition createLockedMRIRow(MusicRangeInformationRow info) throws MDBCServiceException;
+ DatabasePartition createLockedMRIRow(MusicRangeInformationRow info, String owner) throws MDBCServiceException;
/**
* This function is used to create all the required music dependencies
@@ -335,12 +336,13 @@ public interface MusicInterface {
*
* @param currentlyOwned
* @param locksForOwnership
- * @param ownershipId
+ * @param ownershipOpId
+ * @param ownerId
* @return
* @throws MDBCServiceException
*/
- OwnershipReturn mergeLatestRowsIfNecessary(Dag currentlyOwned, Map<UUID, LockResult> locksForOwnership, UUID ownershipId)
- throws MDBCServiceException;
+ OwnershipReturn mergeLatestRowsIfNecessary(Dag currentlyOwned, Map<UUID, LockResult> locksForOwnership,
+ UUID ownershipOpId, String ownerId) throws MDBCServiceException;
/**
* If this connection is using fewer ranges than what is owned in the current partition, split
@@ -351,8 +353,8 @@ public interface MusicInterface {
* @param rangesUsed set of ranges that is the minimal required for this transaction
* @throws MDBCServiceException
*/
- public DatabasePartition splitPartitionIfNecessary(DatabasePartition partition, Set<Range> rangesUsed)
- throws MDBCServiceException;
+ public DatabasePartition splitPartitionIfNecessary(DatabasePartition partition, Set<Range> rangesUsed,
+ String ownerId) throws MDBCServiceException;
/**
* Create ranges in MRI table, if not already present
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
index 264b320..5808a20 100644
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java
@@ -1208,49 +1208,16 @@ public class MusicMixin implements MusicInterface {
return pendingRows;
}
- private List<Range> lockRow(LockRequest request,Map.Entry<UUID, Set<Range>> pending,Map<UUID, String> currentLockRef,
- String fullyQualifiedKey, String lockId, List<Range> pendingToLock,
- Map<UUID, LockResult> alreadyHeldLocks)
- throws MDBCServiceException{
- List<Range> newRanges = new ArrayList<>();
- String newFullyQualifiedKey = music_ns + "." + musicRangeInformationTableName + "." + pending.getKey().toString();
- String newLockId;
- boolean success;
- if (currentLockRef.containsKey(pending.getKey())) {
- newLockId = currentLockRef.get(pending.getKey());
- success = (MusicCore.whoseTurnIsIt(newFullyQualifiedKey) == newLockId);
- } else {
- try {
- newLockId = MusicCore.createLockReference(newFullyQualifiedKey);
- } catch (MusicLockingException e) {
- throw new MDBCServiceException(e);
- }
- ReturnType newLockReturn = acquireLock(fullyQualifiedKey, lockId);
- success = newLockReturn.getResult().compareTo(ResultType.SUCCESS) == 0;
- }
- if (!success) {
- pendingToLock.addAll(pending.getValue());
- currentLockRef.put(pending.getKey(), newLockId);
- } else {
- if(alreadyHeldLocks.containsKey(pending.getKey())){
- throw new MDBCServiceException("Adding key that already exist");
- }
- alreadyHeldLocks.put(pending.getKey(),new LockResult(pending.getKey(), newLockId, true,
- pending.getValue()));
- newRanges.addAll(pending.getValue());
- }
- return newRanges;
- }
-
private boolean isDifferent(NavigableMap<UUID, List<Range>> previous, NavigableMap<UUID, List<Range>> current){
return previous.keySet().equals(current.keySet());
}
- protected String createAndAssignLock(String fullyQualifiedKey, DatabasePartition partition) throws MDBCServiceException {
+ protected String createAndAssignLock(String fullyQualifiedKey, DatabasePartition partition, String ownerId)
+ throws MDBCServiceException {
UUID mriIndex = partition.getMRIIndex();
String lockId;
try {
- lockId = MusicCore.createLockReference(fullyQualifiedKey);
+ lockId = MusicCore.createLockReference(fullyQualifiedKey, ownerId);
} catch (MusicLockingException e1) {
throw new MDBCServiceException(e1);
}
@@ -1343,7 +1310,7 @@ public class MusicMixin implements MusicInterface {
}
- final MusicTxDigestId digestId = new MusicTxDigestId(MDBCUtils.generateUniqueKey(), -1);
+ final MusicTxDigestId digestId = new MusicTxDigestId(mriIndex, MDBCUtils.generateUniqueKey(), -1);
Callable<Boolean> insertDigestCallable =()-> {
try {
createAndAddTxDigest(transactionDigest,digestId.transactionId);
@@ -1366,9 +1333,7 @@ public class MusicMixin implements MusicInterface {
Future<Boolean> appendResultFuture = commitExecutorThreads.submit(appendCallable);
Future<Boolean> digestFuture = commitExecutorThreads.submit(insertDigestCallable);
try {
- //Boolean appendResult = appendResultFuture.get();
- Boolean digestResult = digestFuture.get();
- if(/*!appendResult ||*/ !digestResult){
+ if(!appendResultFuture.get() || !digestFuture.get()){
logger.error(EELFLoggerDelegate.errorLogger, "Error appending to log or adding tx digest");
throw new MDBCServiceException("Error appending to log or adding tx digest");
}
@@ -1497,7 +1462,7 @@ public class MusicMixin implements MusicInterface {
for (String table:tables){
partitions.add(new Range(table));
}
- return new MusicRangeInformationRow(new DatabasePartition(partitions, partitionIndex, ""),
+ return new MusicRangeInformationRow(new DatabasePartition(partitions, partitionIndex),
digestIds, newRow.getBool("islatest"), newRow.getSet("prevmrirows", UUID.class));
}
@@ -1584,14 +1549,15 @@ public class MusicMixin implements MusicInterface {
@Override
- public DatabasePartition createLockedMRIRow(MusicRangeInformationRow info) throws MDBCServiceException {
+ public DatabasePartition createLockedMRIRow(MusicRangeInformationRow info, String ownerId)
+ throws MDBCServiceException {
DatabasePartition newPartition = info.getDBPartition();
String fullyQualifiedMriKey = music_ns+"."+ musicRangeInformationTableName+"."+newPartition.getMRIIndex().toString();
String lockId;
int counter=0;
do {
- lockId = createAndAssignLock(fullyQualifiedMriKey, newPartition);
+ lockId = createAndAssignLock(fullyQualifiedMriKey, newPartition, ownerId);
//TODO: fix this retry logic
} while ((lockId ==null||lockId.isEmpty())&&(counter++<3));
if (lockId == null || lockId.isEmpty()) {
@@ -2144,7 +2110,8 @@ public class MusicMixin implements MusicInterface {
* @param locks
* @throws MDBCServiceException
*/
- private void recoverFromFailureAndUpdateDag(Dag latestDag, Map<UUID,LockResult> locks) throws MDBCServiceException {
+ private void recoverFromFailureAndUpdateDag(Dag latestDag, Map<UUID, LockResult> locks, String ownerId)
+ throws MDBCServiceException {
Pair<Set<Range>, Set<DagNode>> rangesAndDependents = latestDag.getIncompleteRangesAndDependents();
if(rangesAndDependents.getKey()==null || rangesAndDependents.getKey().size()==0 ||
rangesAndDependents.getValue()==null || rangesAndDependents.getValue().size() == 0){
@@ -2156,8 +2123,9 @@ public class MusicMixin implements MusicInterface {
prevPartitions.add(dagnode.getId());
}
- MusicRangeInformationRow r = createAndAssignLock(rangesAndDependents.getKey(), prevPartitions);
- locks.put(r.getPartitionIndex(),new LockResult(r.getPartitionIndex(),r.getDBPartition().getLockId(),true,rangesAndDependents.getKey()));
+ MusicRangeInformationRow r = createAndAssignLock(rangesAndDependents.getKey(), prevPartitions, ownerId);
+ locks.put(r.getPartitionIndex(), new LockResult(true, r.getPartitionIndex(), r.getDBPartition().getLockId(),
+ true, rangesAndDependents.getKey()));
latestDag.addNewNode(r,new ArrayList<>(rangesAndDependents.getValue()));
}
@@ -2191,13 +2159,14 @@ public class MusicMixin implements MusicInterface {
}
@Override
- public OwnershipReturn mergeLatestRowsIfNecessary(Dag currentlyOwned, Map<UUID, LockResult> locksForOwnership, UUID ownershipId) throws MDBCServiceException {
- recoverFromFailureAndUpdateDag(currentlyOwned,locksForOwnership);
+ public OwnershipReturn mergeLatestRowsIfNecessary(Dag currentlyOwned, Map<UUID, LockResult> locksForOwnership,
+ UUID ownershipOpId, String ownerId) throws MDBCServiceException {
+ recoverFromFailureAndUpdateDag(currentlyOwned,locksForOwnership, ownerId);
if (locksForOwnership.keySet().size()==1) {
//reuse if overlapping single partition, no merge necessary
for (UUID uuid: locksForOwnership.keySet()) {
- return new OwnershipReturn(ownershipId, locksForOwnership.get(uuid).getLockId(), uuid,
+ return new OwnershipReturn(ownershipOpId, locksForOwnership.get(uuid).getLockId(), uuid,
currentlyOwned.getNode(uuid).getRangeSet(), currentlyOwned);
}
}
@@ -2208,18 +2177,18 @@ public class MusicMixin implements MusicInterface {
Set<Range> ranges = extractRangesToOwn(currentlyOwned, locksForOwnership.keySet());
- MusicRangeInformationRow createdRow = createAndAssignLock(ranges, locksForOwnership.keySet());
+ MusicRangeInformationRow createdRow = createAndAssignLock(ranges, locksForOwnership.keySet(), ownerId);
currentlyOwned.addNewNodeWithSearch(createdRow, ranges);
changed = setReadOnlyAnyDoubleRow(currentlyOwned, locksForOwnership);
releaseLocks(locksForOwnership);
- return new OwnershipReturn(ownershipId, createdRow.getDBPartition().getLockId(), createdRow.getPartitionIndex(),
+ return new OwnershipReturn(ownershipOpId, createdRow.getDBPartition().getLockId(), createdRow.getPartitionIndex(),
createdRow.getDBPartition().getSnapshot(), currentlyOwned);
}
@Override
- public DatabasePartition splitPartitionIfNecessary(DatabasePartition partition, Set<Range> rangesUsed)
- throws MDBCServiceException {
+ public DatabasePartition splitPartitionIfNecessary(DatabasePartition partition, Set<Range> rangesUsed,
+ String ownerId) throws MDBCServiceException {
if (!this.splitAllowed) {
return partition;
}
@@ -2241,10 +2210,10 @@ public class MusicMixin implements MusicInterface {
+") and own (" + rangesOwned + ", splitting the partition");
Set<UUID> prevPartitions = new HashSet<>();
prevPartitions.add(partition.getMRIIndex());
- MusicRangeInformationRow usedRow = createAndAssignLock(rangesUsed, prevPartitions);
+ MusicRangeInformationRow usedRow = createAndAssignLock(rangesUsed, prevPartitions, ownerId);
rangesOwned.removeAll(rangesUsed);
Set<Range> rangesNotUsed = rangesOwned;
- MusicRangeInformationRow unusedRow = createAndAssignLock(rangesNotUsed, prevPartitions);
+ MusicRangeInformationRow unusedRow = createAndAssignLock(rangesNotUsed, prevPartitions, ownerId);
changeIsLatestToMRI(partition.getMRIIndex(), false, partition.getLockId());
@@ -2266,11 +2235,12 @@ public class MusicMixin implements MusicInterface {
}
- private MusicRangeInformationRow createAndAssignLock(Set<Range> ranges, Set<UUID> prevPartitions) throws MDBCServiceException {
+ private MusicRangeInformationRow createAndAssignLock(Set<Range> ranges, Set<UUID> prevPartitions, String ownerId)
+ throws MDBCServiceException {
UUID newUUID = MDBCUtils.generateTimebasedUniqueKey();
DatabasePartition newPartition = new DatabasePartition(ranges,newUUID,null);
MusicRangeInformationRow row = new MusicRangeInformationRow(newPartition, true, prevPartitions);
- createLockedMRIRow(row);
+ createLockedMRIRow(row, ownerId);
return row;
}
@@ -2349,7 +2319,7 @@ public class MusicMixin implements MusicInterface {
} catch (MDBCServiceException e) {
logger.error("Error relinquishing lock, will use timeout to solve");
}
- partition.setLockId("");
+ partition.setLockId(null);
}
}
@@ -2589,7 +2559,7 @@ public class MusicMixin implements MusicInterface {
}
MusicRangeInformationRow mriRow =
- createAndAssignLock(new HashSet<Range>(Arrays.asList(rangeToCreate)), new HashSet<UUID>());
+ createAndAssignLock(new HashSet<Range>(Arrays.asList(rangeToCreate)), new HashSet<UUID>(), "");
//TODO: should make sure we didn't create 2 new rows simultaneously, while we still own the lock
unlockKeyInMusic(musicRangeInformationTableName, mriRow.getPartitionIndex().toString(),
mriRow.getDBPartition().getLockId());
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java b/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java
index ec32210..8da2817 100644
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java
@@ -354,7 +354,6 @@ public class OwnershipAndCheckpoint{
} catch (MDBCServiceException e) {
MusicDeadlockException de = Utils.getDeadlockException(e);
if (de!=null) {
-// System.out.println("IN O&C.OWN, DETECTED DEADLOCK, REMOVING " + currPartition + ", RELEASING " + locksForOwnership);
locksForOwnership.remove(currPartition.getMRIIndex());
mi.releaseLocks(locksForOwnership);
stopOwnershipTimeoutClock(opId);
@@ -379,7 +378,7 @@ public class OwnershipAndCheckpoint{
//TODO: we shouldn't need to go back to music at this point
List<MusicRangeInformationRow> latestRows = extractRowsForRange(mi, allRanges, true);
currentlyOwn.setRowsPerLatestRange(getIsLatestPerRange(toOwn,latestRows));
- return mi.mergeLatestRowsIfNecessary(currentlyOwn,locksForOwnership,opId);
+ return mi.mergeLatestRowsIfNecessary(currentlyOwn,locksForOwnership,opId, ownerId);
}
/**
@@ -392,7 +391,8 @@ public class OwnershipAndCheckpoint{
* @throws MDBCServiceException
*/
private void takeOwnershipOfDag(MusicInterface mi, DatabasePartition partition, UUID opId,
- Map<UUID, LockResult> ownershipLocks, Dag toOwn, SQLOperationType lockType, String ownerId) throws MDBCServiceException {
+ Map<UUID, LockResult> ownershipLocks, Dag toOwn, SQLOperationType lockType, String ownerId)
+ throws MDBCServiceException {
while(toOwn.hasNextToOwn()){
DagNode node = toOwn.nextToOwn();
diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java b/mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java
index 6d6c661..27ea6ea 100644
--- a/mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java
+++ b/mdbc-server/src/main/java/org/onap/music/mdbc/query/QueryProcessor.java
@@ -30,6 +30,7 @@ import org.apache.calcite.avatica.util.Casing;
import org.apache.calcite.avatica.util.Quoting;
import org.apache.calcite.sql.SqlBasicCall;
import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlDelete;
import org.apache.calcite.sql.SqlIdentifier;
import org.apache.calcite.sql.SqlInsert;
import org.apache.calcite.sql.SqlJoin;
@@ -120,12 +121,15 @@ public class QueryProcessor {
case UPDATE:
parseUpdate((SqlUpdate) sqlNode, tableOpsMap);
break;
+ case DELETE:
+ parseDelete((SqlDelete) sqlNode, tableOpsMap);
+ break;
case SELECT:
parseSelect((SqlSelect) sqlNode, tableOpsMap);
break;
case ORDER_BY:
parseSelect((SqlSelect)((SqlOrderBy) sqlNode).query, tableOpsMap);
- break;
+ break;
default:
logger.error("Unhandled sql query type " + sqlNode.getKind() +" for query " + query);
}
@@ -144,7 +148,7 @@ public class QueryProcessor {
Ops.add(SQLOperation.INSERT);
tableOpsMap.put(tableName, Ops);
}
-
+
private static void parseUpdate(SqlUpdate sqlUpdate, Map<String, List<SQLOperation>> tableOpsMap) {
SqlNode targetTable = sqlUpdate.getTargetTable();
switch (targetTable.getKind()) {
@@ -155,7 +159,18 @@ public class QueryProcessor {
logger.error("Unable to process: " + targetTable.getKind() + " query");
}
}
-
+
+ private static void parseDelete(SqlDelete sqlDelete, Map<String, List<SQLOperation>> tableOpsMap) {
+ SqlNode targetTable = sqlDelete.getTargetTable();
+ switch (targetTable.getKind()) {
+ case IDENTIFIER:
+ addIdentifierToMap(tableOpsMap, (SqlIdentifier) targetTable, SQLOperation.DELETE);
+ break;
+ default:
+ logger.error("Unable to process: " + targetTable.getKind() + " query");
+ }
+ }
+
private static void parseSelect(SqlSelect sqlSelect, Map<String, List<SQLOperation>> tableOpsMap ) {
SqlNode from = sqlSelect.getFrom();
switch (from.getKind()) {
diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/MdbcTestUtils.java b/mdbc-server/src/test/java/org/onap/music/mdbc/MdbcTestUtils.java
index 9bec5eb..96806a3 100644
--- a/mdbc-server/src/test/java/org/onap/music/mdbc/MdbcTestUtils.java
+++ b/mdbc-server/src/test/java/org/onap/music/mdbc/MdbcTestUtils.java
@@ -44,6 +44,7 @@ import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.lockingservice.cassandra.CassaLockStore;
import org.onap.music.mdbc.mixins.MusicMixin;
import org.onap.music.mdbc.mixins.PostgresMixin;
+import org.powermock.reflect.Whitebox;
public class MdbcTestUtils {
@@ -198,6 +199,7 @@ public class MdbcTestUtils {
static void stopMySql(){
try {
db.stop();
+ db=null;
} catch (ManagedProcessException e) {
e.printStackTrace();
fail("Error closing mysql");
@@ -231,14 +233,11 @@ public class MdbcTestUtils {
session = EmbeddedCassandraServerHelper.getSession();
assertNotNull("Invalid configuration for cassandra", session);
-// MusicDataStoreHandle.mDstoreHandle = new MusicDataStore(cluster, session);
-// CassaLockStore store = new CassaLockStore(MusicDataStoreHandle.mDstoreHandle);
- CassaLockStore store;
- try {
- store = new CassaLockStore(MusicDataStoreHandle.getDSHandle());
- } catch (MusicServiceException e) {
- throw new MDBCServiceException(e);
- }
+
+ MusicDataStore mds = new MusicDataStore(cluster, session);
+ Whitebox.setInternalState(MusicDataStoreHandle.class, "mDstoreHandle", mds);
+ CassaLockStore store = new CassaLockStore(mds);
+
assertNotNull("Invalid configuration for music", store);
}
diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java
index 8ec2a0b..bf27ea8 100644
--- a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java
+++ b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java
@@ -144,11 +144,11 @@ public class MusicMixinTest {
private DatabasePartition addRow(Set<Range> ranges,boolean isLatest){
final UUID uuid = MDBCUtils.generateTimebasedUniqueKey();
- DatabasePartition dbPartition = new DatabasePartition(ranges,uuid,null);
+ DatabasePartition dbPartition = new DatabasePartition(ranges,uuid);
MusicRangeInformationRow newRow = new MusicRangeInformationRow(dbPartition, new ArrayList<>(), isLatest);
DatabasePartition partition=null;
try {
- partition = mixin.createLockedMRIRow(newRow);
+ partition = mixin.createLockedMRIRow(newRow, "");
} catch (MDBCServiceException e) {
fail("failure when creating new row");
}
diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MySQLMixinTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MySQLMixinTest.java
index bd493c7..1e42d1e 100644
--- a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MySQLMixinTest.java
+++ b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MySQLMixinTest.java
@@ -60,7 +60,7 @@ public class MySQLMixinTest {
@AfterClass
public static void close() throws Exception {
-
+ MdbcTestUtils.cleanDatabase(DBType.MySQL);
}
@Before
diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java
index 48ab711..e131caa 100644
--- a/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java
+++ b/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java
@@ -223,7 +223,7 @@ public class OwnershipAndCheckpointTest {
Map<MusicRangeInformationRow, LockResult> locks = new HashMap<>();
if(own.getDag()!=null) {
locks.put(own.getDag().getNode(own.getRangeId()).getRow(),
- new LockResult(own.getRangeId(), own.getOwnerId(), true,
+ new LockResult(own.getRangeId(), own.getLockId(), true,
ranges));
ownAndCheck.checkpoint(musicMixin, mysqlMixin, own.getDag(), ranges, ownOpId);
}
@@ -248,7 +248,7 @@ public class OwnershipAndCheckpointTest {
Map<MusicRangeInformationRow, LockResult> locks = new HashMap<>();
if(own.getDag()!=null) {
locks.put(own.getDag().getNode(own.getRangeId()).getRow(),
- new LockResult(own.getRangeId(), own.getOwnerId(), true,
+ new LockResult(own.getRangeId(), own.getLockId(), true,
ranges));
}
ownAndCheck.warmup(musicMixin,mysqlMixin,ranges);
diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/query/QueryProcessorTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/query/QueryProcessorTest.java
index 8d851c7..99e8244 100644
--- a/mdbc-server/src/test/java/org/onap/music/mdbc/query/QueryProcessorTest.java
+++ b/mdbc-server/src/test/java/org/onap/music/mdbc/query/QueryProcessorTest.java
@@ -98,6 +98,16 @@ public class QueryProcessorTest {
}
@Test
+ public void deleteQuery() throws SQLException {
+ String sqlQuery = "delete from db.employees where personid = 721 and lastname = 'Lastname'";
+ HashMap<String, List<SQLOperation>> expectedOut = new HashMap<>();
+ List<SQLOperation> t1op = new ArrayList<>();
+ t1op.add(SQLOperation.DELETE);
+ expectedOut.put("DB.EMPLOYEES", t1op);
+ assertEquals(expectedOut, QueryProcessor.parseSqlQuery(sqlQuery, null));
+ }
+
+ @Test
public void insertSelect() throws SQLException {
String sqlQuery =
"INSERT INTO table1 (CustomerName, City, Country) SELECT SupplierName, City, Country FROM table2";