Changeset 12734 in project


Ignore:
Timestamp:
12/03/08 10:24:13 (11 years ago)
Author:
azul
Message:

Retry if we get a database-locked error.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/svnwiki-chicken/trunk/svnwiki-chicken.scm

    r12729 r12734  
    4444          (format (current-error-port) "Creating initial tables in DB: ~A~%" db-path)
    4545          (scheme-definitions-db-create env))))
    46     (let ((result
    47             (iterator->stream
    48               (lambda (capture stop)
    49                 (receive (stmt rest)
    50                          (sqlite3:prepare *db* query)
    51                   (apply (stream-wrap-proc-string sqlite3:for-each-row) (compose capture vector) stmt params)
    52                   (sqlite3:finalize! stmt))))))
    53       (stream-length result) ; force execution
    54       result)))
     46    (let loop ((attempt 0))
     47      (condition-case
     48        (let ((result
     49                (iterator->stream
     50                  (lambda (capture stop)
     51                    (receive (stmt rest)
     52                             (sqlite3:prepare *db* query)
     53                      (apply (stream-wrap-proc-string sqlite3:for-each-row) (compose capture vector) stmt params)
     54                      (sqlite3:finalize! stmt))))))
     55          (stream-length result) ; force execution
     56          result)
     57        (e (exn sqlite3)
     58           (format (current-error-port) "SQLite error: ~A, attempt ~A~%"
     59                   ((condition-property-accessor 'sqlite3 'status) e)
     60                   attempt)
     61           (cond
     62             ((and (member ((condition-property-accessor 'sqlite3 'status) e) '(locked busy))
     63                   (< attempt *max-retries*))
     64              (let ((seconds-wait (expt 2 attempt)))
     65                (format (current-error-port) (svnwiki-translate #f "scheme-definitions database locked, attempt #~A, retry in ~A seconds~%") attempt seconds-wait)
     66                (sleep seconds-wait))
     67              (loop (+ attempt 1)))
     68             (else
     69              (signal e))))))))
    5570
    5671(define (scheme-definitions-db-create env)
Note: See TracChangeset for help on using the changeset viewer.