فهرست منبع

Removed job grace period and fingerprint-changing wait.

This block of code was really not serving any purpose.  If the fingerprint of a file changed, AP would pick up the file change and trigger another job anyway.  rccontroller would attempt to cancel the already-running job but this would fail since there was no listener set up at this point.
By removing this block, AP is much more responsive to rapidly changing files with no apparent downsides.

Note that testing also showed that a file which was opened for write with no shared access (exclusive write) would fail at the CreateJobs stage since the file can't be opened to even create the job, further making this code useless since it wasn't even possible to get to this code while the file was still locked.

Signed-off-by: amzn-mike <[email protected]>
amzn-mike 3 سال پیش
والد
کامیت
a927420db9

+ 1 - 1
Code/Tools/AssetProcessor/AssetBuilderSDK/AssetBuilderSDK/AssetBuilderSDK.h

@@ -729,7 +729,7 @@ namespace AssetBuilderSDK
         JobDescriptor m_jobDescription; ///! job descriptor for this job.  Note that this still contains the job parameters from when you emitted it during CreateJobs
         JobDescriptor m_jobDescription; ///! job descriptor for this job.  Note that this still contains the job parameters from when you emitted it during CreateJobs
         PlatformInfo m_platformInfo; ///! the information about the platform that this job was emitted for.
         PlatformInfo m_platformInfo; ///! the information about the platform that this job was emitted for.
         AZStd::string m_tempDirPath; // temp directory that the builder should use to create job outputs for this job request
         AZStd::string m_tempDirPath; // temp directory that the builder should use to create job outputs for this job request
-        AZ::u64 m_jobId; ///! job id for this job, this is also the address for the JobCancelListener
+        AZ::u64 m_jobId{}; ///! job id for this job, this is also the address for the JobCancelListener
         AZ::Uuid m_sourceFileUUID; ///! the UUID of the source file.  Will be used as the uuid of the AssetID of the product when combined with the subID.
         AZ::Uuid m_sourceFileUUID; ///! the UUID of the source file.  Will be used as the uuid of the AssetID of the product when combined with the subID.
         AZStd::vector<SourceFileDependency> m_sourceFileDependencyList;
         AZStd::vector<SourceFileDependency> m_sourceFileDependencyList;
 
 

+ 7 - 33
Code/Tools/AssetProcessor/native/resourcecompiler/rcjob.cpp

@@ -34,8 +34,6 @@ namespace
 
 
     const unsigned int g_sleepDurationForLockingAndFingerprintChecking = 100;
     const unsigned int g_sleepDurationForLockingAndFingerprintChecking = 100;
 
 
-    const unsigned int g_graceTimeBeforeLockingAndFingerprintChecking = 300;
-
     const unsigned int g_timeoutInSecsForRetryingCopy = 30;
     const unsigned int g_timeoutInSecsForRetryingCopy = 30;
 
 
     const char* const s_tempString = "%TEMP%";
     const char* const s_tempString = "%TEMP%";
