Skip to content

Add Blob Versioning Support to Azurite - #2735

Open
Rodolfo Orozco Vasquez (rorozcov) wants to merge 83 commits into
Azure:mainfrom
rorozcov:users/rorozcov/blobversioning
Open

Add Blob Versioning Support to Azurite#2735
Rodolfo Orozco Vasquez (rorozcov) wants to merge 83 commits into
Azure:mainfrom
rorozcov:users/rorozcov/blobversioning

Conversation

@rorozcov

Copy link
Copy Markdown

Title: Add Blob Versioning Support to Azurite

Summary

Adds Azure Blob Storage versioning support to Azurite, enabling applications to create, list, retrieve, and delete previous blob versions during local development.

Closes #665.

Account model

This work introduces the account model abstraction designed in collaboration with the Azurite team. The account model provides a central place for account-scoped feature configuration so additional Azure Storage capabilities can be added without coupling them directly to server startup or individual blob handlers.

Blob versioning is currently the first and only feature backed by this abstraction. The design supports Azurite's multi-account mode, allowing each configured account to enable or disable versioning independently. Accounts without an explicit versioning setting retain the existing non-versioned behavior for backward compatibility.

Motivation

Blob versioning automatically preserves previous blob states after modification or deletion. Without emulator support, applications that depend on version-aware workflows cannot be tested locally before deployment to Azure.

Implementation

  • Adds an account-level AccountModel setting for enabling blob versioning.
  • Supports file-based and inline JSON account configuration, including multiple accounts.
  • Persists account configuration in Loki metadata storage.
  • Creates version IDs as ISO 8601 timestamps when version-producing blob operations occur.
  • Supports retrieving and deleting a specific version through versionId.
  • Supports listing versions through includeVersions with version-aware continuation markers.
  • Preserves previous versions as immutable records while tracking the current version.
  • Adds versioning behavior across block, append, and page blob operations.
  • Adds VS Code extension settings for account configuration.
  • Preserves backward compatibility by defaulting accounts without versioning configuration to versioning disabled.

Configuration

Blob versioning can be configured using:

  • --accountConfigFilePath for JSON configuration files.
  • --accountConfigAsJson for inline JSON configuration.

Configured accounts must also be present in AZURITE_ACCOUNTS for authentication.

Behavior

  • Block blob writes create versions except for Put Block.
  • Page and append blobs create versions for Put Blob, Put Block List, Set Blob Metadata, and Copy Blob.
  • Put Page and Append Block do not create versions.
  • Previous versions can be read or deleted using their version ID.
  • Version IDs use JavaScript millisecond precision rather than Azure's seven fractional digits.

Limitations

This change does not currently support:

  • Soft-delete integration
  • Blob expiration with versioning
  • SAS URIs targeting specific versions
  • Version-level immutability policies

Validation

  • TypeScript build and lint pass.
  • Blob version pagination tests pass.
  • Startup and persisted-data upgrade regression tests pass with versioning disabled.

…tore. Now local testing needed. Saving progress
…tests with versioning enabled. Must add versioning related checks
@gavin-thompson-postman

Copy link
Copy Markdown

Rodolfo Orozco Vasquez (@rorozcov) Following your latest commit all of my tests now pass. Your PR now covers everything mine did and more.

Your comments about 'Loose mode' make sense to me. I just wanted to flag it to get your thoughts as it looks like it can be reasonably argued either way.

Do you know which maintainers should be tagged for review?

@rorozcov

Copy link
Copy Markdown
Author

Rodolfo Orozco Vasquez (@rorozcov) Following your latest commit all of my tests now pass. Your PR now covers everything mine did and more.

Your comments about 'Loose mode' make sense to me. I just wanted to flag it to get your thoughts as it looks like it can be reasonably argued either way.

Do you know which maintainers should be tagged for review?

Akanksha Jain (@jainakanksha-msft) is aware of the change and tracking it. It's actively being looked at but I'll let her provide the ETA.

@rorozcov

Copy link
Copy Markdown
Author

Gavin Thompson (@gavin-thompson-postman) spoke to the Azurite team. They are focused on 3.37.0 right now but that their immediate priority will be this PR. No specific ETA but I presume it's coming in the next few weeks.

