Search in sources :

Example 16 with BucketRegion

use of org.apache.geode.internal.cache.BucketRegion in project geode by apache.

the class PRBucketSynchronizationDUnitTest method verifySynchronized.

private void verifySynchronized(VM vm, final InternalDistributedMember crashedMember) {
    vm.invoke(new SerializableCallable("check that synchronization happened") {

        public Object call() throws Exception {
            PartitionedRegion pr = (PartitionedRegion) TestRegion;
            final BucketRegion bucket = pr.getDataStore().getLocalBucketById(0);
            Wait.waitForCriterion(new WaitCriterion() {

                String waitingFor = "primary is still in membership view: " + crashedMember;

                boolean dumped = false;

                public boolean done() {
                    if (TestRegion.getCache().getDistributionManager().isCurrentMember(crashedMember)) {
                        LogWriterUtils.getLogWriter().info(waitingFor);
                        return false;
                    }
                    if (!TestRegion.containsKey("Object3")) {
                        waitingFor = "entry for Object3 not found";
                        LogWriterUtils.getLogWriter().info(waitingFor);
                        return false;
                    }
                    RegionEntry re = bucket.getRegionMap().getEntry("Object5");
                    if (re == null) {
                        if (!dumped) {
                            dumped = true;
                            bucket.dumpBackingMap();
                        }
                        waitingFor = "entry for Object5 not found";
                        LogWriterUtils.getLogWriter().info(waitingFor);
                        return false;
                    }
                    if (!re.isTombstone()) {
                        if (!dumped) {
                            dumped = true;
                            bucket.dumpBackingMap();
                        }
                        waitingFor = "Object5 is not a tombstone but should be: " + re;
                        LogWriterUtils.getLogWriter().info(waitingFor);
                        return false;
                    }
                    return true;
                }

                public String description() {
                    return waitingFor;
                }
            }, 30000, 5000, true);
            return null;
        }
    });
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) RegionEntry(org.apache.geode.internal.cache.RegionEntry) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

Example 17 with BucketRegion

use of org.apache.geode.internal.cache.BucketRegion in project geode by apache.

the class RebalanceOperationDUnitTest method moveBucketsWithUnrecoveredValuesRedundancy.

/**
   * Test to ensure that we wait for in progress write operations before moving a primary.
   * 
   * @throws CancellationException
   */
