4,561,056 th visitor since 2017.2.1 ( Today : 5803 )
Programming
No. 545
Name. swindler
Subject. Reloading may corrupt the apache commons configuration
Main Cate. Java
Sub Cate.
Date. 2009-01-22 13:37
Hit. 3518 (211.43.206.101)
File.




















Commons Configuration

Reloading may corrupt the configuration

Created: 14/Sep/05 11:26 AM   Updated: 02/Jan/09 08:49 AM
Component/s: File reloading
Affects Version/s: 1.1
Fix Version/s: 1.7










Time Tracking:



Not Specified






Bugzilla Id: http://issues.apache.org/bugzilla/show_bug.cgi?id=36652








 Description  « Hide





Current reloading process clears current properties and load updated values from
resource reader. If an IO error occurs (or invalid format), the configuration
gets corrupted and the application becomes unstable.

It may be better for hot-reload to put loaded values into a temporary Properties
and replace previous values only when reloading is successful.


It may also allow to use a 'currentlty-reloading' flag in the synchronized
'reload' block to avoid blocking threads during a reload (they could access
safelly the 'old' properties until reload is finished)

















 All   Comments   Work Log   Change History   Subversion Commits   FishEye      Sort Order: Ascending order - Click to sort in descending order





Emmanuel Bourg - 14/Sep/05 12:02 PM

This issue has been on the todo list for quite some time. It could be quickly
fixed by changing the reload() method in AbstractFileConfiguration, it may look
like this :

public void reload()
{
synchronized (reloadLock)
{
if (noReload == 0 && strategy.reloadingRequired())
{
// save the properties
Map previousProperties = new LinkedMap(store);


try

{ clear(); load(); // notify the strategy strategy.reloadingPerformed(); }

catch (Exception e)

{ e.printStackTrace(); // rollback the changes store = previousProperties; }

}
}
}


I'm not sure it's the best way to rollback the changes though, copying the
properties seems expensive. Any idea ? Should we add a safeReload flag to
enable/disable this feature ?









Emmanuel Bourg - 13/Apr/07 04:10 PM

The copy of the store can be avoided by keeping a reference to the previous store and creating a new empty store before loading the file :

Map previousStore = store;
store = new LinkedMap();


However this will only work for the "flat" configurations like PropertiesConfiguration and INIConfiguration, the hierarchical configurations like XMLConfiguration don't use the Map in BaseConfiguration to store the properties.




[바로가기 링크] : http://coolx.net/cboard/develop/545


Name
Password
Comment
Copyright © 1999-2017, swindler. All rights reserved. 367,611 visitor ( 1999.1.8-2004.5.26 ), 2,405,771 ( -2017.01.31)

  2HLAB   2HLAB_Blog   RedToolBox   Omil   Omil_Blog