Skip to content

Commit 63359d4

Browse files
committed
fix: clear batch on flush failure and tune LMDB for low memory
When add_assets() throws during batch flush, batch.clear() was never reached causing an infinite retry loop where every subsequent file triggers another failed flush of the growing batch. Wrap both mid-loop and final flush in try/except/finally to always clear the batch. Tune LMDB for single-process server: meminit=False skips memset on buffer alloc, max_readers=4 and max_spare_txns=1 reduce overhead.
1 parent bffa526 commit 63359d4

2 files changed

Lines changed: 23 additions & 11 deletions

File tree

iscc_search/cli/add.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,17 @@ def parse_and_index_files(files, index, index_name, batch_size=100, verbose=Fals
187187
# Flush batch when full
188188
if len(batch) >= batch_size:
189189
batch_count += 1
190-
progress.update(parse_task, description=f"Indexing batch {batch_count} ({len(batch)} assets)...")
190+
flush_size = len(batch)
191+
progress.update(parse_task, description=f"Indexing batch {batch_count} ({flush_size} assets)...")
191192

192-
results = index.add_assets(index_name, batch)
193-
all_results.extend(results)
194-
batch.clear()
193+
try:
194+
results = index.add_assets(index_name, batch)
195+
all_results.extend(results)
196+
except Exception as flush_err:
197+
errors.append(f"Batch {batch_count} ({flush_size} assets): {flush_err}")
198+
logger.error(f"Batch {batch_count} failed: {flush_err}")
199+
finally:
200+
batch.clear()
195201
progress.update(parse_task, description="Parsing files...")
196202

197203
except Exception as e:
@@ -205,11 +211,17 @@ def parse_and_index_files(files, index, index_name, batch_size=100, verbose=Fals
205211
# Flush remaining assets
206212
if batch:
207213
batch_count += 1
208-
progress.update(parse_task, description=f"Indexing batch {batch_count} ({len(batch)} assets)...")
214+
flush_size = len(batch)
215+
progress.update(parse_task, description=f"Indexing batch {batch_count} ({flush_size} assets)...")
209216

210-
results = index.add_assets(index_name, batch)
211-
all_results.extend(results)
212-
batch.clear()
217+
try:
218+
results = index.add_assets(index_name, batch)
219+
all_results.extend(results)
220+
except Exception as flush_err:
221+
errors.append(f"Batch {batch_count} ({flush_size} assets): {flush_err}")
222+
logger.error(f"Batch {batch_count} failed: {flush_err}")
223+
finally:
224+
batch.clear()
213225

214226
return all_results, errors
215227

iscc_search/indexes/usearch/index.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ class UsearchIndex:
6262
"create": True,
6363
"readahead": False,
6464
"writemap": False,
65-
"meminit": True,
65+
"meminit": False,
6666
"map_async": False,
67-
"max_readers": 126,
68-
"max_spare_txns": 16,
67+
"max_readers": 4,
68+
"max_spare_txns": 1,
6969
"lock": True,
7070
}
7171

0 commit comments

Comments
 (0)