void QuorumDatabase::SetAccepted(bool accepted) { Buffer key; Buffer value; ReadBuffer rbKey; ReadBuffer rbValue; bool ret; key.Write("accepted"); rbKey.Wrap(key); value.Writef("%d", accepted); rbValue.Wrap(value); ret = paxosShard->Set(rbKey, rbValue); }
void HTTPSession::SetType(Type type_) { const char* mime; ReadBuffer mimeType; type = type_; switch (type) { case PLAIN: mime = MIME_TYPE_TEXT_PLAIN; break; case HTML: mime = MIME_TYPE_TEXT_HTML; break; case JSON: mime = MIME_TYPE_APPLICATION_JSON; break; default: mime = MIME_TYPE_TEXT_PLAIN; break; } if (mimeType.GetLength() == 0) mimeType.Wrap(mime); conn->SetContentType(mimeType); }
void QuorumDatabase::SetUint64(const char* name, uint64_t u64) { ReadBuffer key(name); Buffer tmp; ReadBuffer value; int ret; tmp.Writef("%U", u64); value.Wrap(tmp); ret = paxosShard->Set(key, value); }
void QuorumDatabase::SetAcceptedValue(uint64_t paxosID, ReadBuffer value) { Buffer key; ReadBuffer rbKey; ASSERT(value.GetLength() > 0); key.Writef("accepted:%021U", paxosID); rbKey.Wrap(key); logShard->Set(rbKey, value); }
void ConfigQuorumContext::OnAppend(uint64_t paxosID, Buffer& value, bool ownAppend) { bool ret; ReadBuffer rbValue; ConfigMessage message; nextValue.Clear(); rbValue.Wrap(value); ret = message.Read(rbValue); ASSERT(ret); quorumProcessor->OnAppend(paxosID, message, ownAppend); }
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); } }
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); }
void QuorumDatabase::GetAcceptedValue(uint64_t paxosID, Buffer& value) { Buffer key; ReadBuffer rbKey; ReadBuffer rbValue; bool ret; key.Writef("accepted:%021U", paxosID); rbKey.Wrap(key); ret = logShard->Get(rbKey, rbValue); if (!ret) return; ASSERT(rbValue.GetLength() > 0); value.Write(rbValue); }
int Result::GetKey(ReadBuffer& key) { Request* request; if (requestCursor == NULL) return SDBP_API_ERROR; request = requestCursor; if (request->IsList()) { if (responsePos >= (*responseCursor)->numKeys) return SDBP_API_ERROR; key = (*responseCursor)->keys[responsePos]; } else key.Wrap(request->key); return request->status; }
bool QuorumDatabase::GetAccepted() { Buffer key; ReadBuffer rbKey; ReadBuffer rbValue; bool ret; key.Write("accepted"); rbKey.Wrap(key); ret = paxosShard->Get(rbKey, rbValue); if (!ret) return false; // not found, return default if (rbValue.GetLength() != 1) return false; // incorrect value, return default if (rbValue.GetCharAt(0) == '1') return true; return false; }
int Result::GetValue(ReadBuffer& value) { Request* request; if (requestCursor == NULL) return SDBP_API_ERROR; request = requestCursor; if (request->IsList()) { if (responsePos >= (*responseCursor)->numKeys) return SDBP_API_ERROR; value = (*responseCursor)->values[responsePos]; } else { if (request->response.valueBuffer == NULL) return SDBP_API_ERROR; value.Wrap(*request->response.valueBuffer); } return request->status; }