try {
reconnectIfNeeded();
+ if (!d_inTransaction) {
+ throw PDNSException("replaceRRSet called outside of transaction");
+ }
+
if (qt != QType::ANY) {
d_DeleteRRSetQuery_stmt->
bind("domain_id", domain_id)->
try {
reconnectIfNeeded();
+ if (inTransaction()) {
+ throw PDNSException("Attempted to start transaction while one was already active (domain '" + domain.toLogString() + "')");
+ }
d_db->startTransaction();
d_inTransaction = true;
if(domain_id >= 0) {
try {
reconnectIfNeeded();
+ if (!d_inTransaction) {
+ throw PDNSException("replaceComments called outside of transaction");
+ }
+
d_DeleteCommentRRsetQuery_stmt->
bind("domain_id",domain_id)->
bind("qname", qname)->
UeberBackend::go();
}
-bool rectifyZone(DNSSECKeeper& dk, const DNSName& zone, bool quiet = false)
+bool rectifyZone(DNSSECKeeper& dk, const DNSName& zone, bool quiet = false, bool rectifyTransaction = true)
{
string output;
string error;
- bool ret = dk.rectifyZone(zone, error, output, true);
+ bool ret = dk.rectifyZone(zone, error, output, rectifyTransaction);
if (!quiet || !ret) {
// When quiet, only print output if there was an error
if (!output.empty()) {
return EXIT_SUCCESS;
}
-int editZone(DNSSECKeeper& dk, const DNSName &zone) {
+int editZone(const DNSName &zone) {
UeberBackend B;
DomainInfo di;
+ DNSSECKeeper dk(&B);
if (! B.getDomainInfo(zone, di)) {
cerr<<"Domain '"<<zone<<"' not found!"<<endl;
else if(changed.empty() || c!='a')
goto reAsk2;
+ di.backend->startTransaction(zone, -1);
for(const auto& change : changed) {
vector<DNSResourceRecord> vrr;
for(const DNSRecord& rr : grouped[change.first]) {
}
di.backend->replaceRRSet(di.id, change.first.first, QType(change.first.second), vrr);
}
- rectifyZone(dk, zone);
+ rectifyZone(dk, zone, false, false);
+ di.backend->commitTransaction();
return EXIT_SUCCESS;
}
rr.domain_id = di.id;
rr.qname = name;
DNSResourceRecord oldrr;
+
+ di.backend->startTransaction(zone, -1);
+
if(addOrReplace) { // the 'add' case
di.backend->lookup(rr.qtype, rr.qname, 0, di.id);
di.backend->replaceRRSet(di.id, name, rr.qtype, newrrs);
// need to be explicit to bypass the ueberbackend cache!
di.backend->lookup(rr.qtype, name, 0, di.id);
+ di.backend->commitTransaction();
cout<<"New rrset:"<<endl;
while(di.backend->get(rr)) {
cout<<rr.qname.toString()<<" "<<rr.ttl<<" IN "<<rr.qtype.getName()<<" "<<rr.content<<endl;
name=DNSName(name_)+zone;
QType qt(QType::chartocode(type_.c_str()));
+ di.backend->startTransaction(zone, -1);
di.backend->replaceRRSet(di.id, name, qt, vector<DNSResourceRecord>());
+ di.backend->commitTransaction();
return EXIT_SUCCESS;
}
if(cmds[1]==".")
cmds[1].clear();
- exit(editZone(dk, DNSName(cmds[1])));
+ exit(editZone(DNSName(cmds[1])));
}
else if(cmds[0] == "clear-zone") {
if(cmds.size() != 2) {
+ "capable backends are loaded, or because the backends have DNSSEC disabled. Check your configuration.");
}
-static void updateDomainSettingsFromDocument(UeberBackend& B, const DomainInfo& di, const DNSName& zonename, const Json document) {
+static void updateDomainSettingsFromDocument(UeberBackend& B, const DomainInfo& di, const DNSName& zonename, const Json document, bool rectifyTransaction=true) {
vector<string> zonemaster;
bool shouldRectify = false;
for(auto value : document["masters"].array_items()) {
if (api_rectify == "1") {
string info;
string error_msg;
- if (!dk.rectifyZone(zonename, error_msg, info, true)) {
+ if (!dk.rectifyZone(zonename, error_msg, info, rectifyTransaction)) {
throw ApiException("Failed to rectify '" + zonename.toString() + "' " + error_msg);
}
}
if(!B.getDomainInfo(zonename, di))
throw ApiException("Creating domain '"+zonename.toString()+"' failed: lookup of domain ID failed");
+ di.backend->startTransaction(zonename, di.id);
+
// updateDomainSettingsFromDocument does NOT fill out the default we've established above.
if (!soa_edit_api_kind.empty()) {
di.backend->setDomainMetadataOne(zonename, "SOA-EDIT-API", soa_edit_api_kind);
}
- di.backend->startTransaction(zonename, di.id);
-
for(auto rr : new_records) {
rr.domain_id = di.id;
di.backend->feedRecord(rr, DNSName());
di.backend->feedComment(c);
}
- updateDomainSettingsFromDocument(B, di, zonename, document);
+ updateDomainSettingsFromDocument(B, di, zonename, document, false);
di.backend->commitTransaction();
if(req->method == "PUT") {
// update domain settings
- updateDomainSettingsFromDocument(B, di, zonename, req->json());
+ di.backend->startTransaction(zonename, -1);
+ updateDomainSettingsFromDocument(B, di, zonename, req->json(), false);
+ di.backend->commitTransaction();
resp->body = "";
resp->status = 204; // No Content, but indicate success