@@ -137,7 +137,7 @@ public class LinstorPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
137
137
private HostDao _hostDao ;
138
138
@ Inject private VMTemplateDao _vmTemplateDao ;
139
139
140
- private long volumeStatsLastUpdate = 0L ;
140
+ private final Map < String , Long > volumeStatsLastUpdate = new HashMap <>() ;
141
141
private final Map <String , Pair <Long , Long >> volumeStats = new HashMap <>();
142
142
143
143
public LinstorPrimaryDataStoreDriverImpl ()
@@ -1535,11 +1535,12 @@ public boolean canProvideVolumeStats() {
1535
1535
1536
1536
/**
1537
1537
* Updates the cache map containing current allocated size data.
1538
- * @param api Linstor Developers api object
1538
+ * @param linstorAddr Linstor cluster api address
1539
1539
*/
1540
- private void fillVolumeStatsCache (DevelopersApi api ) {
1540
+ private void fillVolumeStatsCache (String linstorAddr ) {
1541
+ final DevelopersApi api = LinstorUtil .getLinstorAPI (linstorAddr );
1541
1542
try {
1542
- logger .trace ("Start volume stats cache update" );
1543
+ logger .trace ("Start volume stats cache update for " + linstorAddr );
1543
1544
List <ResourceWithVolumes > resources = api .viewResources (
1544
1545
Collections .emptyList (),
1545
1546
Collections .emptyList (),
@@ -1566,29 +1567,34 @@ private void fillVolumeStatsCache(DevelopersApi api) {
1566
1567
}
1567
1568
}
1568
1569
1569
- volumeStats .clear ( );
1570
+ volumeStats .keySet (). removeIf ( key -> key . startsWith ( linstorAddr ) );
1570
1571
for (Map .Entry <String , Long > entry : allocSizeMap .entrySet ()) {
1571
1572
Long reserved = resSizeMap .getOrDefault (entry .getKey (), 0L );
1572
1573
Pair <Long , Long > volStat = new Pair <>(entry .getValue (), reserved );
1573
- volumeStats .put (entry .getKey (), volStat );
1574
+ volumeStats .put (linstorAddr + "/" + entry .getKey (), volStat );
1574
1575
}
1575
- volumeStatsLastUpdate = System .currentTimeMillis ();
1576
- logger .trace ( "Done volume stats cache update: {} " , volumeStats .size ());
1576
+ volumeStatsLastUpdate . put ( linstorAddr , System .currentTimeMillis () );
1577
+ logger .debug ( String . format ( "Done volume stats cache update for %s: %d " , linstorAddr , volumeStats .size () ));
1577
1578
} catch (ApiException e ) {
1578
1579
logger .error ("Unable to fetch Linstor resources: {}" , e .getBestMessage ());
1579
1580
}
1580
1581
}
1581
1582
1582
1583
@ Override
1583
1584
public Pair <Long , Long > getVolumeStats (StoragePool storagePool , String volumeId ) {
1584
- final DevelopersApi api = LinstorUtil . getLinstorAPI ( storagePool .getHostAddress () );
1585
+ String linstorAddr = storagePool .getHostAddress ();
1585
1586
synchronized (volumeStats ) {
1586
- long invalidateCacheTime = volumeStatsLastUpdate +
1587
+ long invalidateCacheTime = volumeStatsLastUpdate . getOrDefault ( storagePool . getHostAddress (), 0L ) +
1587
1588
LinstorConfigurationManager .VolumeStatsCacheTime .value () * 1000 ;
1588
1589
if (invalidateCacheTime < System .currentTimeMillis ()) {
1589
- fillVolumeStatsCache (api );
1590
+ fillVolumeStatsCache (storagePool .getHostAddress ());
1591
+ }
1592
+ String volumeKey = linstorAddr + "/" + LinstorUtil .RSC_PREFIX + volumeId ;
1593
+ Pair <Long , Long > sizePair = volumeStats .get (volumeKey );
1594
+ if (sizePair == null ) {
1595
+ logger .warn (String .format ("Volumestats for %s not found in cache" , volumeKey ));
1590
1596
}
1591
- return volumeStats . get ( LinstorUtil . RSC_PREFIX + volumeId ) ;
1597
+ return sizePair ;
1592
1598
}
1593
1599
}
1594
1600
0 commit comments