Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - sql: add copy-based migrations and VACUUM INTO #6085

Closed
wants to merge 79 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
7a97f7a
sql: improve database schema handling
ivan4th May 31, 2024
6a53628
sql: fixup: malsync and rewards
ivan4th Jun 1, 2024
5db7e18
sql: add migration / schema drift related tests
ivan4th Jun 1, 2024
c2938b2
sql: make schema drift table ignore regexp configurable
ivan4th Jun 1, 2024
ec3397e
sql: refactor localsql / statesql tests
ivan4th Jun 1, 2024
1af47bb
Update CHANGELOG.md
ivan4th Jun 1, 2024
7bb2b1b
config: fix db presets for db schema drift detection
ivan4th Jun 1, 2024
bc98240
sql: fix review comments
ivan4th Jun 5, 2024
895f50f
sql: add database schema handling docs
ivan4th Jun 5, 2024
6f33999
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jun 5, 2024
6257174
config: fix build errors
ivan4th Jun 5, 2024
aada7c6
Fix README.md
ivan4th Jun 7, 2024
dbea047
Fix go.mod / go.sum
ivan4th Jun 7, 2024
6bf114a
sql: use go:generate for database schema files
ivan4th Jun 12, 2024
bd62a8e
sql: make schema drift fatal by default
ivan4th Jun 12, 2024
c9d1a6c
sql: remove db-ignore-schema-rx config option
ivan4th Jun 12, 2024
beccddd
sql: avoid cyclic dependencies in future coded migrations
ivan4th Jun 12, 2024
8552a96
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jun 12, 2024
2e41e1a
activation: fix test
ivan4th Jun 12, 2024
dd2ed3e
sql: fix tests
ivan4th Jun 12, 2024
13e8c14
sql: fix query cache handling
ivan4th Jun 12, 2024
fbf2880
sql: update mocks
ivan4th Jun 13, 2024
6dbc902
sql: fix QueryCache related mocks
ivan4th Jun 13, 2024
09e36bb
node: don't print error twice upon failure
ivan4th Jun 13, 2024
9dc3f0c
sql: fix schema drift on Windows
ivan4th Jun 13, 2024
8bbeeb5
sql: update docs on schema handling
ivan4th Jun 13, 2024
30dcf71
sql, malsync: fix handling of context cancelation
ivan4th Jun 13, 2024
8506114
sql: split Schema.Migrate() method
ivan4th Jun 13, 2024
feb39fe
sql: another fix for Windows newlines in the schema
ivan4th Jun 13, 2024
77b46d1
merge-nodes: fix test naming
ivan4th Jun 13, 2024
ee36ee4
sql: close db on schema errors
ivan4th Jun 13, 2024
da6ab28
sql, datastore: remove unneeded mocks
ivan4th Jun 16, 2024
cbf4195
sql: fix naming
ivan4th Jun 16, 2024
b56dc59
sql: remove unneeded assertions from tests
ivan4th Jun 16, 2024
f1f11fe
sql: schemagen: fix help
ivan4th Jun 16, 2024
a172a94
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jun 16, 2024
b149e23
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jun 25, 2024
c2c7e6f
Moved database schema handling docs to CODING.md
ivan4th Jun 25, 2024
0400d33
api: fix database handling in the test
ivan4th Jun 25, 2024
a2679a5
sql: fix identities test
ivan4th Jun 25, 2024
33b9501
sql: simplify StateDatabase and LocalDatabase interfaces
ivan4th Jun 26, 2024
ff35334
node: make it possibe to allow localsql schema drift
ivan4th Jun 26, 2024
3d38b8f
sql: add copy-based migrations and VACUUM INTO
ivan4th Jun 26, 2024
1df9c30
sql: fix issues found by linter
ivan4th Jun 28, 2024
93a5087
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jun 28, 2024
b568b25
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jun 28, 2024
2c29103
sql: fix review comments
ivan4th Jun 29, 2024
bd28a9f
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jul 8, 2024
507aca6
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jul 8, 2024
5b47e76
sql: fix failing tests
ivan4th Jul 8, 2024
4090f64
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jul 8, 2024
945f2ec
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jul 9, 2024
ce9647b
Merge branch 'develop' into feature/schema-snapshot
ivan4th Jul 11, 2024
1220037
Merge branch 'develop' into feature/schema-snapshot
ivan4th Aug 13, 2024
dcab056
statesql: update schema
ivan4th Aug 13, 2024
1d8d310
tmp: fix lint errors (will need to revert)
ivan4th Aug 13, 2024
a942ccc
Revert "tmp: fix lint errors (will need to revert)"
ivan4th Aug 15, 2024
fe95d18
Move statesql migrations to a separate package to avoid cyclic deps
ivan4th Aug 15, 2024
354dc56
Merge branch 'develop' into feature/schema-snapshot
ivan4th Aug 15, 2024
22847df
sql: fix schemagen
ivan4th Aug 15, 2024
5278bf4
Merge branch 'feature/schema-snapshot' into feature/vacuum-into
ivan4th Aug 15, 2024
25185be
Address comments
ivan4th Aug 15, 2024
9dcdd59
fetch: fix tests
ivan4th Aug 15, 2024
8bf64c7
sql: fix error handling
ivan4th Aug 16, 2024
e7b563b
statesql, localsql: fix InMemoryTest
ivan4th Aug 17, 2024
5247124
sql: fix in-memory db handling
ivan4th Aug 17, 2024
a59cc3c
Merge branch 'develop' into feature/schema-snapshot
ivan4th Aug 20, 2024
47fbc84
Addressed comments
ivan4th Aug 20, 2024
2e7e150
sql: ignore whitespace during schema drift checks
ivan4th Aug 20, 2024
01c3686
Merge branch 'feature/schema-snapshot' into feature/vacuum-into
ivan4th Aug 20, 2024
bd81eb5
Merge branch 'develop' into feature/vacuum-into
ivan4th Aug 20, 2024
670df1b
sql: fix failing migration tests on Windows
ivan4th Aug 20, 2024
d69eab4
Address comments
ivan4th Aug 20, 2024
26aa21c
Address more comments
ivan4th Aug 21, 2024
3a3bd94
sql: improve error handling during migrations
ivan4th Aug 21, 2024
f462433
sql: hold exclusive database locks during copy-based migration
ivan4th Aug 22, 2024
3119a63
sql: further simplify error handling
ivan4th Aug 22, 2024
11527ab
Remove unneeded errors.Join
ivan4th Aug 22, 2024
64f4d38
Address comments
ivan4th Aug 22, 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
2 changes: 1 addition & 1 deletion checkpoint/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@

