Skip to content

Commit 1795446

Browse files
authored
Fix initial checkpoint save (onyx-dot-app#4697)
* Fix initial checkpoint save * Improve comment * Another small fix
1 parent 335f3bb commit 1795446

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

backend/onyx/background/celery/tasks/indexing/tasks.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,21 +367,23 @@ def monitor_ccpair_indexing_taskset(
367367

368368
redis_connector_index.reset()
369369

370-
# mark the CC Pair as `ACTIVE` if it's not already
370+
# mark the CC Pair as `ACTIVE` if the attempt was a success and the
371+
# CC Pair is not active not already
372+
# This should never technically be in this state, but we'll handle it anyway
373+
index_attempt = get_index_attempt(db_session, payload.index_attempt_id)
374+
index_attempt_is_successful = index_attempt and index_attempt.status.is_successful()
371375
if (
372-
# it should never technically be in this state, but we'll handle it anyway
373-
cc_pair.status == ConnectorCredentialPairStatus.SCHEDULED
376+
index_attempt_is_successful
377+
and cc_pair.status == ConnectorCredentialPairStatus.SCHEDULED
374378
or cc_pair.status == ConnectorCredentialPairStatus.INITIAL_INDEXING
375379
):
376380
cc_pair.status = ConnectorCredentialPairStatus.ACTIVE
377381
db_session.commit()
378382

379383
# if the index attempt is successful, clear the repeated error state
380-
if cc_pair.in_repeated_error_state:
381-
index_attempt = get_index_attempt(db_session, payload.index_attempt_id)
382-
if index_attempt and index_attempt.status.is_successful():
383-
cc_pair.in_repeated_error_state = False
384-
db_session.commit()
384+
if cc_pair.in_repeated_error_state and index_attempt_is_successful:
385+
cc_pair.in_repeated_error_state = False
386+
db_session.commit()
385387

386388

387389
@shared_task(

backend/onyx/background/indexing/checkpointing_utils.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ def get_latest_valid_checkpoint(
160160
f"{latest_valid_checkpoint_candidate.id}. Previous checkpoint: "
161161
f"{previous_checkpoint}"
162162
)
163-
save_checkpoint(
164-
db_session=db_session,
165-
index_attempt_id=latest_valid_checkpoint_candidate.id,
166-
checkpoint=previous_checkpoint,
167-
)
168163
return previous_checkpoint
169164

170165

backend/onyx/background/indexing/run_indexing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,14 @@ def _run_indexing(
423423
connector=connector_runner.connector,
424424
)
425425

426+
# save the initial checkpoint to have a proper record of the
427+
# "last used checkpoint"
428+
save_checkpoint(
429+
db_session=db_session_temp,
430+
index_attempt_id=index_attempt_id,
431+
checkpoint=checkpoint,
432+
)
433+
426434
unresolved_errors = get_index_attempt_errors_for_cc_pair(
427435
cc_pair_id=ctx.cc_pair_id,
428436
unresolved_only=True,

0 commit comments

Comments
 (0)