Permalink
Browse files

reduce unused empty map creation in the local writes (sendToHintedEnd…

…points) case

patch by dbrosius reviewed by jbellis for CASSANDRA-5538
  • Loading branch information...
1 parent 32c3b6e commit 3c06ff0a8ee64742416c4b8a5ec083ea5a390e34 @mebigfatguy mebigfatguy committed May 6, 2013
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/java/org/apache/cassandra/service/StorageProxy.java
@@ -692,7 +692,7 @@ public static void sendToHintedEndpoints(final RowMutation rm,
throws OverloadedException
{
// Multimap that holds onto all the messages and addresses meant for a specific datacenter
- Map<String, Multimap<MessageOut, InetAddress>> dcMessages = new HashMap<String, Multimap<MessageOut, InetAddress>>();
+ Map<String, Multimap<MessageOut, InetAddress>> dcMessages = null;
for (InetAddress destination : targets)
{
@@ -720,10 +720,12 @@ public static void sendToHintedEndpoints(final RowMutation rm,
logger.trace("insert writing key " + ByteBufferUtil.bytesToHex(rm.key()) + " to " + destination);
String dc = DatabaseDescriptor.getEndpointSnitch().getDatacenter(destination);
- Multimap<MessageOut, InetAddress> messages = dcMessages.get(dc);
+ Multimap<MessageOut, InetAddress> messages = (dcMessages != null) ? dcMessages.get(dc) : null;
if (messages == null)
{
messages = HashMultimap.create();
+ if (dcMessages == null)
+ dcMessages = new HashMap<String, Multimap<MessageOut, InetAddress>>();
dcMessages.put(dc, messages);
}
@@ -740,7 +742,8 @@ public static void sendToHintedEndpoints(final RowMutation rm,
}
}
- sendMessages(localDataCenter, dcMessages, responseHandler);
+ if (dcMessages != null)
+ sendMessages(localDataCenter, dcMessages, responseHandler);
}
public static Future<Void> submitHint(final RowMutation mutation,

0 comments on commit 3c06ff0

Please sign in to comment.