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

Fix Transaction ID counter for Postgres backups #1630

Closed
jzelinskie opened this issue Oct 31, 2023 · 0 comments · Fixed by #1642
Closed

Fix Transaction ID counter for Postgres backups #1630

jzelinskie opened this issue Oct 31, 2023 · 0 comments · Fixed by #1642
Assignees
Labels
area/CLI Affects the command line area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) kind/tech debt Addresses legacy code/decisions

Comments

@jzelinskie
Copy link
Member

Problem Statement

When performing a backup of a Postgres database, Postgres does not backup/restore the transaction ID counter.
Because SpiceDB depends on this value being set, we need some means of setting the counter or incrementing it to the place where the previous database counter was set.

Solution Brainstorm

After some investigation @jakedt was able to produce a benchmark for batching the creation of transactions to increment the Postgres transaction ID counter. With batch size of 10k its ~2.6 seconds per million transactions. This could probably use a bit more investigation to find an ideal batch size.

func BenchmarkTxidPipeline(b *testing.B) {
	ctx := context.Background()

	conn, err := pgx.Connect(ctx, localhostDB)
	if err != nil {
		b.Fatalf("err: %s", err)
	}
	defer conn.Close(ctx)

	b.ResetTimer()

	// b.Logf("b.N: %d", b.N)
	for i := 0; i < b.N; {
		var batch pgx.Batch

		for j := 0; j < batchSize && i+j < b.N; j++ {
			// b.Logf("queuing query: %d", i+j)
			batch.Queue("begin;")
			batch.Queue("select pg_current_xact_id();")
			batch.Queue("rollback;")
			executed++
		}

		// b.Log("sending batch")

		i += batch.Len()

		br := conn.SendBatch(ctx, &batch)

		if err := br.Close(); err != nil {
			b.Fatalf("err: %s", err)
		}

		// b.Logf("value of i: %d", i)
	}

	b.Logf("total executed: %d", executed)
}
BenchmarkTxid-10            	     170	   6499092 ns/op
BenchmarkTxidPipeline-10    	  400071	      2705 ns/op

After this explored, we need to introduce this into SpiceDB.
A "repair" command could be added as maybe a part of a larger command for sanity-checking configurations (e.g. spicedb status --repair)

@jzelinskie jzelinskie added area/CLI Affects the command line area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) kind/tech debt Addresses legacy code/decisions labels Oct 31, 2023
@josephschorr josephschorr self-assigned this Nov 1, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 9, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 9, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 9, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 13, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 15, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 15, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 15, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 15, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 16, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 16, 2023
josephschorr added a commit to josephschorr/spicedb that referenced this issue Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/CLI Affects the command line area/datastore Affects the storage system area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) kind/tech debt Addresses legacy code/decisions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants