Changeset 3270

Show
Ignore:
Timestamp:
01/12/09 08:49:34 (20 months ago)
Author:
jmoore
Message:

OmeroClustering : Cleaning sessions in jdbc ring and protecting NPEs

(cherry picked from commit bcafc11e48d911ccb405680477e40d66332241d8)

Location:
trunk/components/blitz
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/components/blitz/src/ome/services/blitz/fire/Ring.java

    r3269 r3270  
    1111import java.sql.SQLException; 
    1212import java.util.ArrayList; 
     13import java.util.HashMap; 
    1314import java.util.HashSet; 
    1415import java.util.List; 
     16import java.util.Map; 
    1517import java.util.Set; 
    1618import java.util.UUID; 
     
    213215            } 
    214216            remove(MANAGERS + uuid); 
    215             int count = jdbc.update("delete from session_ring where value = ?", uuid); 
    216             log.info("Removed "+count+" entries for "+uuid); 
     217            int count = jdbc.update("delete from session_ring where value = ?", 
     218                    uuid); 
     219            log.info("Removed " + count + " entries for " + uuid); 
    217220            log.info("Disconnected from OMERO.cluster"); 
    218221        } catch (Exception e) { 
     
    359362            } 
    360363        } 
     364        // Now removing any stale sessions 
     365        StringBuilder sb = new StringBuilder(); 
     366        sb.append("delete from session_ring "); 
     367        sb.append("where key like 'session-%' "); 
     368        sb.append("and ("); 
     369        sb.append(" value != "); 
     370        sb.append(" '"); 
     371        sb.append(uuid); // Self 
     372        sb.append("' "); 
     373        for (String nodeUuid : nodeUuids) { 
     374            sb.append(" and "); 
     375            sb.append("value != '"); 
     376            sb.append(nodeUuid); 
     377            sb.append("' "); 
     378        } 
     379        sb.append(")"); 
     380        int count = jdbc.update(sb.toString()); 
     381        if (count != 0) { 
     382            log.info("Removed " + count + " stale sessions"); 
     383        } 
    361384    } 
    362385 
    363386    protected void purgeNode(String manager) { 
    364387        log.info("Purging node: " + manager); 
    365         int count = jdbc.update("delete from session_ring where key like '" 
    366                 + SESSIONS + "' and value = ?", manager); 
    367         log.info("Removed " + count + " sessions with value " + manager); 
     388        int count = jdbc.update("delete from session_ring where value = ?", 
     389                manager); 
     390        log.info("Removed " + count + " entries with value " + manager); 
    368391        count = jdbc.update("delete from session_ring where key = ?", MANAGERS 
    369392                + manager); 
    370393        log.info("Removed " + MANAGERS + manager); 
    371         count = jdbc.update( 
    372                 "delete from session_ring where key = ? and value = ?", CONFIG 
    373                         + "redirect", manager); 
    374         if (count != 0) { 
    375             log.info("Removed redirect to " + manager); 
    376         } 
    377         putRedirect(uuid); 
     394        putIfAbsent(CONFIG + "redirect", uuid); 
    378395    } 
    379396 
     
    384401        if (arg0 instanceof CreateSessionMessage) { 
    385402            String session = ((CreateSessionMessage) arg0).getSessionId(); 
     403            log.info("Adding session " + session + " to manager " + uuid); 
    386404            put(SESSIONS + session, uuid); // Use our uuid rather than proxy 
    387405        } else if (arg0 instanceof DestroySessionMessage) { 
    388406            String session = ((DestroySessionMessage) arg0).getSessionId(); 
    389407            remove(SESSIONS + session); 
     408            log.info("Removing session " + session + " from manager " + uuid); 
    390409        } else if (arg0 instanceof ContextClosedEvent) { 
    391410            // This happens 3 times for each nested context. Perhaps we 
  • trunk/components/blitz/src/ome/services/blitz/util/BlitzConfiguration.java

    r3266 r3270  
    120120 
    121121        } catch (RuntimeException e) { 
    122             destroy(); 
     122            try { 
     123                destroy(); 
     124            } catch (Exception e2) { 
     125                logger.error("Error destroying configuration after " 
     126                        + "initialization exception. " 
     127                        + "Throwing initialization exception", e2); 
     128            } 
    123129            throw e; 
    124130        } 
  • trunk/components/blitz/test/ome/services/blitz/test/ClusteredRingTest.java

    r3269 r3270  
    1212import ome.services.blitz.fire.Ring; 
    1313import ome.services.blitz.test.mock.MockFixture; 
     14import ome.services.messages.CreateSessionMessage; 
    1415import ome.system.OmeroContext; 
    1516 
     
    123124 
    124125    @Test 
     126    public void testAddedSessionGetsUuidOfManager() throws Exception { 
     127        fixture1.ctx.publishEvent(new CreateSessionMessage(this, "test-for-uuid")); 
     128        assertTrue(fixture1.blitz.getRing().checkPassword("test-for-uuid")); 
     129        String value = fixture1.jdbc.queryForObject("select value from session_ring where key = ?", String.class, "session-test-for-uuid"); 
     130        assertEquals(fixture1.blitz.getRing().uuid, value); 
     131    } 
     132     
     133    @Test 
    125134    public void testHandlesMissingServers() throws Exception { 
    126135        fail(); 
  • trunk/components/blitz/test/ome/services/blitz/test/mock/MockFixture.java

    r3266 r3270  
    3939 
    4040    public final BlitzConfiguration blitz; 
    41     public final OmeroContext ctx; 
     41    public final SimpleJdbcTemplate jdbc; 
    4242    public final SessionManagerI sm; 
    43     public final Executor ex; 
    4443    public final SessionManager mgr; 
    4544    public final SecuritySystem ss; 
    46     public final SimpleJdbcTemplate jdbc; 
     45    public final OmeroContext ctx; 
     46    public final Executor ex; 
     47    public final Ring ring; 
    4748 
    4849    public static OmeroContext basicContext() { 
     
    7172        this.test = test; 
    7273        this.ctx = ctx; 
     74        this.ring = (Ring) ctx.getBean("ring"); 
    7375        this.ex = (Executor) ctx.getBean("executor"); 
    7476        this.ss = (SecuritySystem) ctx.getBean("securitySystem"); 
     
    101103        id.properties.setProperty("ClusterProxy","Cluster:udp -h 224.0.0.5 -p 10000"); 
    102104         
    103          
    104         Ring ring = new Ring(jdbc); 
    105         ring.setApplicationEventPublisher(ctx); 
    106          
    107105        blitz = new BlitzConfiguration(id, ring, mgr, ss, ex); 
    108106        this.sm = (SessionManagerI) blitz.getBlitzManager(); 
  • trunk/components/blitz/test/omero/test.xml

    r3239 r3270  
    110110  </bean> 
    111111 
     112  <!-- Defined here since it is an application listener. --> 
     113  <bean id="ring" class="ome.services.blitz.fire.Ring"> 
     114    <constructor-arg ref="simpleJdbcTemplate"/> 
     115  </bean> 
    112116</beans> 

1.2.1-PRO © 2008-2009 agile42 all rights reserved (this page was served in: 0.115114 sec.)