4444public class RotatingClientKeyProvider implements IClientKeyProvider , StoreReader <Collection <ClientKey >> {
4545 private final ScopedStoreReader <Collection <ClientKey >> reader ;
4646 private final AuthorizableStore <ClientKey > authorizableStore ;
47- private final ConcurrentHashMap <Integer , VersionedValue > oldestClientKeyBySiteIdCache = new ConcurrentHashMap <>();
48- private volatile long snapshotVersion = 0 ;
49-
50- private record VersionedValue (long version , Optional <ClientKey > value ) {}
5147
5248 public RotatingClientKeyProvider (DownloadCloudStorage fileStreamProvider , StoreScope scope ) {
5349 this .reader = new ScopedStoreReader <>(fileStreamProvider , scope , new ClientParser (), "auth keys" );
@@ -73,10 +69,6 @@ public long getVersion(JsonObject metadata) {
7369 public long loadContent (JsonObject metadata ) throws Exception {
7470 long version = reader .loadContent (metadata , "client_keys" );
7571 authorizableStore .refresh (getAll ());
76-
77- // Versioning to prevent race conditions when reading the oldest client key
78- oldestClientKeyBySiteIdCache .clear ();
79- snapshotVersion = getVersion (metadata );
8072 return version ;
8173 }
8274
@@ -109,21 +101,4 @@ public CloudPath getMetadataPath() {
109101 public IAuthorizable get (String key ) {
110102 return getClientKey (key );
111103 }
112-
113- @ Override
114- public ClientKey getOldestClientKey (int siteId ) {
115- long currentVersion = snapshotVersion ;
116- VersionedValue cached = oldestClientKeyBySiteIdCache .get (siteId );
117-
118- if (cached != null && cached .version () == currentVersion ) {
119- return cached .value ().orElse (null );
120- }
121-
122- Optional <ClientKey > computed = this .reader .getSnapshot ().stream ()
123- .filter (k -> k .getSiteId () == siteId )
124- .min (Comparator .comparingLong (ClientKey ::getCreated ));
125-
126- oldestClientKeyBySiteIdCache .put (siteId , new VersionedValue (currentVersion , computed ));
127- return computed .orElse (null );
128- }
129104}
0 commit comments