haorenhui
2023-10-30 6d6cc10d9e8e242661da7fd655dec155a09d676c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Quintiq file version 2.0
#parent: #root
StaticMethod DoFinalizeDatasetCopyChangeToStandAlone (LibOpt_Task task)
{
  Description:
  [*
    Changes the dataset state of memory only datasets (that were created for the current task) to standalone.
    Then unloads the dataset to reduce memory usage.
    This method can be called right before an error. Therefore, don't start any reactive transactions in this method.
  *]
  TextBody:
  [*
    // evr3 Jun-30-2020 (created)
    traverse( task,
              SnapshotComponent.Children.astype( LibOpt_SnapshotReplannableCopyDataset ), 
              snapshot, 
              snapshot.IsMemoryOnly()
              and not snapshot.IsDatasetDeletedByOptimizer() 
              and not snapshot.HasFailedToCreateDataset()
              )
    { 
      editor := MDSEditor::Editor();
      infos := editor.LoadedObjectInfos();
      datasetinfo := infos.Find( snapshot.DatasetName() );
      if( not isnull( datasetinfo ) )
      {
        mdsid := datasetinfo.MDSID();     
        // Changing the storage state can fail if the name of the dataset causes Windows' maximum path length to be exceeded. 
        // It is not possible to catch this failure by using reactive quill, because DatasetCopyChangeToStandAlone can be called right before an error is thrown.
        // This error would mean that any new transactions are reverted.
        editor.ChangeState( mdsid, DatasetState::StandAloneStorage().AsString(), false );
        editor.UnloadMDS( mdsid );
        
        snapshot.IsMemoryOnly( false ); 
      }
    }
  *]
  InterfaceProperties { Accessibility: 'Module' }
}