[ 
https://issues.apache.org/jira/browse/FELIX-4195?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matt Wiselka updated FELIX-4195:
--------------------------------

    Description: 
I ran in to the following problem using the Preferences Service on an embedded 
device with a flash memory:
When a preference is changed the sync method is called to persist it. A sudden 
power loss occurs. On restart the preference file in the bundle cache is empty 
and causes a BackingStoreException: Could not load preference.

It seems to me as that the OS is caching the write to the flash drive and the 
change is not actually persisted. I was able to fix this issue by performing a 
sync on the FileDescriptor of the OutputStream in the store method of the 
DataFileBackingStoreImpl


try {
    final FileOutputStream os = (FileOutputStream) 
this.getOutputStream(root.getDescription());
    this.write(root, os);
    os.getFD().sync();
    os.close();
}
catch (IOException ioe) {
    throw new BackingStoreException("Unable to store preferences.", ioe);
}

  was:
I ran in to the following problem using the Preferences Service on an embedded 
device with a flash memory:
When a preference is changed the sync method is called to persist it. A sudden 
power loss occurs. On restart the preference file in the bundle cache is empty 
and causes a BackingStoreException: Could not load preference.

It seems to me as that the OS is caching the write to the flash drive and the 
change is not actually persisted. I was able to fix this issue by performing a 
sync on the FileDescriptor of the OutputStream in the store method of the 
DataFileBackingStoreImpl

{code}
        try {
            final FileOutputStream os = (FileOutputStream) 
this.getOutputStream(root.getDescription());
            this.write(root, os);
            os.getFD().sync();
            os.close();
        }
        catch (IOException ioe) {
            throw new BackingStoreException("Unable to store preferences.", 
ioe);
        }
{code}

    
> Sync on a Preference doesn't do a OS side sync
> ----------------------------------------------
>
>                 Key: FELIX-4195
>                 URL: https://issues.apache.org/jira/browse/FELIX-4195
>             Project: Felix
>          Issue Type: Bug
>          Components: Preferences Service
>    Affects Versions: prefs-1.0.6
>         Environment: Anstroem Embedded Linux
> UBIFS on a flash drive
>            Reporter: Matt Wiselka
>
> I ran in to the following problem using the Preferences Service on an 
> embedded device with a flash memory:
> When a preference is changed the sync method is called to persist it. A 
> sudden power loss occurs. On restart the preference file in the bundle cache 
> is empty and causes a BackingStoreException: Could not load preference.
> It seems to me as that the OS is caching the write to the flash drive and the 
> change is not actually persisted. I was able to fix this issue by performing 
> a sync on the FileDescriptor of the OutputStream in the store method of the 
> DataFileBackingStoreImpl
> try {
>     final FileOutputStream os = (FileOutputStream) 
> this.getOutputStream(root.getDescription());
>     this.write(root, os);
>     os.getFD().sync();
>     os.close();
> }
> catch (IOException ioe) {
>     throw new BackingStoreException("Unable to store preferences.", ioe);
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to