CC Akanksha Jain (@jainakanksha-msft)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. Impact analysis

    • Package: azurite Blob service; no package version change.
    • Version change: Blob Versioning is added as an opt-in, per-account Loki feature.
    • Usage: Configured through --accountConfigFilePath or --accountConfigAsJson; authentication remains in AZURITE_ACCOUNTS.
    • Impact and risk: Core version lifecycle behavior is broadly aligned with Azure, but the two inline findings are merge blockers because they affect data preservation and API compatibility. SQL metadata and version-specific SAS remain unsupported and should stay explicit limitations.
  2. Build and conflict resolution

    • Commands run: npm ci --include=dev, npm run build, npm run lint, and merge-conflict inspection against current main.
    • Issues found: The PR is currently reported as dirty/conflicting with main.
    • Result: Build and lint pass at fb848e0; rebase and conflict resolution are still required.
  3. Tests

    • Tests added or updated: Broad Blob Versioning coverage across block/page/append blobs, snapshots, listing, metadata, copy, deletes, account parsing, and persistence.
    • Coverage: Missing regressions for more than 5,000 versions/snapshots sharing one blob name and cross-type replacement while previous versions exist.
    • Result: Please add both cases with the fixes.
  4. Test suite

    • Commands run: npm run build, npm run lint, npm run test:blob.
    • Passing: 668 passing.
    • Pending or failing: 3 pending, 0 failing. Production Azure parity tests are skipped/manual, so they do not provide repeatable parity validation.
  5. Changelog

    • Entry added: No.
    • Location: Please add this user-visible feature under ChangeLog.md Upcoming Release.
  6. PR comments

    • Threads reviewed: All 7 existing threads.
    • Actions taken: Verified the 6 resolved threads against the final head and retained two new blockers inline.
    • Unresolved items: The existing BlobServerFactory.createServer() thread remains valid: accountModelStore is optional in the public signature but required at runtime by BlobServer.
  7. Self-rating

    • Score: 5/10 in the current state.
    • Reasoning: Strong design direction and test breadth, offset by a potential GC data-loss path, an Azure-incompatible blob-type transition, the runtime factory break, conflicts, and missing changelog.
  8. Iteration

    • Improvements made after self-review: Traced GC through BlobReferredExtentsAsyncIterator, checked type-transition behavior against Azure Blob Versioning semantics, and validated the exact PR head locally.
  9. Summary

    • Why the update matters: This closes an important Azurite parity gap.
    • Risk if not applied: Version-aware applications cannot be tested locally; applied unchanged, historical version data can be at risk and Azurite can accept operations Azure rejects.
    • Final status: Request changes until both inline blockers, the factory contract, conflicts, and changelog are addressed.

const coll = this.db.getCollection(this.BLOBS_COLLECTION);

// By default, we include all versions. This method is mostly for
// the GC, so there is no point in adding blob versioning support.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Blocking: GC can skip live version extents. listAllBlobs() is consumed by BlobReferredExtentsAsyncIterator, but both ordering and continuation use only blob.name. If one blob has more than maxResults versions/snapshots, the first page returns records with that name and sets the same name as its marker; the next query (obj.name > marker) excludes every remaining record for that blob. Those skipped records' extents are then absent from GC's referred-extent set and can be reclaimed while still referenced. Please use a stable unique ordering/marker such as name plus version/snapshot/record identity, and add a GC regression with more than one page of records sharing the same blob name.

}
coll.remove(blobDoc);

if (this.isBlobVersioningEnabled(blob.accountName) || blobDoc.isCurrentVersion) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Blocking Azure parity issue: Azure requires all versions of a blob to have the same blob type. A block/page/append blob cannot be overwritten with another type while previous versions remain; the base blob and all versions must first be deleted. This branch archives the old current record and later inserts the incoming blob without comparing blobDoc.properties.blobType with blob.properties.blobType, so Put Blob (and the analogous Copy Blob destination path) can create mixed-type history that Azure rejects. Please validate the invariant before mutating the old record and add tests for each cross-type transition, including Copy Blob.

@jainakanksha-msft

Copy link
Copy Markdown
Member

Rodolfo Orozco Vasquez (@rorozcov) could you please update changelog and readme file, and add use case in regression test also.

@rorozcov

Copy link
Copy Markdown
Author

Rodolfo Orozco Vasquez (@rorozcov) could you please update changelog and readme file, and add use case in regression test also.

Will do! Give me 1-2 days at most.

Copilot AI and others added 2 commits September 2, 2026 18:17
…nto copilot/testblob-versioning-gc-regression-again

# Conflicts:
#	src/blob/BlobConfiguration.ts
#	src/blob/BlobEnvironment.ts
#	src/blob/BlobServer.ts
#	src/blob/BlobServerFactory.ts
#	src/blob/errors/StorageErrorFactory.ts
#	src/blob/handlers/BlobHandler.ts
#	src/blob/persistence/IBlobMetadataStore.ts
#	src/blob/persistence/LokiBlobMetadataStore.ts
#	src/blob/persistence/PageWithDelimiter.ts
#	src/blob/persistence/SqlBlobMetadataStore.ts
#	src/common/Environment.ts
#	src/common/VSCEnvironment.ts
#	src/common/VSCServerManagerBlob.ts

Co-authored-by: rorozcov <44987991+rorozcov@users.noreply.github.com>
Co-authored-by: rorozcov <44987991+rorozcov@users.noreply.github.com>
Copilot AI and others added 2 commits September 2, 2026 20:30
Co-authored-by: rorozcov <44987991+rorozcov@users.noreply.github.com>

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.

