From 89d094de2d5c10e4110f7de894789f4b4e57aa50 Mon Sep 17 00:00:00 2001 From: Jakub Konecki Date: Sun, 25 Jan 2015 14:03:50 +0000 Subject: [PATCH 1/2] Fix for methods returning null collections. --- src/Orleans/Utils/SetExtensions.cs | 4 ++-- src/OrleansRuntime/Catalog/ActivationDirectory.cs | 4 +++- src/OrleansRuntime/ConsistentRing/ConsistentRingProvider.cs | 4 ++-- .../GrainDirectory/GrainDirectoryHandoffManager.cs | 2 +- src/OrleansRuntime/GrainDirectory/LocalGrainDirectory.cs | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Orleans/Utils/SetExtensions.cs b/src/Orleans/Utils/SetExtensions.cs index ae31df1b669..ef714d48135 100644 --- a/src/Orleans/Utils/SetExtensions.cs +++ b/src/Orleans/Utils/SetExtensions.cs @@ -42,7 +42,7 @@ internal static class SetExtensions public static HashSet ToSet(this IEnumerable values) { if (values == null) - return null; + return new HashSet(); return new HashSet(values); } @@ -201,7 +201,7 @@ public static string ToStrings(this IEnumerable list, Func toSt public static List Union(List list1, List list2) { if (list1 == null && list2 == null) - return null; + return new List(); if (list1 == null) return list2; if (list2 == null) diff --git a/src/OrleansRuntime/Catalog/ActivationDirectory.cs b/src/OrleansRuntime/Catalog/ActivationDirectory.cs index 4bba29e3025..290effdd763 100644 --- a/src/OrleansRuntime/Catalog/ActivationDirectory.cs +++ b/src/OrleansRuntime/Catalog/ActivationDirectory.cs @@ -163,7 +163,9 @@ public void RemoveTarget(ActivationData target) } } - // Returns null if no activations exist for this grain ID, rather than an empty list + /// + /// Returns null if no activations exist for this grain ID, rather than an empty list + /// public List FindTargets(GrainId key) { List tmp; diff --git a/src/OrleansRuntime/ConsistentRing/ConsistentRingProvider.cs b/src/OrleansRuntime/ConsistentRing/ConsistentRingProvider.cs index 26689f880ad..fd885e24906 100644 --- a/src/OrleansRuntime/ConsistentRing/ConsistentRingProvider.cs +++ b/src/OrleansRuntime/ConsistentRing/ConsistentRingProvider.cs @@ -213,7 +213,7 @@ internal List FindPredecessors(SiloAddress silo, int count) if (index == -1) { log.Warn(ErrorCode.Runtime_Error_100201, "Got request to find predecessors of silo " + silo + ", which is not in the list of members."); - return null; + return new List(); } var result = new List(); @@ -235,7 +235,7 @@ internal List FindSuccessors(SiloAddress silo, int count) if (index == -1) { log.Warn(ErrorCode.Runtime_Error_100203, "Got request to find successors of silo " + silo + ", which is not in the list of members."); - return null; + return new List(); } var result = new List(); diff --git a/src/OrleansRuntime/GrainDirectory/GrainDirectoryHandoffManager.cs b/src/OrleansRuntime/GrainDirectory/GrainDirectoryHandoffManager.cs index b7291f3083c..9e75359229b 100644 --- a/src/OrleansRuntime/GrainDirectory/GrainDirectoryHandoffManager.cs +++ b/src/OrleansRuntime/GrainDirectory/GrainDirectoryHandoffManager.cs @@ -67,7 +67,7 @@ internal List GetHandedOffInfo(GrainId grain) return result.Item1.Select(pair => ActivationAddress.GetAddress(pair.Item1, grain, pair.Item2)).ToList(); } } - return null; + return new List(); } private async Task HandoffMyPartitionUponStop(Dictionary batchUpdate, bool isFullCopy) diff --git a/src/OrleansRuntime/GrainDirectory/LocalGrainDirectory.cs b/src/OrleansRuntime/GrainDirectory/LocalGrainDirectory.cs index 951bcb2a237..b4ce881e256 100644 --- a/src/OrleansRuntime/GrainDirectory/LocalGrainDirectory.cs +++ b/src/OrleansRuntime/GrainDirectory/LocalGrainDirectory.cs @@ -360,7 +360,7 @@ internal List FindPredecessors(SiloAddress silo, int count) if (index == -1) { log.Warn(ErrorCode.Runtime_Error_100201, "Got request to find predecessors of silo " + silo + ", which is not in the list of members"); - return null; + return new List(); } var result = new List(); @@ -382,7 +382,7 @@ internal List FindSuccessors(SiloAddress silo, int count) if (index == -1) { log.Warn(ErrorCode.Runtime_Error_100203, "Got request to find successors of silo " + silo + ", which is not in the list of members"); - return null; + return new List(); } var result = new List(); From 133455968e89a491d2853149ed7e9bb4cf7a6956 Mon Sep 17 00:00:00 2001 From: Jakub Konecki Date: Mon, 26 Jan 2015 20:33:26 +0000 Subject: [PATCH 2/2] Reverted changes. Added comments. --- src/Orleans/Utils/SetExtensions.cs | 4 ++-- .../ConsistentRing/ConsistentRingProvider.cs | 16 ++++++++++++++-- .../GrainDirectoryHandoffManager.cs | 2 +- .../GrainDirectory/LocalGrainDirectory.cs | 4 ++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Orleans/Utils/SetExtensions.cs b/src/Orleans/Utils/SetExtensions.cs index ef714d48135..ae31df1b669 100644 --- a/src/Orleans/Utils/SetExtensions.cs +++ b/src/Orleans/Utils/SetExtensions.cs @@ -42,7 +42,7 @@ internal static class SetExtensions public static HashSet ToSet(this IEnumerable values) { if (values == null) - return new HashSet(); + return null; return new HashSet(values); } @@ -201,7 +201,7 @@ public static string ToStrings(this IEnumerable list, Func toSt public static List Union(List list1, List list2) { if (list1 == null && list2 == null) - return new List(); + return null; if (list1 == null) return list2; if (list2 == null) diff --git a/src/OrleansRuntime/ConsistentRing/ConsistentRingProvider.cs b/src/OrleansRuntime/ConsistentRing/ConsistentRingProvider.cs index fd885e24906..0ca3d2f1d50 100644 --- a/src/OrleansRuntime/ConsistentRing/ConsistentRingProvider.cs +++ b/src/OrleansRuntime/ConsistentRing/ConsistentRingProvider.cs @@ -81,11 +81,17 @@ public IRingRange GetMyRange() return MyRange; // its immutable, so no need to clone } + /// + /// Returns null if silo is not in the list of members + /// public List GetMySucessors(int n = 1) { return FindSuccessors(MyAddress, n); } + /// + /// Returns null if silo is not in the list of members + /// public List GetMyPredecessors(int n = 1) { return FindPredecessors(MyAddress, n); @@ -205,6 +211,9 @@ internal void RemoveServer(SiloAddress silo) } } + /// + /// Returns null if silo is not in the list of members + /// internal List FindPredecessors(SiloAddress silo, int count) { lock (membershipRingList) @@ -213,7 +222,7 @@ internal List FindPredecessors(SiloAddress silo, int count) if (index == -1) { log.Warn(ErrorCode.Runtime_Error_100201, "Got request to find predecessors of silo " + silo + ", which is not in the list of members."); - return new List(); + return null; } var result = new List(); @@ -227,6 +236,9 @@ internal List FindPredecessors(SiloAddress silo, int count) } } + /// + /// Returns null if silo is not in the list of members + /// internal List FindSuccessors(SiloAddress silo, int count) { lock (membershipRingList) @@ -235,7 +247,7 @@ internal List FindSuccessors(SiloAddress silo, int count) if (index == -1) { log.Warn(ErrorCode.Runtime_Error_100203, "Got request to find successors of silo " + silo + ", which is not in the list of members."); - return new List(); + return null; } var result = new List(); diff --git a/src/OrleansRuntime/GrainDirectory/GrainDirectoryHandoffManager.cs b/src/OrleansRuntime/GrainDirectory/GrainDirectoryHandoffManager.cs index 9e75359229b..b7291f3083c 100644 --- a/src/OrleansRuntime/GrainDirectory/GrainDirectoryHandoffManager.cs +++ b/src/OrleansRuntime/GrainDirectory/GrainDirectoryHandoffManager.cs @@ -67,7 +67,7 @@ internal List GetHandedOffInfo(GrainId grain) return result.Item1.Select(pair => ActivationAddress.GetAddress(pair.Item1, grain, pair.Item2)).ToList(); } } - return new List(); + return null; } private async Task HandoffMyPartitionUponStop(Dictionary batchUpdate, bool isFullCopy) diff --git a/src/OrleansRuntime/GrainDirectory/LocalGrainDirectory.cs b/src/OrleansRuntime/GrainDirectory/LocalGrainDirectory.cs index b4ce881e256..951bcb2a237 100644 --- a/src/OrleansRuntime/GrainDirectory/LocalGrainDirectory.cs +++ b/src/OrleansRuntime/GrainDirectory/LocalGrainDirectory.cs @@ -360,7 +360,7 @@ internal List FindPredecessors(SiloAddress silo, int count) if (index == -1) { log.Warn(ErrorCode.Runtime_Error_100201, "Got request to find predecessors of silo " + silo + ", which is not in the list of members"); - return new List(); + return null; } var result = new List(); @@ -382,7 +382,7 @@ internal List FindSuccessors(SiloAddress silo, int count) if (index == -1) { log.Warn(ErrorCode.Runtime_Error_100203, "Got request to find successors of silo " + silo + ", which is not in the list of members"); - return new List(); + return null; } var result = new List();