Is it possible to get generator value twice?

279 Views Asked by At

We have run into a very embarrassing problem. It seems that some network or server error lead the front-end application to get a generator value twice.

Is it possible that getting (and updating) the generator value stays in memory, and in case of loss of power, it remains in memory doesn't get to be written on disk, so when the power restores, it loses it's current value, so we can get the generator value again?

We are using Firebird 1.5.6, Delphi (BDE and native IBExpert components).

Thanks, SanTa

Update 1: It turned out that the server is some linux, if it helps ...

2

There are 2 best solutions below

0
On

This can happen if you are connecting to the database without using aliaes and using paths that are different. Firebird then thinks that they are two separate databases. And one set of memory cache knows nothing about another.

This can cause severe database corruptions so it is important to ensure that all access to a database uses the same path. Or use aliases.

9
On

Generator values are stored on special dedicated pages inside the database. Updates are atomic and occur outside of normal transaction control and should be stored immediately. However when generators keep changing frequently it looks for OS/RAID/HDD as a "hot" page, constantly written and never read. So they have a lot of incentive to keep in cached in memory and little to actually flush it into the media.

If you wanted speed at all costs, disabled FORCED WRITES - or - enabled WRITE CACHE in Device Manager for the drive - or - just chanced to have a RAID Controller that trades speed for safety to get good magazine reviews: then it is quite possible that those header pages did not got saved to HDD before the crash.

Read links mentioned in the answer for https://serverfault.com/questions/279571/lvm-dangers-and-caveats : even if FB thinks the data is saved, even if Windows thinks so - it may simply be untrue. Also read http://blogs.msdn.com/b/oldnewthing/archive/2013/04/16/10411267.aspx


Or maybe you have an error in the program including PSQL.
Like

i := GEN_ID (Name, 0);
i := GEN_ID (Name, 1);

or

i := GEN_ID (Name, +1);
i := GEN_ID (Name, -1);

Or you may have bad options in backup-restore loop, that do reset generator values.


I also suggest you reading all the Release Notes of Firebird 2.0 to 3.0 Alpha - if there are mentioned any generator-related bugs, there are big chances you have them in your obsolete 1.5.6