Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPN-3477 Keep a single representation when storeAsBinary is enabled #2055

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions commons/src/main/java/org/infinispan/commons/util/Util.java
Expand Up @@ -653,4 +653,22 @@ public static int findNextHighestPowerOfTwo(int num) {
int highestBit = Integer.highestOneBit(num);
return num <= highestBit ? highestBit : highestBit << 1;
}

/**
* A function that calculates hash code of a byte array based on its
* contents but using the given size parameter as deliminator for the
* content.
*/
public static int hashCode(byte[] bytes, int size) {
int contentLimit = size;
if (size > bytes.length)
contentLimit = bytes.length;

int hashCode = 1;
for (int i = 0; i < contentLimit; i++)
hashCode = 31 * hashCode + bytes[i];

return hashCode;
}

}
Expand Up @@ -221,11 +221,6 @@ public AdvancedCache<K, V> getAdvancedCache() {
return cache.getAdvancedCache();
}

@Override
public void compact() {
cache.compact();
}

@Override
public ComponentStatus getStatus() {
return cache.getStatus();
Expand Down
9 changes: 0 additions & 9 deletions core/src/main/java/org/infinispan/Cache.java
Expand Up @@ -136,15 +136,6 @@ public interface Cache<K, V> extends BasicCache<K, V>, BatchingCache, FilteringL

AdvancedCache<K, V> getAdvancedCache();

/**
* Method that releases object references of cached objects held in the cache by serializing them to byte buffers.
* Cached objects are lazily de-serialized when accessed again, based on the calling thread's context class loader.
* <p/>
* This can be expensive, based on the effort required to serialize cached objects.
* <p/>
*/
void compact();

ComponentStatus getStatus();

/**
Expand Down
12 changes: 0 additions & 12 deletions core/src/main/java/org/infinispan/CacheImpl.java
Expand Up @@ -1264,18 +1264,6 @@ public AdvancedCache<K, V> getAdvancedCache() {
return this;
}

@Override
public void compact() {
for (InternalCacheEntry e : dataContainer) {
if (e.getKey() instanceof MarshalledValue) {
((MarshalledValue) e.getKey()).compact(true, true);
}
if (e.getValue() instanceof MarshalledValue) {
((MarshalledValue) e.getValue()).compact(true, true);
}
}
}

@Override
public RpcManager getRpcManager() {
return rpcManager;
Expand Down
Expand Up @@ -16,13 +16,11 @@ public class StoreAsBinaryConfiguration {
private boolean enabled;
private final boolean storeKeysAsBinary;
private final boolean storeValuesAsBinary;
private final boolean defensive;

StoreAsBinaryConfiguration(boolean enabled, boolean storeKeysAsBinary, boolean storeValuesAsBinary, boolean defensive) {

StoreAsBinaryConfiguration(boolean enabled, boolean storeKeysAsBinary, boolean storeValuesAsBinary) {
this.enabled = enabled;
this.storeKeysAsBinary = storeKeysAsBinary;
this.storeValuesAsBinary = storeValuesAsBinary;
this.defensive = defensive;
}

/**
Expand Down Expand Up @@ -53,9 +51,12 @@ public boolean storeValuesAsBinary() {

/**
* Enables defensive copies.
*
* @deprecated Store as binary configuration is always defensive now.
*/
@Deprecated
public boolean defensive() {
return defensive;
return true;
}

@Override
Expand All @@ -64,7 +65,6 @@ public String toString() {
"enabled=" + enabled +
", storeKeysAsBinary=" + storeKeysAsBinary +
", storeValuesAsBinary=" + storeValuesAsBinary +
", defensive=" + defensive +
'}';
}

Expand All @@ -78,7 +78,6 @@ public boolean equals(Object o) {
if (enabled != that.enabled) return false;
if (storeKeysAsBinary != that.storeKeysAsBinary) return false;
if (storeValuesAsBinary != that.storeValuesAsBinary) return false;
if (defensive != that.defensive) return false;

return true;
}
Expand All @@ -88,7 +87,6 @@ public int hashCode() {
int result = (enabled ? 1 : 0);
result = 31 * result + (storeKeysAsBinary ? 1 : 0);
result = 31 * result + (storeValuesAsBinary ? 1 : 0);
result = 31 * result + (defensive ? 1 : 0);
return result;
}

Expand Down
Expand Up @@ -18,7 +18,6 @@ public class StoreAsBinaryConfigurationBuilder extends AbstractConfigurationChil
private boolean enabled = false;
private boolean storeKeysAsBinary = true;
private boolean storeValuesAsBinary = true;
private boolean defensive = false;

StoreAsBinaryConfigurationBuilder(ConfigurationBuilder builder) {
super(builder);
Expand Down Expand Up @@ -84,9 +83,10 @@ public StoreAsBinaryConfigurationBuilder storeValuesAsBinary(boolean storeValues
* @param defensive boolean indicating whether defensive copies
* should be enabled cache wide
* @return a configuration builder for fluent programmatic configuration
* @deprecated Store as binary configuration is always defensive now.
*/
@Deprecated
public StoreAsBinaryConfigurationBuilder defensive(boolean defensive) {
this.defensive = defensive;
return this;
}

Expand All @@ -98,15 +98,14 @@ public void validate() {
@Override
public StoreAsBinaryConfiguration create() {
return new StoreAsBinaryConfiguration(
enabled, storeKeysAsBinary, storeValuesAsBinary, defensive);
enabled, storeKeysAsBinary, storeValuesAsBinary);
}

@Override
public StoreAsBinaryConfigurationBuilder read(StoreAsBinaryConfiguration template) {
this.enabled = template.enabled();
this.storeKeysAsBinary = template.storeKeysAsBinary();
this.storeValuesAsBinary = template.storeValuesAsBinary();
this.defensive = template.defensive();

return this;
}
Expand Down
Expand Up @@ -93,7 +93,8 @@ public InterceptorChain buildInterceptorChain() {
}

// add marshallable check interceptor for situations where we want to figure out before marshalling
if (isUsingMarshalledValues(configuration) || configuration.clustering().async().asyncMarshalling()
// Store as binary marshalls keys/values eagerly now, so avoid extra serialization
if (configuration.clustering().async().asyncMarshalling()
|| configuration.clustering().async().useReplQueue() || hasAsyncStore())
interceptorChain.appendInterceptor(createInterceptor(new IsMarshallableInterceptor(), IsMarshallableInterceptor.class), false);

Expand Down Expand Up @@ -129,13 +130,8 @@ public InterceptorChain buildInterceptorChain() {

if (isUsingMarshalledValues(configuration)) {
CommandInterceptor interceptor;
if (configuration.storeAsBinary().defensive()) {
interceptor = createInterceptor(
new DefensiveMarshalledValueInterceptor(), DefensiveMarshalledValueInterceptor.class);
} else {
interceptor = createInterceptor(
new MarshalledValueInterceptor(), MarshalledValueInterceptor.class);
}

interceptorChain.appendInterceptor(interceptor, false);
}
Expand Down

This file was deleted.