Skip to content

feat: builder-style MemWAL initialization API#6815

Merged
jackye1995 merged 5 commits into
lance-format:mainfrom
touch-of-grey:WriterDefaults
May 18, 2026
Merged

feat: builder-style MemWAL initialization API#6815
jackye1995 merged 5 commits into
lance-format:mainfrom
touch-of-grey:WriterDefaults

Conversation

@touch-of-grey

@touch-of-grey touch-of-grey commented May 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces the struct-based MemWAL initialization API with a fluent builder on
Dataset, and persists default ShardWriter configuration in the MemWAL index.

Dataset::initialize_mem_wal() returns an InitializeMemWalBuilder:

dataset
    .initialize_mem_wal()
    .bucket_sharding("id", 16)
    .maintained_indexes(["id_btree"])
    .writer_config_defaults(ShardWriterConfig::default().with_durable_write(false))
    .execute()
    .await?;
  • bucket_sharding(column, num_buckets), unsharded(), and
    identity_sharding(column) are high-level sharding strategies. They own the
    ShardingSpec construction and validation that callers previously did by
    hand; num_shards is derived from the sharding choice.
  • writer_config_defaults(ShardWriterConfig) records the tunable writer
    configuration as the persisted defaults — a new map<string, string> writer_config_defaults field on the MemWalIndexDetails protobuf message —
    so every writer, across processes and restarts, starts from the same
    defaults. add_writer_config_default records arbitrary extra keys.
  • The Python initialize_mem_wal binding accepts the full builder surface
    (sharding, maintained indexes, writer-config defaults) and invokes the
    builder; a new mem_wal_index_details binding reads the recorded details back.
  • Removed: MemWalConfig, MemWalShardConfig, initialize_mem_wal_with_shards.

Context

While reviewing lancedb/lancedb#3396, @jackye1995 noted that per-writer tuning
knobs are runtime configuration and should not be persisted as part of the
sharding spec. That holds for a writer's live ShardWriterConfig, which stays
non-persisted. This PR records only the defaults: without a persisted
default, writers would be configured independently and could silently drift
apart.

@jackye1995 also asked for a builder style so bucket sharding is easy to set,
moving the hash-bucket spec logic out of the LanceDB layer into Lance. The
builder owns all three sharding strategies (bucket, unsharded, identity), so
LanceDB's set_lsm_write_spec can call the builder directly instead of
hand-building shard specs.

Add a `writer_defaults` map to `MemWalIndexDetails` so the default
ShardWriter configuration is persisted and resumes across writers,
recorded at `initialize_mem_wal` time via `MemWalConfig.writer_defaults`.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added enhancement New feature or request A-python Python bindings labels May 17, 2026
Comment thread python/src/dataset.rs Outdated
};

let config = lance::dataset::mem_wal::MemWalConfig {
writer_defaults: Default::default(),

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.

I think at this point we should probably use a builder style. Some logic in your lancedb PR can also be moved here like the logic to do sharding with hash bucket, not shard, etc.

@codecov

codecov Bot commented May 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.86352% with 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance/src/dataset/mem_wal/api.rs 87.90% 25 Missing and 5 partials ⚠️
rust/lance/src/dataset/mem_wal/write.rs 99.23% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Replace the MemWalConfig / MemWalShardConfig structs and the
initialize_mem_wal / initialize_mem_wal_with_shards pair with a fluent
InitializeMemWalBuilder returned by Dataset::initialize_mem_wal.

The builder exposes high-level sharding strategies — bucket_sharding(column,
num_buckets) and unsharded() — owning the ShardingSpec construction and
validation that previously lived in the LanceDB layer. num_shards is now
derived from the sharding choice instead of being a separate input.
@touch-of-grey touch-of-grey changed the title feat: persist default ShardWriter configs in MemWAL index feat: builder-style MemWAL initialization API May 17, 2026
identity_sharding(column) shards by the raw value of a scalar column
(the "identity" transform), for data already partitioned by that column.
It validates that the column exists and is a scalar type usable as a
shard key, and records an open-ended shard count.
Comment thread python/src/dataset.rs Outdated
/// Requires the dataset schema to have at least one field with
/// the `lance-schema:unenforced-primary-key` metadata.
#[pyo3(signature=(maintained_indexes=None, region_spec=None))]
#[pyo3(signature=(maintained_indexes=None))]

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.

Should make sure python can take all input segments in this function and then invoke the builder in the binding

Comment thread rust/lance/src/dataset/mem_wal/api.rs Outdated
))
/// These are defaults only; an individual writer may still override any
/// value at runtime in its own (non-persisted) `ShardWriterConfig`.
pub fn writer_defaults<I, K, V>(mut self, defaults: I) -> Self

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.

We should just move all the ones you had in lancedb over here to allow setting specific config defaults. We can leave a add_writer_default to add arbitrary config defaults.

The Python initialize_mem_wal binding now accepts every builder input —
sharding strategy (bucket / identity / unsharded), maintained indexes, and
ShardWriter config defaults — and invokes InitializeMemWalBuilder. Adds a
mem_wal_index_details binding for reading the recorded MemWAL details back.

The builder's writer-defaults API is replaced by writer_config_defaults, which
takes a ShardWriterConfig and persists its tunable fields, plus
add_writer_default for arbitrary keys.
Comment thread protos/table.proto Outdated
// configuration. These are defaults only: an individual writer may
// still override any value at runtime in its own ShardWriterConfig
// (which is not persisted).
map<string, string> writer_defaults = 11;

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.

we should also rename it as writer_config_defaults

Comment thread rust/lance/src/dataset/mem_wal/api.rs Outdated
///
/// Use this for keys not covered by
/// [`writer_config_defaults`](Self::writer_config_defaults).
pub fn add_writer_default(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {

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.

similarly, add_writer_config_default

Renames the persisted MemWalIndexDetails field (protobuf field 11), the
InitializeMemWalBuilder API, and the Python binding accordingly;
add_writer_default becomes add_writer_config_default.

@jackye1995 jackye1995 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.

this looks great! thanks for the fixes

@jackye1995
jackye1995 merged commit 2f7a96f into lance-format:main May 18, 2026
28 of 30 checks passed
touch-of-grey added a commit to touch-of-grey/lancedb that referenced this pull request May 18, 2026
Now that lance-format/lance#6815 has merged, point the Lance dependency at
the main branch and rewrite set_lsm_write_spec to call the new
InitializeMemWalBuilder (bucket_sharding / unsharded), removing the local
shard-spec construction boilerplate.
touch-of-grey added a commit to touch-of-grey/lancedb that referenced this pull request May 18, 2026
The MemWAL builder changes (lance-format/lance#6815) are now released in
v7.0.0-beta.12; replace the temporary main-branch dependency with the tag.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-python Python bindings enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants