none
Nested Parallel Workflow With Pause RRS feed

  • Question

  • Trying to run SharePoint Upgrade-SPContentDatabase command on two database concurrently per SQL server. We have four SQL servers hosting few terabytes of SharePoint data. Using the powershell workflows I can accomplish it but there are some issues as below.

    1) Upgrade command causes SharePoint to generate log file, since I am executing in parallel, SP generates error message that log file <<filename>> already exist.

    2) I have to upgrade Powershell version on server in order to utilize Workflows.

    Wondering if somebody can help me either with introducing pause in parallel process before each Upgrade command or use a different approach. The second issue is minor.

    The following is the code I am using

    workflow UpgradeContentDB
    {
        Param($csvPath,$throttle,$sleepSec)
    
        $dbColl = Import-Csv $csvPath |
                    Select-Object Server,Name,@{ n = "Size"; e = { [int]($_.Size) } }  |
                    Sort-Object Size -Descending |
                    Group-Object -Property "Server"
    
        foreach -Parallel ($svr in $dbColl)
        {
            foreach -Parallel -throttlelimit $throttle ($db in $svr.Group)
            {
                Sequence
                {  
                    InlineScript {
                        Add-PSSnapin Microsoft.Sharepoint.Powershell;
                        Get-Date -Format G
                        " Server: " + $using:db.Server + " Database: " + $using:db.Name +  " Size: " + $using:db.Size;
                        Upgrade-SPContentDatabase $using:db.Name -Confirm:$false;
                        Start-Sleep -Seconds $using:sleepSec;
                    }
                }
            }
        }
     }

    • Edited by adhanju Tuesday, July 31, 2018 6:22 PM
    • Moved by Bill_Stewart Tuesday, December 11, 2018 10:19 PM This is not "debug/fix/rewrite my script for me" forum
    Tuesday, July 31, 2018 5:50 PM

All replies

  • Post is SharePoint forum for assistance with doing this.

    Please only post code using the code posting tool provided on the toolbar.  What you have posted is badly broken and cannot be read or copied.


    \_(ツ)_/


    • Edited by jrv Tuesday, July 31, 2018 5:56 PM
    Tuesday, July 31, 2018 5:55 PM
  • Thanks for the reply. Fixed the post.
    Tuesday, July 31, 2018 6:23 PM
  • Thank you.  That is much better.

    I suggest parallel by server and sequential by DB.  Each server has its own rebuild log so servers will not interfere,   You can only rebuild on DB at a time.


    \_(ツ)_/


    • Edited by jrv Tuesday, July 31, 2018 6:50 PM
    Tuesday, July 31, 2018 6:49 PM
  • Keep it simple until it works.

    workflow UpgradeContentDB{
        Param($csvPath)
    
        $dbColl = Import-Csv $csvPath |
                    Group-Object -Property Server
        
       foreach -Parallel ($svr in $dbColl){
            foreach($db in $svr.Group){
                InlineScript {
                    Add-PSSnapin Microsoft.Sharepoint.Powershell
                    Get-Date -Format G
                    " Server: " + $using:db.Server + " Database: " + $using:db.Name +  " Size: " + $using:db.Size
                    Upgrade-SPContentDatabase $using:db.Name -Confirm:$false
                }
            }
        }
    }


    \_(ツ)_/

    Tuesday, July 31, 2018 6:57 PM
  • I agree, this allows me to upgrade one database per server which is better than upgrading one database at a time but it will still cause error message when SharePoint tries to create log file for parallel upgrade requests. When I try Start-Sleep command, powershell workflow execute it in parallel then go to next line. 

    The intended behaviour is 

    Foreach Server -Parallel  
     ForEach database -Parallel -throttle 2
      1) Upgrade-SPContentDatabase
      2) Sleep 5 minutes
     End
    End

    Cheers!


    Tuesday, July 31, 2018 7:39 PM
  • Post in SharePoint forum to resolve your issues.

    Note that the CmdLet doesn't wait.  You need to check the status of the process before starting a second upgrade.


    \_(ツ)_/

    Tuesday, July 31, 2018 7:50 PM
  • Implemented workaround by waiting random seconds within loop.

    Add-PSSnapin "Microsoft.SharePoint.Powershell" -ErrorAction Stop
    
    $cdb = Get-SPContentDatabase | 
        Select-Object Server,Name, @{l="Size";e={[int]($_.Disksizerequired/1gb)}} | 
        Sort-Object Size -Descending |
        Group-Object -Property "Server"
    
    workflow UpgradeContentDB
    {
        Param($dbColl,$throttle)
    
        foreach -Parallel ($svr in $dbColl)
        {
            "This should be parallel " + $svr.Name + $(Get-Date -Format G)
            foreach -Parallel -throttlelimit $throttle ($db in $svr.Group)
            {
                Sequence
                {  
                    "Processing " + $db.Name
                    $WaitTime = Get-Random -Maximum 100 -Minimum 1;
                    Start-Sleep -Seconds $WaitTime;
                    "Waited for $WaitTime";
                    InlineScript {
                        Add-PSSnapin Microsoft.Sharepoint.Powershell;
                        Upgrade-SPContentDatabase $using:db.Name -Confirm:$false;
                    }
                }
            }
        }
     }

    Wednesday, August 1, 2018 9:15 PM