fix previous fix because multithread is not correct

This commit is contained in:
fjy 2013-08-12 18:53:50 -07:00
parent 5ff216838d
commit 5cb1475a91
1 changed files with 13 additions and 9 deletions

View File

@ -37,6 +37,7 @@ import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.atomic.AtomicLong;
/** /**
*/ */
@ -50,6 +51,7 @@ public class BatchDataSegmentAnnouncer extends AbstractDataSegmentAnnouncer
private final String liveSegmentLocation; private final String liveSegmentLocation;
private final Object lock = new Object(); private final Object lock = new Object();
private final AtomicLong counter = new AtomicLong(0);
private final Set<SegmentZNode> availableZNodes = new ConcurrentSkipListSet<SegmentZNode>(); private final Set<SegmentZNode> availableZNodes = new ConcurrentSkipListSet<SegmentZNode>();
private final Map<DataSegment, SegmentZNode> segmentLookup = Maps.newConcurrentMap(); private final Map<DataSegment, SegmentZNode> segmentLookup = Maps.newConcurrentMap();
@ -118,6 +120,7 @@ public class BatchDataSegmentAnnouncer extends AbstractDataSegmentAnnouncer
return; return;
} }
synchronized (lock) {
segmentZNode.removeSegment(segment); segmentZNode.removeSegment(segment);
log.info("Unannouncing segment[%s] at path[%s]", segment.getIdentifier(), segmentZNode.getPath()); log.info("Unannouncing segment[%s] at path[%s]", segment.getIdentifier(), segmentZNode.getPath());
@ -129,6 +132,7 @@ public class BatchDataSegmentAnnouncer extends AbstractDataSegmentAnnouncer
availableZNodes.add(segmentZNode); availableZNodes.add(segmentZNode);
} }
} }
}
@Override @Override
public void announceSegments(Iterable<DataSegment> segments) throws IOException public void announceSegments(Iterable<DataSegment> segments) throws IOException
@ -176,7 +180,7 @@ public class BatchDataSegmentAnnouncer extends AbstractDataSegmentAnnouncer
private String makeServedSegmentPath(String zNode) private String makeServedSegmentPath(String zNode)
{ {
return ZKPaths.makePath(liveSegmentLocation, zNode); return ZKPaths.makePath(liveSegmentLocation, String.format("%s%s", zNode, counter.getAndIncrement()));
} }
private class SegmentZNode implements Comparable<SegmentZNode> private class SegmentZNode implements Comparable<SegmentZNode>