Skip to content

Commit c19947d

Browse files
authored
Merge pull request #749 from dolthub/fix/canonical-catalog-storage
Canonicalize stored catalog identity
2 parents d6b9fc3 + 374612f commit c19947d

33 files changed

Lines changed: 3720 additions & 483 deletions

src/chunk_store.h

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@
5151
** v4 layout (current write format):
5252
** v3 fields, then:
5353
** [constraint_violations:20]
54+
**
55+
** v5 layout:
56+
** v4 fields, then:
57+
** [rebase_return_branch: WS_REBASE_BRANCH_LEN bytes, null-padded]
58+
** [constraint_violations:20]
5459
*/
5560
#define WS_FORMAT_VERSION_V2 2
5661
#define WS_FORMAT_VERSION_V3 3
5762
#define WS_FORMAT_VERSION_V4 4
58-
#define WS_FORMAT_VERSION WS_FORMAT_VERSION_V4
63+
#define WS_FORMAT_VERSION_V5 5
64+
#define WS_FORMAT_VERSION WS_FORMAT_VERSION_V5
5965
#define WS_VERSION_SIZE 1
6066
#define WS_WORKING_CAT_OFF WS_VERSION_SIZE
6167
#define WS_WORKING_COMMIT_OFF (WS_WORKING_CAT_OFF + PROLLY_HASH_SIZE)
@@ -70,34 +76,56 @@
7076
#define WS_REBASE_BRANCH_OFF (WS_REBASE_ONTO_OFF + PROLLY_HASH_SIZE)
7177
#define WS_REBASE_BRANCH_LEN 64
7278
#define WS_TOTAL_SIZE_V3 (WS_REBASE_BRANCH_OFF + WS_REBASE_BRANCH_LEN)
73-
#define WS_CONSTRAINT_VIOLATIONS_OFF WS_TOTAL_SIZE_V3
79+
#define WS_CONSTRAINT_VIOLATIONS_OFF_V4 WS_TOTAL_SIZE_V3
80+
#define WS_TOTAL_SIZE_V4 (WS_CONSTRAINT_VIOLATIONS_OFF_V4 + PROLLY_HASH_SIZE)
81+
#define WS_REBASE_RETURN_BRANCH_OFF WS_TOTAL_SIZE_V4
82+
#define WS_CONSTRAINT_VIOLATIONS_OFF (WS_REBASE_RETURN_BRANCH_OFF + WS_REBASE_BRANCH_LEN)
7483
#define WS_TOTAL_SIZE (WS_CONSTRAINT_VIOLATIONS_OFF + PROLLY_HASH_SIZE)
7584

76-
/* Catalog (table registry) format:
77-
** magic(1) + nTables(4 LE) + entries (sorted by name)
85+
/* Catalog (table registry) formats:
86+
** V3:
87+
** magic(1) + nTables(4 LE) + entries (sorted by table name)
7888
** Per entry: iTable(4 LE) + flags(1) + root(20) + schema(20)
7989
** + nameLen(2 LE) + name
80-
** Entries are sorted by name for deterministic content hashing. */
90+
**
91+
** V4:
92+
** magic(1) + nTables(4 LE) + entries (sorted by logical object key)
93+
** Per entry: iTable(4 LE) + flags(1) + root(20) + schema(20)
94+
** + typeLen(2 LE) + nameLen(2 LE) + tblNameLen(2 LE)
95+
** + type + name + tblName
96+
**
97+
** V4 keeps iTable for runtime plumbing but makes persistent catalog
98+
** identity depend on stable schema object metadata instead of creation
99+
** order or "table names only". */
81100
#define CATALOG_FORMAT_V3 0x44
101+
#define CATALOG_FORMAT_V4 0x45
82102
#define CAT_HEADER_SIZE_V3 5
83103
#define CAT_ENTRY_ITABLE_SIZE 4
84104
#define CAT_ENTRY_FLAGS_SIZE 1
85-
#define CAT_ENTRY_FIXED_SIZE (CAT_ENTRY_ITABLE_SIZE + CAT_ENTRY_FLAGS_SIZE + PROLLY_HASH_SIZE + PROLLY_HASH_SIZE + 2)
105+
#define CAT_ENTRY_FIXED_SIZE_V3 (CAT_ENTRY_ITABLE_SIZE + CAT_ENTRY_FLAGS_SIZE + PROLLY_HASH_SIZE + PROLLY_HASH_SIZE + 2)
106+
#define CAT_ENTRY_FIXED_SIZE_V4 (CAT_ENTRY_ITABLE_SIZE + CAT_ENTRY_FLAGS_SIZE + PROLLY_HASH_SIZE + PROLLY_HASH_SIZE + 6)
86107

87-
static SQLITE_INLINE int catalogParseHeader(
88-
const u8 *data, int nData, int *pnTables, const u8 **ppEntries
108+
static SQLITE_INLINE int catalogParseHeaderEx(
109+
const u8 *data, int nData, int *pVersion, int *pnTables, const u8 **ppEntries
89110
){
90111
const u8 *q;
91112
if( nData < CAT_HEADER_SIZE_V3 ) return 0;
92-
if( data[0] != CATALOG_FORMAT_V3 ){
113+
if( data[0] != CATALOG_FORMAT_V3 && data[0] != CATALOG_FORMAT_V4 ){
93114
return 0;
94115
}
116+
if( pVersion ) *pVersion = data[0];
95117
q = data + CAT_HEADER_SIZE_V3 - 4;
96118
*pnTables = (int)(q[0] | (q[1]<<8) | (q[2]<<16) | (q[3]<<24));
97119
*ppEntries = data + CAT_HEADER_SIZE_V3;
98120
return 1;
99121
}
100122

123+
static SQLITE_INLINE int catalogParseHeader(
124+
const u8 *data, int nData, int *pnTables, const u8 **ppEntries
125+
){
126+
return catalogParseHeaderEx(data, nData, 0, pnTables, ppEntries);
127+
}
128+
101129
typedef struct ChunkStore ChunkStore;
102130
typedef struct ChunkIndexEntry ChunkIndexEntry;
103131
typedef struct ConflictEntry ConflictEntry;

0 commit comments

Comments
 (0)