mdbx: packing the 16-bit representations of grow step and shrink threshold values.

Using float point (exponential quantized) representation for internal 16-bit values
of grow step and shrink threshold when huge ones
.
To minimize the impact on compatibility, only the odd values inside the upper half
of the range (i.e. 32769..65533) are used for the new representation.

Resolve https://github.com/erthink/libmdbx/issues/166

Change-Id: I273127c1842deef0d7d8885b55a805b1463556eb
This commit is contained in:
Leonid Yuriev
2021-03-09 11:54:20 +03:00
parent 57af1d2310
commit 8e51a10908
3 changed files with 172 additions and 94 deletions

View File

@@ -300,15 +300,17 @@ typedef struct MDBX_db {
} MDBX_db;
/* database size-related parameters */
typedef struct mdbx_geo_t {
uint16_t grow; /* datafile growth step in pages */
uint16_t shrink; /* datafile shrink threshold in pages */
pgno_t lower; /* minimal size of datafile in pages */
pgno_t upper; /* maximal size of datafile in pages */
pgno_t now; /* current size of datafile in pages */
pgno_t next; /* first unused page in the datafile,
* but actually the file may be shorter. */
} mdbx_geo_t;
typedef struct MDBX_geo {
uint16_t grow_pv; /* datafile growth step as a 16-bit packed (exponential
quantized) value */
uint16_t shrink_pv; /* datafile shrink threshold as a 16-bit packed
(exponential quantized) value */
pgno_t lower; /* minimal size of datafile in pages */
pgno_t upper; /* maximal size of datafile in pages */
pgno_t now; /* current size of datafile in pages */
pgno_t next; /* first unused page in the datafile,
but actually the file may be shorter. */
} MDBX_geo;
/* Meta page content.
* A meta page is the start point for accessing a database snapshot.
@@ -327,7 +329,7 @@ typedef struct MDBX_meta {
uint8_t mm_extra_pagehdr; /* extra bytes in the page header,
* zero (nothing) for now */
mdbx_geo_t mm_geo; /* database size-related parameters */
MDBX_geo mm_geo; /* database size-related parameters */
MDBX_db mm_dbs[CORE_DBS]; /* first is free space, 2nd is main db */
/* The size of pages used in this DB */
@@ -731,7 +733,7 @@ struct MDBX_txn {
MDBX_txn *mt_parent; /* parent of a nested txn */
/* Nested txn under this txn, set together with flag MDBX_TXN_HAS_CHILD */
MDBX_txn *mt_child;
mdbx_geo_t mt_geo;
MDBX_geo mt_geo;
/* next unallocated page */
#define mt_next_pgno mt_geo.next
/* corresponding to the current size of datafile */