Hi!
This is an update to make the function getUpdatedMasters a little faster since
it now use server-side processing instead of client processing.
(and also the performance increase for slave discussed earlier - remember:
there is no slave functionality in the backend - yet.).
For reference, see http://groups.google.com/group/mongodb-
user/browse_frm/thread/40d606279084eed4
--
//fredan
Index: test/mongodb.example.com.generate-hosts
===================================================================
--- test/mongodb.example.com.generate-hosts (revision 2261)
+++ test/mongodb.example.com.generate-hosts (arbetskopia)
@@ -1,4 +1,4 @@
-#!/usr/local/bin/bash
+#!/usr/bin/env bash
h=0
i=0
Index: master.cc
===================================================================
--- master.cc (revision 2261)
+++ master.cc (arbetskopia)
@@ -25,7 +25,7 @@
virtual void getUpdatedMasters(vector<DomainInfo>* domains);
virtual void setNotifed(int id, u_int32_t serial);
*/
-
+/*
void MONGODBBackend::getUpdatedMasters(vector<DomainInfo>* domains) {
//please see the function getTheFreshOnes in private.cc
@@ -34,7 +34,38 @@
getTheFreshOnes(domains, &type, &f_name);
}
+*/
+void MONGODBBackend::getUpdatedMasters(vector<DomainInfo>* domains) {
+ string f_name = "(getUpdatedMasters)";
+ mongo::Query mongo_q = QUERY( "type" << "MASTER" << "$where" << "this.notified_serial != this.SOA.serial" );
+
+ auto_ptr<mongo::DBClientCursor> mongo_c;
+ mongo_c = m_db.query(collection_domains, mongo_q);
+
+ string m_q = mongo_q.toString();
+
+ if(logging)
+ L<<Logger::Info << backend_name << f_name << " Query: "<< m_q << endl;
+
+ if (!mongo_c->more())
+ return;
+
+ while(mongo_c->more()) {
+ DomainInfo di;
+ SOAData sd;
+
+ mongo::BSONObj mongo_r = mongo_c->next();
+
+ string domain = mongo_r.getStringField("domain");
+
+ if (checkDomainInfo(&domain, &mongo_r, &f_name, &m_q, &di, &sd)) {
+ di.serial = sd.serial;
+ domains->push_back(di);
+ }
+ }
+}
+
void MONGODBBackend::setNotifed(int id, u_int32_t serial) {
mongo::Query mongo_q = QUERY( "domain_id" << id );
bson::bo update = BSON( "$set" << BSON("notified_serial" << serial ));
Index: schema.mongodb.sql
===================================================================
--- schema.mongodb.sql (revision 2261)
+++ schema.mongodb.sql (arbetskopia)
@@ -5,6 +5,7 @@
{ "domain_id" : int,
"name" : string,
"last_check" : int,
+ "next_check" : int,
"notified_serial" : int,
"type" : string,
"ttl" : int,
Index: mongodbbackend.hh
===================================================================
--- mongodbbackend.hh (revision 2261)
+++ mongodbbackend.hh (arbetskopia)
@@ -37,6 +37,7 @@
bool isMaster(const string &name, const string &ip);
void getUnfreshSlaveInfos(vector<DomainInfo>* domains);
void setFresh(int id);
+ void setFresh(uint32_t id, uint32_t refresh);
/*
bool startTransaction(const string &qname, int id);
bool commitTransaction();
Index: slave.cc
===================================================================
--- slave.cc (revision 2261)
+++ slave.cc (arbetskopia)
@@ -36,18 +36,28 @@
*/
void MONGODBBackend::setFresh(int id) {
+ SOAData soadata;
+ DomainInfo di;
+ string empty;
+
+ if (getDomainInfo(empty, di, &soadata, id))
+ setFresh(id, ((unsigned int) time(0) + soadata.refresh));
+}
+
+void MONGODBBackend::setFresh(uint32_t id, uint32_t refresh ) {
mongo::Query mongo_q = QUERY( "domain_id" << id );
- bson::bo update = BSON( "$set" << BSON("last_check" << (unsigned int) time(0) ) );
+ bson::bo update = BSON( "$set" << BSON("last_check" << (unsigned int) time(0) << "next_check" << refresh) );
if(logging) {
- L<<Logger::Info << backend_name << "(setFresh)" << " Query: "<< mongo_q.toString() << endl;
+ L<<Logger::Info << backend_name << "(setFresh) Query: " << mongo_q.toString() << endl;
if(logging_content)
- L<<Logger::Info << backend_name << "(setFresh)" << " Update: "<< update.toString() << endl;
+ L<<Logger::Info << backend_name << "(setFresh) Update: " << update.toString() << endl;
}
m_db.update(collection_domains, mongo_q , update, false );
}
+/*
void MONGODBBackend::getUnfreshSlaveInfos(vector<DomainInfo>* domains) {
//please see the function getTheFreshOnes in private.cc
@@ -56,7 +66,44 @@
getTheFreshOnes(domains, &type, &f_name);
}
+*/
+void MONGODBBackend::getUnfreshSlaveInfos(vector<DomainInfo>* domains) {
+ string f_name = "(getUnfreshSlaveInfos)";
+
+ stringstream t;
+ t << (unsigned int) time(0);
+
+ mongo::Query mongo_q = QUERY( "type" << "SLAVE" << "next_refresh" << "{$lte:" + t.str() + "}");
+
+ auto_ptr<mongo::DBClientCursor> mongo_c;
+ mongo_c = m_db.query(collection_domains, mongo_q);
+
+ string m_q = mongo_q.toString();
+
+ if(logging)
+ L<<Logger::Info << backend_name << f_name << " Query: " << m_q << endl;
+
+ if (!mongo_c->more())
+ return;
+
+ while(mongo_c->more()) {
+ DomainInfo di;
+ SOAData sd;
+
+ mongo::BSONObj mongo_r = mongo_c->next();
+
+ string domain = mongo_r.getStringField("domain");
+
+ if (checkDomainInfo(&domain, &mongo_r, &f_name, &m_q, &di, &sd)) {
+ di.serial = sd.serial;
+ domains->push_back(di);
+ }
+ }
+
+
+}
+
bool MONGODBBackend::isMaster(const string &domain, const string &ip) {
mongo::Query mongo_q = QUERY( "name" << toLower(domain) );
Index: minimal.cc
===================================================================
--- minimal.cc (revision 2261)
+++ minimal.cc (arbetskopia)
@@ -67,62 +67,62 @@
m_db.ensureIndex(collection_domains , BSON( "domain_id" << 1), true, "domain_id", true); //, true);
- L<<Logger::Error << backend_name << "Index: domains: 'domain_id' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_domains << ": 'domain_id' done." << endl;
m_db.ensureIndex(collection_domains , BSON( "name" << 1), true, "name", true); //, true);
- L<<Logger::Error << backend_name << "Index: domains: 'name' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_domains << ": 'name' done." << endl;
- m_db.ensureIndex(collection_domains , BSON( "type" << 1), false, "type", true); //, true);
- L<<Logger::Error << backend_name << "Index: domains: 'type' done." << endl;
+ m_db.ensureIndex(collection_domains , BSON( "type" << 1 << "next_check" << 1), false, "type_next_check", true); //, true);
+ L<<Logger::Error << backend_name << "Index: " << collection_domains << ": 'type_next_check' done." << endl;
m_db.ensureIndex(collection_domains , BSON( "account" << 1), false, "account", true); //, true);
- L<<Logger::Error << backend_name << "Index: domains: 'account' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_domains << ": 'account' done." << endl;
m_db.ensureIndex(collection_records, BSON( "domain_id" << 1), false, "domain_id", true); //, true);
- L<<Logger::Error << backend_name << "Index: records: 'domain_id' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_records << ": 'domain_id' done." << endl;
m_db.ensureIndex(collection_records, BSON( "name" << 1), false, "name", true); //, true);
- L<<Logger::Error << backend_name << "Index: records: 'name' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_records << ": 'name' done." << endl;
m_db.ensureIndex(collection_records, BSON( "name" << 1 << "type" << 1), true, "name_type", true); //, true);
- L<<Logger::Error << backend_name << "Index: records: 'name_type' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_records << ": 'name_type' done." << endl;
m_db.ensureIndex(collection_records, BSON( "domain_id" << 1 << "auth" << 1 << "ordername" << -1), false, "domainid_auth_ordername_desc", true); //, true);
- L<<Logger::Error << backend_name << "Index: records: 'domainid_auth_ordername_desc' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_records << ": 'domainid_auth_ordername_desc' done." << endl;
m_db.ensureIndex(collection_records, BSON( "domain_id" << 1 << "auth" << 1 << "ordername" << 1), false, "domainid_auth_ordername_asc", true); //, true);
- L<<Logger::Error << backend_name << "Index: records: 'domainid_auth_ordername_asc' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_records << ": 'domainid_auth_ordername_asc' done." << endl;
m_db.ensureIndex(collection_records, BSON( "domain_id" << 1 << "name" << 1 ), false, "domainid_name", true); //, true);
- L<<Logger::Error << backend_name << "Index: records: 'domainid_name' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_records << ": 'domainid_name' done." << endl;
m_db.ensureIndex(collection_domainmetadata, BSON( "name" << 1 ), true, "name", true); //, true);
- L<<Logger::Error << backend_name << "Index: domainmetadata: 'name' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_domainmetadata << ": 'name' done." << endl;
m_db.ensureIndex(collection_domainmetadata, BSON( "name" << 1 << "content.kind" << 1), true, "name_kind", true); //, true);
- L<<Logger::Error << backend_name << "Index: domainmetadata: 'name_kind' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_domainmetadata << ": 'name_kind' done." << endl;
m_db.ensureIndex(collection_cryptokeys, BSON( "domain_id" << 1 ), true, "domain_id", true); //, true);
- L<<Logger::Error << backend_name << "Index: cryptokeys: 'domain_id' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_cryptokeys << ": 'domain_id' done." << endl;
m_db.ensureIndex(collection_cryptokeys, BSON( "name" << 1 ), true, "name", true); //, true);
- L<<Logger::Error << backend_name << "Index: cryptokeys: 'name' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_cryptokeys << ": 'name' done." << endl;
m_db.ensureIndex(collection_cryptokeys, BSON( "name" << 1 << "domain_id" << 1), true, "name_domainid", true); //, true);
- L<<Logger::Error << backend_name << "Index: cryptokeys: 'name_domainid' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_cryptokeys << ": 'name_domainid' done." << endl;
m_db.ensureIndex(collection_cryptokeys, BSON( "domain_id" << 1 << "content.id" << 1), true, "domainid_id", true); //, true);
- L<<Logger::Error << backend_name << "Index: cryptokeys: 'domainid_id' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_cryptokeys << ": 'domainid_id' done." << endl;
m_db.ensureIndex(collection_cryptokeys, BSON( "name" << 1 << "content.id" << 1), true, "name_id", true); //, true);
- L<<Logger::Error << backend_name << "Index: cryptokeys: 'name_id' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_cryptokeys << ": 'name_id' done." << endl;
m_db.ensureIndex(collection_tsigkeys, BSON( "name" << 1 << "content.algorithm" << 1), true, "name_algo", true); //, true);
- L<<Logger::Error << backend_name << "Index: tsigkeys: 'name_algo' done." << endl;
+ L<<Logger::Error << backend_name << "Index: " << collection_tsigkeys << ": 'name_algo' done." << endl;
L<<Logger::Error << backend_name << "(Re)creating index... DONE!" << endl;
_______________________________________________
Pdns-users mailing list
[email protected]
http://mailman.powerdns.com/mailman/listinfo/pdns-users