Expose transaction concurrency indexes in streams and generators

This commit is contained in:
eyck committed 2026-11-14 18:13:22 +01:00
1 parent 40d402ce8a
commit 1f861cefb8
13 files changed
+264 -16

No files matched your search

@@ -148,7 +148,12 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
*/
synchronized void calculateConcurrency() {
if (rowCount >= 0) return;
int count = TxRowAllocator.assign(getEvents(), (event, row) -> ((TxEvent) event).setConcurrencyIndex(row));
int count = TxRowAllocator.assign(getEvents(), (event, row) -> {
((TxEvent) event).setConcurrencyIndex(row);
Tx tx = (Tx) event.getTransaction();
if (this instanceof TxGenerator) tx.setConcurrencyIdxInGen(row);
else tx.setConcurrencyIndxInStream(row);
});
for (com.minres.scviewer.database.IHierNode child : getChildNodes())
((TxGenerator) child).calculateConcurrency();
rowCount = count;
@@ -38,6 +38,9 @@ class Tx implements ITx {
private final long streamId;
private volatile int concurrencyIndxInStream = -1;
private volatile int concurrencyIdxInGen = -1;
/** The begin time. */
long beginTime = -1;
@@ -175,6 +178,26 @@ class Tx implements ITx {
return loader.txGenerators.get(generatorId);
}
@Override
public int getConcurrencyIndxInStream() {
if (concurrencyIndxInStream < 0) getStream().getRowCount();
return concurrencyIndxInStream;
}
@Override
public int getConcurrencyIdxInGen() {
if (concurrencyIdxInGen < 0) getGenerator().getRowCount();
return concurrencyIdxInGen;
}
void setConcurrencyIndxInStream(int index) {
concurrencyIndxInStream = index;
}
void setConcurrencyIdxInGen(int index) {
concurrencyIdxInGen = index;
}
/**
* Gets the begin time.
*
@@ -133,6 +133,16 @@ class TxRelation implements ITxRelation {
return resolve().getGenerator();
}
@Override
public int getConcurrencyIndxInStream() {
return resolve().getConcurrencyIndxInStream();
}
@Override
public int getConcurrencyIdxInGen() {
return resolve().getConcurrencyIdxInGen();
}
@Override
public long getBeginTime() {
return resolve().getBeginTime();
@@ -26,6 +26,7 @@ import com.minres.scviewer.database.RelationTypeFactory;
import com.minres.scviewer.database.WaveformType;
import com.minres.scviewer.database.sqlite.db.IDatabase;
import com.minres.scviewer.database.tx.ITx;
import com.minres.scviewer.database.tx.TxRowAllocator;
abstract class AbstractTxStream extends HierNode implements IWaveform {
@@ -46,7 +47,11 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
}
@Override
public int getRowCount() {
public synchronized int getRowCount() {
if (this instanceof TxGenerator) {
getEvents();
return maxConcurrency;
}
if(maxConcurrency==null){
StringBuilder sb = new StringBuilder();
sb.append("SELECT MAX(concurrencyLevel) as concurrencyLevel FROM ScvTx where stream=");
@@ -81,16 +86,20 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
EventList.Builder builder = new EventList.Builder();
for (ITx tx : getTransactions().values()) {
if (tx.getBeginTime() == tx.getEndTime()) {
TxEvent single = new TxEvent(EventKind.SINGLE, tx);
TxEvent single = new TxEvent(EventKind.SINGLE, tx, this instanceof TxGenerator);
builder.add(single.getTime(), single);
} else {
TxEvent begin = new TxEvent(EventKind.BEGIN, tx);
TxEvent end = new TxEvent(EventKind.END, tx);
TxEvent begin = new TxEvent(EventKind.BEGIN, tx, this instanceof TxGenerator);
TxEvent end = new TxEvent(EventKind.END, tx, this instanceof TxGenerator);
builder.add(begin.getTime(), begin);
builder.add(end.getTime(), end);
}
}
events = builder.build();
IEventList loaded = builder.build();
if (this instanceof TxGenerator)
maxConcurrency = TxRowAllocator.assign(loaded,
(event, row) -> ((Tx) event.getTransaction()).setConcurrencyIdxInGen(row));
events = loaded;
}
return events;
}
@@ -34,6 +34,7 @@ public class Tx implements ITx {
private TxStream trStream;
private TxGenerator trGenerator;
private ScvTx scvTx;
private volatile int concurrencyIdxInGen = -1;
private List<ITxAttribute> attributes;
private final long begin;
private final long end;
@@ -65,9 +66,20 @@ public class Tx implements ITx {
return trGenerator;
}
int getConcurrencyIndex() {
return scvTx.getConcurrencyLevel();
}
@Override
public int getConcurrencyIndxInStream() {
return scvTx.getConcurrencyLevel();
}
@Override
public int getConcurrencyIdxInGen() {
if (concurrencyIdxInGen < 0) trGenerator.getRowCount();
return concurrencyIdxInGen;
}
void setConcurrencyIdxInGen(int index) {
concurrencyIdxInGen = index;
}
@Override
public long getBeginTime() { return begin; }
@@ -19,12 +19,17 @@ import com.minres.scviewer.database.tx.ITxEvent;
public class TxEvent implements ITxEvent {
private final EventKind type;
private final boolean inGenerator;
private ITx tx;
public TxEvent(EventKind type, ITx tx) {
super();
this.type = type;
this.tx = tx;
this(type, tx, false);
}
TxEvent(EventKind type, ITx tx, boolean inGenerator) {
this.type = type;
this.tx = tx;
this.inGenerator = inGenerator;
}
@Override
@@ -34,7 +39,7 @@ public class TxEvent implements ITxEvent {
@Override
public IEvent duplicate() throws CloneNotSupportedException {
return new TxEvent(type, tx);
return new TxEvent(type, tx, inGenerator);
}
@Override
@@ -59,7 +64,7 @@ public class TxEvent implements ITxEvent {
@Override
public int getRowIndex() {
return ((Tx)tx).getConcurrencyIndex();
return inGenerator ? tx.getConcurrencyIdxInGen() : tx.getConcurrencyIndxInStream();
}
}
@@ -158,7 +158,12 @@ abstract class AbstractTxStream extends HierNode implements IWaveform {
*/
synchronized void calculateConcurrency() {
if (rowCount >= 0) return;
int count = TxRowAllocator.assign(getEvents(), (event, row) -> ((TxEvent) event).setConcurrencyIndex(row));
int count = TxRowAllocator.assign(getEvents(), (event, row) -> {
((TxEvent) event).setConcurrencyIndex(row);
Tx tx = (Tx) event.getTransaction();
if (this instanceof TxGenerator) tx.setConcurrencyIdxInGen(row);
else tx.setConcurrencyIndxInStream(row);
});
for (com.minres.scviewer.database.IHierNode child : getChildNodes())
((TxGenerator) child).calculateConcurrency();
rowCount = count;
@@ -144,7 +144,7 @@ public class TextDbLoader implements IWaveformDbLoader {
* @param txId the tx id
* @return the transaction
*/
public ITx getTransaction(long txId) {
public synchronized ITx getTransaction(long txId) {
if (txCache.containsKey(txId))
return txCache.get(txId);
if(transactions.containsKey(txId)) {
@@ -267,6 +267,7 @@ public class TextDbLoader implements IWaveformDbLoader {
txStreams.clear();
txGenerators.clear();
transactions = null;
txCache.clear();
attributeTypes.clear();
relationsIn.clear();
relationsOut.clear();
@@ -38,6 +38,9 @@ class Tx implements ITx {
private final long streamId;
private volatile int concurrencyIndxInStream = -1;
private volatile int concurrencyIdxInGen = -1;
/** The begin time. */
long beginTime = -1;
@@ -174,6 +177,26 @@ class Tx implements ITx {
return loader.txGenerators.get(generatorId);
}
@Override
public int getConcurrencyIndxInStream() {
if (concurrencyIndxInStream < 0) getStream().getRowCount();
return concurrencyIndxInStream;
}
@Override
public int getConcurrencyIdxInGen() {
if (concurrencyIdxInGen < 0) getGenerator().getRowCount();
return concurrencyIdxInGen;
}
void setConcurrencyIndxInStream(int index) {
concurrencyIndxInStream = index;
}
void setConcurrencyIdxInGen(int index) {
concurrencyIdxInGen = index;
}
/**
* Gets the begin time.
*
@@ -41,6 +41,22 @@ public interface ITx extends Comparable<ITx> {
*/
public IWaveform getGenerator();
/**
* Gets the zero-based row index within the transaction's stream.
* The stream layout is calculated on demand.
*
* @return the concurrency index in the stream
*/
public int getConcurrencyIndxInStream();
/**
* Gets the zero-based row index within the transaction's generator.
* The generator layout is calculated on demand, independently of the stream layout.
*
* @return the concurrency index in the generator
*/
public int getConcurrencyIdxInGen();
/**
* Gets the begin time.
*