mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-09-23 23:15:06 +02:00
back to bulk apply for status updates in BigTable
This commit is contained in:
parent
1ba4ccd98d
commit
1d65c1e43e
1 changed files with 17 additions and 56 deletions
|
@ -91,6 +91,7 @@ void BigTableStatusWriter::writePending()
|
||||||
}
|
}
|
||||||
fprintf(stderr, "Writing %zu pending status entries to BigTable\n", toWrite.size());
|
fprintf(stderr, "Writing %zu pending status entries to BigTable\n", toWrite.size());
|
||||||
|
|
||||||
|
cbt::BulkMutation bulk;
|
||||||
for (const auto& entry : toWrite) {
|
for (const auto& entry : toWrite) {
|
||||||
std::string row_key = entry.network_id + "#" + entry.node_id;
|
std::string row_key = entry.network_id + "#" + entry.node_id;
|
||||||
cbt::SingleRowMutation m(row_key);
|
cbt::SingleRowMutation m(row_key);
|
||||||
|
@ -107,65 +108,25 @@ void BigTableStatusWriter::writePending()
|
||||||
}
|
}
|
||||||
int64_t ts = entry.last_seen;
|
int64_t ts = entry.last_seen;
|
||||||
m.emplace_back(cbt::SetCell(checkInColumnFamily, lastSeenColumn, std::move(ts)));
|
m.emplace_back(cbt::SetCell(checkInColumnFamily, lastSeenColumn, std::move(ts)));
|
||||||
|
bulk.emplace_back(m);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
fprintf(stderr, "Applying %zu mutations to BigTable\n", bulk.size());
|
||||||
auto status = _table->Apply(std::move(m));
|
|
||||||
if (! status.ok()) {
|
try {
|
||||||
fprintf(stderr, "Error writing to BigTable: %s\n", status.message().c_str());
|
std::vector<cbt::FailedMutation> failures = _table->BulkApply(std::move(bulk));
|
||||||
}
|
fprintf(stderr, "BigTable write completed with %zu failures\n", failures.size());
|
||||||
else {
|
for (auto const& r : failures) {
|
||||||
_pubsubWriter->publishStatusChange(
|
// Handle error (log it, retry, etc.)
|
||||||
entry.target, entry.network_id, entry.node_id, entry.os, entry.arch, entry.version,
|
std::cerr << "Error writing to BigTable: " << r.status() << "\n";
|
||||||
entry.last_seen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fprintf(stderr, "Exception writing to BigTable: %s\n", e.what());
|
|
||||||
span->SetAttribute("error", e.what());
|
|
||||||
span->SetStatus(opentelemetry::trace::StatusCode::kError, e.what());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// cbt::BulkMutation bulk;
|
catch (const std::exception& e) {
|
||||||
// for (const auto& entry : toWrite) {
|
fprintf(stderr, "Exception writing to BigTable: %s\n", e.what());
|
||||||
// std::string row_key = entry.network_id + "#" + entry.node_id;
|
span->SetAttribute("error", e.what());
|
||||||
// cbt::SingleRowMutation m(row_key);
|
span->SetStatus(opentelemetry::trace::StatusCode::kError, e.what());
|
||||||
// m.emplace_back(cbt::SetCell(nodeInfoColumnFamily, osColumn, entry.os));
|
return;
|
||||||
// m.emplace_back(cbt::SetCell(nodeInfoColumnFamily, archColumn, entry.arch));
|
}
|
||||||
// m.emplace_back(cbt::SetCell(nodeInfoColumnFamily, versionColumn, entry.version));
|
|
||||||
// char buf[64] = { 0 };
|
|
||||||
// std::string addressStr = entry.address.toString(buf);
|
|
||||||
// if (entry.address.ss_family == AF_INET) {
|
|
||||||
// m.emplace_back(cbt::SetCell(checkInColumnFamily, ipv4Column, std::move(addressStr)));
|
|
||||||
// }
|
|
||||||
// else if (entry.address.ss_family == AF_INET6) {
|
|
||||||
// m.emplace_back(cbt::SetCell(checkInColumnFamily, ipv6Column, std::move(addressStr)));
|
|
||||||
// }
|
|
||||||
// int64_t ts = entry.last_seen;
|
|
||||||
// m.emplace_back(cbt::SetCell(checkInColumnFamily, lastSeenColumn, std::move(ts)));
|
|
||||||
// bulk.emplace_back(m);
|
|
||||||
|
|
||||||
// // TODO: Check performance on this. May need to bach these.
|
|
||||||
// _pubsubWriter->publishStatusChange(
|
|
||||||
// entry.target, entry.network_id, entry.node_id, entry.os, entry.arch, entry.version, entry.last_seen);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// fprintf(stderr, "Applying %zu mutations to BigTable\n", bulk.size());
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// std::vector<cbt::FailedMutation> failures = table.BulkApply(std::move(bulk));
|
|
||||||
// fprintf(stderr, "BigTable write completed with %zu failures\n", failures.size());
|
|
||||||
// for (auto const& r : failures) {
|
|
||||||
// // Handle error (log it, retry, etc.)
|
|
||||||
// std::cerr << "Error writing to BigTable: " << r.status() << "\n";
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// catch (const std::exception& e) {
|
|
||||||
// fprintf(stderr, "Exception writing to BigTable: %s\n", e.what());
|
|
||||||
// span->SetAttribute("error", e.what());
|
|
||||||
// span->SetStatus(opentelemetry::trace::StatusCode::kError, e.what());
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
Loading…
Add table
Reference in a new issue