Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 259981

Summary: Numerous outdated bundledata/configuration files created in equinox stack
Product: [Eclipse Project] Equinox Reporter: Eric Hsu <mfhsu>
Component: FrameworkAssignee: Thomas Watson <tjwatson>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: liukl, rogalski, tjwatson, tomhsu, xhhsld
Version: 3.4Keywords: helpwanted
Target Milestone: Juno M1   
Hardware: PC   
OS: All   
Whiteboard:
Bug Depends on:    
Bug Blocks: 353880    
Attachments:
Description Flags
patch
none
this is the resulting modified StorageManager.java that I had working.
none
diff file to change from original to my version
tjwatson: iplog+
updated patch and test
none
updated patch and tests none

Description Eric Hsu CLA 2009-01-05 12:57:30 EST
Hi..
We've found there will be numerous bundledata created to occupy storage memory.
It's a critical problem in platforms with small storage . For example : handheld device.
Those files look like get created if we are constantly installing new bundles 
or if we make other persistent changes to the framework, such as start/stop bundles.
There are some properties(osgi.embedded.cleanupOnOpen=true and osgi.clean=true) to clean it in stack restarting. 
However, restarting runtime is required and not good for long running equniox stack. The files should be cleaned up during long running stack in which start and shutdown are rare occurrence. Could equinox provide a solution against it?
Thanks a lot.
Comment 1 Thomas Watson CLA 2009-04-20 17:38:18 EDT
Do you think you could work on a patch?  Otherwise this will not make 3.5.
Comment 2 Eric Hsu CLA 2009-04-21 12:17:08 EDT
Hi...Thomas
Unfortunately, we do not have the resource nor expertise to address this problem. What's your plan to fix this issue if it's not in 3.5? Thanks
Comment 3 Thomas Watson CLA 2009-04-21 13:57:05 EDT
Created attachment 132641 [details]
patch

Without any help the solution is going to very minimal.  This patch simply cleans up the files on every save.  It does this only if the existing configuration property osgi.embedded.cleanupOnOpen is set to true.

I will consider releasing this fix, but only after I get confirmation back that this actually solves your issues.
Comment 4 tomhsu CLA 2011-06-10 18:12:43 EDT
We are observing similar issues with release jars:
org.eclipse.osgi_3.4.2.R34x_v20080826-1230.jar

We are seeing huge number of files such as:
.bundledata.YYY
.state.XXX
.lazy.ZZZ
in directory <CONFIG>/org.eclipse.osgi/ folder.

We are not bouncing the OSGi framework either.

Would this patch work to address the growth in that folder?

