Skip to content

Commit

Permalink
fix(jans-auth-server): fixed pool allocation
Browse files Browse the repository at this point in the history
#8562
Signed-off-by: YuriyZ <yzabrovarniy@gmail.com>
  • Loading branch information
yuriyz committed Jun 24, 2024
1 parent 1719b72 commit 11b0fbe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

package io.jans.as.server.service.cluster;

import static io.jans.as.server.service.cluster.ClusterNodeService.LOCK_KEY;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;

import io.jans.as.model.config.StaticConfiguration;
import io.jans.as.model.configuration.AppConfiguration;
import io.jans.model.token.StatusIndexPool;
Expand All @@ -24,6 +17,12 @@
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.slf4j.Logger;

import java.util.Date;
import java.util.List;

import static io.jans.as.server.service.cluster.ClusterNodeService.LOCK_KEY;

/**
* @author Yuriy Movchan
Expand Down Expand Up @@ -91,8 +90,15 @@ public List<StatusIndexPool> getAllPools() {
* @return pool
*/
public StatusIndexPool getPoolLast() {
String baseDn = staticConfiguration.getBaseDn().getNode();
PagedResult<StatusIndexPool> pagedResult = entryManager.findPagedEntries(baseDn, StatusIndexPool.class, Filter.createPresenceFilter("jansNum"), null, "jansNum", SortOrder.DESCENDING, 0, 1, 1);
String baseDn = baseDn();

int count = 1;
if (PersistenceEntryManager.PERSITENCE_TYPES.ldap.name().equals(entryManager.getPersistenceType(baseDn))) {
count = Integer.MAX_VALUE;
}

PagedResult<StatusIndexPool> pagedResult = entryManager.findPagedEntries(baseDn, StatusIndexPool.class,
Filter.createPresenceFilter("jansNum"), null, "jansNum", SortOrder.DESCENDING, 0, count, count);
if (pagedResult.getEntriesCount() >= 1) {
return setIndexes(pagedResult.getEntries().get(0));
}
Expand Down Expand Up @@ -197,19 +203,15 @@ public StatusIndexPool allocate(int nodeId) {
pool.setLockKey(LOCK_KEY);
pool.setExpirationDate(expirationDate);
pool.setLastUpdate(new Date());
pool.setNodeId(nodeId);

update(pool);

// Load pool after update
StatusIndexPool lockedPool = getPoolByDn(pool.getDn());

// If lock is ours reset entry and return it
if (LOCK_KEY.equals(lockedPool.getLockKey())) {
// Assign record for specific nodeId
lockedPool.setNodeId(nodeId);

update(lockedPool);

if (LOCK_KEY.equals(lockedPool.getLockKey()) && lockedPool.getNodeId().equals(nodeId)) {
log.debug("Re-using existing status index pool {}, node {}, LOCK_KEY {}", lockedPool.getId(), nodeId, LOCK_KEY);
return lockedPool;
}
Expand Down Expand Up @@ -246,7 +248,7 @@ public StatusIndexPool allocate(int nodeId) {
StatusIndexPool lockedPool = getPoolByDn(pool.getDn());

// if lock is ours return it
if (LOCK_KEY.equals(lockedPool.getLockKey())) {
if (LOCK_KEY.equals(lockedPool.getLockKey()) && lockedPool.getNodeId().equals(nodeId)) {
log.debug("Successfully created new status index pool {}, node {}", lockedPool.getId(), nodeId);
return setIndexes(lockedPool);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public class StatusListService {
private WebKeysConfiguration webKeysConfiguration;

public Response requestStatusList(String acceptHeader) {
log.debug("Attempting to request token_status_list, acceptHeader: {} ...", acceptHeader);
log.debug("Attempting to request status_list, acceptHeader: {} ...", acceptHeader);

errorResponseFactory.validateFeatureEnabled(FeatureFlagType.STATUS_LIST);

try {
final List<StatusIndexPool> pools = statusTokenPoolService.getAllTokenPools();
final List<StatusIndexPool> pools = statusTokenPoolService.getAllPools();
final StatusList statusList = join(pools);

final boolean isJsonRequested = CONTENT_TYPE_STATUSLIST_JSON.equalsIgnoreCase(acceptHeader);
Expand Down

0 comments on commit 11b0fbe

Please sign in to comment.