Skip to content

Commit

Permalink
RavenDB-23135 upon server startup ensure update of license limits
Browse files Browse the repository at this point in the history
  • Loading branch information
karmeli87 authored and grisha-kotler committed Nov 20, 2024
1 parent 5006bc2 commit a7477db
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/Raven.Server/Commercial/LicenseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void Initialize(StorageEnvironment environment, TransactionContextPool co
ReloadLicense(firstRun: true);
ReloadLicenseLimits(firstRun: true);

Task.Run(PutMyNodeInfoAsync).IgnoreUnobservedExceptions();
Task.Run(() => PutMyNodeInfoAsync(tryForever: true)).IgnoreUnobservedExceptions();
}
catch (Exception e)
{
Expand All @@ -155,13 +155,13 @@ public void Initialize(StorageEnvironment environment, TransactionContextPool co
}
}

public async Task PutMyNodeInfoAsync()
private async Task<bool> TryPutMyNodeInfoAsync()
{
if (_serverStore.IsPassive())
return;
return false;

if (await _licenseLimitsSemaphore.WaitAsync(0) == false)
return;
return false;

try
{
Expand All @@ -177,18 +177,42 @@ public async Task PutMyNodeInfoAsync()
};

await _serverStore.PutNodeLicenseLimitsAsync(_serverStore.NodeTag, detailsPerNode, LicenseStatus.MaxCores);
return true;
}
catch (Exception e)
{
if (Logger.IsOperationsEnabled && _serverStore.IsPassive() == false)
Logger.Operations("Failed to put my node info, will try again later", e);

return false;
}
finally
{
_licenseLimitsSemaphore.Release();
}
}

public async Task PutMyNodeInfoAsync(bool tryForever = false)
{
while (true)
{
if (await TryPutMyNodeInfoAsync())
return;

if (tryForever == false)
return;

try
{
await Task.Delay(TimeSpan.FromMinutes(1), _serverStore.ServerShutdown);
}
catch // shutting down
{
return;
}
}
}

public void ReloadLicense(bool firstRun = false)
{
var license = _serverStore.LoadLicense();
Expand Down Expand Up @@ -293,7 +317,7 @@ public int GetCoresLimitForNode(out LicenseLimits licenseLimits, bool shouldPutN
}

// we don't have any license limits for this node, let's put our info to update it
if(shouldPutNodeInfoIfNotExist)
if (shouldPutNodeInfoIfNotExist)
Task.Run(async () => await PutMyNodeInfoAsync()).IgnoreUnobservedExceptions();
return Math.Min(ProcessorInfo.ProcessorCount, LicenseStatus.MaxCores);
}
Expand Down

0 comments on commit a7477db

Please sign in to comment.