|
17 | 17 | package site.ycsb.db.cloudspanner; |
18 | 18 |
|
19 | 19 | import com.google.common.base.Joiner; |
| 20 | +import com.google.cloud.NoCredentials; |
20 | 21 | import com.google.cloud.spanner.DatabaseId; |
21 | 22 | import com.google.cloud.spanner.DatabaseClient; |
22 | 23 | import com.google.cloud.spanner.Key; |
|
32 | 33 | import com.google.cloud.spanner.Struct; |
33 | 34 | import com.google.cloud.spanner.StructReader; |
34 | 35 | import com.google.cloud.spanner.TimestampBound; |
| 36 | +import io.grpc.ManagedChannelBuilder; |
35 | 37 | import site.ycsb.ByteIterator; |
36 | 38 | import site.ycsb.Client; |
37 | 39 | import site.ycsb.DB; |
@@ -100,6 +102,15 @@ private CloudSpannerProperties() {} |
100 | 102 | * Number of Cloud Spanner client channels to use. It's recommended to leave this to be the default value. |
101 | 103 | */ |
102 | 104 | static final String NUM_CHANNELS = "cloudspanner.channels"; |
| 105 | + /** |
| 106 | + * Use plain text for communication. |
| 107 | + */ |
| 108 | + static final String USE_PLAINTEXT = "cloudspanner.useplaintext"; |
| 109 | + |
| 110 | + /** |
| 111 | + * Connect to Experimental host instead of cloud spanner API. |
| 112 | + */ |
| 113 | + static final String EXPERIMENTAL_HOST="cloudspanner.experimentalhost"; |
103 | 114 | } |
104 | 115 |
|
105 | 116 | private static int fieldCount; |
@@ -167,6 +178,18 @@ private static Spanner getSpanner(Properties properties, String host, String pro |
167 | 178 | if (numChannels != null) { |
168 | 179 | optionsBuilder.setNumChannels(Integer.parseInt(numChannels)); |
169 | 180 | } |
| 181 | + boolean usePlaintext = Boolean.parseBoolean(properties.getProperty(CloudSpannerProperties.USE_PLAINTEXT)); |
| 182 | + if (usePlaintext) { |
| 183 | + optionsBuilder.setChannelConfigurator(ManagedChannelBuilder::usePlaintext); |
| 184 | + //Disable credentials and built in metrics when plaintext is used. |
| 185 | + optionsBuilder.setCredentials(NoCredentials.getInstance()); |
| 186 | + optionsBuilder.setBuiltInMetricsEnabled(false); |
| 187 | + } |
| 188 | + String experimentalHost = properties.getProperty(CloudSpannerProperties.EXPERIMENTAL_HOST); |
| 189 | + if (experimentalHost != null) { |
| 190 | + optionsBuilder.setExperimentalHost(experimentalHost); |
| 191 | + } |
| 192 | + |
170 | 193 | spanner = optionsBuilder.build().getService(); |
171 | 194 | Runtime.getRuntime().addShutdownHook(new Thread("spannerShutdown") { |
172 | 195 | @Override |
|
0 commit comments