public void moveBucketsWithUnrecoveredValuesRedundancy(final boolean simulate) {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {

        public void run() {
            System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "false");
            try {
                Cache cache = getCache();
                if (cache.findDiskStore("store") == null) {
                    cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).setMaxOplogSize(1).create("store");
                }
                AttributesFactory attr = new AttributesFactory();
                PartitionAttributesFactory paf = new PartitionAttributesFactory();
                attr.setDiskStoreName("store");
                attr.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
                paf.setRedundantCopies(0);
                paf.setRecoveryDelay(-1);
                paf.setStartupRecoveryDelay(-1);
                PartitionAttributes prAttr = paf.create();
                attr.setPartitionAttributes(prAttr);
                attr.setCacheLoader(new Bug40228Loader());
                cache.createRegion("region1", attr.create());
            } finally {
                System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "true");
            }
        }
    };
    // Create the region in only 1 VM
    vm0.invoke(createPrRegion);
    // Create some buckets
    vm0.invoke(new SerializableRunnable("createSomeBuckets") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            region.put(Integer.valueOf(1), "A");
            region.put(Integer.valueOf(2), "A");
            region.put(Integer.valueOf(3), "A");
            region.put(Integer.valueOf(4), "A");
            region.put(Integer.valueOf(5), "A");
            region.put(Integer.valueOf(6), "A");
        }
    });
    final long[] bucketSizes = (long[]) vm0.invoke(new SerializableCallable("get sizes and close cache") {

        public Object call() {
            PartitionedRegion region = (PartitionedRegion) getCache().getRegion("region1");
            PartitionedRegionDataStore dataStore = region.getDataStore();
            long[] bucketSizes = new long[7];
            for (int i = 1; i <= 6; i++) {
                BucketRegion bucket = dataStore.getLocalBucketById(i);
                bucketSizes[i] = bucket.getTotalBytes();
                assertEquals(0, bucket.getNumOverflowBytesOnDisk());
                assertEquals(0, bucket.getNumOverflowOnDisk());
                assertEquals(1, bucket.getNumEntriesInVM());
            }
            getCache().close();
            return bucketSizes;
        }
    });
    // now recover the region
    vm0.invoke(createPrRegion);
    vm0.invoke(new SerializableRunnable("check sizes") {

        public void run() {
            PartitionedRegion region = (PartitionedRegion) getCache().getRegion("region1");
            PartitionedRegionDataStore dataStore = region.getDataStore();
            for (int i = 1; i <= 6; i++) {
                BucketRegion bucket = dataStore.getLocalBucketById(i);
                assertEquals(1, bucket.getNumOverflowOnDisk());
                assertEquals(0, bucket.getNumEntriesInVM());
                // the size recorded on disk is not the same is the in memory size, apparently
                assertTrue("Bucket size was " + bucket.getNumOverflowBytesOnDisk(), 1 < bucket.getNumOverflowBytesOnDisk());
                assertEquals(bucket.getNumOverflowBytesOnDisk(), bucket.getTotalBytes());
            }
        }
    });
    // Create the region in the other VM (should have no effect)
    vm1.invoke(createPrRegion);
    // Now simulate a rebalance
    vm0.invoke(new SerializableRunnable("simulateRebalance") {

        public void run() {
            Cache cache = getCache();
            ResourceManager manager = cache.getResourceManager();
            RebalanceResults results = doRebalance(simulate, manager);
            assertEquals(0, results.getTotalBucketCreatesCompleted());
            assertEquals(0, results.getTotalPrimaryTransfersCompleted());
            assertEquals(3, results.getTotalBucketTransfersCompleted());
            assertTrue("Transfered Bytes = " + results.getTotalBucketTransferBytes(), 0 < results.getTotalBucketTransferBytes());
            Set<PartitionRebalanceInfo> detailSet = results.getPartitionRebalanceDetails();
            assertEquals(1, detailSet.size());
            PartitionRebalanceInfo details = detailSet.iterator().next();
            assertEquals(0, details.getBucketCreatesCompleted());
            assertEquals(0, details.getPrimaryTransfersCompleted());
            assertTrue(0 < details.getBucketTransferBytes());
            assertEquals(3, details.getBucketTransfersCompleted());
            Set<PartitionMemberInfo> afterDetails = details.getPartitionMemberDetailsAfter();
            assertEquals(2, afterDetails.size());
            for (PartitionMemberInfo memberDetails : afterDetails) {
                assertEquals(3, memberDetails.getBucketCount());
                assertEquals(3, memberDetails.getPrimaryCount());
            }
            if (!simulate) {
                verifyStats(manager, results);
            }
        }
    });
    if (!simulate) {
        SerializableRunnable checkRedundancyFixed = new SerializableRunnable("checkRedundancyFixed") {

            public void run() {
                Cache cache = getCache();
                Region region = cache.getRegion("region1");
                PartitionRegionInfo details = PartitionRegionHelper.getPartitionRegionInfo(region);
                assertEquals(6, details.getCreatedBucketCount());
                assertEquals(0, details.getActualRedundantCopies());
                assertEquals(0, details.getLowRedundancyBucketCount());
                assertEquals(2, details.getPartitionMemberInfo().size());
                for (PartitionMemberInfo memberDetails : details.getPartitionMemberInfo()) {
                    assertEquals(3, memberDetails.getBucketCount());
                    assertEquals(3, memberDetails.getPrimaryCount());
                }
                // check to make sure that moving buckets didn't close the cache loader
                Bug40228Loader loader = (Bug40228Loader) cache.getRegion("region1").getAttributes().getCacheLoader();
                assertFalse(loader.isClosed());
            }
        };
        vm0.invoke(checkRedundancyFixed);
        vm1.invoke(checkRedundancyFixed);
        SerializableRunnable checkBug40228Fixed = new SerializableRunnable("checkBug40228Fixed") {

            public void run() {
                Cache cache = getCache();
                Bug40228Loader loader = (Bug40228Loader) cache.getRegion("region1").getAttributes().getCacheLoader();
                assertFalse(loader.isClosed());
                // check to make sure that closing the PR closes the cache loader
                cache.getRegion("region1").close();
                assertTrue(loader.isClosed());
            }
        };
        vm0.invoke(checkBug40228Fixed);
        vm1.invoke(checkBug40228Fixed);
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) PartitionRebalanceInfo(org.apache.geode.cache.partition.PartitionRebalanceInfo) Host(org.apache.geode.test.dunit.Host) PartitionedRegionDataStore(org.apache.geode.internal.cache.PartitionedRegionDataStore) ResourceManager(org.apache.geode.cache.control.ResourceManager) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) BucketRegion(org.apache.geode.internal.cache.BucketRegion) PartitionMemberInfo(org.apache.geode.cache.partition.PartitionMemberInfo) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) PartitionRegionInfo(org.apache.geode.cache.partition.PartitionRegionInfo) Cache(org.apache.geode.cache.Cache)

Example 18 with BucketRegion

use of org.apache.geode.internal.cache.BucketRegion in project geode by apache.

the class RegionValue method testLocalDataSetIndexing.

