/** * returns an estimate of the number of entries in this region. This method should be preferred * over size() for hdfs regions where an accurate size is not needed. This method is not supported * on a client * * @return the estimated size of this region */ public int sizeEstimate() { boolean isClient = this.imageState.isClient(); if (isClient) { throw new UnsupportedOperationException("Method not supported on a client"); } return entryCount(null, true); }
/** * Callers of this method should always follow the call with: if (lockRIReadLock()) { try { } * finally { unlockRIReadLock(); } } * * @return true if lock obtained and unlock needs to be called */ private boolean lockRIReadLock() { if (getImageState().isClient()) { getImageState().readLockRI(); return true; } else { return false; } }
private void unlockRIReadLock() { assert getImageState().isClient(); getImageState().readUnlockRI(); }
/** * @return size after considering imageState */ @Override public int getRegionSize() { synchronized (getSizeGuard()) { int result = getRegionMap().size(); // if this is a client with no tombstones then we subtract the number // of entries being affected by register-interest refresh if (this.imageState.isClient() && !this.getConcurrencyChecksEnabled()) { return result - this.imageState.getDestroyedEntriesCount(); } return result - this.tombstoneCount.get(); } }
protected boolean nonTXContainsKey(KeyInfo keyInfo) { boolean contains = getRegionMap().containsKey(keyInfo.getKey()); if (contains && this.imageState.isClient()) { // fix for bug #40871 - concurrent RI causes containsKey for destroyed entry // to return true RegionEntry regionEntry = this.entries.getEntry(keyInfo.getKey()); if (regionEntry == null || regionEntry.isDestroyedOrRemoved()) { contains = false; } } return contains; }
/** * (description copied from entryCount() Returns the number of entries in this region. Note that * because of the concurrency properties of the {@link RegionMap}, the number of entries is only * an approximate. That is, other threads may change the number of entries in this region while * this method is being invoked. * * @see LocalRegion#entryCount() */ @Override public int size() { checkReadiness(); checkForNoAccess(); discoverJTA(); boolean isClient = this.imageState.isClient(); if (isClient) { // bug #40871 - test sees wrong size for region during RI lockRIReadLock(); } try { return entryCount(); } finally { if (isClient) { unlockRIReadLock(); } } }