Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hhbc repo exception monitor and print log #7937

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion hphp/runtime/server/admin-request-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,9 @@ void AdminRequestHandler::handleRequest(Transport *transport) {
"\n"
"/instance-id: instance id that's passed in from command line\n"
"/compiler-id: returns the compiler id that built this app\n"
"/repo-schema: return the repo schema id used by this app\n"
"/repo-schema: return the repo schema id used by this app\n"
"/ini-get-all: dump all settings as JSON\n"
"/check-repo: check tables of hhbc to judge whether error or not\n"
"/check-load: how many threads are actively handling requests\n"
"/check-queued: how many http requests are queued waiting to be\n"
" handled\n"
Expand Down Expand Up @@ -970,6 +971,42 @@ static bool send_status(Transport *transport, Writer::Format format,

bool AdminRequestHandler::handleCheckRequest(const std::string &cmd,
Transport *transport) {
if(cmd == "check-repo"){
string fileMd5Msg, funcMsg, litstrMsg, preClassMsg, unitArrayMsg,
unitLitstrMsg, unitMergeablesMsg, unitSourceLocMsg, unitMsg, magicMsg, writableMsg;
string sendMsg;
bool fileMd5Sel = Repo::get().getMessageFromTable("FileMd5", fileMd5Msg);
bool funcSel = Repo::get().getMessageFromTable("Func", funcMsg);
bool litstrSel = Repo::get().getMessageFromTable("Litstr", litstrMsg);
bool preClassSel = Repo::get().getMessageFromTable("PreClass", preClassMsg);
bool unitArraySel = Repo::get().getMessageFromTable("UnitArray", unitArrayMsg);
bool unitLitstrSel = Repo::get().getMessageFromTable("UnitLitstr", unitLitstrMsg);
bool unitMergeablesSel = Repo::get().getMessageFromTable("UnitMergeables", unitMergeablesMsg);
bool unitSourceLocSel = Repo::get().getMessageFromTable("UnitSourceLoc", unitSourceLocMsg);
bool unitSel = Repo::get().getMessageFromTable("Unit", unitMsg);
bool magicSel = Repo::get().getMessageFromTable("magic", magicMsg);
bool writableSel = Repo::get().getMessageFromTable("writable", writableMsg);
if(fileMd5Sel && funcSel && litstrSel && preClassSel && unitArraySel && unitLitstrSel && unitMergeablesSel
&& unitSourceLocSel && unitSel && magicSel && writableSel){
sendMsg = "hhbc is ok!";
}else{
std::stringstream out;
out << fileMd5Msg << endl;
out << funcMsg << endl;
out << litstrMsg << endl;
out << preClassMsg << endl;
out << unitArrayMsg << endl;
out << unitLitstrMsg << endl;
out << unitMergeablesMsg << endl;
out << unitSourceLocMsg << endl;
out << unitMsg << endl;
out << magicMsg << endl;
out << writableMsg << endl;
sendMsg = out.str();
}
transport->sendString(sendMsg);
return true;
}
if (cmd == "check-load") {
int count = HttpServer::Server->getPageServer()->getActiveWorker();
transport->sendString(folly::to<std::string>(count));
Expand Down
6 changes: 6 additions & 0 deletions hphp/runtime/vm/repo-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <sqlite3.h>

#include <folly/portability/Stdio.h>
#include "hphp/util/logger.h"

namespace HPHP {

Expand Down Expand Up @@ -56,6 +57,11 @@ struct RepoExc : std::exception {
m_msg = msg;
free(msg);
}
std::string log_error = "Error: throw RepoExc ==>" + m_msg;
std::string databaseErrorStr = "no such table";
if(m_msg.find(databaseErrorStr) == std::string::npos){
Logger::Error(log_error);
}
va_end(ap);
}
const std::string& msg() const { return m_msg; }
Expand Down
30 changes: 30 additions & 0 deletions hphp/runtime/vm/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,36 @@ void batchCommit(std::vector<std::unique_ptr<UnitEmitter>> ues) {
}
}

bool Repo::getMessageFromTable(const std::string & tableName, std::string & message)
{
std::string messageLogStr;
try{
RepoTxn txn(*this);
std::stringstream ssSelect;
ssSelect << "SELECT count(*) FROM "
<< table(RepoIdCentral, tableName.c_str())
<< " ;";
RepoStmt stmt(*this);
txn.prepare(stmt, ssSelect.str());

RepoTxnQuery query(txn, stmt);
query.step();
if (!query.row()) {
return false;
}
int countNum = 0;
query.getInt(0, countNum);
std::stringstream ssmessage;
ssmessage << tableName << " :" << countNum;
message = ssmessage.str();
return true;
}catch(RepoExc& re) {
message = tableName + " :" + re.msg();
return false;
}
return false;
}

//////////////////////////////////////////////////////////////////////

}
1 change: 1 addition & 0 deletions hphp/runtime/vm/repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct Repo : RepoProxy {

public:
std::string table(int repoId, const char* tablePrefix);
bool getMessageFromTable(const std::string & tableName, std::string & message);
void exec(const std::string& sQuery); // throws(RepoExc)

void begin(); // throws(RepoExc)
Expand Down