From a7477db286fb4ad07a9c5dd027331282a65d8d96 Mon Sep 17 00:00:00 2001 From: Karmel Indych Date: Thu, 14 Nov 2024 07:58:14 +0200 Subject: [PATCH] RavenDB-23135 upon server startup ensure update of license limits --- src/Raven.Server/Commercial/LicenseManager.cs | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/Raven.Server/Commercial/LicenseManager.cs b/src/Raven.Server/Commercial/LicenseManager.cs index 2a507cd5417d..0ba3d999f46d 100644 --- a/src/Raven.Server/Commercial/LicenseManager.cs +++ b/src/Raven.Server/Commercial/LicenseManager.cs @@ -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) { @@ -155,13 +155,13 @@ public void Initialize(StorageEnvironment environment, TransactionContextPool co } } - public async Task PutMyNodeInfoAsync() + private async Task TryPutMyNodeInfoAsync() { if (_serverStore.IsPassive()) - return; + return false; if (await _licenseLimitsSemaphore.WaitAsync(0) == false) - return; + return false; try { @@ -177,11 +177,14 @@ 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 { @@ -189,6 +192,27 @@ public async Task PutMyNodeInfoAsync() } } + 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(); @@ -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); }