Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
21ef4b2
Duplicate MySQL files to new PostgreSQL directories, preserving git l…
robstradling Oct 1, 2024
78653c2
Restore MySQL files
robstradling Oct 1, 2024
9f48d08
Replace 'MySQL' references with 'PostgreSQL', preserving case of each…
robstradling Oct 1, 2024
b0f7dfe
Build the PostgreSQL protobuf definitions
robstradling Oct 1, 2024
18cf306
Rename PostgreSQL 'testdb' package to 'testdbpgx'
robstradling Oct 1, 2024
e01fb0b
Convert from database/sql API to jackc/pgx/v5 API
robstradling Oct 1, 2024
33451e6
Update imports
robstradling Oct 1, 2024
6d88880
Convert schema
robstradling Oct 1, 2024
74526b6
Use EXPLAIN output to estimate rows in PostgreSQL quota.Manager
robstradling Oct 1, 2024
e3583cd
PostgreSQL doesn't have an equivalent of MySQL's strict mode
robstradling Oct 1, 2024
a167577
Context required for pgx Commit() and Rollback() functions
robstradling Oct 1, 2024
c127965
Remove statement map and PrepareContext() calls, because pgx automati…
robstradling Oct 1, 2024
cb7bda2
Use ANY to bind arrays, instead of expanding placeholders
robstradling Oct 1, 2024
52f2867
Use PostgreSQL's COPY interface and a temporary table to upsert subtrees
robstradling Oct 1, 2024
51def32
Use PostgreSQL parameter placeholder syntax
robstradling Oct 1, 2024
22f955a
Format SQL queries consistently and without including unnecessary whi…
robstradling Oct 1, 2024
e8fdc37
Remove explicit delete from TreeControl, because no previous versions…
robstradling Oct 1, 2024
0f6f593
Adapt getVersion query to PostgreSQL
robstradling Oct 1, 2024
10d47f8
Context required for pgx Exec() and Ping() functions
robstradling Oct 1, 2024
e617388
No error returned by pgx RowsAffected() function
robstradling Oct 1, 2024
a1ccf26
Check Rows errors consistently and correctly
robstradling Oct 1, 2024
66d2c7f
Adapt errors.go to PostgreSQL
robstradling Oct 1, 2024
8218303
Adapt connection pool opening to PostgreSQL
robstradling Oct 1, 2024
92030b3
No error returned by pgxpool Close() function
robstradling Oct 1, 2024
f68b8b9
Pass arguments directly to Query in getLeavesByRangeInternal
robstradling Oct 1, 2024
1456b20
Adapt provider.go with plausible postgreSQLURI and drop calls to data…
robstradling Oct 1, 2024
aff11fc
Remove CockroachDB stuff from testdbpgx and specify plausible default…
robstradling Oct 1, 2024
bdd9faf
Tidy up / fix pgx imports
robstradling Oct 1, 2024
7b0ae0a
Plug PostgreSQL storage and quota providers into log_server and log_s…
robstradling Oct 1, 2024
2846d36
Enable the testdbpgx tokenizer to handle PL/pgSQL functions correctly…
robstradling Oct 1, 2024
0121720
To pass postgresql_quota_test requires fresher row estimates, so ANAL…
robstradling Oct 1, 2024
ba74553
PostgreSQL connection strings support TLS natively
robstradling Oct 1, 2024
2c5598f
Rebuild the PostgreSQL protobuf definitions with updated protoc-gen-go
robstradling Oct 1, 2024
b365aed
Use PostgreSQL's COPY interface for updating sequenced leaves
robstradling Oct 2, 2024
aa47b36
CopyFrom seems to require all lower case for table and column names
robstradling Oct 2, 2024
607c13a
Use PostgreSQL's COPY interface and a temporary table to queue leaves…
robstradling Oct 7, 2024
7a0df88
Fix conflict handling in multiple subtree insert query
robstradling Oct 8, 2024
7ce0258
Unmarshal storage settings before beginning transaction in beginTreeT…
robstradling Oct 8, 2024
55f0656
go get -u github.com/jackc/pgx/v5
robstradling Oct 8, 2024
b644630
go get github.com/google/trillian/storage/postgresql/testdbpgx
robstradling Oct 8, 2024
9ecaa58
Deleted all of the revisioned tree support
mhutchinson Oct 10, 2024
8e459da
Missed one
mhutchinson Oct 10, 2024
6698903
Disambiguate flag name
mhutchinson Oct 10, 2024
9c72070
Merge branch 'master' into postgresql_support
robstradling Oct 15, 2024
7c1f8c5
Merge branch 'google:master' into postgresql_support
robstradling Oct 25, 2024
2d5c941
Fix integration and unit tests
robstradling Oct 25, 2024
d1a21e1
Enable the BigBatch tests
robstradling Oct 25, 2024
0eac2ab
Hopefully fix trillian-pr-tests (trillian-opensource-ci) checks
robstradling Oct 28, 2024
965aa91
No need to sortLeavesForInsert
robstradling Oct 29, 2024
651b3b5
Update copyright details
robstradling Oct 30, 2024
72964d2
Remove vestigial Trees.PrivateKey and Trees.PublicKey fields
robstradling Oct 30, 2024
917f362
Remove vestigial Trees.HashStrategy, Trees.HashAlgorithm, and Trees.S…
robstradling Oct 31, 2024
dd85139
Add missing DROP FUNCTIONs.
robstradling Oct 31, 2024
32096c4
Call out the caveats in the quota manager more explicitly and up-front
robstradling Nov 5, 2024
8c40e33
Add a README.md that provides an overview of the PostgreSQL storage i…
robstradling Nov 5, 2024
28df5c0
Cover PostgreSQL in the mitigation for Issue #1297 in CODEOWNERS
robstradling Nov 5, 2024
286e278
Add PostgreSQL storage and quota implementations to the feature imple…
robstradling Nov 5, 2024
a4ee5cd
Full stops
robstradling Nov 5, 2024
1aa5094
Merge branch 'master' into postgresql_support
robstradling Nov 6, 2024
0462f62
Update CHANGELOG.md
robstradling Nov 6, 2024
6e3eb86
Remove Rob from CODEOWNERS
robstradling Nov 6, 2024
d41757e
Transfer PostgreSQL TODOs to Rob
robstradling Nov 6, 2024
378779f
Use the batched queue implementation, and remove the non-batched option
robstradling Nov 6, 2024
8102b6a
Remove vestigial Subtree.SubtreeRevision field
robstradling Nov 6, 2024
be96182
Remove vestigial TreeHead.TreeRevision field
robstradling Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use PostgreSQL's COPY interface and a temporary table to upsert subtrees
  • Loading branch information
