HCOLL-406 #58 Don't check size configurations of ChronicleMapBuilder, if existing file is accessed

This commit is contained in:
leventov
2015-11-24 15:42:51 +03:00
parent d48a6d2d19
commit 0398f7dfbf
3 changed files with 10 additions and 15 deletions
@@ -181,7 +181,7 @@ public final class SerializationBuilder<T> implements Cloneable, Serializable {
public long constantSizeBySample(T sampleObject) {
long constantSize = serializationSize(sampleObject);
if (sizeIsStaticallyKnown) {
if (constantSizeMarshaller()) {
long expectedConstantSize = constantSize();
if (constantSize != expectedConstantSize) {
throw new IllegalStateException("Although configuring constant size by sample " +
@@ -272,7 +272,8 @@ public final class ChronicleMapBuilder<K, V> implements
*/
@Override
public ChronicleMapBuilder<K, V> averageKeySize(double averageKeySize) {
checkSizeIsNotStaticallyKnown(keyBuilder);
if (keyBuilder.sizeIsStaticallyKnown)
return this;
checkAverageSize(averageKeySize, "key");
this.averageKeySize = averageKeySize;
averageKey = null;
@@ -293,7 +294,9 @@ public final class ChronicleMapBuilder<K, V> implements
*/
@Override
public ChronicleMapBuilder<K, V> averageKey(K averageKey) {
checkSizeIsNotStaticallyKnown(keyBuilder);
Objects.requireNonNull(averageKey);
if (keyBuilder.sizeIsStaticallyKnown)
return this;
this.averageKey = averageKey;
sampleKey = null;
averageKeySize = UNDEFINED_DOUBLE_CONFIG;
@@ -357,7 +360,8 @@ public final class ChronicleMapBuilder<K, V> implements
* @see #actualChunkSize(int)
*/
public ChronicleMapBuilder<K, V> averageValueSize(double averageValueSize) {
checkSizeIsNotStaticallyKnown(valueBuilder);
if (valueBuilder.sizeIsStaticallyKnown)
return this;
checkAverageSize(averageValueSize, "value");
this.averageValueSize = averageValueSize;
averageValue = null;
@@ -399,7 +403,8 @@ public final class ChronicleMapBuilder<K, V> implements
*/
public ChronicleMapBuilder<K, V> averageValue(V averageValue) {
Objects.requireNonNull(averageValue);
checkSizeIsNotStaticallyKnown(valueBuilder);
if (valueBuilder.sizeIsStaticallyKnown)
return this;
this.averageValue = averageValue;
sampleValue = null;
averageValueSize = UNDEFINED_DOUBLE_CONFIG;
@@ -414,12 +419,6 @@ public final class ChronicleMapBuilder<K, V> implements
}
}
private static void checkSizeIsNotStaticallyKnown(SerializationBuilder builder) {
if (builder.sizeIsStaticallyKnown)
throw new IllegalStateException("Size of type " + builder.tClass +
" is statically known and shouldn't be specified manually");
}
/**
* Configures the constant number of bytes, taken by serialized form of values, put into maps,
* created by this builder. This is done by providing the {@code sampleValue}, all values should
@@ -1382,9 +1381,6 @@ public final class ChronicleMapBuilder<K, V> implements
"Expected length is " + expectedFileLength);
}
map.createMappedStoreAndSegments(file);
// This is needed to property initialize key and value serialization builders,
// which are later used in replication
preMapConstruction();
establishReplication(map, singleHashReplication, channel);
fis.getChannel().force(true);
// TODO according to Self Boostrapping Data spec, should write "init complete"