Opened 14 years ago

Closed 14 years ago

#111 closed defect (fixed)

Stop using Open32 registry in QSettings

Reported by: Dmitry A. Kuminov Owned by:
Priority: blocker Milestone: Qt GA
Component: QtCore Version: 4.5.1 Beta 5
Severity: highest Keywords:
Cc:

Description

It has shown that the Windows registry implementation in the Open32 Reg* API that we use for the QSettings storage has one severe bug: under certain conditions (I suspect an application crash while a handle to a registry path is open) it corrupts the registry database so that any further attempt to write to that path or to just delete it returns Error 87 (invalid function). Even worse, this problem is persistent -- after rebooting OS/2, the database is still broken and gives the same error.

The only way to fix the broken database I know of is to restore C:\OS2\SYSTEM\SYSTEM.DAT and C:\OS2\SYSTEM\USER.DAT from the backup. It's obvious that the backup isn't always available which makes the further use of Qt applications on the broken OS/2 system impossible. This situation must be avoided.

Change History (9)

comment:1 Changed 14 years ago by Dmitry A. Kuminov

Milestone: Qt EnhancedQt GA

The only way to avoid this behavior that comes to my mind is to use the plain text files as the backing storage in QSettings: luckily, it doesn't require a lot of coding because this is what Linux and Mac versions of Qt do and the code is in there.

The obvious benefit of using text files to store settings is that text files are human readable, easily editable by hand, easily backupable and so on. The downside is some slowness in parsing comparing to the binary registry. But I have a suspicion that Open32 was quite a dirty and quick work and there is no guarantee that they actually optimized it for speed on OS/2. So we will go the text file way and see how it behaves.

For those, who suffers from the issue and doesn't have a backup of these .DAT files, you may take them from a fresh OS/2 install -- AFAIR, they don't contain any information which is vital for OS/2 itself.

comment:2 Changed 14 years ago by Silvan Scherrer

would it be possible to save it in os/2 ini files. as this could enhance some speed compared to flat files.

comment:3 Changed 14 years ago by Dmitry A. Kuminov

Yes, that's possible, but I don't think that OS/2 INI is much better than the Open32 stuff in terms of stability (I'm pretty sure the latter parts of the former). So I think we will first see if the text file approach is really slow and then decide what to do next.

comment:4 Changed 14 years ago by Silvan Scherrer

Severity: highest

comment:5 Changed 14 years ago by Dmitry A. Kuminov

in r425, committed the fix that makes plain INI files to be used for QSettings instead of the Open32 registry. There are two environment variables that control this behavior:

  QT_PM_NO_REGISTRY         If set, Qt will not use the Open32 registry to store
                            application settings with QSettings. Instead, plain
                            text INI files will be used for both NativeFormat
                            and IniFormat. Due to a number of problems in the
                            Open32 registry implementation (that may easily lead
                            to registry corruption), this is the default
                            behavior if neither this nor the QT_PM_REGISTRY
                            variable is set.

  QT_PM_REGISTRY            The opposite to the above. If set, Qt will use the
                            Open32 registry to store application settings.

comment:6 Changed 14 years ago by Dmitry A. Kuminov

Here is the comparison of the Open32 registry and plain INI file performance. For measurements, I enabled QFONTDATABASE_DEBUG in qfontdatabase.cpp (which causes the font caching code which makes heavy use of QSettings to calculate the time it spends on populating the fonts) and used the demos/textedit example. I made 3 pairs of subsequent runs in both modes deleting the font cache after each pair. Then I started the application in each mode another couple of times and took the average numbers. I have about 60 font files on my system.

Empty Cache Full Cache
Open32 2286 ms 216 ms
plain INI 2512 ms 231 ms

As you see, the slowdown that text INI files bring isn't really substantial: only 0,3 s at initial cache initialization and almost none in in subsequent runs that hit the cache.

So I think that using INI files by default (the Open32 registry is only available through the environment variable now) is fine. I suggest that we leave it as is and watch on how it behaves in real life.

Note that INI files for system-wide settings are stored in %ETC%\xdg. User-level settings are kept in %HOME%\.config. Please report back your experience.

comment:7 Changed 14 years ago by Dmitry A. Kuminov

Regarding the "normal" OS/2 INI files again. Now I think that it won't actually be possible (or will at least require quite a complex code) because QSettings expects a tree-like structure while the OS/2 INI file is flat (only one level of "folders"). We would have to map QSettings trees to these flat folders somehow (using some absolutely cryptic binary keys I suppose) which would make it completely human unreadable and unmaintainable and maybe even slower than plain text file access as we would lose the ability to quickly locate the key by its path provided by the tree structure of the Open32 registry.

comment:8 Changed 14 years ago by Silvan Scherrer

ok i fully agree with this. if we find out that the flat file aproach is somehow to slow, we still can try to figure out a faster way.

comment:9 Changed 14 years ago by Dmitry A. Kuminov

Resolution: fixed
Status: newclosed

Okay, closing the defect then.

Note: See TracTickets for help on using tickets.