uint64_t ShardMigrationWriter::GetThroughput() { uint64_t now; now = NowClock(); if (now > startTime) return (uint64_t)(bytesSent / ((now - startTime)/1000.0)); else return 0; }
void ShardMigrationWriter::Begin(ClusterMessage& request) { ConfigState* configState; ConfigShard* configShard; ConfigShardServer* configShardServer; ASSERT(!isActive); ASSERT(cursor == NULL); configState = shardServer->GetConfigState(); configShard = configState->GetShard(request.srcShardID); ASSERT(configShard != NULL); configShardServer = configState->GetShardServer(request.nodeID); ASSERT(configShardServer != NULL); quorumProcessor = shardServer->GetQuorumProcessor(configShard->quorumID); ASSERT(quorumProcessor != NULL); isActive = true; nodeID = request.nodeID; quorumID = request.quorumID; srcShardID = request.srcShardID; dstShardID = request.dstShardID; bytesTotal = environment->GetSize(QUORUM_DATABASE_DATA_CONTEXT, srcShardID); startTime = NowClock(); CONTEXT_TRANSPORT->AddNode(nodeID, configShardServer->endpoint); Log_Debug("ShardMigrationWriter::Begin() nodeID = %U", nodeID); Log_Debug("ShardMigrationWriter::Begin() quorumID = %U", quorumID); Log_Debug("ShardMigrationWriter::Begin() srcShardID = %U", srcShardID); Log_Debug("ShardMigrationWriter::Begin() dstShardID = %U", dstShardID); Log_Message("Migrating shard %U into quorum %U as shard %U (sending)", srcShardID, quorumID, dstShardID); sendFirst = true; EventLoop::Add(&onTimeout); CONTEXT_TRANSPORT->RegisterWriteReadyness(nodeID, MFUNC(ShardMigrationWriter, OnWriteReadyness)); }
void MessageConnection::OnRead() { bool yield, closed; unsigned pos, msglength, nread, msgbegin, msgend, required; uint64_t start; Stopwatch sw; ReadBuffer msg; if (!readActive) { if (resumeRead.IsActive()) STOP_FAIL(1, "Program bug: resumeRead.IsActive() should be false."); EventLoop::Add(&resumeRead); return; } sw.Start(); Log_Trace("Read buffer: %B", tcpread.buffer); tcpread.requested = IO_READ_ANY; pos = 0; start = NowClock(); yield = false; while(true) { msglength = BufferToUInt64(tcpread.buffer->GetBuffer() + pos, tcpread.buffer->GetLength() - pos, &nread); if (msglength > tcpread.buffer->GetSize() - NumDigits(msglength) - 1) { Log_Trace(); required = msglength + NumDigits(msglength) + 1; if (required > MESSAGING_MAX_SIZE) { Log_Trace(); OnClose(); return; } tcpread.buffer->Allocate(required); break; } if (nread == 0 || (unsigned) tcpread.buffer->GetLength() - pos <= nread) break; if (tcpread.buffer->GetCharAt(pos + nread) != ':') { Log_Trace("Message protocol error"); OnClose(); return; } msgbegin = pos + nread + 1; msgend = pos + nread + 1 + msglength; if ((unsigned) tcpread.buffer->GetLength() < msgend) { // read more //tcpread.requested = msgend - pos; break; } msg.SetBuffer(tcpread.buffer->GetBuffer() + msgbegin); msg.SetLength(msglength); closed = OnMessage(msg); if (closed) return; pos = msgend; // if the user called Close() in OnMessageRead() if (state != CONNECTED) return; if (tcpread.buffer->GetLength() == msgend) break; if (NowClock() - start >= YIELD_TIME || !readActive) { // let other code run every YIELD_TIME msec yield = true; if (resumeRead.IsActive()) STOP_FAIL(1, "Program bug: resumeRead.IsActive() should be false."); EventLoop::Add(&resumeRead); break; } } if (pos > 0) { memmove(tcpread.buffer->GetBuffer(), tcpread.buffer->GetBuffer() + pos, tcpread.buffer->GetLength() - pos); tcpread.buffer->Shorten(pos); } if (state == CONNECTED && !tcpread.active && !yield) IOProcessor::Add(&tcpread); sw.Stop(); Log_Trace("time spent in OnRead(): %U", sw.Elapsed()); }
void StorageCommitJob::Execute() { startTime = NowClock(); logSegment->Commit(); }