Fossil SCM

More improvements to network sync.

drh 2007-07-23 20:40 UTC trunk
Commit 4ee118a6b4a48494736426fbb4b693de28c26acc
1 file changed +21 -8
+21 -8
--- src/xfer.c
+++ src/xfer.c
@@ -483,13 +483,13 @@
483483
void client_sync(int pushFlag, int pullFlag, int cloneFlag){
484484
int go = 1; /* Loop until zero */
485485
int nToken;
486486
const char *zSCode = db_get("server-code", "x");
487487
const char *zPCode = db_get("project-code", 0);
488
- int nSent = 0;
489
- int nRcvd = 0;
490
- int nCycle = 0;
488
+ int nFile = 0;
489
+ int nMsg = 0;
490
+ int nReq = 0;
491491
Blob send; /* Text we are sending to the server */
492492
Blob recv; /* Reply we got back from the server */
493493
Blob line; /* A single line of the reply */
494494
Blob aToken[5]; /* A tokenization of line */
495495
Blob errmsg; /* Error message */
@@ -510,23 +510,28 @@
510510
blob_zero(&errmsg);
511511
512512
513513
while( go ){
514514
go = 0;
515
+ nFile = nReq = nMsg = 0;
515516
516517
/* Generate a request to be sent to the server.
517518
** Always begin with a clone, pull, or push message
518519
*/
520
+
519521
if( cloneFlag ){
520522
blob_appendf(&send, "clone\n");
521523
pushFlag = 0;
522524
pullFlag = 0;
525
+ nMsg++;
523526
}else if( pullFlag ){
524527
blob_appendf(&send, "pull %s %s\n", zSCode, zPCode);
528
+ nMsg++;
525529
}
526530
if( pushFlag ){
527531
blob_appendf(&send, "push %s %s\n", zSCode, zPCode);
532
+ nMsg++;
528533
}
529534
530535
if( pullFlag ){
531536
/* Send gimme message for every phantom that we hold.
532537
*/
@@ -533,17 +538,18 @@
533538
Stmt q;
534539
db_prepare(&q, "SELECT uuid FROM blob WHERE size<0");
535540
while( db_step(&q)==SQLITE_ROW ){
536541
const char *zUuid = db_column_text(&q, 0);
537542
blob_appendf(&send,"gimme %s\n", zUuid);
543
+ nReq++;
538544
}
539545
db_finalize(&q);
540546
}
541547
542548
if( pushFlag ){
543549
/* Send the server any files that the server has requested */
544
- nSent += send_all_pending(&send);
550
+ nFile += send_all_pending(&send);
545551
}
546552
547553
if( pullFlag || pushFlag ){
548554
/* Always send our leaves */
549555
Stmt q;
@@ -552,16 +558,19 @@
552558
" (SELECT cid FROM plink EXCEPT SELECT pid FROM plink)"
553559
);
554560
while( db_step(&q)==SQLITE_ROW ){
555561
const char *zUuid = db_column_text(&q, 0);
556562
blob_appendf(&send, "leaf %s\n", zUuid);
563
+ nMsg++;
557564
}
558565
db_finalize(&q);
559566
}
560567
561568
/* Exchange messages with the server */
562
- printf("Sending %d files to server\n", nSent);
569
+ printf("Send: %d files, %d requests, %d other messages\n",
570
+ nFile, nReq, nMsg);
571
+ nFile = nReq = nMsg = 0;
563572
http_exchange(&send, &recv);
564573
blob_reset(&send);
565574
566575
/* Process the reply that came back from the server */
567576
while( blob_line(&recv, &line) ){
@@ -572,19 +581,20 @@
572581
**
573582
** Receive a file transmitted from the other side
574583
*/
575584
if( blob_eq(&aToken[0],"file") ){
576585
xfer_accept_file(&recv, aToken, nToken, &errmsg);
577
- nRcvd++;
586
+ nFile++;
578587
}else
579588
580589
/* gimme UUID
581590
**
582591
** Server is requesting a file
583592
*/
584593
if( blob_eq(&aToken[0], "gimme") && nToken==2
585594
&& blob_is_uuid(&aToken[1]) ){
595
+ nReq++;
586596
if( pushFlag ){
587597
db_multi_exec(
588598
"INSERT OR IGNORE INTO pending(rid) "
589599
"SELECT rid FROM blob WHERE uuid=%B AND size>=0", &aToken[1]
590600
);
@@ -600,10 +610,11 @@
600610
*/
601611
if( nToken==2
602612
&& (blob_eq(&aToken[0], "igot") || blob_eq(&aToken[0], "leaf"))
603613
&& blob_is_uuid(&aToken[1]) ){
604614
int rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &aToken[1]);
615
+ nMsg++;
605616
if( rid>0 ){
606617
db_multi_exec(
607618
"INSERT OR IGNORE INTO onremote(rid) VALUES(%d)", rid
608619
);
609620
/* Add to the pending set all children of the server's leaves */
@@ -632,10 +643,11 @@
632643
&& blob_is_uuid(&aToken[1]) && blob_is_uuid(&aToken[2]) ){
633644
634645
if( blob_eq_str(&aToken[1], zSCode, -1) ){
635646
fossil_fatal("server loop");
636647
}
648
+ nMsg++;
637649
if( zPCode==0 ){
638650
zPCode = mprintf("%b", &aToken[2]);
639651
db_set("project-code", zPCode);
640652
}
641653
cloneFlag = 0;
@@ -661,15 +673,16 @@
661673
fossil_fatal("%b", &errmsg);
662674
}
663675
blobarray_reset(aToken, nToken);
664676
}
665677
blob_reset(&recv);
666
- printf("Received %d files from server\n", nRcvd);
667
- nSent = nRcvd = 0;
678
+ printf("Received: %d files, %d requests, %d other messages\n",
679
+ nFile, nReq, nMsg);
680
+ nFile = nReq = nMsg = 0;
668681
};
669682
http_close();
670683
db_end_transaction(0);
671684
db_multi_exec(
672685
"DROP TABLE onremote;"
673686
"DROP TABLE pending;"
674687
);
675688
}
676689
--- src/xfer.c
+++ src/xfer.c
@@ -483,13 +483,13 @@
483 void client_sync(int pushFlag, int pullFlag, int cloneFlag){
484 int go = 1; /* Loop until zero */
485 int nToken;
486 const char *zSCode = db_get("server-code", "x");
487 const char *zPCode = db_get("project-code", 0);
488 int nSent = 0;
489 int nRcvd = 0;
490 int nCycle = 0;
491 Blob send; /* Text we are sending to the server */
492 Blob recv; /* Reply we got back from the server */
493 Blob line; /* A single line of the reply */
494 Blob aToken[5]; /* A tokenization of line */
495 Blob errmsg; /* Error message */
@@ -510,23 +510,28 @@
510 blob_zero(&errmsg);
511
512
513 while( go ){
514 go = 0;
 
515
516 /* Generate a request to be sent to the server.
517 ** Always begin with a clone, pull, or push message
518 */
 
519 if( cloneFlag ){
520 blob_appendf(&send, "clone\n");
521 pushFlag = 0;
522 pullFlag = 0;
 
523 }else if( pullFlag ){
524 blob_appendf(&send, "pull %s %s\n", zSCode, zPCode);
 
525 }
526 if( pushFlag ){
527 blob_appendf(&send, "push %s %s\n", zSCode, zPCode);
 
528 }
529
530 if( pullFlag ){
531 /* Send gimme message for every phantom that we hold.
532 */
@@ -533,17 +538,18 @@
533 Stmt q;
534 db_prepare(&q, "SELECT uuid FROM blob WHERE size<0");
535 while( db_step(&q)==SQLITE_ROW ){
536 const char *zUuid = db_column_text(&q, 0);
537 blob_appendf(&send,"gimme %s\n", zUuid);
 
538 }
539 db_finalize(&q);
540 }
541
542 if( pushFlag ){
543 /* Send the server any files that the server has requested */
544 nSent += send_all_pending(&send);
545 }
546
547 if( pullFlag || pushFlag ){
548 /* Always send our leaves */
549 Stmt q;
@@ -552,16 +558,19 @@
552 " (SELECT cid FROM plink EXCEPT SELECT pid FROM plink)"
553 );
554 while( db_step(&q)==SQLITE_ROW ){
555 const char *zUuid = db_column_text(&q, 0);
556 blob_appendf(&send, "leaf %s\n", zUuid);
 
557 }
558 db_finalize(&q);
559 }
560
561 /* Exchange messages with the server */
562 printf("Sending %d files to server\n", nSent);
 
 
563 http_exchange(&send, &recv);
564 blob_reset(&send);
565
566 /* Process the reply that came back from the server */
567 while( blob_line(&recv, &line) ){
@@ -572,19 +581,20 @@
572 **
573 ** Receive a file transmitted from the other side
574 */
575 if( blob_eq(&aToken[0],"file") ){
576 xfer_accept_file(&recv, aToken, nToken, &errmsg);
577 nRcvd++;
578 }else
579
580 /* gimme UUID
581 **
582 ** Server is requesting a file
583 */
584 if( blob_eq(&aToken[0], "gimme") && nToken==2
585 && blob_is_uuid(&aToken[1]) ){
 
586 if( pushFlag ){
587 db_multi_exec(
588 "INSERT OR IGNORE INTO pending(rid) "
589 "SELECT rid FROM blob WHERE uuid=%B AND size>=0", &aToken[1]
590 );
@@ -600,10 +610,11 @@
600 */
601 if( nToken==2
602 && (blob_eq(&aToken[0], "igot") || blob_eq(&aToken[0], "leaf"))
603 && blob_is_uuid(&aToken[1]) ){
604 int rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &aToken[1]);
 
605 if( rid>0 ){
606 db_multi_exec(
607 "INSERT OR IGNORE INTO onremote(rid) VALUES(%d)", rid
608 );
609 /* Add to the pending set all children of the server's leaves */
@@ -632,10 +643,11 @@
632 && blob_is_uuid(&aToken[1]) && blob_is_uuid(&aToken[2]) ){
633
634 if( blob_eq_str(&aToken[1], zSCode, -1) ){
635 fossil_fatal("server loop");
636 }
 
637 if( zPCode==0 ){
638 zPCode = mprintf("%b", &aToken[2]);
639 db_set("project-code", zPCode);
640 }
641 cloneFlag = 0;
@@ -661,15 +673,16 @@
661 fossil_fatal("%b", &errmsg);
662 }
663 blobarray_reset(aToken, nToken);
664 }
665 blob_reset(&recv);
666 printf("Received %d files from server\n", nRcvd);
667 nSent = nRcvd = 0;
 
668 };
669 http_close();
670 db_end_transaction(0);
671 db_multi_exec(
672 "DROP TABLE onremote;"
673 "DROP TABLE pending;"
674 );
675 }
676
--- src/xfer.c
+++ src/xfer.c
@@ -483,13 +483,13 @@
483 void client_sync(int pushFlag, int pullFlag, int cloneFlag){
484 int go = 1; /* Loop until zero */
485 int nToken;
486 const char *zSCode = db_get("server-code", "x");
487 const char *zPCode = db_get("project-code", 0);
488 int nFile = 0;
489 int nMsg = 0;
490 int nReq = 0;
491 Blob send; /* Text we are sending to the server */
492 Blob recv; /* Reply we got back from the server */
493 Blob line; /* A single line of the reply */
494 Blob aToken[5]; /* A tokenization of line */
495 Blob errmsg; /* Error message */
@@ -510,23 +510,28 @@
510 blob_zero(&errmsg);
511
512
513 while( go ){
514 go = 0;
515 nFile = nReq = nMsg = 0;
516
517 /* Generate a request to be sent to the server.
518 ** Always begin with a clone, pull, or push message
519 */
520
521 if( cloneFlag ){
522 blob_appendf(&send, "clone\n");
523 pushFlag = 0;
524 pullFlag = 0;
525 nMsg++;
526 }else if( pullFlag ){
527 blob_appendf(&send, "pull %s %s\n", zSCode, zPCode);
528 nMsg++;
529 }
530 if( pushFlag ){
531 blob_appendf(&send, "push %s %s\n", zSCode, zPCode);
532 nMsg++;
533 }
534
535 if( pullFlag ){
536 /* Send gimme message for every phantom that we hold.
537 */
@@ -533,17 +538,18 @@
538 Stmt q;
539 db_prepare(&q, "SELECT uuid FROM blob WHERE size<0");
540 while( db_step(&q)==SQLITE_ROW ){
541 const char *zUuid = db_column_text(&q, 0);
542 blob_appendf(&send,"gimme %s\n", zUuid);
543 nReq++;
544 }
545 db_finalize(&q);
546 }
547
548 if( pushFlag ){
549 /* Send the server any files that the server has requested */
550 nFile += send_all_pending(&send);
551 }
552
553 if( pullFlag || pushFlag ){
554 /* Always send our leaves */
555 Stmt q;
@@ -552,16 +558,19 @@
558 " (SELECT cid FROM plink EXCEPT SELECT pid FROM plink)"
559 );
560 while( db_step(&q)==SQLITE_ROW ){
561 const char *zUuid = db_column_text(&q, 0);
562 blob_appendf(&send, "leaf %s\n", zUuid);
563 nMsg++;
564 }
565 db_finalize(&q);
566 }
567
568 /* Exchange messages with the server */
569 printf("Send: %d files, %d requests, %d other messages\n",
570 nFile, nReq, nMsg);
571 nFile = nReq = nMsg = 0;
572 http_exchange(&send, &recv);
573 blob_reset(&send);
574
575 /* Process the reply that came back from the server */
576 while( blob_line(&recv, &line) ){
@@ -572,19 +581,20 @@
581 **
582 ** Receive a file transmitted from the other side
583 */
584 if( blob_eq(&aToken[0],"file") ){
585 xfer_accept_file(&recv, aToken, nToken, &errmsg);
586 nFile++;
587 }else
588
589 /* gimme UUID
590 **
591 ** Server is requesting a file
592 */
593 if( blob_eq(&aToken[0], "gimme") && nToken==2
594 && blob_is_uuid(&aToken[1]) ){
595 nReq++;
596 if( pushFlag ){
597 db_multi_exec(
598 "INSERT OR IGNORE INTO pending(rid) "
599 "SELECT rid FROM blob WHERE uuid=%B AND size>=0", &aToken[1]
600 );
@@ -600,10 +610,11 @@
610 */
611 if( nToken==2
612 && (blob_eq(&aToken[0], "igot") || blob_eq(&aToken[0], "leaf"))
613 && blob_is_uuid(&aToken[1]) ){
614 int rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &aToken[1]);
615 nMsg++;
616 if( rid>0 ){
617 db_multi_exec(
618 "INSERT OR IGNORE INTO onremote(rid) VALUES(%d)", rid
619 );
620 /* Add to the pending set all children of the server's leaves */
@@ -632,10 +643,11 @@
643 && blob_is_uuid(&aToken[1]) && blob_is_uuid(&aToken[2]) ){
644
645 if( blob_eq_str(&aToken[1], zSCode, -1) ){
646 fossil_fatal("server loop");
647 }
648 nMsg++;
649 if( zPCode==0 ){
650 zPCode = mprintf("%b", &aToken[2]);
651 db_set("project-code", zPCode);
652 }
653 cloneFlag = 0;
@@ -661,15 +673,16 @@
673 fossil_fatal("%b", &errmsg);
674 }
675 blobarray_reset(aToken, nToken);
676 }
677 blob_reset(&recv);
678 printf("Received: %d files, %d requests, %d other messages\n",
679 nFile, nReq, nMsg);
680 nFile = nReq = nMsg = 0;
681 };
682 http_close();
683 db_end_transaction(0);
684 db_multi_exec(
685 "DROP TABLE onremote;"
686 "DROP TABLE pending;"
687 );
688 }
689

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button