Skip to content

Commit

Permalink
GEODE-7864: Removing null checks that are not required.(Part 1) (apac…
Browse files Browse the repository at this point in the history
  • Loading branch information
nabarunnag authored Apr 22, 2020
1 parent 65dd63e commit 6d08055
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ private ServerLocation getPrimaryServerLocation(Region region, int bucketId) {
}

private void addClientPartitionAdvisor(String regionFullPath, ClientPartitionAdvisor advisor) {
if (this.cache.isClosed() || this.clientPRAdvisors == null) {
if (this.cache.isClosed()) {
return;
}
try {
Expand All @@ -778,7 +778,7 @@ private void addClientPartitionAdvisor(String regionFullPath, ClientPartitionAdv
}

public ClientPartitionAdvisor getClientPartitionAdvisor(String regionFullPath) {
if (this.cache.isClosed() || this.clientPRAdvisors == null) {
if (this.cache.isClosed()) {
return null;
}
ClientPartitionAdvisor prAdvisor = null;
Expand All @@ -791,15 +791,14 @@ public ClientPartitionAdvisor getClientPartitionAdvisor(String regionFullPath) {
}

public Set<ClientPartitionAdvisor> getColocatedClientPartitionAdvisor(String regionFullPath) {
if (this.cache.isClosed() || this.clientPRAdvisors == null
|| this.colocatedPRAdvisors == null) {
if (this.cache.isClosed()) {
return null;
}
return this.colocatedPRAdvisors.get(regionFullPath);
}

private Set<String> getAllRegionFullPaths() {
if (this.cache.isClosed() || this.clientPRAdvisors == null) {
if (this.cache.isClosed()) {
return null;
}
Set<String> keys = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,9 +1014,7 @@ static Class _getAttributeType(String attName) {
"Sets the number of milliseconds to wait for ping responses when determining whether another member is still alive. Defaults to %s.",
DEFAULT_MEMBER_TIMEOUT));

// for some reason the default port range is null under some circumstances
int[] range = DEFAULT_MEMBERSHIP_PORT_RANGE;
String srange = range == null ? "not available" : "" + range[0] + "-" + range[1];
String srange = "" + DEFAULT_MEMBERSHIP_PORT_RANGE[0] + "-" + DEFAULT_MEMBERSHIP_PORT_RANGE[1];
String msg = String.format(
"Sets the range of datagram socket ports that can be used for membership ID purposes and unicast datagram messaging. Defaults to %s.",
srange);
Expand Down
180 changes: 89 additions & 91 deletions geode-core/src/main/java/org/apache/geode/internal/SystemAdmin.java
Original file line number Diff line number Diff line change
Expand Up @@ -1153,113 +1153,111 @@ public void statistics(File directory, List archiveNames, boolean details, boole
"The -persample and -nofilter options are mutually exclusive.");
}
StatSpec[] specs = createSpecs(cmdLineSpecs);
if (archiveOption != null) {
if (directory != null) {
throw new IllegalArgumentException(
"The -archive= and -dir= options are mutually exclusive.");
}
StatArchiveReader reader = null;
boolean interrupted = false;
try {
reader = new StatArchiveReader((File[]) archiveNames.toArray(new File[0]),
specs, !monitor);
// Runtime.getRuntime().gc(); System.out.println("DEBUG: heap size=" +
// (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
if (specs.length == 0) {
if (details) {
StatArchiveReader.StatArchiveFile[] archives = reader.getArchives();
for (int i = 0; i < archives.length; i++) {
System.out.println(archives[i].getArchiveInfo().toString());
}
if (directory != null) {
throw new IllegalArgumentException(
"The -archive= and -dir= options are mutually exclusive.");
}
StatArchiveReader reader = null;
boolean interrupted = false;
try {
reader = new StatArchiveReader((File[]) archiveNames.toArray(new File[0]),
specs, !monitor);
// Runtime.getRuntime().gc(); System.out.println("DEBUG: heap size=" +
// (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));
if (specs.length == 0) {
if (details) {
StatArchiveReader.StatArchiveFile[] archives = reader.getArchives();
for (int i = 0; i < archives.length; i++) {
System.out.println(archives[i].getArchiveInfo().toString());
}
}
do {
if (specs.length == 0) {
Iterator it = reader.getResourceInstList().iterator();
while (it.hasNext()) {
ResourceInst inst = (ResourceInst) it.next();
StatValue values[] = inst.getStatValues();
boolean firstTime = true;
for (int i = 0; i < values.length; i++) {
if (values[i] != null && values[i].hasValueChanged()) {
if (firstTime) {
firstTime = false;
System.out.println(inst.toString());
}
printStatValue(values[i], startTime, endTime, nofilter, persec, persample,
prunezeros, details);
}
do {
if (specs.length == 0) {
Iterator it = reader.getResourceInstList().iterator();
while (it.hasNext()) {
ResourceInst inst = (ResourceInst) it.next();
StatValue values[] = inst.getStatValues();
boolean firstTime = true;
for (int i = 0; i < values.length; i++) {
if (values[i] != null && values[i].hasValueChanged()) {
if (firstTime) {
firstTime = false;
System.out.println(inst.toString());
}
printStatValue(values[i], startTime, endTime, nofilter, persec, persample,
prunezeros, details);
}
}
} else {
Map<CombinedResources, List<StatValue>> allSpecsMap =
new HashMap<CombinedResources, List<StatValue>>();
for (int i = 0; i < specs.length; i++) {
StatValue[] values = reader.matchSpec(specs[i]);
if (values.length == 0) {
if (!quiet) {
System.err.println(String.format("[warning] No stats matched %s.",
specs[i].cmdLineSpec));
}
} else {
Map<CombinedResources, List<StatValue>> specMap =
new HashMap<CombinedResources, List<StatValue>>();
for (StatValue v : values) {
CombinedResources key = new CombinedResources(v);
List<StatArchiveReader.StatValue> list = specMap.get(key);
if (list != null) {
list.add(v);
} else {
specMap.put(key, new ArrayList<StatValue>(Collections.singletonList(v)));
}
}
if (!quiet) {
System.out.println(
String.format("[info] Found %s instances matching %s:",
new Object[] {Integer.valueOf(specMap.size()), specs[i].cmdLineSpec}));
}
for (Map.Entry<CombinedResources, List<StatValue>> me : specMap.entrySet()) {
List<StatArchiveReader.StatValue> list = allSpecsMap.get(me.getKey());
if (list != null) {
list.addAll(me.getValue());
} else {
allSpecsMap.put(me.getKey(), me.getValue());
}
}
} else {
Map<CombinedResources, List<StatValue>> allSpecsMap =
new HashMap<CombinedResources, List<StatValue>>();
for (int i = 0; i < specs.length; i++) {
StatValue[] values = reader.matchSpec(specs[i]);
if (values.length == 0) {
if (!quiet) {
System.err.println(String.format("[warning] No stats matched %s.",
specs[i].cmdLineSpec));
}
} else {
Map<CombinedResources, List<StatValue>> specMap =
new HashMap<CombinedResources, List<StatValue>>();
for (StatValue v : values) {
CombinedResources key = new CombinedResources(v);
List<StatArchiveReader.StatValue> list = specMap.get(key);
if (list != null) {
list.add(v);
} else {
specMap.put(key, new ArrayList<StatValue>(Collections.singletonList(v)));
}
}
}
for (Map.Entry<CombinedResources, List<StatValue>> me : allSpecsMap.entrySet()) {
System.out.println(me.getKey());
for (StatValue v : me.getValue()) {
printStatValue(v, startTime, endTime, nofilter, persec, persample, prunezeros,
details);
if (!quiet) {
System.out.println(
String.format("[info] Found %s instances matching %s:",
new Object[] {Integer.valueOf(specMap.size()), specs[i].cmdLineSpec}));
}
for (Map.Entry<CombinedResources, List<StatValue>> me : specMap.entrySet()) {
List<StatArchiveReader.StatValue> list = allSpecsMap.get(me.getKey());
if (list != null) {
list.addAll(me.getValue());
} else {
allSpecsMap.put(me.getKey(), me.getValue());
}
}
}
}
if (monitor) {
while (!reader.update()) {
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {
interrupted = true;
}
for (Map.Entry<CombinedResources, List<StatValue>> me : allSpecsMap.entrySet()) {
System.out.println(me.getKey());
for (StatValue v : me.getValue()) {
printStatValue(v, startTime, endTime, nofilter, persec, persample, prunezeros,
details);
}
}
} while (monitor && !interrupted);
} catch (IOException ex) {
throw new GemFireIOException(
String.format("Failed reading %s", archiveOption), ex);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignore) {
}
if (monitor) {
while (!reader.update()) {
try {
Thread.sleep(1000);
} catch (InterruptedException ignore) {
interrupted = true;
}
}
}
if (interrupted) {
Thread.currentThread().interrupt();
} while (monitor && !interrupted);
} catch (IOException ex) {
throw new GemFireIOException(
String.format("Failed reading %s", archiveOption), ex);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ignore) {
}
}
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantReadWriteLock;
Expand Down Expand Up @@ -112,6 +113,8 @@ public abstract class AbstractRegion implements InternalRegion, AttributesMutato
private static final Logger logger = LogService.getLogger();
private final ReentrantReadWriteLock readWriteLockForCacheLoader = new ReentrantReadWriteLock();
private final ReentrantReadWriteLock readWriteLockForCacheWriter = new ReentrantReadWriteLock();
protected final ConcurrentHashMap<RegionEntry, EntryExpiryTask> entryExpiryTasks =
new ConcurrentHashMap<>();
/**
* Identifies the static order in which this region was created in relation to other regions or
* other instances of this region during the life of this JVM.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1439,8 +1439,7 @@ protected boolean stillWaiting() {
public String toString() {
// bug 37189 These strings are a work-around for an escaped reference
// in ReplyProcessor21 constructor
String msgsBeingProcessedStr = (this.msgsBeingProcessed == null) ? "nullRef"
: String.valueOf(this.msgsBeingProcessed.get());
String msgsBeingProcessedStr = String.valueOf(this.msgsBeingProcessed.get());
String regionStr = (InitialImageOperation.this.region == null) ? "nullRef"
: InitialImageOperation.this.region.getFullPath();
String numMembersStr = (this.members == null) ? "nullRef" : String.valueOf(numMembers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,6 @@ public enum InitializationLevel {
*/
private int txRefCount;

private final ConcurrentHashMap<RegionEntry, EntryExpiryTask> entryExpiryTasks =
new ConcurrentHashMap<>();

private volatile boolean regionInvalid;

/**
Expand Down Expand Up @@ -7949,9 +7946,6 @@ void cancelExpiryTask(RegionEntry regionEntry, ExpiryTask expiryTask) {
private void cancelAllEntryExpiryTasks() {
// This method gets called during LocalRegion construction
// in which case the final entryExpiryTasks field can still be null
if (entryExpiryTasks == null) {
return;
}
if (entryExpiryTasks.isEmpty()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,6 @@ public static void allPoolsRegisterDataSerializers(SerializerAttributesHolder ho
}

public static void emergencyClose() {
if (impl == null) {
return;
}
impl.itrForEmergencyClose.ifPresent(poolIterator -> {
while (poolIterator.hasNext()) {
Pool pool = poolIterator.next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ public void setPublicKey(ID mbr, Object key) {
}

public void setPublicKeys(GMSMembershipView<ID> otherView) {
if (otherView.publicKeys != null) {
this.publicKeys.putAll(otherView.publicKeys);
}
this.publicKeys.putAll(otherView.publicKeys);
}

public void setViewId(int viewId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,6 @@ private FindCoordinatorResponse<ID> processFindCoordinatorRequest(
services.getMessenger().setPublicKey(findRequest.getMyPublicKey(),
findRequest.getMemberID());

// at this level we want to return the coordinator known to membership services,
// which may be more up-to-date than the one known by the membership manager
if (view == null) {
if (services == null) {
// we must know this process's identity in order to respond
return null;
}
}

GMSMembershipView<ID> responseView = view;
if (responseView == null) {
responseView = recoveredView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1968,8 +1968,7 @@ private void stopWaitingFor(ID mbr) {
* call with synchronized(this)
*/
private void checkIfDone() {
if (notRepliedYet.isEmpty()
|| (pendingRemovals != null && pendingRemovals.containsAll(notRepliedYet))) {
if (notRepliedYet.isEmpty() || pendingRemovals.containsAll(notRepliedYet)) {
logger.debug("All anticipated view responses received - notifying waiting thread");
waiting = false;
notifyAll();
Expand Down

0 comments on commit 6d08055

Please sign in to comment.