Skip to content

Commit bdb349e

Browse files
committed
refactor(ct,solr): improve metadata sync and schema update logic #11959
Simplified metadata synchronization flow by decoupling update checks from fetching logic. Introduced flags for better handling of pending updates and reduced redundant operations. Enhanced logging for clarity. This should better avoid potential race conditions. Also, before the initial sync did not trigger an update, so the schema would have never been updated, even if the two schemas actually are different! Now, we execute the schema processing, which will take care to not replace the schema if there's really no difference between them.
1 parent 58900c9 commit bdb349e

File tree

1 file changed

+40
-39
lines changed

1 file changed

+40
-39
lines changed

conf/solr/solr-driver.sh

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -851,58 +851,59 @@ run_watch() {
851851
log_info "Running in watch mode with ${POLL_INTERVAL}s polling interval"
852852

853853
local last_checksum=""
854-
local initial_sync_done=false
854+
local needs_update="false"
855+
local pending_metadata_file=""
856+
local pending_checksum=""
855857

856858
while true; do
857859
# Update liveness indicator at the start of each cycle
858860
update_liveness
859861

860-
local metadata_file="${WORK_DIR}/metadata_fields_check.xml"
861-
862-
if fetch_metadata_fields "${metadata_file}"; then
863-
local current_checksum
864-
current_checksum=$(calculate_metadata_checksum "${metadata_file}")
865-
866-
if [[ -n "${last_checksum}" && "${current_checksum}" != "${last_checksum}" ]]; then
867-
log_info "Metadata change detected, processing schema update"
868-
869-
# Mark as not ready during update
870-
mark_not_ready
871-
872-
if process_schema_update "true"; then
873-
last_checksum="${current_checksum}"
874-
mark_ready
862+
# Only fetch metadata if we don't have a pending update
863+
if [[ "${needs_update}" == "false" ]]; then
864+
local metadata_file="${WORK_DIR}/metadata_fields_check.xml"
865+
866+
if fetch_metadata_fields "${metadata_file}"; then
867+
pending_checksum=$(calculate_metadata_checksum "${metadata_file}")
868+
869+
if [[ -z "${last_checksum}" ]]; then
870+
log_info "Initial metadata fetch, setting baseline"
871+
mark_not_ready
872+
needs_update="true"
873+
pending_metadata_file="${metadata_file}"
874+
elif [[ "${pending_checksum}" != "${last_checksum}" ]]; then
875+
log_info "Metadata change detected, processing schema update"
876+
mark_not_ready
877+
needs_update="true"
878+
pending_metadata_file="${metadata_file}"
875879
else
876-
log_error "Schema update failed"
877-
# Stay not ready until successful update
878-
fi
879-
elif [[ -z "${last_checksum}" ]]; then
880-
log_info "Initial metadata fetch, setting baseline"
881-
last_checksum="${current_checksum}"
882-
883-
# Mark ready after first successful fetch
884-
if [[ "${initial_sync_done}" == "false" ]]; then
885-
mark_ready
886-
initial_sync_done=true
880+
log_debug "No metadata changes detected"
887881
fi
888882
else
889-
log_info "No metadata changes detected"
890-
891-
# Ensure we're marked ready if we haven't done initial sync
892-
if [[ "${initial_sync_done}" == "false" ]]; then
893-
mark_ready
894-
initial_sync_done=true
895-
fi
883+
log_error "Failed to fetch metadata fields, will retry"
884+
mark_not_ready
896885
fi
897886
else
898-
log_error "Failed to fetch metadata fields, will retry"
899-
# Mark as not ready on fetch failure
900-
mark_not_ready
887+
log_info "Pending update not yet applied, retrying without re-fetching metadata"
901888
fi
902889

903-
# Update liveness before sleep
904-
update_liveness
890+
# Process pending update if needed
891+
if [[ "${needs_update}" == "true" && -n "${pending_metadata_file}" ]]; then
892+
if process_schema_update "true"; then
893+
# Update successful - use the stored checksum
894+
last_checksum="${pending_checksum}"
895+
mark_ready
896+
needs_update="false"
897+
pending_metadata_file=""
898+
pending_checksum=""
899+
else
900+
log_error "Schema update failed, will retry on next cycle"
901+
# Keep needs_update="true", pending_metadata_file, and pending_checksum intact for retry
902+
fi
903+
fi
905904

905+
# Update liveness before sleep (just to be sure - the processing may have taking longer than expected)
906+
update_liveness
906907
sleep "${POLL_INTERVAL}"
907908
done
908909
}

0 commit comments

Comments
 (0)