Produced by Araxis Merge on 12/5/2017 12:06:42 PM Central Standard Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCache\main\src\java\gov\va\med\imaging\storage\cache\impl\eviction | StorageThresholdEvictionStrategy.java | Mon Dec 4 21:35:30 2017 UTC |
| 2 | IV-eHMP_CIF.zip\IMAG_Source\VISA\Java\ImagingCache\main\src\java\gov\va\med\imaging\storage\cache\impl\eviction | StorageThresholdEvictionStrategy.java | Mon Dec 4 22:01:26 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 4 | 1052 |
| Changed | 3 | 6 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
| 1 | /** | |
| 2 | * | |
| 3 | */ | |
| 4 | package go v.va.med.i maging.sto rage.cache .impl.evic tion; | |
| 5 | ||
| 6 | import gov .va.med.im aging.stor age.cache. *; | |
| 7 | import gov .va.med.im aging.stor age.cache. exceptions .CacheExce ption; | |
| 8 | import gov .va.med.im aging.stor age.cache. impl.Group EvictionCa ndidateVis itor; | |
| 9 | import gov .va.med.im aging.stor age.cache. impl.Group Path; | |
| 10 | import gov .va.med.im aging.stor age.cache. impl.Targe tSizeGroup PathSet; | |
| 11 | ||
| 12 | import jav a.text.Dat eFormat; | |
| 13 | import jav a.util.*; | |
| 14 | import jav a.util.con current.*; | |
| 15 | ||
| 16 | import org .apache.lo gging.log4 j.LogManag er; | |
| 17 | import org .apache.lo gging.log4 j.Logger; | |
| 18 | ||
| 19 | /** | |
| 20 | * An evic tion strat egy realiz ation that uses a mi nimum free space and /or maximu m used spa ce | |
| 21 | * to dete rmine when to evict groups. | |
| 22 | * | |
| 23 | * This cl ass will e vict group s so that the total of the use d spaces i s the less er of | |
| 24 | * the max UsedSpaceT hreshold - minFreeSp aceThresho ld or the total | |
| 25 | * availab le space - minFreeSp aceThresho ld. | |
| 26 | * If eith er thresho ld is exce eded then this evict ion strate gy will at tempt to e vict | |
| 27 | * groups such that the result ing total size will be near th e targetFr eeSpaceThr eshold. | |
| 28 | * | |
| 29 | * The par ameters ar e restrict ed in valu e as follo ws: | |
| 30 | * 1.) min FreeSpaceT hreshold < = targetFr eeSpaceThr eshold | |
| 31 | * 2.) max UsedSpaceT hreshold < = availabl e space | |
| 32 | * (de termined a t runtime, the value of maxUse dSpaceThre shold is r educed to available space if g reater) | |
| 33 | * | |
| 34 | * This ev iction str ategy runs periodica lly, on ea ch iterati on it: | |
| 35 | * 1.) For each regi on | |
| 36 | * Che cks if the free spac e has fall en below a minimum | |
| 37 | * 1b.) If the free space has fallen bel ow a minim um or then | |
| 38 | * St arts a tas k on a thr ead pool ( a Region S weep Task) | |
| 39 | * If the maxim um used sp ace proper ty is grea ter than 0 then the collective size | |
| 40 | * of the manag ed regions is determ ined using the same thread | |
| 41 | * 2.) Eac h Region S weep Task creates a set of evi ction cand idates tha t are the LRU groups | |
| 42 | * who se collect ive size f alls just below the target siz e. | |
| 43 | * 3.) Sta rts, yet a nother, th read (the Evictor Ta sk) that a ggregates the set of eviction candidates | |
| 44 | * fro m each reg ion such t hat they a re collect ively the LRU of all the regio ns (whose total size falls | |
| 45 | * jus t below th e target s ize) and t hen remove s the grou ps in the (collectiv e) evictio n candidat e set. | |
| 46 | * | |
| 47 | * NOTE: t here is a problem he re. This will work fine as lo ng as all of the Reg ions that are manage d | |
| 48 | * by this EvictionS trategy ar e persiste d on the s ame device . | |
| 49 | * It is p ermissable to have m ultiple in stances of this Evic tionStrate gy, one fo r each dev ice, then | |
| 50 | * each Re gion on th at device can use th e same ins tance of t his evicti on strateg y. | |
| 51 | * | |
| 52 | * @author
|
|
| 53 | * | |
| 54 | */ | |
| 55 | public cla ss Storage ThresholdE victionStr ategy | |
| 56 | extends Pe riodicSwee pEvictionS trategy | |
| 57 | implements EvictionS trategy, S torageThre sholdEvict ionStrateg yMBean | |
| 58 | { | |
| 59 | pu blic final static lo ng minimum Delay = 0; // imm ediate | |
| 60 | pu blic final static lo ng minimum Interval = 1000; // 1 s econd, whi ch is real ly short e xcept for transient caches | |
| 61 | ||
| 62 | pu blic final static St ring delay PropertyKe y = "delay "; | |
| 63 | pu blic final static St ring inter valPropert yKey = "in terval"; | |
| 64 | pu blic final static St ring minFr eeSpacePro pertyKey = "minimumF reeSpace"; | |
| 65 | pu blic final static St ring targe tFreeSpace PropertyKe y = "targe tFreeSpace "; | |
| 66 | pu blic final static St ring maxUs edSpacePro pertyKey = "maximumU sedSpace"; | |
| 67 | ||
| 68 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== === | |
| 69 | // | |
| 70 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== === | |
| 71 | ||
| 72 | /* * | |
| 73 | * Required Factory Me thod | |
| 74 | * / | |
| 75 | st atic Stora geThreshol dEvictionS trategy cr eate(Prope rties prop , Eviction Timer time r) | |
| 76 | th rows Cache Exception | |
| 77 | { | |
| 78 | Stri ng name = (String)pr op.get(Sim pleEvictio nStrategy. nameProper tyKey); | |
| 79 | bool ean initia lized = (( Boolean)pr op.get(Sim pleEvictio nStrategy. initialize dPropertyK ey)).boole anValue(); | |
| 80 | long delay = ( (Long)prop .get(delay PropertyKe y)).longVa lue(); | |
| 81 | long interval = ((Long)p rop.get(in tervalProp ertyKey)). longValue( ); | |
| 82 | long minFreeSp aceThresho ld = prop. get(minFre eSpaceProp ertyKey) = = null ? | |
| 83 | -1L : | |
| 84 | ((Long )prop.get( minFreeSpa ceProperty Key)).long Value(); | |
| 85 | long targetFre eSpaceThre shold = pr op.get(tar getFreeSpa ceProperty Key) == nu ll ? | |
| 86 | -1L : | |
| 87 | ((Long )prop.get( targetFree SpacePrope rtyKey)).l ongValue() ; | |
| 88 | long maxUsedSp aceThresho ld = prop. get(maxUse dSpaceProp ertyKey) = = null ? | |
| 89 | -1 : | |
| 90 | ((Long )prop.get( maxUsedSpa ceProperty Key)).long Value(); | |
| 91 | ||
| 92 | retu rn new Sto rageThresh oldEvictio nStrategy( | |
| 93 | name, in itialized, timer, | |
| 94 | minFreeS paceThresh old, targe tFreeSpace Threshold, maxUsedSp aceThresho ld, | |
| 95 | delay, i nterval ); | |
| 96 | } | |
| 97 | ||
| 98 | /* * | |
| 99 | * @param me mento | |
| 100 | * @param ti mer | |
| 101 | * @return | |
| 102 | * / | |
| 103 | st atic Evict ionStrateg y create(S torageThre sholdEvict ionStrateg yMemento m emento, Ev ictionTime r timer) | |
| 104 | th rows Cache Exception | |
| 105 | { | |
| 106 | retu rn new Sto rageThresh oldEvictio nStrategy( timer, mem ento); | |
| 107 | } | |
| 108 | ||
| 109 | /* * | |
| 110 | * | |
| 111 | * @param na me | |
| 112 | * @param in itialized | |
| 113 | * @param ev ictionTime r | |
| 114 | * @param mi nFreeSpace Threshold | |
| 115 | * @param ta rgetFreeSp aceThresho ld | |
| 116 | * @param ma xUsedSpace Threshold | |
| 117 | * @param de lay | |
| 118 | * @param in terval | |
| 119 | * @return | |
| 120 | * @throws C acheExcept ion | |
| 121 | * / | |
| 122 | st atic Evict ionStrateg y create( | |
| 123 | Stri ng name, b oolean ini tialized, | |
| 124 | Evic tionTimer evictionTi mer, | |
| 125 | long minFreeSp aceThresho ld, long t argetFreeS paceThresh old, long maxUsedSpa ceThreshol d, | |
| 126 | long delay, lo ng interva l) | |
| 127 | th rows Cache Exception | |
| 128 | { | |
| 129 | retu rn new Sto rageThresh oldEvictio nStrategy( | |
| 130 | name, in itialized, | |
| 131 | eviction Timer, | |
| 132 | minFreeS paceThresh old, targe tFreeSpace Threshold, maxUsedSp aceThresho ld, | |
| 133 | delay, i nterval); | |
| 134 | } | |
| 135 | ||
| 136 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== === | |
| 137 | // | |
| 138 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== === | |
| 139 | ||
| 140 | pr ivate fina l long del ay; | |
| 141 | pr ivate fina l long int erval; | |
| 142 | ||
| 143 | pr ivate long minFreeSp aceThresho ld; | |
| 144 | pr ivate long targetFre eSpaceThre shold; | |
| 145 | pr ivate long maxUsedSp aceThresho ld; | |
| 146 | ||
| 147 | pr ivate Swee pStatistic s lastSwee pStatistic s = new Sw eepStatist ics(System .currentTi meMillis() , 0); | |
| 148 | ||
| 149 | pr ivate Logg er logger = LogManag er.getLogg er(this.ge tClass()); | |
| 150 | ||
| 151 | pr ivate Stor ageThresho ldEviction Strategy( | |
| 152 | Evicti onTimer ev ictionTime r, | |
| 153 | Storag eThreshold EvictionSt rategyMeme nto mement o | |
| 154 | ) | |
| 155 | th rows Cache Exception | |
| 156 | { | |
| 157 | this ( | |
| 158 | mement o.getName( ), | |
| 159 | mement o.isInitia lized(), | |
| 160 | evicti onTimer, | |
| 161 | mement o.getMinFr eeSpaceThr eshold(), | |
| 162 | mement o.getTarge tFreeSpace Threshold( ), | |
| 163 | mement o.getMaxUs edSpaceThr eshold(), | |
| 164 | mement o.getDelay (), | |
| 165 | mement o.getInter val() | |
| 166 | ); | |
| 167 | } | |
| 168 | ||
| 169 | pr ivate Stor ageThresho ldEviction Strategy( | |
| 170 | String name, | |
| 171 | boolea n initiali zed, | |
| 172 | Evicti onTimer ev ictionTime r, | |
| 173 | long m inFreeSpac eThreshold , | |
| 174 | long t argetFreeS paceThresh old, | |
| 175 | long m axUsedSpac eThreshold , | |
| 176 | long d elay, | |
| 177 | long i nterval) | |
| 178 | th rows Cache Exception | |
| 179 | { | |
| 180 | supe r(name, ev ictionTime r); | |
| 181 | ||
| 182 | // i t looks li ke we're s etting min FreeSpaceT hreshold t wice in th e followin g code | |
| 183 | // a nd we are but ... | |
| 184 | // t he call to setMinFre eSpaceThre shold will invoke bo unds check ing that i s not done by simply | |
| 185 | // s etting the field. s etTargetFr eeSpaceThr eshold rel ies on the value of | |
| 186 | // m inFreeSpac eThreshold , so that must be se t before c alling set TargetFree SpaceThres hold. | |
| 187 | this .minFreeSp aceThresho ld = minFr eeSpaceThr eshold; | |
| 188 | setT argetFreeS paceThresh old(target FreeSpaceT hreshold); | |
| 189 | setM inFreeSpac eThreshold (minFreeSp aceThresho ld); | |
| 190 | setM axUsedSpac eThreshold (maxUsedSp aceThresho ld); | |
| 191 | ||
| 192 | this .delay = M ath.max(mi nimumDelay , delay); | |
| 193 | this .interval = Math.max (minimumIn terval, in terval); | |
| 194 | setI nitialized (initializ ed); | |
| 195 | } | |
| 196 | ||
| 197 | /* (non-Java doc) | |
| 198 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.evicti on.Storage ThresholdE victionStr ategyMBean #getDelay( ) | |
| 199 | * / | |
| 200 | pu blic long getDelay() | |
| 201 | { | |
| 202 | retu rn this.de lay; | |
| 203 | } | |
| 204 | ||
| 205 | /* (non-Java doc) | |
| 206 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.evicti on.Storage ThresholdE victionStr ategyMBean #getInterv al() | |
| 207 | * / | |
| 208 | pu blic long getInterva l() | |
| 209 | { | |
| 210 | retu rn this.in terval; | |
| 211 | } | |
| 212 | ||
| 213 | /* (non-Java doc) | |
| 214 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.evicti on.Storage ThresholdE victionStr ategyMBean #getMinFre eSpaceThre shold() | |
| 215 | * / | |
| 216 | pu blic long getMinFree SpaceThres hold() | |
| 217 | { | |
| 218 | retu rn this.mi nFreeSpace Threshold; | |
| 219 | } | |
| 220 | ||
| 221 | /* (non-Java doc) | |
| 222 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.evicti on.Storage ThresholdE victionStr ategyMBean #setMinFre eSpaceThre shold(long ) | |
| 223 | * / | |
| 224 | pu blic void setMinFree SpaceThres hold(long minFreeSpa ceThreshol d) | |
| 225 | { | |
| 226 | // m inFreeSpac eThreshold must be p ositive | |
| 227 | minF reeSpaceTh reshold = Math.max(m inFreeSpac eThreshold , 0L); | |
| 228 | // m inFreeSpac eThreshold must be l ess than o r equal to the targe tFreeSpace Threshold | |
| 229 | minF reeSpaceTh reshold = Math.min(m inFreeSpac eThreshold , getTarge tFreeSpace Threshold( )); | |
| 230 | ||
| 231 | this .minFreeSp aceThresho ld = minFr eeSpaceThr eshold; | |
| 232 | logg er.info("S etting min imum free space thre shold to " + this.mi nFreeSpace Threshold) ; | |
| 233 | } | |
| 234 | ||
| 235 | /* (non-Java doc) | |
| 236 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.evicti on.Storage ThresholdE victionStr ategyMBean #getTarget FreeSpaceT hreshold() | |
| 237 | * / | |
| 238 | pu blic long getTargetF reeSpaceTh reshold() | |
| 239 | { | |
| 240 | retu rn this.ta rgetFreeSp aceThresho ld; | |
| 241 | } | |
| 242 | ||
| 243 | pu blic long getMaxUsed SpaceThres hold() | |
| 244 | { | |
| 245 | retu rn this.ma xUsedSpace Threshold; | |
| 246 | } | |
| 247 | ||
| 248 | pu blic void setMaxUsed SpaceThres hold(long maxUsedSpa ceThreshol d) | |
| 249 | { | |
| 250 | this .maxUsedSp aceThresho ld = maxUs edSpaceThr eshold; | |
| 251 | } | |
| 252 | ||
| 253 | /* (non-Java doc) | |
| 254 | * @see gov. va.med.ima ging.stora ge.cache.i mpl.evicti on.Storage ThresholdE victionStr ategyMBean #setTarget FreeSpaceT hreshold(l ong) | |
| 255 | * / | |
| 256 | pu blic void setTargetF reeSpaceTh reshold(lo ng targetF reeSpaceTh reshold) | |
| 257 | { | |
| 258 | // t argetFreeS paceThresh old must b e positive | |
| 259 | targ etFreeSpac eThreshold = Math.ma x(targetFr eeSpaceThr eshold, 0L ); | |
| 260 | // t argetFreeS paceThresh old must b e greater than or eq ual to the minFreeSp aceThresho ld | |
| 261 | targ etFreeSpac eThreshold = Math.ma x(targetFr eeSpaceThr eshold, ge tMinFreeSp aceThresho ld()); | |
| 262 | ||
| 263 | this .targetFre eSpaceThre shold = ta rgetFreeSp aceThresho ld; | |
| 264 | logg er.info("S etting tar get free s pace thres hold to " + this.tar getFreeSpa ceThreshol d); | |
| 265 | } | |
| 266 | ||
| 267 | pu blic Stora geThreshol dEvictionS trategyMem ento getMe mento() | |
| 268 | { | |
| 269 | retu rn new Sto rageThresh oldEvictio nStrategyM emento( | |
| 270 | getNam e(), isIni tialized() , | |
| 271 | getMin FreeSpaceT hreshold() , getTarge tFreeSpace Threshold( ), getMaxU sedSpaceTh reshold(), | |
| 272 | getDel ay(), getI nterval() | |
| 273 | ); | |
| 274 | } | |
| 275 | ||
| 276 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 277 | // The actua l sweep im plementati on, called periodica lly | |
| 278 | // ========= ========== ========== ========== ========== ========== ========== ========== ========== ========== ========== ====== | |
| 279 | @O verride | |
| 280 | pu blic void sweep() | |
| 281 | { | |
| 282 | // a list, one element p er region, each elem ent consis ting of a list of gr oups to ev ict. | |
| 283 | // b uilding th e list of groups is done by wo rker threa ds, one pe r region | |
| 284 | List <Future<Ta rgetSizeGr oupPathSet >> regionS weepFuture s = new Ar rayList<Fu ture<Targe tSizeGroup PathSet>>( ); | |
| 285 | long freeSpace = -1; | |
| 286 | Date Format df = DateForm at.getDate TimeInstan ce(); | |
| 287 | long totalMana gedSize = 0L; | |
| 288 | ||
| 289 | logg er.info( " Beginning storage th reshold ev iction swe ep at " + df.format( new Date() ) ); | |
| 290 | ||
| 291 | Set< Region> re gions = ge tRegions() ; | |
| 292 | ||
| 293 | if(r egions.isE mpty()) | |
| 294 | return ; | |
| 295 | ||
| 296 | Regi on firstRe gion = nul l; | |
| 297 | // i f maxUsedS paceThresh old is > 0 then that will be u sed as the maximum | |
| 298 | // e lse a log message is generated and the e viction st ops | |
| 299 | // T o get the maximum us ed space r equires a pass throu gh the cac he, and | |
| 300 | // p erhaps a p ass throug h the file system. | |
| 301 | // T he freeSpa ce is eith er the act ual free s pace on th e device o r | |
| 302 | // t he maxUsed SpaceThres hold - tot alManagedS ize | |
| 303 | if(g etMaxUsedS paceThresh old() > 0) | |
| 304 | { | |
| 305 | for(Re gion regio n: getRegi ons()) | |
| 306 | { | |
| 307 | firstReg ion = (fir stRegion = = null ? r egion : fi rstRegion) ; | |
| 308 | totalMan agedSize + = region.g etUsedSpac e(); | |
| 309 | } | |
| 310 | // how much free space foe s the regi on's persi stent stor age think it has ava ilable | |
| 311 | freeSp ace = firs tRegion.ge tFreeSpace (); | |
| 312 | ||
| 313 | // get the minim um of the persistent persisten ce device free space or the | |
| 314 | // "de fined" max imum space minus the actual us ed space. | |
| 315 | // In other word s the less er of what we've def ined as th e minimum free space or the re al device free space . | |
| 316 | freeSp ace = Math .min(freeS pace, getM axUsedSpac eThreshold () - total ManagedSiz e); | |
| 317 | } | |
| 318 | else | |
| 319 | { | |
| 320 | // get the first region li nked to th is evictio n strategy | |
| 321 | firstR egion = ge tRegions() .iterator( ).next(); | |
| 322 | ||
| 323 | // thi s may or m ay not wor k because not all fi le systems support i t. | |
| 324 | // reg ions over file syste ms that do not suppo rt getting free spac e | |
| 325 | // MUS T report t he value a s 0 | |
| 326 | freeSp ace = firs tRegion.ge tFreeSpace (); | |
| 327 | } | |
| 328 | logR egionStati stics(firs tRegion, f reeSpace); | |
| 329 | ||
| 330 | // n ote that f reeSpace c ould be a negative n umber | |
| 331 | // i f it is pr ecisely 0L and the m ax used sp ace is not specified | |
| 332 | // t hen we can not contin ue | |
| 333 | if(f reeSpace ! = 0L && ge tMaxUsedSp aceThresho ld() > 0) | |
| 334 | { | |
| 335 | // for each Regi on | |
| 336 | for(Re gion regio n: getRegi ons()) | |
| 337 | { | |
| 338 | // if th e free spa ce is less than the minimum th en start t he region sweeps | |
| 339 | // else don't | |
| 340 | // NOTE, it is exp ected that the regio n sweeps c ould be ex pensive so running | |
| 341 | // them should be minimized | |
| 342 | if( free Space < ge tMinFreeSp aceThresho ld() ) | |
| 343 | { | |
| 344 | // each re gion is to ld how man y bytes we want to f ree up tot al | |
| 345 | // the can didates th at it prov ides are a ll tacked onto a "ma ster" list | |
| 346 | // which i s used to determine what actua lly gets e victed | |
| 347 | RegionSwee pTask task = new Reg ionSweepTa sk(region, getTarget FreeSpaceT hreshold() - freeSpa ce); | |
| 348 | Future<Tar getSizeGro upPathSet> future = getExecuto r().submit (task); | |
| 349 | ||
| 350 | regionSwee pFutures.a dd(future) ; | |
| 351 | } | |
| 352 | } | |
| 353 | } | |
| 354 | else | |
| 355 | logger .warn( | |
| 356 | "Managed regions d o not supp ort free s pace repor ting and n o maximum size was s pecified. " + | |
| 357 | " The ev iction str ategy is ' " + this.g etClass(). getSimpleN ame() + "' , which re quires it. No evict ion will o ccur in th ese region s."); | |
| 358 | ||
| 359 | // S tart the t hread to d o the actu al evictio ns. | |
| 360 | // T his thread will wait until all of the Fu tures have results a vailable, which is t he | |
| 361 | // s ame as say ing when t he region sweep task s are comp lete, then it will e vict acros s | |
| 362 | // a ll of the regions su fficient t o free up the target space | |
| 363 | getE xecutor(). execute( n ew Evictor Task(regio nSweepFutu res, getTa rgetFreeSp aceThresho ld() - fre eSpace) ); | |
| 364 | ||
| 365 | retu rn; | |
| 366 | } | |
| 367 | ||
| 368 | pr ivate void logRegion Statistics (Region re gion, long freeSpace ) | |
| 369 | { | |
| 370 | logg er.info( | |
| 371 | "Regio n '" + reg ion.getNam e() + | |
| 372 | "' has " + freeS pace + | |
| 373 | " byte s free, ma ximum used threshold is " + ge tMaxUsedSp aceThresho ld() + | |
| 374 | " byte s free, mi nimum thre shold is " + getMinF reeSpaceTh reshold() + | |
| 375 | " byte s free, ta rget thres hold is " + getTarge tFreeSpace Threshold( ) + | |
| 376 | " byte s free." | |
| 377 | ); | |
| 378 | } | |
| 379 | ||
| 380 | @O verride | |
| 381 | pu blic Sweep Statistics getLastSw eepStatist ics() | |
| 382 | { | |
| 383 | retu rn lastSwe epStatisti cs; | |
| 384 | } | |
| 385 | ||
| 386 | vo id setLast SweepStati stics(Swee pStatistic s sweepSta tistics) | |
| 387 | { | |
| 388 | this .lastSweep Statistics = sweepSt atistics; | |
| 389 | } | |
| 390 | ||
| 391 | @O verride | |
| 392 | pu blic Stora geThreshol dEvictionS trategyMem ento creat eMemento() | |
| 393 | { | |
| 394 | Stor ageThresho ldEviction StrategyMe mento meme nto = new StorageThr esholdEvic tionStrate gyMemento( ); | |
| 395 | ||
| 396 | meme nto.setIni tialized(i sInitializ ed()); | |
| 397 | meme nto.setNam e(getName( )); | |
| 398 | meme nto.setDel ay(getDela y()); | |
| 399 | meme nto.setInt erval(getI nterval()) ; | |
| 400 | meme nto.setMin FreeSpaceT hreshold(g etMinFreeS paceThresh old()); | |
| 401 | meme nto.setTar getFreeSpa ceThreshol d(getTarge tFreeSpace Threshold( )); | |
| 402 | meme nto.setMax UsedSpaceT hreshold(g etMaxUsedS paceThresh old()); | |
| 403 | ||
| 404 | retu rn memento ; | |
| 405 | } | |
| 406 | ||
| 407 | ||
| 408 | /* * | |
| 409 | * The worke r task tha t collects the group s that may be evicte d in one r egion. | |
| 410 | * | |
| 411 | * @author
|
|
| 412 | * | |
| 413 | * / | |
| 414 | cl ass Region SweepTask | |
| 415 | im plements C allable<Ta rgetSizeGr oupPathSet > | |
| 416 | { | |
| 417 | priv ate Region region; | |
| 418 | priv ate long e victSize; | |
| 419 | ||
| 420 | Regi onSweepTas k(Region r egion, lon g evictSiz e) | |
| 421 | { | |
| 422 | this.r egion = re gion; | |
| 423 | this.e victSize = evictSize ; | |
| 424 | } | |
| 425 | ||
| 426 | /** | |
| 427 | * @ see java.u til.concur rent.Calla ble#call() | |
| 428 | */ | |
| 429 | publ ic TargetS izeGroupPa thSet call () | |
| 430 | thro ws Excepti on | |
| 431 | { | |
| 432 | // mai ntains a S et of evic tion candi dates in o ldest to n ewest orde r | |
| 433 | // and whose tot al size is less than the evict Size | |
| 434 | Target SizeGroupP athSet evi ctionCandi dates = ne w TargetSi zeGroupPat hSet(evict Size); | |
| 435 | logger .info( | |
| 436 | "Region '" + regio n.getName( ) + | |
| 437 | " bytes free, mini mum thresh old is " + getMinFre eSpaceThre shold() + | |
| 438 | " bytes free, targ et thresho ld is " + getTargetF reeSpaceTh reshold() + " bytes free." | |
| 439 | ); | |
| 440 | ||
| 441 | // spe cial case if the Reg ion implem entation d oes not re port free space | |
| 442 | if(evi ctSize > 0 ) | |
| 443 | { | |
| 444 | // scan leaf nodes first !!! | |
| 445 | // the g roup visit or does no t provide ancestry i nformation | |
| 446 | // DO NO T SCAN ANY THING BUT LEAF NODES , otherwis e the calc ulated siz es will be incorrect | |
| 447 | TargetSi zeGroupPat hSet regio nEvictionC andidates = | |
| 448 | GroupEvict ionCandida teVisitor. createAndR un(region, false, tr ue, evictS ize); | |
| 449 | eviction Candidates .addAll( r egionEvict ionCandida tes ); | |
| 450 | } | |
| 451 | ||
| 452 | return evictionC andidates; | |
| 453 | } | |
| 454 | } | |
| 455 | ||
| 456 | /* * | |
| 457 | * A task th at | |
| 458 | * 1.) Colle cts the re sult from all the re gions and combines t hem | |
| 459 | * into a single l ist of gro ups to be evicted. The collec tive | |
| 460 | * size of the gro ups on the list will be no big ger than t he target | |
| 461 | * size. | |
| 462 | * 2.) | |
| 463 | * | |
| 464 | * @author
|
|
| 465 | * / | |
| 466 | cl ass Evicto rTask | |
| 467 | im plements R unnable | |
| 468 | { | |
| 469 | priv ate List<F uture<Targ etSizeGrou pPathSet>> regionTas kFutures; | |
| 470 | priv ate Target SizeGroupP athSet evi ctableGrou ps; | |
| 471 | ||
| 472 | Evic torTask(Li st<Future< TargetSize GroupPathS et>> regio nTaskFutur es, long s ize) | |
| 473 | { | |
| 474 | this.r egionTaskF utures = r egionTaskF utures; | |
| 475 | evicta bleGroups = new Targ etSizeGrou pPathSet(s ize); | |
| 476 | } | |
| 477 | ||
| 478 | /** | |
| 479 | * | |
| 480 | */ | |
| 481 | publ ic void ru n() | |
| 482 | { | |
| 483 | long s tart = Sys tem.curren tTimeMilli s(); | |
| 484 | int gr oupsEvicte d = 0; | |
| 485 | ||
| 486 | for(Fu ture<Targe tSizeGroup PathSet> f uture : th is.regionT askFutures ) | |
| 487 | { | |
| 488 | try | |
| 489 | { | |
| 490 | // get() - Waits if necessary for the co mputation to complet e, and the n retrieve s its resu lt. | |
| 491 | TargetSize GroupPathS et deletab leGroupPat hs = futur e.get(); | |
| 492 | evictableG roups.addA ll( deleta bleGroupPa ths ); | |
| 493 | } | |
| 494 | catch (I nterrupted Exception x) | |
| 495 | { | |
| 496 | logger.war n("Interru ptedExcept ion caught in region eviction thread whi le getting result.", x); | |
| 497 | } | |
| 498 | catch (E xecutionEx ception x) | |
| 499 | { | |
| 500 | logger.war n("Executi onExceptio n caught i n region e viction th read while getting r esult. At least one region has not contr ibuted to evictable list.", x) ; | |
| 501 | } | |
| 502 | } | |
| 503 | ||
| 504 | logger .info("The re are " + evictable Groups.siz e() + " ca che entrie s to evict ."); | |
| 505 | if(evi ctableGrou ps.size() > 0) | |
| 506 | { | |
| 507 | for( Gro upPath gro upPath:evi ctableGrou ps ) | |
| 508 | { | |
| 509 | try | |
| 510 | { | |
| 511 | Gr oup parent = groupPa th.getRegi on().getGr oup(groupP ath.getPat hName()); | |
| 512 | if (parent == null) | |
| 513 | grou pPath.getR egion().re moveChildG roup(group Path.getGr oup()); | |
| 514 | el se | |
| 515 | pare nt.removeC hildGroup( groupPath. getGroup() ); | |
| 516 | ||
| 517 | ++ groupsEvic ted; | |
| 518 | } | |
| 519 | catch (Cac heExceptio n x) | |
| 520 | { | |
| 521 | lo gger.error ("Unable t o remove g roup '" + groupPath. getGroup() .getName() + "'", x) ; | |
| 522 | } | |
| 523 | } | |
| 524 | } | |
| 525 | ||
| 526 | setLas tSweepStat istics(new SweepStat istics(sta rt, groups Evicted) ) ; | |
| 527 | } | |
| 528 | } | |
| 529 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.