If this is a separate problem. Please let me know.
Comment 5 Thomas Watson CLA 2011-06-13 13:48:03 EDT
(In reply to comment #4)
> We are observing similar issues with release jars:
> org.eclipse.osgi_3.4.2.R34x_v20080826-1230.jar
> 
> We are seeing huge number of files such as:
> .bundledata.YYY
> .state.XXX
> .lazy.ZZZ
> in directory <CONFIG>/org.eclipse.osgi/ folder.
> 
> We are not bouncing the OSGi framework either.
> 
> Would this patch work to address the growth in that folder?
> 
> If this is a separate problem. Please let me know.

This could be a similar issue, but I am concerned by the statement "We are seeing huge nubmer of files such as:".  How many is huge?  These files should only be written if the state of the set of bundles installed in the framework is changing.  Are you doing a lot of continuous operations that install/uninstall/update bundles or even persistently start/stop or set the start-level of the bundles?

Even if you are doing this continuously we should not be writing these files unless a period of 30 seconds has passed with no activity.  So I would not expect huge amounts of these files to appear very quickly.  Any idea how long it takes to get the huge number of files?  Also are you never shutting down the framework?  If you do shutdown the framework how are you doing so?  Upon proper shutdown we should be cleaning up these extra files.

This patch may be able to help but I would like to understand your scenario a bit before determining that this is the right fix for you.
Comment 6 tomhsu CLA 2011-06-13 14:30:31 EDT
We have been running equinox w/o bouncing the JVM for 9 days now. We are seeing the triplet files (.lazy .bundledata and .state) increment from 1 to 1959 now. The du -sh in the <CONFIG>/org.eclipse.osgi directory now stands at 1004MB.

Scenario we are running equinox:
We are using equinox as a server to run custom jobs that conform to a specification on a time schedule. Within an hour, we are running ~500 executions. These executions/jobs are backed from 50 bundles with unique symbolic names. I believe that we install these bundles on the first execution. Subsequent execution of the jobs w/ same symbolic names update the bundle (via bundle.update). For an hour, we should be seeing ~500 bundle.update calls.

Ideally, we are not going to shutdown the server by design.

Thanks,
Tom
Comment 7 Thomas Watson CLA 2011-06-13 23:59:20 EDT
(In reply to comment #6)
> We have been running equinox w/o bouncing the JVM for 9 days now. We are seeing
> the triplet files (.lazy .bundledata and .state) increment from 1 to 1959 now.
> The du -sh in the <CONFIG>/org.eclipse.osgi directory now stands at 1004MB.
> 
> Scenario we are running equinox:
> We are using equinox as a server to run custom jobs that conform to a
> specification on a time schedule. Within an hour, we are running ~500
> executions. These executions/jobs are backed from 50 bundles with unique
> symbolic names. I believe that we install these bundles on the first execution.
> Subsequent execution of the jobs w/ same symbolic names update the bundle (via
> bundle.update). For an hour, we should be seeing ~500 bundle.update calls.
> 
> Ideally, we are not going to shutdown the server by design.
> 
> Thanks,
> Tom

I suspect this patch would be able to help you.  I would be curious if the files get cleaned up when you do shutdown the framework.
Comment 8 tomhsu CLA 2011-06-14 14:56:23 EDT
(In reply to comment #7)
> I suspect this patch would be able to help you.  I would be curious if the
> files get cleaned up when you do shutdown the framework.

I tried the patch. And put in some debug output to let me know if it is making a difference. However, it is not.

I do not see the code calling the cleanup method inside save proposed by the patch. And I still see the files keep getting generated in org.eclipse.osgi:
drwxr-xr-x  5 thsu g900   4096 Jun 14 11:48 ..
drwxr-----  5 thsu g900   4096 Jun 14 11:49 bundles
-rw-r-----  1 thsu g900  16908 Jun 14 11:49 .state.1
-rw-r-----  1 thsu g900 379991 Jun 14 11:49 .lazy.1
-rw-r-----  1 thsu g900  46171 Jun 14 11:49 .bundledata.1
-rw-r-----  1 thsu g900  16908 Jun 14 11:50 .state.2
-rw-r-----  1 thsu g900 379991 Jun 14 11:50 .lazy.2
-rw-r-----  1 thsu g900  46171 Jun 14 11:50 .bundledata.2
-rw-r-----  1 thsu g900  16908 Jun 14 11:51 .state.3
-rw-r-----  1 thsu g900 379991 Jun 14 11:51 .lazy.3
-rw-r-----  1 thsu g900  46171 Jun 14 11:51 .bundledata.3
-rw-r-----  1 thsu g900  16908 Jun 14 11:53 .state.4
drwxr-----  2 thsu g900   4096 Jun 14 11:53 .manager
-rw-r-----  1 thsu g900 379991 Jun 14 11:53 .lazy.4
-rw-r-----  1 thsu g900  46171 Jun 14 11:53 .bundledata.4
.... growing over time

What else can I try to have the system clean up the files lower than .bundledata./.lazy./.state.MAX_NUM?

my config.ini looks like:

#Configuration File
#Fri May 09 14:20:34 EDT 2008
osgi.bundles=org.eclipse.equinox.common@2:start, org.eclipse.update.configurator@3:start, org.eclipse.core.runtime@start
osgi.bundles.defaultStartLevel=4
osgi.instance.area.default=@user.dir/workspace
#osgi.framework=platform:/base/plugins/org.eclipse.osgi
osgi.configuration.cascaded=false
osgi.framework.extensions=com.custom.osgi.adapters
eclipse.noRegistryCache=true
osgi.clean=true
osgi.embedded.cleanupOnOpen=true
osgi.embedded.cleanTempFiles=true

# End of file marker - must be here
eof=eof

Thanks.
Comment 9 tomhsu CLA 2011-06-14 14:57:28 EDT
(In reply to comment #7)
> I suspect this patch would be able to help you.  I would be curious if the
> files get cleaned up when you do shutdown the framework.
The .lazy,bundledata,state do not get cleaned up upon shutdown. It gets cleaned up on restart.
Comment 10 tomhsu CLA 2011-06-16 20:11:38 EDT
After further testing, I finally figured out why the initial patch does not work.

Simply call cleanup() method inside save() again will lead to a 2nd attempt on locking with locker.lock which will fail inside cleanup.

I wrote another cleanupWithLock() for use inside save(). now i see only the highest level of triplet files. the lower generation files are gone.
only see:
.lazy.MAX
.bundledate.MAX
.state.MAX

thanks for the help.
Comment 11 tomhsu CLA 2011-06-16 20:12:46 EDT
(In reply to comment #10)
> After further testing, I finally figured out why the initial patch does not
> work.
> 
> Simply call cleanup() method inside save() again will lead to a 2nd attempt on
> locking with locker.lock which will fail inside cleanup.
> 
> I wrote another cleanupWithLock() for use inside save(). now i see only the
> highest level of triplet files. the lower generation files are gone.
> only see:
> .lazy.MAX
> .bundledate.MAX
> .state.MAX
> 
> thanks for the help.

Actually one more thing. Is this patch available on later releases?
Comment 12 Thomas Watson CLA 2011-06-17 08:39:30 EDT
(In reply to comment #10)
> After further testing, I finally figured out why the initial patch does not
> work.
> 
> Simply call cleanup() method inside save() again will lead to a 2nd attempt on
> locking with locker.lock which will fail inside cleanup.
> 
> I wrote another cleanupWithLock() for use inside save(). now i see only the
> highest level of triplet files. the lower generation files are gone.
> only see:
> .lazy.MAX
> .bundledate.MAX
> .state.MAX
> 
> thanks for the help.

Thanks you!  Could you attach an updated patch with your changes?

(In reply to comment #11)
> Actually one more thing. Is this patch available on later releases?

No, unfortunately I did not get any response from my question in comment 3.

"I will consider releasing this fix, but only after I get confirmation back that
this actually solves your issues."

But now that you are interested in testing and fixing this properly I plan to address this in the next release.  We can also consider backporting to 3.7.1 after getting more testing done.  Thanks for you help.
Comment 13 tomhsu CLA 2011-06-17 13:37:49 EDT
Created attachment 198199 [details]
this is the resulting modified StorageManager.java that I had working.

this is the resulting modified StorageManager.java that I had working. This is a workaround with cleanupWithLock() method inside save().
Comment 14 tomhsu CLA 2011-06-17 13:42:28 EDT
Created attachment 198200 [details]
diff file to change from original to my version

Above diff.txt is the result of the below command:
[thsu@tom-linux: /scratch/thsu/osgi342/source_mod/org/eclipse/osgi/storagemanager] $ diff StorageManager.java.original StorageManager.java > diff.txt

Hopefully the two files uploaded are helpful for you to consider a patch.
Comment 15 Thomas Watson CLA 2011-06-21 09:06:20 EDT
Created attachment 198334 [details]
updated patch and test

Here is an updated patch.  I decided to update the private cleanup method to take a boolean to determine if it should lock/release.  There was an existing bug in the StorageManager that would prevent it from opening if osgi.embedded.cleanupOnOpen was set to true.
Comment 16 Thomas Watson CLA 2011-07-05 15:37:41 EDT
Created attachment 199147 [details]
updated patch and tests

Updated patch against head.
Comment 17 Thomas Watson CLA 2011-07-05 15:53:41 EDT
Released latest patch for Juno.  

Tom, is this something you would want backported for 3.7.1.  If so I will open a separate bug to consider for 3.7.1.
Comment 18 Thomas Watson CLA 2011-07-05 15:57:31 EDT
Comment on attachment 198200 [details]
diff file to change from original to my version

Thanks for the patch!
Comment 19 tomhsu CLA 2011-07-06 12:48:17 EDT
(In reply to comment #17)
> Released latest patch for Juno.  
> 
> Tom, is this something you would want backported for 3.7.1.  If so I will open
> a separate bug to consider for 3.7.1.

Yes pls if the 3.7.1 is the next release drop that we can get the changes.
Comment 20 Ivan Xu CLA 2011-07-27 02:50:17 EDT
Hi, is it better to use tempClean flag ? As from the name of osgi.embedded.cleanupOnOpen, it means to clean up the file while starting the storemanager (usually while starting the framework) ? 
Also, it seems that an exception will be thrown if the repository folder is deleted, as no lock file there when cleanupOnOpen is configured.
Comment 21 Ivan Xu CLA 2011-07-27 03:06:56 EDT
(In reply to comment #20)
> Hi, is it better to use tempClean flag ? As from the name of
> osgi.embedded.cleanupOnOpen, it means to clean up the file while starting the
> storemanager (usually while starting the framework) ? 
> Also, it seems that an exception will be thrown if the repository folder is
> deleted, as no lock file there when cleanupOnOpen is configured.

Hmm, seems that the exception I mean is fixed after moving the codes of locking file.
Comment 22 Thomas Watson CLA 2011-08-04 08:54:10 EDT
(In reply to comment #20)
> Hi, is it better to use tempClean flag ? As from the name of
> osgi.embedded.cleanupOnOpen, it means to clean up the file while starting the
> storemanager (usually while starting the framework) ? 

I don't think using the tempClean flag is the correct flag to use.  This is really intended to clean up .tmp files that may have been left around from a crash.  Perhaps a new flag osgi.embedded.cleanupOnSave is needed.

> Also, it seems that an exception will be thrown if the repository folder is
> deleted, as no lock file there when cleanupOnOpen is configured.

I fixed this in the attachment 199147 [details] that got released to master.
Comment 23 Thomas Watson CLA 2011-08-04 08:57:16 EDT
I opened bug353879 to consider adding a cleanupOnSave option.
Comment 24 Ivan Xu CLA 2011-08-05 03:36:16 EDT
Thanks, a new flag is better. Also, could you please help to port this change to 3.7 branch ? Thanks.
Comment 25 Thomas Watson CLA 2011-08-05 09:31:17 EDT
(In reply to comment #24)
> Thanks, a new flag is better. Also, could you please help to port this change
> to 3.7 branch ? Thanks.

Yes, that will happen in bug353880.