public void update ( StoreDefinition storeDef ) { if ( ! useOneEnvPerStore ) throw new VoldemortException ( "Memory foot print can be set only when using different environments per store" ) ; String storeName = storeDef . getName ( ) ; Environment environment = environments . get ( storeName ) ; // change reservation amount of reserved store if ( ! unreservedStores . contains ( environment ) && storeDef . hasMemoryFootprint ( ) ) { EnvironmentMutableConfig mConfig = environment . getMutableConfig ( ) ; long currentCacheSize = mConfig . getCacheSize ( ) ; long newCacheSize = storeDef . getMemoryFootprintMB ( ) * ByteUtils . BYTES_PER_MB ; if ( currentCacheSize != newCacheSize ) { long newReservedCacheSize = this . reservedCacheSize - currentCacheSize + newCacheSize ; // check that we leave a 'minimum' shared cache if ( ( voldemortConfig . getBdbCacheSize ( ) - newReservedCacheSize ) < voldemortConfig . getBdbMinimumSharedCache ( ) ) { throw new StorageInitializationException ( "Reservation of " + storeDef . getMemoryFootprintMB ( ) + " MB for store " + storeName + " violates minimum shared cache size of " + voldemortConfig . getBdbMinimumSharedCache ( ) ) ; } this . reservedCacheSize = newReservedCacheSize ; adjustCacheSizes ( ) ; mConfig . setCacheSize ( newCacheSize ) ; environment . setMutableConfig ( mConfig ) ; logger . info ( "Setting private cache for store " + storeDef . getName ( ) + " to " + newCacheSize ) ; } } else { // we cannot support changing a reserved store to unreserved or vice // versa since the sharedCache param is not mutable throw new VoldemortException ( "Cannot switch between shared and private cache dynamically" ) ; } }
Detect what has changed in the store definition and rewire BDB environments accordingly .