Search in sources :

Example 1 with Tombstone

use of org.hibernate.cache.infinispan.util.Tombstone in project hibernate-orm by hibernate.

the class TombstoneTest method assertTombstone.

private void assertTombstone(int expectedSize) {
    Tombstone tombstone = assertCacheContains(Tombstone.class);
    assertEquals("Tombstone is " + tombstone, expectedSize, tombstone.size());
}
Also used : Tombstone(org.hibernate.cache.infinispan.util.Tombstone)

Example 2 with Tombstone

use of org.hibernate.cache.infinispan.util.Tombstone in project hibernate-orm by hibernate.

the class TombstoneCallInterceptor method handleTombstoneUpdate.

protected Object handleTombstoneUpdate(MVCCEntry e, TombstoneUpdate tombstoneUpdate, PutKeyValueCommand command) {
    Object storedValue = e.getValue();
    Object value = tombstoneUpdate.getValue();
    if (value == null) {
        // eviction
        if (storedValue == null || storedValue instanceof Tombstone) {
            setFailed(command);
        } else {
            // We have to keep Tombstone, because otherwise putFromLoad could insert a stale entry
            // (after it has been already updated and *then* evicted)
            setValue(e, new Tombstone(ZERO, tombstoneUpdate.getTimestamp()));
        }
    } else if (storedValue instanceof Tombstone) {
        Tombstone tombstone = (Tombstone) storedValue;
        if (tombstone.getLastTimestamp() < tombstoneUpdate.getTimestamp()) {
            setValue(e, value);
        }
    } else if (storedValue == null) {
        // async putFromLoads shouldn't cross the invalidation timestamp
        if (region.getLastRegionInvalidation() < tombstoneUpdate.getTimestamp()) {
            setValue(e, value);
        }
    } else {
    // Don't do anything locally. This could be the async remote write, though, when local
    // value has been already updated: let it propagate to remote nodes, too
    }
    return null;
}
Also used : Tombstone(org.hibernate.cache.infinispan.util.Tombstone)

Example 3 with Tombstone

use of org.hibernate.cache.infinispan.util.Tombstone in project hibernate-orm by hibernate.

the class TombstoneAccessDelegate method write.

protected void write(SharedSessionContractImplementor session, Object key, Object value) {
    TransactionCoordinator tc = session.getTransactionCoordinator();
    FutureUpdateSynchronization sync = new FutureUpdateSynchronization(tc, asyncWriteCache, requiresTransaction, key, value, region, session.getTimestamp());
    // The update will be invalidating all putFromLoads for the duration of expiration or until removed by the synchronization
    Tombstone tombstone = new Tombstone(sync.getUuid(), region.nextTimestamp() + region.getTombstoneExpiration());
    // The outcome of this operation is actually defined in TombstoneCallInterceptor
    // Metadata in PKVC are cleared and set in the interceptor, too
    writeCache.put(key, tombstone);
    tc.getLocalSynchronizations().registerSynchronization(sync);
}
Also used : Tombstone(org.hibernate.cache.infinispan.util.Tombstone) TransactionCoordinator(org.hibernate.resource.transaction.spi.TransactionCoordinator)

Example 4 with Tombstone

use of org.hibernate.cache.infinispan.util.Tombstone in project hibernate-orm by hibernate.

the class TombstoneAccessDelegate method putFromLoad.

@Override
public boolean putFromLoad(SharedSessionContractImplementor session, Object key, Object value, long txTimestamp, Object version, boolean minimalPutOverride) throws CacheException {
    long lastRegionInvalidation = region.getLastRegionInvalidation();
    if (txTimestamp < lastRegionInvalidation) {
        log.tracef("putFromLoad not executed since tx started at %d, before last region invalidation finished = %d", txTimestamp, lastRegionInvalidation);
        return false;
    }
    if (minimalPutOverride) {
        Object prev = cache.get(key);
        if (prev instanceof Tombstone) {
            Tombstone tombstone = (Tombstone) prev;
            long lastTimestamp = tombstone.getLastTimestamp();
            if (txTimestamp <= lastTimestamp) {
                log.tracef("putFromLoad not executed since tx started at %d, before last invalidation finished = %d", txTimestamp, lastTimestamp);
                return false;
            }
        } else if (prev != null) {
            log.tracef("putFromLoad not executed since cache contains %s", prev);
            return false;
        }
    }
    // we can't use putForExternalRead since the PFER flag means that entry is not wrapped into context
    // when it is present in the container. TombstoneCallInterceptor will deal with this.
    putFromLoadCache.put(key, new TombstoneUpdate(session.getTimestamp(), value));
    return true;
}
Also used : Tombstone(org.hibernate.cache.infinispan.util.Tombstone) TombstoneUpdate(org.hibernate.cache.infinispan.util.TombstoneUpdate)

Example 5 with Tombstone

use of org.hibernate.cache.infinispan.util.Tombstone in project hibernate-orm by hibernate.

the class TombstoneCallInterceptor method handleFutureUpdate.

private Object handleFutureUpdate(MVCCEntry e, FutureUpdate futureUpdate, PutKeyValueCommand command) {
    Object storedValue = e.getValue();
    if (storedValue instanceof Tombstone) {
        // Note that the update has to keep tombstone even if the transaction was unsuccessful;
        // before write we have removed the value and we have to protect the entry against stale putFromLoads
        Tombstone tombstone = (Tombstone) storedValue;
        setValue(e, tombstone.applyUpdate(futureUpdate.getUuid(), futureUpdate.getTimestamp(), futureUpdate.getValue()));
    } else {
        // This is an async future update, and it's timestamp may be vastly outdated
        // We need to first execute the async update and then local one, because if we're on the primary
        // owner the local future update would fail the async one.
        // TODO: There is some discrepancy with TombstoneUpdate handling which does not fail the update
        setFailed(command);
    }
    return null;
}
Also used : Tombstone(org.hibernate.cache.infinispan.util.Tombstone)

Aggregations

Tombstone (org.hibernate.cache.infinispan.util.Tombstone)6 TombstoneUpdate (org.hibernate.cache.infinispan.util.TombstoneUpdate)2 FutureUpdate (org.hibernate.cache.infinispan.util.FutureUpdate)1 TransactionCoordinator (org.hibernate.resource.transaction.spi.TransactionCoordinator)1 MVCCEntry (org.infinispan.container.entries.MVCCEntry)1