aboutsummaryrefslogtreecommitdiffstats
path: root/mdbc-server/src
diff options
context:
space:
mode:
authorTschaen, Brendan <ctschaen@att.com>2019-07-03 12:54:25 -0400
committerTschaen, Brendan <ctschaen@att.com>2019-07-09 11:31:43 -0400
commit618b63253109a373909aa46452e16811302a24e7 (patch)
tree55dbf8109586b91467aaa6e887786203903dfc0c /mdbc-server/src
parent8676c0e2fa908386d81ed8e3f0ee4018e99445f7 (diff)
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 <ctschaen@att.com> Change-Id: Ie7aaeb3ff43073eb3947515523e73037089e763d
Diffstat (limited to 'mdbc-server/src')
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/DatabasePartition.java16
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/MDBCUtils.java7
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/MdbcConnection.java26
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/Range.java4
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/StateManager.java14
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/TestUtils.java2
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/configurations/Eventual.java9
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/configurations/NodeConfiguration.java8
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/configurations/TablesConfiguration.java3
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/examples/MdbcTestClient.java64
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/mixins/DBInterface.java4
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/mixins/LockResult.java9
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicInterface.java33
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/mixins/MusicMixin.java126
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/mixins/MySQLMixin.java7
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/mixins/PostgresMixin.java5
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/ownership/Dag.java16
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/ownership/DagNode.java4
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpoint.java51
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicRangeInformationRow.java10
-rw-r--r--mdbc-server/src/main/java/org/onap/music/mdbc/tables/MusicTxDigestDaemon.java6
-rwxr-xr-xmdbc-server/src/main/java/org/onap/music/mdbc/tables/StagingTable.java2
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/StateManagerTest.java6
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/mixins/MusicMixinTest.java14
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/mixins/PostgresMixinTest.java3
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/ownership/DagTest.java118
-rw-r--r--mdbc-server/src/test/java/org/onap/music/mdbc/ownership/OwnershipAndCheckpointTest.java8
27 files changed, 329 insertions, 246 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 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<Range> ranges;
+ protected Set<Range> ranges;
private boolean ready;
@@ -49,14 +49,14 @@ public class DatabasePartition {
*/
public DatabasePartition() {
- this(new ArrayList<Range>(),null,"");
+ this(new HashSet<Range>(),null,"");
}
public DatabasePartition(UUID mriIndex) {
- this(new ArrayList<Range>(), mriIndex,"");
+ this(new HashSet<Range>(), mriIndex,"");
}
-
- public DatabasePartition(List<Range> knownRanges, UUID mriIndex, String lockId) {
+
+ public DatabasePartition(Set<Range> 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<Range> getSnapshot() {
- List<Range> newRange = new ArrayList<>();
- for(Range r : ranges){
+ public synchronized Set<Range> getSnapshot() {
+ Set<Range> 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<Range> getTables(Map<String,List<SQLOperation>> queryParsed){
+ public static Set<Range> getTables(Map<String,List<SQLOperation>> queryParsed){
return getTables(null, queryParsed);
}
- public static List<Range> getTables(String defaultDatabaseName, Map<String,List<SQLOperation>> queryParsed){
- List<Range> ranges = new ArrayList<>();
+ public static Set<Range> getTables(String defaultDatabaseName, Map<String,List<SQLOperation>> queryParsed){
+ Set<Range> 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<String, List<SQLOperation>> tableToQueryType = QueryProcessor.parseSqlQuery(sql, table_set);
//Check ownership of keys
String defaultSchema = dbi.getSchema();
- List<Range> queryTables = MDBCUtils.getTables(defaultSchema, tableToQueryType);
+ Set<Range> queryTables = MDBCUtils.getTables(defaultSchema, tableToQueryType);
if (this.partition!=null) {
- List<Range> snapshot = this.partition.getSnapshot();
+ Set<Range> 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<Range> scQueryTables = filterEveTables(queryTables);
+ Set<Range> 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<Range> filterEveTables(List<Range> queryTables) {
+ private Set<Range> filterEveTables(Set<Range> 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<Range> set1 = dbi.getSQLRangeSet(); // set of tables in the database
+ public void createTriggers() throws QueryException {
+ Set<String> 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<Range> ranges, SQLOperationType lockType) throws MDBCServiceException {
+ private DatabasePartition own(Set<Range> 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<Range> ranges, String table){
+ public static boolean overlaps(Set<Range> 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<String,DatabasePartition> connectionRanges;//Each connection owns its own database partition
private final Lock eventualLock = new ReentrantLock();
- private List<Range> eventualRanges;
+ private Set<Range> 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<Range> getEventualRanges() {
+ public Set<Range> getEventualRanges() {
eventualLock.lock();
- List<Range> returnArray;
+ Set<Range> 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<Range> eventualRanges) {
+ public void setEventualRanges(Set<Range> 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<Range> ranges = new ArrayList<>();
+ Set<Range> 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<Range> ranges;
+ protected Set<Range> ranges;
- public Eventual(List<Range> ranges) {
+ public Eventual(Set<Range> ranges) {
super();
this.ranges = ranges;
}
- public List<Range> getRanges() {
+ public Set<Range> getRanges() {
return ranges;
}
- public void setRanges(List<Range> ranges) {
+ public void setRanges(Set<Range> 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<Range> toRanges(List<String> tables){
- List<Range> newRange = new ArrayList<>();
+ protected Set<Range> toRanges(List<String> tables){
+ Set<Range> newRange = new HashSet<>();
for(String table: tables) {
newRange.add(new Range(table));
}
return newRange;
}
- protected List<Range> toRanges(String tables){
+ protected Set<Range> 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<Range> ranges = mriRowFromCassandraRow.getDBPartition().getSnapshot();
+ Set<Range> 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<Range> ranges) throws SQLException, MDBCServiceException;
+ void replayTransaction(StagingTable digest, Set<Range> ranges) throws SQLException, MDBCServiceException;
void disableForeignKeyChecks() throws SQLException;
void enableForeignKeyChecks() throws SQLException;
- void applyTxDigest(StagingTable txDigest, List<Range> ranges) throws SQLException, MDBCServiceException;
+ void applyTxDigest(StagingTable txDigest, Set<Range> 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<Range> ranges;
+ private Set<Range> ranges;
private boolean newLock;
/** back off time in milliseconds */
private long backOffPeriodms;
- public LockResult(boolean succesful, UUID rowId, String lockId, boolean newLock, List<Range> ranges){
+ public LockResult(boolean succesful, UUID rowId, String lockId, boolean newLock, Set<Range> 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<Range> ranges){
+ public LockResult(UUID rowId, String lockId, boolean newLock, Set<Range> ranges){
this.successful = true;
this.musicRangeInformationIndex = rowId;
this.lockId=lockId;
@@ -74,7 +75,7 @@ public class LockResult{
return musicRangeInformationIndex;
}
- public List<Range> getRanges() {
+ public Set<Range> 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<Range> ranges;
+ private final Set<Range> ranges;
private final Dag dag;
- public OwnershipReturn(UUID ownershipId, String ownerId, UUID rangeId, List<Range> ranges, Dag dag){
+ public OwnershipReturn(UUID ownershipId, String ownerId, UUID rangeId, Set<Range> 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<Range> getRanges(){ return ranges; }
+ public Set<Range> 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<Range> eventualRanges, StagingTable transactionDigest, String txId,TxCommitProgress progressKeeper) throws MDBCServiceException;
+ void commitLog(DatabasePartition partition, Set<Range> eventualRanges, StagingTable transactionDigest, String txId,TxCommitProgress progressKeeper) throws MDBCServiceException;
/**
@@ -208,7 +208,7 @@ public interface MusicInterface {
*/
RangeDependency getMusicRangeDependency(Range baseRange) throws MDBCServiceException;
- List<Range> getRangeDependencies(List<Range> range) throws MDBCServiceException;
+ public Set<Range> getRangeDependencies(Set<Range> range) throws MDBCServiceException;
/**
* This function is used to create a new locked row in the MRI table
@@ -329,18 +329,22 @@ 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<MusicRangeInformationRow> latestRows, List<Range> ranges,
- Map<UUID, LockResult> locks, UUID ownershipId) throws MDBCServiceException;
+ OwnershipReturn mergeLatestRowsIfNecessary(Dag currentlyOwned, Map<UUID, LockResult> 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
* @param r
@@ -348,6 +352,5 @@ public interface MusicInterface {
*/
public void updateCheckpointLocations(Range r, Pair<UUID, Integer> 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<Range> lockRow(LockRequest request,Map.Entry<UUID, List<Range>> pending,Map<UUID, String> currentLockRef,
+ 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{
@@ -1293,7 +1294,7 @@ public class MusicMixin implements MusicInterface {
* This officially commits the transaction globally
*/
@Override
- public void commitLog(DatabasePartition partition,List<Range> eventualRanges, StagingTable transactionDigest,
+ public void commitLog(DatabasePartition partition,Set<Range> 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<Range> snapshot = partition.getSnapshot();
+ Set<Range> 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<Range> ranges = partition.getSnapshot();
+ Set<Range> ranges = partition.getSnapshot();
for(Range r : ranges) {
Map<Range, Pair<MriReference, Integer>> alreadyApplied = stateManager.getOwnAndCheck().getAlreadyApplied();
if(!alreadyApplied.containsKey(r)){
@@ -1380,7 +1381,7 @@ public class MusicMixin implements MusicInterface {
}
}
- private void filterAndAddEventualTxDigest(List<Range> eventualRanges,
+ private void filterAndAddEventualTxDigest(Set<Range> 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<Range> partitions = new ArrayList<>();
+ Set<Range> partitions = new HashSet<>();
Set<String> 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<Range> getRangeDependencies(List<Range> range) throws MDBCServiceException{
+ public Set<Range> getRangeDependencies(Set<Range> range) throws MDBCServiceException{
Set<Range> 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<MusicRangeInformationRow> rows,List<Range> ranges,
- Map<UUID,LockResult> locks) throws MDBCServiceException{
- Pair<List<Range>,Set<DagNode>> rangesAndDependents = latestDag.getIncompleteRangesAndDependents();
+ private void recoverFromFailureAndUpdateDag(Dag latestDag, Map<UUID,LockResult> locks) 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){
return;
}
- MusicRangeInformationRow r = createAndAssignLock(rangesAndDependents.getKey(), rows);
+
+ Set<UUID> 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<MusicRangeInformationRow> setReadOnlyAnyDoubleRow(Dag latestDag,List<MusicRangeInformationRow> rows, Map<UUID,LockResult> locks)
+ private List<MusicRangeInformationRow> setReadOnlyAnyDoubleRow(Dag latestDag,Map<UUID,LockResult> locks)
throws MDBCServiceException{
List<MusicRangeInformationRow> returnInfo = new ArrayList<>();
List<DagNode> toDisable = latestDag.getOldestDoubles();
@@ -2143,15 +2147,6 @@ public class MusicMixin implements MusicInterface {
return returnInfo;
}
- private MusicRangeInformationRow createAndAssignLock(List<Range> ranges, List<MusicRangeInformationRow> 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<MusicRangeInformationRow> latestRows,
- List<Range> ranges, Map<UUID, LockResult> 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<UUID, LockResult> 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<MusicRangeInformationRow> 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<List<Range>, Set<DagNode>> 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<MusicRangeInformationRow> changed = setReadOnlyAnyDoubleRow(currentlyOwned, locksForOwnership);
+ releaseLocks(changed, locksForOwnership);
+
+ Set<Range> 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<Range> ranges, Set<UUID> 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<Range> extractRangesToOwn(Dag currentlyOwned, Set<UUID> UUIDs) {
+ HashSet<Range> ranges = new HashSet<>();
+ for (UUID uuid: UUIDs) {
+ ranges.addAll(currentlyOwned.getNode(uuid).getRow().getDBPartition().getSnapshot());
+ }
+ return ranges;
}
/**
@@ -2496,6 +2499,23 @@ public class MusicMixin implements MusicInterface {
}
@Override
+ public void createPartitionIfNeeded(Range rangeToCreate) throws MDBCServiceException {
+ List<MusicRangeInformationRow> 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<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());
+ }
+
+ @Override
public void updateCheckpointLocations(Range r, Pair<UUID, Integer> playbackPointer) {
String cql = String.format("INSERT INTO %s.%s (mdbcnode, mridigest, digestindex) VALUES ("
+ this.myId + ", " + playbackPointer.getLeft() + ", " + playbackPointer.getRight() + ");",
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<String> getSQLTableSet() {
Set<String> set = new TreeSet<String>();
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<Range> ranges)
+ public void replayTransaction(StagingTable transaction, Set<Range> 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<Range> ranges) throws SQLException, MDBCServiceException {
+ public void applyTxDigest(StagingTable txDigest, Set<Range> 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<Range> ranges)
+ @Override
+ public void replayTransaction(StagingTable transaction, Set<Range> 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<Range> ranges) throws SQLException, MDBCServiceException {
+ public void applyTxDigest(StagingTable txDigest, Set<Range> 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<MusicRangeInformationRow> rows, List<Range> ranges){
+ private void createDag(List<MusicRangeInformationRow> rows, Set<Range> ranges){
this.ranges = new ArrayList<>(ranges);
Map<Range,DagNode> 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<Range> nodeRanges = row.getDBPartition().getSnapshot();
+ Set<Range> 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<MusicRangeInformationRow> rows, List<Range> ranges){
+ public static Dag getDag(List<MusicRangeInformationRow> rows, Set<Range> 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<Range> ranges){
+ public synchronized DagNode nextToApply(Set<Range> ranges){
if(!readyInit){
initApplyDatastructures();
}
@@ -283,7 +283,7 @@ public class Dag {
}
}
- public void addNewNodeWithSearch(MusicRangeInformationRow row, List<Range> ranges) throws MDBCServiceException {
+ public void addNewNodeWithSearch(MusicRangeInformationRow row, Set<Range> ranges) throws MDBCServiceException {
Map<Range,DagNode> newestNode = new HashMap<>();
for(DagNode node : nodes.values()){
for(Range range : ranges) {
@@ -389,8 +389,8 @@ public class Dag {
return toDisable;
}
- public Pair<List<Range>,Set<DagNode>> getIncompleteRangesAndDependents() throws MDBCServiceException {
- List<Range> incomplete = new ArrayList<>();
+ public Pair<Set<Range>, Set<DagNode>> getIncompleteRangesAndDependents() throws MDBCServiceException {
+ Set<Range> incomplete = new HashSet<>();
Set<DagNode> dependents = new HashSet<>();
Map<Range,Set<DagNode>> rowsPerLatestRange = getIsLatestPerRange();
List<DagNode> 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<MusicRangeInformationRow> extractRowsForRange(List<MusicRangeInformationRow> allMriRows, List<Range> ranges,
+ private List<MusicRangeInformationRow> extractRowsForRange(List<MusicRangeInformationRow> allMriRows, Set<Range> ranges,
boolean onlyIsLatest){
List<MusicRangeInformationRow> rows = new ArrayList<>();
for(MusicRangeInformationRow row : allMriRows){
if(onlyIsLatest && !row.getIsLatest()){
continue;
}
- final List<Range> rowRanges = row.getDBPartition().getSnapshot();
+ final Set<Range> 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<MusicRangeInformationRow> extractRowsForRange(MusicInterface music, List<Range> ranges, boolean onlyIsLatest)
+ private List<MusicRangeInformationRow> extractRowsForRange(MusicInterface music, Set<Range> ranges, boolean onlyIsLatest)
throws MDBCServiceException {
final List<MusicRangeInformationRow> 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<Range> ranges,
+ public void checkpoint(MusicInterface mi, DBInterface di, Dag extendedDag, Set<Range> ranges,
Map<MusicRangeInformationRow, LockResult> locks, UUID ownOpId) throws MDBCServiceException {
if(ranges.isEmpty()){
return;
@@ -171,7 +171,7 @@ public class OwnershipAndCheckpoint{
}
}
- private void applyTxDigest(List<Range> ranges, DBInterface di, StagingTable txDigest)
+ private void applyTxDigest(Set<Range> 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<Range> rangesToWarmup) throws MDBCServiceException {
+ public void warmup(MusicInterface mi, DBInterface di, Set<Range> 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<Range> ranges, DagNode node,
+ private void applyDigestAndUpdateDataStructures(MusicInterface mi, DBInterface di, Set<Range> ranges, DagNode node,
Pair<MusicTxDigestId, List<Range>> 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<Range> ranges, UUID ownOpId)
+ private void applyRequiredChanges(MusicInterface mi, DBInterface db, Dag extendedDag, Set<Range> ranges, UUID ownOpId)
throws MDBCServiceException {
Set<Range> rangeSet = new HashSet<Range>(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<Range> ranges,
+ public OwnershipReturn own(MusicInterface mi, Set<Range> 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<UUID,LockResult> newLocks = new HashMap<>();
- List<Range> rangesToOwn = mi.getRangeDependencies(ranges);
+ Map<UUID,LockResult> locksForOwnership = new HashMap<>();
+ Set<Range> rangesToOwn = mi.getRangeDependencies(ranges);
List<MusicRangeInformationRow> rangesToOwnRows = extractRowsForRange(mi,rangesToOwn, false);
Dag toOwn = Dag.getDag(rangesToOwnRows,rangesToOwn);
Dag currentlyOwn = new Dag();
while ( (toOwn.isDifferent(currentlyOwn) || !currentlyOwn.isOwned() ) &&
!timeout(opId)
) {
- 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<Range> allRanges = currentlyOwn.getAllRanges();
- List<MusicRangeInformationRow> latestRows = extractRowsForRange(mi, new ArrayList<>(allRanges), true);
+ //TODO: we shouldn't need to go back to music at this point
+ List<MusicRangeInformationRow> 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<UUID, LockResult> newLocks, Dag toOwn, SQLOperationType lockType) throws MDBCServiceException {
+ Map<UUID, LockResult> 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<Range> ranges = new ArrayList<Range>();
+ Set<Range> ranges = new HashSet<>();
Arrays.stream(rangesStr.split(",")).forEach(a -> ranges.add(new Range(a)));
StringBuffer buffer = new StringBuffer();
- List<Range> rangesToOwn;
+ Set<Range> rangesToOwn;
try {
rangesToOwn = mi.getRangeDependencies(ranges);
List<MusicRangeInformationRow> rangesToOwnRows = extractRowsForRange(mi,rangesToOwn, false);
@@ -458,7 +459,7 @@ public class OwnershipAndCheckpoint{
public void reloadAlreadyApplied(DatabasePartition partition) throws MDBCServiceException {
- List<Range> snapshot = partition.getSnapshot();
+ Set<Range> 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<MusicRangeInfo
this.prevRowIndexes = prevPartitions;
}
+ public MusicRangeInformationRow(DatabasePartition dbPartition, boolean isLatest, Set<UUID> prevPartitions) {
+ this.dbPartition = dbPartition;
+ this.redoLog = new ArrayList<MusicTxDigestId>();
+ 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<Range> ranges) throws MDBCServiceException {
+ public void replayDigest(MusicInterface mi, DBInterface dbi, Set<Range> ranges) throws MDBCServiceException {
StagingTable transaction;
String nodeName = stateManager.getMdbcServerName();
@@ -117,11 +117,11 @@ public class MusicTxDigestDaemon implements Runnable {
List<Range> missingRanges = new ArrayList<>();
if (currentPartitions.size() != 0) {
for (DatabasePartition part : currentPartitions) {
- List<Range> partitionRanges = part.getSnapshot();
+ Set<Range> 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<Range> ranges){
+ synchronized public boolean areEventualContained(Set<Range> 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<Range> evList = new ArrayList<>();
+ Set<Range> 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<Range> evList = new ArrayList<>();
+ Set<Range> 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<Range> eventualRanges = new ArrayList<Range>();
+ Set<Range> eventualRanges = new HashSet<Range>();
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<Range> ranges = new ArrayList<>();
+ Set<Range> ranges = new HashSet<>();
ranges.add(range);
DatabasePartition partition=null;
try {
@@ -139,7 +139,7 @@ public class MusicMixinTest {
}
}
- private DatabasePartition addRow(List<Range> ranges,boolean isLatest){
+ private DatabasePartition addRow(Set<Range> 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<Range> range12 = new ArrayList<>( Arrays.asList(
+ Set<Range> range12 = new HashSet<>( Arrays.asList(
new Range("TEST.RANGE1"),
new Range("TEST.RANGE2")
));
- List<Range> range34 = new ArrayList<>( Arrays.asList(
+ Set<Range> range34 = new HashSet<>( Arrays.asList(
new Range("TEST.RANGE3"),
new Range("TEST.RANGE4")
));
- List<Range> range24 = new ArrayList<>( Arrays.asList(
+ Set<Range> range24 = new HashSet<>( Arrays.asList(
new Range("TEST.RANGE2"),
new Range("TEST.RANGE4")
));
- List<Range> range123 = new ArrayList<>( Arrays.asList(
+ Set<Range> 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<Range> snapshot = dbPartition.getSnapshot();
+ Set<Range> 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<Range> ranges = new ArrayList<>();
+ Set<Range> 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<Range> ranges, String lockid, boolean isLatest){
+ private MusicRangeInformationRow createNewRow(Set<Range> ranges, String lockid, boolean isLatest){
List<MusicTxDigestId> redoLog = new ArrayList<>();
return createNewRow(ranges,lockid,isLatest,redoLog);
}
- private MusicRangeInformationRow createNewRow(List<Range> ranges, String lockid, boolean isLatest,
+ private MusicRangeInformationRow createNewRow(Set<Range> ranges, String lockid, boolean isLatest,
List<MusicTxDigestId> 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<MusicRangeInformationRow> rows = new ArrayList<>();
- List<Range> ranges = new ArrayList<>( Arrays.asList(
+ Set<Range> 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<Range> range2 = new ArrayList<>( Arrays.asList(
new Range("schema.range2")
));
- List<Range> ranges = new ArrayList<>( Arrays.asList(
+ Set<Range> 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<MusicRangeInformationRow> rows = new ArrayList<>();
- List<Range> ranges = new ArrayList<>( Arrays.asList(
+ Set<Range> 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<MusicRangeInformationRow> rows = new ArrayList<>();
- List<Range> ranges = new ArrayList<>( Arrays.asList(
+ Set<Range> ranges = new HashSet<>( Arrays.asList(
new Range("schema.range1")
));
List<MusicTxDigestId> 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<MusicTxDigestId> 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<MusicTxDigestId> 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<Range> rangesSet = new HashSet<>(ranges);
@@ -194,26 +194,26 @@ public class DagTest {
public void nextToApply2() throws InterruptedException, MDBCServiceException {
Map<Range, Pair<MriReference, Integer>> alreadyApplied = new HashMap<>();
List<MusicRangeInformationRow> rows = new ArrayList<>();
- List<Range> ranges = new ArrayList<>( Arrays.asList(
+ Set<Range> ranges = new HashSet<>( Arrays.asList(
new Range("schema.range1")
));
List<MusicTxDigestId> 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<MusicTxDigestId> 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<MusicTxDigestId> 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<Range> rangesSet = new HashSet<>(ranges);
dag.setAlreadyApplied(alreadyApplied, rangesSet);
@@ -249,22 +249,22 @@ public class DagTest {
List<Range> range2 = new ArrayList<>( Arrays.asList(
new Range("schema.range2")
));
- List<Range> ranges = new ArrayList<>( Arrays.asList(
+ Set<Range> 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<MusicRangeInformationRow> rows2 = new ArrayList<>(rows);
List<MusicRangeInformationRow> 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<Range> range2 = new ArrayList<>( Arrays.asList(
new Range("schema.range2")
));
- List<Range> ranges = new ArrayList<>( Arrays.asList(
+ Set<Range> 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<DagNode> 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<Range> ranges = new ArrayList<>( Arrays.asList(
+ Set<Range> 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<List<Range>, Set<DagNode>> incompleteRangesAndDependents = dag.getIncompleteRangesAndDependents();
- List<Range> incomplete = incompleteRangesAndDependents.getKey();
+ Pair<Set<Range>, Set<DagNode>> incompleteRangesAndDependents = dag.getIncompleteRangesAndDependents();
+ Set<Range> incomplete = incompleteRangesAndDependents.getKey();
Set<DagNode> 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<Range> ranges = new ArrayList<>( Arrays.asList(
+ Set<Range> 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<List<Range>, Set<DagNode>> incompleteRangesAndDependents = dag.getIncompleteRangesAndDependents();
- List<Range> incomplete = incompleteRangesAndDependents.getKey();
+ Pair<Set<Range>, Set<DagNode>> incompleteRangesAndDependents = dag.getIncompleteRangesAndDependents();
+ Set<Range> incomplete = incompleteRangesAndDependents.getKey();
Set<DagNode> 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<Range> ranges = new ArrayList<>( Arrays.asList(
+ Set<Range> ranges = new HashSet<>( Arrays.asList(
new Range("schema.range2"),
new Range("schema.range1")
));
- List<Range> allRanges = new ArrayList<>( Arrays.asList(
+ Set<Range> 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<Range> ranges, UUID ownOpId) throws SQLException {
+ private OwnershipReturn cleanAndOwnPartition(Set<Range> ranges, UUID ownOpId) throws SQLException {
dropAndCreateTable();
cleanAlreadyApplied(ownAndCheck);
DatabasePartition currentPartition = new DatabasePartition(MDBCUtils.generateTimebasedUniqueKey());
@@ -214,7 +214,7 @@ public class OwnershipAndCheckpointTest {
initDatabase(range);
- List<Range> ranges = new ArrayList<>();
+ Set<Range> 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<Range> ranges = new ArrayList<>();
+ Set<Range> 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<Range> ranges = new ArrayList<>();
+ Set<Range> ranges = new HashSet<>();
ranges.add(range);
final DatabasePartition partition = TestUtils.createBasicRow(range, mi, MdbcTestUtils.getServerName());
TestUtils.unlockRow(MdbcTestUtils.getKeyspace(), MdbcTestUtils.getMriTableName(), partition);