newDB, err := statesql.Open("file:" + cfg.DbPath())
if err != nil {
return nil, fmt.Errorf("creating new DB: %w", err)
return nil, fmt.Errorf("create new db: %w", err)

Check warning on line 279 in checkpoint/recovery.go

View check run for this annotation

Codecov / codecov/patch

checkpoint/recovery.go#L279

Added line #L279 was not covered by tests
}
defer newDB.Close()
logger.Info("populating new database",
Expand Down
2 changes: 1 addition & 1 deletion fetch/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func TestHandleEpochInfoReq(t *testing.T) {
var resp server.Response
require.NoError(t, codec.Decode(b.Bytes(), &resp))
require.Empty(t, resp.Data)
require.Contains(t, resp.Error, "exec epoch 11: database: no free connection")
require.Contains(t, resp.Error, "exec epoch 11: database closed")
})
})
}
Expand Down
22 changes: 11 additions & 11 deletions fetch/p2p_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func forStreamingCachedUncached(

func TestP2PPeerEpochInfo(t *testing.T) {
forStreamingCachedUncached(
t, "peer error: getting ATX IDs: exec epoch 11: database: no free connection",
t, "peer error: getting ATX IDs: exec epoch 11: database closed",
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
epoch := types.EpochID(11)
atxIDs := tpf.createATXs(epoch)
Expand All @@ -291,7 +291,7 @@ func TestP2PPeerEpochInfo(t *testing.T) {

func TestP2PPeerMeshHashes(t *testing.T) {
forStreaming(
t, "peer error: get aggHashes from 7 to 23 by 5: database: no free connection", false,
t, "peer error: get aggHashes from 7 to 23 by 5: database closed", false,
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
req := &MeshHashRequest{
From: 7,
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestP2PPeerMeshHashes(t *testing.T) {

func TestP2PMaliciousIDs(t *testing.T) {
forStreaming(
t, "database: no free connection", false,
t, "database closed", false,
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
var bad []types.NodeID
for i := 0; i < 11; i++ {
Expand All @@ -349,7 +349,7 @@ func TestP2PMaliciousIDs(t *testing.T) {

func TestP2PGetATXs(t *testing.T) {
forStreamingCachedUncached(
t, "database: no free connection",
t, "database closed",
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
epoch := types.EpochID(11)
atx := newAtx(tpf.t, epoch)
Expand All @@ -365,7 +365,7 @@ func TestP2PGetATXs(t *testing.T) {

func TestP2PGetPoet(t *testing.T) {
forStreaming(
t, "database: no free connection", false,
t, "database closed", false,
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
ref := types.PoetProofRef{0x42, 0x43}
require.NoError(t, poets.Add(tpf.serverCDB, ref, []byte("proof1"), []byte("sid1"), "rid1"))
Expand All @@ -380,7 +380,7 @@ func TestP2PGetPoet(t *testing.T) {

func TestP2PGetBallot(t *testing.T) {
forStreaming(
t, "database: no free connection", false,
t, "database closed", false,
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
signer, err := signing.NewEdSigner()
require.NoError(t, err)
Expand All @@ -402,7 +402,7 @@ func TestP2PGetBallot(t *testing.T) {

func TestP2PGetActiveSet(t *testing.T) {
forStreamingCachedUncached(
t, "database: no free connection",
t, "database closed",
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
id := types.RandomHash()
set := &types.EpochActiveSet{
Expand All @@ -421,7 +421,7 @@ func TestP2PGetActiveSet(t *testing.T) {

func TestP2PGetBlock(t *testing.T) {
forStreaming(
t, "database: no free connection", false,
t, "database closed", false,
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
lid := types.LayerID(111)
bk := types.NewExistingBlock(types.RandomBlockID(), types.InnerBlock{LayerIndex: lid})
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestP2PGetProp(t *testing.T) {

func TestP2PGetBlockTransactions(t *testing.T) {
forStreaming(
t, "database: no free connection", false,
t, "database closed", false,
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
signer, err := signing.NewEdSigner()
require.NoError(t, err)
Expand All @@ -488,7 +488,7 @@ func TestP2PGetBlockTransactions(t *testing.T) {

func TestP2PGetProposalTransactions(t *testing.T) {
forStreaming(
t, "database: no free connection", false,
t, "database closed", false,
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
signer, err := signing.NewEdSigner()
require.NoError(t, err)
Expand All @@ -506,7 +506,7 @@ func TestP2PGetProposalTransactions(t *testing.T) {

func TestP2PGetMalfeasanceProofs(t *testing.T) {
forStreaming(
t, "database: no free connection", false,
t, "database closed", false,
func(t *testing.T, ctx context.Context, tpf *testP2PFetch, errStr string) {
nid := types.RandomNodeID()
proof := types.RandomBytes(11)
Expand Down
4 changes: 2 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,7 @@
}
sqlDB, err := statesql.Open("file:"+filepath.Join(dbPath, dbFile), dbopts...)
if err != nil {
return fmt.Errorf("open sqlite db %w", err)
return fmt.Errorf("open sqlite db: %w", err)

Check warning on line 1969 in node/node.go

View check run for this annotation

Codecov / codecov/patch

node/node.go#L1969

Added line #L1969 was not covered by tests
}
app.db = sqlDB
if app.Config.CollectMetrics && app.Config.DatabaseSizeMeteringInterval != 0 {
Expand Down Expand Up @@ -2012,7 +2012,7 @@
sql.WithAllowSchemaDrift(app.Config.DatabaseSchemaAllowDrift),
)
if err != nil {
return fmt.Errorf("open sqlite db %w", err)
return fmt.Errorf("open sqlite db: %w", err)

Check warning on line 2015 in node/node.go

View check run for this annotation

Codecov / codecov/patch

node/node.go#L2015

Added line #L2015 was not covered by tests
}
app.localDB = localDB
return nil
Expand Down
Loading
Loading