0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 17:10:48 +01:00

Merge branch 'master' of ssh://git.10gen.com/data/gitroot/p

This commit is contained in:
Dwight 2008-12-01 11:00:04 -05:00
commit d68ca4cc23
12 changed files with 1255 additions and 987 deletions

View File

@ -330,6 +330,8 @@ public:
}
};
void webServerThread();
/* versions
114 bad memory bug fixed
115 replay, opLogging
@ -342,6 +344,7 @@ void listen(int port) {
log() << "waiting for connections on port " << port << "..." << endl;
OurListener l(port);
startReplication();
boost::thread thr(webServerThread);
l.listen();
}

File diff suppressed because it is too large Load Diff

92
db/dbwebserver.cpp Normal file
View File

@ -0,0 +1,92 @@
// dbwebserver.cpp
/**
* Copyright (C) 2008 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "../util/miniwebserver.h"
#include "db.h"
#include "repl.h"
#include "replset.h"
extern int port;
extern string replInfo;
class DbWebServer : public MiniWebServer {
public:
void doLockedStuff(stringstream& ss) {
dblock lk;
ss << "# clients: " << clients.size() << '\n';
if( client ) {
ss << "curclient: " << client->name;
if( client->dead )
ss << " DEAD";
ss << '\n';
}
ss << "\nreplication\n";
ss << "master: " << master << '\n';
ss << "slave: " << slave << '\n';
if( replPair ) {
ss << "replpair:\n";
ss << replPair->getInfo();
}
ss << replInfo << '\n';
}
void doUnlockedStuff(stringstream& ss) {
ss << "port: " << port << '\n';
ss << "dblocked: " << dbLocked << " (initial)\n";
}
virtual void doRequest(
const char *rq, // the full request
string url,
// set these and return them:
string& responseMsg,
int& responseCode,
vector<string>& headers // if completely empty, content-type: text/html will be added
)
{
responseCode = 200;
stringstream ss;
ss << "<html><head><title>db</title></head><body>db<p>\n<pre>";
doUnlockedStuff(ss);
int n = 2000;
while( 1 ) {
if( !dbLocked ) {
ss << '\n';
doLockedStuff(ss);
break;
}
sleepmillis(1);
if( --n < 0 ) {
ss << "\ntimed out getting dblock\n";
break;
}
}
ss << "</pre></body></html>";
responseMsg = ss.str();
}
};
void webServerThread() {
DbWebServer mini;
if( mini.init(port+1000) )
mini.run();
}

View File

@ -11,7 +11,7 @@ DBGRID_LIBS = $(LIB_BOOST) -lstdc++
JVM_LIBS = -L/opt/java/lib/
OBJS=../stdafx.o ../util/sock.o ../grid/message.o ../util/mmap.o pdfile.o query.o jsobj.o introspect.o btree.o clientcursor.o ../util/util.o javajs.o tests.o json.o repl.o ../client/dbclient.o btreecursor.o cloner.o namespace.o commands.o matcher.o dbcommands.o dbeval.o ../util/background.o
OBJS=../stdafx.o ../util/sock.o ../grid/message.o ../util/mmap.o pdfile.o query.o jsobj.o introspect.o btree.o clientcursor.o ../util/util.o javajs.o tests.o json.o repl.o ../client/dbclient.o btreecursor.o cloner.o namespace.o commands.o matcher.o dbcommands.o dbeval.o ../util/background.o ../util/miniwebserver.o dbwebserver.o
DBGRID_OBJS=../stdafx.o json.o ../util/sock.o ../grid/message.o ../util/util.o jsobj.o ../client/dbclient.o ../dbgrid/dbgrid.o ../dbgrid/request.o ../client/connpool.o ../dbgrid/gridconfig.o commands.o ../dbgrid/dbgrid_commands.o ../dbgrid/griddatabase.o ../client/model.o ../util/background.o ../dbgrid/shard.o

View File

@ -1,5 +1,5 @@
// matcher.h
// matcher.h
/* JSMatcher is our boolean expression evaluator for "where" clauses */
/**

View File

@ -48,6 +48,9 @@ void ensureHaveIdIndex(const char *ns);
ReplPair *replPair = 0;
/* output by the web console */
string replInfo = "no repl yet";
/* peer unreachable, try our arbiter */
void ReplPair::arbitrate() {
if( arbHost == "-" ) {

View File

@ -28,6 +28,8 @@
#pragma once
#include "../client/dbclient.h"
class DBClientConnection;
class DBClientCursor;
extern bool slave;

View File

@ -47,6 +47,16 @@ public:
string remote; // host:port if port specified.
int date; // -1 not yet set; 0=slave; 1=master
string getInfo() {
stringstream ss;
ss << " state: " << state << '\n';
ss << " info: " << info << '\n';
ss << " arbhost:" << arbHost << '\n';
ss << " remote: " << remoteHost << ':' << remotePort << '\n';
ss << " date: " << date << '\n';
return ss.str();
}
ReplPair(const char *remoteEnd, const char *arbiter);
bool dominant(const string& myname) {

View File

@ -221,3 +221,4 @@ inline unsigned long fixEndian(unsigned long x) { return x; }
#else
inline unsigned long fixEndian(unsigned long x) { return swapEndian(x); }
#endif

96
util/miniwebserver.cpp Normal file
View File

@ -0,0 +1,96 @@
// miniwebserver.cpp
/**
* Copyright (C) 2008 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
#include "miniwebserver.h"
MiniWebServer::MiniWebServer() {
sock = 0;
}
bool MiniWebServer::init(int port) {
SockAddr me(port);
sock = socket(AF_INET, SOCK_STREAM, 0);
if( sock == INVALID_SOCKET ) {
log() << "ERROR: MiniWebServer listen(): invalid socket? " << errno << endl;
return false;
}
prebindOptions( sock );
if( bind(sock, (sockaddr *) &me.sa, me.addressSize) != 0 ) {
log() << "MiniWebServer: bind() failed port:" << port << " errno:" << errno << endl;
if( errno == 98 )
log() << "98 == addr already in use" << endl;
closesocket(sock);
return false;
}
if( ::listen(sock, 16) != 0 ) {
log() << "MiniWebServer: listen() failed " << errno << endl;
closesocket(sock);
return false;
}
return true;
}
void MiniWebServer::accepted(int s) {
char buf[4096];
int x = ::recv(s, buf, sizeof(buf)-1, 0);
if( x <= 0 )
return;
buf[x] = 0;
string responseMsg;
int responseCode = 599;
vector<string> headers;
doRequest(buf, "not implemented yet", responseMsg, responseCode, headers);
stringstream ss;
ss << "HTTP/1.0 " << responseCode;
if( responseCode == 200 ) ss << " OK";
ss << "\r\n";
if( headers.empty() ) {
ss << "Content-Type: text/html\r\n";
}
else {
for( vector<string>::iterator i = headers.begin(); i != headers.end(); i++ )
ss << *i << "\r\n";
}
ss << "\r\n";
ss << responseMsg;
string response = ss.str();
::send(s, response.c_str(), response.size(), 0);
}
void MiniWebServer::run() {
SockAddr from;
while( 1 ) {
int s = accept(sock, (sockaddr *) &from.sa, &from.addressSize);
if( s < 0 ) {
log() << "MiniWebServer: accept() returns " << s << " errno:" << errno << endl;
sleepmillis(200);
continue;
}
disableNagle(s);
RARELY log() << "MiniWebServer: connection accepted from " << from.toString() << endl;
accepted( s );
closesocket(s);
}
}

43
util/miniwebserver.h Normal file
View File

@ -0,0 +1,43 @@
// miniwebserver.h
/**
* Copyright (C) 2008 10gen Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "../grid/message.h"
class MiniWebServer {
public:
MiniWebServer();
bool init(int port);
void run();
virtual void doRequest(
const char *rq, // the full request
string url,
// set these and return them:
string& responseMsg,
int& responseCode,
vector<string>& headers // if completely empty, content-type: text/html will be added
) = 0;
private:
void accepted(int s);
int sock;
};

View File

@ -1,3 +1,5 @@
// util.cpp
/**
* Copyright (C) 2008 10gen Inc.
*