Heap elements manager in heap file.
elements are one heap header and the heap records
see {@link IHeapElementManager} for role description
implement a cache for elements read and to write
data in the cache that was modified will be saved when closing transaction
cache mechanism:
record cache is in {@link #heapRecordToWriteMap} and in{@link #readHeapRecordMap}
{@link #readHeapFileDataRecord(long,boolean)} check if record already incache, if not read it from file and put it in cache ( the record is marked not modified )
{@link #newHeapFileRecord(long,long,long,boolean,boolean,int,int)}, create a new record and put it in the cache
{@link #delete(long)} delete record from the cache
{@link #closeTransaction()} write record marked changed from the cache to thefiles ( see crash safe mechanisms )
crash safe mechanism can be turned off
crash safe mechanism:
to be crash safe file is maintained open for reading, write are not done as soon they are ask but put in the read/write cache. records on the read/write cache marked changed are write to file when {@link #closeTransaction()} iscall, that close the file to be sure all is on disk before reopen file for reading
{@link #wasBadFileStableState()} must be call before use files to restorestable file state if needed
FlagData : flag file indicating data file state stable
FlagBackup: flag file indicating backup data file state stable
FlagGlobal: flag file indicating backup and data file stable state
FlagGlobal present .===#...................#===
.......... absent .....#===================#...
.......................|...................|...
FlagData present ...=======#...#===============
.......... absent .....|...#===#...........|...
.......................|...|...|...........|...
FlagBackup present .===============#...#=======
.......... absent .....|...|...|...#===#...|...
.......................|...|...|...|...|...|...
..................... (1) (2) (3) (4) (5) (6) .
(1) starting of files access for write
(2) starting of data file modification (write)
(3) ending of data file modification
(4) starting of backup data file modification (write)
(5) ending of backup data file modification
(6)end of files access for write
if all flag file are present then all files are in stable state
if 'FlagGlobal' is absent there was a modification crash
- if both 'FlagData' and 'FlagBackup' are present then the files are not deteriorated, but backup data may not be up to date
- if 'FlagData' is absent then data file may be deteriorated, backup file is in stable state ( previous data before last interrupted modification)
- if 'FlagBackup' is absent then backup data file is deteriorated, data file is in stable state ( contains last modification )
@author luc peuvrier