示例#1
0
MessageConnection::MessageConnection()
{
    resumeRead.SetCallable(MFUNC(MessageConnection, OnResumeRead));
    flushWrites.SetCallable(MFUNC(MessageConnection, OnFlushWrites));
    writeBuffers[0].Allocate(MESSAGING_BUFFER_THRESHOLD);
    writeBuffers[1].Allocate(MESSAGING_BUFFER_THRESHOLD);
    autoFlush = true;
    readActive = true;
}
示例#2
0
void PaxosProposer::Init(QuorumContext* context_)
{
    context = context_;
    
    prepareTimeout.SetCallable(MFUNC(PaxosProposer, OnPrepareTimeout));
    prepareTimeout.SetDelay(PAXOS_TIMEOUT);
    proposeTimeout.SetCallable(MFUNC(PaxosProposer, OnProposeTimeout));
    proposeTimeout.SetDelay(PAXOS_TIMEOUT);

    vote = NULL;
    state.Init();
}
void StorageAsyncBulkCursor::OnNextChunk()
{
    ReadBuffer                  startKey;
    StorageFileChunk*           fileChunk;
    StorageMemoChunk*           memoChunk;
    StorageAsyncBulkResult*     result;
    StorageMemoChunkLister      memoLister;
    StorageUnwrittenChunkLister unwrittenLister;
    
    if (itChunk == NULL)
        itChunk = shard->GetChunks().First();
    else
        itChunk = shard->GetChunks().Next(itChunk);
    
    if (itChunk == NULL)
    {
        lastResult = NULL;
        Call(onComplete);
        return;
    }

    if ((*itChunk)->GetChunkState() == StorageChunk::Written)
    {
        fileChunk = (StorageFileChunk*) (*itChunk);
        chunkName = fileChunk->GetFilename();
        threadPool->Execute(MFUNC(StorageAsyncBulkCursor, AsyncReadFileChunk));
    }
    else if ((*itChunk)->GetChunkState() == StorageChunk::Unwritten)
    {
        fileChunk = (StorageFileChunk*) (*itChunk);
        unwrittenLister.Init(fileChunk, startKey, 0, 0);
        result = new StorageAsyncBulkResult(this);
        result->dataPage = *unwrittenLister.GetDataPage();
        result->onComplete = onComplete;
        lastResult = result;
        // direct callback, maybe yieldTimer would be better
        result->OnComplete();        
    }
    else if ((*itChunk)->GetChunkState() == StorageChunk::Serialized)
    {
        memoChunk = (StorageMemoChunk*) (*itChunk);
        memoLister.Init(memoChunk, startKey, 0, 0);
        result = new StorageAsyncBulkResult(this);
        result->dataPage = *memoLister.GetDataPage();
        result->onComplete = onComplete;
        lastResult = result;
        // direct callback, maybe yieldTimer would be better
        result->OnComplete();
    }
    else
    {
        // memoChunk
        // TODO: serialize memoChunk and suspend write operations
    }
}
示例#4
0
ShardLockManager::ShardLockManager()
{
    removeCachedLocks.SetCallable(MFUNC(ShardLockManager, OnRemoveCachedLocks));
    removeCachedLocks.SetDelay(LOCK_CHECK_FREQUENCY);

    numLocked = 0;
    lockExpireTime = LOCK_EXPIRE_TIME;
    maxCacheTime = LOCK_CACHE_TIME;
    maxCacheCount = LOCK_CACHE_COUNT;
    maxPoolCount = LOCK_POOL_COUNT;
}
void ShardMigrationWriter::Abort()
{
    Log_Message("Aborting shard migration...");
    
    CONTEXT_TRANSPORT->UnregisterWriteReadyness(nodeID, MFUNC(ShardMigrationWriter, OnWriteReadyness));
    Reset();

    if (cursor != NULL)
    {
        delete cursor;
        cursor = NULL;
    }
}
示例#6
0
void Watchdog::Start(unsigned timeout_, Callable& callback_)
{
    ASSERT(thread == NULL);

    timeout = timeout_;
    callback = callback_;

    thread = ThreadPool::Create(1);
    thread->Execute(MFUNC(Watchdog, ThreadFunc));

    running = true;
    thread->Start();
}
示例#7
0
// This function is executed in the threadPool
void StorageAsyncGet::AsyncLoadPage()
{
    Callable            asyncGet;
    StorageFileChunk*   fileChunk;
    
    fileChunk = (StorageFileChunk*) (*itChunk);
    if (stage == BLOOM_PAGE)
        lastLoadedPage = fileChunk->AsyncLoadBloomPage();
    else if (stage == INDEX_PAGE)
        lastLoadedPage = fileChunk->AsyncLoadIndexPage();
    else if (stage == DATA_PAGE)
        lastLoadedPage = fileChunk->AsyncLoadDataPage(index, offset);
    
    asyncGet = MFUNC(StorageAsyncGet, ExecuteAsyncGet);
    IOProcessor::Complete(&asyncGet);
}
void ShardMigrationWriter::SendCommit()
{
    ClusterMessage msg;
    
    msg.ShardMigrationCommit(quorumID, dstShardID);
    CONTEXT_TRANSPORT->SendClusterMessage(nodeID, msg);

    Log_Message("Finished sending shard %U...", srcShardID);

    if (cursor != NULL)
    {
        delete cursor;
        cursor = NULL;
    }

    CONTEXT_TRANSPORT->UnregisterWriteReadyness(nodeID, MFUNC(ShardMigrationWriter, OnWriteReadyness));

    Reset();
}
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));
}
// this runs in async thread
void StorageAsyncBulkCursor::AsyncReadFileChunk()
{
    StorageChunkReader      reader;
    StorageDataPage*        dataPage;
    StorageAsyncBulkResult* result;
    Callable                onNextChunk = MFUNC(StorageAsyncBulkCursor, OnNextChunk);
    
    reader.Open(chunkName, MAX_PRELOAD_THRESHOLD);
    
    lastResult = NULL;
    result = new StorageAsyncBulkResult(this);
    dataPage = reader.FirstDataPage();
    
    while (dataPage != NULL)
    {
        // rate control
        while (lastResult != NULL || env->yieldThreads || env->asyncGetThread->GetNumPending() > 0)
        {
            MSleep(1);
        }

        if (isAborted || env->shuttingDown)
        {
            // abort cursor
            delete result;
            delete this;
            return;
        }
    
        TransferDataPage(result, dataPage);
        OnResult(result);
        
        result = new StorageAsyncBulkResult(this);
        dataPage = reader.NextDataPage();
    }
    
    OnResult(result);
    IOProcessor::Complete(&onNextChunk);
}
示例#11
0
void ShardMigrationWriter::SendFirst()
{
    ClusterMessage      msg;
    ReadBuffer          key;
    ReadBuffer          value;

    ASSERT(cursor == NULL);
    cursor = environment->GetBulkCursor(QUORUM_DATABASE_DATA_CONTEXT, srcShardID);
    cursor->SetOnBlockShard(MFUNC(ShardMigrationWriter, OnBlockShard));

    msg.ShardMigrationBegin(quorumID, srcShardID, dstShardID);
    CONTEXT_TRANSPORT->SendClusterMessage(nodeID, msg);

    Log_Debug("ShardMigrationWriter sending BEGIN");

    // send first KV
    kv = cursor->First();
    if (kv)
        SendItem(kv);
    else
        SendCommit();
}
示例#12
0
void ConfigServerApp::Init()
{
    int         sdbpPort;
    Endpoint    httpEndpoint;
    ReadBuffer  docroot;
    ReadBuffer  prefix;
    ReadBuffer  index;
        
    httpHandler.SetConfigServer(&configServer);
    httpServer.Init(configFile.GetIntValue("http.port", 8080));
    httpServer.RegisterHandler(&httpHandler);
         
    docroot.Wrap(configFile.GetValue("http.documentRoot", "."));
    prefix.Wrap(configFile.GetValue("http.staticPrefix", "/webadmin"));
    index.Wrap(configFile.GetValue("http.directoryIndex", "index.html"));

    httpFileHandler.Init(docroot, prefix);
    httpFileHandler.SetDirectoryIndex(index);
    httpServer.RegisterHandler(&httpFileHandler);
    
    sdbpPort = configFile.GetIntValue("sdbp.port", 7080);
    sdbpServer.Init(sdbpPort);
    sdbpServer.SetContext(&configServer);

    // start configServer only after network servers are started
    configServer.Init();

    configServer.GetHTTPEndpoint(httpEndpoint);
    Log_Message("Web admin is started at http://%s%R", httpEndpoint.ToString(), &prefix);
    Log_Message("Waiting for connections on port %d", sdbpPort);
    
    statTimer.SetDelay(configFile.GetIntValue("controller.logStatTime", 0));
    if (statTimer.GetDelay() != 0)
    {
        statTimer.SetCallable(MFUNC(ConfigServerApp, OnStatTimer));
        EventLoop::Add(&statTimer);
    }
}
示例#13
0
void ConfigServerApp::Init()
{
    int         sdbpPort;
    Endpoint    httpEndpoint;
    ReadBuffer  docroot;
    ReadBuffer  prefix;
    ReadBuffer  index;
        
    httpHandler.SetConfigServer(&configServer);
    httpServer.Init(configFile.GetIntValue("http.port", 8080));
    httpServer.RegisterHandler(&httpHandler);
         
    docroot.Wrap(configFile.GetValue("http.documentRoot", "."));
    prefix.Wrap(configFile.GetValue("http.staticPrefix", "/webadmin"));
    index.Wrap(configFile.GetValue("http.directoryIndex", "index.html"));

    httpFileHandler.Init(docroot, prefix);
    httpFileHandler.SetDirectoryIndex(index);
    httpServer.RegisterHandler(&httpFileHandler);
    
    sdbpPort = configFile.GetIntValue("sdbp.port", 7080);
    sdbpServer.Init(sdbpPort);
    sdbpServer.SetContext(&configServer);
    sdbpServer.UseKeepAlive(false);

    // start configServer only after network servers are started
    configServer.Init(this);

    configServer.GetHTTPEndpoint(httpEndpoint);
    Log_Message("Web admin is started at http://%s%R", httpEndpoint.ToString(), &prefix);
    Log_Message("Waiting for connections on port %d", sdbpPort);
    
    logStatTimer.SetCallable(MFUNC(ConfigServerApp, OnLogStatTimer));
    // logStatTime is in seconds in the config file, default is 10min
    SetLogStatTimeout(configFile.GetIntValue("controller.logStatTime", 600) * 1000);
}
示例#14
0
ShardMigrationWriter::ShardMigrationWriter()
{
    onTimeout.SetCallable(MFUNC(ShardMigrationWriter, OnTimeout));
    onTimeout.SetDelay(SHARD_MIGRATION_WRITER_DELAY);
    Reset();
}
示例#15
0
void ShardMigrationWriter::Resume()
{
    CONTEXT_TRANSPORT->RegisterWriteReadyness(nodeID, MFUNC(ShardMigrationWriter, OnWriteReadyness));
}
示例#16
0
ReplicatedLog::ReplicatedLog()
{
    canaryTimer.SetCallable(MFUNC(ReplicatedLog, OnCanaryTimeout));
    canaryTimer.SetDelay(CANARY_TIMEOUT);
}