You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by to...@apache.org on 2017/03/03 20:53:44 UTC
[1/5] kudu git commit: ITBLL: avoid creating client many times during
Generator step
Repository: kudu
Updated Branches:
refs/heads/branch-1.3.x 6cd1e0f9f -> 6139cdd69
ITBLL: avoid creating client many times during Generator step
Previously ITBLL was creating a new client for each table to be created.
This changes it to create the client at the top of 'run' and reuse the
client.
Change-Id: Ib3d9f5c974e1090b9367784fe8214a21a6b96b77
Reviewed-on: http://gerrit.cloudera.org:8080/6236
Reviewed-by: Jean-Daniel Cryans <jd...@apache.org>
Tested-by: Todd Lipcon <to...@apache.org>
(cherry picked from commit 2f94fb665ca1e4fb750215f7522d06c5dfb0631f)
Reviewed-on: http://gerrit.cloudera.org:8080/6241
Reviewed-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/242fbfb7
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/242fbfb7
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/242fbfb7
Branch: refs/heads/branch-1.3.x
Commit: 242fbfb7fb5aee33071b22c96ae8d8cf3ec52be5
Parents: 6cd1e0f
Author: Todd Lipcon <to...@apache.org>
Authored: Thu Mar 2 14:20:44 2017 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Mar 3 18:38:13 2017 +0000
----------------------------------------------------------------------
.../tools/IntegrationTestBigLinkedList.java | 83 +++++++++++---------
1 file changed, 44 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/242fbfb7/java/kudu-client-tools/src/main/java/org/apache/kudu/mapreduce/tools/IntegrationTestBigLinkedList.java
----------------------------------------------------------------------
diff --git a/java/kudu-client-tools/src/main/java/org/apache/kudu/mapreduce/tools/IntegrationTestBigLinkedList.java b/java/kudu-client-tools/src/main/java/org/apache/kudu/mapreduce/tools/IntegrationTestBigLinkedList.java
index 8efac49..19b2ba1 100644
--- a/java/kudu-client-tools/src/main/java/org/apache/kudu/mapreduce/tools/IntegrationTestBigLinkedList.java
+++ b/java/kudu-client-tools/src/main/java/org/apache/kudu/mapreduce/tools/IntegrationTestBigLinkedList.java
@@ -27,6 +27,7 @@ import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import com.google.common.base.Joiner;
+import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
@@ -371,6 +372,9 @@ public class IntegrationTestBigLinkedList extends Configured implements Tool {
private static final Log LOG = LogFactory.getLog(Generator.class);
+ private CommandLineParser parser;
+ private KuduClient client;
+
static class GeneratorInputFormat extends InputFormat<BytesWritable,NullWritable> {
static class GeneratorInputSplit extends InputSplit implements Writable {
@@ -660,57 +664,58 @@ public class IntegrationTestBigLinkedList extends Configured implements Tool {
public int run(int numMappers, long numNodes, int numTablets, Path tmpOutput,
Integer width, Integer wrapMultiplier) throws Exception {
- int ret = runRandomInputGenerator(numMappers, numNodes, tmpOutput, width, wrapMultiplier);
- if (ret > 0) {
- return ret;
+ parser = new CommandLineParser(getConf());
+ client = parser.getClient();
+ try {
+ int ret = runRandomInputGenerator(numMappers, numNodes, tmpOutput, width, wrapMultiplier);
+ if (ret > 0) {
+ return ret;
+ }
+ return runGenerator(numMappers, numNodes, numTablets, tmpOutput, width, wrapMultiplier);
+ } finally {
+ client.close();
+ client = null;
}
- return runGenerator(numMappers, numNodes, numTablets, tmpOutput, width, wrapMultiplier);
}
- protected void createTables(int numTablets) throws Exception {
+ private void createTables(int numTablets) throws Exception {
createSchema(getTableName(getConf()), getTableSchema(), numTablets);
createSchema(getHeadsTable(getConf()), getHeadsTableSchema(), numTablets);
}
- protected void createSchema(String tableName, Schema schema, int numTablets) throws Exception {
- CommandLineParser parser = new CommandLineParser(getConf());
- KuduClient client = parser.getClient();
- try {
- if (numTablets < 1) {
- numTablets = 1;
- }
+ private void createSchema(String tableName, Schema schema, int numTablets) throws Exception {
+ Preconditions.checkNotNull(client);
+ if (numTablets < 1) {
+ numTablets = 1;
+ }
- if (client.tableExists(tableName)) {
- return;
- }
+ if (client.tableExists(tableName)) {
+ return;
+ }
- CreateTableOptions builder =
- new CreateTableOptions().setNumReplicas(parser.getNumReplicas())
- .setRangePartitionColumns(ImmutableList.of("key1", "key2"));
- if (numTablets > 1) {
- BigInteger min = BigInteger.valueOf(Long.MIN_VALUE);
- BigInteger max = BigInteger.valueOf(Long.MAX_VALUE);
- BigInteger step = max.multiply(BigInteger.valueOf(2))
- .divide(BigInteger.valueOf(numTablets));
- LOG.info(min.longValue());
- LOG.info(max.longValue());
- LOG.info(step.longValue());
- PartialRow splitRow = schema.newPartialRow();
- splitRow.addLong("key2", Long.MIN_VALUE);
- for (int i = 1; i < numTablets; i++) {
- long key = min.add(step.multiply(BigInteger.valueOf(i))).longValue();
- LOG.info("key " + key);
- splitRow.addLong("key1", key);
- builder.addSplitRow(splitRow);
- }
+ CreateTableOptions builder =
+ new CreateTableOptions().setNumReplicas(parser.getNumReplicas())
+ .setRangePartitionColumns(ImmutableList.of("key1", "key2"));
+ if (numTablets > 1) {
+ BigInteger min = BigInteger.valueOf(Long.MIN_VALUE);
+ BigInteger max = BigInteger.valueOf(Long.MAX_VALUE);
+ BigInteger step = max.multiply(BigInteger.valueOf(2))
+ .divide(BigInteger.valueOf(numTablets));
+ LOG.info(min.longValue());
+ LOG.info(max.longValue());
+ LOG.info(step.longValue());
+ PartialRow splitRow = schema.newPartialRow();
+ splitRow.addLong("key2", Long.MIN_VALUE);
+ for (int i = 1; i < numTablets; i++) {
+ long key = min.add(step.multiply(BigInteger.valueOf(i))).longValue();
+ LOG.info("key " + key);
+ splitRow.addLong("key1", key);
+ builder.addSplitRow(splitRow);
}
-
- client.createTable(tableName, schema, builder);
- } finally {
- // Done with this client.
- client.shutdown();
}
+
+ client.createTable(tableName, schema, builder);
}
public int runRandomInputGenerator(int numMappers, long numNodes, Path tmpOutput,
[5/5] kudu git commit: mapreduce: support for running on secure
clusters
Posted by to...@apache.org.
mapreduce: support for running on secure clusters
This adds the appropriate hooks to grab authentication credentials at
job submission time and add them to the job's Credentials object as a
Hadoop "Token". The tasks then grab the Token and import it into the
client they create before using it.
It's not possible to test this since we don't have support for running
Kerberized Yarn clusters in the MiniCluster environment. I tested
manually on a secure cluster using ImportTsv, ITBLL, and RowCounter
jobs.
Change-Id: Ieed43b9c8646aaee549078a26850e7e7bdecd802
Reviewed-on: http://gerrit.cloudera.org:8080/6237
Tested-by: Kudu Jenkins
Reviewed-by: Jean-Daniel Cryans <jd...@apache.org>
(cherry picked from commit e9dfbe1e5dd38d4f77ab79537e7e5c6d30e56a1d)
Reviewed-on: http://gerrit.cloudera.org:8080/6242
Reviewed-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/6139cdd6
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/6139cdd6
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/6139cdd6
Branch: refs/heads/branch-1.3.x
Commit: 6139cdd69e781b2adb05c1ee3b6642c1287d902c
Parents: dabf958
Author: Todd Lipcon <to...@apache.org>
Authored: Wed Mar 1 22:38:39 2017 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Mar 3 20:47:33 2017 +0000
----------------------------------------------------------------------
.../tools/IntegrationTestBigLinkedList.java | 2 +
.../org/apache/kudu/client/AsyncKuduClient.java | 9 ++
.../java/org/apache/kudu/client/KuduClient.java | 8 ++
.../kudu/mapreduce/CommandLineParser.java | 5 +-
.../kudu/mapreduce/KuduTableInputFormat.java | 1 +
.../kudu/mapreduce/KuduTableMapReduceUtil.java | 104 +++++++++++++++++++
.../kudu/mapreduce/KuduTableOutputFormat.java | 1 +
7 files changed, 128 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/6139cdd6/java/kudu-client-tools/src/main/java/org/apache/kudu/mapreduce/tools/IntegrationTestBigLinkedList.java
----------------------------------------------------------------------
diff --git a/java/kudu-client-tools/src/main/java/org/apache/kudu/mapreduce/tools/IntegrationTestBigLinkedList.java b/java/kudu-client-tools/src/main/java/org/apache/kudu/mapreduce/tools/IntegrationTestBigLinkedList.java
index 19b2ba1..6171026 100644
--- a/java/kudu-client-tools/src/main/java/org/apache/kudu/mapreduce/tools/IntegrationTestBigLinkedList.java
+++ b/java/kudu-client-tools/src/main/java/org/apache/kudu/mapreduce/tools/IntegrationTestBigLinkedList.java
@@ -774,7 +774,9 @@ public class IntegrationTestBigLinkedList extends Configured implements Tool {
// Lack of YARN-445 means we can't auto-jstack on timeout, so disabling the timeout gives
// us a chance to do it manually.
job.getConfiguration().setInt("mapreduce.task.timeout", 0);
+
KuduTableMapReduceUtil.addDependencyJars(job);
+ KuduTableMapReduceUtil.addCredentialsToJob(client, job);
boolean success = job.waitForCompletion(true);
http://git-wip-us.apache.org/repos/asf/kudu/blob/6139cdd6/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
index acda901..6639284 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/AsyncKuduClient.java
@@ -48,6 +48,7 @@ import javax.annotation.concurrent.GuardedBy;
import javax.security.auth.Subject;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.net.HostAndPort;
@@ -579,6 +580,14 @@ public class AsyncKuduClient implements AutoCloseable {
}
/**
+ * @return the list of master addresses, stringified using commas to separate
+ * them
+ */
+ public String getMasterAddressesAsString() {
+ return Joiner.on(",").join(masterAddresses);
+ }
+
+ /**
* Check if statistics collection is enabled for this client.
* @return true if it is enabled, else false
*/
http://git-wip-us.apache.org/repos/asf/kudu/blob/6139cdd6/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java
----------------------------------------------------------------------
diff --git a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java
index 371d196..b23e5c2 100644
--- a/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java
+++ b/java/kudu-client/src/main/java/org/apache/kudu/client/KuduClient.java
@@ -298,6 +298,14 @@ public class KuduClient implements AutoCloseable {
return asyncClient.getDefaultAdminOperationTimeoutMs();
}
+ /**
+ * @return the list of master addresses, stringified using commas to separate
+ * them
+ */
+ public String getMasterAddressesAsString() {
+ return asyncClient.getMasterAddressesAsString();
+ }
+
// Helper method to handle joining and transforming the Exception we receive.
static <R> R joinAndHandleException(Deferred<R> deferred) throws KuduException {
try {
http://git-wip-us.apache.org/repos/asf/kudu/blob/6139cdd6/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/CommandLineParser.java
----------------------------------------------------------------------
diff --git a/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/CommandLineParser.java b/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/CommandLineParser.java
index 830cb7b..5b701ed 100644
--- a/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/CommandLineParser.java
+++ b/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/CommandLineParser.java
@@ -18,7 +18,6 @@
package org.apache.kudu.mapreduce;
import org.apache.hadoop.conf.Configuration;
-
import org.apache.kudu.annotations.InterfaceAudience;
import org.apache.kudu.annotations.InterfaceStability;
import org.apache.kudu.client.AsyncKuduClient;
@@ -118,11 +117,13 @@ public class CommandLineParser {
* @return a kudu client
*/
public KuduClient getClient() {
- return new KuduClient.KuduClientBuilder(getMasterAddresses())
+ KuduClient c = new KuduClient.KuduClientBuilder(getMasterAddresses())
.defaultOperationTimeoutMs(getOperationTimeoutMs())
.defaultAdminOperationTimeoutMs(getAdminOperationTimeoutMs())
.defaultSocketReadTimeoutMs(getSocketReadTimeoutMs())
.build();
+ KuduTableMapReduceUtil.importCredentialsFromCurrentSubject(c);
+ return c;
}
/**
http://git-wip-us.apache.org/repos/asf/kudu/blob/6139cdd6/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableInputFormat.java
----------------------------------------------------------------------
diff --git a/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableInputFormat.java b/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableInputFormat.java
index 91f4825..8f98170 100644
--- a/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableInputFormat.java
+++ b/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableInputFormat.java
@@ -211,6 +211,7 @@ public class KuduTableInputFormat extends InputFormat<NullWritable, RowResult>
this.client = new KuduClient.KuduClientBuilder(masterAddresses)
.defaultOperationTimeoutMs(operationTimeoutMs)
.build();
+ KuduTableMapReduceUtil.importCredentialsFromCurrentSubject(client);
this.nameServer = conf.get(NAME_SERVER_KEY);
this.cacheBlocks = conf.getBoolean(SCAN_CACHE_BLOCKS, false);
http://git-wip-us.apache.org/repos/asf/kudu/blob/6139cdd6/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableMapReduceUtil.java
----------------------------------------------------------------------
diff --git a/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableMapReduceUtil.java b/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableMapReduceUtil.java
index 6488163..570b464 100644
--- a/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableMapReduceUtil.java
+++ b/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableMapReduceUtil.java
@@ -19,6 +19,7 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
+import java.security.AccessController;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
@@ -29,6 +30,8 @@ import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import javax.security.auth.Subject;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.net.util.Base64;
@@ -36,18 +39,26 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
+import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.TaskInputOutputContext;
+import org.apache.hadoop.security.Credentials;
+import org.apache.hadoop.security.token.Token;
+import org.apache.hadoop.security.token.TokenIdentifier;
import org.apache.hadoop.util.StringUtils;
import org.apache.kudu.annotations.InterfaceAudience;
import org.apache.kudu.annotations.InterfaceStability;
import org.apache.kudu.client.AsyncKuduClient;
import org.apache.kudu.client.ColumnRangePredicate;
+import org.apache.kudu.client.KuduClient;
+import org.apache.kudu.client.KuduException;
import org.apache.kudu.client.KuduPredicate;
import org.apache.kudu.client.KuduTable;
import org.apache.kudu.client.Operation;
+import com.google.common.base.Preconditions;
+
/**
* Utility class to setup MR jobs that use Kudu as an input and/or output.
*/
@@ -59,6 +70,14 @@ public class KuduTableMapReduceUtil {
private static final Log LOG = LogFactory.getLog(KuduTableMapReduceUtil.class);
/**
+ * "Secret key alias" used in Job Credentials to store the Kudu authentication
+ * credentials. This acts as a key in a Hadoop Credentials object.
+ */
+ private static final Text AUTHN_CREDENTIALS_ALIAS = new Text("kudu.authn.credentials");
+
+ private static final Text KUDU_TOKEN_KIND = new Text("kudu-authn-data");
+
+ /**
* Doesn't need instantiation
*/
private KuduTableMapReduceUtil() { }
@@ -96,6 +115,19 @@ public class KuduTableMapReduceUtil {
}
/**
+ * Add credentials to the job so that tasks run as the user that submitted
+ * the job.
+ */
+ protected void addCredentialsToJob(String masterAddresses, long operationTimeoutMs)
+ throws KuduException {
+ try (KuduClient client = new KuduClient.KuduClientBuilder(masterAddresses)
+ .defaultOperationTimeoutMs(operationTimeoutMs)
+ .build()) {
+ KuduTableMapReduceUtil.addCredentialsToJob(client, job);
+ }
+ }
+
+ /**
* Configures the job using the passed parameters.
* @throws IOException If addDependencies is enabled and a problem is encountered reading
* files on the filesystem
@@ -137,6 +169,7 @@ public class KuduTableMapReduceUtil {
if (addDependencies) {
addDependencyJars(job);
}
+ addCredentialsToJob(masterAddresses, operationTimeoutMs);
}
}
@@ -202,6 +235,8 @@ public class KuduTableMapReduceUtil {
if (addDependencies) {
addDependencyJars(job);
}
+
+ addCredentialsToJob(masterAddresses, operationTimeoutMs);
}
}
@@ -363,6 +398,75 @@ public class KuduTableMapReduceUtil {
}
/**
+ * Export the credentials from a {@link KuduClient} and store them in the given MapReduce
+ * {@link Job} so that {@link KuduClient}s created from within tasks of that job can
+ * authenticate to Kudu.
+ *
+ * This must be used before submitting a job when running against a Kudu cluster
+ * configured to require authentication. If using {@link TableInputFormatConfigurator},
+ * {@link TableOutputFormatConfigurator} or another such utility class, this is called
+ * automatically and does not need to be called.
+ *
+ * @param client the client whose credentials to export
+ * @param job the job to configure
+ * @throws KuduException if credentials cannot be exported
+ */
+ public static void addCredentialsToJob(KuduClient client, Job job)
+ throws KuduException {
+ Preconditions.checkNotNull(client);
+ Preconditions.checkNotNull(job);
+
+ byte[] authnCreds = client.exportAuthenticationCredentials();
+ Text service = new Text(client.getMasterAddressesAsString());
+ job.getCredentials().addToken(AUTHN_CREDENTIALS_ALIAS,
+ new Token<TokenIdentifier>(null, authnCreds, KUDU_TOKEN_KIND, service));
+ }
+
+ /**
+ * Import credentials from the current thread's JAAS {@link Subject} into the provided
+ * {@link KuduClient}.
+ *
+ * This must be called for any clients created within a MapReduce job in order to
+ * adopt the credentials added by {@link #addCredentialsToJob(KuduClient, Job)}.
+ * When using {@link KuduTableInputFormat} or {@link KuduTableOutputFormat}, the
+ * implementation automatically handles creating the client and importing necessary
+ * credentials. As such, this is only necessary in jobs that explicitly create a
+ * {@link KuduClient}.
+ *
+ * If no appropriate credentials are found, does nothing.
+ */
+ public static void importCredentialsFromCurrentSubject(KuduClient client) {
+ Subject subj = Subject.getSubject(AccessController.getContext());
+ if (subj == null) {
+ return;
+ }
+ Text service = new Text(client.getMasterAddressesAsString());
+ // Find the Hadoop credentials stored within the JAAS subject.
+ Set<Credentials> credSet = subj.getPrivateCredentials(Credentials.class);
+ if (credSet == null) {
+ return;
+ }
+ for (Credentials creds : credSet) {
+ for (Token<?> tok : creds.getAllTokens()) {
+ if (!tok.getKind().equals(KUDU_TOKEN_KIND)) {
+ continue;
+ }
+ // Only import credentials relevant to the service corresponding to
+ // 'client'. This is necessary if we want to support a job which
+ // reads from one cluster and writes to another.
+ if (!tok.getService().equals(service)) {
+ LOG.debug("Not importing credentials for service " + service +
+ "(expecting service " + service + ")");
+ continue;
+ }
+ LOG.debug("Importing credentials for service " + service);
+ client.importAuthenticationCredentials(tok.getPassword());
+ return;
+ }
+ }
+ }
+
+ /**
* Add the Kudu dependency jars as well as jars for any of the configured
* job classes to the job configuration, so that JobClient will ship them
* to the cluster and add them to the DistributedCache.
http://git-wip-us.apache.org/repos/asf/kudu/blob/6139cdd6/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableOutputFormat.java
----------------------------------------------------------------------
diff --git a/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableOutputFormat.java b/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableOutputFormat.java
index bb64a1e..1a93a36 100644
--- a/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableOutputFormat.java
+++ b/java/kudu-mapreduce/src/main/java/org/apache/kudu/mapreduce/KuduTableOutputFormat.java
@@ -119,6 +119,7 @@ public class KuduTableOutputFormat extends OutputFormat<NullWritable,Operation>
this.client = new KuduClient.KuduClientBuilder(masterAddress)
.defaultOperationTimeoutMs(operationTimeoutMs)
.build();
+ KuduTableMapReduceUtil.importCredentialsFromCurrentSubject(client);
try {
this.table = client.openTable(tableName);
} catch (Exception ex) {
[4/5] kudu git commit: [security] disable PLAIN SASL mech when
authentication is required
Posted by to...@apache.org.
[security] disable PLAIN SASL mech when authentication is required
Change-Id: Id22c43414ed96e2d9d25bf4d13b9f26b08359323
Reviewed-on: http://gerrit.cloudera.org:8080/6235
Reviewed-by: Todd Lipcon <to...@apache.org>
Tested-by: Kudu Jenkins
(cherry picked from commit 28e9349fb775b0215cd2f7ae9a7531390f79d267)
Reviewed-on: http://gerrit.cloudera.org:8080/6243
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/dabf958b
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/dabf958b
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/dabf958b
Branch: refs/heads/branch-1.3.x
Commit: dabf958b56e3dfe4989a4c30ad44df670e1d8e49
Parents: 1183e9d
Author: Dan Burkert <da...@apache.org>
Authored: Thu Mar 2 17:04:29 2017 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Mar 3 18:39:13 2017 +0000
----------------------------------------------------------------------
src/kudu/rpc/messenger.h | 2 +
src/kudu/rpc/negotiation.cc | 78 +++++++++++++++++++++++++------------
src/kudu/rpc/negotiation.h | 6 ++-
src/kudu/rpc/reactor.cc | 3 +-
src/kudu/server/server_base.cc | 1 -
5 files changed, 61 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/dabf958b/src/kudu/rpc/messenger.h
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/messenger.h b/src/kudu/rpc/messenger.h
index f3614a0..2ada341 100644
--- a/src/kudu/rpc/messenger.h
+++ b/src/kudu/rpc/messenger.h
@@ -224,6 +224,8 @@ class Messenger {
authn_token_ = token;
}
+ RpcAuthentication authentication() const { return authentication_; }
+
ThreadPool* negotiation_pool() const { return negotiation_pool_.get(); }
RpczStore* rpcz_store() { return rpcz_store_.get(); }
http://git-wip-us.apache.org/repos/asf/kudu/blob/dabf958b/src/kudu/rpc/negotiation.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/negotiation.cc b/src/kudu/rpc/negotiation.cc
index 8b5b3d4..e912939 100644
--- a/src/kudu/rpc/negotiation.cc
+++ b/src/kudu/rpc/negotiation.cc
@@ -36,6 +36,7 @@
#include "kudu/rpc/rpc_header.pb.h"
#include "kudu/rpc/sasl_common.h"
#include "kudu/rpc/server_negotiation.h"
+#include "kudu/security/tls_context.h"
#include "kudu/util/errno.h"
#include "kudu/util/flag_tags.h"
#include "kudu/util/logging.h"
@@ -54,6 +55,7 @@ DEFINE_int32(rpc_negotiation_inject_delay_ms, 0,
TAG_FLAG(rpc_negotiation_inject_delay_ms, unsafe);
DECLARE_string(keytab_file);
+DECLARE_string(rpc_certificate_file);
DEFINE_bool(rpc_encrypt_loopback_connections, false,
"Whether to encrypt data transfer on RPC connections that stay within "
@@ -151,7 +153,9 @@ static Status DisableSocketTimeouts(Socket* socket) {
}
// Perform client negotiation. We don't LOG() anything, we leave that to our caller.
-static Status DoClientNegotiation(Connection* conn, MonoTime deadline) {
+static Status DoClientNegotiation(Connection* conn,
+ RpcAuthentication authentication,
+ MonoTime deadline) {
const auto* messenger = conn->reactor_thread()->reactor()->messenger();
ClientNegotiation client_negotiation(conn->release_socket(),
&messenger->tls_context(),
@@ -163,23 +167,36 @@ static Status DoClientNegotiation(Connection* conn, MonoTime deadline) {
// canonical hostname to determine the expected server principal.
client_negotiation.set_server_fqdn(conn->remote().host());
- Status s = client_negotiation.EnableGSSAPI();
- if (!s.ok()) {
- // If we can't enable GSSAPI, it's likely the client is just missing the
- // appropriate SASL plugin. We don't want to require it to be installed
- // if the user doesn't care about connecting to servers using Kerberos
- // authentication. So, we'll just VLOG this here. If we try to connect
- // to a server which requires Kerberos, we'll get a negotiation error
- // at that point.
- if (VLOG_IS_ON(1)) {
- KLOG_FIRST_N(INFO, 1) << "Couldn't enable GSSAPI (Kerberos) SASL plugin: "
- << s.message().ToString()
- << ". This process will be unable to connect to "
- << "servers requiring Kerberos authentication.";
+ if (authentication != RpcAuthentication::DISABLED) {
+ Status s = client_negotiation.EnableGSSAPI();
+ if (!s.ok()) {
+ // If we can't enable GSSAPI, it's likely the client is just missing the
+ // appropriate SASL plugin. We don't want to require it to be installed
+ // if the user doesn't care about connecting to servers using Kerberos
+ // authentication. So, we'll just VLOG this here. If we try to connect
+ // to a server which requires Kerberos, we'll get a negotiation error
+ // at that point.
+ if (VLOG_IS_ON(1)) {
+ KLOG_FIRST_N(INFO, 1) << "Couldn't enable GSSAPI (Kerberos) SASL plugin: "
+ << s.message().ToString()
+ << ". This process will be unable to connect to "
+ << "servers requiring Kerberos authentication.";
+ }
+
+ if (authentication == RpcAuthentication::REQUIRED &&
+ !messenger->authn_token() &&
+ !messenger->tls_context().has_signed_cert()) {
+ return Status::InvalidArgument(
+ "Kerberos, token, or PKI certificate credentials must be provided in order to "
+ "require authentication for a client");
+ }
}
}
- RETURN_NOT_OK(client_negotiation.EnablePlain(conn->local_user_credentials().real_user(), ""));
+ if (authentication != RpcAuthentication::REQUIRED) {
+ RETURN_NOT_OK(client_negotiation.EnablePlain(conn->local_user_credentials().real_user(), ""));
+ }
+
client_negotiation.set_deadline(deadline);
RETURN_NOT_OK(WaitForClientConnect(client_negotiation.socket(), deadline));
@@ -195,7 +212,17 @@ static Status DoClientNegotiation(Connection* conn, MonoTime deadline) {
}
// Perform server negotiation. We don't LOG() anything, we leave that to our caller.
-static Status DoServerNegotiation(Connection* conn, const MonoTime& deadline) {
+static Status DoServerNegotiation(Connection* conn,
+ RpcAuthentication authentication,
+ const MonoTime& deadline) {
+ if (authentication == RpcAuthentication::REQUIRED &&
+ FLAGS_keytab_file.empty() &&
+ FLAGS_rpc_certificate_file.empty()) {
+ return Status::InvalidArgument("RPC authentication (--rpc_authentication) may not be "
+ "required unless Kerberos (--keytab_file) or external PKI "
+ "(--rpc_certificate_file et al) are configured");
+ }
+
if (FLAGS_rpc_negotiation_inject_delay_ms > 0) {
LOG(WARNING) << "Injecting " << FLAGS_rpc_negotiation_inject_delay_ms
<< "ms delay in negotiation";
@@ -208,18 +235,17 @@ static Status DoServerNegotiation(Connection* conn, const MonoTime& deadline) {
&messenger->tls_context(),
&messenger->token_verifier());
- // TODO(PKI): this should be enabling PLAIN if authn < required, and GSSAPI if
- // there is a keytab and authn > disabled. Same with client version.
- if (FLAGS_keytab_file.empty()) {
- RETURN_NOT_OK(server_negotiation.EnablePlain());
- } else {
+ if (authentication != RpcAuthentication::DISABLED && !FLAGS_keytab_file.empty()) {
RETURN_NOT_OK(server_negotiation.EnableGSSAPI());
}
+ if (authentication != RpcAuthentication::REQUIRED) {
+ RETURN_NOT_OK(server_negotiation.EnablePlain());
+ }
+
server_negotiation.set_deadline(deadline);
RETURN_NOT_OK(server_negotiation.socket()->SetNonBlocking(false));
-
RETURN_NOT_OK(server_negotiation.Negotiate());
RETURN_NOT_OK(DisableSocketTimeouts(server_negotiation.socket()));
@@ -231,12 +257,14 @@ static Status DoServerNegotiation(Connection* conn, const MonoTime& deadline) {
return Status::OK();
}
-void Negotiation::RunNegotiation(const scoped_refptr<Connection>& conn, MonoTime deadline) {
+void Negotiation::RunNegotiation(const scoped_refptr<Connection>& conn,
+ RpcAuthentication authentication,
+ MonoTime deadline) {
Status s;
if (conn->direction() == Connection::SERVER) {
- s = DoServerNegotiation(conn.get(), deadline);
+ s = DoServerNegotiation(conn.get(), authentication, deadline);
} else {
- s = DoClientNegotiation(conn.get(), deadline);
+ s = DoClientNegotiation(conn.get(), authentication, deadline);
}
if (PREDICT_FALSE(!s.ok())) {
http://git-wip-us.apache.org/repos/asf/kudu/blob/dabf958b/src/kudu/rpc/negotiation.h
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/negotiation.h b/src/kudu/rpc/negotiation.h
index 83539c0..715fca2 100644
--- a/src/kudu/rpc/negotiation.h
+++ b/src/kudu/rpc/negotiation.h
@@ -23,10 +23,10 @@
#include "kudu/util/monotime.h"
namespace kudu {
-
namespace rpc {
class Connection;
+enum class RpcAuthentication;
enum class AuthenticationType {
INVALID,
@@ -42,7 +42,9 @@ class Negotiation {
public:
// Perform negotiation for a connection (either server or client)
- static void RunNegotiation(const scoped_refptr<Connection>& conn, MonoTime deadline);
+ static void RunNegotiation(const scoped_refptr<Connection>& conn,
+ RpcAuthentication authentication,
+ MonoTime deadline);
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(Negotiation);
};
http://git-wip-us.apache.org/repos/asf/kudu/blob/dabf958b/src/kudu/rpc/reactor.cc
----------------------------------------------------------------------
diff --git a/src/kudu/rpc/reactor.cc b/src/kudu/rpc/reactor.cc
index 85f2776..754bca4 100644
--- a/src/kudu/rpc/reactor.cc
+++ b/src/kudu/rpc/reactor.cc
@@ -371,8 +371,9 @@ Status ReactorThread::StartConnectionNegotiation(const scoped_refptr<Connection>
scoped_refptr<Trace> trace(new Trace());
ADOPT_TRACE(trace.get());
TRACE("Submitting negotiation task for $0", conn->ToString());
+ auto authentication = reactor()->messenger()->authentication();
RETURN_NOT_OK(reactor()->messenger()->negotiation_pool()->SubmitClosure(
- Bind(&Negotiation::RunNegotiation, conn, deadline)));
+ Bind(&Negotiation::RunNegotiation, conn, authentication, deadline)));
return Status::OK();
}
http://git-wip-us.apache.org/repos/asf/kudu/blob/dabf958b/src/kudu/server/server_base.cc
----------------------------------------------------------------------
diff --git a/src/kudu/server/server_base.cc b/src/kudu/server/server_base.cc
index 772207d..d15ab8d 100644
--- a/src/kudu/server/server_base.cc
+++ b/src/kudu/server/server_base.cc
@@ -228,7 +228,6 @@ Status ServerBase::Init() {
.set_min_negotiation_threads(FLAGS_min_negotiation_threads)
.set_max_negotiation_threads(FLAGS_max_negotiation_threads)
.set_metric_entity(metric_entity())
- // TODO(PKI): make built-in PKI enabled/disabled based on a flag.
.enable_inbound_tls();
RETURN_NOT_OK(builder.Build(&messenger_));
[3/5] kudu git commit: KUDU-1893 Ensure evaluation of added columns
Posted by to...@apache.org.
KUDU-1893 Ensure evaluation of added columns
During a normal scan, a CFileIterator sets a flag to indicate whether
the block supports decoder-level evaluation, and if, after returning,
this flag has not been set to false, the returned data will be
evaluated against the predicate.
Columns that are added after table creation and after a flush will use
DefaultColumnValueIterators to scan. These iterators were not setting
the flag, so the predicates would not be evaluated on these columns.
All rows in the existing results set would be returned, regardless of
predicates on added columns.
If a column predicate is added to an added column that should filter
out some rows, the scan will yield incorrect results. There is added
test coverage in all_types-scan-correctness-test.cc. Without the
changes in this patch, RunTests() will fail at the following points:
* Null default, Range+IsNull
* Null default, Range+IsNotNull
* Null default, Range
* Non-null default, Range+IsNull
* Non-null default, Range+IsNotNull
* Non-null default, Range with Default
* Non-null default, Range without Default
This patch addresses this by forcing predicate evaluation by the
DefaultColumnValueIterator.
Change-Id: Ic10919962d11effbb1b66d97660acd012b6b4be9
Reviewed-on: http://gerrit.cloudera.org:8080/6129
Tested-by: Kudu Jenkins
Reviewed-by: David Ribeiro Alves <dr...@apache.org>
(cherry picked from commit 3907340a28bad494cc28a0c93431372a811159d0)
Reviewed-on: http://gerrit.cloudera.org:8080/6240
Reviewed-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/1183e9d5
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/1183e9d5
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/1183e9d5
Branch: refs/heads/branch-1.3.x
Commit: 1183e9d59fc3d9fbbe3835ca24b0dbb34e74bb5f
Parents: 6c0704e
Author: Andrew Wong <aw...@cloudera.com>
Authored: Tue Feb 28 16:30:32 2017 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Mar 3 18:38:55 2017 +0000
----------------------------------------------------------------------
src/kudu/cfile/cfile_reader.cc | 14 +
src/kudu/common/column_predicate.cc | 20 +-
src/kudu/common/column_predicate.h | 4 +
.../tablet/all_types-scan-correctness-test.cc | 388 ++++++++++++++++---
4 files changed, 368 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/1183e9d5/src/kudu/cfile/cfile_reader.cc
----------------------------------------------------------------------
diff --git a/src/kudu/cfile/cfile_reader.cc b/src/kudu/cfile/cfile_reader.cc
index d95b618..0b1bfff 100644
--- a/src/kudu/cfile/cfile_reader.cc
+++ b/src/kudu/cfile/cfile_reader.cc
@@ -499,7 +499,16 @@ Status DefaultColumnValueIterator::Scan(ColumnMaterializationContext* ctx) {
ColumnDataView dst_view(dst);
dst_view.SetNullBits(dst->nrows(), value_ != nullptr);
}
+ // Cases where the selection vector can be cleared:
+ // 1. There is a read_default and it does not satisfy the predicate
+ // 2. There is no read_default and the predicate is searching for NULLs
if (value_ != nullptr) {
+ if (ctx->DecoderEvalNotDisabled() &&
+ !ctx->pred()->EvaluateCell(typeinfo_->physical_type(), value_)) {
+ SelectionVectorView sel_view(ctx->sel());
+ sel_view.ClearBits(dst->nrows());
+ return Status::OK();
+ }
if (typeinfo_->physical_type() == BINARY) {
const Slice *src_slice = reinterpret_cast<const Slice *>(value_);
Slice dst_slice;
@@ -514,6 +523,11 @@ Status DefaultColumnValueIterator::Scan(ColumnMaterializationContext* ctx) {
dst->SetCellValue(i, value_);
}
}
+ } else {
+ if (ctx->DecoderEvalNotDisabled() && !ctx->EvaluatingIsNull()) {
+ SelectionVectorView sel_view(ctx->sel());
+ sel_view.ClearBits(dst->nrows());
+ }
}
return Status::OK();
}
http://git-wip-us.apache.org/repos/asf/kudu/blob/1183e9d5/src/kudu/common/column_predicate.cc
----------------------------------------------------------------------
diff --git a/src/kudu/common/column_predicate.cc b/src/kudu/common/column_predicate.cc
index 3b80104..2131b4e 100644
--- a/src/kudu/common/column_predicate.cc
+++ b/src/kudu/common/column_predicate.cc
@@ -582,6 +582,24 @@ void ColumnPredicate::EvaluateForPhysicalType(const ColumnBlock& block,
LOG(FATAL) << "unknown predicate type";
}
+bool ColumnPredicate::EvaluateCell(DataType type, const void* cell) const {
+ switch (type) {
+ case BOOL: return EvaluateCell<BOOL>(cell);
+ case INT8: return EvaluateCell<INT8>(cell);
+ case INT16: return EvaluateCell<INT16>(cell);
+ case INT32: return EvaluateCell<INT32>(cell);
+ case INT64: return EvaluateCell<INT64>(cell);
+ case UINT8: return EvaluateCell<UINT8>(cell);
+ case UINT16: return EvaluateCell<UINT16>(cell);
+ case UINT32: return EvaluateCell<UINT32>(cell);
+ case UINT64: return EvaluateCell<UINT64>(cell);
+ case FLOAT: return EvaluateCell<FLOAT>(cell);
+ case DOUBLE: return EvaluateCell<DOUBLE>(cell);
+ case BINARY: return EvaluateCell<BINARY>(cell);
+ default: LOG(FATAL) << "unknown physical type: " << GetTypeInfo(type)->name();
+ }
+}
+
void ColumnPredicate::Evaluate(const ColumnBlock& block, SelectionVector* sel) const {
DCHECK(sel);
switch (block.type_info()->physical_type()) {
@@ -597,7 +615,7 @@ void ColumnPredicate::Evaluate(const ColumnBlock& block, SelectionVector* sel) c
case FLOAT: return EvaluateForPhysicalType<FLOAT>(block, sel);
case DOUBLE: return EvaluateForPhysicalType<DOUBLE>(block, sel);
case BINARY: return EvaluateForPhysicalType<BINARY>(block, sel);
- default: LOG(FATAL) << "unknown physical type: " << block.type_info()->physical_type();
+ default: LOG(FATAL) << "unknown physical type: " << block.type_info()->name();
}
}
http://git-wip-us.apache.org/repos/asf/kudu/blob/1183e9d5/src/kudu/common/column_predicate.h
----------------------------------------------------------------------
diff --git a/src/kudu/common/column_predicate.h b/src/kudu/common/column_predicate.h
index d28f9b4..6248a68 100644
--- a/src/kudu/common/column_predicate.h
+++ b/src/kudu/common/column_predicate.h
@@ -196,6 +196,10 @@ class ColumnPredicate {
LOG(FATAL) << "unknown predicate type";
}
+ // Evaluate the predicate on a single cell. Used if the physical type is only known at run-time.
+ // Otherwise, use EvaluateCell<DataType>.
+ bool EvaluateCell(DataType type, const void* cell) const;
+
// Print the predicate for debugging.
std::string ToString() const;
http://git-wip-us.apache.org/repos/asf/kudu/blob/1183e9d5/src/kudu/tablet/all_types-scan-correctness-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/tablet/all_types-scan-correctness-test.cc b/src/kudu/tablet/all_types-scan-correctness-test.cc
index 34896de..2bce777 100644
--- a/src/kudu/tablet/all_types-scan-correctness-test.cc
+++ b/src/kudu/tablet/all_types-scan-correctness-test.cc
@@ -9,8 +9,32 @@
namespace kudu {
namespace tablet {
+// Column numbers; kColX refers to column with name "val_x".
+static const int kColA = 1;
+static const int kColB = 2;
+static const int kColC = 3;
+
+// Rows added after altering and before altering the table.
+static const int kNumAddedRows = 2000;
+static const int kNumBaseRows = 10000;
+
+// Number of unique values in each column.
+static const int kCardinality = 21;
+
+// Lower and upper bounds of the predicates.
+static const int kLower = 3;
+static const int kUpper = 10;
+
+// Number of elements to allocate memory for. Each range predicate requires two elements, and each
+// call to AddColumn(read_default) requires one. Must be greater than the number of elements
+// actually needed.
+static const int kNumAllocatedElements = 32;
+
+// Strings and binaries will have the following string length.
+static const int kStrlen = 10;
+
struct RowOpsBase {
- RowOpsBase(DataType type, EncodingType encoding) {
+ RowOpsBase(DataType type, EncodingType encoding) : type_(type), encoding_(encoding) {
schema_ = Schema({ColumnSchema("key", INT32),
ColumnSchema("val_a", type, true, nullptr, nullptr,
ColumnStorageAttributes(encoding, DEFAULT_COMPRESSION)),
@@ -18,6 +42,8 @@ struct RowOpsBase {
ColumnStorageAttributes(encoding, DEFAULT_COMPRESSION))}, 1);
}
+ DataType type_;
+ EncodingType encoding_;
Schema schema_;
Schema altered_schema_;
};
@@ -25,34 +51,48 @@ struct RowOpsBase {
template<typename KeyTypeWrapper>
struct SliceTypeRowOps : public RowOpsBase {
SliceTypeRowOps() : RowOpsBase(KeyTypeWrapper::type, KeyTypeWrapper::encoding),
- strs_(16), slices_(16), cur(0) {}
+ strs_(kNumAllocatedElements), slices_(kNumAllocatedElements), cur(0) {}
// Assumes the string representation of n is under strlen characters.
- std::string LeftZeroPadded(const int& n, const int& strlen) {
+ std::string LeftZeroPadded(int n, int strlen) {
return StringPrintf(Substitute("%0$0$1", strlen, PRId64).c_str(), static_cast<int64_t>(n));
}
- void GenerateRow(const int& value, KuduPartialRow* row) {
+ void GenerateRow(int value, bool altered, KuduPartialRow* row) {
if (value < 0) {
- CHECK_OK(row->SetNull(1));
- CHECK_OK(row->SetNull(2));
+ CHECK_OK(row->SetNull(kColA));
+ CHECK_OK(row->SetNull(kColB));
+ if (altered) {
+ CHECK_OK(row->SetNull(kColC));
+ }
} else {
std::string string_a = LeftZeroPadded(value, 10);
std::string string_b = LeftZeroPadded(value, 10);
+ std::string string_c = LeftZeroPadded(value, 10);
Slice slice_a(string_a);
Slice slice_b(string_b);
- CHECK_OK(row->SetSliceCopy<TypeTraits<KeyTypeWrapper::type>>(1, slice_a));
- CHECK_OK(row->SetSliceCopy<TypeTraits<KeyTypeWrapper::type>>(2, slice_b));
+ Slice slice_c(string_c);
+ CHECK_OK(row->SetSliceCopy<TypeTraits<KeyTypeWrapper::type>>(kColA, slice_a));
+ CHECK_OK(row->SetSliceCopy<TypeTraits<KeyTypeWrapper::type>>(kColB, slice_b));
+ if (altered) {
+ CHECK_OK(row->SetSliceCopy<TypeTraits<KeyTypeWrapper::type>>(kColC, slice_c));
+ }
}
}
- ColumnPredicate GenerateRangePredicate(const size_t& col, const int& lower, const int& upper) {
+ void* GenerateElement(int value) {
+ strs_[cur] = LeftZeroPadded(value, kStrlen);
+ slices_[cur] = Slice(strs_[cur]);
+ return &slices_[cur++];
+ }
+
+ ColumnPredicate GenerateRangePredicate(const Schema& schema, size_t col, int lower, int upper) {
// Key predicate strings and slices in scope in a vector.
strs_[cur] = LeftZeroPadded(lower, 10);
- strs_[cur+1] = LeftZeroPadded(upper, 10);
+ strs_[cur + 1] = LeftZeroPadded(upper, 10);
slices_[cur] = Slice(strs_[cur]);
- slices_[cur+1] = Slice(strs_[cur+1]);
- auto pred = ColumnPredicate::Range(schema_.column(col), &slices_[cur], &slices_[cur+1]);
+ slices_[cur + 1] = Slice(strs_[cur + 1]);
+ auto pred = ColumnPredicate::Range(schema.column(col), &slices_[cur], &slices_[cur + 1]);
cur += 2;
return pred;
}
@@ -67,24 +107,35 @@ struct SliceTypeRowOps : public RowOpsBase {
template<typename KeyTypeWrapper>
struct NumTypeRowOps : public RowOpsBase {
NumTypeRowOps() : RowOpsBase(KeyTypeWrapper::type, KeyTypeWrapper::encoding),
- nums_(16), cur(0) {}
+ nums_(kNumAllocatedElements), cur(0) {}
typedef typename TypeTraits<KeyTypeWrapper::type>::cpp_type CppType;
- void GenerateRow(const int& value, KuduPartialRow* row) {
+ void GenerateRow(int value, bool altered, KuduPartialRow* row) {
if (value < 0) {
- CHECK_OK(row->SetNull(1));
- CHECK_OK(row->SetNull(2));
+ CHECK_OK(row->SetNull(kColA));
+ CHECK_OK(row->SetNull(kColB));
+ if (altered) {
+ CHECK_OK(row->SetNull(kColC));
+ }
} else {
- row->Set<TypeTraits<KeyTypeWrapper::type>>(1, value);
- row->Set<TypeTraits<KeyTypeWrapper::type>>(2, value);
+ row->Set<TypeTraits<KeyTypeWrapper::type>>(kColA, value);
+ row->Set<TypeTraits<KeyTypeWrapper::type>>(kColB, value);
+ if (altered) {
+ row->Set<TypeTraits<KeyTypeWrapper::type>>(kColC, value);
+ }
}
}
- ColumnPredicate GenerateRangePredicate(const size_t& col , const int& lower, const int& upper) {
+ void* GenerateElement(int value) {
+ nums_[cur] = value;
+ return &nums_[cur++];
+ }
+
+ ColumnPredicate GenerateRangePredicate(const Schema& schema, size_t col, int lower, int upper) {
nums_[cur] = lower;
- nums_[cur+1] = upper;
- auto pred = ColumnPredicate::Range(schema_.column(col), &nums_[cur], &nums_[cur+1]);
+ nums_[cur + 1] = upper;
+ auto pred = ColumnPredicate::Range(schema.column(col), &nums_[cur], &nums_[cur + 1]);
cur += 2;
return pred;
}
@@ -97,8 +148,7 @@ struct NumTypeRowOps : public RowOpsBase {
// Calculates the number of values in the range [lower, upper) given a repeated, completely
// non-null pattern with the specified cardinality and the specified number of rows.
-int ExpectedCount(const int& nrows, const int& cardinality, const int& lower_val,
- const int& upper_val) {
+int ExpectedCount(int nrows, int cardinality, int lower_val, int upper_val) {
if (lower_val >= upper_val || lower_val >= cardinality) {
return 0;
}
@@ -123,10 +173,10 @@ int ExpectedCount(const int& nrows, const int& cardinality, const int& lower_val
return (nrows / cardinality) * (upper - lower) + last_chunk_count;
}
-void ScopedTraceMsg(const std::string& test_name, const int& expected, const int& actual) {
+std::string TraceMsg(const std::string& test_name, int expected, int actual) {
std::ostringstream ss;
ss << test_name << " Scan Results: " << expected << " expected, " << actual << " returned.";
- SCOPED_TRACE(ss.str());
+ return ss.str();
}
// Tests for correctness by running predicates on repeated patterns of rows, specified by nrows,
@@ -136,7 +186,8 @@ template <class RowOps>
class AllTypesScanCorrectnessTest : public KuduTabletTest {
public:
AllTypesScanCorrectnessTest() : KuduTabletTest(RowOps().schema_), rowops_(RowOps()),
- schema_(rowops_.schema_), base_nrows_(0), base_cardinality_(0), base_null_upper_(0) {}
+ schema_(rowops_.schema_), altered_schema_(schema_),
+ base_nrows_(0), base_cardinality_(0), base_null_upper_(0), added_nrows_(0) {}
void SetUp() override {
KuduTabletTest::SetUp();
@@ -150,7 +201,6 @@ public:
base_nrows_ = nrows;
base_cardinality_ = cardinality;
base_null_upper_ = null_upper;
- RowBuilder rb(client_schema_);
LocalTabletWriter writer(tablet().get(), &client_schema_);
KuduPartialRow row(&client_schema_);
for (int i = 0; i < nrows; i++) {
@@ -159,46 +209,88 @@ public:
// Populate the bottom of the repeating pattern with NULLs.
// Note: Non-positive null_upper will yield a completely non-NULL column.
if (i % cardinality < null_upper) {
- rowops_.GenerateRow(-1, &row);
+ rowops_.GenerateRow(-1, false, &row);
} else {
- rowops_.GenerateRow(i % cardinality, &row);
+ rowops_.GenerateRow(i % cardinality, false, &row);
}
ASSERT_OK_FAST(writer.Insert(row));
}
ASSERT_OK(tablet()->Flush());
}
+ // Adds the above pattern to the table with keys starting after the base rows.
+ void FillAlteredTestTablet(int nrows) {
+ added_nrows_ = nrows;
+ LocalTabletWriter writer(tablet().get(), &altered_schema_);
+ KuduPartialRow row(&altered_schema_);
+ for (int i = 0; i < nrows; i++) {
+ CHECK_OK(row.SetInt32(0, base_nrows_ + i));
+ if (i % base_cardinality_ < base_null_upper_) {
+ rowops_.GenerateRow(-1, true, &row);
+ } else {
+ rowops_.GenerateRow(i % base_cardinality_, true, &row);
+ }
+ ASSERT_OK_FAST(writer.Upsert(row));
+ }
+ ASSERT_OK(tablet()->Flush());
+ }
+
+ // Adds a column called "val_c" to the schema with the specified read-default.
+ void AddColumn(int read_default) {
+ void* default_ptr;
+ if (read_default < 0) {
+ default_ptr = nullptr;
+ } else {
+ default_ptr = rowops_.GenerateElement(read_default);
+ }
+ SchemaBuilder builder(tablet()->metadata()->schema());
+ builder.RemoveColumn("val_c");
+ ASSERT_OK(builder.AddColumn("val_c", rowops_.type_, true, default_ptr, nullptr));
+ AlterSchema(builder.Build());
+ altered_schema_ = Schema({ColumnSchema("key", INT32),
+ ColumnSchema("val_a", rowops_.type_, true, nullptr, nullptr,
+ ColumnStorageAttributes(rowops_.encoding_, DEFAULT_COMPRESSION)),
+ ColumnSchema("val_b", rowops_.type_, true, nullptr, nullptr,
+ ColumnStorageAttributes(rowops_.encoding_, DEFAULT_COMPRESSION)),
+ ColumnSchema("val_c", rowops_.type_, true, default_ptr, nullptr,
+ ColumnStorageAttributes(rowops_.encoding_, DEFAULT_COMPRESSION))}, 1);
+ }
+
// Scan the results of a query. Set "count" to the number of results satisfying the predicates.
// ScanSpec must have all desired predicates already added to it.
- void ScanWithSpec(ScanSpec spec, int* count) {
+ void ScanWithSpec(const Schema& schema, ScanSpec spec, int* count) {
Arena arena(1028, 1028);
AutoReleasePool pool;
*count = 0;
- spec.OptimizeScan(client_schema_, &arena, &pool, true);
+ spec.OptimizeScan(schema, &arena, &pool, true);
gscoped_ptr<RowwiseIterator> iter;
- ASSERT_OK(tablet()->NewRowIterator(client_schema_, &iter));
+ ASSERT_OK(tablet()->NewRowIterator(schema, &iter));
ASSERT_OK(iter->Init(&spec));
ASSERT_TRUE(spec.predicates().empty()) << "Should have accepted all predicate.";
ASSERT_OK(SilentIterateToStringList(iter.get(), count));
}
void RunTests() {
- int lower = 3;
- int upper = 10;
- int lower_non_null = 3;
- int zero = 0;
- if (lower < base_null_upper_) {
+ RunUnalteredTabletTests();
+ RunAlteredTabletTests();
+ }
+
+ // Runs queries on an un-altered table. Correctness is determined by comparing the number of rows
+ // returned with the number of rows expected by each query.
+ void RunUnalteredTabletTests() {
+ int lower_non_null = kLower;
+ if (kLower < base_null_upper_) {
lower_non_null = base_null_upper_;
}
int count = 0;
{
ScanSpec spec;
- auto pred = rowops_.GenerateRangePredicate(1, lower, upper);
+ auto pred = rowops_.GenerateRangePredicate(schema_, kColA, kLower, kUpper);
spec.AddPredicate(pred);
- ScanWithSpec(spec, &count);
- int expected_count = ExpectedCount(base_nrows_, base_cardinality_, lower_non_null, upper);
- ScopedTraceMsg("Range", expected_count, count);
+ ScanWithSpec(schema_, spec, &count);
+ int expected_count = ExpectedCount(base_nrows_, base_cardinality_, lower_non_null, kUpper);
+ SCOPED_TRACE(TraceMsg("Range", expected_count, count));
ASSERT_EQ(expected_count, count);
}
{
@@ -209,32 +301,210 @@ public:
// Since the two columns have identical data, the result will be:
// AND: [lower_val, upper_val)
ScanSpec spec;
- ColumnPredicate pred_a = rowops_.GenerateRangePredicate(1, zero, upper);
+ ColumnPredicate pred_a = rowops_.GenerateRangePredicate(schema_, kColA, 0, kUpper);
spec.AddPredicate(pred_a);
- ColumnPredicate pred_b = rowops_.GenerateRangePredicate(2, lower, base_cardinality_);
+ ColumnPredicate pred_b = rowops_.GenerateRangePredicate(schema_, kColB, kLower,
+ base_cardinality_);
spec.AddPredicate(pred_b);
- ScanWithSpec(spec, &count);
- int expected_count = ExpectedCount(base_nrows_, base_cardinality_, lower_non_null, upper);
- ScopedTraceMsg("MultiColumn Range", expected_count, count);
+ ScanWithSpec(schema_, spec, &count);
+ int expected_count = ExpectedCount(base_nrows_, base_cardinality_, lower_non_null, kUpper);
+ SCOPED_TRACE(TraceMsg("MultiColumn Range", expected_count, count));
ASSERT_EQ(expected_count, count);
}
{
ScanSpec spec;
- auto pred = ColumnPredicate::IsNotNull(schema_.column(2));
+ auto pred = ColumnPredicate::IsNotNull(schema_.column(kColB));
spec.AddPredicate(pred);
- ScanWithSpec(spec, &count);
+ ScanWithSpec(schema_, spec, &count);
int expected_count = ExpectedCount(base_nrows_, base_cardinality_, base_null_upper_,
base_cardinality_);
- ScopedTraceMsg("IsNotNull", expected_count, count);
+ SCOPED_TRACE(TraceMsg("IsNotNull", expected_count, count));
ASSERT_EQ(expected_count, count);
}
{
ScanSpec spec;
- auto pred = ColumnPredicate::IsNull(schema_.column(2));
+ auto pred = ColumnPredicate::IsNull(schema_.column(kColB));
spec.AddPredicate(pred);
- ScanWithSpec(spec, &count);
- int expected_count = ExpectedCount(base_nrows_, base_cardinality_, zero, base_null_upper_);
- ScopedTraceMsg("IsNull", expected_count, count);
+ ScanWithSpec(schema_, spec, &count);
+ int expected_count = ExpectedCount(base_nrows_, base_cardinality_, 0, base_null_upper_);
+ SCOPED_TRACE(TraceMsg("IsNull", expected_count, count));
+ ASSERT_EQ(expected_count, count);
+ }
+ }
+
+ // Runs tests with an altered table. Queries are run with different read-defaults and are deemed
+ // correct if they return the correct number of results.
+ void RunAlteredTabletTests() {
+ int lower_non_null = kLower;
+ // Determine the lowest non-null value in the data range. Used in getting expected counts.
+ if (kLower < base_null_upper_) {
+ lower_non_null = base_null_upper_;
+ }
+ // Tests with null read-default. Ex. case: (-: null, 1: pred satisfied, 0: pred not satisfied)
+ // kLower: 5, kUpper: 8
+ // Base nrows: 30 |Altered nrows: 25
+ // Cardinality: 20, null_upper: 3, read_default: NULL
+ // Predicate: (val_b >= 0 && val_b < 8) && (val_c >= 5 && val_c < 20)
+ // 0 5 10 15 20 25 |30 35 40 45 50 key
+ // [---11111000000000000---1111100|---11111000000000000---11] val_b
+ // [------------------------------|---00111111111111111---00] val_c
+ // [000000000000000000000000000000|0000011100000000000000000] Result
+ AddColumn(-1);
+ FillAlteredTestTablet(kNumAddedRows);
+ int count = 0;
+ {
+ ScanSpec spec;
+ // val_b >= kLower && val_b <= kUpper && val_c is null
+ auto pred_b = rowops_.GenerateRangePredicate(altered_schema_, kColB, kLower, kUpper);
+ auto pred_c = ColumnPredicate::IsNull(altered_schema_.column(kColC));
+ spec.AddPredicate(pred_b);
+ spec.AddPredicate(pred_c);
+ ScanWithSpec(altered_schema_, spec, &count);
+ int base_expected_count = ExpectedCount(base_nrows_,
+ base_cardinality_,
+ lower_non_null,
+ kUpper);
+ // Since the new column has the same data as the base columns, IsNull with a Range predicate
+ // should yield no rows from the added rows.
+ int altered_expected_count = 0;
+ int expected_count = base_expected_count + altered_expected_count;
+ SCOPED_TRACE(TraceMsg("Null default, Range+IsNull", expected_count, count));
+ ASSERT_EQ(expected_count, count);
+ }
+ {
+ ScanSpec spec;
+ // val_b >= kLower && val_b <= kUpper && val_c is not null
+ auto pred_b = rowops_.GenerateRangePredicate(altered_schema_, kColB, kLower, kUpper);
+ auto pred_c = ColumnPredicate::IsNotNull(altered_schema_.column(kColC));
+ spec.AddPredicate(pred_b);
+ spec.AddPredicate(pred_c);
+ ScanWithSpec(altered_schema_, spec, &count);
+ // Since the table has a null read-default on the added column, the IsNotNull predicate
+ // should filter out all rows in the base data.
+ int base_expected_count = 0;
+ int altered_expected_count = ExpectedCount(added_nrows_,
+ base_cardinality_,
+ lower_non_null,
+ kUpper);
+ int expected_count = base_expected_count + altered_expected_count;
+ SCOPED_TRACE(TraceMsg("Null default, Range+IsNotNull", expected_count, count));
+ ASSERT_EQ(expected_count, count);
+ }
+ {
+ ScanSpec spec;
+ // val_b >= 0 && val_b < kUpper && val_c >= kLower && val_c < cardinality
+ auto pred_b = rowops_.GenerateRangePredicate(altered_schema_, kColB, 0, kUpper);
+ auto pred_c = rowops_.GenerateRangePredicate(altered_schema_, kColC, kLower,
+ base_cardinality_);
+ spec.AddPredicate(pred_b);
+ spec.AddPredicate(pred_c);
+ ScanWithSpec(altered_schema_, spec, &count);
+ // Since the added column has a null read-default, the base rows will be completely filtered.
+ int base_expected_count = 0;
+ // The added data will be predicated with [lower, upper).
+ int altered_expected_count = ExpectedCount(added_nrows_,
+ base_cardinality_,
+ lower_non_null,
+ kUpper);
+ int expected_count = base_expected_count + altered_expected_count;
+ SCOPED_TRACE(TraceMsg("Null default, Range", expected_count, count));
+ ASSERT_EQ(expected_count, count);
+ }
+ // Tests with non-null read-default. Ex. case:
+ // kLower: 5, kUpper: 8
+ // Base nrows: 30 |Altered nrows: 25
+ // Cardinality: 20, null_upper: 3, read_default: 7
+ // Predicate: (val_b >= 0 && val_b < 8) && (val_c >= 5 && val_c < 20)
+ // 0 5 10 15 20 25 |30 35 40 45 50 key
+ // [---11111000000000000---1111100|---11111000000000000---11] val_b
+ // [111111111111111111111111111111|---00111111111111111---00] val_c
+ // [000111110000000000000001111100|0000011100000000000000000] Result
+ int read_default = 7;
+ AddColumn(read_default);
+ FillAlteredTestTablet(kNumAddedRows);
+ {
+ ScanSpec spec;
+ // val_b >= kLower && val_b <= kUpper && val_c is null
+ auto pred_b = rowops_.GenerateRangePredicate(altered_schema_, kColB, kLower, kUpper);
+ auto pred_c = ColumnPredicate::IsNull(altered_schema_.column(kColC));
+ spec.AddPredicate(pred_b);
+ spec.AddPredicate(pred_c);
+ ScanWithSpec(altered_schema_, spec, &count);
+ // The base data is not null, since there is a read-default.
+ int base_expected_count = 0;
+ // Since the new column has the same data as the base columns, IsNull with a Range predicate
+ // should yield no rows from the added rows.
+ int altered_expected_count = 0;
+ int expected_count = base_expected_count + altered_expected_count;
+ SCOPED_TRACE(TraceMsg("Non-null default, Range+IsNull", expected_count, count));
+ ASSERT_EQ(expected_count, count);
+ }
+ {
+ ScanSpec spec;
+ // val_b >= kLower && val_b <= kUpper && val_c is not null
+ auto pred_b = rowops_.GenerateRangePredicate(altered_schema_, kColB, kLower, kUpper);
+ auto pred_c = ColumnPredicate::IsNotNull(altered_schema_.column(kColC));
+ spec.AddPredicate(pred_b);
+ spec.AddPredicate(pred_c);
+ ScanWithSpec(altered_schema_, spec, &count);
+ int base_expected_count = ExpectedCount(base_nrows_, base_cardinality_, lower_non_null,
+ kUpper);
+ // Since the new column has the same data as the base columns, IsNotNull with a Range
+ // predicate should yield the same rows as the Range query alone on the altered data.
+ int altered_expected_count = ExpectedCount(added_nrows_, base_cardinality_, lower_non_null,
+ kUpper);
+ int expected_count = base_expected_count + altered_expected_count;
+ SCOPED_TRACE(TraceMsg("Non-null default, Range+IsNotNull", expected_count, count));
+ ASSERT_EQ(expected_count, count);
+ }
+ {
+ int lower = 0;
+ ScanSpec spec;
+ // val_b >= 0 && val_b < kUpper && val_c >= kLower && val_c < cardinality
+ auto pred_b = rowops_.GenerateRangePredicate(altered_schema_, kColB, 0, kUpper);
+ auto pred_c = rowops_.GenerateRangePredicate(altered_schema_, kColC, kLower,
+ base_cardinality_);
+ spec.AddPredicate(pred_b);
+ spec.AddPredicate(pred_c);
+ ScanWithSpec(altered_schema_, spec, &count);
+ // Take into account possible null values when calculating expected counts.
+ if (base_null_upper_ > 0) {
+ lower = base_null_upper_;
+ }
+ // Because the read_default is in range, the predicate on "val_c" will be satisfied
+ // by base data, and all rows that satisfy "pred_b" will be returned.
+ int base_expected_count = ExpectedCount(base_nrows_, base_cardinality_, lower, kUpper);
+ int altered_expected_count = ExpectedCount(added_nrows_,
+ base_cardinality_,
+ lower_non_null,
+ kUpper);
+ int expected_count = base_expected_count + altered_expected_count;
+ SCOPED_TRACE(TraceMsg("Non-null default, Range with Default", expected_count, count));
+ ASSERT_EQ(expected_count, count);
+ }
+ {
+ // Used to ensure the query does not select the read-default.
+ int default_plus_one = read_default + 1;
+ ScanSpec spec;
+ // val_b >= 0 && val_b < kUpper && val_c >= read_default + 1 && val_c < cardinality
+ auto pred_b = rowops_.GenerateRangePredicate(altered_schema_, kColB, 0, kUpper);
+ auto pred_c = rowops_.GenerateRangePredicate(altered_schema_, kColC, default_plus_one,
+ base_cardinality_);
+ spec.AddPredicate(pred_b);
+ spec.AddPredicate(pred_c);
+ ScanWithSpec(altered_schema_, spec, &count);
+ if (default_plus_one < base_null_upper_) {
+ default_plus_one = base_null_upper_;
+ }
+ // Because the read_default is out of range, the "pred_c" will not be satisfied by base data,
+ // so all base rows will be filtered.
+ int base_expected_count = 0;
+ int altered_expected_count = ExpectedCount(added_nrows_,
+ base_cardinality_,
+ default_plus_one,
+ kUpper);
+ int expected_count = base_expected_count + altered_expected_count;
+ SCOPED_TRACE(TraceMsg("Non-null default, Range without Default", expected_count, count));
ASSERT_EQ(expected_count, count);
}
}
@@ -242,10 +512,11 @@ public:
protected:
RowOps rowops_;
Schema schema_;
+ Schema altered_schema_;
int base_nrows_;
int base_cardinality_;
int base_null_upper_;
- bool has_been_altered_;
+ int added_nrows_;
};
template<DataType KeyType, EncodingType Encoding>
@@ -280,17 +551,20 @@ typedef ::testing::Types<NumTypeRowOps<KeyTypeWrapper<INT8, BIT_SHUFFLE>>,
TYPED_TEST_CASE(AllTypesScanCorrectnessTest, KeyTypes);
TYPED_TEST(AllTypesScanCorrectnessTest, AllNonNull) {
- this->FillTestTablet(10000, 21, 0);
+ int null_upper = 0;
+ this->FillTestTablet(kNumBaseRows, kCardinality, null_upper);
this->RunTests();
}
TYPED_TEST(AllTypesScanCorrectnessTest, SomeNull) {
- this->FillTestTablet(10000, 21, 5);
+ int null_upper = kUpper/2;
+ this->FillTestTablet(kNumBaseRows, kCardinality, null_upper);
this->RunTests();
}
TYPED_TEST(AllTypesScanCorrectnessTest, AllNull) {
- this->FillTestTablet(10000, 21, 21);
+ int null_upper = kCardinality;
+ this->FillTestTablet(kNumBaseRows, kCardinality, null_upper);
this->RunTests();
}
[2/5] kudu git commit: KUDU-1834 Don't redact
KuduRowResult::ToString()
Posted by to...@apache.org.
KUDU-1834 Don't redact KuduRowResult::ToString()
A user on the client side calling ToString on the results of a scan
will likely expect the data to not be redacted. This patch forces
KuduScanPatch::RowPtr::ToString() to not redact.
A test case is added to client-test that turns redaction on and
compares the output of ToString with a redacted row. If the row is
redacted, this case fill fail.
Change-Id: If966e9ba76f747de85350ffa2b91fcf05a9ad324
Reviewed-on: http://gerrit.cloudera.org:8080/6222
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Tested-by: Kudu Jenkins
(cherry picked from commit f1da1eb450cb77878d44d1115d64c05f652378f1)
Reviewed-on: http://gerrit.cloudera.org:8080/6244
Reviewed-by: Todd Lipcon <to...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/6c0704e3
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/6c0704e3
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/6c0704e3
Branch: refs/heads/branch-1.3.x
Commit: 6c0704e315ef57b77ec8710a60d4410d60e51e68
Parents: 242fbfb
Author: Andrew Wong <aw...@cloudera.com>
Authored: Wed Mar 1 16:03:17 2017 -0800
Committer: Todd Lipcon <to...@apache.org>
Committed: Fri Mar 3 18:38:24 2017 +0000
----------------------------------------------------------------------
src/kudu/client/client-test.cc | 19 +++++++++++++++++++
src/kudu/client/scan_batch.cc | 3 +++
2 files changed, 22 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kudu/blob/6c0704e3/src/kudu/client/client-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/client-test.cc b/src/kudu/client/client-test.cc
index f695f7c..702c13d 100644
--- a/src/kudu/client/client-test.cc
+++ b/src/kudu/client/client-test.cc
@@ -1082,6 +1082,25 @@ TEST_F(ClientTest, TestScanCloseProxy) {
}
}
+// Check that the client scanner does not redact rows.
+TEST_F(ClientTest, TestRowPtrNoRedaction) {
+ google::SetCommandLineOption("redact", "log");
+
+ NO_FATALS(InsertTestRows(client_table_.get(), FLAGS_test_scan_num_rows));
+ KuduScanner scanner(client_table_.get());
+ ASSERT_OK(scanner.SetProjectedColumns({ "key" }));
+ ASSERT_OK(scanner.Open());
+
+ ASSERT_TRUE(scanner.HasMoreRows());
+ KuduScanBatch batch;
+ while (scanner.HasMoreRows()) {
+ ASSERT_OK(scanner.NextBatch(&batch));
+ for (const KuduScanBatch::RowPtr& row : batch) {
+ ASSERT_NE("(int32 key=<redacted>)", row.ToString());
+ }
+ }
+}
+
namespace internal {
static void ReadBatchToStrings(KuduScanner* scanner, vector<string>* rows) {
http://git-wip-us.apache.org/repos/asf/kudu/blob/6c0704e3/src/kudu/client/scan_batch.cc
----------------------------------------------------------------------
diff --git a/src/kudu/client/scan_batch.cc b/src/kudu/client/scan_batch.cc
index 14d1784..fb9a538 100644
--- a/src/kudu/client/scan_batch.cc
+++ b/src/kudu/client/scan_batch.cc
@@ -285,6 +285,9 @@ template
Status KuduScanBatch::RowPtr::Get<TypeTraits<BINARY> >(int col_idx, Slice* val) const;
string KuduScanBatch::RowPtr::ToString() const {
+ // Client-users calling ToString() will likely expect it to not be redacted.
+ ScopedDisableRedaction no_redaction;
+
string ret;
ret.append("(");
bool first = true;