forked from Qortal/qortal
When a newer PUT exists for a resource, delete records of peers holding earlier transactions
This should help keep the peer lookup table size down, as there is no need to locate files for transactions that existed before the most recent PUT transaction.
This commit is contained in:
parent
53f9d6869d
commit
3cce097b9d
@ -146,6 +146,9 @@ public class ArbitraryDataCleanupManager extends Thread {
|
||||
arbitraryTransactionData.getName(), Base58.encode(signature)));
|
||||
|
||||
ArbitraryTransactionUtils.deleteCompleteFileAndChunks(arbitraryTransactionData);
|
||||
|
||||
// We should also remove peers for this transaction from the lookup table to save space
|
||||
this.removePeersHostingTransactionData(repository, arbitraryTransactionData);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -187,6 +190,16 @@ public class ArbitraryDataCleanupManager extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
private void removePeersHostingTransactionData(Repository repository, ArbitraryTransactionData transactionData) {
|
||||
byte[] signature = transactionData.getSignature();
|
||||
try {
|
||||
repository.getArbitraryRepository().deleteArbitraryPeersWithSignature(signature);
|
||||
repository.saveChanges();
|
||||
} catch (DataException e) {
|
||||
LOGGER.debug("Unable to delete peers from lookup table for signature: {}", Base58.encode(signature));
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanupTempDirectory(String folder, long now, long minAge) {
|
||||
String baseDir = Settings.getInstance().getTempDataPath();
|
||||
Path tempDir = Paths.get(baseDir, folder);
|
||||
|
@ -33,4 +33,6 @@ public interface ArbitraryRepository {
|
||||
|
||||
public void delete(ArbitraryPeerData arbitraryPeerData) throws DataException;
|
||||
|
||||
public void deleteArbitraryPeersWithSignature(byte[] signature) throws DataException;
|
||||
|
||||
}
|
||||
|
@ -444,4 +444,16 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
||||
throw new DataException("Unable to delete arbitrary peer data from repository", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteArbitraryPeersWithSignature(byte[] signature) throws DataException {
|
||||
byte[] hash = Crypto.digest(signature);
|
||||
try {
|
||||
// Remove all records of peers hosting supplied signature
|
||||
this.repository.delete("ArbitraryPeers", "hash = ?", hash);
|
||||
|
||||
} catch (SQLException e) {
|
||||
throw new DataException("Unable to delete arbitrary peer data from repository", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user