lance-format / lance-format/lance
Cleanup does not remove empty directories
Open
Nobody has claimed this yet.
chore
- Dominant language
- Rust
- Stars
- 7.1k
- Forks
- 852
- Avg merge
- 3d 18h
- Merged PRs (30d)
- 272
Description
If I create an index and then delete it I am left with an empty directory (named after the index uuid)
import lance
import shutil
import pyarrow as pa
import glob
import datetime
shutil.rmtree("/tmp/test.lance", ignore_errors=True)
ds = lance.write_dataset(pa.table({"x": range(1000)}), "/tmp/test.lance")
num_folders = len(glob.glob("/tmp/test.lance/_indices/*"))
num_files = len(glob.glob("/tmp/test.lance/_indices/**/*.lance"))
print(f"Before creating an index there are {num_folders} folders and {num_files} files in the _indices directory")
ds.create_scalar_index("x", "BTREE")
num_folders = len(glob.glob("/tmp/test.lance/_indices/*"))
num_files = len(glob.glob("/tmp/test.lance/_indices/**/*.lance"))
print(f"After creating an index there are {num_folders} folders and {num_files} files in the _indices directory")
ds.drop_index("x_idx")
num_folders = len(glob.glob("/tmp/test.lance/_indices/*"))
num_files = len(glob.glob("/tmp/test.lance/_indices/**/*.lance"))
print(f"After dropping an index there are {num_folders} folders and {num_files} files in the _indices directory")
ds.cleanup_old_versions(older_than=datetime.timedelta(days=0))
num_folders = len(glob.glob("/tmp/test.lance/_indices/*"))
num_files = len(glob.glob("/tmp/test.lance/_indices/**/*.lance"))
print(f"After cleanup there are {num_folders} folders and {num_files} files in the _indices directory")
The output is:
Before creating an index there are 0 folders and 0 files in the _indices directory
After creating an index there are 1 folders and 2 files in the _indices directory
After dropping an index there are 1 folders and 2 files in the _indices directory
After cleanup there are 1 folders and 0 files in the _indices directory
This only matters when using local disk and not object storage.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the local-disk case using the Python sequence in the issue, focusing on create_scalar_index, drop_index, and cleanup_old_versions under the _indices directory. Trace how cleanup removes index files and verify the local directory is also removed when it becomes empty; the existing reproduction should end with no leftover index directory.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- data-engineering
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100