Permalink
Browse files

Fix NPE on BulkLoader caused by losing StreamEvent

patch by yukim; reviewed by sankalp kohli for CASSANDRA-6636
  • Loading branch information...
yukim committed Feb 28, 2014
1 parent fd53628 commit b3a9a443433a271fee33bede60d4892e0c8ffb03
View
@@ -27,6 +27,7 @@
* Optimize single partition batch statements (CASSANDRA-6737)
* Disallow post-query re-ordering when paging (CASSANDRA-6722)
* Fix potential paging bug with deleted columns (CASSANDRA-6748)
+ * Fix NPE on BulkLoader caused by losing StreamEvent (CASSANDRA-6636)
Merged from 1.2:
* Add CMSClassUnloadingEnabled JVM option (CASSANDRA-6541)
* Catch memtable flush exceptions during shutdown (CASSANDRA-6735)
@@ -144,7 +144,7 @@ public StreamResultFuture stream()
return stream(Collections.<InetAddress>emptySet());
}
- public StreamResultFuture stream(Set<InetAddress> toIgnore)
+ public StreamResultFuture stream(Set<InetAddress> toIgnore, StreamEventHandler... listeners)
{
client.init(keyspace);
outputHandler.output("Established connection to initial hosts");
@@ -175,9 +175,8 @@ public StreamResultFuture stream(Set<InetAddress> toIgnore)
plan.transferFiles(remote, streamingDetails.get(remote));
}
- StreamResultFuture bulkResult = plan.execute();
- bulkResult.addEventListener(this);
- return bulkResult;
+ plan.listeners(this, listeners);
+ return plan.execute();
}
public void onSuccess(StreamState finalState) {}
@@ -33,6 +33,7 @@
{
private final UUID planId = UUIDGen.getTimeUUID();
private final String description;
+ private final List<StreamEventHandler> handlers = new ArrayList<>();
// sessions per InetAddress of the other end.
private final Map<InetAddress, StreamSession> sessions = new HashMap<>();
@@ -121,6 +122,14 @@ public StreamPlan transferFiles(InetAddress to, Collection<StreamSession.SSTable
return this;
}
+ public StreamPlan listeners(StreamEventHandler handler, StreamEventHandler... handlers)
+ {
+ this.handlers.add(handler);
+ if (handlers != null)
+ Collections.addAll(this.handlers, handlers);
+ return this;
+ }
+
/**
* @return true if this plan has no plan to execute
*/
@@ -136,7 +145,7 @@ public boolean isEmpty()
*/
public StreamResultFuture execute()
{
- return StreamResultFuture.init(planId, description, sessions.values());
+ return StreamResultFuture.init(planId, description, sessions.values(), handlers);
}
/**
@@ -75,9 +75,14 @@ private StreamResultFuture(UUID planId, String description, Collection<StreamSes
set(getCurrentState());
}
- static StreamResultFuture init(UUID planId, String description, Collection<StreamSession> sessions)
+ static StreamResultFuture init(UUID planId, String description, Collection<StreamSession> sessions, Collection<StreamEventHandler> listeners)
{
StreamResultFuture future = createAndRegister(planId, description, sessions);
+ if (listeners != null)
+ {
+ for (StreamEventHandler listener : listeners)
+ future.addEventListener(listener);
+ }
logger.info("[Stream #{}] Executing streaming plan for {}", planId, description);
// start sessions
@@ -79,7 +79,10 @@ public static void main(String args[])
StreamResultFuture future = null;
try
{
- future = loader.stream(options.ignores);
+ if (options.noProgress)
+ future = loader.stream(options.ignores);
+ else
+ future = loader.stream(options.ignores, new ProgressIndicator());
}
catch (Exception e)
{
@@ -94,8 +97,6 @@ public static void main(String args[])
}
handler.output(String.format("Streaming session ID: %s", future.planId));
- if (!options.noProgress)
- future.addEventListener(new ProgressIndicator());
try
{

0 comments on commit b3a9a44

Please sign in to comment.