-
Notifications
You must be signed in to change notification settings - Fork 441
/
TableConfiguration.java
224 lines (183 loc) · 7.32 KB
/
TableConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.accumulo.server.conf;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import org.apache.accumulo.core.classloader.ClassLoaderUtil;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.crypto.CryptoEnvironmentImpl;
import org.apache.accumulo.core.data.TableId;
import org.apache.accumulo.core.dataImpl.thrift.IterInfo;
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
import org.apache.accumulo.core.iteratorsImpl.IteratorConfigUtil;
import org.apache.accumulo.core.spi.common.ServiceEnvironment;
import org.apache.accumulo.core.spi.compaction.CompactionDispatcher;
import org.apache.accumulo.core.spi.crypto.CryptoEnvironment;
import org.apache.accumulo.core.spi.crypto.CryptoService;
import org.apache.accumulo.core.spi.crypto.CryptoServiceFactory;
import org.apache.accumulo.core.spi.scan.ScanDispatcher;
import org.apache.accumulo.server.ServerContext;
import org.apache.accumulo.server.ServiceEnvironmentImpl;
import org.apache.accumulo.server.conf.store.TablePropKey;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TableConfiguration extends ZooBasedConfiguration {
private final static Logger log = LoggerFactory.getLogger(TableConfiguration.class);
private final TableId tableId;
private final EnumMap<IteratorScope,Deriver<ParsedIteratorConfig>> iteratorConfig;
private final Deriver<ScanDispatcher> scanDispatchDeriver;
private final Deriver<CompactionDispatcher> compactionDispatchDeriver;
private final Deriver<CryptoService> cryptoServiceDeriver;
public TableConfiguration(ServerContext context, TableId tableId, NamespaceConfiguration parent) {
super(log, context, TablePropKey.of(context, tableId), parent);
this.tableId = tableId;
iteratorConfig = new EnumMap<>(IteratorScope.class);
for (IteratorScope scope : IteratorScope.values()) {
iteratorConfig.put(scope, newDeriver(conf -> {
Map<String,Map<String,String>> allOpts = new HashMap<>();
List<IterInfo> iters =
IteratorConfigUtil.parseIterConf(scope, Collections.emptyList(), allOpts, conf);
return new ParsedIteratorConfig(iters, allOpts, ClassLoaderUtil.tableContext(conf));
}));
}
scanDispatchDeriver = newDeriver(conf -> createScanDispatcher(conf, context, tableId));
compactionDispatchDeriver =
newDeriver(conf -> createCompactionDispatcher(conf, context, tableId));
cryptoServiceDeriver =
newDeriver(conf -> createCryptoService(conf, tableId, context.getCryptoFactory()));
}
@Override
public String get(Property property) {
String value = _get(property);
if (value != null) {
return value;
}
AccumuloConfiguration parent = getParent();
if (parent != null) {
return parent.get(property);
}
return null;
}
@Nullable
private String _get(Property property) {
Map<String,String> propMap = getSnapshot();
if (propMap == null) {
return null;
}
return propMap.get(property.getKey());
}
public TableId getTableId() {
return tableId;
}
@Override
public String toString() {
return this.getClass().getSimpleName();
}
public static class ParsedIteratorConfig {
private final List<IterInfo> tableIters;
private final Map<String,Map<String,String>> tableOpts;
private final String context;
private ParsedIteratorConfig(List<IterInfo> ii, Map<String,Map<String,String>> opts,
String context) {
this.tableIters = List.copyOf(ii);
tableOpts = opts.entrySet().stream()
.collect(Collectors.toUnmodifiableMap(Entry::getKey, e -> Map.copyOf(e.getValue())));
this.context = context;
}
public List<IterInfo> getIterInfo() {
return tableIters;
}
public Map<String,Map<String,String>> getOpts() {
return tableOpts;
}
public String getServiceEnv() {
return context;
}
}
public ParsedIteratorConfig getParsedIteratorConfig(IteratorScope scope) {
return iteratorConfig.get(scope).derive();
}
private static ScanDispatcher createScanDispatcher(AccumuloConfiguration conf,
ServerContext context, TableId tableId) {
ScanDispatcher newDispatcher = Property.createTableInstanceFromPropertyName(conf,
Property.TABLE_SCAN_DISPATCHER, ScanDispatcher.class, null);
Map<String,String> opts =
conf.getAllPropertiesWithPrefixStripped(Property.TABLE_SCAN_DISPATCHER_OPTS);
newDispatcher.init(new ScanDispatcher.InitParameters() {
private final ServiceEnvironment senv = new ServiceEnvironmentImpl(context);
@Override
public TableId getTableId() {
return tableId;
}
@Override
public Map<String,String> getOptions() {
return opts;
}
@Override
public ServiceEnvironment getServiceEnv() {
return senv;
}
});
return newDispatcher;
}
private static CompactionDispatcher createCompactionDispatcher(AccumuloConfiguration conf,
ServerContext context, TableId tableId) {
CompactionDispatcher newDispatcher = Property.createTableInstanceFromPropertyName(conf,
Property.TABLE_COMPACTION_DISPATCHER, CompactionDispatcher.class, null);
Map<String,String> opts =
conf.getAllPropertiesWithPrefixStripped(Property.TABLE_COMPACTION_DISPATCHER_OPTS);
newDispatcher.init(new CompactionDispatcher.InitParameters() {
private final ServiceEnvironment senv = new ServiceEnvironmentImpl(context);
@Override
public TableId getTableId() {
return tableId;
}
@Override
public Map<String,String> getOptions() {
return opts;
}
@Override
public ServiceEnvironment getServiceEnv() {
return senv;
}
});
return newDispatcher;
}
public ScanDispatcher getScanDispatcher() {
return scanDispatchDeriver.derive();
}
public CompactionDispatcher getCompactionDispatcher() {
return compactionDispatchDeriver.derive();
}
private CryptoService createCryptoService(AccumuloConfiguration conf, TableId tableId,
CryptoServiceFactory factory) {
CryptoEnvironment env = new CryptoEnvironmentImpl(CryptoEnvironment.Scope.TABLE, tableId, null);
return factory.getService(env, conf.getAllCryptoProperties());
}
public CryptoService getCryptoService() {
return cryptoServiceDeriver.derive();
}
}