Overview
Comment: | Added template for transaction wrapped db writes pulled from c847 |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | multi-transport |
Files: | files | file ages | folders |
SHA1: |
f4c05ffd2b4d5002bea9225d75b060e5 |
User & Date: | matt on 2013-01-29 00:14:53 |
Other Links: | branch diff | manifest | tags |
Context
2013-01-29
| ||
10:15 | Merged multi-transport to trunk, all tests passed check-in: 19f85b577e user: mrwellan tags: trunk | |
00:14 | Added template for transaction wrapped db writes pulled from c847 Closed-Leaf check-in: f4c05ffd2b user: matt tags: multi-transport | |
2013-01-28
| ||
22:14 | Enabled http transport check-in: c3d256ef96 user: matt tags: multi-transport | |
Changes
Modified db.scm from [37752c9579] to [56cbe800e8].
︙ | ︙ | |||
1105 1106 1107 1108 1109 1110 1111 | ;; db:updater is run in a thread to write out the cached data periodically ;; (define (db:updater) ;; (debug:print-info 4 "Starting cache processing") ;; (let loop () ;; (thread-sleep! 10) ;; move save time around to minimize regular collisions? ;; (db:write-cached-data) ;; (loop))) | | > > > | 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 | ;; db:updater is run in a thread to write out the cached data periodically ;; (define (db:updater) ;; (debug:print-info 4 "Starting cache processing") ;; (let loop () ;; (thread-sleep! 10) ;; move save time around to minimize regular collisions? ;; (db:write-cached-data) ;; (loop))) ;; The queue is a list of vectors where the zeroth slot indicates the type of query to ;; apply and the second slot is the time of the query and the third entry is a list of ;; values to be applied ;; ;; NOTE: Can remove the regex and base64 encoding for zmq (define (db:obj->string obj) (case *transport-type* ((fs) obj) ((http) (string-substitute (regexp "=") "_" |
︙ | ︙ | |||
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 | flush sync set-verbosity killserver)) ;; not used, intended to indicate to run in calling process (define db:run-local-queries '()) ;; rollup-tests-pass-fail)) ;; The queue is a list of vectors where the zeroth slot indicates the type of query to ;; apply and the second slot is the time of the query and the third entry is a list of ;; values to be applied ;; (define (db:process-queue db pubsock indata) (let* ((data (sort indata (lambda (a b) | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 | flush sync set-verbosity killserver)) ;; not used, intended to indicate to run in calling process (define db:run-local-queries '()) ;; rollup-tests-pass-fail)) (define (db:write-cached-data) (open-run-close (lambda (db . junkparams) (let ((queries (make-hash-table)) (data #f)) (mutex-lock! *incoming-mutex*) (set! data (sort *incoming-data* (lambda (a b)(< (vector-ref a 1)(vector-ref b 1))))) (set! *incoming-data* '()) (mutex-unlock! *incoming-mutex*) (if (> (length data) 0) (debug:print-info 4 "Writing cached data " data)) ;; prepare the needed statements (for-each (lambda (request-item) (let ((stmt-key (vector-ref request-item 0))) (if (not (hash-table-ref/default queries stmt-key #f)) (let ((stmt (alist-ref stmt-key db:queries))) (if stmt (hash-table-set! queries stmt-key (sqlite3:prepare db (car stmt))) (debug:print 0 "ERROR: Missing query spec for " stmt-key "!")))))) data) (let outerloop ((special-qry #f) (stmts data)) (if special-qry ;; handle a query that cannot be part of the grouped queries (let* ((stmt-key (vector-ref special-qry 0)) (qry (hash-table-ref queries stmt-key)) (params (vector-ref speical-qry 2))) (apply sqlite3:execute db qry params) (if (not (null? stmts)) (outerloop #f stmts))) ;; handle normal queries (sqlite3:with-transaction db (lambda () (debug:print-info 11 "flushing " stmts " to db") (if (not (null? stmts)) (let innerloop ((hed (car stmts)) (tal (cdr stmts))) (let ((params (vector-ref hed 2)) (stmt-key (vector-ref hed 0))) (if (not (member stmt-key db:special-queries)) (begin (debug:print-info 11 "Executing " stmt-key " for " params) (apply sqlite3:execute (hash-table-ref queries stmt-key) params) (if (not (null? tal)) (innerloop (car tal)(cdr tal)))) (outerloop hed tal))))))))) (for-each (lambda (stmt-key) (sqlite3:finalize! (hash-table-ref queries stmt-key))) (hash-table-keys queries)) (let ((cache-size (length data))) (if (> cache-size *max-cache-size*) (set! *max-cache-size* cache-size))) )) #f)) ;; The queue is a list of vectors where the zeroth slot indicates the type of query to ;; apply and the second slot is the time of the query and the third entry is a list of ;; values to be applied ;; (define (db:process-queue db pubsock indata) (let* ((data (sort indata (lambda (a b) |
︙ | ︙ |