Skip to content

Various upload improvements#1012

Merged
LeMikaelF merged 2 commits into
mainfrom
multipart-improvements
Jan 16, 2026
Merged

Various upload improvements#1012
LeMikaelF merged 2 commits into
mainfrom
multipart-improvements

Conversation

@LeMikaelF

@LeMikaelF LeMikaelF commented Dec 26, 2025

Copy link
Copy Markdown
Contributor

Summary

This PR contains various improvements to the multipart upload flow. I realize that it's a lot in the same PR, sorry about that.

  • always use multipart upload
  • retry chunks when they fail. I expect that this will increase stability compared to the previous flow.
  • use the new endpoints, since there was a breaking change (there's an upload_id that's now exposed)
  • refresh token between each chunk and before /finalize. This was necessary because the new flow can include several requests over more than an hour.
  • Show a spinner with the DB size during validation. The first thing we do when we start an upload is that we check that the DB is valid. For large uploads, this could make it look like the CLI is hanging.
  • Add debug logging for multipart upload, using the TURSO_DEBUG_UPLOAD=1 environment variable. I wasn't able to use the existing --debug flag, because that one logs the bodies of the PUT requests, and they can contain control characters that will wreck your terminal.
  • Update the progress tracker at least every 2 seconds. Previously, it was updated every 1% of an upload. For very large uploads, this made it look like the CLI was hanging.

Testing

I uploaded a very small databases (few KB), one that was ~100MB, and one that was 1GB. There are also some automated tests in the PR.

Failing CI test

The integration tests are failing in the CI. It's because multipart upload isn't deployed to us-east-1 yet. I changed the integration tests to use eu-north-1. You can see a passing run in that PR (https://github.com/tursodatabase/tursotest/pull/93).

AI use

The code was mostly written by Claude, but I iterated a lot with it.

Comment thread internal/cmd/db_import.go Outdated
Comment thread internal/cmd/group_flag.go
Comment thread internal/turso/databases.go Outdated
@LeMikaelF LeMikaelF changed the title Always use multipart upload, and show warning for large DBs Always use multipart upload Jan 8, 2026
@LeMikaelF LeMikaelF force-pushed the multipart-improvements branch from db56d5c to 01f9643 Compare January 8, 2026 22:38
LeMikaelF added a commit that referenced this pull request Jan 9, 2026
In #1012, I'm updating
the Go version to 1.25 to be able to use the experimental `synctest`
package, but one of our linters isn't compatible.

I opened a PR (linked in the code), but I don't want to have to wait for
the maintainer (there's a PR that's 2 weeks old with no comments). So
this PR uses my fork instead.
@LeMikaelF LeMikaelF force-pushed the multipart-improvements branch from 01f9643 to 1177c8d Compare January 9, 2026 14:12
@LeMikaelF LeMikaelF force-pushed the multipart-improvements branch from 1177c8d to f5722c6 Compare January 9, 2026 18:20
Comment thread internal/cmd/db_shell.go Outdated

if db != nil && db.Sleeping {
return fmt.Errorf("Your DB might be archived. Please run `turso group unarchive " + db.Group + "` to unarchive it")
return fmt.Errorf("Your DB might be archived. Please run `turso group unarchive %s` to unarchive it", db.Group)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linter error

@LeMikaelF LeMikaelF changed the title Always use multipart upload Various upload improvements Jan 9, 2026
@LeMikaelF

Copy link
Copy Markdown
Contributor Author

@copilot are you there?

Copilot AI commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

@LeMikaelF I've opened a new pull request, #1016, to work on those changes. Once the pull request is ready, I'll request review from you.

@LeMikaelF LeMikaelF force-pushed the multipart-improvements branch from f5722c6 to be8d425 Compare January 9, 2026 19:53
@LeMikaelF LeMikaelF force-pushed the multipart-improvements branch from 02a0cb5 to 97876ec Compare January 9, 2026 21:26
@LeMikaelF LeMikaelF marked this pull request as ready for review January 9, 2026 21:29
@jussisaurio jussisaurio requested a review from Copilot January 13, 2026 17:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces comprehensive improvements to the multipart upload flow for database files, transitioning to always use multipart uploads with enhanced reliability and progress tracking.

Changes:

  • Implemented chunk-level retry logic with exponential backoff for failed uploads
  • Added token refresh mechanism between chunks and before finalization to handle long-running uploads
  • Enhanced progress tracking with time-based (2s) and byte-based (50MB) update thresholds
  • Migrated to v2 upload endpoints with upload_id support and removed single-part upload path

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
go.mod Updates Go version requirement to 1.25 (critical: this version doesn't exist)
internal/turso/turso.go Adds SetToken method to support token refresh
internal/turso/tursoServer.go Core upload logic with retry mechanism, token refresh, and improved progress tracking
internal/turso/tursoServer_test.go Updates tests for v2 API and adds comprehensive progress reader tests using synctest
internal/turso/databases.go Refactors to use TokenProvider pattern and removes multipart flag (always multipart now)
internal/cmd/db_create.go Removes multipart flag parameter
internal/cmd/db_import.go Removes multipart flag declaration
internal/cmd/db_shell.go Improves error message formatting
internal/cmd/group_flag.go Adds validation spinner with file size display and refactors DB seed handling
internal/cmd/group_flag_test.go New test file for database validation logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +270 to +272
log.Printf("[upload] Chunk %d: exhausted all %d retries, giving up", ctx.chunkID, maxRetries+1)
}
return chunkUploadResult{}, fmt.Errorf("failed after %d retries: %w", maxRetries+1, lastErr)

Copilot AI Jan 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The retry count message is misleading. When maxRetries is 15, the loop runs 16 times (attempts 0-15), but the error message says "failed after 16 retries" which should be "failed after 15 retries" (since attempt 0 is the initial try, not a retry). Consider changing to "failed after %d attempts" or adjusting the calculation to show actual retry count.

Suggested change
log.Printf("[upload] Chunk %d: exhausted all %d retries, giving up", ctx.chunkID, maxRetries+1)
}
return chunkUploadResult{}, fmt.Errorf("failed after %d retries: %w", maxRetries+1, lastErr)
log.Printf("[upload] Chunk %d: exhausted all %d attempts, giving up", ctx.chunkID, maxRetries+1)
}
return chunkUploadResult{}, fmt.Errorf("failed after %d attempts: %w", maxRetries+1, lastErr)

Copilot uses AI. Check for mistakes.
Comment thread internal/turso/tursoServer.go Outdated
Comment thread internal/turso/tursoServer.go
Comment thread internal/turso/tursoServer.go
Comment thread internal/cmd/db_shell.go
Comment thread internal/turso/tursoServer.go Outdated
@LeMikaelF LeMikaelF merged commit fba4890 into main Jan 16, 2026
2 checks passed
@LeMikaelF LeMikaelF deleted the multipart-improvements branch January 16, 2026 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants