public StreamSession getOrCreateSessionById(InetAddress peer, int id, InetAddress connecting) { StreamSession session = streamSessions.get(id); if (session == null) { session = new StreamSession(peer, connecting, factory, id, keepSSTableLevel, isIncremental); streamSessions.put(id, session); } return session; }
public void onRemove(InetAddress endpoint) { logger.error("[Stream #{}] Session failed because remote peer {} has left.", planId(), peer.getHostAddress()); closeSession(State.FAILED); }
public void messageReceived(StreamMessage message) { switch (message.type) { case PREPARE: PrepareMessage msg = (PrepareMessage) message; prepare(msg.requests, msg.summaries); break; case FILE: receive((IncomingFileMessage) message); break; case RECEIVED: ReceivedMessage received = (ReceivedMessage) message; received(received.cfId, received.sequenceNumber); break; case COMPLETE: complete(); break; case SESSION_FAILED: sessionFailed(); break; } }
public SessionCompleteEvent(StreamSession session) { super(Type.STREAM_COMPLETE, session.planId()); this.peer = session.peer; this.success = session.isSuccess(); this.sessionIndex = session.sessionIndex(); this.requests = ImmutableSet.copyOf(session.requests); this.description = session.description(); this.transferredRangesPerKeyspace = Collections.unmodifiableMap(session.transferredRangesPerKeyspace); } }
/** * Prepare this session for sending/receiving files. */ public void prepare(Collection<StreamRequest> requests, Collection<StreamSummary> summaries) { // prepare tasks state(State.PREPARING); for (StreamRequest request : requests) addTransferRanges(request.keyspace, request.ranges, request.columnFamilies, true, request.repairedAt); // always flush on stream request for (StreamSummary summary : summaries) prepareReceiving(summary); // send back prepare message if prepare message contains stream request if (!requests.isEmpty()) { PrepareMessage prepare = new PrepareMessage(); for (StreamTransferTask task : transfers.values()) prepare.summaries.add(task.getSummary()); handler.sendMessage(prepare); } // if there are files to stream if (!maybeCompleted()) startStreamingFiles(); }
/** * Set up transfer for specific keyspace/ranges/CFs * * Used in repair - a streamed sstable in repair will be marked with the given repairedAt time * * @param keyspace Transfer keyspace * @param ranges Transfer ranges * @param columnFamilies Transfer ColumnFamilies * @param flushTables flush tables? * @param repairedAt the time the repair started. */ public void addTransferRanges(String keyspace, Collection<Range<Token>> ranges, Collection<String> columnFamilies, boolean flushTables, long repairedAt) { Collection<ColumnFamilyStore> stores = getColumnFamilyStores(keyspace, columnFamilies); if (flushTables) flushSSTables(stores); List<Range<Token>> normalizedRanges = Range.normalize(ranges); List<SSTableStreamingSections> sections = getSSTableSectionsForRanges(normalizedRanges, stores, repairedAt, repairedAt != ActiveRepairService.UNREPAIRED_SSTABLE); try { addTransferFiles(sections); } finally { for (SSTableStreamingSections release : sections) release.ref.release(); } }
public void start() { if (requests.isEmpty() && transfers.isEmpty()) { logger.info("[Stream #{}] Session does not have any tasks.", planId()); closeSession(State.COMPLETE); return; } try { logger.info("[Stream #{}] Starting streaming to {}{}", planId(), peer, peer.equals(connecting) ? "" : " through " + connecting); handler.initiate(); onInitializationComplete(); } catch (Exception e) { JVMStabilityInspector.inspectThrowable(e); onError(e); } }
@SuppressWarnings("resource") private void sendInitMessage() throws IOException { StreamInitMessage message = new StreamInitMessage( FBUtilities.getBroadcastAddress(), session.sessionIndex(), session.planId(), session.description(), !isOutgoingHandler, session.keepSSTableLevel(), session.isIncremental()); ByteBuffer messageBuf = message.createMessage(false, protocolVersion); DataOutputStreamPlus out = getWriteChannel(socket); out.write(messageBuf); out.flush(); }
/** * Check if session is completed on receiving {@code StreamMessage.Type.COMPLETE} message. */ public synchronized void complete() { if (state == State.WAIT_COMPLETE) { if (!completeSent) { handler.sendMessage(new CompleteMessage()); completeSent = true; } closeSession(State.COMPLETE); } else { state(State.WAIT_COMPLETE); handler.closeIncoming(); } }
public void sendInitMessage(Socket socket, boolean isForOutgoing) throws IOException { StreamInitMessage message = new StreamInitMessage( FBUtilities.getBroadcastAddress(), session.sessionIndex(), session.planId(), session.description(), isForOutgoing); ByteBuffer messageBuf = message.createMessage(false, protocolVersion); getWriteChannel(socket).write(messageBuf); }
/** * Set up incoming message handler and initiate streaming. * * This method is called once on initiator. * * @throws IOException */ @SuppressWarnings("resource") public void initiate() throws IOException { logger.debug("[Stream #{}] Sending stream init for incoming stream", session.planId()); Socket incomingSocket = session.createConnection(); incoming.start(incomingSocket, StreamMessage.CURRENT_VERSION, true); logger.debug("[Stream #{}] Sending stream init for outgoing stream", session.planId()); Socket outgoingSocket = session.createConnection(); outgoing.start(outgoingSocket, StreamMessage.CURRENT_VERSION, true); }
/**l * Call back for handling exception during streaming. * * @param e thrown exception */ public void onError(Throwable e) { logError(e); // send session failure message if (handler.isOutgoingConnected()) handler.sendMessage(new SessionFailedMessage()); // fail session closeSession(State.FAILED); }
public void serialize(OutgoingFileMessage message, DataOutputStreamAndChannel out, int version, StreamSession session) throws IOException { message.serialize(out, version, session); session.fileSent(message.header); } };
/** * Request data in {@code columnFamilies} under {@code keyspace} and {@code ranges} from specific node. * * @param from endpoint address to fetch data from. * @param connecting Actual connecting address for the endpoint * @param keyspace name of keyspace * @param ranges ranges to fetch * @param columnFamilies specific column families * @return this object for chaining */ public StreamPlan requestRanges(InetAddress from, InetAddress connecting, String keyspace, Collection<Range<Token>> ranges, String... columnFamilies) { StreamSession session = coordinator.getOrCreateNextSession(from, connecting); session.addStreamRequest(keyspace, ranges, Arrays.asList(columnFamilies), repairedAt); return this; }
/** * Add transfer task to send data of specific {@code columnFamilies} under {@code keyspace} and {@code ranges}. * * @param to endpoint address of receiver * @param connecting Actual connecting address of the endpoint * @param keyspace name of keyspace * @param ranges ranges to send * @param columnFamilies specific column families * @return this object for chaining */ public StreamPlan transferRanges(InetAddress to, InetAddress connecting, String keyspace, Collection<Range<Token>> ranges, String... columnFamilies) { StreamSession session = coordinator.getOrCreateNextSession(to, connecting); session.addTransferRanges(keyspace, ranges, Arrays.asList(columnFamilies), flushBeforeTransfer, repairedAt); return this; }
public synchronized void transferFiles(InetAddress to, Collection<StreamSession.SSTableStreamingSections> sstableDetails) { HostStreamingData sessionList = getOrCreateHostData(to); if (connectionsPerHost > 1) { List<List<StreamSession.SSTableStreamingSections>> buckets = sliceSSTableDetails(sstableDetails); for (List<StreamSession.SSTableStreamingSections> subList : buckets) { StreamSession session = sessionList.getOrCreateNextSession(to, to); session.addTransferFiles(subList); } } else { StreamSession session = sessionList.getOrCreateNextSession(to, to); session.addTransferFiles(sstableDetails); } }
/** * Prepare this session for sending/receiving files. */ public void prepare(Collection<StreamRequest> requests, Collection<StreamSummary> summaries) { // prepare tasks state(State.PREPARING); for (StreamRequest request : requests) addTransferRanges(request.keyspace, request.ranges, request.columnFamilies, true, request.repairedAt); // always flush on stream request for (StreamSummary summary : summaries) prepareReceiving(summary); // send back prepare message if prepare message contains stream request if (!requests.isEmpty()) { PrepareMessage prepare = new PrepareMessage(); for (StreamTransferTask task : transfers.values()) prepare.summaries.add(task.getSummary()); handler.sendMessage(prepare); } // if there are files to stream if (!maybeCompleted()) startStreamingFiles(); }
failIfFinished(); Collection<ColumnFamilyStore> stores = getColumnFamilyStores(keyspace, columnFamilies); if (flushTables) flushSSTables(stores); List<SSTableStreamingSections> sections = getSSTableSectionsForRanges(normalizedRanges, stores, repairedAt, isIncremental); try addTransferFiles(sections); Set<Range<Token>> toBeUpdated = transferredRangesPerKeyspace.get(keyspace); if (toBeUpdated == null)
public void start() { if (requests.isEmpty() && transfers.isEmpty()) { logger.info("[Stream #{}] Session does not have any tasks.", planId()); closeSession(State.COMPLETE); return; } try { logger.info("[Stream #{}] Starting streaming to {}{}", planId(), peer, peer.equals(connecting) ? "" : " through " + connecting); handler.initiate(); onInitializationComplete(); } catch (Exception e) { JVMStabilityInspector.inspectThrowable(e); onError(e); } }
@SuppressWarnings("resource") private void sendInitMessage() throws IOException { StreamInitMessage message = new StreamInitMessage( FBUtilities.getBroadcastAddress(), session.sessionIndex(), session.planId(), session.description(), !isOutgoingHandler, session.keepSSTableLevel(), session.isIncremental()); ByteBuffer messageBuf = message.createMessage(false, protocolVersion); DataOutputStreamPlus out = getWriteChannel(socket); out.write(messageBuf); out.flush(); }