use of org.apache.geode.internal.cache.BucketRegion.RawValue in project geode by apache.
the class PartitionedRegionDataStore method getSerializedLocally.
/**
* Return a value from the bucket region, always serialized
*
* @param keyInfo TODO
* @param clientEvent a "client" event that will hold version information about the entry
* @param returnTombstones TODO
* @throws ForceReattemptException if bucket region is null
* @return value from the bucket region
* @throws PrimaryBucketException if the locally managed bucket is not primary
* @see #getLocally(int, Object, Object, boolean, boolean, ClientProxyMembershipID,
* EntryEventImpl, boolean)
*/
public RawValue getSerializedLocally(KeyInfo keyInfo, boolean doNotLockEntry, ClientProxyMembershipID requestingClient, EntryEventImpl clientEvent, boolean returnTombstones) throws PrimaryBucketException, ForceReattemptException {
final BucketRegion bucketRegion = getInitializedBucketForId(keyInfo.getKey(), keyInfo.getBucketId());
// check for primary (when loader is present) done deeper in the BucketRegion
if (logger.isDebugEnabled()) {
logger.debug("getSerializedLocally: key {}) bucketId={}{}{} region {}", keyInfo.getKey(), this.partitionedRegion.getPRId(), PartitionedRegion.BUCKET_ID_SEPARATOR, keyInfo.getBucketId(), bucketRegion.getName());
}
invokeBucketReadHook();
try {
RawValue result = bucketRegion.getSerialized(keyInfo, true, doNotLockEntry, requestingClient, clientEvent, returnTombstones);
checkIfBucketMoved(bucketRegion);
return result;
} catch (RegionDestroyedException rde) {
if (bucketRegion.isBucketDestroyed()) {
// bucket moved by rebalance
throw new ForceReattemptException("Bucket removed during get", rde);
} else {
throw rde;
}
} catch (IOException e) {
throw new ForceReattemptException(LocalizedStrings.PartitionedRegionDataStore_UNABLE_TO_SERIALIZE_VALUE.toLocalizedString(), e);
}
}
use of org.apache.geode.internal.cache.BucketRegion.RawValue in project geode by apache.
the class GetMessage method operateOnPartitionedRegion.
@Override
protected boolean operateOnPartitionedRegion(final DistributionManager dm, PartitionedRegion r, long startTime) throws ForceReattemptException {
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "GetMessage operateOnRegion: {}", r.getFullPath());
}
PartitionedRegionDataStore ds = r.getDataStore();
if (this.getTXUniqId() != TXManagerImpl.NOTX) {
assert r.getDataView() instanceof TXStateProxy;
}
RawValue valueBytes;
Object val = null;
try {
if (ds != null) {
VersionTagHolder event = new VersionTagHolder();
try {
KeyInfo keyInfo = r.getKeyInfo(key, cbArg);
boolean lockEntry = forceUseOfPRExecutor || isDirectAck();
val = r.getDataView().getSerializedValue(r, keyInfo, !lockEntry, this.context, event, returnTombstones);
if (val == BucketRegion.REQUIRES_ENTRY_LOCK) {
Assert.assertTrue(!lockEntry);
this.forceUseOfPRExecutor = true;
if (logger.isDebugEnabled()) {
logger.debug("Rescheduling GetMessage due to possible cache-miss");
}
schedule(dm);
return false;
}
valueBytes = val instanceof RawValue ? (RawValue) val : new RawValue(val);
} catch (DistributedSystemDisconnectedException sde) {
sendReply(getSender(), this.processorId, dm, new ReplyException(new ForceReattemptException(LocalizedStrings.GetMessage_OPERATION_GOT_INTERRUPTED_DUE_TO_SHUTDOWN_IN_PROGRESS_ON_REMOTE_VM.toLocalizedString(), sde)), r, startTime);
return false;
} catch (PrimaryBucketException pbe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
return false;
} catch (DataLocationException e) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(e), r, startTime);
return false;
}
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.debug("GetMessage sending serialized value {} back via GetReplyMessage using processorId: {}", valueBytes, getProcessorId());
}
r.getPrStats().endPartitionMessagesProcessing(startTime);
GetReplyMessage.send(getSender(), getProcessorId(), valueBytes, getReplySender(dm), event.getVersionTag());
// response
return false;
} else {
throw new InternalGemFireError(LocalizedStrings.GetMessage_GET_MESSAGE_SENT_TO_WRONG_MEMBER.toLocalizedString());
}
} finally {
OffHeapHelper.release(val);
}
}
use of org.apache.geode.internal.cache.BucketRegion.RawValue in project geode by apache.
the class Bug38741DUnitTest method testPartitionedRegionAndCopyOnRead.
/**
* Test to ensure that a PartitionedRegion doesn't make more than the expected number of copies
* when copy-on-read is set to true
*
* @throws Exception
*/
@Test
public void testPartitionedRegionAndCopyOnRead() throws Exception {
final Host h = Host.getHost(0);
final VM accessor = h.getVM(2);
final VM datastore = h.getVM(3);
final String rName = getUniqueName();
final String k1 = "k1";
datastore.invoke(new CacheSerializableRunnable("Create PR DataStore") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(0).create());
createRootRegion(rName, factory.create());
}
});
accessor.invoke(new CacheSerializableRunnable("Create PR Accessor and put new value") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setPartitionAttributes(new PartitionAttributesFactory().setLocalMaxMemory(0).setRedundantCopies(0).create());
Region r = createRootRegion(rName, factory.create());
SerializationCountingValue val = new SerializationCountingValue();
r.put(k1, val);
// First put to a bucket will serialize once to determine the size of the value
// to know how much extra space the new bucket with the new entry will consume
// and serialize again to send the bytes
assertEquals(2, val.count.get());
// A put to an already created bucket should only be serialized once
val = new SerializationCountingValue();
r.put(k1, val);
assertEquals(1, val.count.get());
}
});
datastore.invoke(new CacheSerializableRunnable("assert datastore entry serialization count") {
public void run2() throws CacheException {
PartitionedRegion pr = (PartitionedRegion) getRootRegion(rName);
// Visit the one bucket (since there is only one value in the entire PR)
// to directly copy the entry bytes and assert the serialization count.
// All this extra work is to assure the serialization count does not increase
// (by de-serializing the value stored in the map, which would then have to be
// re-serialized).
pr.getDataStore().visitBuckets(new BucketVisitor() {
public void visit(Integer bucketId, Region r) {
BucketRegion br = (BucketRegion) r;
try {
KeyInfo keyInfo = new KeyInfo(k1, null, bucketId);
RawValue rv = br.getSerialized(keyInfo, false, false, null, null, false);
Object val = rv.getRawValue();
assertTrue(val instanceof CachedDeserializable);
CachedDeserializable cd = (CachedDeserializable) val;
SerializationCountingValue scv = (SerializationCountingValue) cd.getDeserializedForReading();
assertEquals(1, scv.count.get());
} catch (IOException fail) {
Assert.fail("Unexpected IOException", fail);
}
}
});
}
});
accessor.invoke(new CacheSerializableRunnable("assert accessor entry serialization count") {
public void run2() throws CacheException {
Region r = getRootRegion(rName);
SerializationCountingValue v1 = (SerializationCountingValue) r.get(k1);
// The counter was incremented once to send the data to the datastore
assertEquals(1, v1.count.get());
getCache().setCopyOnRead(true);
// Once to send the data to the datastore, no need to do a serialization
// when we make copy since it is serialized from datastore to us.
SerializationCountingValue v2 = (SerializationCountingValue) r.get(k1);
assertEquals(1, v2.count.get());
assertTrue(v1 != v2);
}
});
datastore.invoke(new CacheSerializableRunnable("assert value serialization") {
public void run2() throws CacheException {
Region r = getRootRegion(rName);
SerializationCountingValue v1 = (SerializationCountingValue) r.get(k1);
// Once to send the value from the accessor to the data store
assertEquals(1, v1.count.get());
getCache().setCopyOnRead(true);
// Once to send the value from the accessor to the data store
// once to make a local copy
SerializationCountingValue v2 = (SerializationCountingValue) r.get(k1);
assertEquals(2, v2.count.get());
assertTrue(v1 != v2);
}
});
}
use of org.apache.geode.internal.cache.BucketRegion.RawValue in project geode by apache.
the class RemoteGetMessage method operateOnRegion.
@Override
protected boolean operateOnRegion(final DistributionManager dm, LocalRegion r, long startTime) throws RemoteOperationException {
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "RemoteGetMessage operateOnRegion: {}", r.getFullPath());
}
if (this.getTXUniqId() != TXManagerImpl.NOTX) {
assert r.getDataView() instanceof TXStateProxy;
}
if (!(r instanceof PartitionedRegion)) {
// prs already wait on initialization
// bug #43371 - accessing a region before it's initialized
r.waitOnInitialization();
}
RawValue valueBytes;
Object val = null;
try {
KeyInfo keyInfo = r.getKeyInfo(key, cbArg);
val = r.getDataView().getSerializedValue(r, keyInfo, false, this.context, null, false);
valueBytes = val instanceof RawValue ? (RawValue) val : new RawValue(val);
if (logger.isTraceEnabled(LogMarker.DM)) {
logger.trace(LogMarker.DM, "GetMessage sending serialized value {} back via GetReplyMessage using processorId: {}", valueBytes, getProcessorId());
}
// r.getPrStats().endPartitionMessagesProcessing(startTime);
GetReplyMessage.send(getSender(), getProcessorId(), valueBytes, getReplySender(dm));
// response
return false;
} catch (DistributedSystemDisconnectedException sde) {
sendReply(getSender(), this.processorId, dm, new ReplyException(new RemoteOperationException(LocalizedStrings.GetMessage_OPERATION_GOT_INTERRUPTED_DUE_TO_SHUTDOWN_IN_PROGRESS_ON_REMOTE_VM.toLocalizedString(), sde)), r, startTime);
return false;
} catch (PrimaryBucketException pbe) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(pbe), r, startTime);
return false;
} catch (DataLocationException e) {
sendReply(getSender(), getProcessorId(), dm, new ReplyException(e), r, startTime);
return false;
} finally {
OffHeapHelper.release(val);
}
}
Aggregations