Fix flush dati RIOC
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<RootNamespace>MP.RIOC</RootNamespace>
|
||||
<Version>8.16.2606.1118</Version>
|
||||
<Version>8.16.2606.1119</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo MP-RIOC </i>
|
||||
<h4>Versione: 8.16.2606.1118</h4>
|
||||
<h4>Versione: 8.16.2606.1119</h4>
|
||||
<br /> Note di rilascio:
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
@@ -1 +1 @@
|
||||
8.16.2606.1118
|
||||
8.16.2606.1119
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>8.16.2606.1118</version>
|
||||
<version>8.16.2606.1119</version>
|
||||
<url>https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/MP.RIOC.zip</url>
|
||||
<changelog>https://nexus.steamware.net/repository/SWS/MP-RIOC/stable/LAST/ChangeLog.html</changelog>
|
||||
<mandatory>false</mandatory>
|
||||
|
||||
@@ -69,20 +69,27 @@ namespace MP.RIOC.Services
|
||||
/// <summary>
|
||||
/// Cancellazione ricorsiva chiavi ausiliarie (:status, :errors) e rimozione dall'indice
|
||||
/// </summary>
|
||||
private async Task DeleteAuxKeysAndIndexAsync(RedisKey sKey, RedisKey indexKey, IBatch batch)
|
||||
private async Task DeleteAuxKeysAndIndexAsync(RedisKey sKey, RedisKey indexKey, IBatch batch, List<Task> pendingOps)
|
||||
{
|
||||
string sKeyStr = sKey.ToString();
|
||||
string keyDir = sKeyStr.Substring(0, sKeyStr.LastIndexOf(':'));
|
||||
|
||||
// Cancella :status dal sorted set e dalla hash
|
||||
string statusKey = keyDir + ":status";
|
||||
await batch.SortedSetRemoveAsync(indexKey, statusKey);
|
||||
await batch.KeyDeleteAsync(statusKey);
|
||||
|
||||
try
|
||||
{
|
||||
pendingOps.Add(batch.SortedSetRemoveAsync(indexKey, statusKey));
|
||||
pendingOps.Add(batch.KeyDeleteAsync(statusKey));
|
||||
}
|
||||
catch { }
|
||||
// Cancella :errors dal sorted set e dalla hash
|
||||
string errorKey = keyDir + ":errors";
|
||||
await batch.SortedSetRemoveAsync(indexKey, errorKey);
|
||||
await batch.KeyDeleteAsync(errorKey);
|
||||
try
|
||||
{
|
||||
pendingOps.Add(batch.SortedSetRemoveAsync(indexKey, errorKey));
|
||||
pendingOps.Add(batch.KeyDeleteAsync(errorKey));
|
||||
}
|
||||
catch { }
|
||||
|
||||
// Cancella chiave ausiliaria :status anche da un eventuale indice days se presente
|
||||
if (statusKey.Contains(":stats:hours:"))
|
||||
@@ -90,7 +97,7 @@ namespace MP.RIOC.Services
|
||||
string daysIndex = statusKey.Replace(":stats:hours:", ":stats:days:");
|
||||
try
|
||||
{
|
||||
await batch.SortedSetRemoveAsync(daysIndex, statusKey);
|
||||
pendingOps.Add(batch.SortedSetRemoveAsync(daysIndex, statusKey));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@@ -101,7 +108,7 @@ namespace MP.RIOC.Services
|
||||
string daysIndex = errorKey.Replace(":stats:hours:", ":stats:days:");
|
||||
try
|
||||
{
|
||||
await batch.SortedSetRemoveAsync(daysIndex, errorKey);
|
||||
pendingOps.Add(batch.SortedSetRemoveAsync(daysIndex, errorKey));
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
@@ -150,6 +157,7 @@ namespace MP.RIOC.Services
|
||||
};
|
||||
|
||||
var batch = _db.CreateBatch();
|
||||
var pendingOps = new List<Task>();
|
||||
foreach (var pattern in patternsToScan)
|
||||
{
|
||||
// Nota: KeyScanAsync/KeysAsync e' disponibile su IServer
|
||||
@@ -179,17 +187,19 @@ namespace MP.RIOC.Services
|
||||
isOrphanKey = keyTtl.Value.TotalSeconds < 0 || keyTtl.Value.TotalHours > 30.25 * 24;
|
||||
}
|
||||
|
||||
// Se era scaduta o orfana e abbiamo il permesso, segnamola per la cancellazione
|
||||
if ((meta.Timestamp < currentDayStart || isOrphanKey) && deleteConfirmed)
|
||||
// Se è orfana e abbiamo il permesso, segnamola per la cancellazione
|
||||
// NOTA: non usiamo il confronto con currentDayStart perché taglierebbe fuori
|
||||
// i dati delle ore/giorni precedenti che devono essere ancora processati dal DB
|
||||
if (isOrphanKey && deleteConfirmed)
|
||||
{
|
||||
// 1. Segna la chiave Hash (Dati) per l'eliminazione
|
||||
keysToDelete.Add(sKey);
|
||||
|
||||
// 2. Rimuovi il riferimento dal Sorted Set (Indice)
|
||||
await batch.SortedSetRemoveAsync(indexKey, statKey);
|
||||
pendingOps.Add(batch.SortedSetRemoveAsync(indexKey, statKey));
|
||||
|
||||
// 3. Cancellazione ricorsiva delle chiavi ausiliarie (:status, :errors, :days)
|
||||
await DeleteAuxKeysAndIndexAsync(sKey, indexKey, batch);
|
||||
await DeleteAuxKeysAndIndexAsync(sKey, indexKey, batch, pendingOps);
|
||||
}
|
||||
|
||||
// Recupero dati dalla Hash
|
||||
@@ -236,6 +246,8 @@ namespace MP.RIOC.Services
|
||||
}
|
||||
}
|
||||
batch.Execute();
|
||||
// attendo conclusione
|
||||
await Task.WhenAll(pendingOps);
|
||||
}
|
||||
|
||||
// --- FASE UPSERT DB ---
|
||||
@@ -251,13 +263,16 @@ namespace MP.RIOC.Services
|
||||
if (deleteConfirmed && keysToDelete.Any())
|
||||
{
|
||||
var batch = _db.CreateBatch();
|
||||
var pendingOps = new List<Task>();
|
||||
int deletedCount = 0;
|
||||
foreach (var key in keysToDelete)
|
||||
{
|
||||
await batch.KeyDeleteAsync(key);
|
||||
pendingOps.Add(batch.KeyDeleteAsync(key));
|
||||
deletedCount++;
|
||||
}
|
||||
batch.Execute();
|
||||
// attendo conclusione
|
||||
await Task.WhenAll(pendingOps);
|
||||
Log.Info($"[CLEANUP DAY] Deleted {deletedCount} expired metric keys from Redis");
|
||||
}
|
||||
}
|
||||
@@ -294,6 +309,7 @@ namespace MP.RIOC.Services
|
||||
};
|
||||
|
||||
var batch = _db.CreateBatch();
|
||||
var pendingOps = new List<Task>();
|
||||
foreach (var pattern in patternsToScan)
|
||||
{
|
||||
// Nota: KeyScanAsync/KeysAsync e' disponibile su IServer
|
||||
@@ -323,17 +339,19 @@ namespace MP.RIOC.Services
|
||||
isOrphanKey = keyTtl.Value.TotalSeconds < 0 || keyTtl.Value.TotalHours > 15.25 * 24;
|
||||
}
|
||||
|
||||
// Se era scaduta o orfana e abbiamo il permesso, segnamola per la cancellazione
|
||||
if ((meta.Timestamp < currentHourStart || isOrphanKey) && deleteConfirmed)
|
||||
// Se è orfana e abbiamo il permesso, segnamola per la cancellazione
|
||||
// NOTA: non usiamo il confronto con currentHourStart perché taglierebbe fuori
|
||||
// i dati delle ore precedenti che devono essere ancora processati dal DB
|
||||
if (isOrphanKey && deleteConfirmed)
|
||||
{
|
||||
// 1. Segna la chiave Hash (Dati) per l'eliminazione
|
||||
keysToDelete.Add(sKey);
|
||||
|
||||
// 2. Rimuovi il riferimento dal Sorted Set (Indice)
|
||||
await batch.SortedSetRemoveAsync(indexKey, statKey);
|
||||
pendingOps.Add(batch.SortedSetRemoveAsync(indexKey, statKey));
|
||||
|
||||
// 3. Cancellazione ricorsiva chiavi ausiliarie
|
||||
await DeleteAuxKeysAndIndexAsync(sKey, indexKey, batch);
|
||||
await DeleteAuxKeysAndIndexAsync(sKey, indexKey, batch, pendingOps);
|
||||
}
|
||||
|
||||
// Recupero dati dalla Hash
|
||||
@@ -379,6 +397,8 @@ namespace MP.RIOC.Services
|
||||
}
|
||||
}
|
||||
batch.Execute();
|
||||
// attendo conclusione
|
||||
await Task.WhenAll(pendingOps);
|
||||
}
|
||||
|
||||
// --- FASE UPSERT DB ---
|
||||
@@ -394,13 +414,16 @@ namespace MP.RIOC.Services
|
||||
if (deleteConfirmed && keysToDelete.Count > 0)
|
||||
{
|
||||
var batch = _db.CreateBatch();
|
||||
var pendingOps = new List<Task>();
|
||||
int deletedCount = 0;
|
||||
foreach (var key in keysToDelete)
|
||||
{
|
||||
await batch.KeyDeleteAsync(key);
|
||||
pendingOps.Add(batch.KeyDeleteAsync(key));
|
||||
deletedCount++;
|
||||
}
|
||||
batch.Execute();
|
||||
// attendo conclusione
|
||||
await Task.WhenAll(pendingOps);
|
||||
Log.Info($"[CLEANUP HOUR] Deleted {deletedCount} expired metric keys from Redis");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user