diff options
author | Sulabh Mahajan <sulabh.mahajan@mongodb.com> | 2017-07-24 09:56:58 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-24 09:56:58 +1000 |
commit | 71c66de3023f2a73f51cd6c9ee688a2a674193d6 (patch) | |
tree | b8fbe44247c6ea9485870f65ef560a01972d0c61 /src/include/btmem.h | |
parent | 311b718ccd1eefffc9f056a1524173ce46ac955d (diff) | |
download | mongo-71c66de3023f2a73f51cd6c9ee688a2a674193d6.tar.gz |
WT-3380 Make 8-byte timestamps a special case (#3509)
* Change wt_timestamp_t to union of uint64 and uint8 array
* Add contents from Keith's change
* Whitespace and s_string ok addition
* Get rid of WT_GET_TIMESTAMP_PTR
* Fix the change after the merge
* Remove superfluous struct around union, simplify macros
* Remove packed attribute from WT_UPDATE. (#3523)
* Remove packed attribute from WT_UPDATE.
Add 3B of data declaration at the end of the WT_UPDATE structure. That
way we don't have to pack the structure to avoid wasting data bytes,
and we don't have to use a macro to identify the start of the data.
* Locate the timestamp in the WT_UPDATE structure depending on its
alignment, to avoid padding.
* I lost a change, the size of the WT_UPDATE structure has to reflect the
size of the timestamp.
* Change the __wt_timestamp_t union into a structure so the compiler doesn't
insert padding in the middle of the WT_UPDATE structure (the existence of
the uint64_t in the union causes the whole thing to be aligned, even if we
never access it).
Incorporate Michael's change to replace sizeof(WT_UPDATE) with WT_UPDATESIZE,
the compiler is padding the structure at the end and we need to ignore that.
* If there's no union, we can't reach into it and get the field, take
the address like we do everywhere else.
* Simplify size calculations for WT_UPDATE.
In particular, go back to having WT_UPDATE_SIZE match the size of a
WT_UPDATE excluding the payload data. That means the declared size of
the data array in WT_UPDATE is no longer special.
* Switch from a 3-byte array to a C99 flexible array member.
There is no longer anything special about the 3 byte array: since the
timestamp can be any size, there is no guarantee it makes a WT_UPDATE
any nicely rounded size. Compilers enforce some rules around how
flexible array members can be used: we should consider switching our
other uses of structs with trailing arrays (in a separate ticket).
* Remove some more unnecessary casts now that upd->data is typed.
Diffstat (limited to 'src/include/btmem.h')
-rw-r--r-- | src/include/btmem.h | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/include/btmem.h b/src/include/btmem.h index 37501a484b0..b694930c8fd 100644 --- a/src/include/btmem.h +++ b/src/include/btmem.h @@ -885,9 +885,11 @@ struct __wt_ikey { * is done for an entry, WT_UPDATE structures are formed into a forward-linked * list. */ -WT_PACKED_STRUCT_BEGIN(__wt_update) - volatile uint64_t txnid; /* Transaction ID */ - WT_DECL_TIMESTAMP(timestamp) +struct __wt_update { + volatile uint64_t txnid; /* transaction ID */ +#if WT_TIMESTAMP_SIZE == 8 + WT_DECL_TIMESTAMP(timestamp) /* aligned uint64_t timestamp */ +#endif WT_UPDATE *next; /* forward-linked list */ @@ -898,13 +900,20 @@ WT_PACKED_STRUCT_BEGIN(__wt_update) #define WT_UPDATE_RESERVED 2 uint8_t type; /* type (one byte to conserve memory) */ - /* The update includes a complete value. */ + /* If the update includes a complete value. */ #define WT_UPDATE_DATA_VALUE(upd) \ ((upd)->type == WT_UPDATE_STANDARD || (upd)->type == WT_UPDATE_DELETED) - /* The untyped value immediately follows the WT_UPDATE structure. */ -#define WT_UPDATE_DATA(upd) \ - ((void *)((uint8_t *)(upd) + sizeof(WT_UPDATE))) +#if WT_TIMESTAMP_SIZE != 8 + WT_DECL_TIMESTAMP(timestamp) /* unaligned uint8_t array timestamp */ +#endif + + /* + * Zero or more bytes of value (the payload) immediately follows the + * WT_UPDATE structure. We use a C99 flexible array member which has + * the semantics we want. + */ + uint8_t data[]; /* start of the data */ /* * The memory size of an update: include some padding because this is @@ -912,12 +921,12 @@ WT_PACKED_STRUCT_BEGIN(__wt_update) * cache overhead calculation. */ #define WT_UPDATE_MEMSIZE(upd) \ - WT_ALIGN(sizeof(WT_UPDATE) + (upd)->size, 32) -WT_PACKED_STRUCT_END + WT_ALIGN(WT_UPDATE_SIZE + (upd)->size, 32) +}; /* - * WT_UPDATE_SIZE is the expected structure size -- we verify the build to - * ensure the compiler hasn't inserted padding. + * WT_UPDATE_SIZE is the expected structure size excluding the payload data -- + * we verify the build to ensure the compiler hasn't inserted padding. */ #define WT_UPDATE_SIZE (21 + WT_TIMESTAMP_SIZE) |