@@ -279,12 +277,12 @@ namespace AssetProcessor
     {
     {
         // the following trace can be uncommented if there is a need to deeply inspect job running.
         // the following trace can be uncommented if there is a need to deeply inspect job running.
         //AZ_TracePrintf(AssetProcessor::DebugChannel, "JobTrace Start(%i %s,%s,%s)\n", this, GetInputFileAbsolutePath().toUtf8().data(), GetPlatform().toUtf8().data(), GetJobKey().toUtf8().data());
         //AZ_TracePrintf(AssetProcessor::DebugChannel, "JobTrace Start(%i %s,%s,%s)\n", this, GetInputFileAbsolutePath().toUtf8().data(), GetPlatform().toUtf8().data(), GetJobKey().toUtf8().data());
-
+        
         AssetUtilities::QuitListener listener;
         AssetUtilities::QuitListener listener;
         listener.BusConnect();
         listener.BusConnect();
         RCParams rc(this);
         RCParams rc(this);
         BuilderParams builderParams(this);
         BuilderParams builderParams(this);
-
+        
         //Create the process job request
         //Create the process job request
         AssetBuilderSDK::ProcessJobRequest processJobRequest;
         AssetBuilderSDK::ProcessJobRequest processJobRequest;
         PopulateProcessJobRequest(processJobRequest);
         PopulateProcessJobRequest(processJobRequest);
@@ -344,13 +342,14 @@ namespace AssetProcessor
 
 
         // Signal start and end of the job
         // Signal start and end of the job
         ScopedJobSignaler signaler;
         ScopedJobSignaler signaler;
-
+        
         // listen for the user quitting (CTRL-C or otherwise)
         // listen for the user quitting (CTRL-C or otherwise)
         AssetUtilities::QuitListener listener;
         AssetUtilities::QuitListener listener;
         listener.BusConnect();
         listener.BusConnect();
         QElapsedTimer ticker;
         QElapsedTimer ticker;
         ticker.start();
         ticker.start();
         AssetBuilderSDK::ProcessJobResponse result;
         AssetBuilderSDK::ProcessJobResponse result;
+        AssetBuilderSDK::JobCancelListener cancelListener(builderParams.m_processJobRequest.m_jobId);
 
 
         if (builderParams.m_rcJob->m_jobDetails.m_autoFail)
         if (builderParams.m_rcJob->m_jobDetails.m_autoFail)
         {
         {
@@ -367,15 +366,7 @@ namespace AssetProcessor
             return;
             return;
         }
         }
 
 
-        // We are adding a grace time before we check exclusive lock and validate the fingerprint of the file.
-        // This grace time should prevent multiple jobs from getting added to the queue if the source file is still updating.
-        qint64 milliSecsDiff = QDateTime::currentMSecsSinceEpoch() - builderParams.m_rcJob->GetJobEntry().m_computedFingerprintTimeStamp;
-        if (milliSecsDiff < g_graceTimeBeforeLockingAndFingerprintChecking)
-        {
-            QThread::msleep(aznumeric_cast<unsigned long>(g_graceTimeBeforeLockingAndFingerprintChecking - milliSecsDiff));
-        }
-        // Lock and unlock the source file to ensure it is not still open by another process.
-        // This prevents premature processing of some source files that are opened for writing, but are zero bytes for longer than the modification threshhold
+        // If requested, make sure we can open the file with exclusive permissions
         QString inputFile = builderParams.m_rcJob->GetJobEntry().GetAbsoluteSourcePath();
         QString inputFile = builderParams.m_rcJob->GetJobEntry().GetAbsoluteSourcePath();
         if (builderParams.m_rcJob->GetJobEntry().m_checkExclusiveLock && QFile::exists(inputFile))
         if (builderParams.m_rcJob->GetJobEntry().m_checkExclusiveLock && QFile::exists(inputFile))
         {
         {
@@ -383,7 +374,7 @@ namespace AssetProcessor
             while (!AssetUtilities::CheckCanLock(inputFile))
             while (!AssetUtilities::CheckCanLock(inputFile))
             {
             {
                 QThread::msleep(g_sleepDurationForLockingAndFingerprintChecking);
                 QThread::msleep(g_sleepDurationForLockingAndFingerprintChecking);
-                if (listener.WasQuitRequested() || (ticker.elapsed() > g_jobMaximumWaitTime))
+                if (listener.WasQuitRequested() || cancelListener.IsCancelled() || (ticker.elapsed() > g_jobMaximumWaitTime))
                 {
                 {
                     result.m_resultCode = AssetBuilderSDK::ProcessJobResult_Cancelled;
                     result.m_resultCode = AssetBuilderSDK::ProcessJobResult_Cancelled;
                     Q_EMIT builderParams.m_rcJob->JobFinished(result);
                     Q_EMIT builderParams.m_rcJob->JobFinished(result);
@@ -391,24 +382,7 @@ namespace AssetProcessor
                 }
                 }
             }
             }
         }
         }
-
-        // We will only continue once the fingerprint of the file stops changing
-        unsigned int fingerprint = AssetUtilities::GenerateFingerprint(builderParams.m_rcJob->m_jobDetails);
-        while (fingerprint != builderParams.m_rcJob->GetOriginalFingerprint())
-        {
-            builderParams.m_rcJob->SetOriginalFingerprint(fingerprint);
-            QThread::msleep(g_sleepDurationForLockingAndFingerprintChecking);
-
-            if (listener.WasQuitRequested() || (ticker.elapsed() > g_jobMaximumWaitTime))
-            {
-                result.m_resultCode = AssetBuilderSDK::ProcessJobResult_Cancelled;
-                Q_EMIT builderParams.m_rcJob->JobFinished(result);
-                return;
-            }
-
-            fingerprint = AssetUtilities::GenerateFingerprint(builderParams.m_rcJob->m_jobDetails);
-        }
-
+            
         Q_EMIT builderParams.m_rcJob->BeginWork();
         Q_EMIT builderParams.m_rcJob->BeginWork();
         // We will actually start working on the job after this point and even if RcController gets the same job again, we will put it in the queue for processing
         // We will actually start working on the job after this point and even if RcController gets the same job again, we will put it in the queue for processing
         builderParams.m_rcJob->DoWork(result, builderParams, listener);
         builderParams.m_rcJob->DoWork(result, builderParams, listener);