void Master::OnInstructions() { ReplicationInstruction instruction; while (m_inst_queue.Pop(instruction)) { switch (instruction.type) { case REPL_INSTRUCTION_ADD_SLAVE: { SlaveConnection* conn = (SlaveConnection*) instruction.ptr; m_channel_service.AttachChannel(conn->conn, true); conn->state = SLAVE_STATE_CONNECTED; m_slave_table[conn->conn->GetID()] = conn; conn->conn->ClearPipeline(); { LockGuard<ThreadMutex> guard(m_port_table_mutex); conn->port = m_slave_port_table[conn->conn->GetID()]; } ChannelOptions options; options.auto_disable_writing = false; conn->conn->Configure(options); conn->conn->SetChannelPipelineInitializor(slave_pipeline_init, this); conn->conn->SetChannelPipelineFinalizer(slave_pipeline_finallize, NULL); SyncSlave(*conn); break; } case REPL_INSTRUCTION_FEED_CMD: { RedisCommandWithDBID* cmd = (RedisCommandWithDBID*) instruction.ptr; //m_backlog.Feed(cmd->second, cmd->first); WriteSlaves(cmd->first, cmd->second); DELETE(cmd); break; } case REPL_INSTRUCTION_DELETE_SLAVES: { SlaveConnTable tmp = m_slave_table; SlaveConnTable::iterator it = tmp.begin(); while (it != tmp.end()) { it->second->conn->Close(); it++; } break; } default: { break; } } } }
void Master::AddSlave(SlaveConn* slave) { DEBUG_LOG("Add slave %s", slave->GetAddress().c_str()); g_repl->GetIOServ().AttachChannel(slave->conn, true); slave->state = SYNC_STATE_START; m_slaves[slave->conn->GetID()] = slave; slave->conn->ClearPipeline(); if (g_db->GetConfig().repl_disable_tcp_nodelay) { ChannelOptions newoptions = slave->conn->GetOptions(); newoptions.tcp_nodelay = false; slave->conn->Configure(newoptions); } slave->conn->SetChannelPipelineInitializor(slave_pipeline_init, NULL); slave->conn->SetChannelPipelineFinalizer(slave_pipeline_finallize, NULL); slave->conn->GetWritableOptions().auto_disable_writing = false; SyncSlave(slave); }