private void exportOnMember(File snapshot, SnapshotFormat format, SnapshotOptions<K, V> options) throws IOException { LocalRegion local = getLocalRegion(region); Exporter<K, V> exp = createExporter(region, options); if (getLoggerI18n().fineEnabled()) { getLoggerI18n().fine("Writing to snapshot " + snapshot.getAbsolutePath()); } long count = 0; long start = CachePerfStats.getStatTime(); SnapshotWriter writer = GFSnapshot.create(snapshot, region.getFullPath()); try { if (getLoggerI18n().infoEnabled()) getLoggerI18n().info(LocalizedStrings.Snapshot_EXPORT_BEGIN_0, region.getName()); SnapshotWriterSink sink = new SnapshotWriterSink(writer); count = exp.export(region, sink, options); if (getLoggerI18n().infoEnabled()) { getLoggerI18n() .info( LocalizedStrings.Snapshot_EXPORT_END_0_1_2_3, new Object[] {count, sink.getBytesWritten(), region.getName(), snapshot}); } } finally { writer.snapshotComplete(); local.getCachePerfStats().endExport(count, start); } }
@Before public void setup() { assertThat(factorials, is(notNullValue())); assertThat(factorials.getName(), is(equalTo("Factorials"))); assertThat( factorials.getFullPath(), is(equalTo(String.format("%1$sFactorials", Region.SEPARATOR)))); assertThat(factorials.getAttributes(), is(notNullValue())); assertThat(factorials.getAttributes().getDataPolicy(), is(equalTo(DataPolicy.EMPTY))); assertThat( factorials.getAttributes().getPoolName(), is(equalTo(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME))); }
protected static void assertRegionMetaData( final Region<?, ?> region, final String expectedName, final String expectedFullPath, final DataPolicy expectedDataPolicy) { assertNotNull( String.format("Region (%1$s) was not properly configured and initialized!", expectedName), region); assertEquals(expectedName, region.getName()); assertEquals(expectedFullPath, region.getFullPath()); assertNotNull( String.format("Region (%1$s) must have RegionAttributes defined!", expectedName), region.getAttributes()); assertEquals(expectedDataPolicy, region.getAttributes().getDataPolicy()); assertFalse(region.getAttributes().getDataPolicy().withPersistence()); }
private void importOnMember(File snapshot, SnapshotFormat format, SnapshotOptions<K, V> options) throws IOException, ClassNotFoundException { final LocalRegion local = getLocalRegion(region); if (getLoggerI18n().infoEnabled()) getLoggerI18n().info(LocalizedStrings.Snapshot_IMPORT_BEGIN_0, region.getName()); long count = 0; long bytes = 0; long start = CachePerfStats.getStatTime(); // Would be interesting to use a PriorityQueue ordered on isDone() // but this is probably close enough in practice. LinkedList<Future<?>> puts = new LinkedList<Future<?>>(); GFSnapshotImporter in = new GFSnapshotImporter(snapshot); try { int bufferSize = 0; Map<K, V> buffer = new HashMap<K, V>(); SnapshotRecord record; while ((record = in.readSnapshotRecord()) != null) { bytes += record.getSize(); K key = record.getKeyObject(); // Until we modify the semantics of put/putAll to allow null values we // have to subvert the API by using Token.INVALID. Alternatively we could // invoke create/invalidate directly but that prevents us from using // bulk operations. The ugly type coercion below is necessary to allow // strong typing elsewhere. V val = (V) Token.INVALID; if (record.hasValue()) { byte[] data = record.getValue(); // If the underlying object is a byte[], we can't wrap it in a // CachedDeserializable. Somewhere along the line the header bytes // get lost and we start seeing serialization problems. if (data.length > 0 && data[0] == DSCODE.BYTE_ARRAY) { // It would be faster to use System.arraycopy() directly but since // length field is variable it's probably safest and simplest to // keep the logic in the InternalDataSerializer. val = record.getValueObject(); } else { val = (V) CachedDeserializableFactory.create(record.getValue()); } } if (includeEntry(options, key, val)) { buffer.put(key, val); bufferSize += record.getSize(); count++; // Push entries into cache using putAll on a separate thread so we // can keep the disk busy. Throttle puts so we don't overwhelm the cache. if (bufferSize > BUFFER_SIZE) { if (puts.size() == IMPORT_CONCURRENCY) { puts.removeFirst().get(); } final Map<K, V> copy = new HashMap<K, V>(buffer); Future<?> f = GemFireCacheImpl.getExisting("Importing region from snapshot") .getDistributionManager() .getWaitingThreadPool() .submit( new Runnable() { @Override public void run() { local.basicImportPutAll(copy, true); } }); puts.addLast(f); buffer.clear(); bufferSize = 0; } } } // send off any remaining entries if (!buffer.isEmpty()) { local.basicImportPutAll(buffer, true); } // wait for completion and check for errors while (!puts.isEmpty()) { puts.removeFirst().get(); } if (getLoggerI18n().infoEnabled()) { getLoggerI18n() .info( LocalizedStrings.Snapshot_IMPORT_END_0_1_2_3, new Object[] {count, bytes, region.getName(), snapshot}); } } catch (InterruptedException e) { while (!puts.isEmpty()) { puts.removeFirst().cancel(true); } Thread.currentThread().interrupt(); throw (IOException) new InterruptedIOException().initCause(e); } catch (ExecutionException e) { while (!puts.isEmpty()) { puts.removeFirst().cancel(true); } throw new IOException(e); } finally { in.close(); local.getCachePerfStats().endImport(count, start); } }
/** * Initializes without children. * * @param region The region from which RegionInfo is extracted. */ @SuppressWarnings({"unchecked", "rawtypes"}) private void init(Region region) { if (region == null) { return; } DistributedMember member = CacheFactory.getAnyInstance().getDistributedSystem().getDistributedMember(); setName(region.getName()); setFullPath(region.getFullPath()); GemfireRegionAttributeInfo attrInfo = new GemfireRegionAttributeInfo(); RegionAttributes<?, ?> attr = region.getAttributes(); attrInfo.setAttribute(GemfireRegionAttributeInfo.DATA_POLICY, attr.getDataPolicy().toString()); attrInfo.setAttribute(GemfireRegionAttributeInfo.SCOPE, attr.getScope().toString()); if (region instanceof PartitionedRegion) { PartitionedRegion pr = (PartitionedRegion) region; PartitionAttributes pattr = pr.getPartitionAttributes(); attrInfo.setAttribute( GemfireRegionAttributeInfo.LOCAL_MAX_MEMORY, pattr.getLocalMaxMemory() + ""); attrInfo.setAttribute( GemfireRegionAttributeInfo.REDUNDANT_COPIES, pattr.getRedundantCopies() + ""); attrInfo.setAttribute( GemfireRegionAttributeInfo.TOTAL_MAX_MEMORY, pattr.getTotalMaxMemory() + ""); attrInfo.setAttribute( GemfireRegionAttributeInfo.TOTAL_NUM_BUCKETS, pattr.getTotalNumBuckets() + ""); // data store is null if it's a proxy, i.e., LOCAL_MAX_MEMORY=0 if (pr.getDataStore() != null) { Set<BucketRegion> localtBuketSet = pr.getDataStore().getAllLocalBucketRegions(); List<BucketInfo> primaryList = new ArrayList<BucketInfo>(); List<BucketInfo> redundantList = new ArrayList<BucketInfo>(); this.size = 0; for (BucketRegion br : localtBuketSet) { BucketInfo bucketInfo = new GemfireBucketInfo( br.getId(), br.getBucketAdvisor().isPrimary(), br.size(), br.getTotalBytes()); // InternalDistributedMember m = pr.getBucketPrimary(br.getId()); // if (m.getId().equals(member.getId())) { if (bucketInfo.isPrimary()) { primaryList.add(bucketInfo); this.size += bucketInfo.getSize(); } else { redundantList.add(bucketInfo); } } Collections.sort(primaryList); Collections.sort(redundantList); setPrimaryBucketInfoList(primaryList); setRedundantBucketInfoList(redundantList); } } else { this.size = region.size(); } setAttrInfo(attrInfo); temporalType = GemfireTemporalManager.getTemporalType(region); if (region.isDestroyed() == false && region.isEmpty() == false) { Set<Map.Entry> regionEntrySet = region.entrySet(); for (Map.Entry entry : regionEntrySet) { Object key = entry.getKey(); Object value = entry.getValue(); keyTypeName = key.getClass().getName(); valueTypeName = value.getClass().getName(); break; } } }
public String getName() { return region.getName(); }
public Index createIndex( String indexName, IndexType indexType, String indexedExpression, String fromClause, String imports, boolean loadEntries, Region region) throws IndexNameConflictException, IndexExistsException, RegionNotFoundException { if (pool != null) { throw new UnsupportedOperationException( "Index creation on the server is not supported from the client."); } PartitionedIndex parIndex = null; if (region == null) { region = getRegionFromPath(imports, fromClause); } RegionAttributes ra = region.getAttributes(); // Asif: If the evistion action is Overflow to disk then do not allow index creation // It is Ok to have index creation if it is persist only mode as data will always // exist in memory // if(ra.getEvictionAttributes().getAction().isOverflowToDisk() ) { // throw new // UnsupportedOperationException(LocalizedStrings.DefaultQueryService_INDEX_CREATION_IS_NOT_SUPPORTED_FOR_REGIONS_WHICH_OVERFLOW_TO_DISK_THE_REGION_INVOLVED_IS_0.toLocalizedString(regionPath)); // } // if its a pr the create index on all of the local buckets. if (((LocalRegion) region).heapThresholdReached.get() && !InternalResourceManager.isLowMemoryExceptionDisabled()) { LocalRegion lr = (LocalRegion) region; throw new LowMemoryException( LocalizedStrings.ResourceManager_LOW_MEMORY_FOR_INDEX.toLocalizedString(region.getName()), lr.getHeapThresholdReachedMembers()); } if (region instanceof PartitionedRegion) { try { parIndex = (PartitionedIndex) ((PartitionedRegion) region) .createIndex( false, indexType, indexName, indexedExpression, fromClause, imports, loadEntries); } catch (ForceReattemptException ex) { region .getCache() .getLoggerI18n() .info( LocalizedStrings .DefaultQueryService_EXCEPTION_WHILE_CREATING_INDEX_ON_PR_DEFAULT_QUERY_PROCESSOR, ex); } catch (IndexCreationException exx) { region .getCache() .getLoggerI18n() .info( LocalizedStrings .DefaultQueryService_EXCEPTION_WHILE_CREATING_INDEX_ON_PR_DEFAULT_QUERY_PROCESSOR, exx); } return parIndex; } else { IndexManager indexManager = IndexUtils.getIndexManager(region, true); Index index = indexManager.createIndex( indexName, indexType, indexedExpression, fromClause, imports, null, null, loadEntries); return index; } }