forked from voldemort/voldemort
/
StoreDefinition.java
457 lines (391 loc) · 18.6 KB
/
StoreDefinition.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
/*
* Copyright 2008-2009 LinkedIn, Inc
*
* Licensed 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
*
* http://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 voldemort.store;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import voldemort.client.RoutingTier;
import voldemort.serialization.SerializerDefinition;
import voldemort.store.slop.strategy.HintedHandoffStrategyType;
import voldemort.utils.Utils;
import com.google.common.base.Objects;
/**
* The configuration information for a store.
*
*
*/
public class StoreDefinition implements Serializable {
private static final long serialVersionUID = 1;
private final String name;
private final String type;
private final String description;
private final SerializerDefinition keySerializer;
private final SerializerDefinition valueSerializer;
private final SerializerDefinition transformsSerializer;
private final RoutingTier routingPolicy;
private final int replicationFactor;
private final Integer preferredWrites;
private final int requiredWrites;
private final Integer preferredReads;
private final int requiredReads;
private final Integer retentionPeriodDays;
private final Integer retentionScanThrottleRate;
private final Integer retentionFrequencyDays;
private final String routingStrategyType;
private final String viewOf;
private final HashMap<Integer, Integer> zoneReplicationFactor;
private final Integer zoneCountReads;
private final Integer zoneCountWrites;
private final String valueTransformation;
private final String serializerFactory;
private final HintedHandoffStrategyType hintedHandoffStrategyType;
private final Integer hintPrefListSize;
private final List<String> owners;
private final long memoryFootprintMB;
public StoreDefinition(String name,
String type,
String description,
SerializerDefinition keySerializer,
SerializerDefinition valueSerializer,
SerializerDefinition transformsSerializer,
RoutingTier routingPolicy,
String routingStrategyType,
int replicationFactor,
Integer preferredReads,
int requiredReads,
Integer preferredWrites,
int requiredWrites,
String viewOfStore,
String valTrans,
HashMap<Integer, Integer> zoneReplicationFactor,
Integer zoneCountReads,
Integer zoneCountWrites,
Integer retentionDays,
Integer retentionThrottleRate,
Integer retentionFrequencyDays,
String factory,
HintedHandoffStrategyType hintedHandoffStrategyType,
Integer hintPrefListSize,
List<String> owners,
long memoryFootprintMB) {
this.name = Utils.notNull(name);
this.type = type;
this.description = description;
this.replicationFactor = replicationFactor;
this.preferredReads = preferredReads;
this.requiredReads = requiredReads;
this.preferredWrites = preferredWrites;
this.requiredWrites = requiredWrites;
this.routingPolicy = routingPolicy;
this.keySerializer = keySerializer;
this.valueSerializer = valueSerializer;
this.transformsSerializer = transformsSerializer;
this.retentionPeriodDays = retentionDays;
this.retentionScanThrottleRate = retentionThrottleRate;
this.retentionFrequencyDays = retentionFrequencyDays;
this.memoryFootprintMB = memoryFootprintMB;
this.routingStrategyType = routingStrategyType;
this.viewOf = viewOfStore;
this.valueTransformation = valTrans;
this.zoneReplicationFactor = zoneReplicationFactor;
this.zoneCountReads = zoneCountReads;
this.zoneCountWrites = zoneCountWrites;
this.serializerFactory = factory;
this.hintedHandoffStrategyType = hintedHandoffStrategyType;
this.hintPrefListSize = hintPrefListSize;
this.owners = owners;
}
protected void checkParameterLegality() {
// null checks
Utils.notNull(this.type);
Utils.notNull(routingPolicy);
Utils.notNull(keySerializer);
Utils.notNull(valueSerializer);
if(requiredReads < 1)
throw new IllegalArgumentException("Cannot have a requiredReads number less than 1.");
else if(requiredReads > replicationFactor)
throw new IllegalArgumentException("Cannot have more requiredReads then there are replicas.");
if(requiredWrites < 1)
throw new IllegalArgumentException("Cannot have a requiredWrites number less than 1.");
else if(requiredWrites > replicationFactor)
throw new IllegalArgumentException("Cannot have more requiredWrites then there are replicas.");
if(preferredWrites != null) {
if(preferredWrites < requiredWrites)
throw new IllegalArgumentException("preferredWrites must be greater or equal to requiredWrites.");
if(preferredWrites > replicationFactor)
throw new IllegalArgumentException("Cannot have more preferredWrites then there are replicas.");
}
if(preferredReads != null) {
if(preferredReads < requiredReads)
throw new IllegalArgumentException("preferredReads must be greater or equal to requiredReads.");
if(preferredReads > replicationFactor)
throw new IllegalArgumentException("Cannot have more preferredReads then there are replicas.");
}
if(retentionPeriodDays != null && retentionPeriodDays < 0)
throw new IllegalArgumentException("Retention days must be non-negative.");
if(zoneReplicationFactor != null && zoneReplicationFactor.size() != 0) {
if(zoneCountReads == null || zoneCountReads < 0)
throw new IllegalArgumentException("Zone Counts reads must be non-negative / non-null");
if(zoneCountWrites == null || zoneCountWrites < 0)
throw new IllegalArgumentException("Zone Counts writes must be non-negative");
int sumZoneReplicationFactor = 0;
int replicatingZones = 0;
for(Integer zoneId: zoneReplicationFactor.keySet()) {
int currentZoneRepFactor = zoneReplicationFactor.get(zoneId);
sumZoneReplicationFactor += currentZoneRepFactor;
if(currentZoneRepFactor > 0)
replicatingZones++;
}
if(replicatingZones <= 0) {
throw new IllegalArgumentException("Cannot have no zones to replicate to. "
+ "Should have some positive zoneReplicationFactor");
}
// Check if sum of individual zones is equal to total replication
// factor
if(sumZoneReplicationFactor != replicationFactor) {
throw new IllegalArgumentException("Sum total of zones ("
+ sumZoneReplicationFactor
+ ") does not match the total replication factor ("
+ replicationFactor + ")");
}
// Check if number of zone-count-reads and zone-count-writes are
// less than zones replicating to
if(zoneCountReads >= replicatingZones) {
throw new IllegalArgumentException("Number of zones to block for while reading ("
+ zoneCountReads
+ ") should be less then replicating zones ("
+ replicatingZones + ")");
}
if(zoneCountWrites >= replicatingZones) {
throw new IllegalArgumentException("Number of zones to block for while writing ("
+ zoneCountWrites
+ ") should be less then replicating zones ("
+ replicatingZones + ")");
}
}
}
public String getDescription() {
return this.description;
}
public String getSerializerFactory() {
return this.serializerFactory;
}
public boolean hasTransformsSerializer() {
return transformsSerializer != null;
}
public String getName() {
return name;
}
public int getRequiredWrites() {
return requiredWrites;
}
public SerializerDefinition getKeySerializer() {
return keySerializer;
}
public SerializerDefinition getValueSerializer() {
return valueSerializer;
}
public SerializerDefinition getTransformsSerializer() {
return transformsSerializer;
}
public RoutingTier getRoutingPolicy() {
return this.routingPolicy;
}
public int getReplicationFactor() {
return this.replicationFactor;
}
public String getRoutingStrategyType() {
return routingStrategyType;
}
public int getRequiredReads() {
return this.requiredReads;
}
public boolean hasPreferredWrites() {
return preferredWrites != null;
}
public int getPreferredWrites() {
return preferredWrites == null ? getRequiredWrites() : preferredWrites;
}
public int getPreferredReads() {
return preferredReads == null ? getRequiredReads() : preferredReads;
}
public boolean hasPreferredReads() {
return preferredReads != null;
}
public String getType() {
return type;
}
public boolean hasRetentionPeriod() {
return this.retentionPeriodDays != null;
}
public Integer getRetentionDays() {
return this.retentionPeriodDays;
}
public boolean hasRetentionScanThrottleRate() {
return this.retentionScanThrottleRate != null;
}
public Integer getRetentionScanThrottleRate() {
return this.retentionScanThrottleRate;
}
public boolean hasRetentionFrequencyDays() {
return this.retentionFrequencyDays != null;
}
public Integer getRetentionFrequencyDays() {
return this.retentionFrequencyDays;
}
public boolean isView() {
return this.viewOf != null;
}
public String getViewTargetStoreName() {
return viewOf;
}
public boolean hasValueTransformation() {
return this.valueTransformation != null;
}
public String getValueTransformation() {
return valueTransformation;
}
public HashMap<Integer, Integer> getZoneReplicationFactor() {
return zoneReplicationFactor;
}
public Integer getZoneCountReads() {
return zoneCountReads;
}
public boolean hasZoneCountReads() {
return zoneCountReads != null;
}
public Integer getZoneCountWrites() {
return zoneCountWrites;
}
public boolean hasZoneCountWrites() {
return zoneCountWrites != null;
}
public HintedHandoffStrategyType getHintedHandoffStrategyType() {
return hintedHandoffStrategyType;
}
public boolean hasHintedHandoffStrategyType() {
return hintedHandoffStrategyType != null;
}
public Integer getHintPrefListSize() {
return hintPrefListSize;
}
public boolean hasHintPreflistSize() {
return hintPrefListSize != null;
}
public List<String> getOwners() {
return this.owners;
}
public long getMemoryFootprintMB() {
return this.memoryFootprintMB;
}
public boolean hasMemoryFootprint() {
return memoryFootprintMB != 0;
}
@Override
public boolean equals(Object o) {
if(this == o)
return true;
else if(o == null)
return false;
else if(!(o.getClass() == StoreDefinition.class))
return false;
StoreDefinition def = (StoreDefinition) o;
return getName().equals(def.getName())
&& getType().equals(def.getType())
&& getReplicationFactor() == def.getReplicationFactor()
&& getRequiredReads() == def.getRequiredReads()
&& Objects.equal(getPreferredReads(), def.getPreferredReads())
&& getRequiredWrites() == def.getRequiredWrites()
&& Objects.equal(getPreferredWrites(), def.getPreferredWrites())
&& getKeySerializer().equals(def.getKeySerializer())
&& getValueSerializer().equals(def.getValueSerializer())
&& Objects.equal(getTransformsSerializer() != null ? getTransformsSerializer()
: null,
def.getTransformsSerializer() != null ? def.getTransformsSerializer()
: null)
&& getRoutingPolicy() == def.getRoutingPolicy()
&& Objects.equal(getViewTargetStoreName(), def.getViewTargetStoreName())
&& Objects.equal(getValueTransformation() != null ? getValueTransformation().getClass()
: null,
def.getValueTransformation() != null ? def.getValueTransformation()
.getClass() : null)
&& Objects.equal(getZoneReplicationFactor() != null ? getZoneReplicationFactor().getClass()
: null,
def.getZoneReplicationFactor() != null ? def.getZoneReplicationFactor()
.getClass()
: null)
&& Objects.equal(getZoneCountReads(), def.getZoneCountReads())
&& Objects.equal(getZoneCountWrites(), def.getZoneCountWrites())
&& Objects.equal(getRetentionDays(), def.getRetentionDays())
&& Objects.equal(getRetentionScanThrottleRate(), def.getRetentionScanThrottleRate())
&& Objects.equal(getSerializerFactory() != null ? getSerializerFactory() : null,
def.getSerializerFactory() != null ? def.getSerializerFactory()
: null)
&& Objects.equal(getHintedHandoffStrategyType(), def.getHintedHandoffStrategyType())
&& Objects.equal(getHintPrefListSize(), def.getHintPrefListSize())
&& Objects.equal(getMemoryFootprintMB(), def.getMemoryFootprintMB());
}
@Override
public int hashCode() {
return Objects.hashCode(getName(),
getType(),
getDescription(),
getKeySerializer(),
getValueSerializer(),
getTransformsSerializer(),
getRoutingPolicy(),
getRoutingStrategyType(),
getReplicationFactor(),
getRequiredReads(),
getRequiredWrites(),
getPreferredReads(),
getPreferredWrites(),
getViewTargetStoreName(),
getValueTransformation() == null ? null
: getValueTransformation().getClass(),
getZoneReplicationFactor() == null ? null
: getZoneReplicationFactor().getClass(),
getZoneCountReads(),
getZoneCountWrites(),
getRetentionDays(),
getRetentionScanThrottleRate(),
getSerializerFactory(),
hasHintedHandoffStrategyType() ? getHintedHandoffStrategyType()
: null,
hasHintPreflistSize() ? getHintPrefListSize() : null,
getOwners(),
getMemoryFootprintMB());
}
@Override
public String toString() {
return "StoreDefinition(name = " + getName() + ", type = " + getType() + ", description = "
+ getDescription() + ", key-serializer = " + getKeySerializer()
+ ", value-serializer = " + getValueSerializer() + ", routing = "
+ getRoutingPolicy() + ", routing-strategy = " + getRoutingStrategyType()
+ ", replication = " + getReplicationFactor() + ", required-reads = "
+ getRequiredReads() + ", preferred-reads = " + getPreferredReads()
+ ", required-writes = " + getRequiredWrites() + ", preferred-writes = "
+ getPreferredWrites() + ", view-target = " + getViewTargetStoreName()
+ ", value-transformation = " + getValueTransformation() + ", retention-days = "
+ getRetentionDays() + ", throttle-rate = " + getRetentionScanThrottleRate()
+ ", zone-replication-factor = " + getZoneReplicationFactor()
+ ", zone-count-reads = " + getZoneCountReads() + ", zone-count-writes = "
+ getZoneCountWrites() + ", serializer factory = " + getSerializerFactory() + ")"
+ ", hinted-handoff-strategy = " + getHintedHandoffStrategyType()
+ ", hint-preflist-size = " + getHintPrefListSize() + ", owners = " + getOwners()
+ ", memory-footprint(MB)" + getMemoryFootprintMB() + ")";
}
}