[java-identity-provider COMMIT] in /trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl: StorageBack...

noreply at shibboleth.net noreply at shibboleth.net
Thu Feb 18 12:11:36 EST 2016


Author: scantor
Date: Thu Feb 18 12:11:36 2016
New Revision: 8094

URL: http://svn.shibboleth.net/view/java-identity-provider?rev=8094&view=rev
Log:
IDP-922 - Session cache needs some inherent limits

https://issues.shibboleth.net/jira/browse/IDP-922

Fix the bloat problem by removing the secondary index for an SPSession
if it's replaced by a new one. This is the common case when transient
NameIDs are used.

Modified:
    trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java
    trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedSessionManager.java

Modified: trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java?rev=8094&r1=8093&r2=8094&view=diff
==============================================================================
--- trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java	(original)
+++ trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedIdPSession.java	Thu Feb 18 12:11:36 2016
@@ -387,8 +387,12 @@
                 log.info("Unable to add SP session due to to storage service limitations");
                 return null;
             }
-            
+                        
             try {
+                // Prime things to make sure any previous instance from this SP is loaded so
+                // we know to remove it.
+                getSPSession(spSession.getId());
+
                 // Store the record.
                 if (!saveSPSessionToStorage(spSession) && !sessionManager.isMaskStorageFailure()) {
                     throw new SessionException("Unable to save SPSession to storage");
@@ -410,6 +414,8 @@
                     if (!success) {
                         log.error("Exhausted retry attempts updating record for session {}", getId());
                     }
+                } else {
+                    sessionManager.unindexSPSession(this, prev, 10);
                 }
                 sessionManager.indexBySPSession(this, spSession, 10);
                 return prev;

Modified: trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedSessionManager.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedSessionManager.java?rev=8094&r1=8093&r2=8094&view=diff
==============================================================================
--- trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedSessionManager.java	(original)
+++ trunk/idp-session-impl/src/main/java/net/shibboleth/idp/session/impl/StorageBackedSessionManager.java	Thu Feb 18 12:11:36 2016
@@ -691,7 +691,7 @@
                 log.error("Exception maintaining secondary index for service ID {} and key {}",
                         serviceId, serviceKey, e);
                 if (!maskStorageFailure) {
-                    throw new SessionException("Exception maintaining seconday index", e);
+                    throw new SessionException("Exception maintaining secondary index", e);
                 }
             } catch (final VersionMismatchException e) {
                 log.debug("Secondary index record was updated between read/update, retrying");
@@ -700,6 +700,86 @@
         }
     }
 
+    /**
+     * Remove or update a secondary index record from an SPSession to a parent IdPSession.
+     * 
+     * @param idpSession the parent session
+     * @param spSession the SPSession to de-index
+     * @param attempts number of times to retry operation in the event of a synchronization issue
+     * 
+     * @throws SessionException if a fatal error occurs
+     */
+    protected void unindexSPSession(@Nonnull final IdPSession idpSession, @Nonnull final SPSession spSession,
+            final int attempts) throws SessionException {
+        if (attempts <= 0) {
+            log.error("Exceeded retry attempts while removing from secondary index");
+            if (!maskStorageFailure) {
+                throw new SessionException("Exceeded retry attempts while removing from secondary index");
+            }
+        } else if (secondaryServiceIndex && storageServiceMeetsThreshold()) {
+            String serviceId = spSession.getId();
+            String serviceKey = spSession.getSPSessionKey();
+            if (serviceKey == null) {
+                return;
+            }
+            log.debug("Removing secondary index for service ID {} and key {}", serviceId, serviceKey);
+
+            final int contextSize = storageService.getCapabilities().getContextSize();
+            final int keySize = storageService.getCapabilities().getKeySize();
+
+            // Truncate context and key if needed.
+            if (serviceId.length() > contextSize) {
+                serviceId = serviceId.substring(0, contextSize);
+            }

[... 53 lines stripped ...]


More information about the commits mailing list