Skip to content

Commit 5b451b8

Browse files
authored
Shorten managed dependencies snapshot folder names (#293)
* Remove dot from snapshot folder name postfixes * Remove dashes and dots from snasphot folder names * Remove microseconds from snapshot folder names * Remove century from the year number in snapshot folder names
1 parent bc54803 commit 5b451b8

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

docs/designs/PowerShell-AzF-Overall-Design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ A snapshot is considered _acceptable_ if it contains any version _allowed_ by th
492492

493493
However, if the latest snapshot is _not acceptable_ (i.e. it does not contain module versions required by the manifest), the worker starts installing the dependencies into a new snapshot, and all the subsequent function invocation requests are blocked, waiting for the new snapshot installation to complete.
494494

495-
When a snapshot installation starts, the dependencies are first installed into a folder with a name following a special pattern (`*.i`), so that this snapshot is not picked up by any worker prematurely, before the installation is complete. After _successful_ completion, the snapshot is _atomically promoted_ by renaming the folder to follow a different pattern (`*.r`), which indicates to other workers that this snapshot is ready to use. If the installation fails or cannot complete for any reason (for example, the worker restarts, crashes, or gets decommissioned), the folder stays in the installing state until removed.
495+
When a snapshot installation starts, the dependencies are first installed into a folder with a name following a special pattern (`*i`), so that this snapshot is not picked up by any worker prematurely, before the installation is complete. After _successful_ completion, the snapshot is _atomically promoted_ by renaming the folder to follow a different pattern (`*r`), which indicates to other workers that this snapshot is ready to use. If the installation fails or cannot complete for any reason (for example, the worker restarts, crashes, or gets decommissioned), the folder stays in the installing state until removed.
496496

497497
Incomplete and old snapshots that are no longer in use are periodically removed from the file storage. In order to allow detecting unused snapshots, each PowerShell worker keeps "touching" a file named `.used` at the root of the used snapshot folder every `MDHeartbeatPeriod` minutes. Before and after installing any new snapshot, every PowerShell worker looks for unused snapshots by checking the folder creation time and the `.used` file modification time. If both these time values are older than (`MDHeartbeatPeriod` + `MDOldSnapshotHeartbeatMargin`) minutes, the snapshot is considered unused, so the PowerShell worker removes it. The latest `MDMinNumberOfSnapshotsToKeep` snapshots will never be removed, regardless of usage.
498498

src/DependencyManagement/DependencySnapshotFolderNameTools.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.DependencyManagement
1010

1111
internal static class DependencySnapshotFolderNameTools
1212
{
13-
private const string InstallingPostfix = ".i";
13+
private const string InstallingPostfix = "i";
1414

15-
public const string InstalledPostfix = ".r";
15+
public const string InstalledPostfix = "r";
1616

1717
public const string InstalledPattern = "*" + InstalledPostfix;
1818

1919
private const string AccessMarkerFileName = ".used";
2020

2121
public static string CreateUniqueName()
2222
{
23-
var uniqueBase = DateTime.UtcNow.ToString("yyyyMMdd-HHmmss.ffffff");
23+
var uniqueBase = DateTime.UtcNow.ToString("yyMMddHHmmssfff");
2424
return uniqueBase + InstalledPostfix;
2525
}
2626

@@ -29,11 +29,11 @@ public static string CreateUniqueName()
2929
/// appending a postfix, so that that the resulting path follows a different
3030
/// pattern and can be discovered using a different file mask.
3131
/// For example, for the _installed_ path
32-
/// ".../20190710-1234.567890.r"
32+
/// ".../1907101234567r"
3333
/// the _installing_ path will be:
34-
/// ".../20190710-1234.567890.r.i"
35-
/// This makes it possible to enumerate all the installed snapshots by using ".../*.r" mask,
36-
/// and all the installing snapshots by using ".../*.i" mask.
34+
/// ".../1907101234567ri"
35+
/// This makes it possible to enumerate all the installed snapshots by using ".../*r" mask,
36+
/// and all the installing snapshots by using ".../*i" mask.
3737
/// </summary>
3838
public static string ConvertInstalledToInstalling(string installedPath)
3939
{

test/Unit/DependencyManagement/DependencySnapshotFolderNameToolsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class DependencySnapshotFolderNameToolsTests
1717
public void CreatesUniqueEnoughNames()
1818
{
1919
var name1 = DependencySnapshotFolderNameTools.CreateUniqueName();
20-
Thread.Sleep(1); // A snapshot name created 1 millisecond later must be different
20+
Thread.Sleep(2); // A snapshot name created 2 milliseconds later must be different
2121
var name2 = DependencySnapshotFolderNameTools.CreateUniqueName();
2222
Assert.NotEqual(name1, name2);
2323
}
@@ -41,7 +41,7 @@ public void NamesConvertedFromInstalledToInstallingDoNotHaveInstalledPostfix()
4141
public void UniqueNamesConvertedFromInstalledToInstallingAreStillUnique()
4242
{
4343
var name1 = DependencySnapshotFolderNameTools.CreateUniqueName();
44-
Thread.Sleep(1); // A snapshot name created 1 millisecond later must be different
44+
Thread.Sleep(2); // A snapshot name created 2 milliseconds later must be different
4545
var name2 = DependencySnapshotFolderNameTools.CreateUniqueName();
4646

4747
var convertedToInstalling1 = DependencySnapshotFolderNameTools.ConvertInstalledToInstalling(name1);

0 commit comments

Comments
 (0)