Skip to content

Commit

Permalink
ISPN-11554 Off-heap state transfer resets timestamps
Browse files Browse the repository at this point in the history
* Preserve the timestamps in OffHeapEntryFactoryImpl
* Delete deprecated OffHeapEntryFactory.create overload
* Pull up the storageType parameter in MultipleCacheManagersTest
* Use the inherited lockingMode in ExceptionEvictionTest
  • Loading branch information
danberindei authored and Gustavo committed Apr 3, 2020
1 parent a0ad59e commit 25eaee6
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 215 deletions.
Expand Up @@ -27,7 +27,6 @@ public class StorageRoutingTest extends MultiHotRodServersTest {

private static final int CLUSTER_SIZE = 3;

protected StorageType storageType;
private Object key;

public Object[] factory() {
Expand All @@ -45,11 +44,11 @@ public Object[] factory() {
}

protected String[] parameterNames() {
return new String[]{"storage", "key"};
return new String[]{null, "key"};
}

protected Object[] parameterValues() {
return new Object[]{storageType, key};
return new Object[]{storageType, key.getClass().getSimpleName()};
}

private StorageRoutingTest withStorageType(StorageType storageType) {
Expand Down
Expand Up @@ -40,7 +40,6 @@ public class MultiServerStoreQueryTest extends MultiHotRodServersTest {

private RemoteCache<Object, Object> userCache;

private StorageType storageType;
private long evictionSize = -1;

@Override
Expand Down Expand Up @@ -71,7 +70,7 @@ public Object[] factory() {
};
}

MultiServerStoreQueryTest storageType(StorageType storageType) {
public MultiServerStoreQueryTest storageType(StorageType storageType) {
this.storageType = storageType;
return this;
}
Expand Down
Expand Up @@ -581,7 +581,7 @@ public InternalCacheEntry<WrappedBytes, WrappedBytes> compute(WrappedBytes key,
if (prev == result) {
// noop
} else if (result != null) {
long newAddress = offHeapEntryFactory.create(key, result.getValue(), result.getMetadata(), result.getInternalMetadata());
long newAddress = offHeapEntryFactory.create(key, hashCode, result);
// TODO: Technically actualAddress could be a 0 and bucketAddress != 0, which means we will loop through
// entire bucket for no reason as it will never match (doing key equality checks)
performPut(bucketAddress, actualAddress, newAddress, key, memoryOffset, false, false);
Expand Down Expand Up @@ -696,7 +696,7 @@ public InternalCacheEntry<WrappedBytes, WrappedBytes> put(WrappedBytes key,

int memoryOffset = getMemoryOffset(hashCode);
long address = memoryLookup.getMemoryAddressOffset(memoryOffset);
long newAddress = offHeapEntryFactory.create(key, hashCode, value.getValue(), value.getMetadata(), value.getInternalMetadata());
long newAddress = offHeapEntryFactory.create(key, hashCode, value);
returnedValue = performPut(address, 0, newAddress, key, memoryOffset, true, false);
} finally {
stampedLock.unlockWrite(writeStamp);
Expand Down Expand Up @@ -1048,7 +1048,7 @@ private InternalCacheEntry<WrappedBytes, WrappedBytes> performReplace(long bucke
ice = offHeapEntryFactory.fromMemory(address);
}

long newAddress = offHeapEntryFactory.create(key, hashCode, newValue.getValue(), newValue.getMetadata(), newValue.getInternalMetadata());
long newAddress = offHeapEntryFactory.create(key, hashCode, newValue);

entryReplaced(newAddress, address);
if (prevAddress != 0) {
Expand Down
Expand Up @@ -13,57 +13,14 @@
* @since 9.0
*/
public interface OffHeapEntryFactory extends KeyValueMetadataSizeCalculator<WrappedBytes, WrappedBytes> {
/**
* Creates an off heap entry using the provided key value and metadata
* @param key the key to use
* @param value the value to use
* @param metadata the metadata to use
* @return the address of where the entry was created
*/
default long create(WrappedBytes key, WrappedBytes value, Metadata metadata) {
//TODO! can it ^ be removed?
return create(key, key.hashCode(), value, metadata, null);
}

/**
* Creates an off heap entry using the provided key value and metadata
*
* @param key the key to use
* @param value the value to use
* @param metadata the metadata to use
* @param internalMetadata the internal metadata to use
* @return the address of where the entry was created
*/
default long create(WrappedBytes key, WrappedBytes value, Metadata metadata,
MetaParamsInternalMetadata internalMetadata) {
return create(key, key.hashCode(), value, metadata, internalMetadata);
}

/**
* Creates an off heap entry using the provided key value and metadata
* @param key the key to use
* @param hashCode the hashCode of the key
* @param value the value to use
* @param metadata the metadata to use
* @return the address of where the entry was created
*/
default long create(WrappedBytes key, int hashCode, WrappedBytes value, Metadata metadata) {
//TODO! can it ^ be removed?
return create(key, hashCode, value, metadata, null);
}

/**
* Creates an off heap entry using the provided key value and metadata(s)
*
* @param key the key to use
* @param hashCode the hashCode of the key
* @param value the value to use
* @param metadata the metadata to use
* @param internalMetadata the internal metadata to use
* @param ice the internal entry to use
* @return the address of where the entry was created
*/
long create(WrappedBytes key, int hashCode, WrappedBytes value, Metadata metadata,
MetaParamsInternalMetadata internalMetadata);
long create(WrappedBytes key, int hashCode, InternalCacheEntry<WrappedBytes, WrappedBytes> ice);

/**
* Returns how many bytes in memory this address location uses assuming it is an {@link InternalCacheEntry}.
Expand Down
Expand Up @@ -68,10 +68,11 @@ public void start() {
}

@Override
public long create(WrappedBytes key, int hashCode, WrappedBytes value, Metadata metadata, MetaParamsInternalMetadata internalMetadata) {
public long create(WrappedBytes key, int hashCode, InternalCacheEntry<WrappedBytes, WrappedBytes> ice) {
byte type;
boolean shouldWriteMetadataSize = false;
byte[] metadataBytes;
Metadata metadata = ice.getMetadata();
if (metadata instanceof EmbeddedMetadata) {
EntryVersion version = metadata.version();
byte[] versionBytes;
Expand All @@ -98,22 +99,21 @@ public long create(WrappedBytes key, int hashCode, WrappedBytes value, Metadata
type |= MORTAL;
metadataBytes = new byte[16 + versionBytes.length];
Bits.putLong(metadataBytes, 0, lifespan);
Bits.putLong(metadataBytes, 8, timeService.wallClockTime());
Bits.putLong(metadataBytes, 8, ice.getCreated());
System.arraycopy(versionBytes, 0, metadataBytes, 16, versionBytes.length);
} else if (lifespan < 0 && maxIdle > -1) {
type |= TRANSIENT;
metadataBytes = new byte[16 + versionBytes.length];
Bits.putLong(metadataBytes, 0, maxIdle);
Bits.putLong(metadataBytes, 8, timeService.wallClockTime());
Bits.putLong(metadataBytes, 8, ice.getLastUsed());
System.arraycopy(versionBytes, 0, metadataBytes, 16, versionBytes.length);
} else {
type |= TRANSIENT_MORTAL;
metadataBytes = new byte[32 + versionBytes.length];
Bits.putLong(metadataBytes, 0, lifespan);
Bits.putLong(metadataBytes, 8, maxIdle);
long time = timeService.wallClockTime();
Bits.putLong(metadataBytes, 16, time);
Bits.putLong(metadataBytes, 24, time);
Bits.putLong(metadataBytes, 16, ice.getCreated());
Bits.putLong(metadataBytes, 24, ice.getLastUsed());
System.arraycopy(versionBytes, 0, metadataBytes, 32, versionBytes.length);
}
} else {
Expand All @@ -125,10 +125,11 @@ public long create(WrappedBytes key, int hashCode, WrappedBytes value, Metadata

int keySize = key.getLength();
int metadataSize = metadataBytes.length;
WrappedBytes value = ice.getValue();
int valueSize = value != null ? value.getLength() : 0;

byte[] internalMetadataBytes = shouldWriteInternalMetadata(internalMetadata) ?
marshall(internalMetadata) :
byte[] internalMetadataBytes = shouldWriteInternalMetadata(ice.getInternalMetadata()) ?
marshall(ice.getInternalMetadata()) :
Util.EMPTY_BYTE_ARRAY;
int internalMetadataSize = internalMetadataBytes.length;

Expand Down

0 comments on commit 25eaee6

Please sign in to comment.