Fossil SCM
More improvements to network sync.
Commit
4ee118a6b4a48494736426fbb4b693de28c26acc
Parent
75c476ccd178dca…
1 file changed
+21
-8
+21
-8
| --- src/xfer.c | ||
| +++ src/xfer.c | ||
| @@ -483,13 +483,13 @@ | ||
| 483 | 483 | void client_sync(int pushFlag, int pullFlag, int cloneFlag){ |
| 484 | 484 | int go = 1; /* Loop until zero */ |
| 485 | 485 | int nToken; |
| 486 | 486 | const char *zSCode = db_get("server-code", "x"); |
| 487 | 487 | 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; | |
| 491 | 491 | Blob send; /* Text we are sending to the server */ |
| 492 | 492 | Blob recv; /* Reply we got back from the server */ |
| 493 | 493 | Blob line; /* A single line of the reply */ |
| 494 | 494 | Blob aToken[5]; /* A tokenization of line */ |
| 495 | 495 | Blob errmsg; /* Error message */ |
| @@ -510,23 +510,28 @@ | ||
| 510 | 510 | blob_zero(&errmsg); |
| 511 | 511 | |
| 512 | 512 | |
| 513 | 513 | while( go ){ |
| 514 | 514 | go = 0; |
| 515 | + nFile = nReq = nMsg = 0; | |
| 515 | 516 | |
| 516 | 517 | /* Generate a request to be sent to the server. |
| 517 | 518 | ** Always begin with a clone, pull, or push message |
| 518 | 519 | */ |
| 520 | + | |
| 519 | 521 | if( cloneFlag ){ |
| 520 | 522 | blob_appendf(&send, "clone\n"); |
| 521 | 523 | pushFlag = 0; |
| 522 | 524 | pullFlag = 0; |
| 525 | + nMsg++; | |
| 523 | 526 | }else if( pullFlag ){ |
| 524 | 527 | blob_appendf(&send, "pull %s %s\n", zSCode, zPCode); |
| 528 | + nMsg++; | |
| 525 | 529 | } |
| 526 | 530 | if( pushFlag ){ |
| 527 | 531 | blob_appendf(&send, "push %s %s\n", zSCode, zPCode); |
| 532 | + nMsg++; | |
| 528 | 533 | } |
| 529 | 534 | |
| 530 | 535 | if( pullFlag ){ |
| 531 | 536 | /* Send gimme message for every phantom that we hold. |
| 532 | 537 | */ |
| @@ -533,17 +538,18 @@ | ||
| 533 | 538 | Stmt q; |
| 534 | 539 | db_prepare(&q, "SELECT uuid FROM blob WHERE size<0"); |
| 535 | 540 | while( db_step(&q)==SQLITE_ROW ){ |
| 536 | 541 | const char *zUuid = db_column_text(&q, 0); |
| 537 | 542 | blob_appendf(&send,"gimme %s\n", zUuid); |
| 543 | + nReq++; | |
| 538 | 544 | } |
| 539 | 545 | db_finalize(&q); |
| 540 | 546 | } |
| 541 | 547 | |
| 542 | 548 | if( pushFlag ){ |
| 543 | 549 | /* Send the server any files that the server has requested */ |
| 544 | - nSent += send_all_pending(&send); | |
| 550 | + nFile += send_all_pending(&send); | |
| 545 | 551 | } |
| 546 | 552 | |
| 547 | 553 | if( pullFlag || pushFlag ){ |
| 548 | 554 | /* Always send our leaves */ |
| 549 | 555 | Stmt q; |
| @@ -552,16 +558,19 @@ | ||
| 552 | 558 | " (SELECT cid FROM plink EXCEPT SELECT pid FROM plink)" |
| 553 | 559 | ); |
| 554 | 560 | while( db_step(&q)==SQLITE_ROW ){ |
| 555 | 561 | const char *zUuid = db_column_text(&q, 0); |
| 556 | 562 | blob_appendf(&send, "leaf %s\n", zUuid); |
| 563 | + nMsg++; | |
| 557 | 564 | } |
| 558 | 565 | db_finalize(&q); |
| 559 | 566 | } |
| 560 | 567 | |
| 561 | 568 | /* 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; | |
| 563 | 572 | http_exchange(&send, &recv); |
| 564 | 573 | blob_reset(&send); |
| 565 | 574 | |
| 566 | 575 | /* Process the reply that came back from the server */ |
| 567 | 576 | while( blob_line(&recv, &line) ){ |
| @@ -572,19 +581,20 @@ | ||
| 572 | 581 | ** |
| 573 | 582 | ** Receive a file transmitted from the other side |
| 574 | 583 | */ |
| 575 | 584 | if( blob_eq(&aToken[0],"file") ){ |
| 576 | 585 | xfer_accept_file(&recv, aToken, nToken, &errmsg); |
| 577 | - nRcvd++; | |
| 586 | + nFile++; | |
| 578 | 587 | }else |
| 579 | 588 | |
| 580 | 589 | /* gimme UUID |
| 581 | 590 | ** |
| 582 | 591 | ** Server is requesting a file |
| 583 | 592 | */ |
| 584 | 593 | if( blob_eq(&aToken[0], "gimme") && nToken==2 |
| 585 | 594 | && blob_is_uuid(&aToken[1]) ){ |
| 595 | + nReq++; | |
| 586 | 596 | if( pushFlag ){ |
| 587 | 597 | db_multi_exec( |
| 588 | 598 | "INSERT OR IGNORE INTO pending(rid) " |
| 589 | 599 | "SELECT rid FROM blob WHERE uuid=%B AND size>=0", &aToken[1] |
| 590 | 600 | ); |
| @@ -600,10 +610,11 @@ | ||
| 600 | 610 | */ |
| 601 | 611 | if( nToken==2 |
| 602 | 612 | && (blob_eq(&aToken[0], "igot") || blob_eq(&aToken[0], "leaf")) |
| 603 | 613 | && blob_is_uuid(&aToken[1]) ){ |
| 604 | 614 | int rid = db_int(0, "SELECT rid FROM blob WHERE uuid=%B", &aToken[1]); |
| 615 | + nMsg++; | |
| 605 | 616 | if( rid>0 ){ |
| 606 | 617 | db_multi_exec( |
| 607 | 618 | "INSERT OR IGNORE INTO onremote(rid) VALUES(%d)", rid |
| 608 | 619 | ); |
| 609 | 620 | /* Add to the pending set all children of the server's leaves */ |
| @@ -632,10 +643,11 @@ | ||
| 632 | 643 | && blob_is_uuid(&aToken[1]) && blob_is_uuid(&aToken[2]) ){ |
| 633 | 644 | |
| 634 | 645 | if( blob_eq_str(&aToken[1], zSCode, -1) ){ |
| 635 | 646 | fossil_fatal("server loop"); |
| 636 | 647 | } |
| 648 | + nMsg++; | |
| 637 | 649 | if( zPCode==0 ){ |
| 638 | 650 | zPCode = mprintf("%b", &aToken[2]); |
| 639 | 651 | db_set("project-code", zPCode); |
| 640 | 652 | } |
| 641 | 653 | cloneFlag = 0; |
| @@ -661,15 +673,16 @@ | ||
| 661 | 673 | fossil_fatal("%b", &errmsg); |
| 662 | 674 | } |
| 663 | 675 | blobarray_reset(aToken, nToken); |
| 664 | 676 | } |
| 665 | 677 | 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; | |
| 668 | 681 | }; |
| 669 | 682 | http_close(); |
| 670 | 683 | db_end_transaction(0); |
| 671 | 684 | db_multi_exec( |
| 672 | 685 | "DROP TABLE onremote;" |
| 673 | 686 | "DROP TABLE pending;" |
| 674 | 687 | ); |
| 675 | 688 | } |
| 676 | 689 |
| --- 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 |