Add developer option to display sync options (#924)

* It may be desirable to see what options are being passed in to performSync() without enabling the full verbose debug logging. This has been useful when tracking down 'sync_list' / sync issue & other performance related items without having to enable full verbose debugging to see what is going on
This commit is contained in:
abraunegg 2020-05-25 11:30:04 +10:00 committed by GitHub
parent 0096e7efce
commit f9c3ccc311
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 111 additions and 32 deletions

View file

@ -92,6 +92,9 @@ final class Config
// - It may be desirable to, when running in monitor mode, force monitor mode to 'quit' after X number of loops
// - This is especially beneficial when debugging or performing memory tests with Valgrind
longValues["monitor_max_loop"] = 0;
// display_sync_options = true | false
// - It may be desirable to see what options are being passed in to performSync() without enabling the full verbose debug logging
boolValues["display_sync_options"] = false;
// Determine the users home directory.
// Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d or systemd scripts

View file

@ -31,6 +31,7 @@ int main(string[] args)
string syncListHashFile;
string configBackupFile;
string syncDir;
string logOutputMessage;
bool configOptionsDifferent = false;
bool syncListConfigured = false;
bool syncListDifferent = false;
@ -41,6 +42,7 @@ int main(string[] args)
bool performSyncOK = false;
bool onedriveInitialised = false;
bool displayMemoryUsage = false;
bool displaySyncOptions = false;
// Define scopes
scope(exit) {
@ -129,6 +131,9 @@ int main(string[] args)
// set memory display
displayMemoryUsage = cfg.getValueBool("display_memory");
// set display sync options
displaySyncOptions = cfg.getValueBool("display_sync_options");
// update configuration from command line args
cfg.update_from_args(args);
@ -332,13 +337,9 @@ int main(string[] args)
}
}
// dry-run notification
// dry-run notification and database setup
if (cfg.getValueBool("dry_run")) {
log.log("DRY-RUN Configured. Output below shows what 'would' have occurred.");
}
// dry-run database setup
if (cfg.getValueBool("dry_run")) {
// If the dry run database exists, clean this up
if (exists(cfg.databaseFilePathDryRun)) {
// remove the existing file
@ -748,7 +749,7 @@ int main(string[] args)
// perform a --synchronize sync
// fullScanRequired = false, for final true-up
// but if we have sync_list configured, use syncListConfigured which = true
performSync(sync, cfg.getValueString("single_directory"), cfg.getValueBool("download_only"), cfg.getValueBool("local_first"), cfg.getValueBool("upload_only"), LOG_NORMAL, false, syncListConfigured);
performSync(sync, cfg.getValueString("single_directory"), cfg.getValueBool("download_only"), cfg.getValueBool("local_first"), cfg.getValueBool("upload_only"), LOG_NORMAL, false, syncListConfigured, displaySyncOptions);
}
}
@ -858,7 +859,12 @@ int main(string[] args)
auto currTime = MonoTime.currTime();
if (currTime - lastCheckTime > checkInterval) {
// monitor sync loop
log.vdebug("################################################## NEW LOOP ##################################################");
logOutputMessage = "################################################## NEW LOOP ##################################################";
if (displaySyncOptions) {
log.log(logOutputMessage);
} else {
log.vdebug(logOutputMessage);
}
// Increment monitorLoopFullCount
monitorLoopFullCount++;
// Display memory details at start of loop
@ -888,12 +894,19 @@ int main(string[] args)
}
}
// Monitor Loop Counter
log.vdebug("fullScanCounter = ", fullScanCounter);
// sync option handling per sync loop
log.vdebug("syncListConfigured = ", syncListConfigured);
log.vdebug("fullScanRequired = ", fullScanRequired);
log.vdebug("syncListConfiguredFullScanOverride = ", syncListConfiguredFullScanOverride);
if (displaySyncOptions) {
// sync option handling per sync loop
log.log("fullScanCounter = ", fullScanCounter);
log.log("syncListConfigured = ", syncListConfigured);
log.log("fullScanRequired = ", fullScanRequired);
log.log("syncListConfiguredFullScanOverride = ", syncListConfiguredFullScanOverride);
} else {
// sync option handling per sync loop via debug
log.vdebug("fullScanCounter = ", fullScanCounter);
log.vdebug("syncListConfigured = ", syncListConfigured);
log.vdebug("fullScanRequired = ", fullScanRequired);
log.vdebug("syncListConfiguredFullScanOverride = ", syncListConfiguredFullScanOverride);
}
try {
if (!initSyncEngine(sync)) {
@ -903,7 +916,7 @@ int main(string[] args)
try {
// perform a --monitor sync
log.vlog("Starting a sync with OneDrive");
performSync(sync, cfg.getValueString("single_directory"), cfg.getValueBool("download_only"), cfg.getValueBool("local_first"), cfg.getValueBool("upload_only"), (logMonitorCounter == logInterval ? MONITOR_LOG_QUIET : MONITOR_LOG_SILENT), fullScanRequired, syncListConfiguredFullScanOverride);
performSync(sync, cfg.getValueString("single_directory"), cfg.getValueBool("download_only"), cfg.getValueBool("local_first"), cfg.getValueBool("upload_only"), (logMonitorCounter == logInterval ? MONITOR_LOG_QUIET : MONITOR_LOG_SILENT), fullScanRequired, syncListConfiguredFullScanOverride, displaySyncOptions);
if (!cfg.getValueBool("download_only")) {
// discard all events that may have been generated by the sync
try {
@ -940,7 +953,13 @@ int main(string[] args)
if (displayMemoryUsage) {
log.displayMemoryUsagePostGC();
}
// monitor loop complete
logOutputMessage = "################################################ LOOP COMPLETE ###############################################";
if (displaySyncOptions) {
log.log(logOutputMessage);
} else {
log.vdebug(logOutputMessage);
}
// Developer break via config option
if (cfg.getValueLong("monitor_max_loop") > 0) {
// developer set option to limit --monitor loops
@ -988,11 +1007,12 @@ bool initSyncEngine(SyncEngine sync)
}
// try to synchronize the folder three times
void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, bool localFirst, bool uploadOnly, long logLevel, bool fullScanRequired, bool syncListConfiguredFullScanOverride)
void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, bool localFirst, bool uploadOnly, long logLevel, bool fullScanRequired, bool syncListConfiguredFullScanOverride, bool displaySyncOptions)
{
int count;
string remotePath = "/";
string localPath = ".";
string logOutputMessage;
// performSync API scan triggers
log.vdebug("performSync API scan triggers");
@ -1017,7 +1037,13 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo
do {
try {
log.vdebug("################################################## NEW SYNC ##################################################");
// starting a sync
logOutputMessage = "################################################## NEW SYNC ##################################################";
if (displaySyncOptions) {
log.log(logOutputMessage);
} else {
log.vdebug(logOutputMessage);
}
if (singleDirectory != ""){
// we were requested to sync a single directory
log.vlog("Syncing changes from this selected path: ", singleDirectory);
@ -1053,6 +1079,7 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo
sync.scanForDifferences(localPath);
} else {
// No upload only
string syncCallLogOutput;
if (localFirst) {
// sync local files first before downloading from OneDrive
if (logLevel < MONITOR_LOG_QUIET) log.log("Syncing changes from local path first before downloading changes from OneDrive ...");
@ -1070,15 +1097,31 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo
if (logLevel < MONITOR_LOG_SILENT) log.log("Syncing changes from OneDrive ...");
// For the initial sync, always use the delta link so that we capture all the right delta changes including adds, moves & deletes
log.vdebug("Calling sync.applyDifferences(false);");
logOutputMessage = "Initial Scan: Call OneDrive Delta API for delta changes as compared to last successful sync.";
syncCallLogOutput = "Calling sync.applyDifferences(false);";
if (displaySyncOptions) {
log.log(logOutputMessage);
log.log(syncCallLogOutput);
} else {
log.vdebug(logOutputMessage);
log.vdebug(syncCallLogOutput);
}
sync.applyDifferences(false);
// is this a download only request?
if (!downloadOnly) {
// process local changes walking the entire path checking for changes
// in monitor mode all local changes are captured via inotify
// thus scanning every 'monitor_interval' (default 45 seconds) for local changes is excessive and not required
log.vdebug("Calling sync.scanForDifferences(localPath);");
// thus scanning every 'monitor_interval' (default 300 seconds) for local changes is excessive and not required
logOutputMessage = "Process local filesystem (sync_dir) for file changes as compared to database entries";
syncCallLogOutput = "Calling sync.scanForDifferences(localPath);";
if (displaySyncOptions) {
log.log(logOutputMessage);
log.log(syncCallLogOutput);
} else {
log.vdebug(logOutputMessage);
log.vdebug(syncCallLogOutput);
}
sync.scanForDifferences(localPath);
// At this point, all OneDrive changes / local changes should be uploaded and in sync
@ -1096,39 +1139,72 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo
// Do not perform a full walk of the OneDrive objects
if ((!fullScanRequired) && (!syncListConfiguredFullScanOverride)){
log.vdebug("Final True-Up: Do not perform a full walk of the OneDrive objects - not required");
log.vdebug("Calling sync.applyDifferences(false);");
logOutputMessage = "Final True-Up: Do not perform a full walk of the OneDrive objects - not required";
syncCallLogOutput = "Calling sync.applyDifferences(false);";
if (displaySyncOptions) {
log.log(logOutputMessage);
log.log(syncCallLogOutput);
} else {
log.vdebug(logOutputMessage);
log.vdebug(syncCallLogOutput);
}
sync.applyDifferences(false);
return;
}
// Perform a full walk of OneDrive objects because sync_list is in use / or trigger was set in --monitor loop
if ((!fullScanRequired) && (syncListConfiguredFullScanOverride)){
log.vdebug("Final True-Up: Perform a full walk of OneDrive objects because sync_list is in use / or trigger was set in --monitor loop");
log.vdebug("Calling sync.applyDifferences(true);");
logOutputMessage = "Final True-Up: Perform a full walk of OneDrive objects because sync_list is in use / or trigger was set in --monitor loop";
syncCallLogOutput = "Calling sync.applyDifferences(true);";
if (displaySyncOptions) {
log.log(logOutputMessage);
log.log(syncCallLogOutput);
} else {
log.vdebug(logOutputMessage);
log.vdebug(syncCallLogOutput);
}
sync.applyDifferences(true);
return;
}
// Perform a full walk of OneDrive objects because a full scan was required
if ((fullScanRequired) && (!syncListConfiguredFullScanOverride)){
log.vdebug("Final True-Up: Perform a full walk of OneDrive objects because a full scan was required");
log.vdebug("Calling sync.applyDifferences(true);");
logOutputMessage = "Final True-Up: Perform a full walk of OneDrive objects because a full scan was required";
syncCallLogOutput = "Calling sync.applyDifferences(true);";
if (displaySyncOptions) {
log.log(logOutputMessage);
log.log(syncCallLogOutput);
} else {
log.vdebug(logOutputMessage);
log.vdebug(syncCallLogOutput);
}
sync.applyDifferences(true);
return;
}
// Perform a full walk of OneDrive objects because a full scan was required and sync_list is in use and trigger was set in --monitor loop
if ((fullScanRequired) && (syncListConfiguredFullScanOverride)){
log.vdebug("Final True-Up: Perform a full walk of OneDrive objects because a full scan was required and sync_list is in use and trigger was set in --monitor loop");
log.vdebug("Calling sync.applyDifferences(true);");
logOutputMessage = "Final True-Up: Perform a full walk of OneDrive objects because a full scan was required and sync_list is in use and trigger was set in --monitor loop";
syncCallLogOutput = "Calling sync.applyDifferences(true);";
if (displaySyncOptions) {
log.log(logOutputMessage);
log.log(syncCallLogOutput);
} else {
log.vdebug(logOutputMessage);
log.vdebug(syncCallLogOutput);
}
sync.applyDifferences(true);
return;
}
}
}
}
}
// sync is complete
logOutputMessage = "################################################ SYNC COMPLETE ###############################################";
if (displaySyncOptions) {
log.log(logOutputMessage);
} else {
log.vdebug(logOutputMessage);
}
count = -1;
} catch (Exception e) {
if (++count == 3) {