From 6f2f5a388ca7cbc73385e6e08184a74f5e755741 Mon Sep 17 00:00:00 2001 From: Eyck Jentzsch Date: Sat, 18 Mar 2023 12:18:20 +0100 Subject: [PATCH] fixes deferred loading of Tx when being referenced --- .../scviewer/database/ftr/FtrDbLoader.java | 10 ++- .../scviewer/database/ftr/TxRelation.java | 87 ++++++++++++++++++- .../scviewer/database/ftr/TxStream.java | 24 ++--- 3 files changed, 105 insertions(+), 16 deletions(-) diff --git a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java index 0ee72bb..d7ead39 100644 --- a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java +++ b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/FtrDbLoader.java @@ -129,7 +129,7 @@ public class FtrDbLoader implements IWaveformDbLoader { * Gets the transaction. * * @param txId the tx id - * @return the transaction + * @return the transaction or null if the transaction is not available */ public synchronized ITx getTransaction(long txId) { if (txCache.containsKey(txId)) @@ -139,7 +139,7 @@ public class FtrDbLoader implements IWaveformDbLoader { txCache.put(txId, tx); return tx; } else { - throw new IllegalArgumentException(); + return null; } } @@ -528,12 +528,14 @@ public class FtrDbLoader implements IWaveformDbLoader { CborType next = cborDecoder.peekType(); while(next != null && !break_type.isEqualType(next)) { long sz = cborDecoder.readArrayLength(); - assert(sz==3); + assert(sz==5); long type_id = cborDecoder.readInt(); long from_id = cborDecoder.readInt(); long to_id = cborDecoder.readInt(); + long from_fiber = sz>3?cborDecoder.readInt():-1; + long to_fiber = sz>3?cborDecoder.readInt():-1; String rel_name = strDict.get((int)type_id); - FtrRelation ftrRel = new FtrRelation(relationTypes.getOrDefault(rel_name, RelationTypeFactory.create(rel_name)), from_id, to_id); + FtrRelation ftrRel = new FtrRelation(relationTypes.getOrDefault(rel_name, RelationTypeFactory.create(rel_name)), from_id, to_id, from_fiber, to_fiber); relationsOut.put(from_id, ftrRel); relationsIn.put(to_id, ftrRel); next = cborDecoder.peekType(); diff --git a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxRelation.java b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxRelation.java index 0f1e8ba..6a4c158 100644 --- a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxRelation.java +++ b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxRelation.java @@ -10,8 +10,14 @@ *******************************************************************************/ package com.minres.scviewer.database.ftr; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.minres.scviewer.database.IWaveform; import com.minres.scviewer.database.RelationType; import com.minres.scviewer.database.tx.ITx; +import com.minres.scviewer.database.tx.ITxAttribute; import com.minres.scviewer.database.tx.ITxRelation; /** @@ -53,7 +59,9 @@ class TxRelation implements ITxRelation { */ @Override public ITx getSource() { - return loader.getTransaction(scvRelation.source); + ITx tx = loader.getTransaction(scvRelation.source); + if(tx!=null) return tx; + return new TxFacade(scvRelation.source_fiber, scvRelation.source); } /** @@ -63,7 +71,82 @@ class TxRelation implements ITxRelation { */ @Override public ITx getTarget() { - return loader.getTransaction(scvRelation.target); + ITx tx = loader.getTransaction(scvRelation.target); + if(tx!=null) return tx; + return new TxFacade(scvRelation.target_fiber, scvRelation.target); } + private class TxFacade implements ITx { + + final long fiberId; + + final long txId; + + ITx tx = null; + + public TxFacade(long fiberId, long txId) { + this.fiberId = fiberId; + this.txId=txId; + } + + @Override + public int compareTo(ITx o) { + return tx==null?-1:tx.compareTo(o); + } + + @Override + public long getId() { + return txId; + } + + @Override + public IWaveform getStream() { + if(tx==null) { + TxStream fiber = loader.txStreams.get(fiberId); + fiber.loadStream(); + tx = loader.getTransaction(txId); + return loader.txStreams.get(fiberId); + } else + return tx.getStream(); + } + + @Override + public IWaveform getGenerator() { + if(tx==null) { + loader.txStreams.get(fiberId).loadStream(); + tx = loader.getTransaction(txId); + } + return tx.getGenerator(); + } + + @Override + public long getBeginTime() { + return tx==null?-1:tx.getBeginTime(); + } + + @Override + public long getEndTime() { + return tx==null?-1:tx.getBeginTime(); + } + + @Override + public List getAttributes() { + return tx==null?new ArrayList<>():tx.getAttributes(); + } + + @Override + public Collection getIncomingRelations() { + return tx==null?new ArrayList<>():tx.getIncomingRelations(); + } + + @Override + public Collection getOutgoingRelations() { + return tx==null?new ArrayList<>():tx.getOutgoingRelations(); + } + + @Override + public String toString() { + return tx==null?("tx#" + getId() + "[not available]"):tx.toString(); + } + } } diff --git a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxStream.java b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxStream.java index bb356c3..5c95e5b 100644 --- a/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxStream.java +++ b/plugins/com.minres.scviewer.database.ftr/src/com/minres/scviewer/database/ftr/TxStream.java @@ -71,6 +71,18 @@ class TxStream extends AbstractTxStream { return chunks; } + public void loadStream() { + try { + List chunks = getChunks(); + int blockid = 0; + for (byte[] bs : chunks) { + loader.parseTx(this, blockid, bs); + blockid++; + } + } catch (InputFormatException e) { + } catch (IOException e) { + } + } /** * Gets the events. * @@ -79,17 +91,9 @@ class TxStream extends AbstractTxStream { @Override public IEventList getEvents() { if(events.size()==0) { - try { - List chunks = getChunks(); - int blockid = 0; - for (byte[] bs : chunks) { - loader.parseTx(this, blockid, bs); - blockid++; - } - } catch (InputFormatException e) { - } catch (IOException e) { - } + loadStream(); } return events; } + }