@Test
public void testLocalDataSetIndexing() {
    final CacheSerializableRunnable createPRs = new CacheSerializableRunnable("create prs ") {

        public void run2() {
            AttributesFactory<Integer, RegionValue> factory = new AttributesFactory<Integer, RegionValue>();
            factory.setPartitionAttributes(new PartitionAttributesFactory<Integer, RegionValue>().setRedundantCopies(1).setTotalNumBuckets(8).create());
            final PartitionedRegion pr1 = (PartitionedRegion) createRootRegion("pr1", factory.create());
            factory = new AttributesFactory<Integer, RegionValue>();
            factory.setPartitionAttributes(new PartitionAttributesFactory<Integer, RegionValue>().setRedundantCopies(1).setTotalNumBuckets(8).setColocatedWith(pr1.getName()).create());
            final PartitionedRegion pr2 = (PartitionedRegion) createRootRegion("pr2", factory.create());
        }
    };
    final CacheSerializableRunnable createIndexesOnPRs = new CacheSerializableRunnable("create prs ") {

        public void run2() {
            try {
                QueryService qs = getCache().getQueryService();
                qs.createIndex("valueIndex1", IndexType.FUNCTIONAL, "e1.value", "/pr1 e1");
                qs.createIndex("valueIndex2", IndexType.FUNCTIONAL, "e2.value", "/pr2 e2");
            } catch (Exception e) {
                org.apache.geode.test.dunit.Assert.fail("Test failed due to Exception in index creation ", e);
            }
        }
    };
    final CacheSerializableRunnable execute = new CacheSerializableRunnable("execute function") {

        public void run2() {
            final PartitionedRegion pr1 = (PartitionedRegion) getRootRegion("pr1");
            final PartitionedRegion pr2 = (PartitionedRegion) getRootRegion("pr2");
            final Set<Integer> filter = new HashSet<Integer>();
            for (int i = 1; i <= 80; i++) {
                pr1.put(i, new RegionValue(i));
                if (i <= 20) {
                    pr2.put(i, new RegionValue(i));
                    if ((i % 5) == 0) {
                        filter.add(i);
                    }
                }
            }
            ArrayList<List> result = (ArrayList<List>) FunctionService.onRegion(pr1).withFilter(filter).execute(new FunctionAdapter() {

                public void execute(FunctionContext context) {
                    try {
                        RegionFunctionContext rContext = (RegionFunctionContext) context;
                        Region pr1 = rContext.getDataSet();
                        LocalDataSet localCust = (LocalDataSet) PartitionRegionHelper.getLocalDataForContext(rContext);
                        Map<String, Region<?, ?>> colocatedRegions = PartitionRegionHelper.getColocatedRegions(pr1);
                        Map<String, Region<?, ?>> localColocatedRegions = PartitionRegionHelper.getLocalColocatedRegions(rContext);
                        Region pr2 = colocatedRegions.get("/pr2");
                        LocalDataSet localOrd = (LocalDataSet) localColocatedRegions.get("/pr2");
                        QueryObserverImpl observer = new QueryObserverImpl();
                        QueryObserverHolder.setInstance(observer);
                        QueryService qs = pr1.getCache().getQueryService();
                        DefaultQuery query = (DefaultQuery) qs.newQuery("select distinct e1.value from /pr1 e1, /pr2  e2 where e1.value=e2.value");
                        GemFireCacheImpl.getInstance().getLogger().fine(" Num BUCKET SET: " + localCust.getBucketSet());
                        GemFireCacheImpl.getInstance().getLogger().fine("VALUES FROM PR1 bucket:");
                        for (Integer bId : localCust.getBucketSet()) {
                            BucketRegion br = ((PartitionedRegion) pr1).getDataStore().getLocalBucketById(bId);
                            String val = "";
                            for (Object e : br.values()) {
                                val += (e + ",");
                            }
                            GemFireCacheImpl.getInstance().getLogger().fine(": " + val);
                        }
                        GemFireCacheImpl.getInstance().getLogger().fine("VALUES FROM PR2 bucket:");
                        for (Integer bId : localCust.getBucketSet()) {
                            BucketRegion br = ((PartitionedRegion) pr2).getDataStore().getLocalBucketById(bId);
                            String val = "";
                            for (Object e : br.values()) {
                                val += (e + ",");
                            }
                            GemFireCacheImpl.getInstance().getLogger().fine(": " + val);
                        }
                        SelectResults r = (SelectResults) localCust.executeQuery(query, null, localCust.getBucketSet());
                        GemFireCacheImpl.getInstance().getLogger().fine("Result :" + r.asList());
                        Assert.assertTrue(observer.isIndexesUsed);
                        pr1.getCache().getLogger().fine("Index Used: " + observer.numIndexesUsed());
                        Assert.assertTrue(2 == observer.numIndexesUsed());
                        context.getResultSender().lastResult((Serializable) r.asList());
                    } catch (Exception e) {
                        context.getResultSender().lastResult(Boolean.TRUE);
                    }
                }

                @Override
                public String getId() {
                    return "ok";
                }

                @Override
                public boolean optimizeForWrite() {
                    return false;
                }
            }).getResult();
            int numResults = 0;
            for (List oneNodeResult : result) {
                GemFireCacheImpl.getInstance().getLogger().fine("Result :" + numResults + " oneNodeResult.size(): " + oneNodeResult.size() + " oneNodeResult :" + oneNodeResult);
                numResults = +oneNodeResult.size();
            }
            Assert.assertTrue(10 == numResults);
        }
    };
    dataStore1.invoke(createPRs);
    dataStore2.invoke(createPRs);
    dataStore1.invoke(createIndexesOnPRs);
    dataStore1.invoke(execute);
}
Also used : Serializable(java.io.Serializable) ArrayList(java.util.ArrayList) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) List(java.util.List) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) FunctionContext(org.apache.geode.cache.execute.FunctionContext) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) BucketRegion(org.apache.geode.internal.cache.BucketRegion) QueryService(org.apache.geode.cache.query.QueryService) LocalDataSet(org.apache.geode.internal.cache.LocalDataSet) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) Map(java.util.Map) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 19 with BucketRegion

