Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ public interface IClientKeyProvider extends IAuthorizableProvider {
ClientKey getClientKey(String key);
ClientKey getClientKeyFromHash(String hash);
Collection<ClientKey> getAll();
ClientKey getOldestClientKey(int siteId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
public class RotatingClientKeyProvider implements IClientKeyProvider, StoreReader<Collection<ClientKey>> {
private final ScopedStoreReader<Collection<ClientKey>> reader;
private final AuthorizableStore<ClientKey> authorizableStore;
private final ConcurrentHashMap<Integer, VersionedValue> oldestClientKeyBySiteIdCache = new ConcurrentHashMap<>();
private volatile long snapshotVersion = 0;

private record VersionedValue(long version, Optional<ClientKey> value) {}

public RotatingClientKeyProvider(DownloadCloudStorage fileStreamProvider, StoreScope scope) {
this.reader = new ScopedStoreReader<>(fileStreamProvider, scope, new ClientParser(), "auth keys");
Expand All @@ -73,10 +69,6 @@ public long getVersion(JsonObject metadata) {
public long loadContent(JsonObject metadata) throws Exception {
long version = reader.loadContent(metadata, "client_keys");
authorizableStore.refresh(getAll());

// Versioning to prevent race conditions when reading the oldest client key
oldestClientKeyBySiteIdCache.clear();
snapshotVersion = getVersion(metadata);
return version;
}

Expand Down Expand Up @@ -109,21 +101,4 @@ public CloudPath getMetadataPath() {
public IAuthorizable get(String key) {
return getClientKey(key);
}

@Override
public ClientKey getOldestClientKey(int siteId) {
long currentVersion = snapshotVersion;
VersionedValue cached = oldestClientKeyBySiteIdCache.get(siteId);

if (cached != null && cached.version() == currentVersion) {
return cached.value().orElse(null);
}

Optional<ClientKey> computed = this.reader.getSnapshot().stream()
.filter(k -> k.getSiteId() == siteId)
.min(Comparator.comparingLong(ClientKey::getCreated));

oldestClientKeyBySiteIdCache.put(siteId, new VersionedValue(currentVersion, computed));
return computed.orElse(null);
}
}

This file was deleted.

Loading