# HG changeset patch # User Sascha L. Teichmann # Date 1312283519 0 # Node ID 31ee2b3b5a5793e530de0e8f18a7ae805bbcd8cf # Parent ddc35c950e97b9e23c26eafc2c2d594d25bb76fa forward list of deleted collections and artifacts from data cleaner to backend to backend listeners. artifacts/trunk@2445 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r ddc35c950e97 -r 31ee2b3b5a57 ChangeLog --- a/ChangeLog Mon Aug 01 15:43:44 2011 +0000 +++ b/ChangeLog Tue Aug 02 11:11:59 2011 +0000 @@ -1,3 +1,19 @@ +2011-08-02 Sascha L. Teichmann + + * artifact-database/src/main/resources/sql/org-h2-driver.properties, + artifact-database/src/main/resources/sql/org-postgresql-driver.properties: + Return uuid in statements used by database cleaner, too. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/BackendListener.java, + artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultBackendListener.java: + Two new methods to reports a list of external killed collections and artifacts. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java: + Broadcast the lists of externally killed collections and artifacts to the listeners. + + * artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java: + Fire lists of deleted collections and artifacts to backend. + 2011-08-01 Sascha L. Teichmann * artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java: diff -r ddc35c950e97 -r 31ee2b3b5a57 artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Mon Aug 01 15:43:44 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Backend.java Tue Aug 02 11:11:59 2011 +0000 @@ -1797,5 +1797,21 @@ return success; } + + @Override + public void killedArtifacts(List identifiers) { + logger.debug("killedArtifacts"); + for (BackendListener listener: listeners) { + listener.killedArtifacts(identifiers, this); + } + } + + @Override + public void killedCollections(List identifiers) { + logger.debug("killedCollections"); + for (BackendListener listener: listeners) { + listener.killedCollections(identifiers, this); + } + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r ddc35c950e97 -r 31ee2b3b5a57 artifact-database/src/main/java/de/intevation/artifactdatabase/BackendListener.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/BackendListener.java Mon Aug 01 15:43:44 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/BackendListener.java Tue Aug 02 11:11:59 2011 +0000 @@ -1,5 +1,7 @@ package de.intevation.artifactdatabase; +import java.util.List; + import de.intevation.artifacts.Artifact; import de.intevation.artifacts.ArtifactCollection; import de.intevation.artifacts.GlobalContext; @@ -47,5 +49,13 @@ void setCollectionName( String collectionId, String name); + + void killedCollections( + List identifiers, + Backend backend); + + void killedArtifacts( + List identifiers, + Backend backend); } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r ddc35c950e97 -r 31ee2b3b5a57 artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java Mon Aug 01 15:43:44 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DatabaseCleaner.java Tue Aug 02 11:11:59 2011 +0000 @@ -61,6 +61,9 @@ */ Artifact reviveArtifact(String factoryName, byte [] bytes); + void killedArtifacts(List identifiers); + void killedCollections(List identifiers); + } // interface ArtifactReviver public interface LockedIdsProvider { @@ -205,14 +208,30 @@ return SLEEP_DEFAULT; } - private static final class IdData { + private static class IdIdentifier { int id; + String identifier; + + private IdIdentifier(int id, String identifier) { + this.id = id; + this.identifier = identifier; + } + } // class IdIdentifier + + private static final class IdData + extends IdIdentifier + { byte [] data; String factoryName; - public IdData(int id, String factoryName, byte [] data) { - this.id = id; + public IdData( + int id, + String factoryName, + byte [] data, + String identifier + ) { + super(id, identifier); this.factoryName = factoryName; this.data = data; } @@ -236,9 +255,6 @@ PreparedStatement stmnt = null; ResultSet result = null; - int removedCollections = 0; - int removedArtifacts = 0; - DataSource dataSource = dbConnection.getDataSource(); Set lockedIds = lockedIdsProvider != null @@ -249,6 +265,9 @@ ? "-666" // XXX: A bit hackish. : StringUtils.repeat('?', lockedIds.size(), ','); + List deletedCollections = new ArrayList(); + List deletedArtifacts = new ArrayList(); + try { connection = dataSource.getConnection(); connection.setAutoCommit(false); @@ -273,10 +292,12 @@ ++idx; } - ArrayList cs = new ArrayList(); + ArrayList cs = new ArrayList(); result = stmnt.executeQuery(); while (result.next()) { - cs.add(result.getInt(1)); + cs.add(new IdIdentifier( + result.getInt(1), + result.getString(2))); } result.close(); result = null; @@ -285,8 +306,8 @@ // delete collection items stmnt = connection.prepareStatement(SQL_DELETE_COLLECTION_ITEMS); - for (Integer id: cs) { - stmnt.setInt(1, id); + for (IdIdentifier id: cs) { + stmnt.setInt(1, id.id); stmnt.execute(); } @@ -295,15 +316,16 @@ // delete collections stmnt = connection.prepareStatement(SQL_DELETE_COLLECTION); - for (Integer id: cs) { - stmnt.setInt(1, id); + for (IdIdentifier id: cs) { + stmnt.setInt(1, id.id); stmnt.execute(); + deletedCollections.add(id.identifier); } stmnt.close(); stmnt = null; connection.commit(); - removedCollections = cs.size(); cs = null; + cs = null; // remove artifacts stmnt = connection.prepareStatement(SQL_DELETE_ARTIFACT); @@ -317,7 +339,8 @@ ids.add(new IdData( result.getInt(1), result.getString(2), - result.getBytes(3))); + result.getBytes(3), + result.getString(4))); } result.close(); result = null; @@ -344,9 +367,9 @@ catch (Exception e) { logger.error(e.getLocalizedMessage(), e); } + + deletedArtifacts.add(idData.identifier); } // for all fetched data - - removedArtifacts += ids.size(); } } catch (SQLException sqle) { @@ -371,8 +394,15 @@ } } - logger.info("collections removed: " + removedCollections); - logger.info("artifacts removed: " + removedArtifacts); + reviver.killedCollections(deletedCollections); + reviver.killedArtifacts(deletedArtifacts); + + if (logger.isDebugEnabled()) { + logger.debug( + "collections removed: " + deletedCollections.size()); + logger.debug( + "artifacts removed: " + deletedArtifacts.size()); + } } /** diff -r ddc35c950e97 -r 31ee2b3b5a57 artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultBackendListener.java --- a/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultBackendListener.java Mon Aug 01 15:43:44 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/DefaultBackendListener.java Tue Aug 02 11:11:59 2011 +0000 @@ -1,5 +1,7 @@ package de.intevation.artifactdatabase; +import java.util.List; + import de.intevation.artifacts.Artifact; import de.intevation.artifacts.ArtifactCollection; import de.intevation.artifacts.GlobalContext; @@ -99,6 +101,16 @@ ) { log.debug("setCollectionName"); } + + @Override + public void killedCollections(List identifiers, Backend backend) { + log.debug("killedCollections"); + } + + @Override + public void killedArtifacts(List identifiers, Backend backend) { + log.debug("killedArtifacts"); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r ddc35c950e97 -r 31ee2b3b5a57 artifact-database/src/main/resources/sql/org-h2-driver.properties --- a/artifact-database/src/main/resources/sql/org-h2-driver.properties Mon Aug 01 15:43:44 2011 +0000 +++ b/artifact-database/src/main/resources/sql/org-h2-driver.properties Tue Aug 02 11:11:59 2011 +0000 @@ -9,7 +9,7 @@ artifacts.touch=UPDATE artifacts SET last_access = CURRENT_TIMESTAMP WHERE id = ? -artifacts.outdated=SELECT id, factory, data FROM artifacts WHERE ttl IS NOT NULL \ +artifacts.outdated=SELECT id, factory, data, gid FROM artifacts WHERE ttl IS NOT NULL \ AND DATEDIFF('MILLISECOND', last_access, CURRENT_TIMESTAMP) > ttl \ AND id NOT IN (SELECT DISTINCT artifact_id FROM collection_items) \ AND id NOT IN ($LOCKED_IDS$) \ @@ -91,7 +91,7 @@ # COLLECTIONS collections.outdated= \ - SELECT c.id FROM collections c \ + SELECT c.id, c.gid FROM collections c \ INNER JOIN collection_items ci ON c.id = ci.collection_id \ INNER JOIN artifacts a ON ci.artifact_id = a.id \ WHERE c.ttl IS NOT NULL \ diff -r ddc35c950e97 -r 31ee2b3b5a57 artifact-database/src/main/resources/sql/org-postgresql-driver.properties --- a/artifact-database/src/main/resources/sql/org-postgresql-driver.properties Mon Aug 01 15:43:44 2011 +0000 +++ b/artifact-database/src/main/resources/sql/org-postgresql-driver.properties Tue Aug 02 11:11:59 2011 +0000 @@ -9,7 +9,7 @@ artifacts.touch=UPDATE artifacts SET last_access = CURRENT_TIMESTAMP WHERE id = ? -artifacts.outdated=SELECT id, factory, data FROM artifacts WHERE ttl IS NOT NULL \ +artifacts.outdated=SELECT id, factory, data, gid FROM artifacts WHERE ttl IS NOT NULL \ AND CURRENT_TIMESTAMP - last_access > (ttl || ' milliseconds')::interval \ AND id NOT IN (SELECT DISTINCT artifact_id FROM collection_items) \ AND id NOT IN ($LOCKED_IDS$) \ @@ -91,7 +91,7 @@ # COLLECTIONS collections.outdated= \ - SELECT c.id FROM collections c \ + SELECT c.id, c.gid FROM collections c \ INNER JOIN collection_items ci ON c.id = ci.collection_id \ INNER JOIN artifacts a ON ci.artifact_id = a.id \ WHERE c.ttl IS NOT NULL \