Update PR

* Update PR
This commit is contained in:
abraunegg 2023-10-06 09:19:04 +11:00
parent 5127464f2c
commit 1503f969df
3 changed files with 32 additions and 30 deletions

View file

@ -671,6 +671,7 @@ final class ItemDatabase {
// Perform a vacuum on the database, commit WAL / SHM to file // Perform a vacuum on the database, commit WAL / SHM to file
void performVacuum() { void performVacuum() {
log.vdebug("Attempting to perform a database vacuum to merge any temporary data");
try { try {
auto stmt = db.prepare("VACUUM;"); auto stmt = db.prepare("VACUUM;");
stmt.exec(); stmt.exec();

View file

@ -109,6 +109,14 @@ int main(string[] cliArgs) {
if (oneDriveApiInstance !is null) object.destroy(oneDriveApiInstance); if (oneDriveApiInstance !is null) object.destroy(oneDriveApiInstance);
if (selectiveSync !is null) object.destroy(selectiveSync); if (selectiveSync !is null) object.destroy(selectiveSync);
if (syncEngineInstance !is null) object.destroy(syncEngineInstance); if (syncEngineInstance !is null) object.destroy(syncEngineInstance);
// Set these to be null due to failure scope - prevent 'ERROR: Unable to perform a database vacuum: out of memory' when the exit scope is then called
log.vdebug("Setting Class Objects to null due to failure scope");
itemDB = null;
appConfig = null;
oneDriveApiInstance = null;
selectiveSync = null;
syncEngineInstance = null;
} }
// Read in application options as passed in // Read in application options as passed in

View file

@ -661,20 +661,16 @@ class SyncEngine {
for (;;) { for (;;) {
responseBundleCount++; responseBundleCount++;
// Get the /delta changes via the OneDrive API // Get the /delta changes via the OneDrive API
log.vdebug("");
log.vdebug("------------------------------------------------------------------");
log.vdebug("driveIdToQuery: ", driveIdToQuery);
log.vdebug("itemIdToQuery: ", itemIdToQuery);
log.vdebug("deltaLink: ", deltaLink);
log.vdebug("------------------------------------------------------------------");
// getDeltaChangesByItemId has the re-try logic for transient errors // getDeltaChangesByItemId has the re-try logic for transient errors
deltaChanges = getDeltaChangesByItemId(driveIdToQuery, itemIdToQuery, deltaLink); deltaChanges = getDeltaChangesByItemId(driveIdToQuery, itemIdToQuery, deltaLink);
// If deltaChanges is an invalid JSON object, must exit // If the initial deltaChanges response is an invalid JSON object, keep trying ..
if (deltaChanges.type() != JSONType.object){ if (deltaChanges.type() != JSONType.object) {
// Handle the invalid JSON response while (deltaChanges.type() != JSONType.object) {
invalidJSONResponseFromOneDriveAPI(); // Handle the invalid JSON response adn retry
log.error("ERROR: Query of the OneDrive API via deltaChanges = getDeltaChangesByItemId() returned an invalid JSON response");
deltaChanges = getDeltaChangesByItemId(driveIdToQuery, itemIdToQuery, deltaLink);
}
} }
ulong nrChanges = count(deltaChanges["value"].array); ulong nrChanges = count(deltaChanges["value"].array);
@ -2147,18 +2143,19 @@ class SyncEngine {
OneDriveApi getDeltaQueryOneDriveApiInstance; OneDriveApi getDeltaQueryOneDriveApiInstance;
getDeltaQueryOneDriveApiInstance = new OneDriveApi(appConfig); getDeltaQueryOneDriveApiInstance = new OneDriveApi(appConfig);
getDeltaQueryOneDriveApiInstance.initialise(); getDeltaQueryOneDriveApiInstance.initialise();
log.vdebug("------------------------------------------------------------------");
log.vdebug("selectedDriveId: ", selectedDriveId);
log.vdebug("selectedItemId: ", selectedItemId);
log.vdebug("providedDeltaLink: ", providedDeltaLink);
log.vdebug("------------------------------------------------------------------");
try { try {
deltaChangesBundle = getDeltaQueryOneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, providedDeltaLink); deltaChangesBundle = getDeltaQueryOneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, providedDeltaLink);
} catch (OneDriveException exception) { } catch (OneDriveException exception) {
// caught an exception // caught an exception
log.log("------------------------------------------------------------------"); log.vdebug("getDeltaQueryOneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, providedDeltaLink) generated a OneDriveException");
log.log("getDeltaQueryOneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, providedDeltaLink) generated a OneDriveException");
log.log("");
log.log("selectedDriveId: ", selectedDriveId);
log.log("selectedItemId: ", selectedItemId);
log.log("providedDeltaLink: ", providedDeltaLink);
log.log("------------------------------------------------------------------");
auto errorArray = splitLines(exception.msg); auto errorArray = splitLines(exception.msg);
string thisFunctionName = getFunctionName!({}); string thisFunctionName = getFunctionName!({});
// HTTP request returned status code 408,429,503,504 // HTTP request returned status code 408,429,503,504
@ -2181,9 +2178,9 @@ class SyncEngine {
log.vdebug("Thread sleeping for 30 seconds as the server did not receive a timely response from the upstream server it needed to access in attempting to complete the request"); log.vdebug("Thread sleeping for 30 seconds as the server did not receive a timely response from the upstream server it needed to access in attempting to complete the request");
Thread.sleep(dur!"seconds"(30)); Thread.sleep(dur!"seconds"(30));
} }
// re-try original request - retried for 429, 503, 504 - but loop back calling this function // dont retry request, loop back to calling function
log.vdebug("Retrying Query: "); log.vdebug("Looping back after failure");
deltaChangesBundle = getDeltaQueryOneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, providedDeltaLink); deltaChangesBundle = null;
} else { } else {
// Default operation if not 408,429,503,504 errors // Default operation if not 408,429,503,504 errors
if (exception.httpStatusCode == 410) { if (exception.httpStatusCode == 410) {
@ -2192,21 +2189,18 @@ class SyncEngine {
log.log("WARNING: Retrying OneDrive API call without using the locally stored deltaLink value"); log.log("WARNING: Retrying OneDrive API call without using the locally stored deltaLink value");
// Configure an empty deltaLink // Configure an empty deltaLink
log.vdebug("Delta link expired for 'getDeltaQueryOneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, providedDeltaLink)', setting 'deltaLink = null'"); log.vdebug("Delta link expired for 'getDeltaQueryOneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, providedDeltaLink)', setting 'deltaLink = null'");
string emptyDeltaLink; string emptyDeltaLink = "";
// retry with empty deltaLink
deltaChangesBundle = getDeltaQueryOneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, emptyDeltaLink); deltaChangesBundle = getDeltaQueryOneDriveApiInstance.viewChangesByItemId(selectedDriveId, selectedItemId, emptyDeltaLink);
} else { } else {
// display what the error is // display what the error is
log.log("CODING TO DO: Hitting this failure error output");
displayOneDriveErrorMessage(exception.msg, thisFunctionName); displayOneDriveErrorMessage(exception.msg, thisFunctionName);
deltaChangesBundle = null;
} }
} }
} }
// Check the response JSON
if (deltaChangesBundle.type() != JSONType.object){
// Handle the invalid JSON response
invalidJSONResponseFromOneDriveAPI();
}
// Shutdown the API // Shutdown the API
getDeltaQueryOneDriveApiInstance.shutdown(); getDeltaQueryOneDriveApiInstance.shutdown();
// Free object and memory // Free object and memory
@ -2250,7 +2244,6 @@ class SyncEngine {
// If the JSON response is not correct JSON object, exit // If the JSON response is not correct JSON object, exit
void invalidJSONResponseFromOneDriveAPI() { void invalidJSONResponseFromOneDriveAPI() {
log.error("ERROR: Query of the OneDrive API returned an invalid JSON response"); log.error("ERROR: Query of the OneDrive API returned an invalid JSON response");
// Must exit // Must exit
exit(-1); exit(-1);