feat(cli): add branch command for local instance database management#788
feat(cli): add branch command for local instance database management#788erayack wants to merge 4 commits intoHelixDB:mainfrom
Conversation
This commit introduces a new `branch` command to the Helix CLI, allowing users to create branches of local instance databases. The command supports options for specifying output directories, deploying the branched instance, and configuring instance names and ports. Additionally, it includes updates to the configuration structure to handle data directories and enhances the handling of instance data paths across various commands.
Greptile's behavior is changing!From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
|
I think this should start a new instance using the copied files |
|
Hi @xav-db, you want the Is it correct? |
|
yeah although I think it shouldn't need a --deploy flag. we already have a backup command that copies the lmdb files properly. I would use this then rerun the existing docker build on a new port as a new container. does this sound good? @erayack |
|
Yes, much more simple. Thanks for direction @xav-db
|
|
Lovely job, will review shortly! |
|
Any update? @xav-db |
|
Apologies i've been extremely ill the past few days, getting back to it now |
|
Get well soon, no rush. @xav-db |
Description
helix branchto snapshot local LMDB data into a new directory (with optional deploy), with safe overwrite prompts and default.helix/.branchesoutput.data_dirinhelix.tomland use it for backup/start/push/delete output and Docker volume mounts.HELIX_CACHE_DIRplus test-safe cache roots.fs2dependency inhelix-clifor cross-process file locking.helix-cli/README.md) and contributor command list (CONTRIBUTORS.md).C:parsing issues ('src/docker.rs').Related Issues
#787.
Checklist when merging to main
rustfmthelix-cli/Cargo.tomlandhelixdb/Cargo.tomlAdditional Notes
Cache behavior:
HELIX_CACHE_DIRoverrides the default repo cache location for build/check flows.Dependency note:
helix-clinow depends onfs2for file locking./separators and quoted inhost:containervolume specs.Tests
Tests are passing.
Tests Added
helix-cli/src/tests/branch_tests.rstest_resolve_output_dir_defaultstest_resolve_output_dir_relative_pathtest_branch_persists_deploy_configtest_prepare_output_user_dir_rejects_existing_dataGreptile Summary
This PR implements the
helix branchcommand to safely clone LMDB databases for local instances, with optional deployment. The implementation reuses existing LMDBenv.copy_to_path()logic from the backup command.Key Changes
Branch Command: Creates atomic LMDB snapshots to
.helix/.branches/<timestamp>(default). Includes overwrite protection with interactive prompts and size warnings for databases >10GB.Data Directory Persistence: Added optional
data_dirfield toLocalInstanceConfiginhelix.toml, enabling custom data locations. Commands likestart,delete, andbackupnow respect this configuration.Cache Locking: Implemented dual-locking (in-process
Mutex+ cross-process file lock viafs2) for the Helix repo cache inbuildandcheckcommands. Prevents concurrent cache mutations and supportsHELIX_CACHE_DIRoverride.Windows Path Handling: Normalized and quoted Windows absolute paths in Docker Compose volume specs to avoid
C:parsing issues ("C:/path:/data"format).Test Isolation: Tests now use per-thread, per-process temporary cache directories to avoid conflicts with user caches.
Testing
Four unit tests added covering output directory resolution, config persistence, and overwrite protection.
Important Files Changed
Sequence Diagram
sequenceDiagram participant User participant CLI as helix branch participant Project as ProjectContext participant Config as helix.toml participant LMDB as LMDB Env participant Docker as DockerManager participant Build as build::run User->>CLI: helix branch <instance> [--deploy] [--name <name>] CLI->>Project: find_and_load() Project->>Config: load instance config Config-->>CLI: LocalInstanceConfig CLI->>CLI: resolve_output_dir() Note over CLI: Default: .helix/.branches/<timestamp><br/>or .helix/.volumes/<branch-name> if --deploy CLI->>CLI: prepare_output_user_dir() alt Directory exists with data CLI->>User: Prompt for overwrite confirmation User-->>CLI: Confirm/Cancel end CLI->>LMDB: Open read-only snapshot LMDB-->>CLI: Environment handle CLI->>LMDB: copy_to_path(output_dir/user/data.mdb) LMDB-->>CLI: Atomic copy complete alt --deploy flag set CLI->>CLI: select_available_port() CLI->>Config: persist_branch_config() Note over Config: Add new instance with data_dir Config->>Config: save helix.toml CLI->>Docker: check_runtime_available() CLI->>Build: run(branch_name) Note over Build: Builds Docker image<br/>with branched data Build-->>CLI: Build complete CLI->>Docker: start_instance(branch_name) Docker-->>CLI: Container running CLI->>User: Display connection info end CLI-->>User: Branch created successfully