Details
-
Improvement
-
Status: Patch Available
-
Minor
-
Resolution: Unresolved
-
3.0.0
-
None
-
None
Description
Source:
MergeThread.java
Update this class to use Java 1.8 concurrent package. There also some corner-cases not being addressed with the current implementation:
MergeThread.java
// There is a scenario here where N threads have submitted inputs and are all waiting for the 'pendingToBeMerged' object. At this point, imagine the 'close' method is called. The close method will run, see nothing in the queue, interrupt the processing thread, and cause it to exit. Afterwards, the 'startMerge' threads will all be triggered and add the inputs to a queue for which there is no consumer. At this point, the T items have been removed from the inputs with no way to recover them. In practice, this may not ever be the case, but it can be tightened up. public void startMerge(Set<T> inputs) { if (!closed) { numPending.incrementAndGet(); List<T> toMergeInputs = new ArrayList<T>(); Iterator<T> iter=inputs.iterator(); for (int ctr = 0; iter.hasNext() && ctr < mergeFactor; ++ctr) { toMergeInputs.add(iter.next()); iter.remove(); } LOG.info(getName() + ": Starting merge with " + toMergeInputs.size() + " segments, while ignoring " + inputs.size() + " segments"); synchronized(pendingToBeMerged) { pendingToBeMerged.addLast(toMergeInputs); pendingToBeMerged.notifyAll(); } } } public synchronized void close() throws InterruptedException { closed = true; waitForMerge(); interrupt(); }