From 618b63253109a373909aa46452e16811302a24e7 Mon Sep 17 00:00:00 2001 From: "Tschaen, Brendan" Date: Wed, 3 Jul 2019 12:54:25 -0400 Subject: Merge if necessary after ownership Cleaned up merge if necessary code Change List to Set, which caused cascading changes.... Issue-ID: MUSIC-404 Signed-off-by: Tschaen, Brendan Change-Id: Ie7aaeb3ff43073eb3947515523e73037089e763d --- .../org/onap/music/mdbc/DatabasePartition.java | 16 +-- .../main/java/org/onap/music/mdbc/MDBCUtils.java | 7 +- .../java/org/onap/music/mdbc/MdbcConnection.java | 26 ++--- .../src/main/java/org/onap/music/mdbc/Range.java | 4 +- .../java/org/onap/music/mdbc/StateManager.java | 14 +-- .../main/java/org/onap/music/mdbc/TestUtils.java | 2 +- .../onap/music/mdbc/configurations/Eventual.java | 9 +- .../mdbc/configurations/NodeConfiguration.java | 8 +- .../mdbc/configurations/TablesConfiguration.java | 3 +- .../onap/music/mdbc/examples/MdbcTestClient.java | 64 +++++++++-- .../org/onap/music/mdbc/mixins/DBInterface.java | 4 +- .../org/onap/music/mdbc/mixins/LockResult.java | 9 +- .../org/onap/music/mdbc/mixins/MusicInterface.java | 33 +++--- .../org/onap/music/mdbc/mixins/MusicMixin.java | 126 ++++++++++++--------- .../org/onap/music/mdbc/mixins/MySQLMixin.java | 7 +- .../org/onap/music/mdbc/mixins/PostgresMixin.java | 5 +- .../java/org/onap/music/mdbc/ownership/Dag.java | 16 +-- .../org/onap/music/mdbc/ownership/DagNode.java | 4 +- .../mdbc/ownership/OwnershipAndCheckpoint.java | 51 +++++---- .../mdbc/tables/MusicRangeInformationRow.java | 10 +- .../music/mdbc/tables/MusicTxDigestDaemon.java | 6 +- .../org/onap/music/mdbc/tables/StagingTable.java | 2 +- .../java/org/onap/music/mdbc/StateManagerTest.java | 6 +- .../org/onap/music/mdbc/mixins/MusicMixinTest.java | 14 +-- .../onap/music/mdbc/mixins/PostgresMixinTest.java | 3 +- .../org/onap/music/mdbc/ownership/DagTest.java | 118 +++++++++---------- .../mdbc/ownership/OwnershipAndCheckpointTest.java | 8 +- 27 files changed, 329 insertions(+), 246 deletions(-) (limited to 'mdbc-server') 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 c8cad47..314248f 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 @@ -39,7 +39,7 @@ public class DatabasePartition { private UUID musicRangeInformationIndex;//Index that can be obtained either from private String lockId; - protected List ranges; + protected Set ranges; private boolean ready; @@ -49,14 +49,14 @@ public class DatabasePartition { */ public DatabasePartition() { - this(new ArrayList(),null,""); + this(new HashSet(),null,""); } public DatabasePartition(UUID mriIndex) { - this(new ArrayList(), mriIndex,""); + this(new HashSet(), mriIndex,""); } - - public DatabasePartition(List knownRanges, UUID mriIndex, String lockId) { + + public DatabasePartition(Set knownRanges, UUID mriIndex, String lockId) { if(mriIndex==null){ ready = false; } @@ -139,9 +139,9 @@ public class DatabasePartition { * Get all the ranges that are currently owned * @return ranges */ - public synchronized List getSnapshot() { - List newRange = new ArrayList<>(); - for(Range r : ranges){ + public synchronized Set getSnapshot() { + Set newRange = new HashSet<>(); + for (Range r: ranges){ newRange.add(r.clone()); } return newRange; diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/MDBCUtils.java b/mdbc-server/src/main/java/org/onap/music/mdbc/MDBCUtils.java index a02e6d0..b60062e 100755 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/MDBCUtils.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/MDBCUtils.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.Base64; import java.util.Deque; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -98,12 +99,12 @@ public class MDBCUtils { return prop; } - public static List getTables(Map> queryParsed){ + public static Set getTables(Map> queryParsed){ return getTables(null, queryParsed); } - public static List getTables(String defaultDatabaseName, Map> queryParsed){ - List ranges = new ArrayList<>(); + public static Set getTables(String defaultDatabaseName, Map> queryParsed){ + Set ranges = new HashSet<>(); for(String table: queryParsed.keySet()){ String[] parts = table.split("\\."); if(parts.length==2){ 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 062b0bf..2294673 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 @@ -518,16 +518,16 @@ public class MdbcConnection implements Connection { Map> tableToQueryType = QueryProcessor.parseSqlQuery(sql, table_set); //Check ownership of keys String defaultSchema = dbi.getSchema(); - List queryTables = MDBCUtils.getTables(defaultSchema, tableToQueryType); + Set queryTables = MDBCUtils.getTables(defaultSchema, tableToQueryType); if (this.partition!=null) { - List snapshot = this.partition.getSnapshot(); + Set snapshot = this.partition.getSnapshot(); if(snapshot!=null){ queryTables.addAll(snapshot); } } // filter out ranges that fall under Eventually consistent // category as these tables do not need ownership - List scQueryTables = filterEveTables(queryTables); + Set scQueryTables = filterEveTables(queryTables); DatabasePartition tempPartition = own(scQueryTables, MDBCUtils.getOperationType(tableToQueryType)); if(tempPartition!=null && tempPartition != partition) { this.partition.updateDatabasePartition(tempPartition); @@ -537,7 +537,7 @@ public class MdbcConnection implements Connection { } - private List filterEveTables(List queryTables) { + private Set filterEveTables(Set queryTables) { queryTables.removeAll(statemanager.getEventualRanges()); return queryTables; } @@ -561,17 +561,17 @@ public class MdbcConnection implements Connection { * proxy first starts, and whenever there is the possibility that tables were created or dropped. It is synchronized * in order to prevent multiple threads from running this code in parallel. */ - private void createTriggers() throws QueryException { - //TODO: this should probably be in the dbinterface, maybe as an abstract class - Set set1 = dbi.getSQLRangeSet(); // set of tables in the database + public void createTriggers() throws QueryException { + Set set1 = dbi.getSQLTableSet(); // set of tables in the database logger.debug(EELFLoggerDelegate.applicationLogger, "synchronizing tables:" + set1); - for (Range r : set1) { + for (String tableName : set1) { // This map will be filled in if this table was previously discovered - if (!table_set.contains(r.getTable().toUpperCase()) && !dbi.getReservedTblNames().contains(r.getTable().toUpperCase())) { - logger.info(EELFLoggerDelegate.applicationLogger, "New table discovered: "+r.getTable()); + if (!table_set.contains(tableName.toUpperCase()) && !dbi.getReservedTblNames().contains(tableName.toUpperCase())) { + logger.info(EELFLoggerDelegate.applicationLogger, "New table discovered: "+tableName); try { - dbi.createSQLTriggers(r.getTable()); - table_set.add(r.getTable().toUpperCase()); + dbi.createSQLTriggers(tableName); + mi.createPartitionIfNeeded(new Range(tableName)); + table_set.add(tableName.toUpperCase()); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, e.getMessage(),AppMessages.UNKNOWNERROR, ErrorSeverity.CRITICAL, ErrorTypes.QUERYERROR); //logger.error(EELFLoggerDelegate.errorLogger, "Exception synchronizeTables: "+e); @@ -591,7 +591,7 @@ public class MdbcConnection implements Connection { * @return * @throws MDBCServiceException */ - private DatabasePartition own(List ranges, SQLOperationType lockType) throws MDBCServiceException { + private DatabasePartition own(Set ranges, SQLOperationType lockType) throws MDBCServiceException { if(ranges==null||ranges.isEmpty()){ return null; } diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/Range.java b/mdbc-server/src/main/java/org/onap/music/mdbc/Range.java index 41aed26..82a5d16 100755 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/Range.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/Range.java @@ -22,7 +22,7 @@ package org.onap.music.mdbc; import java.io.Serializable; import java.util.List; import java.util.Objects; - +import java.util.Set; import org.onap.music.logging.EELFLoggerDelegate; import org.onap.music.mdbc.mixins.MusicMixin; @@ -83,7 +83,7 @@ public class Range implements Cloneable{ } - public static boolean overlaps(List ranges, String table){ + public static boolean overlaps(Set ranges, String table) { //\TODO check if parallel stream makes sense here return ranges.stream().map((Range r) -> r.table.toUpperCase().equals(table.toUpperCase())).anyMatch((Boolean b) -> b); } diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/StateManager.java b/mdbc-server/src/main/java/org/onap/music/mdbc/StateManager.java index 6ca323e..66c8fa9 100644 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/StateManager.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/StateManager.java @@ -86,7 +86,7 @@ public class StateManager { private String mdbcServerName; private Map connectionRanges;//Each connection owns its own database partition private final Lock eventualLock = new ReentrantLock(); - private List eventualRanges; + private Set eventualRanges; /** lock for warmupRanges */ private final Lock warmupLock = new ReentrantLock(); /** a set of ranges that should be periodically updated with latest information, if null all tables should be warmed up */ @@ -255,24 +255,24 @@ public class StateManager { * Get a list of ranges that are eventually consistent * @return */ - public List getEventualRanges() { + public Set getEventualRanges() { eventualLock.lock(); - List returnArray; + Set returnSet; try { if(eventualRanges!=null){ - returnArray = new ArrayList<>(eventualRanges); + returnSet = new HashSet<>(eventualRanges); } else{ - returnArray= new ArrayList<>(); + returnSet= new HashSet<>(); } } finally{ eventualLock.unlock(); } - return returnArray; + return returnSet; } - public void setEventualRanges(List eventualRanges) { + public void setEventualRanges(Set eventualRanges) { eventualLock.lock(); try { this.eventualRanges = eventualRanges; 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 0693a97..496f48d 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 @@ -42,7 +42,7 @@ public class TestUtils { public static DatabasePartition createBasicRow(Range range, MusicInterface mixin, String mdbcServerName) throws MDBCServiceException { final UUID uuid = MDBCUtils.generateTimebasedUniqueKey(); - List ranges = new ArrayList<>(); + Set ranges = new HashSet<>(); ranges.add(range); DatabasePartition dbPartition = new DatabasePartition(ranges,uuid,null); new MusicRangeInformationRow(dbPartition, new ArrayList<>(), true); diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/Eventual.java b/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/Eventual.java index 0021bcc..bbd3f35 100644 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/Eventual.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/Eventual.java @@ -20,6 +20,7 @@ package org.onap.music.mdbc.configurations; import java.util.List; +import java.util.Set; import org.onap.music.logging.EELFLoggerDelegate; import org.onap.music.mdbc.Range; @@ -30,18 +31,18 @@ public class Eventual { private transient static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(Eventual.class); - protected List ranges; + protected Set ranges; - public Eventual(List ranges) { + public Eventual(Set ranges) { super(); this.ranges = ranges; } - public List getRanges() { + public Set getRanges() { return ranges; } - public void setRanges(List ranges) { + public void setRanges(Set ranges) { this.ranges = ranges; } diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/NodeConfiguration.java b/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/NodeConfiguration.java index 391ee1a..be8217b 100755 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/NodeConfiguration.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/NodeConfiguration.java @@ -49,17 +49,17 @@ public class NodeConfiguration { this.sqlDatabaseName = sqlDatabaseName; } - protected List toRanges(List tables){ - List newRange = new ArrayList<>(); + protected Set toRanges(List tables){ + Set newRange = new HashSet<>(); for(String table: tables) { newRange.add(new Range(table)); } return newRange; } - protected List toRanges(String tables){ + protected Set toRanges(String tables){ if(tables.isEmpty()){ - return new ArrayList<>(); + return new HashSet<>(); } String[] tablesArray=tables.split(","); return toRanges(new ArrayList<>(Arrays.asList(tablesArray))); diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/TablesConfiguration.java b/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/TablesConfiguration.java index 0598271..1c9d07c 100755 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/TablesConfiguration.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/configurations/TablesConfiguration.java @@ -38,6 +38,7 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.UUID; public class TablesConfiguration { @@ -113,7 +114,7 @@ public class TablesConfiguration { final ResultSet resultSet = MusicCore.quorumGet(checkRowsInTable); while(resultSet!=null && !resultSet.isExhausted()){ final MusicRangeInformationRow mriRowFromCassandraRow = MusicMixin.getMRIRowFromCassandraRow(resultSet.one()); - List ranges = mriRowFromCassandraRow.getDBPartition().getSnapshot(); + Set ranges = mriRowFromCassandraRow.getDBPartition().getSnapshot(); for(Range range: partition.getTables()) { if (Range.overlaps(ranges,range.getTable())){ throw new MDBCServiceException("MRI row already exists"); diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java b/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java index fea329d..fac9f36 100644 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java @@ -106,11 +106,13 @@ public class MdbcTestClient { e.printStackTrace(); } - final String insertSQL = "INSERT INTO Persons VALUES (1, 'Martinez', 'Juan', 'KACB', 'ATLANTA');"; - final String insertSQL1 = "DELETE FROM Persons WHERE PersonID=2;"; - final String insertSQL2 = "INSERT INTO Persons VALUES (2, 'Smith', 'JOHN', 'GNOC', 'BEDMINSTER');"; + final String insertSQL = "INSERT INTO Persons VALUES (1, 'Smith', 'Juan', 'KACB', 'ATLANTA');"; + final String insertSQL1 = "INSERT INTO Persons2 VALUES (1, 'Smith', 'Juan', 'KACB', 'ATLANTA');"; + final String insertSQL2 = "INSERT INTO Persons3 VALUES (2, 'Smith', 'JOHN', 'GNOC', 'BEDMINSTER');"; final String insertSQL3 = "UPDATE Persons SET FirstName='JOSH' WHERE LastName='Smith';"; - final String insertSQL4 = "UPDATE Persons SET FirstName='JOHN' WHERE LastName='Smith';"; + final String insertSQL4 = "UPDATE Persons2 SET FirstName='JOHN' WHERE LastName='Smith';"; + final String insertSQL5 = "UPDATE Persons SET FirstName='JOHN' WHERE LastName='Smith';"; + final String insertSQL6 = "UPDATE Persons3 SET FirstName='JOHN' WHERE LastName='Smith';"; final String selectSQL1 = "SELECT * FROM Persons;"; @@ -123,13 +125,55 @@ public class MdbcTestClient { } try { - //execute = insertStmt.execute(insertSQL); - //execute = insertStmt.execute(insertSQL1); - //execute = insertStmt.execute(insertSQL2); - //execute = insertStmt.execute(insertSQL3); - //execute = insertStmt.execute(insertSQL4); + /* + * insert into 1 + * insert into 2 + * insert into 3 + * insert into 1,2 + * insert into 1,3 + */ + execute = insertStmt.execute(insertSQL); + connection.commit(); + + connection.close(); + connection = DriverManager.getConnection("jdbc:avatica:remote:url=" + "http://localhost:30000/test"+ ";serialization=protobuf"); + connection.setAutoCommit(false); + insertStmt = connection.createStatement(); + + execute = insertStmt.execute(insertSQL1); + connection.commit(); + + connection.close(); + connection = DriverManager.getConnection("jdbc:avatica:remote:url=" + "http://localhost:30000/test"+ ";serialization=protobuf"); + connection.setAutoCommit(false); + insertStmt = connection.createStatement(); + + execute = insertStmt.execute(insertSQL2); + connection.commit(); + + connection.close(); + connection = DriverManager.getConnection("jdbc:avatica:remote:url=" + "http://localhost:30000/test"+ ";serialization=protobuf"); + connection.setAutoCommit(false); + insertStmt = connection.createStatement(); + + System.out.println("1,2"); + execute = insertStmt.execute(insertSQL3); + execute = insertStmt.execute(insertSQL4); + connection.commit(); + + connection.close(); + connection = DriverManager.getConnection("jdbc:avatica:remote:url=" + "http://localhost:30000/test"+ ";serialization=protobuf"); + connection.setAutoCommit(false); + insertStmt = connection.createStatement(); + + System.out.println("1,3,2"); + + execute = insertStmt.execute(insertSQL5); + execute = insertStmt.execute(insertSQL6); + execute = insertStmt.execute(insertSQL4); + connection.commit(); - ///* + /* ResultSet rs = insertStmt.executeQuery(selectSQL1); while (rs.next()) { System.out.printf("%d, %s, %s\n", rs.getInt("PersonID"), rs.getString("FirstName"), rs.getString("LastName")); diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/DBInterface.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/DBInterface.java index c572523..745307c 100755 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/DBInterface.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/DBInterface.java @@ -134,13 +134,13 @@ public interface DBInterface { * @throws SQLException if replay cannot occur correctly * @throws MDBCServiceException */ - void replayTransaction(StagingTable digest, List ranges) throws SQLException, MDBCServiceException; + void replayTransaction(StagingTable digest, Set ranges) throws SQLException, MDBCServiceException; void disableForeignKeyChecks() throws SQLException; void enableForeignKeyChecks() throws SQLException; - void applyTxDigest(StagingTable txDigest, List ranges) throws SQLException, MDBCServiceException; + void applyTxDigest(StagingTable txDigest, Set ranges) throws SQLException, MDBCServiceException; Connection getSQLConnection(); diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/LockResult.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/LockResult.java index 8e3f20c..5e8ba87 100644 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/LockResult.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/LockResult.java @@ -21,6 +21,7 @@ package org.onap.music.mdbc.mixins; import java.util.List; +import java.util.Set; import java.util.UUID; import org.onap.music.mdbc.Range; @@ -28,12 +29,12 @@ public class LockResult{ private boolean successful; private UUID musicRangeInformationIndex; private String lockId; - private List ranges; + private Set ranges; private boolean newLock; /** back off time in milliseconds */ private long backOffPeriodms; - public LockResult(boolean succesful, UUID rowId, String lockId, boolean newLock, List ranges){ + public LockResult(boolean succesful, UUID rowId, String lockId, boolean newLock, Set ranges){ this.successful = succesful; this.musicRangeInformationIndex = rowId; this.lockId=lockId; @@ -48,7 +49,7 @@ public class LockResult{ * @param ranges */ @Deprecated - public LockResult(UUID rowId, String lockId, boolean newLock, List ranges){ + public LockResult(UUID rowId, String lockId, boolean newLock, Set ranges){ this.successful = true; this.musicRangeInformationIndex = rowId; this.lockId=lockId; @@ -74,7 +75,7 @@ public class LockResult{ return musicRangeInformationIndex; } - public List getRanges() { + public Set getRanges() { return ranges; } 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 2955536..637cb15 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 @@ -46,24 +46,24 @@ import org.onap.music.mdbc.tables.*; public interface MusicInterface { class OwnershipReturn{ private final UUID ownershipId; - private final String ownerId; + private final String lockId; private final UUID rangeId; - private final List ranges; + private final Set ranges; private final Dag dag; - public OwnershipReturn(UUID ownershipId, String ownerId, UUID rangeId, List ranges, Dag dag){ + public OwnershipReturn(UUID ownershipId, String ownerId, UUID rangeId, Set ranges, Dag dag){ this.ownershipId=ownershipId; - this.ownerId=ownerId; + this.lockId=ownerId; this.rangeId=rangeId; this.ranges=ranges; this.dag=dag; } public String getOwnerId(){ - return ownerId; + return lockId; } public UUID getRangeId(){ return rangeId; } - public List getRanges(){ return ranges; } + public Set getRanges(){ return ranges; } public Dag getDag(){return dag;} public UUID getOwnershipId() { return ownershipId; } } @@ -189,7 +189,7 @@ public interface MusicInterface { * @param progressKeeper data structure that is used to handle to detect failures, and know what to do * @throws MDBCServiceException */ - void commitLog(DatabasePartition partition, List eventualRanges, StagingTable transactionDigest, String txId,TxCommitProgress progressKeeper) throws MDBCServiceException; + void commitLog(DatabasePartition partition, Set eventualRanges, StagingTable transactionDigest, String txId,TxCommitProgress progressKeeper) throws MDBCServiceException; /** @@ -208,7 +208,7 @@ public interface MusicInterface { */ RangeDependency getMusicRangeDependency(Range baseRange) throws MDBCServiceException; - List getRangeDependencies(List range) throws MDBCServiceException; + public Set getRangeDependencies(Set range) throws MDBCServiceException; /** * This function is used to create a new locked row in the MRI table @@ -329,17 +329,21 @@ public interface MusicInterface { * * 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 currentlyOwned + * @param locksForOwnership * @param ownershipId * @return * @throws MDBCServiceException */ - OwnershipReturn mergeLatestRowsIfNecessary(Dag extendedDag, List latestRows, List ranges, - Map locks, UUID ownershipId) throws MDBCServiceException; + OwnershipReturn mergeLatestRowsIfNecessary(Dag currentlyOwned, Map locksForOwnership, UUID ownershipId) + throws MDBCServiceException; + /** + * Create ranges in MRI table, if not already present + * @param range to add into mri table + */ + public void createPartitionIfNeeded(Range rangeToCreate) throws MDBCServiceException; + /** * Update pointer to where this server has successfully replayed transactions * This is an eventual operation for minimal performance hits @@ -348,6 +352,5 @@ public interface MusicInterface { */ public void updateCheckpointLocations(Range r, Pair playbackPointer); - } 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 c0061f9..5581573 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 @@ -24,6 +24,7 @@ import java.io.Reader; import java.nio.ByteBuffer; import java.sql.Types; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -1197,7 +1198,7 @@ public class MusicMixin implements MusicInterface { return pendingRows; } - private List lockRow(LockRequest request,Map.Entry> pending,Map currentLockRef, + private List lockRow(LockRequest request,Map.Entry> pending,Map currentLockRef, String fullyQualifiedKey, String lockId, List pendingToLock, Map alreadyHeldLocks) throws MDBCServiceException{ @@ -1293,7 +1294,7 @@ public class MusicMixin implements MusicInterface { * This officially commits the transaction globally */ @Override - public void commitLog(DatabasePartition partition,List eventualRanges, StagingTable transactionDigest, + public void commitLog(DatabasePartition partition,Set eventualRanges, StagingTable transactionDigest, String txId ,TxCommitProgress progressKeeper) throws MDBCServiceException { // first deal with commit for eventually consistent tables @@ -1304,7 +1305,7 @@ public class MusicMixin implements MusicInterface { return; } - List snapshot = partition.getSnapshot(); + Set snapshot = partition.getSnapshot(); if(snapshot==null || snapshot.isEmpty()){ logger.warn("Trying to commit log with empty ranges"); return; @@ -1363,7 +1364,7 @@ public class MusicMixin implements MusicInterface { if (progressKeeper != null) { progressKeeper.setRecordId(txId, digestId); } - List ranges = partition.getSnapshot(); + Set ranges = partition.getSnapshot(); for(Range r : ranges) { Map> alreadyApplied = stateManager.getOwnAndCheck().getAlreadyApplied(); if(!alreadyApplied.containsKey(r)){ @@ -1380,7 +1381,7 @@ public class MusicMixin implements MusicInterface { } } - private void filterAndAddEventualTxDigest(List eventualRanges, + private void filterAndAddEventualTxDigest(Set eventualRanges, StagingTable transactionDigest, String txId, TxCommitProgress progressKeeper) throws MDBCServiceException { @@ -1484,7 +1485,7 @@ public class MusicMixin implements MusicInterface { final UUID id = t.getUUID(1); digestIds.add(new MusicTxDigestId(partitionIndex,id,index++)); } - List partitions = new ArrayList<>(); + Set partitions = new HashSet<>(); Set tables = newRow.getSet("keys",String.class); for (String table:tables){ partitions.add(new Range(table)); @@ -2072,7 +2073,7 @@ public class MusicMixin implements MusicInterface { * @throws MDBCServiceException */ @Override - public List getRangeDependencies(List range) throws MDBCServiceException{ + public Set getRangeDependencies(Set range) throws MDBCServiceException{ Set extendedRange = new HashSet<>(); for(Range r: range){ extendedRange.add(r); @@ -2081,7 +2082,7 @@ public class MusicMixin implements MusicInterface { extendedRange.addAll(dependencies.dependentRanges()); } } - return new ArrayList<>(extendedRange); + return extendedRange; } @Override @@ -2113,25 +2114,28 @@ public class MusicMixin implements MusicInterface { /** * fixes the DAG in case the previous owner failed while trying to own the row * @param latestDag - * @param rows - * @param ranges * @param locks * @throws MDBCServiceException */ - private void recoverFromFailureAndUpdateDag(Dag latestDag,List rows,List ranges, - Map locks) throws MDBCServiceException{ - Pair,Set> rangesAndDependents = latestDag.getIncompleteRangesAndDependents(); + private void recoverFromFailureAndUpdateDag(Dag latestDag, Map locks) throws MDBCServiceException { + Pair, Set> rangesAndDependents = latestDag.getIncompleteRangesAndDependents(); if(rangesAndDependents.getKey()==null || rangesAndDependents.getKey().size()==0 || rangesAndDependents.getValue()==null || rangesAndDependents.getValue().size() == 0){ return; } - MusicRangeInformationRow r = createAndAssignLock(rangesAndDependents.getKey(), rows); + + Set prevPartitions = new HashSet<>(); + for (DagNode dagnode: rangesAndDependents.getRight()) { + prevPartitions.add(dagnode.getId()); + } + + MusicRangeInformationRow r = createAndAssignLock(rangesAndDependents.getKey(), prevPartitions); locks.put(r.getPartitionIndex(),new LockResult(r.getPartitionIndex(),r.getDBPartition().getLockId(),true,rangesAndDependents.getKey())); latestDag.addNewNode(r,new ArrayList<>(rangesAndDependents.getValue())); } - private List setReadOnlyAnyDoubleRow(Dag latestDag,List rows, Map locks) + private List setReadOnlyAnyDoubleRow(Dag latestDag,Map locks) throws MDBCServiceException{ List returnInfo = new ArrayList<>(); List toDisable = latestDag.getOldestDoubles(); @@ -2143,15 +2147,6 @@ public class MusicMixin implements MusicInterface { return returnInfo; } - private MusicRangeInformationRow createAndAssignLock(List ranges, List latestRows) throws MDBCServiceException { - UUID newUUID = MDBCUtils.generateTimebasedUniqueKey(); - DatabasePartition newPartition = new DatabasePartition(ranges,newUUID,null); - MusicRangeInformationRow newRow = new MusicRangeInformationRow(newPartition,new ArrayList<>(), - true, extractPreviousPartitions(latestRows)); - createLockedMRIRow(newRow); - return newRow; - } - /** * Create a set of previous partitions to their uuids * @param latestRows @@ -2166,37 +2161,45 @@ public class MusicMixin implements MusicInterface { } @Override - public OwnershipReturn mergeLatestRowsIfNecessary(Dag extendedDag, List latestRows, - List ranges, Map locks, UUID ownershipId) throws MDBCServiceException { - recoverFromFailureAndUpdateDag(extendedDag,latestRows,ranges,locks); - - 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()); - if (lockresult!=null) { - return new OwnershipReturn(ownershipId, lockresult.getLockId(), row.getPartitionIndex(), ranges, extendedDag); + public OwnershipReturn mergeLatestRowsIfNecessary(Dag currentlyOwned, Map locksForOwnership, UUID ownershipId) throws MDBCServiceException { + recoverFromFailureAndUpdateDag(currentlyOwned,locksForOwnership); + + 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, + currentlyOwned.getNode(uuid).getRangeSet(), currentlyOwned); } } - List changed = setReadOnlyAnyDoubleRow(extendedDag, latestRows,locks); - releaseLocks(changed, locks); - MusicRangeInformationRow row = createAndAssignLock(ranges, latestRows); - latestRows.add(row); - locks.put(row.getPartitionIndex(),new LockResult(row.getPartitionIndex(),row.getDBPartition().getLockId(),true,ranges)); - extendedDag.addNewNodeWithSearch(row,ranges); - Pair, Set> missing = extendedDag.getIncompleteRangesAndDependents(); - if(missing.getKey().size()!=0 && missing.getValue().size()!=0) { - MusicRangeInformationRow newRow = createAndAssignLock(missing.getKey(), latestRows); - latestRows.add(newRow); - locks.put(newRow.getPartitionIndex(), new LockResult(newRow.getPartitionIndex(), row.getDBPartition().getLockId(), - true, missing.getKey())); - extendedDag.addNewNode(newRow, new ArrayList<>(missing.getValue())); - } - changed = setReadOnlyAnyDoubleRow(extendedDag, latestRows,locks); - releaseLocks(changed,locks); - releaseAllLocksExcept(row.getPartitionIndex(),locks); - LockResult ownRow = locks.get(row.getPartitionIndex()); - return new OwnershipReturn(ownershipId, ownRow.getLockId(), ownRow.getIndex(),ranges,extendedDag); + + //merge is necessary + List changed = setReadOnlyAnyDoubleRow(currentlyOwned, locksForOwnership); + releaseLocks(changed, locksForOwnership); + + Set ranges = extractRangesToOwn(currentlyOwned, locksForOwnership.keySet()); + + MusicRangeInformationRow createdRow = createAndAssignLock(ranges, locksForOwnership.keySet()); + currentlyOwned.addNewNodeWithSearch(createdRow, ranges); + changed = setReadOnlyAnyDoubleRow(currentlyOwned, locksForOwnership); + releaseLocks(locksForOwnership); + return new OwnershipReturn(ownershipId, createdRow.getDBPartition().getLockId(), createdRow.getPartitionIndex(), + createdRow.getDBPartition().getSnapshot(), currentlyOwned); + } + + private MusicRangeInformationRow createAndAssignLock(Set ranges, Set prevPartitions) throws MDBCServiceException { + UUID newUUID = MDBCUtils.generateTimebasedUniqueKey(); + DatabasePartition newPartition = new DatabasePartition(ranges,newUUID,null); + MusicRangeInformationRow row = new MusicRangeInformationRow(newPartition, true, prevPartitions); + createLockedMRIRow(row); + return row; + } + + private Set extractRangesToOwn(Dag currentlyOwned, Set UUIDs) { + HashSet ranges = new HashSet<>(); + for (UUID uuid: UUIDs) { + ranges.addAll(currentlyOwned.getNode(uuid).getRow().getDBPartition().getSnapshot()); + } + return ranges; } /** @@ -2495,6 +2498,23 @@ public class MusicMixin implements MusicInterface { return stateManager; } + @Override + public void createPartitionIfNeeded(Range rangeToCreate) throws MDBCServiceException { + List allRows = getAllMriRows(); + for (MusicRangeInformationRow row: allRows) { + if (row.getDBPartition().getSnapshot().contains(rangeToCreate)) { + //range already in MRI row, do not re-create + return; + } + } + + MusicRangeInformationRow mriRow = + createAndAssignLock(new HashSet(Arrays.asList(rangeToCreate)), new HashSet()); + //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()); + } + @Override public void updateCheckpointLocations(Range r, Pair playbackPointer) { String cql = String.format("INSERT INTO %s.%s (mdbcnode, mridigest, digestindex) VALUES (" diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java index da4e413..ec91ceb 100755 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java @@ -214,7 +214,7 @@ public class MySQLMixin implements DBInterface { public Set getSQLTableSet() { Set set = new TreeSet(); String sql = - "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_TYPE='BASE TABLE'"; + "SELECT CONCAT(TABLE_SCHEMA, '.', TABLE_NAME) as TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_TYPE='BASE TABLE'"; try { Statement stmt = jdbcConn.createStatement(); ResultSet rs = stmt.executeQuery(sql); @@ -703,7 +703,6 @@ public class MySQLMixin implements DBInterface { } - /** * Update music with data from MySQL table * @@ -878,7 +877,7 @@ public class MySQLMixin implements DBInterface { * @param transaction - base 64 encoded, serialized digest * @throws MDBCServiceException */ - public void replayTransaction(StagingTable transaction, List ranges) + public void replayTransaction(StagingTable transaction, Set ranges) throws SQLException, MDBCServiceException { boolean autocommit = jdbcConn.getAutoCommit(); jdbcConn.setAutoCommit(false); @@ -921,7 +920,7 @@ public class MySQLMixin implements DBInterface { } @Override - public void applyTxDigest(StagingTable txDigest, List ranges) throws SQLException, MDBCServiceException { + public void applyTxDigest(StagingTable txDigest, Set ranges) throws SQLException, MDBCServiceException { replayTransaction(txDigest, ranges); } diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/PostgresMixin.java b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/PostgresMixin.java index 76f4942..4afaa71 100755 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/PostgresMixin.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/mixins/PostgresMixin.java @@ -816,7 +816,8 @@ public class PostgresMixin implements DBInterface { * * @param transaction - base 64 encoded, serialized digest */ - public void replayTransaction(StagingTable transaction, List ranges) + @Override + public void replayTransaction(StagingTable transaction, Set ranges) throws SQLException, MDBCServiceException { boolean autocommit = jdbcConn.getAutoCommit(); jdbcConn.setAutoCommit(false); @@ -858,7 +859,7 @@ public class PostgresMixin implements DBInterface { } @Override - public void applyTxDigest(StagingTable txDigest, List ranges) throws SQLException, MDBCServiceException { + public void applyTxDigest(StagingTable txDigest, Set ranges) throws SQLException, MDBCServiceException { replayTransaction(txDigest, ranges); } diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/Dag.java b/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/Dag.java index ff2102f..9d1685c 100644 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/Dag.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/Dag.java @@ -62,7 +62,7 @@ public class Dag { rowsPerLatestRange = null; } - private void createDag(List rows, List ranges){ + private void createDag(List rows, Set ranges){ this.ranges = new ArrayList<>(ranges); Map latestRow = new HashMap<>(); //sort to make sure rows are in chronological order @@ -72,7 +72,7 @@ public class Dag { DagNode node = new DagNode(row); nodes.put(row.getPartitionIndex(),node); for(Range range : ranges){ - List nodeRanges = row.getDBPartition().getSnapshot(); + Set nodeRanges = row.getDBPartition().getSnapshot(); for(Range nRange : nodeRanges){ if(nRange.overlaps(range)){ if(latestRow.containsKey(range)){ @@ -88,7 +88,7 @@ public class Dag { } } - public static Dag getDag(List rows, List ranges){ + public static Dag getDag(List rows, Set ranges){ Dag newDag = new Dag(true); newDag.createDag(rows,ranges); return newDag; @@ -116,7 +116,7 @@ public class Dag { }); } - public DagNode getNode(UUID rowId) throws MDBCServiceException { + public DagNode getNode(UUID rowId) { if(!nodes.containsKey(rowId)){ return null; } @@ -141,7 +141,7 @@ public class Dag { return nextNode; } - public synchronized DagNode nextToApply(List ranges){ + public synchronized DagNode nextToApply(Set ranges){ if(!readyInit){ initApplyDatastructures(); } @@ -283,7 +283,7 @@ public class Dag { } } - public void addNewNodeWithSearch(MusicRangeInformationRow row, List ranges) throws MDBCServiceException { + public void addNewNodeWithSearch(MusicRangeInformationRow row, Set ranges) throws MDBCServiceException { Map newestNode = new HashMap<>(); for(DagNode node : nodes.values()){ for(Range range : ranges) { @@ -389,8 +389,8 @@ public class Dag { return toDisable; } - public Pair,Set> getIncompleteRangesAndDependents() throws MDBCServiceException { - List incomplete = new ArrayList<>(); + public Pair, Set> getIncompleteRangesAndDependents() throws MDBCServiceException { + Set incomplete = new HashSet<>(); Set dependents = new HashSet<>(); Map> rowsPerLatestRange = getIsLatestPerRange(); List toDisable = getOldestDoubleRows(rowsPerLatestRange); diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/DagNode.java b/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/DagNode.java index e737b26..78c68e1 100644 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/DagNode.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/ownership/DagNode.java @@ -61,7 +61,9 @@ public class DagNode { startIndex = new HashMap<>(); } - public MusicRangeInformationRow getRow() { return row;} + public MusicRangeInformationRow getRow() { + return row; + } public synchronized void setOwned(){ owned = true; 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 fb4cfe3..b848964 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 @@ -88,14 +88,14 @@ public class OwnershipAndCheckpoint{ } - private List extractRowsForRange(List allMriRows, List ranges, + private List extractRowsForRange(List allMriRows, Set ranges, boolean onlyIsLatest){ List rows = new ArrayList<>(); for(MusicRangeInformationRow row : allMriRows){ if(onlyIsLatest && !row.getIsLatest()){ continue; } - final List rowRanges = row.getDBPartition().getSnapshot(); + final Set rowRanges = row.getDBPartition().getSnapshot(); boolean found = false; for(Range sRange : ranges){ for(Range rRange: rowRanges) { @@ -118,7 +118,7 @@ public class OwnershipAndCheckpoint{ * @param onlyIsLatest - only return the "latest" rows * @return */ - private List extractRowsForRange(MusicInterface music, List ranges, boolean onlyIsLatest) + private List extractRowsForRange(MusicInterface music, Set ranges, boolean onlyIsLatest) throws MDBCServiceException { final List allMriRows = music.getAllMriRows(); return extractRowsForRange(allMriRows,ranges,onlyIsLatest); @@ -134,7 +134,7 @@ public class OwnershipAndCheckpoint{ * @param ownOpId * @throws MDBCServiceException */ - public void checkpoint(MusicInterface mi, DBInterface di, Dag extendedDag, List ranges, + public void checkpoint(MusicInterface mi, DBInterface di, Dag extendedDag, Set ranges, Map locks, UUID ownOpId) throws MDBCServiceException { if(ranges.isEmpty()){ return; @@ -171,7 +171,7 @@ public class OwnershipAndCheckpoint{ } } - private void applyTxDigest(List ranges, DBInterface di, StagingTable txDigest) + private void applyTxDigest(Set ranges, DBInterface di, StagingTable txDigest) throws MDBCServiceException { try { di.applyTxDigest(txDigest,ranges); @@ -187,7 +187,7 @@ public class OwnershipAndCheckpoint{ * @param rangesToWarmup * @throws MDBCServiceException */ - public void warmup(MusicInterface mi, DBInterface di, List rangesToWarmup) throws MDBCServiceException { + public void warmup(MusicInterface mi, DBInterface di, Set rangesToWarmup) throws MDBCServiceException { if(rangesToWarmup.isEmpty()){ return; } @@ -236,7 +236,7 @@ public class OwnershipAndCheckpoint{ * @param pair * @throws MDBCServiceException */ - private void applyDigestAndUpdateDataStructures(MusicInterface mi, DBInterface di, List ranges, DagNode node, + private void applyDigestAndUpdateDataStructures(MusicInterface mi, DBInterface di, Set ranges, DagNode node, Pair> pair) throws MDBCServiceException { final StagingTable txDigest; try { @@ -278,7 +278,7 @@ public class OwnershipAndCheckpoint{ * @param ownOpId * @throws MDBCServiceException */ - private void applyRequiredChanges(MusicInterface mi, DBInterface db, Dag extendedDag, List ranges, UUID ownOpId) + private void applyRequiredChanges(MusicInterface mi, DBInterface db, Dag extendedDag, Set ranges, UUID ownOpId) throws MDBCServiceException { Set rangeSet = new HashSet(ranges); disableForeignKeys(db); @@ -309,7 +309,7 @@ public class OwnershipAndCheckpoint{ * @return an object indicating the status of the own function result * @throws MDBCServiceException */ - public OwnershipReturn own(MusicInterface mi, List ranges, + public OwnershipReturn own(MusicInterface mi, Set ranges, DatabasePartition currPartition, UUID opId, SQLOperationType lockType) throws MDBCServiceException { if (ranges == null || ranges.isEmpty()) { @@ -323,15 +323,15 @@ public class OwnershipAndCheckpoint{ currPartition.getSnapshot(),null); } //Find - Map newLocks = new HashMap<>(); - List rangesToOwn = mi.getRangeDependencies(ranges); + Map locksForOwnership = new HashMap<>(); + Set rangesToOwn = mi.getRangeDependencies(ranges); List rangesToOwnRows = extractRowsForRange(mi,rangesToOwn, false); Dag toOwn = Dag.getDag(rangesToOwnRows,rangesToOwn); Dag currentlyOwn = new Dag(); while ( (toOwn.isDifferent(currentlyOwn) || !currentlyOwn.isOwned() ) && !timeout(opId) ) { - takeOwnershipOfDag(mi, currPartition, opId, newLocks, toOwn, lockType); + takeOwnershipOfDag(mi, currPartition, opId, locksForOwnership, toOwn, lockType); currentlyOwn=toOwn; //TODO instead of comparing dags, compare rows rangesToOwnRows = extractRowsForRange(mi, rangesToOwn, false); @@ -339,29 +339,30 @@ public class OwnershipAndCheckpoint{ } if (!currentlyOwn.isOwned() || toOwn.isDifferent(currentlyOwn)) { //hold on to previous partition - newLocks.remove(currPartition.getMRIIndex()); - mi.releaseLocks(newLocks); + locksForOwnership.remove(currPartition.getMRIIndex()); + mi.releaseLocks(locksForOwnership); stopOwnershipTimeoutClock(opId); logger.error("Error when owning a range: Timeout"); throw new MDBCServiceException("Ownership timeout"); } Set allRanges = currentlyOwn.getAllRanges(); - List latestRows = extractRowsForRange(mi, new ArrayList<>(allRanges), true); + //TODO: we shouldn't need to go back to music at this point + List latestRows = extractRowsForRange(mi, new HashSet<>(allRanges), true); currentlyOwn.setRowsPerLatestRange(getIsLatestPerRange(toOwn,latestRows)); - return mi.mergeLatestRowsIfNecessary(currentlyOwn,latestRows,ranges,newLocks,opId); + return mi.mergeLatestRowsIfNecessary(currentlyOwn,locksForOwnership,opId); } - + /** * Step through dag and take lock ownership of each range * @param partition current partition owned by system * @param opId - * @param newLocks + * @param ownershipLocks * @param toOwn * @param lockType * @throws MDBCServiceException */ private void takeOwnershipOfDag(MusicInterface mi, DatabasePartition partition, UUID opId, - Map newLocks, Dag toOwn, SQLOperationType lockType) throws MDBCServiceException { + Map ownershipLocks, Dag toOwn, SQLOperationType lockType) throws MDBCServiceException { while(toOwn.hasNextToOwn()){ DagNode node = toOwn.nextToOwn(); @@ -369,9 +370,9 @@ public class OwnershipAndCheckpoint{ UUID uuidToOwn = row.getPartitionIndex(); if (partition.isLocked() && partition.getMRIIndex().equals(uuidToOwn) ) { toOwn.setOwn(node); - newLocks.put(uuidToOwn, new LockResult(true, uuidToOwn, partition.getLockId(), + ownershipLocks.put(uuidToOwn, new LockResult(true, uuidToOwn, partition.getLockId(), false, partition.getSnapshot())); - } else if ( newLocks.containsKey(uuidToOwn) || !row.getIsLatest() ) { + } else if ( ownershipLocks.containsKey(uuidToOwn) || !row.getIsLatest() ) { toOwn.setOwn(node); } else { LockRequest request = new LockRequest(uuidToOwn, @@ -401,7 +402,7 @@ public class OwnershipAndCheckpoint{ // TODO look into updating the partition object with the latest lockId; if(owned){ toOwn.setOwn(node); - newLocks.put(uuidToOwn,result); + ownershipLocks.put(uuidToOwn,result); } else{ mi.relinquish(lockId,uuidToOwn.toString()); @@ -413,11 +414,11 @@ public class OwnershipAndCheckpoint{ public String getDebugInfo(MusicInterface mi, String rangesStr) { - List ranges = new ArrayList(); + Set ranges = new HashSet<>(); Arrays.stream(rangesStr.split(",")).forEach(a -> ranges.add(new Range(a))); StringBuffer buffer = new StringBuffer(); - List rangesToOwn; + Set rangesToOwn; try { rangesToOwn = mi.getRangeDependencies(ranges); List rangesToOwnRows = extractRowsForRange(mi,rangesToOwn, false); @@ -458,7 +459,7 @@ public class OwnershipAndCheckpoint{ public void reloadAlreadyApplied(DatabasePartition partition) throws MDBCServiceException { - List snapshot = partition.getSnapshot(); + Set snapshot = partition.getSnapshot(); UUID row = partition.getMRIIndex(); for(Range r : snapshot){ alreadyApplied.put(r,Pair.of(new MriReference(row),-1)); diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicRangeInformationRow.java b/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicRangeInformationRow.java index 6e6ade6..de711ef 100755 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicRangeInformationRow.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicRangeInformationRow.java @@ -19,6 +19,7 @@ */ package org.onap.music.mdbc.tables; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -49,8 +50,15 @@ public final class MusicRangeInformationRow implements Comparable prevPartitions) { + this.dbPartition = dbPartition; + this.redoLog = new ArrayList(); + this.isLatest = isLatest; + this.prevRowIndexes = prevPartitions; + } + public UUID getPartitionIndex() { - return dbPartition.getMRIIndex(); + return dbPartition.getMRIIndex(); } public boolean getIsLatest(){ return isLatest; } diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicTxDigestDaemon.java b/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicTxDigestDaemon.java index 5c6fae4..6f95d3c 100644 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicTxDigestDaemon.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicTxDigestDaemon.java @@ -51,7 +51,7 @@ public class MusicTxDigestDaemon implements Runnable { * @param dbi interface to the database that will replay the operations * @param ranges only these ranges will be applied from the digests */ - public void replayDigest(MusicInterface mi, DBInterface dbi, List ranges) throws MDBCServiceException { + public void replayDigest(MusicInterface mi, DBInterface dbi, Set ranges) throws MDBCServiceException { StagingTable transaction; String nodeName = stateManager.getMdbcServerName(); @@ -117,11 +117,11 @@ public class MusicTxDigestDaemon implements Runnable { List missingRanges = new ArrayList<>(); if (currentPartitions.size() != 0) { for (DatabasePartition part : currentPartitions) { - List partitionRanges = part.getSnapshot(); + Set partitionRanges = part.getSnapshot(); warmupRanges.removeAll(partitionRanges); } try { - stateManager.getOwnAndCheck().warmup(mi, dbi, new ArrayList<>(warmupRanges)); + stateManager.getOwnAndCheck().warmup(mi, dbi, new HashSet<>(warmupRanges)); } catch (MDBCServiceException e) { logger.error("Unable to update for partition : " + warmupRanges + ". " + e.getMessage()); continue; diff --git a/mdbc-server/src/main/java/org/onap/music/mdbc/tables/StagingTable.java b/mdbc-server/src/main/java/org/onap/music/mdbc/tables/StagingTable.java index 4ef9d30..9ff7a0f 100755 --- a/mdbc-server/src/main/java/org/onap/music/mdbc/tables/StagingTable.java +++ b/mdbc-server/src/main/java/org/onap/music/mdbc/tables/StagingTable.java @@ -266,7 +266,7 @@ public class StagingTable { digestBuilder.clear(); } - synchronized public boolean areEventualContained(List ranges){ + synchronized public boolean areEventualContained(Set ranges){ return eventuallyConsistentRanges.containsAll(ranges); } } diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/StateManagerTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/StateManagerTest.java index 899fff2..280c733 100644 --- a/mdbc-server/src/test/java/org/onap/music/mdbc/StateManagerTest.java +++ b/mdbc-server/src/test/java/org/onap/music/mdbc/StateManagerTest.java @@ -53,7 +53,7 @@ public class StateManagerTest { @Test public void testGetEventualRanges() throws NoSuchFieldException, SecurityException { - List evList = new ArrayList<>(); + Set evList = new HashSet<>(); evList.add(new Range("eventualRange")); FieldSetter.setField(stateManager, stateManager.getClass().getDeclaredField("eventualRanges"), evList); assertEquals(evList, stateManager.getEventualRanges()); @@ -61,7 +61,7 @@ public class StateManagerTest { @Test public void testSetEventualRanges() { - List evList = new ArrayList<>(); + Set evList = new HashSet<>(); evList.add(new Range("eventualRange")); stateManager.setEventualRanges(evList); assertEquals(evList, stateManager.getEventualRanges()); @@ -116,7 +116,7 @@ public class StateManagerTest { allRanges.add(new Range("eventualRange")); Mockito.when(dbiMock.getSQLRangeSet()).thenReturn(allRanges); - List eventualRanges = new ArrayList(); + Set eventualRanges = new HashSet(); eventualRanges.add(new Range("eventualRange")); stateManager.setEventualRanges(eventualRanges); 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 f2bbdcd..ef26cb6 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 @@ -115,7 +115,7 @@ public class MusicMixinTest { @Test public void own() { Range range = new Range("TEST.TABLE1"); - List ranges = new ArrayList<>(); + Set ranges = new HashSet<>(); ranges.add(range); DatabasePartition partition=null; try { @@ -139,7 +139,7 @@ public class MusicMixinTest { } } - private DatabasePartition addRow(List ranges,boolean isLatest){ + private DatabasePartition addRow(Set ranges,boolean isLatest){ final UUID uuid = MDBCUtils.generateTimebasedUniqueKey(); DatabasePartition dbPartition = new DatabasePartition(ranges,uuid,null); MusicRangeInformationRow newRow = new MusicRangeInformationRow(dbPartition, new ArrayList<>(), isLatest); @@ -161,19 +161,19 @@ public class MusicMixinTest { @Ignore // TODO: Move ownership tests to OwnershipAndCheckpointTest @Test(timeout=1000) public void own2() throws InterruptedException, MDBCServiceException { - List range12 = new ArrayList<>( Arrays.asList( + Set range12 = new HashSet<>( Arrays.asList( new Range("TEST.RANGE1"), new Range("TEST.RANGE2") )); - List range34 = new ArrayList<>( Arrays.asList( + Set range34 = new HashSet<>( Arrays.asList( new Range("TEST.RANGE3"), new Range("TEST.RANGE4") )); - List range24 = new ArrayList<>( Arrays.asList( + Set range24 = new HashSet<>( Arrays.asList( new Range("TEST.RANGE2"), new Range("TEST.RANGE4") )); - List range123 = new ArrayList<>( Arrays.asList( + Set range123 = new HashSet<>( Arrays.asList( new Range("TEST.RANGE1"), new Range("TEST.RANGE2"), new Range("TEST.RANGE3") @@ -225,7 +225,7 @@ public class MusicMixinTest { MusicRangeInformationRow row = mixin.getMusicRangeInformation(own.getRangeId()); assertTrue(row.getIsLatest()); DatabasePartition dbPartition = row.getDBPartition(); - List snapshot = dbPartition.getSnapshot(); + Set snapshot = dbPartition.getSnapshot(); assertEquals(3,snapshot.size()); MusicRangeInformationRow node5row = mixin.getMusicRangeInformation(node5.getId()); assertFalse(node5row.getIsLatest()); diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/PostgresMixinTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/PostgresMixinTest.java index 2134a79..a1cf2b1 100644 --- a/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/PostgresMixinTest.java +++ b/mdbc-server/src/test/java/org/onap/music/mdbc/mixins/PostgresMixinTest.java @@ -24,6 +24,7 @@ import static org.junit.Assert.*; import java.sql.*; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; import java.util.Properties; import java.util.Set; @@ -207,7 +208,7 @@ public class PostgresMixinTest { assertFalse(st.isEmpty()); cleanTestTable(); checkEmptyTestTable(); - List ranges = new ArrayList<>(); + Set ranges = new HashSet<>(); ranges.add(new Range("public.testtable")); try { mixin.applyTxDigest(st,ranges); diff --git a/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/DagTest.java b/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/DagTest.java index fa5583c..ee50dca 100644 --- a/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/DagTest.java +++ b/mdbc-server/src/test/java/org/onap/music/mdbc/ownership/DagTest.java @@ -43,12 +43,12 @@ import static org.junit.Assert.*; public class DagTest { - private MusicRangeInformationRow createNewRow(List ranges, String lockid, boolean isLatest){ + private MusicRangeInformationRow createNewRow(Set ranges, String lockid, boolean isLatest){ List redoLog = new ArrayList<>(); return createNewRow(ranges,lockid,isLatest,redoLog); } - private MusicRangeInformationRow createNewRow(List ranges, String lockid, boolean isLatest, + private MusicRangeInformationRow createNewRow(Set ranges, String lockid, boolean isLatest, List redoLog) { UUID id = MDBCUtils.generateTimebasedUniqueKey(); DatabasePartition dbPartition = new DatabasePartition(ranges, id, lockid); @@ -58,14 +58,14 @@ public class DagTest { @Test public void getDag() throws InterruptedException, MDBCServiceException { List rows = new ArrayList<>(); - List ranges = new ArrayList<>( Arrays.asList( + Set ranges = new HashSet<>( Arrays.asList( new Range("schema.range1") )); - rows.add(createNewRow(new ArrayList<>(ranges),"",false)); + rows.add(createNewRow(new HashSet<>(ranges),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(ranges),"",false)); + rows.add(createNewRow(new HashSet<>(ranges),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(ranges),"",true)); + rows.add(createNewRow(new HashSet<>(ranges),"",true)); Dag dag = Dag.getDag(rows, ranges); DagNode node1 = dag.getNode(rows.get(0).getPartitionIndex()); DagNode node2 = dag.getNode(rows.get(1).getPartitionIndex()); @@ -92,15 +92,15 @@ public class DagTest { List range2 = new ArrayList<>( Arrays.asList( new Range("schema.range2") )); - List ranges = new ArrayList<>( Arrays.asList( + Set ranges = new HashSet<>( Arrays.asList( new Range("schema.range2"), new Range("schema.range1") )); - rows.add(createNewRow(new ArrayList<>(range1),"",false)); + rows.add(createNewRow(new HashSet<>(range1),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range2),"",false)); + rows.add(createNewRow(new HashSet<>(range2),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(ranges),"",true)); + rows.add(createNewRow(new HashSet<>(ranges),"",true)); Dag dag = Dag.getDag(rows, ranges); DagNode node1 = dag.getNode(rows.get(0).getPartitionIndex()); DagNode node2 = dag.getNode(rows.get(1).getPartitionIndex()); @@ -122,14 +122,14 @@ public class DagTest { @Test public void nextToOwn() throws InterruptedException, MDBCServiceException { List rows = new ArrayList<>(); - List ranges = new ArrayList<>( Arrays.asList( + Set ranges = new HashSet<>( Arrays.asList( new Range("schema.range1") )); - rows.add(createNewRow(new ArrayList<>(ranges),"",false)); + rows.add(createNewRow(new HashSet<>(ranges),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(ranges),"",false)); + rows.add(createNewRow(new HashSet<>(ranges),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(ranges),"",true)); + rows.add(createNewRow(new HashSet<>(ranges),"",true)); Dag dag = Dag.getDag(rows, ranges); int counter = 0; while(dag.hasNextToOwn()){ @@ -148,23 +148,23 @@ public class DagTest { @Test public void nextToApply() throws InterruptedException { List rows = new ArrayList<>(); - List ranges = new ArrayList<>( Arrays.asList( + Set ranges = new HashSet<>( Arrays.asList( new Range("schema.range1") )); List redo1 = new ArrayList<>(Arrays.asList( new MusicTxDigestId(null,MDBCUtils.generateUniqueKey(),0) )); - rows.add(createNewRow(new ArrayList<>(ranges),"",false,redo1)); + rows.add(createNewRow(new HashSet<>(ranges),"",false,redo1)); MILLISECONDS.sleep(10); List redo2 = new ArrayList<>(Arrays.asList( new MusicTxDigestId(null,MDBCUtils.generateUniqueKey(),0) )); - rows.add(createNewRow(new ArrayList<>(ranges),"",false,redo2)); + rows.add(createNewRow(new HashSet<>(ranges),"",false,redo2)); MILLISECONDS.sleep(10); List redo3 = new ArrayList<>(Arrays.asList( new MusicTxDigestId(null,MDBCUtils.generateUniqueKey(),0) )); - rows.add(createNewRow(new ArrayList<>(ranges),"",true,redo3)); + rows.add(createNewRow(new HashSet<>(ranges),"",true,redo3)); Dag dag = Dag.getDag(rows, ranges); int nodeCounter = 0; HashSet rangesSet = new HashSet<>(ranges); @@ -194,26 +194,26 @@ public class DagTest { public void nextToApply2() throws InterruptedException, MDBCServiceException { Map> alreadyApplied = new HashMap<>(); List rows = new ArrayList<>(); - List ranges = new ArrayList<>( Arrays.asList( + Set ranges = new HashSet<>( Arrays.asList( new Range("schema.range1") )); List redo1 = new ArrayList<>(Arrays.asList( new MusicTxDigestId(null,MDBCUtils.generateUniqueKey(),0) )); - rows.add(createNewRow(new ArrayList<>(ranges),"",false,redo1)); + rows.add(createNewRow(new HashSet<>(ranges),"",false,redo1)); MILLISECONDS.sleep(10); List redo2 = new ArrayList<>(Arrays.asList( new MusicTxDigestId(null,MDBCUtils.generateUniqueKey(),0), new MusicTxDigestId(null,MDBCUtils.generateUniqueKey(),1) )); - MusicRangeInformationRow newRow = createNewRow(new ArrayList<>(ranges), "", false, redo2); + MusicRangeInformationRow newRow = createNewRow(new HashSet<>(ranges), "", false, redo2); alreadyApplied.put(new Range("schema.range1"),Pair.of(new MriReference(newRow.getPartitionIndex()), 0)); rows.add(newRow); MILLISECONDS.sleep(10); List redo3 = new ArrayList<>(Arrays.asList( new MusicTxDigestId(null,MDBCUtils.generateUniqueKey(),0) )); - rows.add(createNewRow(new ArrayList<>(ranges),"",true,redo3)); + rows.add(createNewRow(new HashSet<>(ranges),"",true,redo3)); Dag dag = Dag.getDag(rows, ranges); HashSet rangesSet = new HashSet<>(ranges); dag.setAlreadyApplied(alreadyApplied, rangesSet); @@ -249,22 +249,22 @@ public class DagTest { List range2 = new ArrayList<>( Arrays.asList( new Range("schema.range2") )); - List ranges = new ArrayList<>( Arrays.asList( + Set ranges = new HashSet<>( Arrays.asList( new Range("schema.range2"), new Range("schema.range1") )); - rows.add(createNewRow(new ArrayList<>(range1),"",false)); + rows.add(createNewRow(new HashSet<>(range1),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range2),"",false)); + rows.add(createNewRow(new HashSet<>(range2),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(ranges),"",true)); + rows.add(createNewRow(new HashSet<>(ranges),"",true)); List rows2 = new ArrayList<>(rows); List rows3 = new ArrayList<>(rows); MILLISECONDS.sleep(10); - rows3.add(createNewRow(new ArrayList<>(ranges),"",true)); + rows3.add(createNewRow(new HashSet<>(ranges),"",true)); Dag dag = Dag.getDag(rows, ranges); - Dag dag2 = Dag.getDag(rows2, new ArrayList<>(ranges)); - Dag dag3 = Dag.getDag(rows3, new ArrayList<>(ranges)); + Dag dag2 = Dag.getDag(rows2, new HashSet<>(ranges)); + Dag dag3 = Dag.getDag(rows3, new HashSet<>(ranges)); assertFalse(dag.isDifferent(dag2)); assertFalse(dag2.isDifferent(dag)); assertTrue(dag.isDifferent(dag3)); @@ -282,19 +282,19 @@ public class DagTest { List range2 = new ArrayList<>( Arrays.asList( new Range("schema.range2") )); - List ranges = new ArrayList<>( Arrays.asList( + Set ranges = new HashSet<>( Arrays.asList( new Range("schema.range2"), new Range("schema.range1") )); - rows.add(createNewRow(new ArrayList<>(range1),"",false)); + rows.add(createNewRow(new HashSet<>(range1),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range2),"",false)); + rows.add(createNewRow(new HashSet<>(range2),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range1),"",true)); + rows.add(createNewRow(new HashSet<>(range1),"",true)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range2),"",true)); + rows.add(createNewRow(new HashSet<>(range2),"",true)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(ranges),"",true)); + rows.add(createNewRow(new HashSet<>(ranges),"",true)); Dag dag = Dag.getDag(rows, ranges); List oldestDoubles = dag.getOldestDoubles(); assertTrue(oldestDoubles.contains(dag.getNode(rows.get(2).getPartitionIndex()))); @@ -312,22 +312,22 @@ public class DagTest { new Range("schema.range2"), new Range("schema.range3") )); - List ranges = new ArrayList<>( Arrays.asList( + Set ranges = new HashSet<>( Arrays.asList( new Range("schema.range2"), new Range("schema.range1") )); - rows.add(createNewRow(new ArrayList<>(range1),"",false)); + rows.add(createNewRow(new HashSet<>(range1),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range2),"",false)); + rows.add(createNewRow(new HashSet<>(range2),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range1),"",true)); + rows.add(createNewRow(new HashSet<>(range1),"",true)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range2),"",true)); + rows.add(createNewRow(new HashSet<>(range2),"",true)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(ranges),"",true)); + rows.add(createNewRow(new HashSet<>(ranges),"",true)); Dag dag = Dag.getDag(rows, ranges); - Pair, Set> incompleteRangesAndDependents = dag.getIncompleteRangesAndDependents(); - List incomplete = incompleteRangesAndDependents.getKey(); + Pair, Set> incompleteRangesAndDependents = dag.getIncompleteRangesAndDependents(); + Set incomplete = incompleteRangesAndDependents.getKey(); Set dependents = incompleteRangesAndDependents.getValue(); assertEquals(1,incomplete.size()); assertTrue(incomplete.contains(new Range("schema.range3"))); @@ -346,22 +346,22 @@ public class DagTest { new Range("schema.range2"), new Range("schema.range3") )); - List ranges = new ArrayList<>( Arrays.asList( + Set ranges = new HashSet<>( Arrays.asList( new Range("schema.range2"), new Range("schema.range1") )); - rows.add(createNewRow(new ArrayList<>(range1),"",false)); + rows.add(createNewRow(new HashSet<>(range1),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range2),"",false)); + rows.add(createNewRow(new HashSet<>(range2),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range1),"",true)); + rows.add(createNewRow(new HashSet<>(range1),"",true)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range2),"",true)); + rows.add(createNewRow(new HashSet<>(range2),"",true)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(ranges),"",true)); + rows.add(createNewRow(new HashSet<>(ranges),"",true)); Dag dag = Dag.getDag(rows, ranges); - Pair, Set> incompleteRangesAndDependents = dag.getIncompleteRangesAndDependents(); - List incomplete = incompleteRangesAndDependents.getKey(); + Pair, Set> incompleteRangesAndDependents = dag.getIncompleteRangesAndDependents(); + Set incomplete = incompleteRangesAndDependents.getKey(); Set dependents = incompleteRangesAndDependents.getValue(); assertEquals(2,incomplete.size()); assertTrue(incomplete.contains(new Range("schema.range3"))); @@ -381,26 +381,26 @@ public class DagTest { new Range("schema.range2"), new Range("schema.range3") )); - List ranges = new ArrayList<>( Arrays.asList( + Set ranges = new HashSet<>( Arrays.asList( new Range("schema.range2"), new Range("schema.range1") )); - List allRanges = new ArrayList<>( Arrays.asList( + Set allRanges = new HashSet<>( Arrays.asList( new Range("schema.range2"), new Range("schema.range3"), new Range("schema.range1") )); - rows.add(createNewRow(new ArrayList<>(range1),"",false)); + rows.add(createNewRow(new HashSet<>(range1),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range2),"",false)); + rows.add(createNewRow(new HashSet<>(range2),"",false)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range1),"",true)); + rows.add(createNewRow(new HashSet<>(range1),"",true)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(range2),"",true)); + rows.add(createNewRow(new HashSet<>(range2),"",true)); MILLISECONDS.sleep(10); - rows.add(createNewRow(new ArrayList<>(ranges),"",true)); + rows.add(createNewRow(new HashSet<>(ranges),"",true)); Dag dag = Dag.getDag(rows, ranges); - MusicRangeInformationRow newRow = createNewRow(new ArrayList<>(allRanges), "", true); + MusicRangeInformationRow newRow = createNewRow(new HashSet<>(allRanges), "", true); dag.addNewNodeWithSearch(newRow,allRanges); DagNode newNode = dag.getNode(newRow.getPartitionIndex()); DagNode node = dag.getNode(rows.get(4).getPartitionIndex()); 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 59f001c..2443d1e 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 @@ -171,7 +171,7 @@ public class OwnershipAndCheckpointTest { } } - private OwnershipReturn cleanAndOwnPartition(List ranges, UUID ownOpId) throws SQLException { + private OwnershipReturn cleanAndOwnPartition(Set ranges, UUID ownOpId) throws SQLException { dropAndCreateTable(); cleanAlreadyApplied(ownAndCheck); DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey()); @@ -214,7 +214,7 @@ public class OwnershipAndCheckpointTest { initDatabase(range); - List ranges = new ArrayList<>(); + Set ranges = new HashSet<>(); ranges.add(range); UUID ownOpId = MDBCUtils.generateTimebasedUniqueKey(); OwnershipReturn own = cleanAndOwnPartition(ranges,ownOpId); @@ -238,7 +238,7 @@ public class OwnershipAndCheckpointTest { initDatabase(range); - List ranges = new ArrayList<>(); + Set ranges = new HashSet<>(); ranges.add(range); UUID ownOpId = MDBCUtils.generateTimebasedUniqueKey(); OwnershipReturn own = cleanAndOwnPartition(ranges,ownOpId); @@ -260,7 +260,7 @@ public class OwnershipAndCheckpointTest { public void readOwn() throws Exception { Range range = new Range("TABLE1"); MusicInterface mi = MdbcTestUtils.getMusicMixin(); - List ranges = new ArrayList<>(); + Set ranges = new HashSet<>(); ranges.add(range); final DatabasePartition partition = TestUtils.createBasicRow(range, mi, MdbcTestUtils.getServerName()); TestUtils.unlockRow(MdbcTestUtils.getKeyspace(), MdbcTestUtils.getMriTableName(), partition); -- cgit 1.2.3-korg