use of org.apache.geode.internal.cache.BucketRegion in project geode by apache.

the class QueryDataDUnitTest method getLocalDataSet.

private List<String> getLocalDataSet(final String region) {
    PartitionedRegion partitionedRegion = PartitionedRegionHelper.getPartitionedRegion(region, this.managementTestRule.getCache());
    Set<BucketRegion> localPrimaryBucketRegions = partitionedRegion.getDataStore().getAllLocalPrimaryBucketRegions();
    List<String> allPrimaryValues = new ArrayList<>();
    for (BucketRegion bucketRegion : localPrimaryBucketRegions) {
        for (Object value : bucketRegion.values()) {
            allPrimaryValues.add((String) value);
        }
    }
    return allPrimaryValues;
}
Also used : BucketRegion(org.apache.geode.internal.cache.BucketRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject)

Example 20 with BucketRegion

use of org.apache.geode.internal.cache.BucketRegion in project geode by apache.

the class RawIndexRepositoryFactory method computeIndexRepository.

@Override
public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository) throws IOException {
    final IndexRepository repo;
    if (oldRepository != null) {
        oldRepository.cleanup();
    }
    LuceneRawIndex indexForRaw = (LuceneRawIndex) index;
    BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
    Directory dir = null;
    if (indexForRaw.withPersistence()) {
        String bucketLocation = LuceneServiceImpl.getUniqueIndexName(index.getName(), index.getRegionPath() + "_" + bucketId);
        File location = new File(index.getName(), bucketLocation);
        if (!location.exists()) {
            location.mkdirs();
        }
        dir = new NIOFSDirectory(location.toPath());
    } else {
        dir = new RAMDirectory();
    }
    IndexWriterConfig config = new IndexWriterConfig(indexForRaw.getAnalyzer());
    IndexWriter writer = new IndexWriter(dir, config);
    return new IndexRepositoryImpl(null, writer, serializer, indexForRaw.getIndexStats(), dataBucket, null, "");
}
Also used : NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) BucketRegion(org.apache.geode.internal.cache.BucketRegion) IndexWriter(org.apache.lucene.index.IndexWriter) File(java.io.File) RAMDirectory(org.apache.lucene.store.RAMDirectory) RegionDirectory(org.apache.geode.cache.lucene.internal.directory.RegionDirectory) RAMDirectory(org.apache.lucene.store.RAMDirectory) Directory(org.apache.lucene.store.Directory) NIOFSDirectory(org.apache.lucene.store.NIOFSDirectory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) IndexRepositoryImpl(org.apache.geode.cache.lucene.internal.repository.IndexRepositoryImpl)

Aggregations

BucketRegion (org.apache.geode.internal.cache.BucketRegion)55 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)35 Region (org.apache.geode.cache.Region)13 Test (org.junit.Test)13 Bucket (org.apache.geode.internal.cache.partitioned.Bucket)11 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)10 ArrayList (java.util.ArrayList)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)9 HashMap (java.util.HashMap)7 LocalRegion (org.apache.geode.internal.cache.LocalRegion)7 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 HashSet (java.util.HashSet)5 GatewaySender (org.apache.geode.cache.wan.GatewaySender)5 Map (java.util.Map)4 AttributesFactory (org.apache.geode.cache.AttributesFactory)4 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)4 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)4