You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by aw...@apache.org on 2021/02/09 21:35:31 UTC
[kudu] branch master updated: txns: syntactically sweeten some
tuple-like variables
This is an automated email from the ASF dual-hosted git repository.
awong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 7afdac0 txns: syntactically sweeten some tuple-like variables
7afdac0 is described below
commit 7afdac0155f1c0730242594b6d13a549c3084d5d
Author: Andrew Wong <aw...@cloudera.com>
AuthorDate: Mon Feb 8 16:07:18 2021 -0800
txns: syntactically sweeten some tuple-like variables
This uses the C++17 feature to use structured bindings[1] in a few
places.
To pass lint, this patch also pulls in a patch[2] merged into the
cpplint project.
Note that the Google Style Guide[3] does mention structured bindings, so
they seem like fair game in Kudu's codebase.
[1] https://en.cppreference.com/w/cpp/language/structured_binding
[2] https://github.com/cpplint/cpplint/pull/126
[3] https://google.github.io/styleguide/cppguide.html#Type_deduction
Change-Id: Ice0add1d0c8487f97772732cffb463292efe8910
Reviewed-on: http://gerrit.cloudera.org:8080/17046
Tested-by: Kudu Jenkins
Reviewed-by: Alexey Serbin <as...@cloudera.com>
---
src/kudu/transactions/txn_status_manager.cc | 34 ++++++++++------------
thirdparty/download-thirdparty.sh | 2 +-
thirdparty/patches/google-styleguide-cpplint.patch | 11 +++++++
3 files changed, 27 insertions(+), 20 deletions(-)
diff --git a/src/kudu/transactions/txn_status_manager.cc b/src/kudu/transactions/txn_status_manager.cc
index b2d7a1f..9111451 100644
--- a/src/kudu/transactions/txn_status_manager.cc
+++ b/src/kudu/transactions/txn_status_manager.cc
@@ -22,6 +22,7 @@
#include <mutex>
#include <ostream>
#include <string>
+#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
@@ -362,10 +363,7 @@ void TxnStatusManagerBuildingVisitor::VisitTransactionEntries(
{
// Lock the transaction while we build the participants.
TransactionEntryLock txn_lock(txn.get(), LockMode::READ);
- for (auto& participant_and_state : participants) {
- const auto& prt_id = participant_and_state.first;
- auto& prt_entry_pb = participant_and_state.second;
-
+ for (auto& [prt_id, prt_entry_pb] : participants) {
// Register a participant entry for this transaction.
auto prt = txn->GetOrCreateParticipant(prt_id);
ParticipantEntryLock l(prt.get(), LockMode::WRITE);
@@ -493,10 +491,9 @@ Status TxnStatusManager::LoadFromTabletUnlocked() {
unordered_map<int64_t, scoped_refptr<CommitTasks>> commits_in_flight;
unordered_map<int64_t, scoped_refptr<CommitTasks>> new_tasks;
if (txn_client) {
- for (const auto& txn_id_and_entry : txns_by_id) {
- const auto& txn_entry = txn_id_and_entry.second;
- if (txn_id_and_entry.second->state() == TxnStatePB::COMMIT_IN_PROGRESS) {
- const auto& txn_id = txn_id_and_entry.first;
+ for (const auto& [txn_id, txn_entry] : txns_by_id) {
+ const auto& state = txn_entry->state();
+ if (state == TxnStatePB::COMMIT_IN_PROGRESS) {
new_tasks.emplace(txn_id,
new CommitTasks(txn_id, txn_entry->GetParticipantIds(),
txn_client, commit_pool_, this));
@@ -509,15 +506,15 @@ Status TxnStatusManager::LoadFromTabletUnlocked() {
txns_by_id_ = std::move(txns_by_id);
commits_in_flight = std::move(commits_in_flight_);
// Stop any previously on-going tasks.
- for (const auto& txn_id_and_tasks : commits_in_flight) {
- txn_id_and_tasks.second->stop();
+ for (const auto& [_, tasks] : commits_in_flight) {
+ tasks->stop();
}
commits_in_flight_ = std::move(new_tasks);
if (!commits_in_flight_.empty()) {
LOG(INFO) << Substitute("Starting $0 commit tasks", commits_in_flight_.size());
- }
- for (const auto& id_and_commit_task : commits_in_flight_) {
- id_and_commit_task.second->BeginCommitAsync();
+ for (const auto& [_, tasks] : commits_in_flight_) {
+ tasks->BeginCommitAsync();
+ }
}
}
return Status::OK();
@@ -843,12 +840,12 @@ Status TxnStatusManager::BeginCommitTransaction(int64_t txn_id, const string& us
if (PREDICT_TRUE(FLAGS_txn_schedule_background_tasks)) {
auto participant_ids = txn->GetParticipantIds();
std::unique_lock<simple_spinlock> l(lock_);
- auto iter_and_emplaced = commits_in_flight_.emplace(txn_id,
+ auto [map_iter, emplaced] = commits_in_flight_.emplace(txn_id,
new CommitTasks(txn_id, std::move(participant_ids),
txn_client, commit_pool_, this));
l.unlock();
- if (iter_and_emplaced.second) {
- iter_and_emplaced.first->second->BeginCommitAsync();
+ if (emplaced) {
+ map_iter->second->BeginCommitAsync();
}
}
txn_lock.Commit();
@@ -1074,11 +1071,10 @@ void TxnStatusManager::AbortStaleTransactions() {
ParticipantIdsByTxnId TxnStatusManager::GetParticipantsByTxnIdForTests() const {
ParticipantIdsByTxnId ret;
std::lock_guard<simple_spinlock> l(lock_);
- for (const auto& id_and_txn : txns_by_id_) {
- const auto& txn = id_and_txn.second;
+ for (const auto& [id, txn] : txns_by_id_) {
vector<string> prt_ids = txn->GetParticipantIds();
std::sort(prt_ids.begin(), prt_ids.end());
- EmplaceOrDie(&ret, id_and_txn.first, std::move(prt_ids));
+ EmplaceOrDie(&ret, id, std::move(prt_ids));
}
return ret;
}
diff --git a/thirdparty/download-thirdparty.sh b/thirdparty/download-thirdparty.sh
index 1491c0e..07914cf 100755
--- a/thirdparty/download-thirdparty.sh
+++ b/thirdparty/download-thirdparty.sh
@@ -288,7 +288,7 @@ fetch_and_patch \
$MUSTACHE_SOURCE \
$MUSTACHE_PATCHLEVEL
-GSG_PATCHLEVEL=2
+GSG_PATCHLEVEL=3
fetch_and_patch \
google-styleguide-${GSG_VERSION}.tar.gz \
$GSG_SOURCE \
diff --git a/thirdparty/patches/google-styleguide-cpplint.patch b/thirdparty/patches/google-styleguide-cpplint.patch
index ab92de3..57857ac 100644
--- a/thirdparty/patches/google-styleguide-cpplint.patch
+++ b/thirdparty/patches/google-styleguide-cpplint.patch
@@ -109,6 +109,17 @@
def CheckVlogArguments(filename, clean_lines, linenum, error):
"""Checks that VLOG() is only used for defining a logging level.
+@@ -3111,8 +3111,8 @@
+ line = clean_lines.elided[linenum]
+
+ # You shouldn't have spaces before your brackets, except maybe after
+- # 'delete []' or 'return []() {};'
+- if Search(r'\w\s+\[', line) and not Search(r'(?:delete|return)\s+\[', line):
++ # 'delete []', 'return []() {};', or 'auto [abc, ...] = ...;'.
++ if Search(r'\w\s+\[', line) and not Search(r'(?:auto&?|delete|return)\s+\[', line):
+ error(filename, linenum, 'whitespace/braces', 5,
+ 'Extra space before [')
+
@@ -5488,7 +5574,7 @@
('<stack>', ('stack',)),
('<string>', ('char_traits', 'basic_string',)),