Changeset 5023
- Timestamp:
- Jul 27, 2009, 1:14:07 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/config/dist/base.config
r4827 r5023 54 54 db.raw-data-types = /raw-data-types.xml 55 55 db.batch-size = 50 56 # Number of hours between cleanup of unused items in the database 57 # Set to 0 to disable (recommended for job agents) 58 db.cleanup.interval = 24 56 59 57 60 -
trunk/doc/src/docbook/appendix/base.config.xml
r4827 r5023 234 234 </listitem> 235 235 </varlistentry> 236 237 <varlistentry> 238 <term><property>db.cleanup.interval</property></term> 239 <listitem> 240 <para> 241 Interval in hours between database cleanups. Set this to 242 0 to disable (recommened for job agents). The default value 243 is 24. 244 </para> 245 </listitem> 246 </varlistentry> 236 247 237 248 <varlistentry> -
trunk/src/core/net/sf/basedb/core/Application.java
r4889 r5023 505 505 long milliSeconds = 60 * 1000 * sessionCacheTimeout; 506 506 getScheduler().schedule(new SessionControlCacheCleaner(), milliSeconds, milliSeconds, false); 507 508 // Adding a task that cleans the database at regular intervals 509 long cleanupInterval = 3600 * 1000 * Config.getInt("db.cleanup.interval", 24); 510 if (cleanupInterval > 0) 511 { 512 getScheduler().schedule(new DbCleaner(), cleanupInterval, cleanupInterval, false); 513 } 507 514 508 515 // Adding a task that cleans the static cache at regular intervals … … 1084 1091 } 1085 1092 1093 private static class DbCleaner 1094 extends TimerTask 1095 { 1096 /* 1097 From the TimerTask class 1098 ------------------------------------------- 1099 */ 1100 public void run() 1101 { 1102 log.info("Cleaning database"); 1103 // Stray any-to-any links 1104 int numDeleted = AnyToAny.deleteStrayLinks(null); 1105 log.info("Found " + numDeleted + " stray any-to-any links"); 1106 1107 // Item and project keys 1108 numDeleted = ItemKey.deleteUnusedItemKeys(); 1109 log.info("Found " + numDeleted + " unused item keys"); 1110 numDeleted = ProjectKey.deleteUnusedProjectKeys(); 1111 log.info("Found " + numDeleted + " unused project keys"); 1112 1113 log.info("Finished cleaning of database"); 1114 } 1115 // ------------------------------------------- 1116 } 1117 1118 1086 1119 private static class SecondaryStorageControllerTask 1087 1120 extends TimerTask -
trunk/src/core/net/sf/basedb/core/ItemKey.java
r4889 r5023 148 148 149 149 /** 150 @deprecated Use {@link #deleteUnusedItemKeys()} instead which returns the number of 151 deleted keys 152 */ 153 public static synchronized void deleteUnusedKeys() 154 throws BaseException 155 { 156 deleteUnusedItemKeys(); 157 } 158 159 160 /** 150 161 Delete all keys that are currently not used by any item. This method 151 162 is intended to be executed at regular intervals by a cleanup application. 152 @throws BaseException If a unused key could not be deleted. 153 */ 154 public static synchronized void deleteUnusedKeys() 163 @return The number of deleted item keys 164 @throws BaseException If a unused key could not be deleted. 165 @since 2.13 166 */ 167 public static synchronized int deleteUnusedItemKeys() 155 168 throws BaseException 156 169 { 157 170 org.hibernate.Session session = null; 158 171 org.hibernate.Transaction tx = null; 172 int numDeleted = 0; 159 173 try 160 174 { … … 179 193 { 180 194 HibernateUtil.deleteData(session, ik); 195 numDeleted++; 181 196 } 182 197 HibernateUtil.commit(tx); … … 191 206 if (session != null) HibernateUtil.close(session); 192 207 } 208 return numDeleted; 193 209 } 194 210 -
trunk/src/core/net/sf/basedb/core/ProjectKey.java
r4889 r5023 122 122 123 123 /** 124 @deprecated Use {@link #deleteUnusedProjectKeys()} instead which returns the number of 125 deleted keys 126 */ 127 public static synchronized void deleteUnusedKeys() 128 throws BaseException 129 { 130 deleteUnusedProjectKeys(); 131 } 132 133 /** 124 134 Delete all keys that are currently not used by any item. This method 125 135 is intended to be executed at regular intervals by a cleanup application. 126 136 @throws BaseException If there is some kind of error. 127 137 */ 128 public static synchronized void deleteUnusedKeys()138 public static synchronized int deleteUnusedProjectKeys() 129 139 throws BaseException 130 140 { 131 141 org.hibernate.Session session = null; 132 142 org.hibernate.Transaction tx = null; 143 int numDeleted = 0; 133 144 try 134 145 { … … 153 164 { 154 165 HibernateUtil.deleteData(session, pk); 166 numDeleted++; 155 167 } 156 168 HibernateUtil.commit(tx); … … 165 177 if (session != null) HibernateUtil.close(session); 166 178 } 179 return numDeleted; 167 180 } 168 181 -
trunk/src/test/TestItemKey.java
r4889 r5023 62 62 TestGroup.test_delete(groupId); 63 63 64 test_delete_unused( );64 test_delete_unused(2); 65 65 66 66 write("++Testing item key "+(ok ? "OK" : "Failed")+"\n"); … … 123 123 } 124 124 125 static void test_delete_unused( )125 static void test_delete_unused(int expected) 126 126 { 127 127 try 128 128 { 129 ItemKey.deleteUnusedKeys(); 130 write("--Delete unused item keys OK"); 129 int numDeleted = ItemKey.deleteUnusedItemKeys(); 130 if (expected >= 0 && numDeleted != expected) 131 { 132 throw new BaseException("Unexpected number of unused item keys: " + 133 numDeleted + "; expected " + expected); 134 } 135 write("--Delete unused item keys OK (" + expected + ")"); 131 136 } 132 137 catch (Throwable ex) -
trunk/src/test/TestProjectKey.java
r4889 r5023 22 22 */ 23 23 import net.sf.basedb.core.*; 24 24 25 import java.util.EnumSet; 25 26 … … 80 81 // TestProject.test_delete(projectId2); 81 82 82 test_delete_unused( );83 test_delete_unused(2); 83 84 84 85 write("++Testing project key "+(ok ? "OK" : "Failed")+"\n"); … … 143 144 } 144 145 145 static void test_delete_unused() 146 { 147 try 148 { 149 ProjectKey.deleteUnusedKeys(); 150 write("--Delete unused project keys OK"); 146 static void test_delete_unused(int expected) 147 { 148 try 149 { 150 int numDeleted = ProjectKey.deleteUnusedProjectKeys(); 151 if (expected >= 0 && numDeleted != expected) 152 { 153 throw new BaseException("Unexpected number of unused item keys: " + 154 numDeleted + "; expected " + expected); 155 } 156 write("--Delete unused project keys OK (" + expected + ")"); 151 157 } 152 158 catch (Throwable ex)
Note: See TracChangeset
for help on using the changeset viewer.