@@ -27,6 +27,8 @@ std::ostream &operator<<(std::ostream &os,
27
27
return os;
28
28
}
29
29
30
+ // TODO: TLOG or such that does LOG(level) << *this << " " << rest...
31
+
30
32
int64_t readAtLeast (ServerSocket &s, char *buf, int64_t max, int64_t atLeast,
31
33
int64_t len) {
32
34
VLOG (4 ) << " readAtLeast len " << len << " max " << max << " atLeast "
@@ -115,13 +117,13 @@ ReceiverState ReceiverThread::listen() {
115
117
threadStats_.setLocalErrorCode (code);
116
118
return FAILED;
117
119
}
118
- LOG (INFO) << " Sleeping after failed attempt " << retry;
120
+ LOG (INFO) << * this << " Sleeping after failed attempt " << retry;
119
121
/* sleep override */
120
122
usleep (options_.sleep_millis * 1000 );
121
123
}
122
124
// one more/last try (stays true if it worked above)
123
125
if (socket_->listen () != OK) {
124
- LOG (ERROR) << " Unable to listen/bind despite retries" ;
126
+ LOG (ERROR) << * this << " Unable to listen/bind despite retries" ;
125
127
threadStats_.setLocalErrorCode (CONN_ERROR);
126
128
return FAILED;
127
129
}
@@ -143,13 +145,14 @@ ReceiverState ReceiverThread::acceptFirstConnection() {
143
145
return ACCEPT_WITH_TIMEOUT;
144
146
}
145
147
if (acceptAttempts == options_.max_accept_retries ) {
146
- LOG (ERROR) << " unable to accept after " << acceptAttempts << " attempts" ;
148
+ LOG (ERROR) << *this << " Unable to accept after " << acceptAttempts
149
+ << " attempts" ;
147
150
threadStats_.setLocalErrorCode (CONN_ERROR);
148
151
return FAILED;
149
152
}
150
153
if (wdtParent_->getCurAbortCode () != OK) {
151
- LOG (ERROR) << " Thread marked to abort while trying to accept first "
152
- << " connection. Num attempts " << acceptAttempts;
154
+ LOG (ERROR) << * this << " Thread marked to abort while trying to accept "
155
+ << " first connection. Num attempts " << acceptAttempts;
153
156
// Even though there is a transition FAILED here
154
157
// getCurAbortCode() is going to be checked again in the receiveOne.
155
158
// So this is pretty much irrelevant
@@ -194,7 +197,7 @@ ReceiverState ReceiverThread::acceptWithTimeout() {
194
197
socket_->acceptNextConnection (timeout, curConnectionVerified_);
195
198
curConnectionVerified_ = false ;
196
199
if (code != OK) {
197
- LOG (ERROR) << " accept() failed with timeout " << timeout;
200
+ LOG (ERROR) << * this << " accept() failed with timeout " << timeout;
198
201
threadStats_.setLocalErrorCode (code);
199
202
return FINISH_WITH_ERROR;
200
203
}
@@ -224,7 +227,7 @@ ReceiverState ReceiverThread::sendLocalCheckpoint() {
224
227
checkpoints);
225
228
int written = socket_->write (buf_, checkpointLen);
226
229
if (written != checkpointLen) {
227
- LOG (ERROR) << " unable to write local checkpoint. write mismatch "
230
+ LOG (ERROR) << * this << " unable to write local checkpoint. write mismatch "
228
231
<< checkpointLen << " " << written;
229
232
threadStats_.setLocalErrorCode (SOCKET_WRITE_ERROR);
230
233
return ACCEPT_WITH_TIMEOUT;
@@ -241,8 +244,8 @@ ReceiverState ReceiverThread::readNextCmd() {
241
244
numRead_ = readAtLeast (*socket_, buf_ + off_, bufSize_ - off_,
242
245
Protocol::kMinBufLength , numRead_);
243
246
if (numRead_ < Protocol::kMinBufLength ) {
244
- LOG (ERROR) << " socket read failure " << Protocol::kMinBufLength << " "
245
- << numRead_;
247
+ LOG (ERROR) << * this << " socket read failure " << Protocol::kMinBufLength
248
+ << " " << numRead_;
246
249
threadStats_.setLocalErrorCode (SOCKET_READ_ERROR);
247
250
return ACCEPT_WITH_TIMEOUT;
248
251
}
@@ -259,7 +262,7 @@ ReceiverState ReceiverThread::readNextCmd() {
259
262
if (cmd == Protocol::SIZE_CMD) {
260
263
return PROCESS_SIZE_CMD;
261
264
}
262
- LOG (ERROR) << " received an unknown cmd " << cmd;
265
+ LOG (ERROR) << * this << " received an unknown cmd " << cmd;
263
266
threadStats_.setLocalErrorCode (PROTOCOL_ERROR);
264
267
return FINISH_WITH_ERROR;
265
268
}
@@ -273,7 +276,7 @@ ReceiverState ReceiverThread::processSettingsCmd() {
273
276
bool success = Protocol::decodeVersion (
274
277
buf_, off_, oldOffset_ + Protocol::kMaxVersion , senderProtocolVersion);
275
278
if (!success) {
276
- LOG (ERROR) << " Unable to decode version " << threadIndex_;
279
+ LOG (ERROR) << * this << " Unable to decode version " << threadIndex_;
277
280
threadStats_.setLocalErrorCode (PROTOCOL_ERROR);
278
281
return FINISH_WITH_ERROR;
279
282
}
@@ -283,13 +286,14 @@ ReceiverState ReceiverThread::processSettingsCmd() {
283
286
int negotiatedProtocol = Protocol::negotiateProtocol (
284
287
senderProtocolVersion, threadProtocolVersion_);
285
288
if (negotiatedProtocol == 0 ) {
286
- LOG (WARNING) << " Can not support sender with version "
289
+ LOG (WARNING) << * this << " Can not support sender with version "
287
290
<< senderProtocolVersion << " , aborting!" ;
288
291
threadStats_.setLocalErrorCode (VERSION_INCOMPATIBLE);
289
292
return SEND_ABORT_CMD;
290
293
} else {
291
294
LOG_IF (INFO, threadProtocolVersion_ != negotiatedProtocol)
292
- << " Changing receiver protocol version to " << negotiatedProtocol;
295
+ << *this << " Changing receiver protocol version to "
296
+ << negotiatedProtocol;
293
297
threadProtocolVersion_ = negotiatedProtocol;
294
298
if (negotiatedProtocol != senderProtocolVersion) {
295
299
threadStats_.setLocalErrorCode (VERSION_MISMATCH);
@@ -309,7 +313,7 @@ ReceiverState ReceiverThread::processSettingsCmd() {
309
313
auto senderId = settings.transferId ;
310
314
auto transferId = wdtParent_->getTransferId ();
311
315
if (transferId != senderId) {
312
- LOG (ERROR) << " Receiver and sender id mismatch " << senderId << " "
316
+ LOG (ERROR) << * this << " Receiver and sender id mismatch " << senderId << " "
313
317
<< transferId;
314
318
threadStats_.setLocalErrorCode (ID_MISMATCH);
315
319
return SEND_ABORT_CMD;
@@ -374,7 +378,7 @@ ReceiverState ReceiverThread::processFileCmd() {
374
378
ErrorCode transferStatus = (ErrorCode)buf_[off_++];
375
379
if (transferStatus != OK) {
376
380
// TODO: use this status information to implement fail fast mode
377
- VLOG (1 ) << " sender entered into error state "
381
+ VLOG (1 ) << * this << " sender entered into error state "
378
382
<< errorCodeToStr (transferStatus);
379
383
}
380
384
int16_t headerLen = folly::loadUnaligned<int16_t >(buf_ + off_);
@@ -387,7 +391,8 @@ ReceiverState ReceiverThread::processFileCmd() {
387
391
readAtLeast (*socket_, buf_ + end, bufSize_ - end, headerLen, numRead_);
388
392
}
389
393
if (numRead_ < headerLen) {
390
- LOG (ERROR) << " Unable to read full header " << headerLen << " " << numRead_;
394
+ LOG (ERROR) << *this << " Unable to read full header " << headerLen << " "
395
+ << numRead_;
391
396
threadStats_.setLocalErrorCode (SOCKET_READ_ERROR);
392
397
return ACCEPT_WITH_TIMEOUT;
393
398
}
@@ -402,7 +407,7 @@ ReceiverState ReceiverThread::processFileCmd() {
402
407
threadStats_.addHeaderBytes (headerBytes);
403
408
threadStats_.addEffectiveBytes (headerBytes, 0 );
404
409
if (!success) {
405
- LOG (ERROR) << " Error decoding at"
410
+ LOG (ERROR) << * this << " Error decoding at"
406
411
<< " ooff:" << oldOffset_ << " off_: " << off_
407
412
<< " numRead_: " << numRead_;
408
413
threadStats_.setLocalErrorCode (PROTOCOL_ERROR);
@@ -411,7 +416,7 @@ ReceiverState ReceiverThread::processFileCmd() {
411
416
412
417
// received a well formed file cmd, apply the pending checkpoint update
413
418
checkpointIndex_ = pendingCheckpointIndex_;
414
- VLOG (1 ) << " Read id:" << blockDetails.fileName
419
+ VLOG (1 ) << * this << " Read id:" << blockDetails.fileName
415
420
<< " size:" << blockDetails.dataSize << " ooff:" << oldOffset_
416
421
<< " off_: " << off_ << " numRead_: " << numRead_;
417
422
auto &fileCreator = wdtParent_->getFileCreator ();
@@ -461,7 +466,8 @@ ReceiverState ReceiverThread::processFileCmd() {
461
466
// also means no leftOver so it's ok we use buf_ from start
462
467
while (writer.getTotalWritten () < blockDetails.dataSize ) {
463
468
if (wdtParent_->getCurAbortCode () != OK) {
464
- LOG (ERROR) << " Thread marked for abort while processing a file."
469
+ LOG (ERROR) << *this << " Thread marked for abort while processing "
470
+ << blockDetails.fileName << " " << blockDetails.seqId
465
471
<< " port : " << socket_->getPort ();
466
472
return FAILED;
467
473
}
@@ -488,8 +494,8 @@ ReceiverState ReceiverThread::processFileCmd() {
488
494
if (writer.getTotalWritten () != blockDetails.dataSize ) {
489
495
// This can only happen if there are transmission errors
490
496
// Write errors to disk are already taken care of above
491
- LOG (ERROR) << " could not read entire content for " << blockDetails. fileName
492
- << " port " << socket_->getPort ();
497
+ LOG (ERROR) << * this << " could not read entire content for "
498
+ << blockDetails. fileName << " port " << socket_->getPort ();
493
499
threadStats_.setLocalErrorCode (SOCKET_READ_ERROR);
494
500
return ACCEPT_WITH_TIMEOUT;
495
501
}
@@ -523,14 +529,14 @@ ReceiverState ReceiverThread::processFileCmd() {
523
529
numRead_ = readAtLeast (*socket_, buf_ + off_, bufSize_ - off_,
524
530
Protocol::kMinBufLength , numRead_);
525
531
if (numRead_ < Protocol::kMinBufLength ) {
526
- LOG (ERROR) << " socket read failure " << Protocol::kMinBufLength << " "
527
- << numRead_;
532
+ LOG (ERROR) << * this << " socket read failure " << Protocol::kMinBufLength
533
+ << " " << numRead_;
528
534
threadStats_.setLocalErrorCode (SOCKET_READ_ERROR);
529
535
return ACCEPT_WITH_TIMEOUT;
530
536
}
531
537
Protocol::CMD_MAGIC cmd = (Protocol::CMD_MAGIC)buf_[off_++];
532
538
if (cmd != Protocol::FOOTER_CMD) {
533
- LOG (ERROR) << " Expecting footer cmd, but received " << cmd;
539
+ LOG (ERROR) << * this << " Expecting footer cmd, but received " << cmd;
534
540
threadStats_.setLocalErrorCode (PROTOCOL_ERROR);
535
541
return FINISH_WITH_ERROR;
536
542
}
@@ -540,13 +546,13 @@ ReceiverState ReceiverThread::processFileCmd() {
540
546
buf_, off_, oldOffset_ + Protocol::kMaxFooter , receivedChecksum,
541
547
receivedTag, (footerType_ == ENC_TAG_FOOTER));
542
548
if (!success) {
543
- LOG (ERROR) << " Unable to decode footer cmd" ;
549
+ LOG (ERROR) << * this << " Unable to decode footer cmd" ;
544
550
threadStats_.setLocalErrorCode (PROTOCOL_ERROR);
545
551
return FINISH_WITH_ERROR;
546
552
}
547
553
if (footerType_ == CHECKSUM_FOOTER) {
548
554
if (checksum != receivedChecksum) {
549
- LOG (ERROR) << " Checksum mismatch " << checksum << " "
555
+ LOG (ERROR) << * this << " Checksum mismatch " << checksum << " "
550
556
<< receivedChecksum << " port " << socket_->getPort ()
551
557
<< " file " << blockDetails.fileName ;
552
558
threadStats_.setLocalErrorCode (CHECKSUM_MISMATCH);
@@ -558,7 +564,7 @@ ReceiverState ReceiverThread::processFileCmd() {
558
564
blocksWaitingVerification_.emplace_back (blockDetails);
559
565
if (decryptorCtxSaved) {
560
566
if (!socket_->verifyTag (receivedTag)) {
561
- LOG (ERROR) << *this << " GCM encryption tag mismatch "
567
+ LOG (ERROR) << *this << " GCM encryption tag mismatch "
562
568
<< folly::humanify (receivedTag) << " file "
563
569
<< blockDetails.fileName ;
564
570
threadStats_.setLocalErrorCode (ENCRYPTION_ERROR);
@@ -597,7 +603,7 @@ void ReceiverThread::markReceivedBlocksVerified() {
597
603
ReceiverState ReceiverThread::processDoneCmd () {
598
604
VLOG (1 ) << *this << " entered PROCESS_DONE_CMD state" ;
599
605
if (numRead_ != Protocol::kMinBufLength ) {
600
- LOG (ERROR) << " Unexpected state for done command"
606
+ LOG (ERROR) << * this << " Unexpected state for done command"
601
607
<< " off_: " << off_ << " numRead_: " << numRead_;
602
608
threadStats_.setLocalErrorCode (PROTOCOL_ERROR);
603
609
return FINISH_WITH_ERROR;
@@ -610,7 +616,7 @@ ReceiverState ReceiverThread::processDoneCmd() {
610
616
oldOffset_ + Protocol::kMaxDone ,
611
617
numBlocksSend, totalSenderBytes);
612
618
if (!success) {
613
- LOG (ERROR) << " Unable to decode done cmd" ;
619
+ LOG (ERROR) << * this << " Unable to decode done cmd" ;
614
620
threadStats_.setLocalErrorCode (PROTOCOL_ERROR);
615
621
return FINISH_WITH_ERROR;
616
622
}
@@ -629,7 +635,7 @@ ReceiverState ReceiverThread::processSizeCmd() {
629
635
bool success = Protocol::decodeSize (
630
636
buf_, off_, oldOffset_ + Protocol::kMaxSize , totalSenderBytes);
631
637
if (!success) {
632
- LOG (ERROR) << " Unable to decode size cmd" ;
638
+ LOG (ERROR) << * this << " Unable to decode size cmd" ;
633
639
threadStats_.setLocalErrorCode (PROTOCOL_ERROR);
634
640
return FINISH_WITH_ERROR;
635
641
}
@@ -686,7 +692,7 @@ ReceiverState ReceiverThread::sendFileChunks() {
686
692
threadStats_.addHeaderBytes (written);
687
693
}
688
694
if (written != off) {
689
- LOG (ERROR) << " Socket write error " << off << " " << written;
695
+ LOG (ERROR) << * this << " socket write err " << off << " " << written;
690
696
threadStats_.setLocalErrorCode (SOCKET_READ_ERROR);
691
697
execFunnel->notifyFail ();
692
698
return ACCEPT_WITH_TIMEOUT;
@@ -712,7 +718,7 @@ ReceiverState ReceiverThread::sendFileChunks() {
712
718
numEntriesWritten += numEntriesEncoded;
713
719
}
714
720
if (numEntriesWritten != numParsedChunksInfo) {
715
- LOG (ERROR) << " Could not write all the file chunks "
721
+ LOG (ERROR) << * this << " Could not write all the file chunks "
716
722
<< numParsedChunksInfo << " " << numEntriesWritten;
717
723
threadStats_.setLocalErrorCode (SOCKET_WRITE_ERROR);
718
724
execFunnel->notifyFail ();
@@ -722,7 +728,8 @@ ReceiverState ReceiverThread::sendFileChunks() {
722
728
int64_t toRead = 1 ;
723
729
int64_t numRead = socket_->read (buf_, toRead);
724
730
if (numRead != toRead) {
725
- LOG (ERROR) << " Socket read error " << toRead << " " << numRead;
731
+ LOG (ERROR) << *this << " Socket read error " << toRead << " "
732
+ << numRead;
726
733
threadStats_.setLocalErrorCode (SOCKET_READ_ERROR);
727
734
execFunnel->notifyFail ();
728
735
return ACCEPT_WITH_TIMEOUT;
@@ -750,7 +757,7 @@ ReceiverState ReceiverThread::sendGlobalCheckpoint() {
750
757
751
758
int written = socket_->write (buf_, off_);
752
759
if (written != off_) {
753
- LOG (ERROR) << " unable to write error checkpoints" ;
760
+ LOG (ERROR) << * this << " unable to write error checkpoints" ;
754
761
threadStats_.setLocalErrorCode (SOCKET_WRITE_ERROR);
755
762
return ACCEPT_WITH_TIMEOUT;
756
763
} else {
@@ -785,7 +792,7 @@ ReceiverState ReceiverThread::sendDoneCmd() {
785
792
VLOG (1 ) << *this << " entered SEND_DONE_CMD state" ;
786
793
buf_[0 ] = Protocol::DONE_CMD;
787
794
if (socket_->write (buf_, 1 ) != 1 ) {
788
- PLOG (ERROR) << " unable to send DONE " << threadIndex_;
795
+ PLOG (ERROR) << * this << " unable to send DONE " << threadIndex_;
789
796
threadStats_.setLocalErrorCode (SOCKET_WRITE_ERROR);
790
797
return ACCEPT_WITH_TIMEOUT;
791
798
}
@@ -883,15 +890,15 @@ ReceiverState ReceiverThread::waitForFinishOrNewCheckpoint() {
883
890
884
891
void ReceiverThread::start () {
885
892
if (buf_ == nullptr ) {
886
- LOG (ERROR) << " Unable to allocate buffer" ;
893
+ LOG (ERROR) << * this << " Unable to allocate buffer" ;
887
894
threadStats_.setLocalErrorCode (MEMORY_ALLOCATION_ERROR);
888
895
return ;
889
896
}
890
897
ReceiverState state = LISTEN;
891
898
while (true ) {
892
899
ErrorCode abortCode = wdtParent_->getCurAbortCode ();
893
900
if (abortCode != OK) {
894
- LOG (ERROR) << " Transfer aborted " << socket_->getPort () << " "
901
+ LOG (ERROR) << * this << " Transfer aborted " << socket_->getPort () << " "
895
902
<< errorCodeToStr (abortCode);
896
903
threadStats_.setLocalErrorCode (ABORT);
897
904
break ;
@@ -928,7 +935,7 @@ ErrorCode ReceiverThread::init() {
928
935
return ERROR;
929
936
}
930
937
checkpoint_.port = socket_->getPort ();
931
- LOG (INFO) << " Listening on port " << socket_->getPort ();
938
+ LOG (INFO) << * this << " Listening on port " << socket_->getPort ();
932
939
return OK;
933
940
}
934
941
0 commit comments