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 2019/03/31 19:18:44 UTC
[kudu] branch master updated: tablet_server_authorization-test: fix
SIGSEGV with static linkage
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 44ad18c tablet_server_authorization-test: fix SIGSEGV with static linkage
44ad18c is described below
commit 44ad18c4ad0c7f25c88e3724116ebe54ce7c64a1
Author: Adar Dembo <ad...@cloudera.com>
AuthorDate: Sun Mar 31 11:37:42 2019 -0700
tablet_server_authorization-test: fix SIGSEGV with static linkage
There was a global Random instance that called LOG() when initialized.
That's a no-no as LOG() will crash if it is called before glog is
initialized. Sadly it wasn't caught by precommit as we force RELEASE builds
(which are normally statically linked) to use dynamic linkage.
Anyway, the fix is simple: make the Random instance a member of the test
fixture, and convert a few utility methods into fixture methods. The
'mutable' keyword is syntactic sugar that lets those methods remain 'const'.
Change-Id: I91d4988356a5bbd5e6b33ee08b7d49553be45227
Reviewed-on: http://gerrit.cloudera.org:8080/12899
Reviewed-by: Andrew Wong <aw...@cloudera.com>
Tested-by: Kudu Jenkins
---
.../tserver/tablet_server_authorization-test.cc | 109 +++++++++++----------
1 file changed, 58 insertions(+), 51 deletions(-)
diff --git a/src/kudu/tserver/tablet_server_authorization-test.cc b/src/kudu/tserver/tablet_server_authorization-test.cc
index f05ee1e..56d6b25 100644
--- a/src/kudu/tserver/tablet_server_authorization-test.cc
+++ b/src/kudu/tserver/tablet_server_authorization-test.cc
@@ -195,6 +195,11 @@ Status ChecksumGenerator(const Schema& schema, const SignedTokenPB* token,
class AuthzTabletServerTestBase : public TabletServerTestBase {
public:
const string kUser = "dan";
+
+ AuthzTabletServerTestBase()
+ : prng_(SeedRandom()) {
+ }
+
void SetUp() override {
FLAGS_tserver_enforce_access_control = true;
NO_FATALS(TabletServerTestBase::SetUp());
@@ -215,11 +220,35 @@ class AuthzTabletServerTestBase : public TabletServerTestBase {
}
protected:
+
+ // Utility to select an element from a container at random.
+ template <typename Container, typename T>
+ T SelectAtRandom(const Container& c) const {
+ CHECK(!c.empty());
+ vector<T> rand_list;
+ prng_.ReservoirSample(c, 1, set<T>{}, &rand_list);
+ CHECK_EQ(1, rand_list.size());
+ return rand_list[0];
+ }
+
+ // Returns a randomly-sized randomized list of elements from 'full_set'.
+ template <typename T>
+ vector<T> RandomFromList(const vector<T>& full_list, int min_to_return) const {
+ CHECK_GT(full_list.size(), min_to_return);
+ int num_to_return = min_to_return + rand() % (full_list.size() - min_to_return);
+ vector<T> rand_list;
+ prng_.ReservoirSample(full_list, num_to_return, set<T>{}, &rand_list);
+ return rand_list;
+ }
+
// Signer used to create authz tokens.
unique_ptr<TokenSigner> signer_;
// Initial set of public keys to use to import.
vector<TokenSigningPublicKeyPB> public_keys;
+
+ // Generates various random selections in the tests.
+ mutable Random prng_;
};
class AuthzTabletServerTest : public AuthzTabletServerTestBase,
@@ -467,28 +496,6 @@ void MisnamedColumnSchemaToPB(const ColumnSchema& col, ColumnSchemaPB* pb) {
col.type_attributes()), pb);
}
-Random r(SeedRandom());
-
-// Utility to select an element from a container at random.
-template <typename Container, typename T>
-T SelectAtRandom(const Container& c) {
- CHECK(!c.empty());
- vector<T> rand_list;
- r.ReservoirSample(c, 1, set<T>{}, &rand_list);
- CHECK_EQ(1, rand_list.size());
- return rand_list[0];
-}
-
-// Returns a randomly-sized randomized list of elements from 'full_set'.
-template <typename T>
-vector<T> RandomFromList(const vector<T>& full_list, int min_to_return) {
- CHECK_GT(full_list.size(), min_to_return);
- int num_to_return = min_to_return + rand() % (full_list.size() - min_to_return);
- vector<T> rand_list;
- r.ReservoirSample(full_list, num_to_return, set<T>{}, &rand_list);
- return rand_list;
-}
-
} // anonymous namespace
// Functor to parameterize tests with that generates scan-like requests (e.g.
@@ -1104,35 +1111,6 @@ string WritePrivilegesToString(const WritePrivileges& privileges) {
return Substitute("Privileges: { $0 }", JoinStrings(privs, ", "));
}
-// Returns a randomly selected set of write operation types to be used for
-// sending write requests. Always returns at least one type.
-RowOpTypes RandomOpTypes() {
- static const vector<RowOperationsPB::Type> write_op_types = {
- RowOperationsPB::DELETE,
- RowOperationsPB::INSERT,
- RowOperationsPB::UPDATE,
- RowOperationsPB::UPSERT,
- };
- RowOpTypes types;
- types.reset(RandomFromList(write_op_types, /*min_to_return=*/1));
- return types;
-}
-
-// Returns a randomly selected set of write privileges to be used for
-// generating authz tokens. May be empty.
-WritePrivileges RandomWritePrivileges() {
- static const vector<WritePrivilegeType> write_privilege_types {
- WritePrivilegeType::DELETE,
- WritePrivilegeType::INSERT,
- WritePrivilegeType::UPDATE,
- };
- vector<WritePrivilegeType> rand_types = RandomFromList(write_privilege_types,
- /*min_to_return=*/0);
- WritePrivileges privileges;
- privileges.reset(rand_types);
- return privileges;
-}
-
} // anonymous namespace
class WritePrivilegeAuthzTest : public AuthzTabletServerTestBase {
@@ -1221,6 +1199,35 @@ class WritePrivilegeAuthzTest : public AuthzTabletServerTestBase {
SCOPED_TRACE(WritePrivilegesToString(privileges));
ASSERT_OK(SendWrite(write_ops, privileges));
}
+
+ // Returns a randomly selected set of write operation types to be used for
+ // sending write requests. Always returns at least one type.
+ RowOpTypes RandomOpTypes() const {
+ static const vector<RowOperationsPB::Type> write_op_types = {
+ RowOperationsPB::DELETE,
+ RowOperationsPB::INSERT,
+ RowOperationsPB::UPDATE,
+ RowOperationsPB::UPSERT,
+ };
+ RowOpTypes types;
+ types.reset(RandomFromList(write_op_types, /*min_to_return=*/1));
+ return types;
+ }
+
+ // Returns a randomly selected set of write privileges to be used for
+ // generating authz tokens. May be empty.
+ WritePrivileges RandomWritePrivileges() const {
+ static const vector<WritePrivilegeType> write_privilege_types {
+ WritePrivilegeType::DELETE,
+ WritePrivilegeType::INSERT,
+ WritePrivilegeType::UPDATE,
+ };
+ vector<WritePrivilegeType> rand_types = RandomFromList(write_privilege_types,
+ /*min_to_return=*/0);
+ WritePrivileges privileges;
+ privileges.reset(rand_types);
+ return privileges;
+ }
};
// Simple test for individual write operations.