Search in sources :

Example 1 with FetchEntriesResponse

use of org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesResponse in project geode by apache.

the class FetchEntriesMessageJUnitTest method testProcessChunk.

@Test
public void testProcessChunk() throws Exception {
    cache = Fakes.cache();
    PartitionedRegion pr = mock(PartitionedRegion.class);
    InternalDistributedSystem system = cache.getInternalDistributedSystem();
    FetchEntriesResponse response = new FetchEntriesResponse(system, pr, null, 0);
    HeapDataOutputStream chunkStream = createDummyChunk();
    FetchEntriesReplyMessage reply = new FetchEntriesReplyMessage(null, 0, 0, chunkStream, 0, 0, 0, false, false);
    reply.chunk = chunkStream.toByteArray();
    response.processChunk(reply);
    assertNull(response.returnRVV);
    assertEquals(2, response.returnValue.size());
    assertTrue(response.returnValue.get("keyWithOutVersionTag").equals("valueWithOutVersionTag"));
    assertTrue(response.returnValue.get("keyWithVersionTag").equals("valueWithVersionTag"));
    assertNull(response.returnVersions.get("keyWithOutVersionTag"));
    assertNotNull(response.returnVersions.get("keyWithVersionTag"));
}
Also used : FetchEntriesResponse(org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesResponse) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) FetchEntriesReplyMessage(org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesReplyMessage) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 2 with FetchEntriesResponse

use of org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesResponse in project geode by apache.

the class PartitionedRegion method getAllBucketEntries.

/**
   * Test Method: Get all entries for all copies of a bucket
   * 
   * This method will not work correctly if membership in the distributed system changes while the
   * result is being calculated.
   * 
   * @return a List of HashMaps, each map being a copy of the entries in a bucket
   */
public List<BucketDump> getAllBucketEntries(final int bucketId) throws ForceReattemptException {
    if (bucketId >= getTotalNumberOfBuckets()) {
        return Collections.emptyList();
    }
    ArrayList<BucketDump> ret = new ArrayList<BucketDump>();
    HashSet<InternalDistributedMember> collected = new HashSet<InternalDistributedMember>();
    for (; ; ) {
        // Collect all the candidates by re-examining the advisor...
        Set<InternalDistributedMember> owners = getRegionAdvisor().getBucketOwners(bucketId);
        // Remove ones we've already polled...
        owners.removeAll(collected);
        // Terminate if no more entries
        if (owners.isEmpty()) {
            break;
        }
        // Get first entry
        Iterator<InternalDistributedMember> ownersI = owners.iterator();
        InternalDistributedMember owner = (InternalDistributedMember) ownersI.next();
        // Remove it from our list
        collected.add(owner);
        // If it is ourself, answer directly
        if (owner.equals(getMyId())) {
            BucketRegion br = this.dataStore.handleRemoteGetEntries(bucketId);
            Map<Object, Object> m = new HashMap<Object, Object>() {

                // TODO: clean this up -- outer class is not serializable
                private static final long serialVersionUID = 0L;

                @Override
                public String toString() {
                    return "Bucket id = " + bucketId + " from local member = " + getDistributionManager().getDistributionManagerId() + ": " + super.toString();
                }
            };
            Map<Object, VersionTag> versions = new HashMap<Object, VersionTag>();
            for (Iterator<Map.Entry> it = br.entrySet().iterator(); it.hasNext(); ) {
                LocalRegion.NonTXEntry entry = (LocalRegion.NonTXEntry) it.next();
                RegionEntry re = entry.getRegionEntry();
                // OFFHEAP: incrc, deserialize, decrc
                Object value = re.getValue(br);
                VersionStamp versionStamp = re.getVersionStamp();
                VersionTag versionTag = versionStamp != null ? versionStamp.asVersionTag() : null;
                if (versionTag != null) {
                    versionTag.replaceNullIDs(br.getVersionMember());
                }
                if (Token.isRemoved(value)) {
                    continue;
                } else if (Token.isInvalid(value)) {
                    value = null;
                } else if (value instanceof CachedDeserializable) {
                    value = ((CachedDeserializable) value).getDeserializedForReading();
                }
                m.put(re.getKey(), value);
                versions.put(re.getKey(), versionTag);
            }
            RegionVersionVector rvv = br.getVersionVector();
            rvv = rvv != null ? rvv.getCloneForTransmission() : null;
            ret.add(new BucketDump(bucketId, owner, rvv, m, versions));
            continue;
        }
        // Send a message
        try {
            final FetchEntriesResponse r;
            r = FetchEntriesMessage.send(owner, this, bucketId);
            ret.add(r.waitForEntries());
        } catch (ForceReattemptException ignore) {
        // node has departed? Ignore.
        }
    }
    return ret;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) HashSet(java.util.HashSet) VersionStamp(org.apache.geode.internal.cache.versions.VersionStamp) FetchEntriesResponse(org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesResponse) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember)

Aggregations

FetchEntriesResponse (org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesResponse)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 FetchEntriesReplyMessage (org.apache.geode.internal.cache.partitioned.FetchEntriesMessage.FetchEntriesReplyMessage)1 RegionVersionVector (org.apache.geode.internal.cache.versions.RegionVersionVector)1 VersionStamp (org.apache.geode.internal.cache.versions.VersionStamp)1 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)1 UnitTest (org.apache.geode.test.junit.categories.UnitTest)1 Test (org.junit.Test)1