🔵 Needs a closer look

The version-aware continuation token encoding introduced in PageWithDelimiter can become ambiguous with user-controlled blob names, risking broken pagination for valid names and should be made unambiguous before approval.

Review details

Suppressed comments (4)

Previously missed (4) — in code that hasn't changed since the last review.

src/blob/persistence/PageWithDelimiter.ts:16

  • The continuation token format for version-aware listings uses a plain delimiter string (__version_marker__) to join [name, timestamp]. Since blob names are user-controlled, a blob name containing this substring will make markers ambiguous and can cause listing to fail when the marker is later parsed/split. Consider encoding the marker as a structured value (e.g., JSON array like ListAllBlobsMarker) or escaping the name component before concatenation.
    tests/blob/apis/versioning.azurite.parity.test.ts:185
  • This Azurite parity test is tagged @production in its title, which appears to be a copy/paste mistake (the file/suite is for Azurite). If you use these tags to filter test runs, this mislabel can cause the test to be skipped or miscategorized.
    src/blob/BlobServer.ts:82
  • The error thrown when accountModelStore is missing is correct, but it can be confusing because BlobServer still has a code path that constructs a default BlobConfiguration when none is provided. Consider clarifying the message so callers know BlobServer must be created via BlobServerFactory (or with an explicit configuration that includes accountModelStore).
    tests/testutils.ts:30
  • export is split across lines (export\n async function ...), which is unusual in this codebase and can be reformatted by Prettier/linting. Keeping export async function on one line improves readability and avoids style tool churn.
  • Files reviewed: 58/60 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Copilot AI and others added 4 commits September 2, 2026 21:04
Co-authored-by: rorozcov <44987991+rorozcov@users.noreply.github.com>
Co-authored-by: rorozcov <44987991+rorozcov@users.noreply.github.com>
Co-authored-by: rorozcov <44987991+rorozcov@users.noreply.github.com>
Co-authored-by: rorozcov <44987991+rorozcov@users.noreply.github.com>

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.

🔵 Needs a closer look

The change set is large and feature-defining (new persistence/config abstractions plus handler/store contract changes), so it warrants final human verification despite only minor specific issues noted.

Review details

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

tests/blob/apis/versioning.azurite.parity.test.ts:185

  • The test case name ends with @production even though this is the Azurite parity suite. This can cause the test to be skipped or mis-grouped when running with grep/tag filters.
  • Files reviewed: 59/61 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +45 to +50
const accountModels = new Map<string, AccountModel>();
accountModels.set(EMULATOR_ACCOUNT_NAME, {
key: EMULATOR_ACCOUNT_KEY,
isBlobVersioningEnabled: versioningEnabled
});
return new LokiAccountModelStore(databaseFile, true, accountModels);
Co-authored-by: rorozcov <44987991+rorozcov@users.noreply.github.com>

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.

🔵 Needs a closer look

The new continuation-token encoding for version-aware pagination is ambiguous for certain valid blob names and can break paging behavior, so it should be made robust before merge.

Review details

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

src/blob/persistence/PageWithDelimiter.ts:226

  • Continuation tokens for name+timestamp mode are currently built by joining [name, timestamp] with the hard-coded __version_marker__ separator. If a blob name contains that substring, the token becomes ambiguous and marker.split(VERSIONING_MARKER) (e.g., in LokiBlobMetadataStore.listBlobs) will fail and return 400, breaking pagination for valid blob names. Consider encoding the marker tuple as an unambiguous format (e.g., JSON string or base64 of JSON) and accepting the legacy joined format for backward compatibility.
    src/blob/persistence/LokiBlobMetadataStore.ts:166
  • PR description mentions version IDs using JavaScript millisecond precision rather than Azure's 7 fractional digits, but the implementation converts timestamps to 7 fractional digits and even uses a per-blob sub-millisecond counter (see generateVersionId). Please align the PR description (and any external docs) with the implemented 7-digit RFC3339 versionId format so expectations match runtime behavior.
  • Files reviewed: 59/61 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@rorozcov

Copy link
Copy Markdown
Author

Rodolfo Orozco Vasquez (@rorozcov) could you please update changelog and readme file, and add use case in regression test also.

Will do! Give me 1-2 days at most.

Akanksha Jain (@jainakanksha-msft)

Your comments have been addressed. I am merging main into my branch again.

I am also working on the pagination continuation token and wanted your input. Initially, I made it very simple to keep it backwards compatible with how azurite used to do it. However, it is technically opaque from Azure's point of view so I am thinking of making it opaque as well rather than azurite's current use of the blob name as the continuation token and my PR's use of blobname__Version_marker__timestamp.

Let me know what you think. If not once I merge main we should be good to go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable Blob versioning

5 participants