robstradling committed Oct 8, 2024
commit 52f2867d775f25313065225043103ce7fbf7d4b3
38 changes: 31 additions & 7 deletions storage/postgresql/tree_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ import (

// These statements are fixed
const (
insertSubtreeMultiSQL = `INSERT INTO Subtree(TreeId, SubtreeId, Nodes, SubtreeRevision) ` + placeholderSQL + ` ON DUPLICATE KEY UPDATE Nodes=VALUES(Nodes)`
createTempSubtreeTable = `CREATE TEMP TABLE TempSubtree (
TreeId BIGINT,
SubtreeId BYTEA,
Nodes BYTEA,
SubtreeRevision INTEGER,
CONSTRAINT TempSubtree_pk PRIMARY KEY (TreeId,SubtreeId,SubtreeRevision)
) ON COMMIT DROP`
insertSubtreeMultiSQL = `INSERT INTO Subtree(TreeId, SubtreeId, Nodes, SubtreeRevision) SELECT TreeId, SubtreeId, Nodes, SubtreeRevision FROM TempSubtree ON CONFLICT ON CONSTRAINT TempSubtree_pk DO UPDATE Nodes=EXCLUDED.Nodes`
insertTreeHeadSQL = `INSERT INTO TreeHead(TreeId,TreeHeadTimestamp,TreeSize,RootHash,TreeRevision,RootSignature)
VALUES(?,?,?,?,?,?)`

Expand Down Expand Up @@ -223,7 +230,7 @@ func (t *treeTX) storeSubtrees(ctx context.Context, subtrees []*storagepb.Subtre

// TODO(al): probably need to be able to batch this in the case where we have
// a really large number of subtrees to store.
args := make([]interface{}, 0, len(subtrees))
rows := make([][]interface{}, 0, len(subtrees))

// If not using subtree revisions then default value of 0 is fine. There is no
// significance to this value, other than it cannot be NULL in the DB.
Expand All @@ -241,13 +248,30 @@ func (t *treeTX) storeSubtrees(ctx context.Context, subtrees []*storagepb.Subtre
if err != nil {
return err
}
args = append(args, t.treeID)
args = append(args, s.Prefix)
args = append(args, subtreeBytes)
args = append(args, subtreeRev)
rows = append(rows, []interface{}{t.treeID, s.Prefix, subtreeBytes, subtreeRev})
}

r, err := t.tx.Exec(ctx, insertSubtreeMultiSQL, args...)
// Create temporary subtree table.
_, err := t.tx.Exec(ctx, createTempSubtreeTable)
if err != nil {
klog.Warningf("Failed to create temporary subtree table: %s", err)
return err
}

// Copy subtrees to temporary table.
_, err = t.tx.CopyFrom(
ctx,
pgx.Identifier{"TempSubtree"},
[]string{"TreeId", "SubtreeId", "Nodes", "SubtreeRevision"},
pgx.CopyFromRows(rows),
)
if err != nil {
klog.Warningf("Failed to copy merkle subtrees: %s", err)
return err
}

// Upsert the subtrees.
_, err = t.tx.Exec(ctx, insertSubtreeMultiSQL)
if err != nil {
klog.Warningf("Failed to set merkle subtrees: %s", err)
return err
Expand Down