ErrorCode LogParser::processFileInvalidationEntry(char *buf, int size) { if (!headerParsed_) { LOG(ERROR) << "Invalid log: File invalidation entry found before transfer " "log header"; return INVALID_LOG; } int64_t timestamp, seqId; if (!encoderDecoder_.decodeFileInvalidationEntry(buf, size, timestamp, seqId)) { return INVALID_LOG; } if (parseOnly_) { std::cout << getFormattedTimestamp(timestamp) << " Invalidation entry for seq-id " << seqId << std::endl; return OK; } if (options_.resume_using_dir_tree) { LOG(ERROR) << "Can not have a file invalidation entry in directory based " "resumption mode " << seqId; return INVALID_LOG; } if (fileInfoMap_.find(seqId) == fileInfoMap_.end() && invalidSeqIds_.find(seqId) == invalidSeqIds_.end()) { LOG(ERROR) << "Invalidation entry for an unknown sequence id " << seqId; return INVALID_LOG; } fileInfoMap_.erase(seqId); invalidSeqIds_.erase(seqId); return OK; }
ErrorCode LogParser::processFileCreationEntry(char *buf, int size) { if (!headerParsed_) { LOG(ERROR) << "Invalid log: File creation entry found before transfer log header"; return INVALID_LOG; } int64_t timestamp, seqId, fileSize; std::string fileName; if (!encoderDecoder_.decodeFileCreationEntry(buf, size, timestamp, fileName, seqId, fileSize)) { return INVALID_LOG; } if (parseOnly_) { std::cout << getFormattedTimestamp(timestamp) << " File created " << fileName << " seq-id " << seqId << " file-size " << fileSize << std::endl; return OK; } if (options_.resume_using_dir_tree) { LOG(ERROR) << "Can not have a file creation entry in directory based " "resumption mode " << fileName << " " << seqId << " " << fileSize; return INVALID_LOG; } if (fileInfoMap_.find(seqId) != fileInfoMap_.end() || invalidSeqIds_.find(seqId) != invalidSeqIds_.end()) { LOG(ERROR) << "Multiple FILE_CREATION entry for same sequence-id " << fileName << " " << seqId << " " << fileSize; return INVALID_LOG; } // verify size bool sizeVerificationSuccess = false; struct stat buffer; std::string fullPath; folly::toAppend(rootDir_, fileName, &fullPath); if (stat(fullPath.c_str(), &buffer) != 0) { PLOG(ERROR) << "stat failed for " << fileName; } else { if (options_.shouldPreallocateFiles()) { sizeVerificationSuccess = (buffer.st_size >= fileSize); } else { sizeVerificationSuccess = true; } } if (sizeVerificationSuccess) { fileInfoMap_.emplace(seqId, FileChunksInfo(seqId, fileName, buffer.st_size)); seqIdToSizeMap_.emplace(seqId, fileSize); } else { LOG(INFO) << "Sanity check failed for " << fileName << " seq-id " << seqId << " file-size " << fileSize; invalidSeqIds_.insert(seqId); } return OK; }
//----------------------------------------------------------------------------- // Function: StickyNote::onTextEdited() //----------------------------------------------------------------------------- void StickyNote::onTextEdited() { QString timestamp = getFormattedTimestamp(); StickyNoteEditCommand* command = new StickyNoteEditCommand(this, textArea_->toPlainText(), contentExtension_->value(), timestamp, timestampExtension_->value()); command->redo(); emit modified(command); }
ErrorCode LogParser::processDirectoryInvalidationEntry(char *buf, int size) { int64_t timestamp; if (!encoderDecoder_.decodeDirectoryInvalidationEntry(buf, size, timestamp)) { return INVALID_LOG; } if (parseOnly_) { std::cout << getFormattedTimestamp(timestamp) << " Directory invalidated" << std::endl; return OK; } headerParsed_ = false; return INCONSISTENT_DIRECTORY; }
ErrorCode LogParser::processFileResizeEntry(char *buf, int size) { if (!headerParsed_) { LOG(ERROR) << "Invalid log: File resize entry found before transfer log header"; return INVALID_LOG; } int64_t timestamp, seqId, fileSize; if (!encoderDecoder_.decodeFileResizeEntry(buf, size, timestamp, seqId, fileSize)) { return INVALID_LOG; } if (parseOnly_) { std::cout << getFormattedTimestamp(timestamp) << " File resized," << " seq-id " << seqId << " new file-size " << fileSize << std::endl; return OK; } if (options_.resume_using_dir_tree) { LOG(ERROR) << "Can not have a file resize entry in directory based " "resumption mode " << seqId << " " << fileSize; return INVALID_LOG; } auto it = fileInfoMap_.find(seqId); if (it == fileInfoMap_.end()) { LOG(ERROR) << "File resize entry for unknown sequence-id " << seqId << " " << fileSize; return INVALID_LOG; } FileChunksInfo &chunksInfo = it->second; const std::string &fileName = chunksInfo.getFileName(); auto sizeIt = seqIdToSizeMap_.find(seqId); WDT_CHECK(sizeIt != seqIdToSizeMap_.end()); if (fileSize < sizeIt->second) { LOG(ERROR) << "File size can not reduce during resizing " << fileName << " " << seqId << " " << fileSize << " " << sizeIt->second; return INVALID_LOG; } if (options_.shouldPreallocateFiles() && fileSize > chunksInfo.getFileSize()) { LOG(ERROR) << "Size on the disk is less than the resized size for " << fileName << " seq-id " << seqId << " disk-size " << chunksInfo.getFileSize() << " resized-size " << fileSize; return INVALID_LOG; } sizeIt->second = fileSize; return OK; }
ErrorCode LogParser::processBlockWriteEntry(char *buf, int size) { if (!headerParsed_) { LOG(ERROR) << "Invalid log: Block write entry found before transfer log header"; return INVALID_LOG; } int64_t timestamp, seqId, offset, blockSize; if (!encoderDecoder_.decodeBlockWriteEntry(buf, size, timestamp, seqId, offset, blockSize)) { return INVALID_LOG; } if (parseOnly_) { std::cout << getFormattedTimestamp(timestamp) << " Block written," << " seq-id " << seqId << " offset " << offset << " block-size " << blockSize << std::endl; return OK; } if (options_.resume_using_dir_tree) { LOG(ERROR) << "Can not have a block write entry in directory based " "resumption mode " << seqId << " " << offset << " " << blockSize; return INVALID_LOG; } if (invalidSeqIds_.find(seqId) != invalidSeqIds_.end()) { LOG(INFO) << "Block entry for an invalid sequence-id " << seqId << ", ignoring"; return OK; } auto it = fileInfoMap_.find(seqId); if (it == fileInfoMap_.end()) { LOG(ERROR) << "Block entry for unknown sequence-id " << seqId << " " << offset << " " << blockSize; return INVALID_LOG; } FileChunksInfo &chunksInfo = it->second; // check whether the block is within disk size if (offset + blockSize > chunksInfo.getFileSize()) { LOG(ERROR) << "Block end point is greater than file size in disk " << chunksInfo.getFileName() << " seq-id " << seqId << " offset " << offset << " block-size " << blockSize << " file size in disk " << chunksInfo.getFileSize(); return INVALID_LOG; } chunksInfo.addChunk(Interval(offset, offset + blockSize)); return OK; }
ErrorCode LogParser::processHeaderEntry(char *buf, int size, std::string &senderIp) { int64_t timestamp; int logVersion; std::string logRecoveryId; int64_t logConfig; if (!encoderDecoder_.decodeLogHeader(buf, size, timestamp, logVersion, logRecoveryId, senderIp, logConfig)) { LOG(ERROR) << "Couldn't decode the log header"; return INVALID_LOG; } if (logVersion != TransferLogManager::LOG_VERSION) { LOG(ERROR) << "Can not parse log version " << logVersion << ", parser version " << TransferLogManager::LOG_VERSION; return INVALID_LOG; } if (senderIp.empty()) { LOG(ERROR) << "Log header has empty sender ip"; return INVALID_LOG; } if (parseOnly_) { std::cout << getFormattedTimestamp(timestamp) << " Header entry, log-version " << logVersion << " recovery-id " << logRecoveryId << " sender-ip " << senderIp << " config " << logConfig << std::endl; // we do not perform verifications for parse only mode headerParsed_ = true; return OK; } if (recoveryId_ != logRecoveryId) { LOG(ERROR) << "Current recovery-id does not match with log recovery-id " << recoveryId_ << " " << logRecoveryId; return INCONSISTENT_DIRECTORY; } if (config_ != logConfig) { LOG(ERROR) << "Current config does not match with log config " << config_ << " " << logConfig; return INCONSISTENT_DIRECTORY; } headerParsed_ = true; return OK; }
//----------------------------------------------------------------------------- // Function: StickyNote::StickyNote() //----------------------------------------------------------------------------- StickyNote::StickyNote(QGraphicsItem* parent): QGraphicsItemGroup(parent), Associable(), oldPos_(), extension_(), positionExtension_(), contentExtension_(), associationExtensions_(), timestampExtension_(), textArea_(0), timeLabel_(0), associationButton_(0) { initializeExtensions(); setItemOptions(); createGluedEdge(); createWritableArea(); createAssociationButton(); setTimestamp(getFormattedTimestamp()); connect(textArea_, SIGNAL(contentChanged()), this, SLOT(onTextEdited()), Qt::UniqueConnection); }