Don't update statuses when processing arbitrary transactions, to improve success rate and speed it up.

This commit is contained in:
CalDescent 2023-07-08 14:16:50 +01:00
parent 537779b152
commit d8237abde5
2 changed files with 38 additions and 2 deletions

View File

@ -86,6 +86,10 @@ public class ArbitraryDataCacheManager extends Thread {
arbitraryTransaction.updateArbitraryMetadataCache(repository);
repository.saveChanges();
// Update status as separate commit, as this is more prone to failure
arbitraryTransaction.updateArbitraryResourceStatus(repository);
repository.saveChanges();
LOGGER.debug(() -> String.format("Finished processing transaction %.8s in arbitrary resource queue...", Base58.encode(transactionData.getSignature())));
} catch (DataException e) {
@ -168,11 +172,15 @@ public class ArbitraryDataCacheManager extends Thread {
ArbitraryTransaction arbitraryTransaction = new ArbitraryTransaction(repository, transactionData);
arbitraryTransaction.updateArbitraryResourceCache(repository);
arbitraryTransaction.updateArbitraryMetadataCache(repository);
repository.saveChanges();
// Update status as separate commit, as this is more prone to failure
arbitraryTransaction.updateArbitraryResourceStatus(repository);
repository.saveChanges();
}
offset += batchSize;
}
repository.saveChanges();
LOGGER.info("Completed build of arbitrary resources cache.");
return true;
}

View File

@ -289,7 +289,9 @@ public class ArbitraryTransaction extends Transaction {
}
}
// Add/update arbitrary resource caches
// Add/update arbitrary resource caches, but don't update the status as this involves time-consuming
// disk reads, and is more prone to failure. The status will be updated on metadata retrieval, or when
// accessing the resource.
this.updateArbitraryResourceCache(repository);
this.updateArbitraryMetadataCache(repository);
@ -408,6 +410,32 @@ public class ArbitraryTransaction extends Transaction {
// Save
repository.getArbitraryRepository().save(arbitraryResourceData);
}
public void updateArbitraryResourceStatus(Repository repository) throws DataException {
// Don't cache resources without a name (such as auto updates)
if (arbitraryTransactionData.getName() == null) {
return;
}
Service service = arbitraryTransactionData.getService();
String name = arbitraryTransactionData.getName();
String identifier = arbitraryTransactionData.getIdentifier();
if (service == null) {
// Unsupported service - ignore this resource
return;
}
// In the cache we store null identifiers as "default", as it is part of the primary key
if (identifier == null) {
identifier = "default";
}
ArbitraryResourceData arbitraryResourceData = new ArbitraryResourceData();
arbitraryResourceData.service = service;
arbitraryResourceData.name = name;
arbitraryResourceData.identifier = identifier;
// Update status
ArbitraryDataResource resource = new ArbitraryDataResource(name, ArbitraryDataFile.ResourceIdType.NAME, service, identifier);